pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.3.91';
  22. PDFJS.build = 'd1e83b5';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. var globalScope = (typeof window === 'undefined') ? this : window;
  27. var isWorker = (typeof window === 'undefined');
  28. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  29. var TextRenderingMode = {
  30. FILL: 0,
  31. STROKE: 1,
  32. FILL_STROKE: 2,
  33. INVISIBLE: 3,
  34. FILL_ADD_TO_PATH: 4,
  35. STROKE_ADD_TO_PATH: 5,
  36. FILL_STROKE_ADD_TO_PATH: 6,
  37. ADD_TO_PATH: 7,
  38. FILL_STROKE_MASK: 3,
  39. ADD_TO_PATH_FLAG: 4
  40. };
  41. var ImageKind = {
  42. GRAYSCALE_1BPP: 1,
  43. RGB_24BPP: 2,
  44. RGBA_32BPP: 3
  45. };
  46. var AnnotationType = {
  47. TEXT: 1,
  48. LINK: 2,
  49. FREETEXT: 3,
  50. LINE: 4,
  51. SQUARE: 5,
  52. CIRCLE: 6,
  53. POLYGON: 7,
  54. POLYLINE: 8,
  55. HIGHLIGHT: 9,
  56. UNDERLINE: 10,
  57. SQUIGGLY: 11,
  58. STRIKEOUT: 12,
  59. STAMP: 13,
  60. CARET: 14,
  61. INK: 15,
  62. POPUP: 16,
  63. FILEATTACHMENT: 17,
  64. SOUND: 18,
  65. MOVIE: 19,
  66. WIDGET: 20,
  67. SCREEN: 21,
  68. PRINTERMARK: 22,
  69. TRAPNET: 23,
  70. WATERMARK: 24,
  71. THREED: 25,
  72. REDACT: 26
  73. };
  74. var AnnotationFlag = {
  75. INVISIBLE: 0x01,
  76. HIDDEN: 0x02,
  77. PRINT: 0x04,
  78. NOZOOM: 0x08,
  79. NOROTATE: 0x10,
  80. NOVIEW: 0x20,
  81. READONLY: 0x40,
  82. LOCKED: 0x80,
  83. TOGGLENOVIEW: 0x100,
  84. LOCKEDCONTENTS: 0x200
  85. };
  86. var AnnotationBorderStyleType = {
  87. SOLID: 1,
  88. DASHED: 2,
  89. BEVELED: 3,
  90. INSET: 4,
  91. UNDERLINE: 5
  92. };
  93. var StreamType = {
  94. UNKNOWN: 0,
  95. FLATE: 1,
  96. LZW: 2,
  97. DCT: 3,
  98. JPX: 4,
  99. JBIG: 5,
  100. A85: 6,
  101. AHX: 7,
  102. CCF: 8,
  103. RL: 9
  104. };
  105. var FontType = {
  106. UNKNOWN: 0,
  107. TYPE1: 1,
  108. TYPE1C: 2,
  109. CIDFONTTYPE0: 3,
  110. CIDFONTTYPE0C: 4,
  111. TRUETYPE: 5,
  112. CIDFONTTYPE2: 6,
  113. TYPE3: 7,
  114. OPENTYPE: 8,
  115. TYPE0: 9,
  116. MMTYPE1: 10
  117. };
  118. // The global PDFJS object exposes the API
  119. // In production, it will be declared outside a global wrapper
  120. // In development, it will be declared here
  121. if (!globalScope.PDFJS) {
  122. globalScope.PDFJS = {};
  123. }
  124. globalScope.PDFJS.pdfBug = false;
  125. PDFJS.VERBOSITY_LEVELS = {
  126. errors: 0,
  127. warnings: 1,
  128. infos: 5
  129. };
  130. // All the possible operations for an operator list.
  131. var OPS = PDFJS.OPS = {
  132. // Intentionally start from 1 so it is easy to spot bad operators that will be
  133. // 0's.
  134. dependency: 1,
  135. setLineWidth: 2,
  136. setLineCap: 3,
  137. setLineJoin: 4,
  138. setMiterLimit: 5,
  139. setDash: 6,
  140. setRenderingIntent: 7,
  141. setFlatness: 8,
  142. setGState: 9,
  143. save: 10,
  144. restore: 11,
  145. transform: 12,
  146. moveTo: 13,
  147. lineTo: 14,
  148. curveTo: 15,
  149. curveTo2: 16,
  150. curveTo3: 17,
  151. closePath: 18,
  152. rectangle: 19,
  153. stroke: 20,
  154. closeStroke: 21,
  155. fill: 22,
  156. eoFill: 23,
  157. fillStroke: 24,
  158. eoFillStroke: 25,
  159. closeFillStroke: 26,
  160. closeEOFillStroke: 27,
  161. endPath: 28,
  162. clip: 29,
  163. eoClip: 30,
  164. beginText: 31,
  165. endText: 32,
  166. setCharSpacing: 33,
  167. setWordSpacing: 34,
  168. setHScale: 35,
  169. setLeading: 36,
  170. setFont: 37,
  171. setTextRenderingMode: 38,
  172. setTextRise: 39,
  173. moveText: 40,
  174. setLeadingMoveText: 41,
  175. setTextMatrix: 42,
  176. nextLine: 43,
  177. showText: 44,
  178. showSpacedText: 45,
  179. nextLineShowText: 46,
  180. nextLineSetSpacingShowText: 47,
  181. setCharWidth: 48,
  182. setCharWidthAndBounds: 49,
  183. setStrokeColorSpace: 50,
  184. setFillColorSpace: 51,
  185. setStrokeColor: 52,
  186. setStrokeColorN: 53,
  187. setFillColor: 54,
  188. setFillColorN: 55,
  189. setStrokeGray: 56,
  190. setFillGray: 57,
  191. setStrokeRGBColor: 58,
  192. setFillRGBColor: 59,
  193. setStrokeCMYKColor: 60,
  194. setFillCMYKColor: 61,
  195. shadingFill: 62,
  196. beginInlineImage: 63,
  197. beginImageData: 64,
  198. endInlineImage: 65,
  199. paintXObject: 66,
  200. markPoint: 67,
  201. markPointProps: 68,
  202. beginMarkedContent: 69,
  203. beginMarkedContentProps: 70,
  204. endMarkedContent: 71,
  205. beginCompat: 72,
  206. endCompat: 73,
  207. paintFormXObjectBegin: 74,
  208. paintFormXObjectEnd: 75,
  209. beginGroup: 76,
  210. endGroup: 77,
  211. beginAnnotations: 78,
  212. endAnnotations: 79,
  213. beginAnnotation: 80,
  214. endAnnotation: 81,
  215. paintJpegXObject: 82,
  216. paintImageMaskXObject: 83,
  217. paintImageMaskXObjectGroup: 84,
  218. paintImageXObject: 85,
  219. paintInlineImageXObject: 86,
  220. paintInlineImageXObjectGroup: 87,
  221. paintImageXObjectRepeat: 88,
  222. paintImageMaskXObjectRepeat: 89,
  223. paintSolidColorImageMask: 90,
  224. constructPath: 91
  225. };
  226. // A notice for devs. These are good for things that are helpful to devs, such
  227. // as warning that Workers were disabled, which is important to devs but not
  228. // end users.
  229. function info(msg) {
  230. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  231. console.log('Info: ' + msg);
  232. }
  233. }
  234. // Non-fatal warnings.
  235. function warn(msg) {
  236. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  237. console.log('Warning: ' + msg);
  238. }
  239. }
  240. // Deprecated API function -- treated as warnings.
  241. function deprecated(details) {
  242. warn('Deprecated API usage: ' + details);
  243. }
  244. // Fatal errors that should trigger the fallback UI and halt execution by
  245. // throwing an exception.
  246. function error(msg) {
  247. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  248. console.log('Error: ' + msg);
  249. console.log(backtrace());
  250. }
  251. throw new Error(msg);
  252. }
  253. function backtrace() {
  254. try {
  255. throw new Error();
  256. } catch (e) {
  257. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  258. }
  259. }
  260. function assert(cond, msg) {
  261. if (!cond) {
  262. error(msg);
  263. }
  264. }
  265. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  266. unknown: 'unknown',
  267. forms: 'forms',
  268. javaScript: 'javaScript',
  269. smask: 'smask',
  270. shadingPattern: 'shadingPattern',
  271. font: 'font'
  272. };
  273. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  274. // absolute URL, it will be returned as is.
  275. function combineUrl(baseUrl, url) {
  276. if (!url) {
  277. return baseUrl;
  278. }
  279. return new URL(url, baseUrl).href;
  280. }
  281. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  282. function isValidUrl(url, allowRelative) {
  283. if (!url) {
  284. return false;
  285. }
  286. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  287. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  288. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  289. if (!protocol) {
  290. return allowRelative;
  291. }
  292. protocol = protocol[0].toLowerCase();
  293. switch (protocol) {
  294. case 'http':
  295. case 'https':
  296. case 'ftp':
  297. case 'mailto':
  298. case 'tel':
  299. return true;
  300. default:
  301. return false;
  302. }
  303. }
  304. PDFJS.isValidUrl = isValidUrl;
  305. function shadow(obj, prop, value) {
  306. Object.defineProperty(obj, prop, { value: value,
  307. enumerable: true,
  308. configurable: true,
  309. writable: false });
  310. return value;
  311. }
  312. PDFJS.shadow = shadow;
  313. var LinkTarget = PDFJS.LinkTarget = {
  314. NONE: 0, // Default value.
  315. SELF: 1,
  316. BLANK: 2,
  317. PARENT: 3,
  318. TOP: 4,
  319. };
  320. var LinkTargetStringMap = [
  321. '',
  322. '_self',
  323. '_blank',
  324. '_parent',
  325. '_top'
  326. ];
  327. function isExternalLinkTargetSet() {
  328. if (PDFJS.openExternalLinksInNewWindow) {
  329. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  330. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  331. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  332. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  333. }
  334. // Reset the deprecated parameter, to suppress further warnings.
  335. PDFJS.openExternalLinksInNewWindow = false;
  336. }
  337. switch (PDFJS.externalLinkTarget) {
  338. case LinkTarget.NONE:
  339. return false;
  340. case LinkTarget.SELF:
  341. case LinkTarget.BLANK:
  342. case LinkTarget.PARENT:
  343. case LinkTarget.TOP:
  344. return true;
  345. }
  346. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  347. // Reset the external link target, to suppress further warnings.
  348. PDFJS.externalLinkTarget = LinkTarget.NONE;
  349. return false;
  350. }
  351. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  352. var PasswordResponses = PDFJS.PasswordResponses = {
  353. NEED_PASSWORD: 1,
  354. INCORRECT_PASSWORD: 2
  355. };
  356. var PasswordException = (function PasswordExceptionClosure() {
  357. function PasswordException(msg, code) {
  358. this.name = 'PasswordException';
  359. this.message = msg;
  360. this.code = code;
  361. }
  362. PasswordException.prototype = new Error();
  363. PasswordException.constructor = PasswordException;
  364. return PasswordException;
  365. })();
  366. PDFJS.PasswordException = PasswordException;
  367. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  368. function UnknownErrorException(msg, details) {
  369. this.name = 'UnknownErrorException';
  370. this.message = msg;
  371. this.details = details;
  372. }
  373. UnknownErrorException.prototype = new Error();
  374. UnknownErrorException.constructor = UnknownErrorException;
  375. return UnknownErrorException;
  376. })();
  377. PDFJS.UnknownErrorException = UnknownErrorException;
  378. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  379. function InvalidPDFException(msg) {
  380. this.name = 'InvalidPDFException';
  381. this.message = msg;
  382. }
  383. InvalidPDFException.prototype = new Error();
  384. InvalidPDFException.constructor = InvalidPDFException;
  385. return InvalidPDFException;
  386. })();
  387. PDFJS.InvalidPDFException = InvalidPDFException;
  388. var MissingPDFException = (function MissingPDFExceptionClosure() {
  389. function MissingPDFException(msg) {
  390. this.name = 'MissingPDFException';
  391. this.message = msg;
  392. }
  393. MissingPDFException.prototype = new Error();
  394. MissingPDFException.constructor = MissingPDFException;
  395. return MissingPDFException;
  396. })();
  397. PDFJS.MissingPDFException = MissingPDFException;
  398. var UnexpectedResponseException =
  399. (function UnexpectedResponseExceptionClosure() {
  400. function UnexpectedResponseException(msg, status) {
  401. this.name = 'UnexpectedResponseException';
  402. this.message = msg;
  403. this.status = status;
  404. }
  405. UnexpectedResponseException.prototype = new Error();
  406. UnexpectedResponseException.constructor = UnexpectedResponseException;
  407. return UnexpectedResponseException;
  408. })();
  409. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  410. var NotImplementedException = (function NotImplementedExceptionClosure() {
  411. function NotImplementedException(msg) {
  412. this.message = msg;
  413. }
  414. NotImplementedException.prototype = new Error();
  415. NotImplementedException.prototype.name = 'NotImplementedException';
  416. NotImplementedException.constructor = NotImplementedException;
  417. return NotImplementedException;
  418. })();
  419. var MissingDataException = (function MissingDataExceptionClosure() {
  420. function MissingDataException(begin, end) {
  421. this.begin = begin;
  422. this.end = end;
  423. this.message = 'Missing data [' + begin + ', ' + end + ')';
  424. }
  425. MissingDataException.prototype = new Error();
  426. MissingDataException.prototype.name = 'MissingDataException';
  427. MissingDataException.constructor = MissingDataException;
  428. return MissingDataException;
  429. })();
  430. var XRefParseException = (function XRefParseExceptionClosure() {
  431. function XRefParseException(msg) {
  432. this.message = msg;
  433. }
  434. XRefParseException.prototype = new Error();
  435. XRefParseException.prototype.name = 'XRefParseException';
  436. XRefParseException.constructor = XRefParseException;
  437. return XRefParseException;
  438. })();
  439. function bytesToString(bytes) {
  440. assert(bytes !== null && typeof bytes === 'object' &&
  441. bytes.length !== undefined, 'Invalid argument for bytesToString');
  442. var length = bytes.length;
  443. var MAX_ARGUMENT_COUNT = 8192;
  444. if (length < MAX_ARGUMENT_COUNT) {
  445. return String.fromCharCode.apply(null, bytes);
  446. }
  447. var strBuf = [];
  448. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  449. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  450. var chunk = bytes.subarray(i, chunkEnd);
  451. strBuf.push(String.fromCharCode.apply(null, chunk));
  452. }
  453. return strBuf.join('');
  454. }
  455. function stringToBytes(str) {
  456. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  457. var length = str.length;
  458. var bytes = new Uint8Array(length);
  459. for (var i = 0; i < length; ++i) {
  460. bytes[i] = str.charCodeAt(i) & 0xFF;
  461. }
  462. return bytes;
  463. }
  464. function string32(value) {
  465. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  466. (value >> 8) & 0xff, value & 0xff);
  467. }
  468. function log2(x) {
  469. var n = 1, i = 0;
  470. while (x > n) {
  471. n <<= 1;
  472. i++;
  473. }
  474. return i;
  475. }
  476. function readInt8(data, start) {
  477. return (data[start] << 24) >> 24;
  478. }
  479. function readUint16(data, offset) {
  480. return (data[offset] << 8) | data[offset + 1];
  481. }
  482. function readUint32(data, offset) {
  483. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  484. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  485. }
  486. // Lazy test the endianness of the platform
  487. // NOTE: This will be 'true' for simulated TypedArrays
  488. function isLittleEndian() {
  489. var buffer8 = new Uint8Array(2);
  490. buffer8[0] = 1;
  491. var buffer16 = new Uint16Array(buffer8.buffer);
  492. return (buffer16[0] === 1);
  493. }
  494. Object.defineProperty(PDFJS, 'isLittleEndian', {
  495. configurable: true,
  496. get: function PDFJS_isLittleEndian() {
  497. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  498. }
  499. });
  500. // Lazy test if the userAgent support CanvasTypedArrays
  501. function hasCanvasTypedArrays() {
  502. var canvas = document.createElement('canvas');
  503. canvas.width = canvas.height = 1;
  504. var ctx = canvas.getContext('2d');
  505. var imageData = ctx.createImageData(1, 1);
  506. return (typeof imageData.data.buffer !== 'undefined');
  507. }
  508. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  509. configurable: true,
  510. get: function PDFJS_hasCanvasTypedArrays() {
  511. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  512. }
  513. });
  514. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  515. function Uint32ArrayView(buffer, length) {
  516. this.buffer = buffer;
  517. this.byteLength = buffer.length;
  518. this.length = length === undefined ? (this.byteLength >> 2) : length;
  519. ensureUint32ArrayViewProps(this.length);
  520. }
  521. Uint32ArrayView.prototype = Object.create(null);
  522. var uint32ArrayViewSetters = 0;
  523. function createUint32ArrayProp(index) {
  524. return {
  525. get: function () {
  526. var buffer = this.buffer, offset = index << 2;
  527. return (buffer[offset] | (buffer[offset + 1] << 8) |
  528. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  529. },
  530. set: function (value) {
  531. var buffer = this.buffer, offset = index << 2;
  532. buffer[offset] = value & 255;
  533. buffer[offset + 1] = (value >> 8) & 255;
  534. buffer[offset + 2] = (value >> 16) & 255;
  535. buffer[offset + 3] = (value >>> 24) & 255;
  536. }
  537. };
  538. }
  539. function ensureUint32ArrayViewProps(length) {
  540. while (uint32ArrayViewSetters < length) {
  541. Object.defineProperty(Uint32ArrayView.prototype,
  542. uint32ArrayViewSetters,
  543. createUint32ArrayProp(uint32ArrayViewSetters));
  544. uint32ArrayViewSetters++;
  545. }
  546. }
  547. return Uint32ArrayView;
  548. })();
  549. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  550. var Util = PDFJS.Util = (function UtilClosure() {
  551. function Util() {}
  552. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  553. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  554. // creating many intermediate strings.
  555. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  556. rgbBuf[1] = r;
  557. rgbBuf[3] = g;
  558. rgbBuf[5] = b;
  559. return rgbBuf.join('');
  560. };
  561. // Concatenates two transformation matrices together and returns the result.
  562. Util.transform = function Util_transform(m1, m2) {
  563. return [
  564. m1[0] * m2[0] + m1[2] * m2[1],
  565. m1[1] * m2[0] + m1[3] * m2[1],
  566. m1[0] * m2[2] + m1[2] * m2[3],
  567. m1[1] * m2[2] + m1[3] * m2[3],
  568. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  569. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  570. ];
  571. };
  572. // For 2d affine transforms
  573. Util.applyTransform = function Util_applyTransform(p, m) {
  574. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  575. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  576. return [xt, yt];
  577. };
  578. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  579. var d = m[0] * m[3] - m[1] * m[2];
  580. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  581. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  582. return [xt, yt];
  583. };
  584. // Applies the transform to the rectangle and finds the minimum axially
  585. // aligned bounding box.
  586. Util.getAxialAlignedBoundingBox =
  587. function Util_getAxialAlignedBoundingBox(r, m) {
  588. var p1 = Util.applyTransform(r, m);
  589. var p2 = Util.applyTransform(r.slice(2, 4), m);
  590. var p3 = Util.applyTransform([r[0], r[3]], m);
  591. var p4 = Util.applyTransform([r[2], r[1]], m);
  592. return [
  593. Math.min(p1[0], p2[0], p3[0], p4[0]),
  594. Math.min(p1[1], p2[1], p3[1], p4[1]),
  595. Math.max(p1[0], p2[0], p3[0], p4[0]),
  596. Math.max(p1[1], p2[1], p3[1], p4[1])
  597. ];
  598. };
  599. Util.inverseTransform = function Util_inverseTransform(m) {
  600. var d = m[0] * m[3] - m[1] * m[2];
  601. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  602. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  603. };
  604. // Apply a generic 3d matrix M on a 3-vector v:
  605. // | a b c | | X |
  606. // | d e f | x | Y |
  607. // | g h i | | Z |
  608. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  609. // with v as [X,Y,Z]
  610. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  611. return [
  612. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  613. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  614. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  615. ];
  616. };
  617. // This calculation uses Singular Value Decomposition.
  618. // The SVD can be represented with formula A = USV. We are interested in the
  619. // matrix S here because it represents the scale values.
  620. Util.singularValueDecompose2dScale =
  621. function Util_singularValueDecompose2dScale(m) {
  622. var transpose = [m[0], m[2], m[1], m[3]];
  623. // Multiply matrix m with its transpose.
  624. var a = m[0] * transpose[0] + m[1] * transpose[2];
  625. var b = m[0] * transpose[1] + m[1] * transpose[3];
  626. var c = m[2] * transpose[0] + m[3] * transpose[2];
  627. var d = m[2] * transpose[1] + m[3] * transpose[3];
  628. // Solve the second degree polynomial to get roots.
  629. var first = (a + d) / 2;
  630. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  631. var sx = first + second || 1;
  632. var sy = first - second || 1;
  633. // Scale values are the square roots of the eigenvalues.
  634. return [Math.sqrt(sx), Math.sqrt(sy)];
  635. };
  636. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  637. // For coordinate systems whose origin lies in the bottom-left, this
  638. // means normalization to (BL,TR) ordering. For systems with origin in the
  639. // top-left, this means (TL,BR) ordering.
  640. Util.normalizeRect = function Util_normalizeRect(rect) {
  641. var r = rect.slice(0); // clone rect
  642. if (rect[0] > rect[2]) {
  643. r[0] = rect[2];
  644. r[2] = rect[0];
  645. }
  646. if (rect[1] > rect[3]) {
  647. r[1] = rect[3];
  648. r[3] = rect[1];
  649. }
  650. return r;
  651. };
  652. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  653. // intersection of rect1 and rect2. If no intersection, returns 'false'
  654. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  655. Util.intersect = function Util_intersect(rect1, rect2) {
  656. function compare(a, b) {
  657. return a - b;
  658. }
  659. // Order points along the axes
  660. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  661. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  662. result = [];
  663. rect1 = Util.normalizeRect(rect1);
  664. rect2 = Util.normalizeRect(rect2);
  665. // X: first and second points belong to different rectangles?
  666. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  667. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  668. // Intersection must be between second and third points
  669. result[0] = orderedX[1];
  670. result[2] = orderedX[2];
  671. } else {
  672. return false;
  673. }
  674. // Y: first and second points belong to different rectangles?
  675. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  676. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  677. // Intersection must be between second and third points
  678. result[1] = orderedY[1];
  679. result[3] = orderedY[2];
  680. } else {
  681. return false;
  682. }
  683. return result;
  684. };
  685. Util.sign = function Util_sign(num) {
  686. return num < 0 ? -1 : 1;
  687. };
  688. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  689. Array.prototype.push.apply(arr1, arr2);
  690. };
  691. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  692. Array.prototype.unshift.apply(arr1, arr2);
  693. };
  694. Util.extendObj = function extendObj(obj1, obj2) {
  695. for (var key in obj2) {
  696. obj1[key] = obj2[key];
  697. }
  698. };
  699. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  700. name) {
  701. while (dict && !dict.has(name)) {
  702. dict = dict.get('Parent');
  703. }
  704. if (!dict) {
  705. return null;
  706. }
  707. return dict.get(name);
  708. };
  709. Util.inherit = function Util_inherit(sub, base, prototype) {
  710. sub.prototype = Object.create(base.prototype);
  711. sub.prototype.constructor = sub;
  712. for (var prop in prototype) {
  713. sub.prototype[prop] = prototype[prop];
  714. }
  715. };
  716. Util.loadScript = function Util_loadScript(src, callback) {
  717. var script = document.createElement('script');
  718. var loaded = false;
  719. script.setAttribute('src', src);
  720. if (callback) {
  721. script.onload = function() {
  722. if (!loaded) {
  723. callback();
  724. }
  725. loaded = true;
  726. };
  727. }
  728. document.getElementsByTagName('head')[0].appendChild(script);
  729. };
  730. return Util;
  731. })();
  732. /**
  733. * PDF page viewport created based on scale, rotation and offset.
  734. * @class
  735. * @alias PDFJS.PageViewport
  736. */
  737. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  738. /**
  739. * @constructor
  740. * @private
  741. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  742. * @param scale {number} scale of the viewport.
  743. * @param rotation {number} rotations of the viewport in degrees.
  744. * @param offsetX {number} offset X
  745. * @param offsetY {number} offset Y
  746. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  747. */
  748. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  749. this.viewBox = viewBox;
  750. this.scale = scale;
  751. this.rotation = rotation;
  752. this.offsetX = offsetX;
  753. this.offsetY = offsetY;
  754. // creating transform to convert pdf coordinate system to the normal
  755. // canvas like coordinates taking in account scale and rotation
  756. var centerX = (viewBox[2] + viewBox[0]) / 2;
  757. var centerY = (viewBox[3] + viewBox[1]) / 2;
  758. var rotateA, rotateB, rotateC, rotateD;
  759. rotation = rotation % 360;
  760. rotation = rotation < 0 ? rotation + 360 : rotation;
  761. switch (rotation) {
  762. case 180:
  763. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  764. break;
  765. case 90:
  766. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  767. break;
  768. case 270:
  769. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  770. break;
  771. //case 0:
  772. default:
  773. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  774. break;
  775. }
  776. if (dontFlip) {
  777. rotateC = -rotateC; rotateD = -rotateD;
  778. }
  779. var offsetCanvasX, offsetCanvasY;
  780. var width, height;
  781. if (rotateA === 0) {
  782. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  783. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  784. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  785. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  786. } else {
  787. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  788. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  789. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  790. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  791. }
  792. // creating transform for the following operations:
  793. // translate(-centerX, -centerY), rotate and flip vertically,
  794. // scale, and translate(offsetCanvasX, offsetCanvasY)
  795. this.transform = [
  796. rotateA * scale,
  797. rotateB * scale,
  798. rotateC * scale,
  799. rotateD * scale,
  800. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  801. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  802. ];
  803. this.width = width;
  804. this.height = height;
  805. this.fontScale = scale;
  806. }
  807. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  808. /**
  809. * Clones viewport with additional properties.
  810. * @param args {Object} (optional) If specified, may contain the 'scale' or
  811. * 'rotation' properties to override the corresponding properties in
  812. * the cloned viewport.
  813. * @returns {PDFJS.PageViewport} Cloned viewport.
  814. */
  815. clone: function PageViewPort_clone(args) {
  816. args = args || {};
  817. var scale = 'scale' in args ? args.scale : this.scale;
  818. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  819. return new PageViewport(this.viewBox.slice(), scale, rotation,
  820. this.offsetX, this.offsetY, args.dontFlip);
  821. },
  822. /**
  823. * Converts PDF point to the viewport coordinates. For examples, useful for
  824. * converting PDF location into canvas pixel coordinates.
  825. * @param x {number} X coordinate.
  826. * @param y {number} Y coordinate.
  827. * @returns {Object} Object that contains 'x' and 'y' properties of the
  828. * point in the viewport coordinate space.
  829. * @see {@link convertToPdfPoint}
  830. * @see {@link convertToViewportRectangle}
  831. */
  832. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  833. return Util.applyTransform([x, y], this.transform);
  834. },
  835. /**
  836. * Converts PDF rectangle to the viewport coordinates.
  837. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  838. * @returns {Array} Contains corresponding coordinates of the rectangle
  839. * in the viewport coordinate space.
  840. * @see {@link convertToViewportPoint}
  841. */
  842. convertToViewportRectangle:
  843. function PageViewport_convertToViewportRectangle(rect) {
  844. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  845. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  846. return [tl[0], tl[1], br[0], br[1]];
  847. },
  848. /**
  849. * Converts viewport coordinates to the PDF location. For examples, useful
  850. * for converting canvas pixel location into PDF one.
  851. * @param x {number} X coordinate.
  852. * @param y {number} Y coordinate.
  853. * @returns {Object} Object that contains 'x' and 'y' properties of the
  854. * point in the PDF coordinate space.
  855. * @see {@link convertToViewportPoint}
  856. */
  857. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  858. return Util.applyInverseTransform([x, y], this.transform);
  859. }
  860. };
  861. return PageViewport;
  862. })();
  863. var PDFStringTranslateTable = [
  864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  865. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  866. 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,
  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, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  870. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  871. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  872. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  873. ];
  874. function stringToPDFString(str) {
  875. var i, n = str.length, strBuf = [];
  876. if (str[0] === '\xFE' && str[1] === '\xFF') {
  877. // UTF16BE BOM
  878. for (i = 2; i < n; i += 2) {
  879. strBuf.push(String.fromCharCode(
  880. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  881. }
  882. } else {
  883. for (i = 0; i < n; ++i) {
  884. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  885. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  886. }
  887. }
  888. return strBuf.join('');
  889. }
  890. function stringToUTF8String(str) {
  891. return decodeURIComponent(escape(str));
  892. }
  893. function utf8StringToString(str) {
  894. return unescape(encodeURIComponent(str));
  895. }
  896. function isEmptyObj(obj) {
  897. for (var key in obj) {
  898. return false;
  899. }
  900. return true;
  901. }
  902. function isBool(v) {
  903. return typeof v === 'boolean';
  904. }
  905. function isInt(v) {
  906. return typeof v === 'number' && ((v | 0) === v);
  907. }
  908. function isNum(v) {
  909. return typeof v === 'number';
  910. }
  911. function isString(v) {
  912. return typeof v === 'string';
  913. }
  914. function isName(v) {
  915. return v instanceof Name;
  916. }
  917. function isCmd(v, cmd) {
  918. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  919. }
  920. function isDict(v, type) {
  921. if (!(v instanceof Dict)) {
  922. return false;
  923. }
  924. if (!type) {
  925. return true;
  926. }
  927. var dictType = v.get('Type');
  928. return isName(dictType) && dictType.name === type;
  929. }
  930. function isArray(v) {
  931. return v instanceof Array;
  932. }
  933. function isStream(v) {
  934. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  935. }
  936. function isArrayBuffer(v) {
  937. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  938. }
  939. function isRef(v) {
  940. return v instanceof Ref;
  941. }
  942. /**
  943. * Promise Capability object.
  944. *
  945. * @typedef {Object} PromiseCapability
  946. * @property {Promise} promise - A promise object.
  947. * @property {function} resolve - Fullfills the promise.
  948. * @property {function} reject - Rejects the promise.
  949. */
  950. /**
  951. * Creates a promise capability object.
  952. * @alias PDFJS.createPromiseCapability
  953. *
  954. * @return {PromiseCapability} A capability object contains:
  955. * - a Promise, resolve and reject methods.
  956. */
  957. function createPromiseCapability() {
  958. var capability = {};
  959. capability.promise = new Promise(function (resolve, reject) {
  960. capability.resolve = resolve;
  961. capability.reject = reject;
  962. });
  963. return capability;
  964. }
  965. PDFJS.createPromiseCapability = createPromiseCapability;
  966. /**
  967. * Polyfill for Promises:
  968. * The following promise implementation tries to generally implement the
  969. * Promise/A+ spec. Some notable differences from other promise libaries are:
  970. * - There currently isn't a seperate deferred and promise object.
  971. * - Unhandled rejections eventually show an error if they aren't handled.
  972. *
  973. * Based off of the work in:
  974. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  975. */
  976. (function PromiseClosure() {
  977. if (globalScope.Promise) {
  978. // Promises existing in the DOM/Worker, checking presence of all/resolve
  979. if (typeof globalScope.Promise.all !== 'function') {
  980. globalScope.Promise.all = function (iterable) {
  981. var count = 0, results = [], resolve, reject;
  982. var promise = new globalScope.Promise(function (resolve_, reject_) {
  983. resolve = resolve_;
  984. reject = reject_;
  985. });
  986. iterable.forEach(function (p, i) {
  987. count++;
  988. p.then(function (result) {
  989. results[i] = result;
  990. count--;
  991. if (count === 0) {
  992. resolve(results);
  993. }
  994. }, reject);
  995. });
  996. if (count === 0) {
  997. resolve(results);
  998. }
  999. return promise;
  1000. };
  1001. }
  1002. if (typeof globalScope.Promise.resolve !== 'function') {
  1003. globalScope.Promise.resolve = function (value) {
  1004. return new globalScope.Promise(function (resolve) { resolve(value); });
  1005. };
  1006. }
  1007. if (typeof globalScope.Promise.reject !== 'function') {
  1008. globalScope.Promise.reject = function (reason) {
  1009. return new globalScope.Promise(function (resolve, reject) {
  1010. reject(reason);
  1011. });
  1012. };
  1013. }
  1014. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1015. globalScope.Promise.prototype.catch = function (onReject) {
  1016. return globalScope.Promise.prototype.then(undefined, onReject);
  1017. };
  1018. }
  1019. return;
  1020. }
  1021. var STATUS_PENDING = 0;
  1022. var STATUS_RESOLVED = 1;
  1023. var STATUS_REJECTED = 2;
  1024. // In an attempt to avoid silent exceptions, unhandled rejections are
  1025. // tracked and if they aren't handled in a certain amount of time an
  1026. // error is logged.
  1027. var REJECTION_TIMEOUT = 500;
  1028. var HandlerManager = {
  1029. handlers: [],
  1030. running: false,
  1031. unhandledRejections: [],
  1032. pendingRejectionCheck: false,
  1033. scheduleHandlers: function scheduleHandlers(promise) {
  1034. if (promise._status === STATUS_PENDING) {
  1035. return;
  1036. }
  1037. this.handlers = this.handlers.concat(promise._handlers);
  1038. promise._handlers = [];
  1039. if (this.running) {
  1040. return;
  1041. }
  1042. this.running = true;
  1043. setTimeout(this.runHandlers.bind(this), 0);
  1044. },
  1045. runHandlers: function runHandlers() {
  1046. var RUN_TIMEOUT = 1; // ms
  1047. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1048. while (this.handlers.length > 0) {
  1049. var handler = this.handlers.shift();
  1050. var nextStatus = handler.thisPromise._status;
  1051. var nextValue = handler.thisPromise._value;
  1052. try {
  1053. if (nextStatus === STATUS_RESOLVED) {
  1054. if (typeof handler.onResolve === 'function') {
  1055. nextValue = handler.onResolve(nextValue);
  1056. }
  1057. } else if (typeof handler.onReject === 'function') {
  1058. nextValue = handler.onReject(nextValue);
  1059. nextStatus = STATUS_RESOLVED;
  1060. if (handler.thisPromise._unhandledRejection) {
  1061. this.removeUnhandeledRejection(handler.thisPromise);
  1062. }
  1063. }
  1064. } catch (ex) {
  1065. nextStatus = STATUS_REJECTED;
  1066. nextValue = ex;
  1067. }
  1068. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1069. if (Date.now() >= timeoutAt) {
  1070. break;
  1071. }
  1072. }
  1073. if (this.handlers.length > 0) {
  1074. setTimeout(this.runHandlers.bind(this), 0);
  1075. return;
  1076. }
  1077. this.running = false;
  1078. },
  1079. addUnhandledRejection: function addUnhandledRejection(promise) {
  1080. this.unhandledRejections.push({
  1081. promise: promise,
  1082. time: Date.now()
  1083. });
  1084. this.scheduleRejectionCheck();
  1085. },
  1086. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1087. promise._unhandledRejection = false;
  1088. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1089. if (this.unhandledRejections[i].promise === promise) {
  1090. this.unhandledRejections.splice(i);
  1091. i--;
  1092. }
  1093. }
  1094. },
  1095. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1096. if (this.pendingRejectionCheck) {
  1097. return;
  1098. }
  1099. this.pendingRejectionCheck = true;
  1100. setTimeout(function rejectionCheck() {
  1101. this.pendingRejectionCheck = false;
  1102. var now = Date.now();
  1103. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1104. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1105. var unhandled = this.unhandledRejections[i].promise._value;
  1106. var msg = 'Unhandled rejection: ' + unhandled;
  1107. if (unhandled.stack) {
  1108. msg += '\n' + unhandled.stack;
  1109. }
  1110. warn(msg);
  1111. this.unhandledRejections.splice(i);
  1112. i--;
  1113. }
  1114. }
  1115. if (this.unhandledRejections.length) {
  1116. this.scheduleRejectionCheck();
  1117. }
  1118. }.bind(this), REJECTION_TIMEOUT);
  1119. }
  1120. };
  1121. function Promise(resolver) {
  1122. this._status = STATUS_PENDING;
  1123. this._handlers = [];
  1124. try {
  1125. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1126. } catch (e) {
  1127. this._reject(e);
  1128. }
  1129. }
  1130. /**
  1131. * Builds a promise that is resolved when all the passed in promises are
  1132. * resolved.
  1133. * @param {array} array of data and/or promises to wait for.
  1134. * @return {Promise} New dependant promise.
  1135. */
  1136. Promise.all = function Promise_all(promises) {
  1137. var resolveAll, rejectAll;
  1138. var deferred = new Promise(function (resolve, reject) {
  1139. resolveAll = resolve;
  1140. rejectAll = reject;
  1141. });
  1142. var unresolved = promises.length;
  1143. var results = [];
  1144. if (unresolved === 0) {
  1145. resolveAll(results);
  1146. return deferred;
  1147. }
  1148. function reject(reason) {
  1149. if (deferred._status === STATUS_REJECTED) {
  1150. return;
  1151. }
  1152. results = [];
  1153. rejectAll(reason);
  1154. }
  1155. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1156. var promise = promises[i];
  1157. var resolve = (function(i) {
  1158. return function(value) {
  1159. if (deferred._status === STATUS_REJECTED) {
  1160. return;
  1161. }
  1162. results[i] = value;
  1163. unresolved--;
  1164. if (unresolved === 0) {
  1165. resolveAll(results);
  1166. }
  1167. };
  1168. })(i);
  1169. if (Promise.isPromise(promise)) {
  1170. promise.then(resolve, reject);
  1171. } else {
  1172. resolve(promise);
  1173. }
  1174. }
  1175. return deferred;
  1176. };
  1177. /**
  1178. * Checks if the value is likely a promise (has a 'then' function).
  1179. * @return {boolean} true if value is thenable
  1180. */
  1181. Promise.isPromise = function Promise_isPromise(value) {
  1182. return value && typeof value.then === 'function';
  1183. };
  1184. /**
  1185. * Creates resolved promise
  1186. * @param value resolve value
  1187. * @returns {Promise}
  1188. */
  1189. Promise.resolve = function Promise_resolve(value) {
  1190. return new Promise(function (resolve) { resolve(value); });
  1191. };
  1192. /**
  1193. * Creates rejected promise
  1194. * @param reason rejection value
  1195. * @returns {Promise}
  1196. */
  1197. Promise.reject = function Promise_reject(reason) {
  1198. return new Promise(function (resolve, reject) { reject(reason); });
  1199. };
  1200. Promise.prototype = {
  1201. _status: null,
  1202. _value: null,
  1203. _handlers: null,
  1204. _unhandledRejection: null,
  1205. _updateStatus: function Promise__updateStatus(status, value) {
  1206. if (this._status === STATUS_RESOLVED ||
  1207. this._status === STATUS_REJECTED) {
  1208. return;
  1209. }
  1210. if (status === STATUS_RESOLVED &&
  1211. Promise.isPromise(value)) {
  1212. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1213. this._updateStatus.bind(this, STATUS_REJECTED));
  1214. return;
  1215. }
  1216. this._status = status;
  1217. this._value = value;
  1218. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1219. this._unhandledRejection = true;
  1220. HandlerManager.addUnhandledRejection(this);
  1221. }
  1222. HandlerManager.scheduleHandlers(this);
  1223. },
  1224. _resolve: function Promise_resolve(value) {
  1225. this._updateStatus(STATUS_RESOLVED, value);
  1226. },
  1227. _reject: function Promise_reject(reason) {
  1228. this._updateStatus(STATUS_REJECTED, reason);
  1229. },
  1230. then: function Promise_then(onResolve, onReject) {
  1231. var nextPromise = new Promise(function (resolve, reject) {
  1232. this.resolve = resolve;
  1233. this.reject = reject;
  1234. });
  1235. this._handlers.push({
  1236. thisPromise: this,
  1237. onResolve: onResolve,
  1238. onReject: onReject,
  1239. nextPromise: nextPromise
  1240. });
  1241. HandlerManager.scheduleHandlers(this);
  1242. return nextPromise;
  1243. },
  1244. catch: function Promise_catch(onReject) {
  1245. return this.then(undefined, onReject);
  1246. }
  1247. };
  1248. globalScope.Promise = Promise;
  1249. })();
  1250. var StatTimer = (function StatTimerClosure() {
  1251. function rpad(str, pad, length) {
  1252. while (str.length < length) {
  1253. str += pad;
  1254. }
  1255. return str;
  1256. }
  1257. function StatTimer() {
  1258. this.started = {};
  1259. this.times = [];
  1260. this.enabled = true;
  1261. }
  1262. StatTimer.prototype = {
  1263. time: function StatTimer_time(name) {
  1264. if (!this.enabled) {
  1265. return;
  1266. }
  1267. if (name in this.started) {
  1268. warn('Timer is already running for ' + name);
  1269. }
  1270. this.started[name] = Date.now();
  1271. },
  1272. timeEnd: function StatTimer_timeEnd(name) {
  1273. if (!this.enabled) {
  1274. return;
  1275. }
  1276. if (!(name in this.started)) {
  1277. warn('Timer has not been started for ' + name);
  1278. }
  1279. this.times.push({
  1280. 'name': name,
  1281. 'start': this.started[name],
  1282. 'end': Date.now()
  1283. });
  1284. // Remove timer from started so it can be called again.
  1285. delete this.started[name];
  1286. },
  1287. toString: function StatTimer_toString() {
  1288. var i, ii;
  1289. var times = this.times;
  1290. var out = '';
  1291. // Find the longest name for padding purposes.
  1292. var longest = 0;
  1293. for (i = 0, ii = times.length; i < ii; ++i) {
  1294. var name = times[i]['name'];
  1295. if (name.length > longest) {
  1296. longest = name.length;
  1297. }
  1298. }
  1299. for (i = 0, ii = times.length; i < ii; ++i) {
  1300. var span = times[i];
  1301. var duration = span.end - span.start;
  1302. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1303. }
  1304. return out;
  1305. }
  1306. };
  1307. return StatTimer;
  1308. })();
  1309. PDFJS.createBlob = function createBlob(data, contentType) {
  1310. if (typeof Blob !== 'undefined') {
  1311. return new Blob([data], { type: contentType });
  1312. }
  1313. // Blob builder is deprecated in FF14 and removed in FF18.
  1314. var bb = new MozBlobBuilder();
  1315. bb.append(data);
  1316. return bb.getBlob(contentType);
  1317. };
  1318. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1319. // Blob/createObjectURL is not available, falling back to data schema.
  1320. var digits =
  1321. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1322. return function createObjectURL(data, contentType) {
  1323. if (!PDFJS.disableCreateObjectURL &&
  1324. typeof URL !== 'undefined' && URL.createObjectURL) {
  1325. var blob = PDFJS.createBlob(data, contentType);
  1326. return URL.createObjectURL(blob);
  1327. }
  1328. var buffer = 'data:' + contentType + ';base64,';
  1329. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1330. var b1 = data[i] & 0xFF;
  1331. var b2 = data[i + 1] & 0xFF;
  1332. var b3 = data[i + 2] & 0xFF;
  1333. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1334. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1335. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1336. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1337. }
  1338. return buffer;
  1339. };
  1340. })();
  1341. function MessageHandler(sourceName, targetName, comObj) {
  1342. this.sourceName = sourceName;
  1343. this.targetName = targetName;
  1344. this.comObj = comObj;
  1345. this.callbackIndex = 1;
  1346. this.postMessageTransfers = true;
  1347. var callbacksCapabilities = this.callbacksCapabilities = {};
  1348. var ah = this.actionHandler = {};
  1349. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1350. var data = event.data;
  1351. if (data.targetName !== this.sourceName) {
  1352. return;
  1353. }
  1354. if (data.isReply) {
  1355. var callbackId = data.callbackId;
  1356. if (data.callbackId in callbacksCapabilities) {
  1357. var callback = callbacksCapabilities[callbackId];
  1358. delete callbacksCapabilities[callbackId];
  1359. if ('error' in data) {
  1360. callback.reject(data.error);
  1361. } else {
  1362. callback.resolve(data.data);
  1363. }
  1364. } else {
  1365. error('Cannot resolve callback ' + callbackId);
  1366. }
  1367. } else if (data.action in ah) {
  1368. var action = ah[data.action];
  1369. if (data.callbackId) {
  1370. var sourceName = this.sourceName;
  1371. var targetName = data.sourceName;
  1372. Promise.resolve().then(function () {
  1373. return action[0].call(action[1], data.data);
  1374. }).then(function (result) {
  1375. comObj.postMessage({
  1376. sourceName: sourceName,
  1377. targetName: targetName,
  1378. isReply: true,
  1379. callbackId: data.callbackId,
  1380. data: result
  1381. });
  1382. }, function (reason) {
  1383. if (reason instanceof Error) {
  1384. // Serialize error to avoid "DataCloneError"
  1385. reason = reason + '';
  1386. }
  1387. comObj.postMessage({
  1388. sourceName: sourceName,
  1389. targetName: targetName,
  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. }.bind(this);
  1402. comObj.addEventListener('message', this._onComObjOnMessage);
  1403. }
  1404. MessageHandler.prototype = {
  1405. on: function messageHandlerOn(actionName, handler, scope) {
  1406. var ah = this.actionHandler;
  1407. if (ah[actionName]) {
  1408. error('There is already an actionName called "' + actionName + '"');
  1409. }
  1410. ah[actionName] = [handler, scope];
  1411. },
  1412. /**
  1413. * Sends a message to the comObj to invoke the action with the supplied data.
  1414. * @param {String} actionName Action to call.
  1415. * @param {JSON} data JSON data to send.
  1416. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1417. */
  1418. send: function messageHandlerSend(actionName, data, transfers) {
  1419. var message = {
  1420. sourceName: this.sourceName,
  1421. targetName: this.targetName,
  1422. action: actionName,
  1423. data: data
  1424. };
  1425. this.postMessage(message, transfers);
  1426. },
  1427. /**
  1428. * Sends a message to the comObj to invoke the action with the supplied data.
  1429. * Expects that other side will callback with the response.
  1430. * @param {String} actionName Action to call.
  1431. * @param {JSON} data JSON data to send.
  1432. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1433. * @returns {Promise} Promise to be resolved with response data.
  1434. */
  1435. sendWithPromise:
  1436. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1437. var callbackId = this.callbackIndex++;
  1438. var message = {
  1439. sourceName: this.sourceName,
  1440. targetName: this.targetName,
  1441. action: actionName,
  1442. data: data,
  1443. callbackId: callbackId
  1444. };
  1445. var capability = createPromiseCapability();
  1446. this.callbacksCapabilities[callbackId] = capability;
  1447. try {
  1448. this.postMessage(message, transfers);
  1449. } catch (e) {
  1450. capability.reject(e);
  1451. }
  1452. return capability.promise;
  1453. },
  1454. /**
  1455. * Sends raw message to the comObj.
  1456. * @private
  1457. * @param message {Object} Raw message.
  1458. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1459. */
  1460. postMessage: function (message, transfers) {
  1461. if (transfers && this.postMessageTransfers) {
  1462. this.comObj.postMessage(message, transfers);
  1463. } else {
  1464. this.comObj.postMessage(message);
  1465. }
  1466. },
  1467. destroy: function () {
  1468. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1469. }
  1470. };
  1471. function loadJpegStream(id, imageUrl, objs) {
  1472. var img = new Image();
  1473. img.onload = (function loadJpegStream_onloadClosure() {
  1474. objs.resolve(id, img);
  1475. });
  1476. img.onerror = (function loadJpegStream_onerrorClosure() {
  1477. objs.resolve(id, null);
  1478. warn('Error during JPEG image loading');
  1479. });
  1480. img.src = imageUrl;
  1481. }
  1482. // Polyfill from https://github.com/Polymer/URL
  1483. /* Any copyright is dedicated to the Public Domain.
  1484. * http://creativecommons.org/publicdomain/zero/1.0/ */
  1485. (function checkURLConstructor(scope) {
  1486. /* jshint ignore:start */
  1487. // feature detect for URL constructor
  1488. var hasWorkingUrl = false;
  1489. if (typeof URL === 'function' && ('origin' in URL.prototype)) {
  1490. try {
  1491. var u = new URL('b', 'http://a');
  1492. u.pathname = 'c%20d';
  1493. hasWorkingUrl = u.href === 'http://a/c%20d';
  1494. } catch(e) {}
  1495. }
  1496. if (hasWorkingUrl)
  1497. return;
  1498. var relative = Object.create(null);
  1499. relative['ftp'] = 21;
  1500. relative['file'] = 0;
  1501. relative['gopher'] = 70;
  1502. relative['http'] = 80;
  1503. relative['https'] = 443;
  1504. relative['ws'] = 80;
  1505. relative['wss'] = 443;
  1506. var relativePathDotMapping = Object.create(null);
  1507. relativePathDotMapping['%2e'] = '.';
  1508. relativePathDotMapping['.%2e'] = '..';
  1509. relativePathDotMapping['%2e.'] = '..';
  1510. relativePathDotMapping['%2e%2e'] = '..';
  1511. function isRelativeScheme(scheme) {
  1512. return relative[scheme] !== undefined;
  1513. }
  1514. function invalid() {
  1515. clear.call(this);
  1516. this._isInvalid = true;
  1517. }
  1518. function IDNAToASCII(h) {
  1519. if ('' == h) {
  1520. invalid.call(this)
  1521. }
  1522. // XXX
  1523. return h.toLowerCase()
  1524. }
  1525. function percentEscape(c) {
  1526. var unicode = c.charCodeAt(0);
  1527. if (unicode > 0x20 &&
  1528. unicode < 0x7F &&
  1529. // " # < > ? `
  1530. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  1531. ) {
  1532. return c;
  1533. }
  1534. return encodeURIComponent(c);
  1535. }
  1536. function percentEscapeQuery(c) {
  1537. // XXX This actually needs to encode c using encoding and then
  1538. // convert the bytes one-by-one.
  1539. var unicode = c.charCodeAt(0);
  1540. if (unicode > 0x20 &&
  1541. unicode < 0x7F &&
  1542. // " # < > ` (do not escape '?')
  1543. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  1544. ) {
  1545. return c;
  1546. }
  1547. return encodeURIComponent(c);
  1548. }
  1549. var EOF = undefined,
  1550. ALPHA = /[a-zA-Z]/,
  1551. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  1552. function parse(input, stateOverride, base) {
  1553. function err(message) {
  1554. errors.push(message)
  1555. }
  1556. var state = stateOverride || 'scheme start',
  1557. cursor = 0,
  1558. buffer = '',
  1559. seenAt = false,
  1560. seenBracket = false,
  1561. errors = [];
  1562. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  1563. var c = input[cursor];
  1564. switch (state) {
  1565. case 'scheme start':
  1566. if (c && ALPHA.test(c)) {
  1567. buffer += c.toLowerCase(); // ASCII-safe
  1568. state = 'scheme';
  1569. } else if (!stateOverride) {
  1570. buffer = '';
  1571. state = 'no scheme';
  1572. continue;
  1573. } else {
  1574. err('Invalid scheme.');
  1575. break loop;
  1576. }
  1577. break;
  1578. case 'scheme':
  1579. if (c && ALPHANUMERIC.test(c)) {
  1580. buffer += c.toLowerCase(); // ASCII-safe
  1581. } else if (':' == c) {
  1582. this._scheme = buffer;
  1583. buffer = '';
  1584. if (stateOverride) {
  1585. break loop;
  1586. }
  1587. if (isRelativeScheme(this._scheme)) {
  1588. this._isRelative = true;
  1589. }
  1590. if ('file' == this._scheme) {
  1591. state = 'relative';
  1592. } else if (this._isRelative && base && base._scheme == this._scheme) {
  1593. state = 'relative or authority';
  1594. } else if (this._isRelative) {
  1595. state = 'authority first slash';
  1596. } else {
  1597. state = 'scheme data';
  1598. }
  1599. } else if (!stateOverride) {
  1600. buffer = '';
  1601. cursor = 0;
  1602. state = 'no scheme';
  1603. continue;
  1604. } else if (EOF == c) {
  1605. break loop;
  1606. } else {
  1607. err('Code point not allowed in scheme: ' + c)
  1608. break loop;
  1609. }
  1610. break;
  1611. case 'scheme data':
  1612. if ('?' == c) {
  1613. this._query = '?';
  1614. state = 'query';
  1615. } else if ('#' == c) {
  1616. this._fragment = '#';
  1617. state = 'fragment';
  1618. } else {
  1619. // XXX error handling
  1620. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  1621. this._schemeData += percentEscape(c);
  1622. }
  1623. }
  1624. break;
  1625. case 'no scheme':
  1626. if (!base || !(isRelativeScheme(base._scheme))) {
  1627. err('Missing scheme.');
  1628. invalid.call(this);
  1629. } else {
  1630. state = 'relative';
  1631. continue;
  1632. }
  1633. break;
  1634. case 'relative or authority':
  1635. if ('/' == c && '/' == input[cursor+1]) {
  1636. state = 'authority ignore slashes';
  1637. } else {
  1638. err('Expected /, got: ' + c);
  1639. state = 'relative';
  1640. continue
  1641. }
  1642. break;
  1643. case 'relative':
  1644. this._isRelative = true;
  1645. if ('file' != this._scheme)
  1646. this._scheme = base._scheme;
  1647. if (EOF == c) {
  1648. this._host = base._host;
  1649. this._port = base._port;
  1650. this._path = base._path.slice();
  1651. this._query = base._query;
  1652. this._username = base._username;
  1653. this._password = base._password;
  1654. break loop;
  1655. } else if ('/' == c || '\\' == c) {
  1656. if ('\\' == c)
  1657. err('\\ is an invalid code point.');
  1658. state = 'relative slash';
  1659. } else if ('?' == c) {
  1660. this._host = base._host;
  1661. this._port = base._port;
  1662. this._path = base._path.slice();
  1663. this._query = '?';
  1664. this._username = base._username;
  1665. this._password = base._password;
  1666. state = 'query';
  1667. } else if ('#' == c) {
  1668. this._host = base._host;
  1669. this._port = base._port;
  1670. this._path = base._path.slice();
  1671. this._query = base._query;
  1672. this._fragment = '#';
  1673. this._username = base._username;
  1674. this._password = base._password;
  1675. state = 'fragment';
  1676. } else {
  1677. var nextC = input[cursor+1]
  1678. var nextNextC = input[cursor+2]
  1679. if (
  1680. 'file' != this._scheme || !ALPHA.test(c) ||
  1681. (nextC != ':' && nextC != '|') ||
  1682. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  1683. this._host = base._host;
  1684. this._port = base._port;
  1685. this._username = base._username;
  1686. this._password = base._password;
  1687. this._path = base._path.slice();
  1688. this._path.pop();
  1689. }
  1690. state = 'relative path';
  1691. continue;
  1692. }
  1693. break;
  1694. case 'relative slash':
  1695. if ('/' == c || '\\' == c) {
  1696. if ('\\' == c) {
  1697. err('\\ is an invalid code point.');
  1698. }
  1699. if ('file' == this._scheme) {
  1700. state = 'file host';
  1701. } else {
  1702. state = 'authority ignore slashes';
  1703. }
  1704. } else {
  1705. if ('file' != this._scheme) {
  1706. this._host = base._host;
  1707. this._port = base._port;
  1708. this._username = base._username;
  1709. this._password = base._password;
  1710. }
  1711. state = 'relative path';
  1712. continue;
  1713. }
  1714. break;
  1715. case 'authority first slash':
  1716. if ('/' == c) {
  1717. state = 'authority second slash';
  1718. } else {
  1719. err("Expected '/', got: " + c);
  1720. state = 'authority ignore slashes';
  1721. continue;
  1722. }
  1723. break;
  1724. case 'authority second slash':
  1725. state = 'authority ignore slashes';
  1726. if ('/' != c) {
  1727. err("Expected '/', got: " + c);
  1728. continue;
  1729. }
  1730. break;
  1731. case 'authority ignore slashes':
  1732. if ('/' != c && '\\' != c) {
  1733. state = 'authority';
  1734. continue;
  1735. } else {
  1736. err('Expected authority, got: ' + c);
  1737. }
  1738. break;
  1739. case 'authority':
  1740. if ('@' == c) {
  1741. if (seenAt) {
  1742. err('@ already seen.');
  1743. buffer += '%40';
  1744. }
  1745. seenAt = true;
  1746. for (var i = 0; i < buffer.length; i++) {
  1747. var cp = buffer[i];
  1748. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  1749. err('Invalid whitespace in authority.');
  1750. continue;
  1751. }
  1752. // XXX check URL code points
  1753. if (':' == cp && null === this._password) {
  1754. this._password = '';
  1755. continue;
  1756. }
  1757. var tempC = percentEscape(cp);
  1758. (null !== this._password) ? this._password += tempC : this._username += tempC;
  1759. }
  1760. buffer = '';
  1761. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  1762. cursor -= buffer.length;
  1763. buffer = '';
  1764. state = 'host';
  1765. continue;
  1766. } else {
  1767. buffer += c;
  1768. }
  1769. break;
  1770. case 'file host':
  1771. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  1772. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  1773. state = 'relative path';
  1774. } else if (buffer.length == 0) {
  1775. state = 'relative path start';
  1776. } else {
  1777. this._host = IDNAToASCII.call(this, buffer);
  1778. buffer = '';
  1779. state = 'relative path start';
  1780. }
  1781. continue;
  1782. } else if ('\t' == c || '\n' == c || '\r' == c) {
  1783. err('Invalid whitespace in file host.');
  1784. } else {
  1785. buffer += c;
  1786. }
  1787. break;
  1788. case 'host':
  1789. case 'hostname':
  1790. if (':' == c && !seenBracket) {
  1791. // XXX host parsing
  1792. this._host = IDNAToASCII.call(this, buffer);
  1793. buffer = '';
  1794. state = 'port';
  1795. if ('hostname' == stateOverride) {
  1796. break loop;
  1797. }
  1798. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  1799. this._host = IDNAToASCII.call(this, buffer);
  1800. buffer = '';
  1801. state = 'relative path start';
  1802. if (stateOverride) {
  1803. break loop;
  1804. }
  1805. continue;
  1806. } else if ('\t' != c && '\n' != c && '\r' != c) {
  1807. if ('[' == c) {
  1808. seenBracket = true;
  1809. } else if (']' == c) {
  1810. seenBracket = false;
  1811. }
  1812. buffer += c;
  1813. } else {
  1814. err('Invalid code point in host/hostname: ' + c);
  1815. }
  1816. break;
  1817. case 'port':
  1818. if (/[0-9]/.test(c)) {
  1819. buffer += c;
  1820. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  1821. if ('' != buffer) {
  1822. var temp = parseInt(buffer, 10);
  1823. if (temp != relative[this._scheme]) {
  1824. this._port = temp + '';
  1825. }
  1826. buffer = '';
  1827. }
  1828. if (stateOverride) {
  1829. break loop;
  1830. }
  1831. state = 'relative path start';
  1832. continue;
  1833. } else if ('\t' == c || '\n' == c || '\r' == c) {
  1834. err('Invalid code point in port: ' + c);
  1835. } else {
  1836. invalid.call(this);
  1837. }
  1838. break;
  1839. case 'relative path start':
  1840. if ('\\' == c)
  1841. err("'\\' not allowed in path.");
  1842. state = 'relative path';
  1843. if ('/' != c && '\\' != c) {
  1844. continue;
  1845. }
  1846. break;
  1847. case 'relative path':
  1848. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  1849. if ('\\' == c) {
  1850. err('\\ not allowed in relative path.');
  1851. }
  1852. var tmp;
  1853. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  1854. buffer = tmp;
  1855. }
  1856. if ('..' == buffer) {
  1857. this._path.pop();
  1858. if ('/' != c && '\\' != c) {
  1859. this._path.push('');
  1860. }
  1861. } else if ('.' == buffer && '/' != c && '\\' != c) {
  1862. this._path.push('');
  1863. } else if ('.' != buffer) {
  1864. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  1865. buffer = buffer[0] + ':';
  1866. }
  1867. this._path.push(buffer);
  1868. }
  1869. buffer = '';
  1870. if ('?' == c) {
  1871. this._query = '?';
  1872. state = 'query';
  1873. } else if ('#' == c) {
  1874. this._fragment = '#';
  1875. state = 'fragment';
  1876. }
  1877. } else if ('\t' != c && '\n' != c && '\r' != c) {
  1878. buffer += percentEscape(c);
  1879. }
  1880. break;
  1881. case 'query':
  1882. if (!stateOverride && '#' == c) {
  1883. this._fragment = '#';
  1884. state = 'fragment';
  1885. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  1886. this._query += percentEscapeQuery(c);
  1887. }
  1888. break;
  1889. case 'fragment':
  1890. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  1891. this._fragment += c;
  1892. }
  1893. break;
  1894. }
  1895. cursor++;
  1896. }
  1897. }
  1898. function clear() {
  1899. this._scheme = '';
  1900. this._schemeData = '';
  1901. this._username = '';
  1902. this._password = null;
  1903. this._host = '';
  1904. this._port = '';
  1905. this._path = [];
  1906. this._query = '';
  1907. this._fragment = '';
  1908. this._isInvalid = false;
  1909. this._isRelative = false;
  1910. }
  1911. // Does not process domain names or IP addresses.
  1912. // Does not handle encoding for the query parameter.
  1913. function jURL(url, base /* , encoding */) {
  1914. if (base !== undefined && !(base instanceof jURL))
  1915. base = new jURL(String(base));
  1916. this._url = url;
  1917. clear.call(this);
  1918. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  1919. // encoding = encoding || 'utf-8'
  1920. parse.call(this, input, null, base);
  1921. }
  1922. jURL.prototype = {
  1923. toString: function() {
  1924. return this.href;
  1925. },
  1926. get href() {
  1927. if (this._isInvalid)
  1928. return this._url;
  1929. var authority = '';
  1930. if ('' != this._username || null != this._password) {
  1931. authority = this._username +
  1932. (null != this._password ? ':' + this._password : '') + '@';
  1933. }
  1934. return this.protocol +
  1935. (this._isRelative ? '//' + authority + this.host : '') +
  1936. this.pathname + this._query + this._fragment;
  1937. },
  1938. set href(href) {
  1939. clear.call(this);
  1940. parse.call(this, href);
  1941. },
  1942. get protocol() {
  1943. return this._scheme + ':';
  1944. },
  1945. set protocol(protocol) {
  1946. if (this._isInvalid)
  1947. return;
  1948. parse.call(this, protocol + ':', 'scheme start');
  1949. },
  1950. get host() {
  1951. return this._isInvalid ? '' : this._port ?
  1952. this._host + ':' + this._port : this._host;
  1953. },
  1954. set host(host) {
  1955. if (this._isInvalid || !this._isRelative)
  1956. return;
  1957. parse.call(this, host, 'host');
  1958. },
  1959. get hostname() {
  1960. return this._host;
  1961. },
  1962. set hostname(hostname) {
  1963. if (this._isInvalid || !this._isRelative)
  1964. return;
  1965. parse.call(this, hostname, 'hostname');
  1966. },
  1967. get port() {
  1968. return this._port;
  1969. },
  1970. set port(port) {
  1971. if (this._isInvalid || !this._isRelative)
  1972. return;
  1973. parse.call(this, port, 'port');
  1974. },
  1975. get pathname() {
  1976. return this._isInvalid ? '' : this._isRelative ?
  1977. '/' + this._path.join('/') : this._schemeData;
  1978. },
  1979. set pathname(pathname) {
  1980. if (this._isInvalid || !this._isRelative)
  1981. return;
  1982. this._path = [];
  1983. parse.call(this, pathname, 'relative path start');
  1984. },
  1985. get search() {
  1986. return this._isInvalid || !this._query || '?' == this._query ?
  1987. '' : this._query;
  1988. },
  1989. set search(search) {
  1990. if (this._isInvalid || !this._isRelative)
  1991. return;
  1992. this._query = '?';
  1993. if ('?' == search[0])
  1994. search = search.slice(1);
  1995. parse.call(this, search, 'query');
  1996. },
  1997. get hash() {
  1998. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  1999. '' : this._fragment;
  2000. },
  2001. set hash(hash) {
  2002. if (this._isInvalid)
  2003. return;
  2004. this._fragment = '#';
  2005. if ('#' == hash[0])
  2006. hash = hash.slice(1);
  2007. parse.call(this, hash, 'fragment');
  2008. },
  2009. get origin() {
  2010. var host;
  2011. if (this._isInvalid || !this._scheme) {
  2012. return '';
  2013. }
  2014. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  2015. // Gecko throws error for "data://"
  2016. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  2017. // Gecko returns String("") for file: mailto:
  2018. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  2019. switch (this._scheme) {
  2020. case 'data':
  2021. case 'file':
  2022. case 'javascript':
  2023. case 'mailto':
  2024. return 'null';
  2025. }
  2026. host = this.host;
  2027. if (!host) {
  2028. return '';
  2029. }
  2030. return this._scheme + '://' + host;
  2031. }
  2032. };
  2033. // Copy over the static methods
  2034. var OriginalURL = scope.URL;
  2035. if (OriginalURL) {
  2036. jURL.createObjectURL = function(blob) {
  2037. // IE extension allows a second optional options argument.
  2038. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  2039. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  2040. };
  2041. jURL.revokeObjectURL = function(url) {
  2042. OriginalURL.revokeObjectURL(url);
  2043. };
  2044. }
  2045. scope.URL = jURL;
  2046. /* jshint ignore:end */
  2047. })(globalScope);
  2048. var NetworkManager = (function NetworkManagerClosure() {
  2049. var OK_RESPONSE = 200;
  2050. var PARTIAL_CONTENT_RESPONSE = 206;
  2051. function NetworkManager(url, args) {
  2052. this.url = url;
  2053. args = args || {};
  2054. this.isHttp = /^https?:/i.test(url);
  2055. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  2056. this.withCredentials = args.withCredentials || false;
  2057. this.getXhr = args.getXhr ||
  2058. function NetworkManager_getXhr() {
  2059. return new XMLHttpRequest();
  2060. };
  2061. this.currXhrId = 0;
  2062. this.pendingRequests = {};
  2063. this.loadedRequests = {};
  2064. }
  2065. function getArrayBuffer(xhr) {
  2066. var data = xhr.response;
  2067. if (typeof data !== 'string') {
  2068. return data;
  2069. }
  2070. var length = data.length;
  2071. var array = new Uint8Array(length);
  2072. for (var i = 0; i < length; i++) {
  2073. array[i] = data.charCodeAt(i) & 0xFF;
  2074. }
  2075. return array.buffer;
  2076. }
  2077. var supportsMozChunked = (function supportsMozChunkedClosure() {
  2078. try {
  2079. var x = new XMLHttpRequest();
  2080. // Firefox 37- required .open() to be called before setting responseType.
  2081. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  2082. // Even though the URL is not visited, .open() could fail if the URL is
  2083. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  2084. // When this error occurs, this feature detection method will mistakenly
  2085. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  2086. x.open('GET', 'https://example.com');
  2087. x.responseType = 'moz-chunked-arraybuffer';
  2088. return x.responseType === 'moz-chunked-arraybuffer';
  2089. } catch (e) {
  2090. return false;
  2091. }
  2092. })();
  2093. NetworkManager.prototype = {
  2094. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  2095. var args = {
  2096. begin: begin,
  2097. end: end
  2098. };
  2099. for (var prop in listeners) {
  2100. args[prop] = listeners[prop];
  2101. }
  2102. return this.request(args);
  2103. },
  2104. requestFull: function NetworkManager_requestFull(listeners) {
  2105. return this.request(listeners);
  2106. },
  2107. request: function NetworkManager_request(args) {
  2108. var xhr = this.getXhr();
  2109. var xhrId = this.currXhrId++;
  2110. var pendingRequest = this.pendingRequests[xhrId] = {
  2111. xhr: xhr
  2112. };
  2113. xhr.open('GET', this.url);
  2114. xhr.withCredentials = this.withCredentials;
  2115. for (var property in this.httpHeaders) {
  2116. var value = this.httpHeaders[property];
  2117. if (typeof value === 'undefined') {
  2118. continue;
  2119. }
  2120. xhr.setRequestHeader(property, value);
  2121. }
  2122. if (this.isHttp && 'begin' in args && 'end' in args) {
  2123. var rangeStr = args.begin + '-' + (args.end - 1);
  2124. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  2125. pendingRequest.expectedStatus = 206;
  2126. } else {
  2127. pendingRequest.expectedStatus = 200;
  2128. }
  2129. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  2130. if (useMozChunkedLoading) {
  2131. xhr.responseType = 'moz-chunked-arraybuffer';
  2132. pendingRequest.onProgressiveData = args.onProgressiveData;
  2133. pendingRequest.mozChunked = true;
  2134. } else {
  2135. xhr.responseType = 'arraybuffer';
  2136. }
  2137. if (args.onError) {
  2138. xhr.onerror = function(evt) {
  2139. args.onError(xhr.status);
  2140. };
  2141. }
  2142. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  2143. xhr.onprogress = this.onProgress.bind(this, xhrId);
  2144. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  2145. pendingRequest.onDone = args.onDone;
  2146. pendingRequest.onError = args.onError;
  2147. pendingRequest.onProgress = args.onProgress;
  2148. xhr.send(null);
  2149. return xhrId;
  2150. },
  2151. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  2152. var pendingRequest = this.pendingRequests[xhrId];
  2153. if (!pendingRequest) {
  2154. // Maybe abortRequest was called...
  2155. return;
  2156. }
  2157. if (pendingRequest.mozChunked) {
  2158. var chunk = getArrayBuffer(pendingRequest.xhr);
  2159. pendingRequest.onProgressiveData(chunk);
  2160. }
  2161. var onProgress = pendingRequest.onProgress;
  2162. if (onProgress) {
  2163. onProgress(evt);
  2164. }
  2165. },
  2166. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  2167. var pendingRequest = this.pendingRequests[xhrId];
  2168. if (!pendingRequest) {
  2169. // Maybe abortRequest was called...
  2170. return;
  2171. }
  2172. var xhr = pendingRequest.xhr;
  2173. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  2174. pendingRequest.onHeadersReceived();
  2175. delete pendingRequest.onHeadersReceived;
  2176. }
  2177. if (xhr.readyState !== 4) {
  2178. return;
  2179. }
  2180. if (!(xhrId in this.pendingRequests)) {
  2181. // The XHR request might have been aborted in onHeadersReceived()
  2182. // callback, in which case we should abort request
  2183. return;
  2184. }
  2185. delete this.pendingRequests[xhrId];
  2186. // success status == 0 can be on ftp, file and other protocols
  2187. if (xhr.status === 0 && this.isHttp) {
  2188. if (pendingRequest.onError) {
  2189. pendingRequest.onError(xhr.status);
  2190. }
  2191. return;
  2192. }
  2193. var xhrStatus = xhr.status || OK_RESPONSE;
  2194. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  2195. // "A server MAY ignore the Range header". This means it's possible to
  2196. // get a 200 rather than a 206 response from a range request.
  2197. var ok_response_on_range_request =
  2198. xhrStatus === OK_RESPONSE &&
  2199. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  2200. if (!ok_response_on_range_request &&
  2201. xhrStatus !== pendingRequest.expectedStatus) {
  2202. if (pendingRequest.onError) {
  2203. pendingRequest.onError(xhr.status);
  2204. }
  2205. return;
  2206. }
  2207. this.loadedRequests[xhrId] = true;
  2208. var chunk = getArrayBuffer(xhr);
  2209. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  2210. var rangeHeader = xhr.getResponseHeader('Content-Range');
  2211. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  2212. var begin = parseInt(matches[1], 10);
  2213. pendingRequest.onDone({
  2214. begin: begin,
  2215. chunk: chunk
  2216. });
  2217. } else if (pendingRequest.onProgressiveData) {
  2218. pendingRequest.onDone(null);
  2219. } else if (chunk) {
  2220. pendingRequest.onDone({
  2221. begin: 0,
  2222. chunk: chunk
  2223. });
  2224. } else if (pendingRequest.onError) {
  2225. pendingRequest.onError(xhr.status);
  2226. }
  2227. },
  2228. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  2229. for (var xhrId in this.pendingRequests) {
  2230. return true;
  2231. }
  2232. return false;
  2233. },
  2234. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  2235. return this.pendingRequests[xhrId].xhr;
  2236. },
  2237. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  2238. return !!(this.pendingRequests[xhrId].onProgressiveData);
  2239. },
  2240. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  2241. return xhrId in this.pendingRequests;
  2242. },
  2243. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  2244. return xhrId in this.loadedRequests;
  2245. },
  2246. abortAllRequests: function NetworkManager_abortAllRequests() {
  2247. for (var xhrId in this.pendingRequests) {
  2248. this.abortRequest(xhrId | 0);
  2249. }
  2250. },
  2251. abortRequest: function NetworkManager_abortRequest(xhrId) {
  2252. var xhr = this.pendingRequests[xhrId].xhr;
  2253. delete this.pendingRequests[xhrId];
  2254. xhr.abort();
  2255. }
  2256. };
  2257. return NetworkManager;
  2258. })();
  2259. var ChunkedStream = (function ChunkedStreamClosure() {
  2260. function ChunkedStream(length, chunkSize, manager) {
  2261. this.bytes = new Uint8Array(length);
  2262. this.start = 0;
  2263. this.pos = 0;
  2264. this.end = length;
  2265. this.chunkSize = chunkSize;
  2266. this.loadedChunks = [];
  2267. this.numChunksLoaded = 0;
  2268. this.numChunks = Math.ceil(length / chunkSize);
  2269. this.manager = manager;
  2270. this.progressiveDataLength = 0;
  2271. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  2272. }
  2273. // required methods for a stream. if a particular stream does not
  2274. // implement these, an error should be thrown
  2275. ChunkedStream.prototype = {
  2276. getMissingChunks: function ChunkedStream_getMissingChunks() {
  2277. var chunks = [];
  2278. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  2279. if (!this.loadedChunks[chunk]) {
  2280. chunks.push(chunk);
  2281. }
  2282. }
  2283. return chunks;
  2284. },
  2285. getBaseStreams: function ChunkedStream_getBaseStreams() {
  2286. return [this];
  2287. },
  2288. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  2289. return this.numChunksLoaded === this.numChunks;
  2290. },
  2291. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  2292. var end = begin + chunk.byteLength;
  2293. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  2294. // Using this.length is inaccurate here since this.start can be moved
  2295. // See ChunkedStream.moveStart()
  2296. var length = this.bytes.length;
  2297. assert(end % this.chunkSize === 0 || end === length,
  2298. 'Bad end offset: ' + end);
  2299. this.bytes.set(new Uint8Array(chunk), begin);
  2300. var chunkSize = this.chunkSize;
  2301. var beginChunk = Math.floor(begin / chunkSize);
  2302. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  2303. var curChunk;
  2304. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  2305. if (!this.loadedChunks[curChunk]) {
  2306. this.loadedChunks[curChunk] = true;
  2307. ++this.numChunksLoaded;
  2308. }
  2309. }
  2310. },
  2311. onReceiveProgressiveData:
  2312. function ChunkedStream_onReceiveProgressiveData(data) {
  2313. var position = this.progressiveDataLength;
  2314. var beginChunk = Math.floor(position / this.chunkSize);
  2315. this.bytes.set(new Uint8Array(data), position);
  2316. position += data.byteLength;
  2317. this.progressiveDataLength = position;
  2318. var endChunk = position >= this.end ? this.numChunks :
  2319. Math.floor(position / this.chunkSize);
  2320. var curChunk;
  2321. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  2322. if (!this.loadedChunks[curChunk]) {
  2323. this.loadedChunks[curChunk] = true;
  2324. ++this.numChunksLoaded;
  2325. }
  2326. }
  2327. },
  2328. ensureByte: function ChunkedStream_ensureByte(pos) {
  2329. var chunk = Math.floor(pos / this.chunkSize);
  2330. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  2331. return;
  2332. }
  2333. if (!this.loadedChunks[chunk]) {
  2334. throw new MissingDataException(pos, pos + 1);
  2335. }
  2336. this.lastSuccessfulEnsureByteChunk = chunk;
  2337. },
  2338. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  2339. if (begin >= end) {
  2340. return;
  2341. }
  2342. if (end <= this.progressiveDataLength) {
  2343. return;
  2344. }
  2345. var chunkSize = this.chunkSize;
  2346. var beginChunk = Math.floor(begin / chunkSize);
  2347. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  2348. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2349. if (!this.loadedChunks[chunk]) {
  2350. throw new MissingDataException(begin, end);
  2351. }
  2352. }
  2353. },
  2354. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  2355. var chunk, numChunks = this.numChunks;
  2356. for (var i = 0; i < numChunks; ++i) {
  2357. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  2358. if (!this.loadedChunks[chunk]) {
  2359. return chunk;
  2360. }
  2361. }
  2362. return null;
  2363. },
  2364. hasChunk: function ChunkedStream_hasChunk(chunk) {
  2365. return !!this.loadedChunks[chunk];
  2366. },
  2367. get length() {
  2368. return this.end - this.start;
  2369. },
  2370. get isEmpty() {
  2371. return this.length === 0;
  2372. },
  2373. getByte: function ChunkedStream_getByte() {
  2374. var pos = this.pos;
  2375. if (pos >= this.end) {
  2376. return -1;
  2377. }
  2378. this.ensureByte(pos);
  2379. return this.bytes[this.pos++];
  2380. },
  2381. getUint16: function ChunkedStream_getUint16() {
  2382. var b0 = this.getByte();
  2383. var b1 = this.getByte();
  2384. if (b0 === -1 || b1 === -1) {
  2385. return -1;
  2386. }
  2387. return (b0 << 8) + b1;
  2388. },
  2389. getInt32: function ChunkedStream_getInt32() {
  2390. var b0 = this.getByte();
  2391. var b1 = this.getByte();
  2392. var b2 = this.getByte();
  2393. var b3 = this.getByte();
  2394. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  2395. },
  2396. // returns subarray of original buffer
  2397. // should only be read
  2398. getBytes: function ChunkedStream_getBytes(length) {
  2399. var bytes = this.bytes;
  2400. var pos = this.pos;
  2401. var strEnd = this.end;
  2402. if (!length) {
  2403. this.ensureRange(pos, strEnd);
  2404. return bytes.subarray(pos, strEnd);
  2405. }
  2406. var end = pos + length;
  2407. if (end > strEnd) {
  2408. end = strEnd;
  2409. }
  2410. this.ensureRange(pos, end);
  2411. this.pos = end;
  2412. return bytes.subarray(pos, end);
  2413. },
  2414. peekByte: function ChunkedStream_peekByte() {
  2415. var peekedByte = this.getByte();
  2416. this.pos--;
  2417. return peekedByte;
  2418. },
  2419. peekBytes: function ChunkedStream_peekBytes(length) {
  2420. var bytes = this.getBytes(length);
  2421. this.pos -= bytes.length;
  2422. return bytes;
  2423. },
  2424. getByteRange: function ChunkedStream_getBytes(begin, end) {
  2425. this.ensureRange(begin, end);
  2426. return this.bytes.subarray(begin, end);
  2427. },
  2428. skip: function ChunkedStream_skip(n) {
  2429. if (!n) {
  2430. n = 1;
  2431. }
  2432. this.pos += n;
  2433. },
  2434. reset: function ChunkedStream_reset() {
  2435. this.pos = this.start;
  2436. },
  2437. moveStart: function ChunkedStream_moveStart() {
  2438. this.start = this.pos;
  2439. },
  2440. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  2441. this.ensureRange(start, start + length);
  2442. function ChunkedStreamSubstream() {}
  2443. ChunkedStreamSubstream.prototype = Object.create(this);
  2444. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  2445. var chunkSize = this.chunkSize;
  2446. var beginChunk = Math.floor(this.start / chunkSize);
  2447. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  2448. var missingChunks = [];
  2449. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2450. if (!this.loadedChunks[chunk]) {
  2451. missingChunks.push(chunk);
  2452. }
  2453. }
  2454. return missingChunks;
  2455. };
  2456. var subStream = new ChunkedStreamSubstream();
  2457. subStream.pos = subStream.start = start;
  2458. subStream.end = start + length || this.end;
  2459. subStream.dict = dict;
  2460. return subStream;
  2461. },
  2462. isStream: true
  2463. };
  2464. return ChunkedStream;
  2465. })();
  2466. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  2467. function ChunkedStreamManager(length, chunkSize, url, args) {
  2468. this.stream = new ChunkedStream(length, chunkSize, this);
  2469. this.length = length;
  2470. this.chunkSize = chunkSize;
  2471. this.url = url;
  2472. this.disableAutoFetch = args.disableAutoFetch;
  2473. var msgHandler = this.msgHandler = args.msgHandler;
  2474. if (args.chunkedViewerLoading) {
  2475. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  2476. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  2477. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  2478. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  2479. };
  2480. } else {
  2481. var getXhr = function getXhr() {
  2482. return new XMLHttpRequest();
  2483. };
  2484. this.networkManager = new NetworkManager(this.url, {
  2485. getXhr: getXhr,
  2486. httpHeaders: args.httpHeaders,
  2487. withCredentials: args.withCredentials
  2488. });
  2489. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  2490. this.networkManager.requestRange(begin, end, {
  2491. onDone: this.onReceiveData.bind(this),
  2492. onProgress: this.onProgress.bind(this)
  2493. });
  2494. };
  2495. }
  2496. this.currRequestId = 0;
  2497. this.chunksNeededByRequest = {};
  2498. this.requestsByChunk = {};
  2499. this.promisesByRequest = {};
  2500. this.progressiveDataLength = 0;
  2501. this._loadedStreamCapability = createPromiseCapability();
  2502. if (args.initialData) {
  2503. this.onReceiveData({chunk: args.initialData});
  2504. }
  2505. }
  2506. ChunkedStreamManager.prototype = {
  2507. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  2508. return this._loadedStreamCapability.promise;
  2509. },
  2510. // Get all the chunks that are not yet loaded and groups them into
  2511. // contiguous ranges to load in as few requests as possible
  2512. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  2513. var missingChunks = this.stream.getMissingChunks();
  2514. this._requestChunks(missingChunks);
  2515. return this._loadedStreamCapability.promise;
  2516. },
  2517. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  2518. var requestId = this.currRequestId++;
  2519. var chunksNeeded;
  2520. var i, ii;
  2521. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  2522. for (i = 0, ii = chunks.length; i < ii; i++) {
  2523. if (!this.stream.hasChunk(chunks[i])) {
  2524. chunksNeeded[chunks[i]] = true;
  2525. }
  2526. }
  2527. if (isEmptyObj(chunksNeeded)) {
  2528. return Promise.resolve();
  2529. }
  2530. var capability = createPromiseCapability();
  2531. this.promisesByRequest[requestId] = capability;
  2532. var chunksToRequest = [];
  2533. for (var chunk in chunksNeeded) {
  2534. chunk = chunk | 0;
  2535. if (!(chunk in this.requestsByChunk)) {
  2536. this.requestsByChunk[chunk] = [];
  2537. chunksToRequest.push(chunk);
  2538. }
  2539. this.requestsByChunk[chunk].push(requestId);
  2540. }
  2541. if (!chunksToRequest.length) {
  2542. return capability.promise;
  2543. }
  2544. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  2545. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  2546. var groupedChunk = groupedChunksToRequest[i];
  2547. var begin = groupedChunk.beginChunk * this.chunkSize;
  2548. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  2549. this.sendRequest(begin, end);
  2550. }
  2551. return capability.promise;
  2552. },
  2553. getStream: function ChunkedStreamManager_getStream() {
  2554. return this.stream;
  2555. },
  2556. // Loads any chunks in the requested range that are not yet loaded
  2557. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  2558. end = Math.min(end, this.length);
  2559. var beginChunk = this.getBeginChunk(begin);
  2560. var endChunk = this.getEndChunk(end);
  2561. var chunks = [];
  2562. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2563. chunks.push(chunk);
  2564. }
  2565. return this._requestChunks(chunks);
  2566. },
  2567. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  2568. ranges = ranges || [];
  2569. var chunksToRequest = [];
  2570. for (var i = 0; i < ranges.length; i++) {
  2571. var beginChunk = this.getBeginChunk(ranges[i].begin);
  2572. var endChunk = this.getEndChunk(ranges[i].end);
  2573. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  2574. if (chunksToRequest.indexOf(chunk) < 0) {
  2575. chunksToRequest.push(chunk);
  2576. }
  2577. }
  2578. }
  2579. chunksToRequest.sort(function(a, b) { return a - b; });
  2580. return this._requestChunks(chunksToRequest);
  2581. },
  2582. // Groups a sorted array of chunks into as few contiguous larger
  2583. // chunks as possible
  2584. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  2585. var groupedChunks = [];
  2586. var beginChunk = -1;
  2587. var prevChunk = -1;
  2588. for (var i = 0; i < chunks.length; ++i) {
  2589. var chunk = chunks[i];
  2590. if (beginChunk < 0) {
  2591. beginChunk = chunk;
  2592. }
  2593. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  2594. groupedChunks.push({ beginChunk: beginChunk,
  2595. endChunk: prevChunk + 1 });
  2596. beginChunk = chunk;
  2597. }
  2598. if (i + 1 === chunks.length) {
  2599. groupedChunks.push({ beginChunk: beginChunk,
  2600. endChunk: chunk + 1 });
  2601. }
  2602. prevChunk = chunk;
  2603. }
  2604. return groupedChunks;
  2605. },
  2606. onProgress: function ChunkedStreamManager_onProgress(args) {
  2607. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2608. args.loaded);
  2609. this.msgHandler.send('DocProgress', {
  2610. loaded: bytesLoaded,
  2611. total: this.length
  2612. });
  2613. },
  2614. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2615. var chunk = args.chunk;
  2616. var isProgressive = args.begin === undefined;
  2617. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2618. var end = begin + chunk.byteLength;
  2619. var beginChunk = Math.floor(begin / this.chunkSize);
  2620. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2621. Math.ceil(end / this.chunkSize);
  2622. if (isProgressive) {
  2623. this.stream.onReceiveProgressiveData(chunk);
  2624. this.progressiveDataLength = end;
  2625. } else {
  2626. this.stream.onReceiveData(begin, chunk);
  2627. }
  2628. if (this.stream.allChunksLoaded()) {
  2629. this._loadedStreamCapability.resolve(this.stream);
  2630. }
  2631. var loadedRequests = [];
  2632. var i, requestId;
  2633. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2634. // The server might return more chunks than requested
  2635. var requestIds = this.requestsByChunk[chunk] || [];
  2636. delete this.requestsByChunk[chunk];
  2637. for (i = 0; i < requestIds.length; ++i) {
  2638. requestId = requestIds[i];
  2639. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2640. if (chunk in chunksNeeded) {
  2641. delete chunksNeeded[chunk];
  2642. }
  2643. if (!isEmptyObj(chunksNeeded)) {
  2644. continue;
  2645. }
  2646. loadedRequests.push(requestId);
  2647. }
  2648. }
  2649. // If there are no pending requests, automatically fetch the next
  2650. // unfetched chunk of the PDF
  2651. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2652. var nextEmptyChunk;
  2653. if (this.stream.numChunksLoaded === 1) {
  2654. // This is a special optimization so that after fetching the first
  2655. // chunk, rather than fetching the second chunk, we fetch the last
  2656. // chunk.
  2657. var lastChunk = this.stream.numChunks - 1;
  2658. if (!this.stream.hasChunk(lastChunk)) {
  2659. nextEmptyChunk = lastChunk;
  2660. }
  2661. } else {
  2662. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2663. }
  2664. if (isInt(nextEmptyChunk)) {
  2665. this._requestChunks([nextEmptyChunk]);
  2666. }
  2667. }
  2668. for (i = 0; i < loadedRequests.length; ++i) {
  2669. requestId = loadedRequests[i];
  2670. var capability = this.promisesByRequest[requestId];
  2671. delete this.promisesByRequest[requestId];
  2672. capability.resolve();
  2673. }
  2674. this.msgHandler.send('DocProgress', {
  2675. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2676. total: this.length
  2677. });
  2678. },
  2679. onError: function ChunkedStreamManager_onError(err) {
  2680. this._loadedStreamCapability.reject(err);
  2681. },
  2682. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2683. var chunk = Math.floor(begin / this.chunkSize);
  2684. return chunk;
  2685. },
  2686. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2687. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2688. return chunk;
  2689. },
  2690. abort: function ChunkedStreamManager_abort() {
  2691. if (this.networkManager) {
  2692. this.networkManager.abortAllRequests();
  2693. }
  2694. for(var requestId in this.promisesByRequest) {
  2695. var capability = this.promisesByRequest[requestId];
  2696. capability.reject(new Error('Request was aborted'));
  2697. }
  2698. }
  2699. };
  2700. return ChunkedStreamManager;
  2701. })();
  2702. var BasePdfManager = (function BasePdfManagerClosure() {
  2703. function BasePdfManager() {
  2704. throw new Error('Cannot initialize BaseManagerManager');
  2705. }
  2706. BasePdfManager.prototype = {
  2707. get docId() {
  2708. return this._docId;
  2709. },
  2710. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2711. throw new NotImplementedException();
  2712. },
  2713. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2714. return this.ensure(this.pdfDocument, prop, args);
  2715. },
  2716. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2717. return this.ensure(this.pdfDocument.xref, prop, args);
  2718. },
  2719. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2720. return this.ensure(this.pdfDocument.catalog, prop, args);
  2721. },
  2722. getPage: function BasePdfManager_getPage(pageIndex) {
  2723. return this.pdfDocument.getPage(pageIndex);
  2724. },
  2725. cleanup: function BasePdfManager_cleanup() {
  2726. return this.pdfDocument.cleanup();
  2727. },
  2728. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2729. return new NotImplementedException();
  2730. },
  2731. requestRange: function BasePdfManager_requestRange(begin, end) {
  2732. return new NotImplementedException();
  2733. },
  2734. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2735. return new NotImplementedException();
  2736. },
  2737. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2738. return new NotImplementedException();
  2739. },
  2740. updatePassword: function BasePdfManager_updatePassword(password) {
  2741. this.pdfDocument.xref.password = this.password = password;
  2742. if (this._passwordChangedCapability) {
  2743. this._passwordChangedCapability.resolve();
  2744. }
  2745. },
  2746. passwordChanged: function BasePdfManager_passwordChanged() {
  2747. this._passwordChangedCapability = createPromiseCapability();
  2748. return this._passwordChangedCapability.promise;
  2749. },
  2750. terminate: function BasePdfManager_terminate() {
  2751. return new NotImplementedException();
  2752. }
  2753. };
  2754. return BasePdfManager;
  2755. })();
  2756. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2757. function LocalPdfManager(docId, data, password) {
  2758. this._docId = docId;
  2759. var stream = new Stream(data);
  2760. this.pdfDocument = new PDFDocument(this, stream, password);
  2761. this._loadedStreamCapability = createPromiseCapability();
  2762. this._loadedStreamCapability.resolve(stream);
  2763. }
  2764. Util.inherit(LocalPdfManager, BasePdfManager, {
  2765. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  2766. return new Promise(function (resolve, reject) {
  2767. try {
  2768. var value = obj[prop];
  2769. var result;
  2770. if (typeof value === 'function') {
  2771. result = value.apply(obj, args);
  2772. } else {
  2773. result = value;
  2774. }
  2775. resolve(result);
  2776. } catch (e) {
  2777. reject(e);
  2778. }
  2779. });
  2780. },
  2781. requestRange: function LocalPdfManager_requestRange(begin, end) {
  2782. return Promise.resolve();
  2783. },
  2784. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  2785. return;
  2786. },
  2787. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  2788. return this._loadedStreamCapability.promise;
  2789. },
  2790. terminate: function LocalPdfManager_terminate() {
  2791. return;
  2792. }
  2793. });
  2794. return LocalPdfManager;
  2795. })();
  2796. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2797. function NetworkPdfManager(docId, args, msgHandler) {
  2798. this._docId = docId;
  2799. this.msgHandler = msgHandler;
  2800. var params = {
  2801. msgHandler: msgHandler,
  2802. httpHeaders: args.httpHeaders,
  2803. withCredentials: args.withCredentials,
  2804. chunkedViewerLoading: args.chunkedViewerLoading,
  2805. disableAutoFetch: args.disableAutoFetch,
  2806. initialData: args.initialData
  2807. };
  2808. this.streamManager = new ChunkedStreamManager(args.length,
  2809. args.rangeChunkSize,
  2810. args.url, params);
  2811. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2812. args.password);
  2813. }
  2814. Util.inherit(NetworkPdfManager, BasePdfManager, {
  2815. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  2816. var pdfManager = this;
  2817. return new Promise(function (resolve, reject) {
  2818. function ensureHelper() {
  2819. try {
  2820. var result;
  2821. var value = obj[prop];
  2822. if (typeof value === 'function') {
  2823. result = value.apply(obj, args);
  2824. } else {
  2825. result = value;
  2826. }
  2827. resolve(result);
  2828. } catch(e) {
  2829. if (!(e instanceof MissingDataException)) {
  2830. reject(e);
  2831. return;
  2832. }
  2833. pdfManager.streamManager.requestRange(e.begin, e.end).
  2834. then(ensureHelper, reject);
  2835. }
  2836. }
  2837. ensureHelper();
  2838. });
  2839. },
  2840. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  2841. return this.streamManager.requestRange(begin, end);
  2842. },
  2843. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  2844. this.streamManager.requestAllChunks();
  2845. },
  2846. sendProgressiveData:
  2847. function NetworkPdfManager_sendProgressiveData(chunk) {
  2848. this.streamManager.onReceiveData({ chunk: chunk });
  2849. },
  2850. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  2851. return this.streamManager.onLoadedStream();
  2852. },
  2853. terminate: function NetworkPdfManager_terminate() {
  2854. this.streamManager.abort();
  2855. }
  2856. });
  2857. return NetworkPdfManager;
  2858. })();
  2859. var Page = (function PageClosure() {
  2860. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2861. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2862. this.pdfManager = pdfManager;
  2863. this.pageIndex = pageIndex;
  2864. this.pageDict = pageDict;
  2865. this.xref = xref;
  2866. this.ref = ref;
  2867. this.fontCache = fontCache;
  2868. this.idCounters = {
  2869. obj: 0
  2870. };
  2871. this.resourcesPromise = null;
  2872. }
  2873. Page.prototype = {
  2874. getPageProp: function Page_getPageProp(key) {
  2875. return this.pageDict.get(key);
  2876. },
  2877. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2878. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2879. var MAX_LOOP_COUNT = 100;
  2880. // Always walk up the entire parent chain, to be able to find
  2881. // e.g. \Resources placed on multiple levels of the tree.
  2882. while (dict) {
  2883. var value = dict.get(key);
  2884. if (value) {
  2885. if (!valueArray) {
  2886. valueArray = [];
  2887. }
  2888. valueArray.push(value);
  2889. }
  2890. if (++loopCount > MAX_LOOP_COUNT) {
  2891. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2892. break;
  2893. }
  2894. dict = dict.get('Parent');
  2895. }
  2896. if (!valueArray) {
  2897. return Dict.empty;
  2898. }
  2899. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2900. loopCount > MAX_LOOP_COUNT) {
  2901. return valueArray[0];
  2902. }
  2903. return Dict.merge(this.xref, valueArray);
  2904. },
  2905. get content() {
  2906. return this.getPageProp('Contents');
  2907. },
  2908. get resources() {
  2909. // For robustness: The spec states that a \Resources entry has to be
  2910. // present, but can be empty. Some document omit it still, in this case
  2911. // we return an empty dictionary.
  2912. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2913. },
  2914. get mediaBox() {
  2915. var obj = this.getInheritedPageProp('MediaBox');
  2916. // Reset invalid media box to letter size.
  2917. if (!isArray(obj) || obj.length !== 4) {
  2918. obj = LETTER_SIZE_MEDIABOX;
  2919. }
  2920. return shadow(this, 'mediaBox', obj);
  2921. },
  2922. get view() {
  2923. var mediaBox = this.mediaBox;
  2924. var cropBox = this.getInheritedPageProp('CropBox');
  2925. if (!isArray(cropBox) || cropBox.length !== 4) {
  2926. return shadow(this, 'view', mediaBox);
  2927. }
  2928. // From the spec, 6th ed., p.963:
  2929. // "The crop, bleed, trim, and art boxes should not ordinarily
  2930. // extend beyond the boundaries of the media box. If they do, they are
  2931. // effectively reduced to their intersection with the media box."
  2932. cropBox = Util.intersect(cropBox, mediaBox);
  2933. if (!cropBox) {
  2934. return shadow(this, 'view', mediaBox);
  2935. }
  2936. return shadow(this, 'view', cropBox);
  2937. },
  2938. get rotate() {
  2939. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2940. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2941. if (rotate % 90 !== 0) {
  2942. rotate = 0;
  2943. } else if (rotate >= 360) {
  2944. rotate = rotate % 360;
  2945. } else if (rotate < 0) {
  2946. // The spec doesn't cover negatives, assume its counterclockwise
  2947. // rotation. The following is the other implementation of modulo.
  2948. rotate = ((rotate % 360) + 360) % 360;
  2949. }
  2950. return shadow(this, 'rotate', rotate);
  2951. },
  2952. getContentStream: function Page_getContentStream() {
  2953. var content = this.content;
  2954. var stream;
  2955. if (isArray(content)) {
  2956. // fetching items
  2957. var xref = this.xref;
  2958. var i, n = content.length;
  2959. var streams = [];
  2960. for (i = 0; i < n; ++i) {
  2961. streams.push(xref.fetchIfRef(content[i]));
  2962. }
  2963. stream = new StreamsSequenceStream(streams);
  2964. } else if (isStream(content)) {
  2965. stream = content;
  2966. } else {
  2967. // replacing non-existent page content with empty one
  2968. stream = new NullStream();
  2969. }
  2970. return stream;
  2971. },
  2972. loadResources: function Page_loadResources(keys) {
  2973. if (!this.resourcesPromise) {
  2974. // TODO: add async getInheritedPageProp and remove this.
  2975. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2976. }
  2977. return this.resourcesPromise.then(function resourceSuccess() {
  2978. var objectLoader = new ObjectLoader(this.resources.map,
  2979. keys,
  2980. this.xref);
  2981. return objectLoader.load();
  2982. }.bind(this));
  2983. },
  2984. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  2985. var self = this;
  2986. var pdfManager = this.pdfManager;
  2987. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2988. []);
  2989. var resourcesPromise = this.loadResources([
  2990. 'ExtGState',
  2991. 'ColorSpace',
  2992. 'Pattern',
  2993. 'Shading',
  2994. 'XObject',
  2995. 'Font'
  2996. // ProcSet
  2997. // Properties
  2998. ]);
  2999. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  3000. handler, this.pageIndex,
  3001. 'p' + this.pageIndex + '_',
  3002. this.idCounters,
  3003. this.fontCache);
  3004. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  3005. var pageListPromise = dataPromises.then(function(data) {
  3006. var contentStream = data[0];
  3007. var opList = new OperatorList(intent, handler, self.pageIndex);
  3008. handler.send('StartRenderPage', {
  3009. transparency: partialEvaluator.hasBlendModes(self.resources),
  3010. pageIndex: self.pageIndex,
  3011. intent: intent
  3012. });
  3013. return partialEvaluator.getOperatorList(contentStream, task,
  3014. self.resources, opList).then(function () {
  3015. return opList;
  3016. });
  3017. });
  3018. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  3019. return Promise.all([pageListPromise, annotationsPromise]).then(
  3020. function(datas) {
  3021. var pageOpList = datas[0];
  3022. var annotations = datas[1];
  3023. if (annotations.length === 0) {
  3024. pageOpList.flush(true);
  3025. return pageOpList;
  3026. }
  3027. var annotationsReadyPromise = Annotation.appendToOperatorList(
  3028. annotations, pageOpList, partialEvaluator, task, intent);
  3029. return annotationsReadyPromise.then(function () {
  3030. pageOpList.flush(true);
  3031. return pageOpList;
  3032. });
  3033. });
  3034. },
  3035. extractTextContent: function Page_extractTextContent(task,
  3036. normalizeWhitespace) {
  3037. var handler = {
  3038. on: function nullHandlerOn() {},
  3039. send: function nullHandlerSend() {}
  3040. };
  3041. var self = this;
  3042. var pdfManager = this.pdfManager;
  3043. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  3044. []);
  3045. var resourcesPromise = this.loadResources([
  3046. 'ExtGState',
  3047. 'XObject',
  3048. 'Font'
  3049. ]);
  3050. var dataPromises = Promise.all([contentStreamPromise,
  3051. resourcesPromise]);
  3052. return dataPromises.then(function(data) {
  3053. var contentStream = data[0];
  3054. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  3055. handler, self.pageIndex,
  3056. 'p' + self.pageIndex + '_',
  3057. self.idCounters,
  3058. self.fontCache);
  3059. return partialEvaluator.getTextContent(contentStream,
  3060. task,
  3061. self.resources,
  3062. /* stateManager = */ null,
  3063. normalizeWhitespace);
  3064. });
  3065. },
  3066. getAnnotationsData: function Page_getAnnotationsData(intent) {
  3067. var annotations = this.annotations;
  3068. var annotationsData = [];
  3069. for (var i = 0, n = annotations.length; i < n; ++i) {
  3070. if (intent) {
  3071. if (!(intent === 'display' && annotations[i].viewable) &&
  3072. !(intent === 'print' && annotations[i].printable)) {
  3073. continue;
  3074. }
  3075. }
  3076. annotationsData.push(annotations[i].data);
  3077. }
  3078. return annotationsData;
  3079. },
  3080. get annotations() {
  3081. var annotations = [];
  3082. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  3083. var annotationFactory = new AnnotationFactory();
  3084. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  3085. var annotationRef = annotationRefs[i];
  3086. var annotation = annotationFactory.create(this.xref, annotationRef);
  3087. if (annotation) {
  3088. annotations.push(annotation);
  3089. }
  3090. }
  3091. return shadow(this, 'annotations', annotations);
  3092. }
  3093. };
  3094. return Page;
  3095. })();
  3096. /**
  3097. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  3098. * `PDFDoc`, this one doesn't have any job management code.
  3099. * Right now there exists one PDFDocument on the main thread + one object
  3100. * for each worker. If there is no worker support enabled, there are two
  3101. * `PDFDocument` objects on the main thread created.
  3102. */
  3103. var PDFDocument = (function PDFDocumentClosure() {
  3104. var FINGERPRINT_FIRST_BYTES = 1024;
  3105. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  3106. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  3107. function PDFDocument(pdfManager, arg, password) {
  3108. if (isStream(arg)) {
  3109. init.call(this, pdfManager, arg, password);
  3110. } else if (isArrayBuffer(arg)) {
  3111. init.call(this, pdfManager, new Stream(arg), password);
  3112. } else {
  3113. error('PDFDocument: Unknown argument type');
  3114. }
  3115. }
  3116. function init(pdfManager, stream, password) {
  3117. assert(stream.length > 0, 'stream must have data');
  3118. this.pdfManager = pdfManager;
  3119. this.stream = stream;
  3120. var xref = new XRef(this.stream, password, pdfManager);
  3121. this.xref = xref;
  3122. }
  3123. function find(stream, needle, limit, backwards) {
  3124. var pos = stream.pos;
  3125. var end = stream.end;
  3126. var strBuf = [];
  3127. if (pos + limit > end) {
  3128. limit = end - pos;
  3129. }
  3130. for (var n = 0; n < limit; ++n) {
  3131. strBuf.push(String.fromCharCode(stream.getByte()));
  3132. }
  3133. var str = strBuf.join('');
  3134. stream.pos = pos;
  3135. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  3136. if (index === -1) {
  3137. return false; /* not found */
  3138. }
  3139. stream.pos += index;
  3140. return true; /* found */
  3141. }
  3142. var DocumentInfoValidators = {
  3143. get entries() {
  3144. // Lazily build this since all the validation functions below are not
  3145. // defined until after this file loads.
  3146. return shadow(this, 'entries', {
  3147. Title: isString,
  3148. Author: isString,
  3149. Subject: isString,
  3150. Keywords: isString,
  3151. Creator: isString,
  3152. Producer: isString,
  3153. CreationDate: isString,
  3154. ModDate: isString,
  3155. Trapped: isName
  3156. });
  3157. }
  3158. };
  3159. PDFDocument.prototype = {
  3160. parse: function PDFDocument_parse(recoveryMode) {
  3161. this.setup(recoveryMode);
  3162. var version = this.catalog.catDict.get('Version');
  3163. if (isName(version)) {
  3164. this.pdfFormatVersion = version.name;
  3165. }
  3166. try {
  3167. // checking if AcroForm is present
  3168. this.acroForm = this.catalog.catDict.get('AcroForm');
  3169. if (this.acroForm) {
  3170. this.xfa = this.acroForm.get('XFA');
  3171. var fields = this.acroForm.get('Fields');
  3172. if ((!fields || !isArray(fields) || fields.length === 0) &&
  3173. !this.xfa) {
  3174. // no fields and no XFA -- not a form (?)
  3175. this.acroForm = null;
  3176. }
  3177. }
  3178. } catch (ex) {
  3179. info('Something wrong with AcroForm entry');
  3180. this.acroForm = null;
  3181. }
  3182. },
  3183. get linearization() {
  3184. var linearization = null;
  3185. if (this.stream.length) {
  3186. try {
  3187. linearization = Linearization.create(this.stream);
  3188. } catch (err) {
  3189. if (err instanceof MissingDataException) {
  3190. throw err;
  3191. }
  3192. info(err);
  3193. }
  3194. }
  3195. // shadow the prototype getter with a data property
  3196. return shadow(this, 'linearization', linearization);
  3197. },
  3198. get startXRef() {
  3199. var stream = this.stream;
  3200. var startXRef = 0;
  3201. var linearization = this.linearization;
  3202. if (linearization) {
  3203. // Find end of first obj.
  3204. stream.reset();
  3205. if (find(stream, 'endobj', 1024)) {
  3206. startXRef = stream.pos + 6;
  3207. }
  3208. } else {
  3209. // Find startxref by jumping backward from the end of the file.
  3210. var step = 1024;
  3211. var found = false, pos = stream.end;
  3212. while (!found && pos > 0) {
  3213. pos -= step - 'startxref'.length;
  3214. if (pos < 0) {
  3215. pos = 0;
  3216. }
  3217. stream.pos = pos;
  3218. found = find(stream, 'startxref', step, true);
  3219. }
  3220. if (found) {
  3221. stream.skip(9);
  3222. var ch;
  3223. do {
  3224. ch = stream.getByte();
  3225. } while (Lexer.isSpace(ch));
  3226. var str = '';
  3227. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  3228. str += String.fromCharCode(ch);
  3229. ch = stream.getByte();
  3230. }
  3231. startXRef = parseInt(str, 10);
  3232. if (isNaN(startXRef)) {
  3233. startXRef = 0;
  3234. }
  3235. }
  3236. }
  3237. // shadow the prototype getter with a data property
  3238. return shadow(this, 'startXRef', startXRef);
  3239. },
  3240. get mainXRefEntriesOffset() {
  3241. var mainXRefEntriesOffset = 0;
  3242. var linearization = this.linearization;
  3243. if (linearization) {
  3244. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  3245. }
  3246. // shadow the prototype getter with a data property
  3247. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  3248. },
  3249. // Find the header, remove leading garbage and setup the stream
  3250. // starting from the header.
  3251. checkHeader: function PDFDocument_checkHeader() {
  3252. var stream = this.stream;
  3253. stream.reset();
  3254. if (find(stream, '%PDF-', 1024)) {
  3255. // Found the header, trim off any garbage before it.
  3256. stream.moveStart();
  3257. // Reading file format version
  3258. var MAX_VERSION_LENGTH = 12;
  3259. var version = '', ch;
  3260. while ((ch = stream.getByte()) > 0x20) { // SPACE
  3261. if (version.length >= MAX_VERSION_LENGTH) {
  3262. break;
  3263. }
  3264. version += String.fromCharCode(ch);
  3265. }
  3266. if (!this.pdfFormatVersion) {
  3267. // removing "%PDF-"-prefix
  3268. this.pdfFormatVersion = version.substring(5);
  3269. }
  3270. return;
  3271. }
  3272. // May not be a PDF file, continue anyway.
  3273. },
  3274. parseStartXRef: function PDFDocument_parseStartXRef() {
  3275. var startXRef = this.startXRef;
  3276. this.xref.setStartXRef(startXRef);
  3277. },
  3278. setup: function PDFDocument_setup(recoveryMode) {
  3279. this.xref.parse(recoveryMode);
  3280. this.catalog = new Catalog(this.pdfManager, this.xref);
  3281. },
  3282. get numPages() {
  3283. var linearization = this.linearization;
  3284. var num = linearization ? linearization.numPages : this.catalog.numPages;
  3285. // shadow the prototype getter
  3286. return shadow(this, 'numPages', num);
  3287. },
  3288. get documentInfo() {
  3289. var docInfo = {
  3290. PDFFormatVersion: this.pdfFormatVersion,
  3291. IsAcroFormPresent: !!this.acroForm,
  3292. IsXFAPresent: !!this.xfa
  3293. };
  3294. var infoDict;
  3295. try {
  3296. infoDict = this.xref.trailer.get('Info');
  3297. } catch (err) {
  3298. info('The document information dictionary is invalid.');
  3299. }
  3300. if (infoDict) {
  3301. var validEntries = DocumentInfoValidators.entries;
  3302. // Only fill the document info with valid entries from the spec.
  3303. for (var key in validEntries) {
  3304. if (infoDict.has(key)) {
  3305. var value = infoDict.get(key);
  3306. // Make sure the value conforms to the spec.
  3307. if (validEntries[key](value)) {
  3308. docInfo[key] = (typeof value !== 'string' ?
  3309. value : stringToPDFString(value));
  3310. } else {
  3311. info('Bad value in document info for "' + key + '"');
  3312. }
  3313. }
  3314. }
  3315. }
  3316. return shadow(this, 'documentInfo', docInfo);
  3317. },
  3318. get fingerprint() {
  3319. var xref = this.xref, hash, fileID = '';
  3320. var idArray = xref.trailer.get('ID');
  3321. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  3322. idArray[0] !== EMPTY_FINGERPRINT) {
  3323. hash = stringToBytes(idArray[0]);
  3324. } else {
  3325. if (this.stream.ensureRange) {
  3326. this.stream.ensureRange(0,
  3327. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  3328. }
  3329. hash = calculateMD5(this.stream.bytes.subarray(0,
  3330. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  3331. }
  3332. for (var i = 0, n = hash.length; i < n; i++) {
  3333. var hex = hash[i].toString(16);
  3334. fileID += hex.length === 1 ? '0' + hex : hex;
  3335. }
  3336. return shadow(this, 'fingerprint', fileID);
  3337. },
  3338. getPage: function PDFDocument_getPage(pageIndex) {
  3339. return this.catalog.getPage(pageIndex);
  3340. },
  3341. cleanup: function PDFDocument_cleanup() {
  3342. return this.catalog.cleanup();
  3343. }
  3344. };
  3345. return PDFDocument;
  3346. })();
  3347. var Name = (function NameClosure() {
  3348. function Name(name) {
  3349. this.name = name;
  3350. }
  3351. Name.prototype = {};
  3352. var nameCache = {};
  3353. Name.get = function Name_get(name) {
  3354. var nameValue = nameCache[name];
  3355. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  3356. };
  3357. return Name;
  3358. })();
  3359. var Cmd = (function CmdClosure() {
  3360. function Cmd(cmd) {
  3361. this.cmd = cmd;
  3362. }
  3363. Cmd.prototype = {};
  3364. var cmdCache = {};
  3365. Cmd.get = function Cmd_get(cmd) {
  3366. var cmdValue = cmdCache[cmd];
  3367. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  3368. };
  3369. return Cmd;
  3370. })();
  3371. var Dict = (function DictClosure() {
  3372. var nonSerializable = function nonSerializableClosure() {
  3373. return nonSerializable; // creating closure on some variable
  3374. };
  3375. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  3376. 'Background': true,
  3377. 'ExtGState': true,
  3378. 'Halftone': true,
  3379. 'Layout': true,
  3380. 'Mask': true,
  3381. 'Pagination': true,
  3382. 'Printing': true
  3383. };
  3384. function isRecursionAllowedFor(dict) {
  3385. if (!isName(dict.Type)) {
  3386. return true;
  3387. }
  3388. var dictType = dict.Type.name;
  3389. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  3390. }
  3391. // xref is optional
  3392. function Dict(xref) {
  3393. // Map should only be used internally, use functions below to access.
  3394. this.map = Object.create(null);
  3395. this.xref = xref;
  3396. this.objId = null;
  3397. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  3398. }
  3399. Dict.prototype = {
  3400. assignXref: function Dict_assignXref(newXref) {
  3401. this.xref = newXref;
  3402. },
  3403. // automatically dereferences Ref objects
  3404. get: function Dict_get(key1, key2, key3) {
  3405. var value;
  3406. var xref = this.xref;
  3407. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  3408. typeof key2 === 'undefined') {
  3409. return xref ? xref.fetchIfRef(value) : value;
  3410. }
  3411. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  3412. typeof key3 === 'undefined') {
  3413. return xref ? xref.fetchIfRef(value) : value;
  3414. }
  3415. value = this.map[key3] || null;
  3416. return xref ? xref.fetchIfRef(value) : value;
  3417. },
  3418. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  3419. getAsync: function Dict_getAsync(key1, key2, key3) {
  3420. var value;
  3421. var xref = this.xref;
  3422. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  3423. typeof key2 === 'undefined') {
  3424. if (xref) {
  3425. return xref.fetchIfRefAsync(value);
  3426. }
  3427. return Promise.resolve(value);
  3428. }
  3429. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  3430. typeof key3 === 'undefined') {
  3431. if (xref) {
  3432. return xref.fetchIfRefAsync(value);
  3433. }
  3434. return Promise.resolve(value);
  3435. }
  3436. value = this.map[key3] || null;
  3437. if (xref) {
  3438. return xref.fetchIfRefAsync(value);
  3439. }
  3440. return Promise.resolve(value);
  3441. },
  3442. // Same as get(), but dereferences all elements if the result is an Array.
  3443. getArray: function Dict_getArray(key1, key2, key3) {
  3444. var value = this.get(key1, key2, key3);
  3445. var xref = this.xref;
  3446. if (!isArray(value) || !xref) {
  3447. return value;
  3448. }
  3449. value = value.slice(); // Ensure that we don't modify the Dict data.
  3450. for (var i = 0, ii = value.length; i < ii; i++) {
  3451. if (!isRef(value[i])) {
  3452. continue;
  3453. }
  3454. value[i] = xref.fetch(value[i]);
  3455. }
  3456. return value;
  3457. },
  3458. // no dereferencing
  3459. getRaw: function Dict_getRaw(key) {
  3460. return this.map[key];
  3461. },
  3462. // creates new map and dereferences all Refs
  3463. getAll: function Dict_getAll() {
  3464. var all = Object.create(null);
  3465. var queue = null;
  3466. var key, obj;
  3467. for (key in this.map) {
  3468. obj = this.get(key);
  3469. if (obj instanceof Dict) {
  3470. if (isRecursionAllowedFor(obj)) {
  3471. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  3472. } else {
  3473. all[key] = this.getRaw(key);
  3474. }
  3475. } else {
  3476. all[key] = obj;
  3477. }
  3478. }
  3479. if (!queue) {
  3480. return all;
  3481. }
  3482. // trying to take cyclic references into the account
  3483. var processed = Object.create(null);
  3484. while (queue.length > 0) {
  3485. var item = queue.shift();
  3486. var itemObj = item.obj;
  3487. var objId = itemObj.objId;
  3488. if (objId && objId in processed) {
  3489. item.target[item.key] = processed[objId];
  3490. continue;
  3491. }
  3492. var dereferenced = Object.create(null);
  3493. for (key in itemObj.map) {
  3494. obj = itemObj.get(key);
  3495. if (obj instanceof Dict) {
  3496. if (isRecursionAllowedFor(obj)) {
  3497. queue.push({target: dereferenced, key: key, obj: obj});
  3498. } else {
  3499. dereferenced[key] = itemObj.getRaw(key);
  3500. }
  3501. } else {
  3502. dereferenced[key] = obj;
  3503. }
  3504. }
  3505. if (objId) {
  3506. processed[objId] = dereferenced;
  3507. }
  3508. item.target[item.key] = dereferenced;
  3509. }
  3510. return all;
  3511. },
  3512. getKeys: function Dict_getKeys() {
  3513. return Object.keys(this.map);
  3514. },
  3515. set: function Dict_set(key, value) {
  3516. this.map[key] = value;
  3517. },
  3518. has: function Dict_has(key) {
  3519. return key in this.map;
  3520. },
  3521. forEach: function Dict_forEach(callback) {
  3522. for (var key in this.map) {
  3523. callback(key, this.get(key));
  3524. }
  3525. }
  3526. };
  3527. Dict.empty = new Dict(null);
  3528. Dict.merge = function Dict_merge(xref, dictArray) {
  3529. var mergedDict = new Dict(xref);
  3530. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  3531. var dict = dictArray[i];
  3532. if (!isDict(dict)) {
  3533. continue;
  3534. }
  3535. for (var keyName in dict.map) {
  3536. if (mergedDict.map[keyName]) {
  3537. continue;
  3538. }
  3539. mergedDict.map[keyName] = dict.map[keyName];
  3540. }
  3541. }
  3542. return mergedDict;
  3543. };
  3544. return Dict;
  3545. })();
  3546. var Ref = (function RefClosure() {
  3547. function Ref(num, gen) {
  3548. this.num = num;
  3549. this.gen = gen;
  3550. }
  3551. Ref.prototype = {
  3552. toString: function Ref_toString() {
  3553. // This function is hot, so we make the string as compact as possible.
  3554. // |this.gen| is almost always zero, so we treat that case specially.
  3555. var str = this.num + 'R';
  3556. if (this.gen !== 0) {
  3557. str += this.gen;
  3558. }
  3559. return str;
  3560. }
  3561. };
  3562. return Ref;
  3563. })();
  3564. // The reference is identified by number and generation.
  3565. // This structure stores only one instance of the reference.
  3566. var RefSet = (function RefSetClosure() {
  3567. function RefSet() {
  3568. this.dict = {};
  3569. }
  3570. RefSet.prototype = {
  3571. has: function RefSet_has(ref) {
  3572. return ref.toString() in this.dict;
  3573. },
  3574. put: function RefSet_put(ref) {
  3575. this.dict[ref.toString()] = true;
  3576. },
  3577. remove: function RefSet_remove(ref) {
  3578. delete this.dict[ref.toString()];
  3579. }
  3580. };
  3581. return RefSet;
  3582. })();
  3583. var RefSetCache = (function RefSetCacheClosure() {
  3584. function RefSetCache() {
  3585. this.dict = Object.create(null);
  3586. }
  3587. RefSetCache.prototype = {
  3588. get: function RefSetCache_get(ref) {
  3589. return this.dict[ref.toString()];
  3590. },
  3591. has: function RefSetCache_has(ref) {
  3592. return ref.toString() in this.dict;
  3593. },
  3594. put: function RefSetCache_put(ref, obj) {
  3595. this.dict[ref.toString()] = obj;
  3596. },
  3597. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  3598. this.dict[ref.toString()] = this.get(aliasRef);
  3599. },
  3600. forEach: function RefSetCache_forEach(fn, thisArg) {
  3601. for (var i in this.dict) {
  3602. fn.call(thisArg, this.dict[i]);
  3603. }
  3604. },
  3605. clear: function RefSetCache_clear() {
  3606. this.dict = Object.create(null);
  3607. }
  3608. };
  3609. return RefSetCache;
  3610. })();
  3611. var Catalog = (function CatalogClosure() {
  3612. function Catalog(pdfManager, xref) {
  3613. this.pdfManager = pdfManager;
  3614. this.xref = xref;
  3615. this.catDict = xref.getCatalogObj();
  3616. this.fontCache = new RefSetCache();
  3617. assert(isDict(this.catDict),
  3618. 'catalog object is not a dictionary');
  3619. this.pagePromises = [];
  3620. }
  3621. Catalog.prototype = {
  3622. get metadata() {
  3623. var streamRef = this.catDict.getRaw('Metadata');
  3624. if (!isRef(streamRef)) {
  3625. return shadow(this, 'metadata', null);
  3626. }
  3627. var encryptMetadata = (!this.xref.encrypt ? false :
  3628. this.xref.encrypt.encryptMetadata);
  3629. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3630. var metadata;
  3631. if (stream && isDict(stream.dict)) {
  3632. var type = stream.dict.get('Type');
  3633. var subtype = stream.dict.get('Subtype');
  3634. if (isName(type) && isName(subtype) &&
  3635. type.name === 'Metadata' && subtype.name === 'XML') {
  3636. // XXX: This should examine the charset the XML document defines,
  3637. // however since there are currently no real means to decode
  3638. // arbitrary charsets, let's just hope that the author of the PDF
  3639. // was reasonable enough to stick with the XML default charset,
  3640. // which is UTF-8.
  3641. try {
  3642. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3643. } catch (e) {
  3644. info('Skipping invalid metadata.');
  3645. }
  3646. }
  3647. }
  3648. return shadow(this, 'metadata', metadata);
  3649. },
  3650. get toplevelPagesDict() {
  3651. var pagesObj = this.catDict.get('Pages');
  3652. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3653. // shadow the prototype getter
  3654. return shadow(this, 'toplevelPagesDict', pagesObj);
  3655. },
  3656. get documentOutline() {
  3657. var obj = null;
  3658. try {
  3659. obj = this.readDocumentOutline();
  3660. } catch (ex) {
  3661. if (ex instanceof MissingDataException) {
  3662. throw ex;
  3663. }
  3664. warn('Unable to read document outline');
  3665. }
  3666. return shadow(this, 'documentOutline', obj);
  3667. },
  3668. readDocumentOutline: function Catalog_readDocumentOutline() {
  3669. var xref = this.xref;
  3670. var obj = this.catDict.get('Outlines');
  3671. var root = { items: [] };
  3672. if (isDict(obj)) {
  3673. obj = obj.getRaw('First');
  3674. var processed = new RefSet();
  3675. if (isRef(obj)) {
  3676. var queue = [{obj: obj, parent: root}];
  3677. // to avoid recursion keeping track of the items
  3678. // in the processed dictionary
  3679. processed.put(obj);
  3680. while (queue.length > 0) {
  3681. var i = queue.shift();
  3682. var outlineDict = xref.fetchIfRef(i.obj);
  3683. if (outlineDict === null) {
  3684. continue;
  3685. }
  3686. if (!outlineDict.has('Title')) {
  3687. error('Invalid outline item');
  3688. }
  3689. var dest = outlineDict.get('A');
  3690. if (dest) {
  3691. dest = dest.get('D');
  3692. } else if (outlineDict.has('Dest')) {
  3693. dest = outlineDict.getRaw('Dest');
  3694. if (isName(dest)) {
  3695. dest = dest.name;
  3696. }
  3697. }
  3698. var title = outlineDict.get('Title');
  3699. var outlineItem = {
  3700. dest: dest,
  3701. title: stringToPDFString(title),
  3702. color: outlineDict.get('C') || [0, 0, 0],
  3703. count: outlineDict.get('Count'),
  3704. bold: !!(outlineDict.get('F') & 2),
  3705. italic: !!(outlineDict.get('F') & 1),
  3706. items: []
  3707. };
  3708. i.parent.items.push(outlineItem);
  3709. obj = outlineDict.getRaw('First');
  3710. if (isRef(obj) && !processed.has(obj)) {
  3711. queue.push({obj: obj, parent: outlineItem});
  3712. processed.put(obj);
  3713. }
  3714. obj = outlineDict.getRaw('Next');
  3715. if (isRef(obj) && !processed.has(obj)) {
  3716. queue.push({obj: obj, parent: i.parent});
  3717. processed.put(obj);
  3718. }
  3719. }
  3720. }
  3721. }
  3722. return (root.items.length > 0 ? root.items : null);
  3723. },
  3724. get numPages() {
  3725. var obj = this.toplevelPagesDict.get('Count');
  3726. assert(
  3727. isInt(obj),
  3728. 'page count in top level pages object is not an integer'
  3729. );
  3730. // shadow the prototype getter
  3731. return shadow(this, 'num', obj);
  3732. },
  3733. get destinations() {
  3734. function fetchDestination(dest) {
  3735. return isDict(dest) ? dest.get('D') : dest;
  3736. }
  3737. var xref = this.xref;
  3738. var dests = {}, nameTreeRef, nameDictionaryRef;
  3739. var obj = this.catDict.get('Names');
  3740. if (obj && obj.has('Dests')) {
  3741. nameTreeRef = obj.getRaw('Dests');
  3742. } else if (this.catDict.has('Dests')) {
  3743. nameDictionaryRef = this.catDict.get('Dests');
  3744. }
  3745. if (nameDictionaryRef) {
  3746. // reading simple destination dictionary
  3747. obj = nameDictionaryRef;
  3748. obj.forEach(function catalogForEach(key, value) {
  3749. if (!value) {
  3750. return;
  3751. }
  3752. dests[key] = fetchDestination(value);
  3753. });
  3754. }
  3755. if (nameTreeRef) {
  3756. var nameTree = new NameTree(nameTreeRef, xref);
  3757. var names = nameTree.getAll();
  3758. for (var name in names) {
  3759. if (!names.hasOwnProperty(name)) {
  3760. continue;
  3761. }
  3762. dests[name] = fetchDestination(names[name]);
  3763. }
  3764. }
  3765. return shadow(this, 'destinations', dests);
  3766. },
  3767. getDestination: function Catalog_getDestination(destinationId) {
  3768. function fetchDestination(dest) {
  3769. return isDict(dest) ? dest.get('D') : dest;
  3770. }
  3771. var xref = this.xref;
  3772. var dest = null, nameTreeRef, nameDictionaryRef;
  3773. var obj = this.catDict.get('Names');
  3774. if (obj && obj.has('Dests')) {
  3775. nameTreeRef = obj.getRaw('Dests');
  3776. } else if (this.catDict.has('Dests')) {
  3777. nameDictionaryRef = this.catDict.get('Dests');
  3778. }
  3779. if (nameDictionaryRef) { // Simple destination dictionary.
  3780. var value = nameDictionaryRef.get(destinationId);
  3781. if (value) {
  3782. dest = fetchDestination(value);
  3783. }
  3784. }
  3785. if (nameTreeRef) {
  3786. var nameTree = new NameTree(nameTreeRef, xref);
  3787. dest = fetchDestination(nameTree.get(destinationId));
  3788. }
  3789. return dest;
  3790. },
  3791. get attachments() {
  3792. var xref = this.xref;
  3793. var attachments = null, nameTreeRef;
  3794. var obj = this.catDict.get('Names');
  3795. if (obj) {
  3796. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3797. }
  3798. if (nameTreeRef) {
  3799. var nameTree = new NameTree(nameTreeRef, xref);
  3800. var names = nameTree.getAll();
  3801. for (var name in names) {
  3802. if (!names.hasOwnProperty(name)) {
  3803. continue;
  3804. }
  3805. var fs = new FileSpec(names[name], xref);
  3806. if (!attachments) {
  3807. attachments = {};
  3808. }
  3809. attachments[stringToPDFString(name)] = fs.serializable;
  3810. }
  3811. }
  3812. return shadow(this, 'attachments', attachments);
  3813. },
  3814. get javaScript() {
  3815. var xref = this.xref;
  3816. var obj = this.catDict.get('Names');
  3817. var javaScript = [];
  3818. function appendIfJavaScriptDict(jsDict) {
  3819. var type = jsDict.get('S');
  3820. if (!isName(type) || type.name !== 'JavaScript') {
  3821. return;
  3822. }
  3823. var js = jsDict.get('JS');
  3824. if (isStream(js)) {
  3825. js = bytesToString(js.getBytes());
  3826. } else if (!isString(js)) {
  3827. return;
  3828. }
  3829. javaScript.push(stringToPDFString(js));
  3830. }
  3831. if (obj && obj.has('JavaScript')) {
  3832. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3833. var names = nameTree.getAll();
  3834. for (var name in names) {
  3835. if (!names.hasOwnProperty(name)) {
  3836. continue;
  3837. }
  3838. // We don't really use the JavaScript right now. This code is
  3839. // defensive so we don't cause errors on document load.
  3840. var jsDict = names[name];
  3841. if (isDict(jsDict)) {
  3842. appendIfJavaScriptDict(jsDict);
  3843. }
  3844. }
  3845. }
  3846. // Append OpenAction actions to javaScript array
  3847. var openactionDict = this.catDict.get('OpenAction');
  3848. if (isDict(openactionDict, 'Action')) {
  3849. var actionType = openactionDict.get('S');
  3850. if (isName(actionType) && actionType.name === 'Named') {
  3851. // The named Print action is not a part of the PDF 1.7 specification,
  3852. // but is supported by many PDF readers/writers (including Adobe's).
  3853. var action = openactionDict.get('N');
  3854. if (isName(action) && action.name === 'Print') {
  3855. javaScript.push('print({});');
  3856. }
  3857. } else {
  3858. appendIfJavaScriptDict(openactionDict);
  3859. }
  3860. }
  3861. return shadow(this, 'javaScript', javaScript);
  3862. },
  3863. cleanup: function Catalog_cleanup() {
  3864. var promises = [];
  3865. this.fontCache.forEach(function (promise) {
  3866. promises.push(promise);
  3867. });
  3868. return Promise.all(promises).then(function (translatedFonts) {
  3869. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3870. var font = translatedFonts[i].dict;
  3871. delete font.translated;
  3872. }
  3873. this.fontCache.clear();
  3874. }.bind(this));
  3875. },
  3876. getPage: function Catalog_getPage(pageIndex) {
  3877. if (!(pageIndex in this.pagePromises)) {
  3878. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3879. function (a) {
  3880. var dict = a[0];
  3881. var ref = a[1];
  3882. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3883. this.fontCache);
  3884. }.bind(this)
  3885. );
  3886. }
  3887. return this.pagePromises[pageIndex];
  3888. },
  3889. getPageDict: function Catalog_getPageDict(pageIndex) {
  3890. var capability = createPromiseCapability();
  3891. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3892. var currentPageIndex = 0;
  3893. var xref = this.xref;
  3894. var checkAllKids = false;
  3895. function next() {
  3896. while (nodesToVisit.length) {
  3897. var currentNode = nodesToVisit.pop();
  3898. if (isRef(currentNode)) {
  3899. xref.fetchAsync(currentNode).then(function (obj) {
  3900. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3901. if (pageIndex === currentPageIndex) {
  3902. capability.resolve([obj, currentNode]);
  3903. } else {
  3904. currentPageIndex++;
  3905. next();
  3906. }
  3907. return;
  3908. }
  3909. nodesToVisit.push(obj);
  3910. next();
  3911. }, capability.reject);
  3912. return;
  3913. }
  3914. // Must be a child page dictionary.
  3915. assert(
  3916. isDict(currentNode),
  3917. 'page dictionary kid reference points to wrong type of object'
  3918. );
  3919. var count = currentNode.get('Count');
  3920. // If the current node doesn't have any children, avoid getting stuck
  3921. // in an empty node further down in the tree (see issue5644.pdf).
  3922. if (count === 0) {
  3923. checkAllKids = true;
  3924. }
  3925. // Skip nodes where the page can't be.
  3926. if (currentPageIndex + count <= pageIndex) {
  3927. currentPageIndex += count;
  3928. continue;
  3929. }
  3930. var kids = currentNode.get('Kids');
  3931. assert(isArray(kids), 'page dictionary kids object is not an array');
  3932. if (!checkAllKids && count === kids.length) {
  3933. // Nodes that don't have the page have been skipped and this is the
  3934. // bottom of the tree which means the page requested must be a
  3935. // descendant of this pages node. Ideally we would just resolve the
  3936. // promise with the page ref here, but there is the case where more
  3937. // pages nodes could link to single a page (see issue 3666 pdf). To
  3938. // handle this push it back on the queue so if it is a pages node it
  3939. // will be descended into.
  3940. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3941. currentPageIndex = pageIndex;
  3942. continue;
  3943. } else {
  3944. for (var last = kids.length - 1; last >= 0; last--) {
  3945. nodesToVisit.push(kids[last]);
  3946. }
  3947. }
  3948. }
  3949. capability.reject('Page index ' + pageIndex + ' not found.');
  3950. }
  3951. next();
  3952. return capability.promise;
  3953. },
  3954. getPageIndex: function Catalog_getPageIndex(ref) {
  3955. // The page tree nodes have the count of all the leaves below them. To get
  3956. // how many pages are before we just have to walk up the tree and keep
  3957. // adding the count of siblings to the left of the node.
  3958. var xref = this.xref;
  3959. function pagesBeforeRef(kidRef) {
  3960. var total = 0;
  3961. var parentRef;
  3962. return xref.fetchAsync(kidRef).then(function (node) {
  3963. if (!node) {
  3964. return null;
  3965. }
  3966. parentRef = node.getRaw('Parent');
  3967. return node.getAsync('Parent');
  3968. }).then(function (parent) {
  3969. if (!parent) {
  3970. return null;
  3971. }
  3972. return parent.getAsync('Kids');
  3973. }).then(function (kids) {
  3974. if (!kids) {
  3975. return null;
  3976. }
  3977. var kidPromises = [];
  3978. var found = false;
  3979. for (var i = 0; i < kids.length; i++) {
  3980. var kid = kids[i];
  3981. assert(isRef(kid), 'kids must be a ref');
  3982. if (kid.num === kidRef.num) {
  3983. found = true;
  3984. break;
  3985. }
  3986. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3987. if (kid.has('Count')) {
  3988. var count = kid.get('Count');
  3989. total += count;
  3990. } else { // page leaf node
  3991. total++;
  3992. }
  3993. }));
  3994. }
  3995. if (!found) {
  3996. error('kid ref not found in parents kids');
  3997. }
  3998. return Promise.all(kidPromises).then(function () {
  3999. return [total, parentRef];
  4000. });
  4001. });
  4002. }
  4003. var total = 0;
  4004. function next(ref) {
  4005. return pagesBeforeRef(ref).then(function (args) {
  4006. if (!args) {
  4007. return total;
  4008. }
  4009. var count = args[0];
  4010. var parentRef = args[1];
  4011. total += count;
  4012. return next(parentRef);
  4013. });
  4014. }
  4015. return next(ref);
  4016. }
  4017. };
  4018. return Catalog;
  4019. })();
  4020. var XRef = (function XRefClosure() {
  4021. function XRef(stream, password) {
  4022. this.stream = stream;
  4023. this.entries = [];
  4024. this.xrefstms = {};
  4025. // prepare the XRef cache
  4026. this.cache = [];
  4027. this.password = password;
  4028. this.stats = {
  4029. streamTypes: [],
  4030. fontTypes: []
  4031. };
  4032. }
  4033. XRef.prototype = {
  4034. setStartXRef: function XRef_setStartXRef(startXRef) {
  4035. // Store the starting positions of xref tables as we process them
  4036. // so we can recover from missing data errors
  4037. this.startXRefQueue = [startXRef];
  4038. },
  4039. parse: function XRef_parse(recoveryMode) {
  4040. var trailerDict;
  4041. if (!recoveryMode) {
  4042. trailerDict = this.readXRef();
  4043. } else {
  4044. warn('Indexing all PDF objects');
  4045. trailerDict = this.indexObjects();
  4046. }
  4047. trailerDict.assignXref(this);
  4048. this.trailer = trailerDict;
  4049. var encrypt = trailerDict.get('Encrypt');
  4050. if (encrypt) {
  4051. var ids = trailerDict.get('ID');
  4052. var fileId = (ids && ids.length) ? ids[0] : '';
  4053. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  4054. this.password);
  4055. }
  4056. // get the root dictionary (catalog) object
  4057. if (!(this.root = trailerDict.get('Root'))) {
  4058. error('Invalid root reference');
  4059. }
  4060. },
  4061. processXRefTable: function XRef_processXRefTable(parser) {
  4062. if (!('tableState' in this)) {
  4063. // Stores state of the table as we process it so we can resume
  4064. // from middle of table in case of missing data error
  4065. this.tableState = {
  4066. entryNum: 0,
  4067. streamPos: parser.lexer.stream.pos,
  4068. parserBuf1: parser.buf1,
  4069. parserBuf2: parser.buf2
  4070. };
  4071. }
  4072. var obj = this.readXRefTable(parser);
  4073. // Sanity check
  4074. if (!isCmd(obj, 'trailer')) {
  4075. error('Invalid XRef table: could not find trailer dictionary');
  4076. }
  4077. // Read trailer dictionary, e.g.
  4078. // trailer
  4079. // << /Size 22
  4080. // /Root 20R
  4081. // /Info 10R
  4082. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  4083. // >>
  4084. // The parser goes through the entire stream << ... >> and provides
  4085. // a getter interface for the key-value table
  4086. var dict = parser.getObj();
  4087. // The pdflib PDF generator can generate a nested trailer dictionary
  4088. if (!isDict(dict) && dict.dict) {
  4089. dict = dict.dict;
  4090. }
  4091. if (!isDict(dict)) {
  4092. error('Invalid XRef table: could not parse trailer dictionary');
  4093. }
  4094. delete this.tableState;
  4095. return dict;
  4096. },
  4097. readXRefTable: function XRef_readXRefTable(parser) {
  4098. // Example of cross-reference table:
  4099. // xref
  4100. // 0 1 <-- subsection header (first obj #, obj count)
  4101. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  4102. // 23 2 <-- subsection header ... and so on ...
  4103. // 0000025518 00002 n
  4104. // 0000025635 00000 n
  4105. // trailer
  4106. // ...
  4107. var stream = parser.lexer.stream;
  4108. var tableState = this.tableState;
  4109. stream.pos = tableState.streamPos;
  4110. parser.buf1 = tableState.parserBuf1;
  4111. parser.buf2 = tableState.parserBuf2;
  4112. // Outer loop is over subsection headers
  4113. var obj;
  4114. while (true) {
  4115. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  4116. if (isCmd(obj = parser.getObj(), 'trailer')) {
  4117. break;
  4118. }
  4119. tableState.firstEntryNum = obj;
  4120. tableState.entryCount = parser.getObj();
  4121. }
  4122. var first = tableState.firstEntryNum;
  4123. var count = tableState.entryCount;
  4124. if (!isInt(first) || !isInt(count)) {
  4125. error('Invalid XRef table: wrong types in subsection header');
  4126. }
  4127. // Inner loop is over objects themselves
  4128. for (var i = tableState.entryNum; i < count; i++) {
  4129. tableState.streamPos = stream.pos;
  4130. tableState.entryNum = i;
  4131. tableState.parserBuf1 = parser.buf1;
  4132. tableState.parserBuf2 = parser.buf2;
  4133. var entry = {};
  4134. entry.offset = parser.getObj();
  4135. entry.gen = parser.getObj();
  4136. var type = parser.getObj();
  4137. if (isCmd(type, 'f')) {
  4138. entry.free = true;
  4139. } else if (isCmd(type, 'n')) {
  4140. entry.uncompressed = true;
  4141. }
  4142. // Validate entry obj
  4143. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  4144. !(entry.free || entry.uncompressed)) {
  4145. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  4146. }
  4147. if (!this.entries[i + first]) {
  4148. this.entries[i + first] = entry;
  4149. }
  4150. }
  4151. tableState.entryNum = 0;
  4152. tableState.streamPos = stream.pos;
  4153. tableState.parserBuf1 = parser.buf1;
  4154. tableState.parserBuf2 = parser.buf2;
  4155. delete tableState.firstEntryNum;
  4156. delete tableState.entryCount;
  4157. }
  4158. // Per issue 3248: hp scanners generate bad XRef
  4159. if (first === 1 && this.entries[1] && this.entries[1].free) {
  4160. // shifting the entries
  4161. this.entries.shift();
  4162. }
  4163. // Sanity check: as per spec, first object must be free
  4164. if (this.entries[0] && !this.entries[0].free) {
  4165. error('Invalid XRef table: unexpected first object');
  4166. }
  4167. return obj;
  4168. },
  4169. processXRefStream: function XRef_processXRefStream(stream) {
  4170. if (!('streamState' in this)) {
  4171. // Stores state of the stream as we process it so we can resume
  4172. // from middle of stream in case of missing data error
  4173. var streamParameters = stream.dict;
  4174. var byteWidths = streamParameters.get('W');
  4175. var range = streamParameters.get('Index');
  4176. if (!range) {
  4177. range = [0, streamParameters.get('Size')];
  4178. }
  4179. this.streamState = {
  4180. entryRanges: range,
  4181. byteWidths: byteWidths,
  4182. entryNum: 0,
  4183. streamPos: stream.pos
  4184. };
  4185. }
  4186. this.readXRefStream(stream);
  4187. delete this.streamState;
  4188. return stream.dict;
  4189. },
  4190. readXRefStream: function XRef_readXRefStream(stream) {
  4191. var i, j;
  4192. var streamState = this.streamState;
  4193. stream.pos = streamState.streamPos;
  4194. var byteWidths = streamState.byteWidths;
  4195. var typeFieldWidth = byteWidths[0];
  4196. var offsetFieldWidth = byteWidths[1];
  4197. var generationFieldWidth = byteWidths[2];
  4198. var entryRanges = streamState.entryRanges;
  4199. while (entryRanges.length > 0) {
  4200. var first = entryRanges[0];
  4201. var n = entryRanges[1];
  4202. if (!isInt(first) || !isInt(n)) {
  4203. error('Invalid XRef range fields: ' + first + ', ' + n);
  4204. }
  4205. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  4206. !isInt(generationFieldWidth)) {
  4207. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  4208. }
  4209. for (i = streamState.entryNum; i < n; ++i) {
  4210. streamState.entryNum = i;
  4211. streamState.streamPos = stream.pos;
  4212. var type = 0, offset = 0, generation = 0;
  4213. for (j = 0; j < typeFieldWidth; ++j) {
  4214. type = (type << 8) | stream.getByte();
  4215. }
  4216. // if type field is absent, its default value is 1
  4217. if (typeFieldWidth === 0) {
  4218. type = 1;
  4219. }
  4220. for (j = 0; j < offsetFieldWidth; ++j) {
  4221. offset = (offset << 8) | stream.getByte();
  4222. }
  4223. for (j = 0; j < generationFieldWidth; ++j) {
  4224. generation = (generation << 8) | stream.getByte();
  4225. }
  4226. var entry = {};
  4227. entry.offset = offset;
  4228. entry.gen = generation;
  4229. switch (type) {
  4230. case 0:
  4231. entry.free = true;
  4232. break;
  4233. case 1:
  4234. entry.uncompressed = true;
  4235. break;
  4236. case 2:
  4237. break;
  4238. default:
  4239. error('Invalid XRef entry type: ' + type);
  4240. }
  4241. if (!this.entries[first + i]) {
  4242. this.entries[first + i] = entry;
  4243. }
  4244. }
  4245. streamState.entryNum = 0;
  4246. streamState.streamPos = stream.pos;
  4247. entryRanges.splice(0, 2);
  4248. }
  4249. },
  4250. indexObjects: function XRef_indexObjects() {
  4251. // Simple scan through the PDF content to find objects,
  4252. // trailers and XRef streams.
  4253. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  4254. var PERCENT = 0x25, LT = 0x3C;
  4255. function readToken(data, offset) {
  4256. var token = '', ch = data[offset];
  4257. while (ch !== LF && ch !== CR && ch !== LT) {
  4258. if (++offset >= data.length) {
  4259. break;
  4260. }
  4261. token += String.fromCharCode(ch);
  4262. ch = data[offset];
  4263. }
  4264. return token;
  4265. }
  4266. function skipUntil(data, offset, what) {
  4267. var length = what.length, dataLength = data.length;
  4268. var skipped = 0;
  4269. // finding byte sequence
  4270. while (offset < dataLength) {
  4271. var i = 0;
  4272. while (i < length && data[offset + i] === what[i]) {
  4273. ++i;
  4274. }
  4275. if (i >= length) {
  4276. break; // sequence found
  4277. }
  4278. offset++;
  4279. skipped++;
  4280. }
  4281. return skipped;
  4282. }
  4283. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  4284. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  4285. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  4286. 101, 102]);
  4287. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  4288. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  4289. // Clear out any existing entries, since they may be bogus.
  4290. this.entries.length = 0;
  4291. var stream = this.stream;
  4292. stream.pos = 0;
  4293. var buffer = stream.getBytes();
  4294. var position = stream.start, length = buffer.length;
  4295. var trailers = [], xrefStms = [];
  4296. while (position < length) {
  4297. var ch = buffer[position];
  4298. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  4299. ++position;
  4300. continue;
  4301. }
  4302. if (ch === PERCENT) { // %-comment
  4303. do {
  4304. ++position;
  4305. if (position >= length) {
  4306. break;
  4307. }
  4308. ch = buffer[position];
  4309. } while (ch !== LF && ch !== CR);
  4310. continue;
  4311. }
  4312. var token = readToken(buffer, position);
  4313. var m;
  4314. if (token.indexOf('xref') === 0 &&
  4315. (token.length === 4 || /\s/.test(token[4]))) {
  4316. position += skipUntil(buffer, position, trailerBytes);
  4317. trailers.push(position);
  4318. position += skipUntil(buffer, position, startxrefBytes);
  4319. } else if ((m = objRegExp.exec(token))) {
  4320. if (typeof this.entries[m[1]] === 'undefined') {
  4321. this.entries[m[1]] = {
  4322. offset: position - stream.start,
  4323. gen: m[2] | 0,
  4324. uncompressed: true
  4325. };
  4326. }
  4327. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  4328. var content = buffer.subarray(position, position + contentLength);
  4329. // checking XRef stream suspect
  4330. // (it shall have '/XRef' and next char is not a letter)
  4331. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  4332. if (xrefTagOffset < contentLength &&
  4333. content[xrefTagOffset + 5] < 64) {
  4334. xrefStms.push(position - stream.start);
  4335. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  4336. }
  4337. position += contentLength;
  4338. } else if (token.indexOf('trailer') === 0 &&
  4339. (token.length === 7 || /\s/.test(token[7]))) {
  4340. trailers.push(position);
  4341. position += skipUntil(buffer, position, startxrefBytes);
  4342. } else {
  4343. position += token.length + 1;
  4344. }
  4345. }
  4346. // reading XRef streams
  4347. var i, ii;
  4348. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  4349. this.startXRefQueue.push(xrefStms[i]);
  4350. this.readXRef(/* recoveryMode */ true);
  4351. }
  4352. // finding main trailer
  4353. var dict;
  4354. for (i = 0, ii = trailers.length; i < ii; ++i) {
  4355. stream.pos = trailers[i];
  4356. var parser = new Parser(new Lexer(stream), true, this);
  4357. var obj = parser.getObj();
  4358. if (!isCmd(obj, 'trailer')) {
  4359. continue;
  4360. }
  4361. // read the trailer dictionary
  4362. if (!isDict(dict = parser.getObj())) {
  4363. continue;
  4364. }
  4365. // taking the first one with 'ID'
  4366. if (dict.has('ID')) {
  4367. return dict;
  4368. }
  4369. }
  4370. // no tailer with 'ID', taking last one (if exists)
  4371. if (dict) {
  4372. return dict;
  4373. }
  4374. // nothing helps
  4375. // calling error() would reject worker with an UnknownErrorException.
  4376. throw new InvalidPDFException('Invalid PDF structure');
  4377. },
  4378. readXRef: function XRef_readXRef(recoveryMode) {
  4379. var stream = this.stream;
  4380. try {
  4381. while (this.startXRefQueue.length) {
  4382. var startXRef = this.startXRefQueue[0];
  4383. stream.pos = startXRef + stream.start;
  4384. var parser = new Parser(new Lexer(stream), true, this);
  4385. var obj = parser.getObj();
  4386. var dict;
  4387. // Get dictionary
  4388. if (isCmd(obj, 'xref')) {
  4389. // Parse end-of-file XRef
  4390. dict = this.processXRefTable(parser);
  4391. if (!this.topDict) {
  4392. this.topDict = dict;
  4393. }
  4394. // Recursively get other XRefs 'XRefStm', if any
  4395. obj = dict.get('XRefStm');
  4396. if (isInt(obj)) {
  4397. var pos = obj;
  4398. // ignore previously loaded xref streams
  4399. // (possible infinite recursion)
  4400. if (!(pos in this.xrefstms)) {
  4401. this.xrefstms[pos] = 1;
  4402. this.startXRefQueue.push(pos);
  4403. }
  4404. }
  4405. } else if (isInt(obj)) {
  4406. // Parse in-stream XRef
  4407. if (!isInt(parser.getObj()) ||
  4408. !isCmd(parser.getObj(), 'obj') ||
  4409. !isStream(obj = parser.getObj())) {
  4410. error('Invalid XRef stream');
  4411. }
  4412. dict = this.processXRefStream(obj);
  4413. if (!this.topDict) {
  4414. this.topDict = dict;
  4415. }
  4416. if (!dict) {
  4417. error('Failed to read XRef stream');
  4418. }
  4419. } else {
  4420. error('Invalid XRef stream header');
  4421. }
  4422. // Recursively get previous dictionary, if any
  4423. obj = dict.get('Prev');
  4424. if (isInt(obj)) {
  4425. this.startXRefQueue.push(obj);
  4426. } else if (isRef(obj)) {
  4427. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  4428. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  4429. this.startXRefQueue.push(obj.num);
  4430. }
  4431. this.startXRefQueue.shift();
  4432. }
  4433. return this.topDict;
  4434. } catch (e) {
  4435. if (e instanceof MissingDataException) {
  4436. throw e;
  4437. }
  4438. info('(while reading XRef): ' + e);
  4439. }
  4440. if (recoveryMode) {
  4441. return;
  4442. }
  4443. throw new XRefParseException();
  4444. },
  4445. getEntry: function XRef_getEntry(i) {
  4446. var xrefEntry = this.entries[i];
  4447. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  4448. return xrefEntry;
  4449. }
  4450. return null;
  4451. },
  4452. fetchIfRef: function XRef_fetchIfRef(obj) {
  4453. if (!isRef(obj)) {
  4454. return obj;
  4455. }
  4456. return this.fetch(obj);
  4457. },
  4458. fetch: function XRef_fetch(ref, suppressEncryption) {
  4459. assert(isRef(ref), 'ref object is not a reference');
  4460. var num = ref.num;
  4461. if (num in this.cache) {
  4462. var cacheEntry = this.cache[num];
  4463. return cacheEntry;
  4464. }
  4465. var xrefEntry = this.getEntry(num);
  4466. // the referenced entry can be free
  4467. if (xrefEntry === null) {
  4468. return (this.cache[num] = null);
  4469. }
  4470. if (xrefEntry.uncompressed) {
  4471. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  4472. } else {
  4473. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  4474. }
  4475. if (isDict(xrefEntry)){
  4476. xrefEntry.objId = ref.toString();
  4477. } else if (isStream(xrefEntry)) {
  4478. xrefEntry.dict.objId = ref.toString();
  4479. }
  4480. return xrefEntry;
  4481. },
  4482. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  4483. suppressEncryption) {
  4484. var gen = ref.gen;
  4485. var num = ref.num;
  4486. if (xrefEntry.gen !== gen) {
  4487. error('inconsistent generation in XRef');
  4488. }
  4489. var stream = this.stream.makeSubStream(xrefEntry.offset +
  4490. this.stream.start);
  4491. var parser = new Parser(new Lexer(stream), true, this);
  4492. var obj1 = parser.getObj();
  4493. var obj2 = parser.getObj();
  4494. var obj3 = parser.getObj();
  4495. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  4496. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  4497. !isCmd(obj3)) {
  4498. error('bad XRef entry');
  4499. }
  4500. if (!isCmd(obj3, 'obj')) {
  4501. // some bad PDFs use "obj1234" and really mean 1234
  4502. if (obj3.cmd.indexOf('obj') === 0) {
  4503. num = parseInt(obj3.cmd.substring(3), 10);
  4504. if (!isNaN(num)) {
  4505. return num;
  4506. }
  4507. }
  4508. error('bad XRef entry');
  4509. }
  4510. if (this.encrypt && !suppressEncryption) {
  4511. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  4512. } else {
  4513. xrefEntry = parser.getObj();
  4514. }
  4515. if (!isStream(xrefEntry)) {
  4516. this.cache[num] = xrefEntry;
  4517. }
  4518. return xrefEntry;
  4519. },
  4520. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  4521. suppressEncryption) {
  4522. var tableOffset = xrefEntry.offset;
  4523. var stream = this.fetch(new Ref(tableOffset, 0));
  4524. if (!isStream(stream)) {
  4525. error('bad ObjStm stream');
  4526. }
  4527. var first = stream.dict.get('First');
  4528. var n = stream.dict.get('N');
  4529. if (!isInt(first) || !isInt(n)) {
  4530. error('invalid first and n parameters for ObjStm stream');
  4531. }
  4532. var parser = new Parser(new Lexer(stream), false, this);
  4533. parser.allowStreams = true;
  4534. var i, entries = [], num, nums = [];
  4535. // read the object numbers to populate cache
  4536. for (i = 0; i < n; ++i) {
  4537. num = parser.getObj();
  4538. if (!isInt(num)) {
  4539. error('invalid object number in the ObjStm stream: ' + num);
  4540. }
  4541. nums.push(num);
  4542. var offset = parser.getObj();
  4543. if (!isInt(offset)) {
  4544. error('invalid object offset in the ObjStm stream: ' + offset);
  4545. }
  4546. }
  4547. // read stream objects for cache
  4548. for (i = 0; i < n; ++i) {
  4549. entries.push(parser.getObj());
  4550. num = nums[i];
  4551. var entry = this.entries[num];
  4552. if (entry && entry.offset === tableOffset && entry.gen === i) {
  4553. this.cache[num] = entries[i];
  4554. }
  4555. }
  4556. xrefEntry = entries[xrefEntry.gen];
  4557. if (xrefEntry === undefined) {
  4558. error('bad XRef entry for compressed object');
  4559. }
  4560. return xrefEntry;
  4561. },
  4562. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  4563. if (!isRef(obj)) {
  4564. return Promise.resolve(obj);
  4565. }
  4566. return this.fetchAsync(obj);
  4567. },
  4568. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  4569. var streamManager = this.stream.manager;
  4570. var xref = this;
  4571. return new Promise(function tryFetch(resolve, reject) {
  4572. try {
  4573. resolve(xref.fetch(ref, suppressEncryption));
  4574. } catch (e) {
  4575. if (e instanceof MissingDataException) {
  4576. streamManager.requestRange(e.begin, e.end).then(function () {
  4577. tryFetch(resolve, reject);
  4578. }, reject);
  4579. return;
  4580. }
  4581. reject(e);
  4582. }
  4583. });
  4584. },
  4585. getCatalogObj: function XRef_getCatalogObj() {
  4586. return this.root;
  4587. }
  4588. };
  4589. return XRef;
  4590. })();
  4591. /**
  4592. * A NameTree is like a Dict but has some advantageous properties, see the
  4593. * spec (7.9.6) for more details.
  4594. * TODO: implement all the Dict functions and make this more efficent.
  4595. */
  4596. var NameTree = (function NameTreeClosure() {
  4597. function NameTree(root, xref) {
  4598. this.root = root;
  4599. this.xref = xref;
  4600. }
  4601. NameTree.prototype = {
  4602. getAll: function NameTree_getAll() {
  4603. var dict = {};
  4604. if (!this.root) {
  4605. return dict;
  4606. }
  4607. var xref = this.xref;
  4608. // reading name tree
  4609. var processed = new RefSet();
  4610. processed.put(this.root);
  4611. var queue = [this.root];
  4612. while (queue.length > 0) {
  4613. var i, n;
  4614. var obj = xref.fetchIfRef(queue.shift());
  4615. if (!isDict(obj)) {
  4616. continue;
  4617. }
  4618. if (obj.has('Kids')) {
  4619. var kids = obj.get('Kids');
  4620. for (i = 0, n = kids.length; i < n; i++) {
  4621. var kid = kids[i];
  4622. if (processed.has(kid)) {
  4623. error('invalid destinations');
  4624. }
  4625. queue.push(kid);
  4626. processed.put(kid);
  4627. }
  4628. continue;
  4629. }
  4630. var names = obj.get('Names');
  4631. if (names) {
  4632. for (i = 0, n = names.length; i < n; i += 2) {
  4633. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  4634. }
  4635. }
  4636. }
  4637. return dict;
  4638. },
  4639. get: function NameTree_get(destinationId) {
  4640. if (!this.root) {
  4641. return null;
  4642. }
  4643. var xref = this.xref;
  4644. var kidsOrNames = xref.fetchIfRef(this.root);
  4645. var loopCount = 0;
  4646. var MAX_NAMES_LEVELS = 10;
  4647. var l, r, m;
  4648. // Perform a binary search to quickly find the entry that
  4649. // contains the named destination we are looking for.
  4650. while (kidsOrNames.has('Kids')) {
  4651. loopCount++;
  4652. if (loopCount > MAX_NAMES_LEVELS) {
  4653. warn('Search depth limit for named destionations has been reached.');
  4654. return null;
  4655. }
  4656. var kids = kidsOrNames.get('Kids');
  4657. if (!isArray(kids)) {
  4658. return null;
  4659. }
  4660. l = 0;
  4661. r = kids.length - 1;
  4662. while (l <= r) {
  4663. m = (l + r) >> 1;
  4664. var kid = xref.fetchIfRef(kids[m]);
  4665. var limits = kid.get('Limits');
  4666. if (destinationId < xref.fetchIfRef(limits[0])) {
  4667. r = m - 1;
  4668. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  4669. l = m + 1;
  4670. } else {
  4671. kidsOrNames = xref.fetchIfRef(kids[m]);
  4672. break;
  4673. }
  4674. }
  4675. if (l > r) {
  4676. return null;
  4677. }
  4678. }
  4679. // If we get here, then we have found the right entry. Now
  4680. // go through the named destinations in the Named dictionary
  4681. // until we find the exact destination we're looking for.
  4682. var names = kidsOrNames.get('Names');
  4683. if (isArray(names)) {
  4684. // Perform a binary search to reduce the lookup time.
  4685. l = 0;
  4686. r = names.length - 2;
  4687. while (l <= r) {
  4688. // Check only even indices (0, 2, 4, ...) because the
  4689. // odd indices contain the actual D array.
  4690. m = (l + r) & ~1;
  4691. if (destinationId < xref.fetchIfRef(names[m])) {
  4692. r = m - 2;
  4693. } else if (destinationId > xref.fetchIfRef(names[m])) {
  4694. l = m + 2;
  4695. } else {
  4696. return xref.fetchIfRef(names[m + 1]);
  4697. }
  4698. }
  4699. }
  4700. return null;
  4701. }
  4702. };
  4703. return NameTree;
  4704. })();
  4705. /**
  4706. * "A PDF file can refer to the contents of another file by using a File
  4707. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4708. * NOTE: Only embedded files are supported (as part of the attachments support)
  4709. * TODO: support the 'URL' file system (with caching if !/V), portable
  4710. * collections attributes and related files (/RF)
  4711. */
  4712. var FileSpec = (function FileSpecClosure() {
  4713. function FileSpec(root, xref) {
  4714. if (!root || !isDict(root)) {
  4715. return;
  4716. }
  4717. this.xref = xref;
  4718. this.root = root;
  4719. if (root.has('FS')) {
  4720. this.fs = root.get('FS');
  4721. }
  4722. this.description = root.has('Desc') ?
  4723. stringToPDFString(root.get('Desc')) :
  4724. '';
  4725. if (root.has('RF')) {
  4726. warn('Related file specifications are not supported');
  4727. }
  4728. this.contentAvailable = true;
  4729. if (!root.has('EF')) {
  4730. this.contentAvailable = false;
  4731. warn('Non-embedded file specifications are not supported');
  4732. }
  4733. }
  4734. function pickPlatformItem(dict) {
  4735. // Look for the filename in this order:
  4736. // UF, F, Unix, Mac, DOS
  4737. if (dict.has('UF')) {
  4738. return dict.get('UF');
  4739. } else if (dict.has('F')) {
  4740. return dict.get('F');
  4741. } else if (dict.has('Unix')) {
  4742. return dict.get('Unix');
  4743. } else if (dict.has('Mac')) {
  4744. return dict.get('Mac');
  4745. } else if (dict.has('DOS')) {
  4746. return dict.get('DOS');
  4747. } else {
  4748. return null;
  4749. }
  4750. }
  4751. FileSpec.prototype = {
  4752. get filename() {
  4753. if (!this._filename && this.root) {
  4754. var filename = pickPlatformItem(this.root) || 'unnamed';
  4755. this._filename = stringToPDFString(filename).
  4756. replace(/\\\\/g, '\\').
  4757. replace(/\\\//g, '/').
  4758. replace(/\\/g, '/');
  4759. }
  4760. return this._filename;
  4761. },
  4762. get content() {
  4763. if (!this.contentAvailable) {
  4764. return null;
  4765. }
  4766. if (!this.contentRef && this.root) {
  4767. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4768. }
  4769. var content = null;
  4770. if (this.contentRef) {
  4771. var xref = this.xref;
  4772. var fileObj = xref.fetchIfRef(this.contentRef);
  4773. if (fileObj && isStream(fileObj)) {
  4774. content = fileObj.getBytes();
  4775. } else {
  4776. warn('Embedded file specification points to non-existing/invalid ' +
  4777. 'content');
  4778. }
  4779. } else {
  4780. warn('Embedded file specification does not have a content');
  4781. }
  4782. return content;
  4783. },
  4784. get serializable() {
  4785. return {
  4786. filename: this.filename,
  4787. content: this.content
  4788. };
  4789. }
  4790. };
  4791. return FileSpec;
  4792. })();
  4793. /**
  4794. * A helper for loading missing data in object graphs. It traverses the graph
  4795. * depth first and queues up any objects that have missing data. Once it has
  4796. * has traversed as many objects that are available it attempts to bundle the
  4797. * missing data requests and then resume from the nodes that weren't ready.
  4798. *
  4799. * NOTE: It provides protection from circular references by keeping track of
  4800. * of loaded references. However, you must be careful not to load any graphs
  4801. * that have references to the catalog or other pages since that will cause the
  4802. * entire PDF document object graph to be traversed.
  4803. */
  4804. var ObjectLoader = (function() {
  4805. function mayHaveChildren(value) {
  4806. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4807. }
  4808. function addChildren(node, nodesToVisit) {
  4809. var value;
  4810. if (isDict(node) || isStream(node)) {
  4811. var map;
  4812. if (isDict(node)) {
  4813. map = node.map;
  4814. } else {
  4815. map = node.dict.map;
  4816. }
  4817. for (var key in map) {
  4818. value = map[key];
  4819. if (mayHaveChildren(value)) {
  4820. nodesToVisit.push(value);
  4821. }
  4822. }
  4823. } else if (isArray(node)) {
  4824. for (var i = 0, ii = node.length; i < ii; i++) {
  4825. value = node[i];
  4826. if (mayHaveChildren(value)) {
  4827. nodesToVisit.push(value);
  4828. }
  4829. }
  4830. }
  4831. }
  4832. function ObjectLoader(obj, keys, xref) {
  4833. this.obj = obj;
  4834. this.keys = keys;
  4835. this.xref = xref;
  4836. this.refSet = null;
  4837. this.capability = null;
  4838. }
  4839. ObjectLoader.prototype = {
  4840. load: function ObjectLoader_load() {
  4841. var keys = this.keys;
  4842. this.capability = createPromiseCapability();
  4843. // Don't walk the graph if all the data is already loaded.
  4844. if (!(this.xref.stream instanceof ChunkedStream) ||
  4845. this.xref.stream.getMissingChunks().length === 0) {
  4846. this.capability.resolve();
  4847. return this.capability.promise;
  4848. }
  4849. this.refSet = new RefSet();
  4850. // Setup the initial nodes to visit.
  4851. var nodesToVisit = [];
  4852. for (var i = 0; i < keys.length; i++) {
  4853. nodesToVisit.push(this.obj[keys[i]]);
  4854. }
  4855. this._walk(nodesToVisit);
  4856. return this.capability.promise;
  4857. },
  4858. _walk: function ObjectLoader_walk(nodesToVisit) {
  4859. var nodesToRevisit = [];
  4860. var pendingRequests = [];
  4861. // DFS walk of the object graph.
  4862. while (nodesToVisit.length) {
  4863. var currentNode = nodesToVisit.pop();
  4864. // Only references or chunked streams can cause missing data exceptions.
  4865. if (isRef(currentNode)) {
  4866. // Skip nodes that have already been visited.
  4867. if (this.refSet.has(currentNode)) {
  4868. continue;
  4869. }
  4870. try {
  4871. var ref = currentNode;
  4872. this.refSet.put(ref);
  4873. currentNode = this.xref.fetch(currentNode);
  4874. } catch (e) {
  4875. if (!(e instanceof MissingDataException)) {
  4876. throw e;
  4877. }
  4878. nodesToRevisit.push(currentNode);
  4879. pendingRequests.push({ begin: e.begin, end: e.end });
  4880. }
  4881. }
  4882. if (currentNode && currentNode.getBaseStreams) {
  4883. var baseStreams = currentNode.getBaseStreams();
  4884. var foundMissingData = false;
  4885. for (var i = 0; i < baseStreams.length; i++) {
  4886. var stream = baseStreams[i];
  4887. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4888. foundMissingData = true;
  4889. pendingRequests.push({
  4890. begin: stream.start,
  4891. end: stream.end
  4892. });
  4893. }
  4894. }
  4895. if (foundMissingData) {
  4896. nodesToRevisit.push(currentNode);
  4897. }
  4898. }
  4899. addChildren(currentNode, nodesToVisit);
  4900. }
  4901. if (pendingRequests.length) {
  4902. this.xref.stream.manager.requestRanges(pendingRequests).then(
  4903. function pendingRequestCallback() {
  4904. nodesToVisit = nodesToRevisit;
  4905. for (var i = 0; i < nodesToRevisit.length; i++) {
  4906. var node = nodesToRevisit[i];
  4907. // Remove any reference nodes from the currrent refset so they
  4908. // aren't skipped when we revist them.
  4909. if (isRef(node)) {
  4910. this.refSet.remove(node);
  4911. }
  4912. }
  4913. this._walk(nodesToVisit);
  4914. }.bind(this), this.capability.reject);
  4915. return;
  4916. }
  4917. // Everything is loaded.
  4918. this.refSet = null;
  4919. this.capability.resolve();
  4920. }
  4921. };
  4922. return ObjectLoader;
  4923. })();
  4924. var ISOAdobeCharset = [
  4925. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4926. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4927. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4928. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4929. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4930. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4931. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4932. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4933. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4934. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4935. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4936. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4937. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4938. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4939. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4940. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4941. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4942. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4943. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4944. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4945. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4946. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4947. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4948. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4949. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4950. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4951. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4952. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4953. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4954. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4955. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4956. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4957. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4958. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4959. ];
  4960. var ExpertCharset = [
  4961. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4962. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4963. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4964. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4965. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4966. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4967. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4968. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4969. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4970. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4971. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4972. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4973. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4974. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4975. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4976. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4977. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4978. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4979. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4980. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4981. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4982. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4983. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4984. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4985. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4986. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4987. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4988. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4989. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4990. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4991. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4992. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4993. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4994. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4995. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4996. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4997. 'Ydieresissmall'
  4998. ];
  4999. var ExpertSubsetCharset = [
  5000. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  5001. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  5002. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  5003. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  5004. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  5005. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  5006. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  5007. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  5008. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  5009. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  5010. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  5011. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  5012. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  5013. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  5014. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  5015. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  5016. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  5017. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  5018. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  5019. 'periodinferior', 'commainferior'
  5020. ];
  5021. var DEFAULT_ICON_SIZE = 22; // px
  5022. /**
  5023. * @class
  5024. * @alias AnnotationFactory
  5025. */
  5026. function AnnotationFactory() {}
  5027. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  5028. /**
  5029. * @param {XRef} xref
  5030. * @param {Object} ref
  5031. * @returns {Annotation}
  5032. */
  5033. create: function AnnotationFactory_create(xref, ref) {
  5034. var dict = xref.fetchIfRef(ref);
  5035. if (!isDict(dict)) {
  5036. return;
  5037. }
  5038. // Determine the annotation's subtype.
  5039. var subtype = dict.get('Subtype');
  5040. subtype = isName(subtype) ? subtype.name : '';
  5041. // Return the right annotation object based on the subtype and field type.
  5042. var parameters = {
  5043. dict: dict,
  5044. ref: ref
  5045. };
  5046. switch (subtype) {
  5047. case 'Link':
  5048. return new LinkAnnotation(parameters);
  5049. case 'Text':
  5050. return new TextAnnotation(parameters);
  5051. case 'Widget':
  5052. var fieldType = Util.getInheritableProperty(dict, 'FT');
  5053. if (isName(fieldType) && fieldType.name === 'Tx') {
  5054. return new TextWidgetAnnotation(parameters);
  5055. }
  5056. return new WidgetAnnotation(parameters);
  5057. default:
  5058. warn('Unimplemented annotation type "' + subtype + '", ' +
  5059. 'falling back to base annotation');
  5060. return new Annotation(parameters);
  5061. }
  5062. }
  5063. };
  5064. var Annotation = (function AnnotationClosure() {
  5065. // 12.5.5: Algorithm: Appearance streams
  5066. function getTransformMatrix(rect, bbox, matrix) {
  5067. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  5068. var minX = bounds[0];
  5069. var minY = bounds[1];
  5070. var maxX = bounds[2];
  5071. var maxY = bounds[3];
  5072. if (minX === maxX || minY === maxY) {
  5073. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  5074. // just apply the transform for rect
  5075. return [1, 0, 0, 1, rect[0], rect[1]];
  5076. }
  5077. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  5078. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  5079. return [
  5080. xRatio,
  5081. 0,
  5082. 0,
  5083. yRatio,
  5084. rect[0] - minX * xRatio,
  5085. rect[1] - minY * yRatio
  5086. ];
  5087. }
  5088. function getDefaultAppearance(dict) {
  5089. var appearanceState = dict.get('AP');
  5090. if (!isDict(appearanceState)) {
  5091. return;
  5092. }
  5093. var appearance;
  5094. var appearances = appearanceState.get('N');
  5095. if (isDict(appearances)) {
  5096. var as = dict.get('AS');
  5097. if (as && appearances.has(as.name)) {
  5098. appearance = appearances.get(as.name);
  5099. }
  5100. } else {
  5101. appearance = appearances;
  5102. }
  5103. return appearance;
  5104. }
  5105. function Annotation(params) {
  5106. var dict = params.dict;
  5107. this.setFlags(dict.get('F'));
  5108. this.setRectangle(dict.get('Rect'));
  5109. this.setColor(dict.get('C'));
  5110. this.setBorderStyle(dict);
  5111. this.appearance = getDefaultAppearance(dict);
  5112. // Expose public properties using a data object.
  5113. this.data = {};
  5114. this.data.id = params.ref.num;
  5115. this.data.subtype = dict.get('Subtype').name;
  5116. this.data.annotationFlags = this.flags;
  5117. this.data.rect = this.rectangle;
  5118. this.data.color = this.color;
  5119. this.data.borderStyle = this.borderStyle;
  5120. this.data.hasAppearance = !!this.appearance;
  5121. }
  5122. Annotation.prototype = {
  5123. /**
  5124. * @return {boolean}
  5125. */
  5126. get viewable() {
  5127. if (this.flags) {
  5128. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  5129. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  5130. !this.hasFlag(AnnotationFlag.NOVIEW);
  5131. }
  5132. return true;
  5133. },
  5134. /**
  5135. * @return {boolean}
  5136. */
  5137. get printable() {
  5138. if (this.flags) {
  5139. return this.hasFlag(AnnotationFlag.PRINT) &&
  5140. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  5141. !this.hasFlag(AnnotationFlag.HIDDEN);
  5142. }
  5143. return false;
  5144. },
  5145. /**
  5146. * Set the flags.
  5147. *
  5148. * @public
  5149. * @memberof Annotation
  5150. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  5151. * characteristics
  5152. * @see {@link shared/util.js}
  5153. */
  5154. setFlags: function Annotation_setFlags(flags) {
  5155. if (isInt(flags)) {
  5156. this.flags = flags;
  5157. } else {
  5158. this.flags = 0;
  5159. }
  5160. },
  5161. /**
  5162. * Check if a provided flag is set.
  5163. *
  5164. * @public
  5165. * @memberof Annotation
  5166. * @param {number} flag - Hexadecimal representation for an annotation
  5167. * characteristic
  5168. * @return {boolean}
  5169. * @see {@link shared/util.js}
  5170. */
  5171. hasFlag: function Annotation_hasFlag(flag) {
  5172. if (this.flags) {
  5173. return (this.flags & flag) > 0;
  5174. }
  5175. return false;
  5176. },
  5177. /**
  5178. * Set the rectangle.
  5179. *
  5180. * @public
  5181. * @memberof Annotation
  5182. * @param {Array} rectangle - The rectangle array with exactly four entries
  5183. */
  5184. setRectangle: function Annotation_setRectangle(rectangle) {
  5185. if (isArray(rectangle) && rectangle.length === 4) {
  5186. this.rectangle = Util.normalizeRect(rectangle);
  5187. } else {
  5188. this.rectangle = [0, 0, 0, 0];
  5189. }
  5190. },
  5191. /**
  5192. * Set the color and take care of color space conversion.
  5193. *
  5194. * @public
  5195. * @memberof Annotation
  5196. * @param {Array} color - The color array containing either 0
  5197. * (transparent), 1 (grayscale), 3 (RGB) or
  5198. * 4 (CMYK) elements
  5199. */
  5200. setColor: function Annotation_setColor(color) {
  5201. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  5202. if (!isArray(color)) {
  5203. this.color = rgbColor;
  5204. return;
  5205. }
  5206. switch (color.length) {
  5207. case 0: // Transparent, which we indicate with a null value
  5208. this.color = null;
  5209. break;
  5210. case 1: // Convert grayscale to RGB
  5211. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  5212. this.color = rgbColor;
  5213. break;
  5214. case 3: // Convert RGB percentages to RGB
  5215. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  5216. this.color = rgbColor;
  5217. break;
  5218. case 4: // Convert CMYK to RGB
  5219. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  5220. this.color = rgbColor;
  5221. break;
  5222. default:
  5223. this.color = rgbColor;
  5224. break;
  5225. }
  5226. },
  5227. /**
  5228. * Set the border style (as AnnotationBorderStyle object).
  5229. *
  5230. * @public
  5231. * @memberof Annotation
  5232. * @param {Dict} borderStyle - The border style dictionary
  5233. */
  5234. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  5235. this.borderStyle = new AnnotationBorderStyle();
  5236. if (!isDict(borderStyle)) {
  5237. return;
  5238. }
  5239. if (borderStyle.has('BS')) {
  5240. var dict = borderStyle.get('BS');
  5241. var dictType;
  5242. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  5243. dictType.name === 'Border')) {
  5244. this.borderStyle.setWidth(dict.get('W'));
  5245. this.borderStyle.setStyle(dict.get('S'));
  5246. this.borderStyle.setDashArray(dict.get('D'));
  5247. }
  5248. } else if (borderStyle.has('Border')) {
  5249. var array = borderStyle.get('Border');
  5250. if (isArray(array) && array.length >= 3) {
  5251. this.borderStyle.setHorizontalCornerRadius(array[0]);
  5252. this.borderStyle.setVerticalCornerRadius(array[1]);
  5253. this.borderStyle.setWidth(array[2]);
  5254. if (array.length === 4) { // Dash array available
  5255. this.borderStyle.setDashArray(array[3]);
  5256. }
  5257. }
  5258. } else {
  5259. // There are no border entries in the dictionary. According to the
  5260. // specification, we should draw a solid border of width 1 in that
  5261. // case, but Adobe Reader did not implement that part of the
  5262. // specification and instead draws no border at all, so we do the same.
  5263. // See also https://github.com/mozilla/pdf.js/issues/6179.
  5264. this.borderStyle.setWidth(0);
  5265. }
  5266. },
  5267. loadResources: function Annotation_loadResources(keys) {
  5268. return new Promise(function (resolve, reject) {
  5269. this.appearance.dict.getAsync('Resources').then(function (resources) {
  5270. if (!resources) {
  5271. resolve();
  5272. return;
  5273. }
  5274. var objectLoader = new ObjectLoader(resources.map,
  5275. keys,
  5276. resources.xref);
  5277. objectLoader.load().then(function() {
  5278. resolve(resources);
  5279. }, reject);
  5280. }, reject);
  5281. }.bind(this));
  5282. },
  5283. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  5284. if (!this.appearance) {
  5285. return Promise.resolve(new OperatorList());
  5286. }
  5287. var data = this.data;
  5288. var appearanceDict = this.appearance.dict;
  5289. var resourcesPromise = this.loadResources([
  5290. 'ExtGState',
  5291. 'ColorSpace',
  5292. 'Pattern',
  5293. 'Shading',
  5294. 'XObject',
  5295. 'Font'
  5296. // ProcSet
  5297. // Properties
  5298. ]);
  5299. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  5300. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  5301. var transform = getTransformMatrix(data.rect, bbox, matrix);
  5302. var self = this;
  5303. return resourcesPromise.then(function(resources) {
  5304. var opList = new OperatorList();
  5305. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  5306. return evaluator.getOperatorList(self.appearance, task,
  5307. resources, opList).
  5308. then(function () {
  5309. opList.addOp(OPS.endAnnotation, []);
  5310. self.appearance.reset();
  5311. return opList;
  5312. });
  5313. });
  5314. }
  5315. };
  5316. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  5317. annotations, opList, partialEvaluator, task, intent) {
  5318. var annotationPromises = [];
  5319. for (var i = 0, n = annotations.length; i < n; ++i) {
  5320. if ((intent === 'display' && annotations[i].viewable) ||
  5321. (intent === 'print' && annotations[i].printable)) {
  5322. annotationPromises.push(
  5323. annotations[i].getOperatorList(partialEvaluator, task));
  5324. }
  5325. }
  5326. return Promise.all(annotationPromises).then(function(operatorLists) {
  5327. opList.addOp(OPS.beginAnnotations, []);
  5328. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  5329. opList.addOpList(operatorLists[i]);
  5330. }
  5331. opList.addOp(OPS.endAnnotations, []);
  5332. });
  5333. };
  5334. return Annotation;
  5335. })();
  5336. /**
  5337. * Contains all data regarding an annotation's border style.
  5338. *
  5339. * @class
  5340. */
  5341. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  5342. /**
  5343. * @constructor
  5344. * @private
  5345. */
  5346. function AnnotationBorderStyle() {
  5347. this.width = 1;
  5348. this.style = AnnotationBorderStyleType.SOLID;
  5349. this.dashArray = [3];
  5350. this.horizontalCornerRadius = 0;
  5351. this.verticalCornerRadius = 0;
  5352. }
  5353. AnnotationBorderStyle.prototype = {
  5354. /**
  5355. * Set the width.
  5356. *
  5357. * @public
  5358. * @memberof AnnotationBorderStyle
  5359. * @param {integer} width - The width
  5360. */
  5361. setWidth: function AnnotationBorderStyle_setWidth(width) {
  5362. if (width === (width | 0)) {
  5363. this.width = width;
  5364. }
  5365. },
  5366. /**
  5367. * Set the style.
  5368. *
  5369. * @public
  5370. * @memberof AnnotationBorderStyle
  5371. * @param {Object} style - The style object
  5372. * @see {@link shared/util.js}
  5373. */
  5374. setStyle: function AnnotationBorderStyle_setStyle(style) {
  5375. if (!style) {
  5376. return;
  5377. }
  5378. switch (style.name) {
  5379. case 'S':
  5380. this.style = AnnotationBorderStyleType.SOLID;
  5381. break;
  5382. case 'D':
  5383. this.style = AnnotationBorderStyleType.DASHED;
  5384. break;
  5385. case 'B':
  5386. this.style = AnnotationBorderStyleType.BEVELED;
  5387. break;
  5388. case 'I':
  5389. this.style = AnnotationBorderStyleType.INSET;
  5390. break;
  5391. case 'U':
  5392. this.style = AnnotationBorderStyleType.UNDERLINE;
  5393. break;
  5394. default:
  5395. break;
  5396. }
  5397. },
  5398. /**
  5399. * Set the dash array.
  5400. *
  5401. * @public
  5402. * @memberof AnnotationBorderStyle
  5403. * @param {Array} dashArray - The dash array with at least one element
  5404. */
  5405. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  5406. // We validate the dash array, but we do not use it because CSS does not
  5407. // allow us to change spacing of dashes. For more information, visit
  5408. // http://www.w3.org/TR/css3-background/#the-border-style.
  5409. if (isArray(dashArray) && dashArray.length > 0) {
  5410. // According to the PDF specification: the elements in a dashArray
  5411. // shall be numbers that are nonnegative and not all equal to zero.
  5412. var isValid = true;
  5413. var allZeros = true;
  5414. for (var i = 0, len = dashArray.length; i < len; i++) {
  5415. var element = dashArray[i];
  5416. var validNumber = (+element >= 0);
  5417. if (!validNumber) {
  5418. isValid = false;
  5419. break;
  5420. } else if (element > 0) {
  5421. allZeros = false;
  5422. }
  5423. }
  5424. if (isValid && !allZeros) {
  5425. this.dashArray = dashArray;
  5426. } else {
  5427. this.width = 0; // Adobe behavior when the array is invalid.
  5428. }
  5429. } else if (dashArray) {
  5430. this.width = 0; // Adobe behavior when the array is invalid.
  5431. }
  5432. },
  5433. /**
  5434. * Set the horizontal corner radius (from a Border dictionary).
  5435. *
  5436. * @public
  5437. * @memberof AnnotationBorderStyle
  5438. * @param {integer} radius - The horizontal corner radius
  5439. */
  5440. setHorizontalCornerRadius:
  5441. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  5442. if (radius === (radius | 0)) {
  5443. this.horizontalCornerRadius = radius;
  5444. }
  5445. },
  5446. /**
  5447. * Set the vertical corner radius (from a Border dictionary).
  5448. *
  5449. * @public
  5450. * @memberof AnnotationBorderStyle
  5451. * @param {integer} radius - The vertical corner radius
  5452. */
  5453. setVerticalCornerRadius:
  5454. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  5455. if (radius === (radius | 0)) {
  5456. this.verticalCornerRadius = radius;
  5457. }
  5458. }
  5459. };
  5460. return AnnotationBorderStyle;
  5461. })();
  5462. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  5463. function WidgetAnnotation(params) {
  5464. Annotation.call(this, params);
  5465. var dict = params.dict;
  5466. var data = this.data;
  5467. data.annotationType = AnnotationType.WIDGET;
  5468. data.fieldValue = stringToPDFString(
  5469. Util.getInheritableProperty(dict, 'V') || '');
  5470. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  5471. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  5472. var fieldType = Util.getInheritableProperty(dict, 'FT');
  5473. data.fieldType = isName(fieldType) ? fieldType.name : '';
  5474. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  5475. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  5476. // Hide unsupported Widget signatures.
  5477. if (data.fieldType === 'Sig') {
  5478. warn('unimplemented annotation type: Widget signature');
  5479. this.setFlags(AnnotationFlag.HIDDEN);
  5480. }
  5481. // Building the full field name by collecting the field and
  5482. // its ancestors 'T' data and joining them using '.'.
  5483. var fieldName = [];
  5484. var namedItem = dict;
  5485. var ref = params.ref;
  5486. while (namedItem) {
  5487. var parent = namedItem.get('Parent');
  5488. var parentRef = namedItem.getRaw('Parent');
  5489. var name = namedItem.get('T');
  5490. if (name) {
  5491. fieldName.unshift(stringToPDFString(name));
  5492. } else if (parent && ref) {
  5493. // The field name is absent, that means more than one field
  5494. // with the same name may exist. Replacing the empty name
  5495. // with the '`' plus index in the parent's 'Kids' array.
  5496. // This is not in the PDF spec but necessary to id the
  5497. // the input controls.
  5498. var kids = parent.get('Kids');
  5499. var j, jj;
  5500. for (j = 0, jj = kids.length; j < jj; j++) {
  5501. var kidRef = kids[j];
  5502. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  5503. break;
  5504. }
  5505. }
  5506. fieldName.unshift('`' + j);
  5507. }
  5508. namedItem = parent;
  5509. ref = parentRef;
  5510. }
  5511. data.fullName = fieldName.join('.');
  5512. }
  5513. Util.inherit(WidgetAnnotation, Annotation, {});
  5514. return WidgetAnnotation;
  5515. })();
  5516. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  5517. function TextWidgetAnnotation(params) {
  5518. WidgetAnnotation.call(this, params);
  5519. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  5520. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  5521. }
  5522. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  5523. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  5524. task) {
  5525. if (this.appearance) {
  5526. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  5527. }
  5528. var opList = new OperatorList();
  5529. var data = this.data;
  5530. // Even if there is an appearance stream, ignore it. This is the
  5531. // behaviour used by Adobe Reader.
  5532. if (!data.defaultAppearance) {
  5533. return Promise.resolve(opList);
  5534. }
  5535. var stream = new Stream(stringToBytes(data.defaultAppearance));
  5536. return evaluator.getOperatorList(stream, task,
  5537. this.fieldResources, opList).
  5538. then(function () {
  5539. return opList;
  5540. });
  5541. }
  5542. });
  5543. return TextWidgetAnnotation;
  5544. })();
  5545. var TextAnnotation = (function TextAnnotationClosure() {
  5546. function TextAnnotation(params) {
  5547. Annotation.call(this, params);
  5548. var dict = params.dict;
  5549. var data = this.data;
  5550. var content = dict.get('Contents');
  5551. var title = dict.get('T');
  5552. data.annotationType = AnnotationType.TEXT;
  5553. data.content = stringToPDFString(content || '');
  5554. data.title = stringToPDFString(title || '');
  5555. data.hasHtml = true;
  5556. if (data.hasAppearance) {
  5557. data.name = 'NoIcon';
  5558. } else {
  5559. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  5560. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  5561. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  5562. }
  5563. if (dict.has('C')) {
  5564. data.hasBgColor = true;
  5565. }
  5566. }
  5567. Util.inherit(TextAnnotation, Annotation, {});
  5568. return TextAnnotation;
  5569. })();
  5570. var LinkAnnotation = (function LinkAnnotationClosure() {
  5571. function LinkAnnotation(params) {
  5572. Annotation.call(this, params);
  5573. var dict = params.dict;
  5574. var data = this.data;
  5575. data.annotationType = AnnotationType.LINK;
  5576. data.hasHtml = true;
  5577. var action = dict.get('A');
  5578. if (action && isDict(action)) {
  5579. var linkType = action.get('S').name;
  5580. if (linkType === 'URI') {
  5581. var url = action.get('URI');
  5582. if (isName(url)) {
  5583. // Some bad PDFs do not put parentheses around relative URLs.
  5584. url = '/' + url.name;
  5585. } else if (url) {
  5586. url = addDefaultProtocolToUrl(url);
  5587. }
  5588. // TODO: pdf spec mentions urls can be relative to a Base
  5589. // entry in the dictionary.
  5590. if (!isValidUrl(url, false)) {
  5591. url = '';
  5592. }
  5593. // According to ISO 32000-1:2008, section 12.6.4.7,
  5594. // URI should to be encoded in 7-bit ASCII.
  5595. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  5596. try {
  5597. data.url = stringToUTF8String(url);
  5598. } catch (e) {
  5599. // Fall back to a simple copy.
  5600. data.url = url;
  5601. }
  5602. } else if (linkType === 'GoTo') {
  5603. data.dest = action.get('D');
  5604. } else if (linkType === 'GoToR') {
  5605. var urlDict = action.get('F');
  5606. if (isDict(urlDict)) {
  5607. // We assume that the 'url' is a Filspec dictionary
  5608. // and fetch the url without checking any further
  5609. url = urlDict.get('F') || '';
  5610. }
  5611. // TODO: pdf reference says that GoToR
  5612. // can also have 'NewWindow' attribute
  5613. if (!isValidUrl(url, false)) {
  5614. url = '';
  5615. }
  5616. data.url = url;
  5617. data.dest = action.get('D');
  5618. } else if (linkType === 'Named') {
  5619. data.action = action.get('N').name;
  5620. } else {
  5621. warn('unrecognized link type: ' + linkType);
  5622. }
  5623. } else if (dict.has('Dest')) {
  5624. // simple destination link
  5625. var dest = dict.get('Dest');
  5626. data.dest = isName(dest) ? dest.name : dest;
  5627. }
  5628. }
  5629. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  5630. function addDefaultProtocolToUrl(url) {
  5631. if (url && url.indexOf('www.') === 0) {
  5632. return ('http://' + url);
  5633. }
  5634. return url;
  5635. }
  5636. Util.inherit(LinkAnnotation, Annotation, {});
  5637. return LinkAnnotation;
  5638. })();
  5639. var PDFFunction = (function PDFFunctionClosure() {
  5640. var CONSTRUCT_SAMPLED = 0;
  5641. var CONSTRUCT_INTERPOLATED = 2;
  5642. var CONSTRUCT_STICHED = 3;
  5643. var CONSTRUCT_POSTSCRIPT = 4;
  5644. return {
  5645. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  5646. str) {
  5647. var i, ii;
  5648. var length = 1;
  5649. for (i = 0, ii = size.length; i < ii; i++) {
  5650. length *= size[i];
  5651. }
  5652. length *= outputSize;
  5653. var array = new Array(length);
  5654. var codeSize = 0;
  5655. var codeBuf = 0;
  5656. // 32 is a valid bps so shifting won't work
  5657. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  5658. var strBytes = str.getBytes((length * bps + 7) / 8);
  5659. var strIdx = 0;
  5660. for (i = 0; i < length; i++) {
  5661. while (codeSize < bps) {
  5662. codeBuf <<= 8;
  5663. codeBuf |= strBytes[strIdx++];
  5664. codeSize += 8;
  5665. }
  5666. codeSize -= bps;
  5667. array[i] = (codeBuf >> codeSize) * sampleMul;
  5668. codeBuf &= (1 << codeSize) - 1;
  5669. }
  5670. return array;
  5671. },
  5672. getIR: function PDFFunction_getIR(xref, fn) {
  5673. var dict = fn.dict;
  5674. if (!dict) {
  5675. dict = fn;
  5676. }
  5677. var types = [this.constructSampled,
  5678. null,
  5679. this.constructInterpolated,
  5680. this.constructStiched,
  5681. this.constructPostScript];
  5682. var typeNum = dict.get('FunctionType');
  5683. var typeFn = types[typeNum];
  5684. if (!typeFn) {
  5685. error('Unknown type of function');
  5686. }
  5687. return typeFn.call(this, fn, dict, xref);
  5688. },
  5689. fromIR: function PDFFunction_fromIR(IR) {
  5690. var type = IR[0];
  5691. switch (type) {
  5692. case CONSTRUCT_SAMPLED:
  5693. return this.constructSampledFromIR(IR);
  5694. case CONSTRUCT_INTERPOLATED:
  5695. return this.constructInterpolatedFromIR(IR);
  5696. case CONSTRUCT_STICHED:
  5697. return this.constructStichedFromIR(IR);
  5698. //case CONSTRUCT_POSTSCRIPT:
  5699. default:
  5700. return this.constructPostScriptFromIR(IR);
  5701. }
  5702. },
  5703. parse: function PDFFunction_parse(xref, fn) {
  5704. var IR = this.getIR(xref, fn);
  5705. return this.fromIR(IR);
  5706. },
  5707. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  5708. if (!isArray(fnObj)) {
  5709. // not an array -- parsing as regular function
  5710. return this.parse(xref, fnObj);
  5711. }
  5712. var fnArray = [];
  5713. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  5714. var obj = xref.fetchIfRef(fnObj[j]);
  5715. fnArray.push(PDFFunction.parse(xref, obj));
  5716. }
  5717. return function (src, srcOffset, dest, destOffset) {
  5718. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  5719. fnArray[i](src, srcOffset, dest, destOffset + i);
  5720. }
  5721. };
  5722. },
  5723. constructSampled: function PDFFunction_constructSampled(str, dict) {
  5724. function toMultiArray(arr) {
  5725. var inputLength = arr.length;
  5726. var out = [];
  5727. var index = 0;
  5728. for (var i = 0; i < inputLength; i += 2) {
  5729. out[index] = [arr[i], arr[i + 1]];
  5730. ++index;
  5731. }
  5732. return out;
  5733. }
  5734. var domain = dict.get('Domain');
  5735. var range = dict.get('Range');
  5736. if (!domain || !range) {
  5737. error('No domain or range');
  5738. }
  5739. var inputSize = domain.length / 2;
  5740. var outputSize = range.length / 2;
  5741. domain = toMultiArray(domain);
  5742. range = toMultiArray(range);
  5743. var size = dict.get('Size');
  5744. var bps = dict.get('BitsPerSample');
  5745. var order = dict.get('Order') || 1;
  5746. if (order !== 1) {
  5747. // No description how cubic spline interpolation works in PDF32000:2008
  5748. // As in poppler, ignoring order, linear interpolation may work as good
  5749. info('No support for cubic spline interpolation: ' + order);
  5750. }
  5751. var encode = dict.get('Encode');
  5752. if (!encode) {
  5753. encode = [];
  5754. for (var i = 0; i < inputSize; ++i) {
  5755. encode.push(0);
  5756. encode.push(size[i] - 1);
  5757. }
  5758. }
  5759. encode = toMultiArray(encode);
  5760. var decode = dict.get('Decode');
  5761. if (!decode) {
  5762. decode = range;
  5763. } else {
  5764. decode = toMultiArray(decode);
  5765. }
  5766. var samples = this.getSampleArray(size, outputSize, bps, str);
  5767. return [
  5768. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  5769. outputSize, Math.pow(2, bps) - 1, range
  5770. ];
  5771. },
  5772. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  5773. // See chapter 3, page 109 of the PDF reference
  5774. function interpolate(x, xmin, xmax, ymin, ymax) {
  5775. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  5776. }
  5777. return function constructSampledFromIRResult(src, srcOffset,
  5778. dest, destOffset) {
  5779. // See chapter 3, page 110 of the PDF reference.
  5780. var m = IR[1];
  5781. var domain = IR[2];
  5782. var encode = IR[3];
  5783. var decode = IR[4];
  5784. var samples = IR[5];
  5785. var size = IR[6];
  5786. var n = IR[7];
  5787. //var mask = IR[8];
  5788. var range = IR[9];
  5789. // Building the cube vertices: its part and sample index
  5790. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5791. var cubeVertices = 1 << m;
  5792. var cubeN = new Float64Array(cubeVertices);
  5793. var cubeVertex = new Uint32Array(cubeVertices);
  5794. var i, j;
  5795. for (j = 0; j < cubeVertices; j++) {
  5796. cubeN[j] = 1;
  5797. }
  5798. var k = n, pos = 1;
  5799. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5800. for (i = 0; i < m; ++i) {
  5801. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5802. var domain_2i = domain[i][0];
  5803. var domain_2i_1 = domain[i][1];
  5804. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5805. domain_2i_1);
  5806. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5807. // Encode_2i, Encode_2i+1)
  5808. var e = interpolate(xi, domain_2i, domain_2i_1,
  5809. encode[i][0], encode[i][1]);
  5810. // e_i' = min(max(e_i, 0), Size_i - 1)
  5811. var size_i = size[i];
  5812. e = Math.min(Math.max(e, 0), size_i - 1);
  5813. // Adjusting the cube: N and vertex sample index
  5814. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5815. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5816. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5817. var offset0 = e0 * k;
  5818. var offset1 = offset0 + k; // e1 * k
  5819. for (j = 0; j < cubeVertices; j++) {
  5820. if (j & pos) {
  5821. cubeN[j] *= n1;
  5822. cubeVertex[j] += offset1;
  5823. } else {
  5824. cubeN[j] *= n0;
  5825. cubeVertex[j] += offset0;
  5826. }
  5827. }
  5828. k *= size_i;
  5829. pos <<= 1;
  5830. }
  5831. for (j = 0; j < n; ++j) {
  5832. // Sum all cube vertices' samples portions
  5833. var rj = 0;
  5834. for (i = 0; i < cubeVertices; i++) {
  5835. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5836. }
  5837. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5838. // Decode_2j, Decode_2j+1)
  5839. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5840. // y_j = min(max(r_j, range_2j), range_2j+1)
  5841. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5842. range[j][1]);
  5843. }
  5844. };
  5845. },
  5846. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5847. dict) {
  5848. var c0 = dict.get('C0') || [0];
  5849. var c1 = dict.get('C1') || [1];
  5850. var n = dict.get('N');
  5851. if (!isArray(c0) || !isArray(c1)) {
  5852. error('Illegal dictionary for interpolated function');
  5853. }
  5854. var length = c0.length;
  5855. var diff = [];
  5856. for (var i = 0; i < length; ++i) {
  5857. diff.push(c1[i] - c0[i]);
  5858. }
  5859. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5860. },
  5861. constructInterpolatedFromIR:
  5862. function PDFFunction_constructInterpolatedFromIR(IR) {
  5863. var c0 = IR[1];
  5864. var diff = IR[2];
  5865. var n = IR[3];
  5866. var length = diff.length;
  5867. return function constructInterpolatedFromIRResult(src, srcOffset,
  5868. dest, destOffset) {
  5869. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5870. for (var j = 0; j < length; ++j) {
  5871. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5872. }
  5873. };
  5874. },
  5875. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5876. var domain = dict.get('Domain');
  5877. if (!domain) {
  5878. error('No domain');
  5879. }
  5880. var inputSize = domain.length / 2;
  5881. if (inputSize !== 1) {
  5882. error('Bad domain for stiched function');
  5883. }
  5884. var fnRefs = dict.get('Functions');
  5885. var fns = [];
  5886. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5887. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5888. }
  5889. var bounds = dict.get('Bounds');
  5890. var encode = dict.get('Encode');
  5891. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5892. },
  5893. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5894. var domain = IR[1];
  5895. var bounds = IR[2];
  5896. var encode = IR[3];
  5897. var fnsIR = IR[4];
  5898. var fns = [];
  5899. var tmpBuf = new Float32Array(1);
  5900. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5901. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5902. }
  5903. return function constructStichedFromIRResult(src, srcOffset,
  5904. dest, destOffset) {
  5905. var clip = function constructStichedFromIRClip(v, min, max) {
  5906. if (v > max) {
  5907. v = max;
  5908. } else if (v < min) {
  5909. v = min;
  5910. }
  5911. return v;
  5912. };
  5913. // clip to domain
  5914. var v = clip(src[srcOffset], domain[0], domain[1]);
  5915. // calulate which bound the value is in
  5916. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5917. if (v < bounds[i]) {
  5918. break;
  5919. }
  5920. }
  5921. // encode value into domain of function
  5922. var dmin = domain[0];
  5923. if (i > 0) {
  5924. dmin = bounds[i - 1];
  5925. }
  5926. var dmax = domain[1];
  5927. if (i < bounds.length) {
  5928. dmax = bounds[i];
  5929. }
  5930. var rmin = encode[2 * i];
  5931. var rmax = encode[2 * i + 1];
  5932. // Prevent the value from becoming NaN as a result
  5933. // of division by zero (fixes issue6113.pdf).
  5934. tmpBuf[0] = dmin === dmax ? rmin :
  5935. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5936. // call the appropriate function
  5937. fns[i](tmpBuf, 0, dest, destOffset);
  5938. };
  5939. },
  5940. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5941. xref) {
  5942. var domain = dict.get('Domain');
  5943. var range = dict.get('Range');
  5944. if (!domain) {
  5945. error('No domain.');
  5946. }
  5947. if (!range) {
  5948. error('No range.');
  5949. }
  5950. var lexer = new PostScriptLexer(fn);
  5951. var parser = new PostScriptParser(lexer);
  5952. var code = parser.parse();
  5953. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5954. },
  5955. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5956. IR) {
  5957. var domain = IR[1];
  5958. var range = IR[2];
  5959. var code = IR[3];
  5960. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5961. if (compiled) {
  5962. // Compiled function consists of simple expressions such as addition,
  5963. // subtraction, Math.max, and also contains 'var' and 'return'
  5964. // statements. See the generation in the PostScriptCompiler below.
  5965. /*jshint -W054 */
  5966. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5967. }
  5968. info('Unable to compile PS function');
  5969. var numOutputs = range.length >> 1;
  5970. var numInputs = domain.length >> 1;
  5971. var evaluator = new PostScriptEvaluator(code);
  5972. // Cache the values for a big speed up, the cache size is limited though
  5973. // since the number of possible values can be huge from a PS function.
  5974. var cache = {};
  5975. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5976. // seen in our tests.
  5977. var MAX_CACHE_SIZE = 2048 * 4;
  5978. var cache_available = MAX_CACHE_SIZE;
  5979. var tmpBuf = new Float32Array(numInputs);
  5980. return function constructPostScriptFromIRResult(src, srcOffset,
  5981. dest, destOffset) {
  5982. var i, value;
  5983. var key = '';
  5984. var input = tmpBuf;
  5985. for (i = 0; i < numInputs; i++) {
  5986. value = src[srcOffset + i];
  5987. input[i] = value;
  5988. key += value + '_';
  5989. }
  5990. var cachedValue = cache[key];
  5991. if (cachedValue !== undefined) {
  5992. dest.set(cachedValue, destOffset);
  5993. return;
  5994. }
  5995. var output = new Float32Array(numOutputs);
  5996. var stack = evaluator.execute(input);
  5997. var stackIndex = stack.length - numOutputs;
  5998. for (i = 0; i < numOutputs; i++) {
  5999. value = stack[stackIndex + i];
  6000. var bound = range[i * 2];
  6001. if (value < bound) {
  6002. value = bound;
  6003. } else {
  6004. bound = range[i * 2 +1];
  6005. if (value > bound) {
  6006. value = bound;
  6007. }
  6008. }
  6009. output[i] = value;
  6010. }
  6011. if (cache_available > 0) {
  6012. cache_available--;
  6013. cache[key] = output;
  6014. }
  6015. dest.set(output, destOffset);
  6016. };
  6017. }
  6018. };
  6019. })();
  6020. function isPDFFunction(v) {
  6021. var fnDict;
  6022. if (typeof v !== 'object') {
  6023. return false;
  6024. } else if (isDict(v)) {
  6025. fnDict = v;
  6026. } else if (isStream(v)) {
  6027. fnDict = v.dict;
  6028. } else {
  6029. return false;
  6030. }
  6031. return fnDict.has('FunctionType');
  6032. }
  6033. var PostScriptStack = (function PostScriptStackClosure() {
  6034. var MAX_STACK_SIZE = 100;
  6035. function PostScriptStack(initialStack) {
  6036. this.stack = !initialStack ? [] :
  6037. Array.prototype.slice.call(initialStack, 0);
  6038. }
  6039. PostScriptStack.prototype = {
  6040. push: function PostScriptStack_push(value) {
  6041. if (this.stack.length >= MAX_STACK_SIZE) {
  6042. error('PostScript function stack overflow.');
  6043. }
  6044. this.stack.push(value);
  6045. },
  6046. pop: function PostScriptStack_pop() {
  6047. if (this.stack.length <= 0) {
  6048. error('PostScript function stack underflow.');
  6049. }
  6050. return this.stack.pop();
  6051. },
  6052. copy: function PostScriptStack_copy(n) {
  6053. if (this.stack.length + n >= MAX_STACK_SIZE) {
  6054. error('PostScript function stack overflow.');
  6055. }
  6056. var stack = this.stack;
  6057. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  6058. stack.push(stack[i]);
  6059. }
  6060. },
  6061. index: function PostScriptStack_index(n) {
  6062. this.push(this.stack[this.stack.length - n - 1]);
  6063. },
  6064. // rotate the last n stack elements p times
  6065. roll: function PostScriptStack_roll(n, p) {
  6066. var stack = this.stack;
  6067. var l = stack.length - n;
  6068. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  6069. for (i = l, j = r; i < j; i++, j--) {
  6070. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  6071. }
  6072. for (i = l, j = c - 1; i < j; i++, j--) {
  6073. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  6074. }
  6075. for (i = c, j = r; i < j; i++, j--) {
  6076. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  6077. }
  6078. }
  6079. };
  6080. return PostScriptStack;
  6081. })();
  6082. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  6083. function PostScriptEvaluator(operators) {
  6084. this.operators = operators;
  6085. }
  6086. PostScriptEvaluator.prototype = {
  6087. execute: function PostScriptEvaluator_execute(initialStack) {
  6088. var stack = new PostScriptStack(initialStack);
  6089. var counter = 0;
  6090. var operators = this.operators;
  6091. var length = operators.length;
  6092. var operator, a, b;
  6093. while (counter < length) {
  6094. operator = operators[counter++];
  6095. if (typeof operator === 'number') {
  6096. // Operator is really an operand and should be pushed to the stack.
  6097. stack.push(operator);
  6098. continue;
  6099. }
  6100. switch (operator) {
  6101. // non standard ps operators
  6102. case 'jz': // jump if false
  6103. b = stack.pop();
  6104. a = stack.pop();
  6105. if (!a) {
  6106. counter = b;
  6107. }
  6108. break;
  6109. case 'j': // jump
  6110. a = stack.pop();
  6111. counter = a;
  6112. break;
  6113. // all ps operators in alphabetical order (excluding if/ifelse)
  6114. case 'abs':
  6115. a = stack.pop();
  6116. stack.push(Math.abs(a));
  6117. break;
  6118. case 'add':
  6119. b = stack.pop();
  6120. a = stack.pop();
  6121. stack.push(a + b);
  6122. break;
  6123. case 'and':
  6124. b = stack.pop();
  6125. a = stack.pop();
  6126. if (isBool(a) && isBool(b)) {
  6127. stack.push(a && b);
  6128. } else {
  6129. stack.push(a & b);
  6130. }
  6131. break;
  6132. case 'atan':
  6133. a = stack.pop();
  6134. stack.push(Math.atan(a));
  6135. break;
  6136. case 'bitshift':
  6137. b = stack.pop();
  6138. a = stack.pop();
  6139. if (a > 0) {
  6140. stack.push(a << b);
  6141. } else {
  6142. stack.push(a >> b);
  6143. }
  6144. break;
  6145. case 'ceiling':
  6146. a = stack.pop();
  6147. stack.push(Math.ceil(a));
  6148. break;
  6149. case 'copy':
  6150. a = stack.pop();
  6151. stack.copy(a);
  6152. break;
  6153. case 'cos':
  6154. a = stack.pop();
  6155. stack.push(Math.cos(a));
  6156. break;
  6157. case 'cvi':
  6158. a = stack.pop() | 0;
  6159. stack.push(a);
  6160. break;
  6161. case 'cvr':
  6162. // noop
  6163. break;
  6164. case 'div':
  6165. b = stack.pop();
  6166. a = stack.pop();
  6167. stack.push(a / b);
  6168. break;
  6169. case 'dup':
  6170. stack.copy(1);
  6171. break;
  6172. case 'eq':
  6173. b = stack.pop();
  6174. a = stack.pop();
  6175. stack.push(a === b);
  6176. break;
  6177. case 'exch':
  6178. stack.roll(2, 1);
  6179. break;
  6180. case 'exp':
  6181. b = stack.pop();
  6182. a = stack.pop();
  6183. stack.push(Math.pow(a, b));
  6184. break;
  6185. case 'false':
  6186. stack.push(false);
  6187. break;
  6188. case 'floor':
  6189. a = stack.pop();
  6190. stack.push(Math.floor(a));
  6191. break;
  6192. case 'ge':
  6193. b = stack.pop();
  6194. a = stack.pop();
  6195. stack.push(a >= b);
  6196. break;
  6197. case 'gt':
  6198. b = stack.pop();
  6199. a = stack.pop();
  6200. stack.push(a > b);
  6201. break;
  6202. case 'idiv':
  6203. b = stack.pop();
  6204. a = stack.pop();
  6205. stack.push((a / b) | 0);
  6206. break;
  6207. case 'index':
  6208. a = stack.pop();
  6209. stack.index(a);
  6210. break;
  6211. case 'le':
  6212. b = stack.pop();
  6213. a = stack.pop();
  6214. stack.push(a <= b);
  6215. break;
  6216. case 'ln':
  6217. a = stack.pop();
  6218. stack.push(Math.log(a));
  6219. break;
  6220. case 'log':
  6221. a = stack.pop();
  6222. stack.push(Math.log(a) / Math.LN10);
  6223. break;
  6224. case 'lt':
  6225. b = stack.pop();
  6226. a = stack.pop();
  6227. stack.push(a < b);
  6228. break;
  6229. case 'mod':
  6230. b = stack.pop();
  6231. a = stack.pop();
  6232. stack.push(a % b);
  6233. break;
  6234. case 'mul':
  6235. b = stack.pop();
  6236. a = stack.pop();
  6237. stack.push(a * b);
  6238. break;
  6239. case 'ne':
  6240. b = stack.pop();
  6241. a = stack.pop();
  6242. stack.push(a !== b);
  6243. break;
  6244. case 'neg':
  6245. a = stack.pop();
  6246. stack.push(-a);
  6247. break;
  6248. case 'not':
  6249. a = stack.pop();
  6250. if (isBool(a)) {
  6251. stack.push(!a);
  6252. } else {
  6253. stack.push(~a);
  6254. }
  6255. break;
  6256. case 'or':
  6257. b = stack.pop();
  6258. a = stack.pop();
  6259. if (isBool(a) && isBool(b)) {
  6260. stack.push(a || b);
  6261. } else {
  6262. stack.push(a | b);
  6263. }
  6264. break;
  6265. case 'pop':
  6266. stack.pop();
  6267. break;
  6268. case 'roll':
  6269. b = stack.pop();
  6270. a = stack.pop();
  6271. stack.roll(a, b);
  6272. break;
  6273. case 'round':
  6274. a = stack.pop();
  6275. stack.push(Math.round(a));
  6276. break;
  6277. case 'sin':
  6278. a = stack.pop();
  6279. stack.push(Math.sin(a));
  6280. break;
  6281. case 'sqrt':
  6282. a = stack.pop();
  6283. stack.push(Math.sqrt(a));
  6284. break;
  6285. case 'sub':
  6286. b = stack.pop();
  6287. a = stack.pop();
  6288. stack.push(a - b);
  6289. break;
  6290. case 'true':
  6291. stack.push(true);
  6292. break;
  6293. case 'truncate':
  6294. a = stack.pop();
  6295. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  6296. stack.push(a);
  6297. break;
  6298. case 'xor':
  6299. b = stack.pop();
  6300. a = stack.pop();
  6301. if (isBool(a) && isBool(b)) {
  6302. stack.push(a !== b);
  6303. } else {
  6304. stack.push(a ^ b);
  6305. }
  6306. break;
  6307. default:
  6308. error('Unknown operator ' + operator);
  6309. break;
  6310. }
  6311. }
  6312. return stack.stack;
  6313. }
  6314. };
  6315. return PostScriptEvaluator;
  6316. })();
  6317. // Most of the PDFs functions consist of simple operations such as:
  6318. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  6319. //
  6320. // We can compile most of such programs, and at the same moment, we can
  6321. // optimize some expressions using basic math properties. Keeping track of
  6322. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  6323. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  6324. function AstNode(type) {
  6325. this.type = type;
  6326. }
  6327. AstNode.prototype.visit = function (visitor) {
  6328. throw new Error('abstract method');
  6329. };
  6330. function AstArgument(index, min, max) {
  6331. AstNode.call(this, 'args');
  6332. this.index = index;
  6333. this.min = min;
  6334. this.max = max;
  6335. }
  6336. AstArgument.prototype = Object.create(AstNode.prototype);
  6337. AstArgument.prototype.visit = function (visitor) {
  6338. visitor.visitArgument(this);
  6339. };
  6340. function AstLiteral(number) {
  6341. AstNode.call(this, 'literal');
  6342. this.number = number;
  6343. this.min = number;
  6344. this.max = number;
  6345. }
  6346. AstLiteral.prototype = Object.create(AstNode.prototype);
  6347. AstLiteral.prototype.visit = function (visitor) {
  6348. visitor.visitLiteral(this);
  6349. };
  6350. function AstBinaryOperation(op, arg1, arg2, min, max) {
  6351. AstNode.call(this, 'binary');
  6352. this.op = op;
  6353. this.arg1 = arg1;
  6354. this.arg2 = arg2;
  6355. this.min = min;
  6356. this.max = max;
  6357. }
  6358. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  6359. AstBinaryOperation.prototype.visit = function (visitor) {
  6360. visitor.visitBinaryOperation(this);
  6361. };
  6362. function AstMin(arg, max) {
  6363. AstNode.call(this, 'max');
  6364. this.arg = arg;
  6365. this.min = arg.min;
  6366. this.max = max;
  6367. }
  6368. AstMin.prototype = Object.create(AstNode.prototype);
  6369. AstMin.prototype.visit = function (visitor) {
  6370. visitor.visitMin(this);
  6371. };
  6372. function AstVariable(index, min, max) {
  6373. AstNode.call(this, 'var');
  6374. this.index = index;
  6375. this.min = min;
  6376. this.max = max;
  6377. }
  6378. AstVariable.prototype = Object.create(AstNode.prototype);
  6379. AstVariable.prototype.visit = function (visitor) {
  6380. visitor.visitVariable(this);
  6381. };
  6382. function AstVariableDefinition(variable, arg) {
  6383. AstNode.call(this, 'definition');
  6384. this.variable = variable;
  6385. this.arg = arg;
  6386. }
  6387. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  6388. AstVariableDefinition.prototype.visit = function (visitor) {
  6389. visitor.visitVariableDefinition(this);
  6390. };
  6391. function ExpressionBuilderVisitor() {
  6392. this.parts = [];
  6393. }
  6394. ExpressionBuilderVisitor.prototype = {
  6395. visitArgument: function (arg) {
  6396. this.parts.push('Math.max(', arg.min, ', Math.min(',
  6397. arg.max, ', src[srcOffset + ', arg.index, ']))');
  6398. },
  6399. visitVariable: function (variable) {
  6400. this.parts.push('v', variable.index);
  6401. },
  6402. visitLiteral: function (literal) {
  6403. this.parts.push(literal.number);
  6404. },
  6405. visitBinaryOperation: function (operation) {
  6406. this.parts.push('(');
  6407. operation.arg1.visit(this);
  6408. this.parts.push(' ', operation.op, ' ');
  6409. operation.arg2.visit(this);
  6410. this.parts.push(')');
  6411. },
  6412. visitVariableDefinition: function (definition) {
  6413. this.parts.push('var ');
  6414. definition.variable.visit(this);
  6415. this.parts.push(' = ');
  6416. definition.arg.visit(this);
  6417. this.parts.push(';');
  6418. },
  6419. visitMin: function (max) {
  6420. this.parts.push('Math.min(');
  6421. max.arg.visit(this);
  6422. this.parts.push(', ', max.max, ')');
  6423. },
  6424. toString: function () {
  6425. return this.parts.join('');
  6426. }
  6427. };
  6428. function buildAddOperation(num1, num2) {
  6429. if (num2.type === 'literal' && num2.number === 0) {
  6430. // optimization: second operand is 0
  6431. return num1;
  6432. }
  6433. if (num1.type === 'literal' && num1.number === 0) {
  6434. // optimization: first operand is 0
  6435. return num2;
  6436. }
  6437. if (num2.type === 'literal' && num1.type === 'literal') {
  6438. // optimization: operands operand are literals
  6439. return new AstLiteral(num1.number + num2.number);
  6440. }
  6441. return new AstBinaryOperation('+', num1, num2,
  6442. num1.min + num2.min, num1.max + num2.max);
  6443. }
  6444. function buildMulOperation(num1, num2) {
  6445. if (num2.type === 'literal') {
  6446. // optimization: second operands is a literal...
  6447. if (num2.number === 0) {
  6448. return new AstLiteral(0); // and it's 0
  6449. } else if (num2.number === 1) {
  6450. return num1; // and it's 1
  6451. } else if (num1.type === 'literal') {
  6452. // ... and first operands is a literal too
  6453. return new AstLiteral(num1.number * num2.number);
  6454. }
  6455. }
  6456. if (num1.type === 'literal') {
  6457. // optimization: first operands is a literal...
  6458. if (num1.number === 0) {
  6459. return new AstLiteral(0); // and it's 0
  6460. } else if (num1.number === 1) {
  6461. return num2; // and it's 1
  6462. }
  6463. }
  6464. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  6465. num1.max * num2.min, num1.max * num2.max);
  6466. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  6467. num1.max * num2.min, num1.max * num2.max);
  6468. return new AstBinaryOperation('*', num1, num2, min, max);
  6469. }
  6470. function buildSubOperation(num1, num2) {
  6471. if (num2.type === 'literal') {
  6472. // optimization: second operands is a literal...
  6473. if (num2.number === 0) {
  6474. return num1; // ... and it's 0
  6475. } else if (num1.type === 'literal') {
  6476. // ... and first operands is a literal too
  6477. return new AstLiteral(num1.number - num2.number);
  6478. }
  6479. }
  6480. if (num2.type === 'binary' && num2.op === '-' &&
  6481. num1.type === 'literal' && num1.number === 1 &&
  6482. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  6483. // optimization for case: 1 - (1 - x)
  6484. return num2.arg2;
  6485. }
  6486. return new AstBinaryOperation('-', num1, num2,
  6487. num1.min - num2.max, num1.max - num2.min);
  6488. }
  6489. function buildMinOperation(num1, max) {
  6490. if (num1.min >= max) {
  6491. // optimization: num1 min value is not less than required max
  6492. return new AstLiteral(max); // just returning max
  6493. } else if (num1.max <= max) {
  6494. // optimization: num1 max value is not greater than required max
  6495. return num1; // just returning an argument
  6496. }
  6497. return new AstMin(num1, max);
  6498. }
  6499. function PostScriptCompiler() {}
  6500. PostScriptCompiler.prototype = {
  6501. compile: function PostScriptCompiler_compile(code, domain, range) {
  6502. var stack = [];
  6503. var i, ii;
  6504. var instructions = [];
  6505. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  6506. var lastRegister = 0;
  6507. var n, j, min, max;
  6508. var num1, num2, ast1, ast2, tmpVar, item;
  6509. for (i = 0; i < inputSize; i++) {
  6510. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  6511. }
  6512. for (i = 0, ii = code.length; i < ii; i++) {
  6513. item = code[i];
  6514. if (typeof item === 'number') {
  6515. stack.push(new AstLiteral(item));
  6516. continue;
  6517. }
  6518. switch (item) {
  6519. case 'add':
  6520. if (stack.length < 2) {
  6521. return null;
  6522. }
  6523. num2 = stack.pop();
  6524. num1 = stack.pop();
  6525. stack.push(buildAddOperation(num1, num2));
  6526. break;
  6527. case 'cvr':
  6528. if (stack.length < 1) {
  6529. return null;
  6530. }
  6531. break;
  6532. case 'mul':
  6533. if (stack.length < 2) {
  6534. return null;
  6535. }
  6536. num2 = stack.pop();
  6537. num1 = stack.pop();
  6538. stack.push(buildMulOperation(num1, num2));
  6539. break;
  6540. case 'sub':
  6541. if (stack.length < 2) {
  6542. return null;
  6543. }
  6544. num2 = stack.pop();
  6545. num1 = stack.pop();
  6546. stack.push(buildSubOperation(num1, num2));
  6547. break;
  6548. case 'exch':
  6549. if (stack.length < 2) {
  6550. return null;
  6551. }
  6552. ast1 = stack.pop(); ast2 = stack.pop();
  6553. stack.push(ast1, ast2);
  6554. break;
  6555. case 'pop':
  6556. if (stack.length < 1) {
  6557. return null;
  6558. }
  6559. stack.pop();
  6560. break;
  6561. case 'index':
  6562. if (stack.length < 1) {
  6563. return null;
  6564. }
  6565. num1 = stack.pop();
  6566. if (num1.type !== 'literal') {
  6567. return null;
  6568. }
  6569. n = num1.number;
  6570. if (n < 0 || (n|0) !== n || stack.length < n) {
  6571. return null;
  6572. }
  6573. ast1 = stack[stack.length - n - 1];
  6574. if (ast1.type === 'literal' || ast1.type === 'var') {
  6575. stack.push(ast1);
  6576. break;
  6577. }
  6578. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  6579. stack[stack.length - n - 1] = tmpVar;
  6580. stack.push(tmpVar);
  6581. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  6582. break;
  6583. case 'dup':
  6584. if (stack.length < 1) {
  6585. return null;
  6586. }
  6587. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  6588. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  6589. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  6590. // special case of the commands sequence for the min operation
  6591. num1 = stack.pop();
  6592. stack.push(buildMinOperation(num1, code[i + 1]));
  6593. i += 6;
  6594. break;
  6595. }
  6596. ast1 = stack[stack.length - 1];
  6597. if (ast1.type === 'literal' || ast1.type === 'var') {
  6598. // we don't have to save into intermediate variable a literal or
  6599. // variable.
  6600. stack.push(ast1);
  6601. break;
  6602. }
  6603. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  6604. stack[stack.length - 1] = tmpVar;
  6605. stack.push(tmpVar);
  6606. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  6607. break;
  6608. case 'roll':
  6609. if (stack.length < 2) {
  6610. return null;
  6611. }
  6612. num2 = stack.pop();
  6613. num1 = stack.pop();
  6614. if (num2.type !== 'literal' || num1.type !== 'literal') {
  6615. // both roll operands must be numbers
  6616. return null;
  6617. }
  6618. j = num2.number;
  6619. n = num1.number;
  6620. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  6621. // ... and integers
  6622. return null;
  6623. }
  6624. j = ((j % n) + n) % n;
  6625. if (j === 0) {
  6626. break; // just skipping -- there are nothing to rotate
  6627. }
  6628. Array.prototype.push.apply(stack,
  6629. stack.splice(stack.length - n, n - j));
  6630. break;
  6631. default:
  6632. return null; // unsupported operator
  6633. }
  6634. }
  6635. if (stack.length !== outputSize) {
  6636. return null;
  6637. }
  6638. var result = [];
  6639. instructions.forEach(function (instruction) {
  6640. var statementBuilder = new ExpressionBuilderVisitor();
  6641. instruction.visit(statementBuilder);
  6642. result.push(statementBuilder.toString());
  6643. });
  6644. stack.forEach(function (expr, i) {
  6645. var statementBuilder = new ExpressionBuilderVisitor();
  6646. expr.visit(statementBuilder);
  6647. var min = range[i * 2], max = range[i * 2 + 1];
  6648. var out = [statementBuilder.toString()];
  6649. if (min > expr.min) {
  6650. out.unshift('Math.max(', min, ', ');
  6651. out.push(')');
  6652. }
  6653. if (max < expr.max) {
  6654. out.unshift('Math.min(', max, ', ');
  6655. out.push(')');
  6656. }
  6657. out.unshift('dest[destOffset + ', i, '] = ');
  6658. out.push(';');
  6659. result.push(out.join(''));
  6660. });
  6661. return result.join('\n');
  6662. }
  6663. };
  6664. return PostScriptCompiler;
  6665. })();
  6666. var ColorSpace = (function ColorSpaceClosure() {
  6667. // Constructor should define this.numComps, this.defaultColor, this.name
  6668. function ColorSpace() {
  6669. error('should not call ColorSpace constructor');
  6670. }
  6671. ColorSpace.prototype = {
  6672. /**
  6673. * Converts the color value to the RGB color. The color components are
  6674. * located in the src array starting from the srcOffset. Returns the array
  6675. * of the rgb components, each value ranging from [0,255].
  6676. */
  6677. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  6678. var rgb = new Uint8Array(3);
  6679. this.getRgbItem(src, srcOffset, rgb, 0);
  6680. return rgb;
  6681. },
  6682. /**
  6683. * Converts the color value to the RGB color, similar to the getRgb method.
  6684. * The result placed into the dest array starting from the destOffset.
  6685. */
  6686. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  6687. dest, destOffset) {
  6688. error('Should not call ColorSpace.getRgbItem');
  6689. },
  6690. /**
  6691. * Converts the specified number of the color values to the RGB colors.
  6692. * The colors are located in the src array starting from the srcOffset.
  6693. * The result is placed into the dest array starting from the destOffset.
  6694. * The src array items shall be in [0,2^bits) range, the dest array items
  6695. * will be in [0,255] range. alpha01 indicates how many alpha components
  6696. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  6697. * array).
  6698. */
  6699. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  6700. dest, destOffset, bits,
  6701. alpha01) {
  6702. error('Should not call ColorSpace.getRgbBuffer');
  6703. },
  6704. /**
  6705. * Determines the number of bytes required to store the result of the
  6706. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  6707. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  6708. */
  6709. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  6710. alpha01) {
  6711. error('Should not call ColorSpace.getOutputLength');
  6712. },
  6713. /**
  6714. * Returns true if source data will be equal the result/output data.
  6715. */
  6716. isPassthrough: function ColorSpace_isPassthrough(bits) {
  6717. return false;
  6718. },
  6719. /**
  6720. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  6721. * how many alpha components there are in the dest array; it will be either
  6722. * 0 (RGB array) or 1 (RGBA array).
  6723. */
  6724. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  6725. originalHeight, width, height,
  6726. actualHeight, bpc, comps, alpha01) {
  6727. var count = originalWidth * originalHeight;
  6728. var rgbBuf = null;
  6729. var numComponentColors = 1 << bpc;
  6730. var needsResizing = originalHeight !== height || originalWidth !== width;
  6731. var i, ii;
  6732. if (this.isPassthrough(bpc)) {
  6733. rgbBuf = comps;
  6734. } else if (this.numComps === 1 && count > numComponentColors &&
  6735. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  6736. // Optimization: create a color map when there is just one component and
  6737. // we are converting more colors than the size of the color map. We
  6738. // don't build the map if the colorspace is gray or rgb since those
  6739. // methods are faster than building a map. This mainly offers big speed
  6740. // ups for indexed and alternate colorspaces.
  6741. //
  6742. // TODO it may be worth while to cache the color map. While running
  6743. // testing I never hit a cache so I will leave that out for now (perhaps
  6744. // we are reparsing colorspaces too much?).
  6745. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  6746. new Uint16Array(numComponentColors);
  6747. var key;
  6748. for (i = 0; i < numComponentColors; i++) {
  6749. allColors[i] = i;
  6750. }
  6751. var colorMap = new Uint8Array(numComponentColors * 3);
  6752. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  6753. /* alpha01 = */ 0);
  6754. var destPos, rgbPos;
  6755. if (!needsResizing) {
  6756. // Fill in the RGB values directly into |dest|.
  6757. destPos = 0;
  6758. for (i = 0; i < count; ++i) {
  6759. key = comps[i] * 3;
  6760. dest[destPos++] = colorMap[key];
  6761. dest[destPos++] = colorMap[key + 1];
  6762. dest[destPos++] = colorMap[key + 2];
  6763. destPos += alpha01;
  6764. }
  6765. } else {
  6766. rgbBuf = new Uint8Array(count * 3);
  6767. rgbPos = 0;
  6768. for (i = 0; i < count; ++i) {
  6769. key = comps[i] * 3;
  6770. rgbBuf[rgbPos++] = colorMap[key];
  6771. rgbBuf[rgbPos++] = colorMap[key + 1];
  6772. rgbBuf[rgbPos++] = colorMap[key + 2];
  6773. }
  6774. }
  6775. } else {
  6776. if (!needsResizing) {
  6777. // Fill in the RGB values directly into |dest|.
  6778. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  6779. alpha01);
  6780. } else {
  6781. rgbBuf = new Uint8Array(count * 3);
  6782. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  6783. /* alpha01 = */ 0);
  6784. }
  6785. }
  6786. if (rgbBuf) {
  6787. if (needsResizing) {
  6788. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  6789. height, dest, alpha01);
  6790. } else {
  6791. rgbPos = 0;
  6792. destPos = 0;
  6793. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6794. dest[destPos++] = rgbBuf[rgbPos++];
  6795. dest[destPos++] = rgbBuf[rgbPos++];
  6796. dest[destPos++] = rgbBuf[rgbPos++];
  6797. destPos += alpha01;
  6798. }
  6799. }
  6800. }
  6801. },
  6802. /**
  6803. * True if the colorspace has components in the default range of [0, 1].
  6804. * This should be true for all colorspaces except for lab color spaces
  6805. * which are [0,100], [-128, 127], [-128, 127].
  6806. */
  6807. usesZeroToOneRange: true
  6808. };
  6809. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6810. var IR = ColorSpace.parseToIR(cs, xref, res);
  6811. if (IR instanceof AlternateCS) {
  6812. return IR;
  6813. }
  6814. return ColorSpace.fromIR(IR);
  6815. };
  6816. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6817. var name = isArray(IR) ? IR[0] : IR;
  6818. var whitePoint, blackPoint, gamma;
  6819. switch (name) {
  6820. case 'DeviceGrayCS':
  6821. return this.singletons.gray;
  6822. case 'DeviceRgbCS':
  6823. return this.singletons.rgb;
  6824. case 'DeviceCmykCS':
  6825. return this.singletons.cmyk;
  6826. case 'CalGrayCS':
  6827. whitePoint = IR[1].WhitePoint;
  6828. blackPoint = IR[1].BlackPoint;
  6829. gamma = IR[1].Gamma;
  6830. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6831. case 'CalRGBCS':
  6832. whitePoint = IR[1].WhitePoint;
  6833. blackPoint = IR[1].BlackPoint;
  6834. gamma = IR[1].Gamma;
  6835. var matrix = IR[1].Matrix;
  6836. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6837. case 'PatternCS':
  6838. var basePatternCS = IR[1];
  6839. if (basePatternCS) {
  6840. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6841. }
  6842. return new PatternCS(basePatternCS);
  6843. case 'IndexedCS':
  6844. var baseIndexedCS = IR[1];
  6845. var hiVal = IR[2];
  6846. var lookup = IR[3];
  6847. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6848. case 'AlternateCS':
  6849. var numComps = IR[1];
  6850. var alt = IR[2];
  6851. var tintFnIR = IR[3];
  6852. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6853. PDFFunction.fromIR(tintFnIR));
  6854. case 'LabCS':
  6855. whitePoint = IR[1].WhitePoint;
  6856. blackPoint = IR[1].BlackPoint;
  6857. var range = IR[1].Range;
  6858. return new LabCS(whitePoint, blackPoint, range);
  6859. default:
  6860. error('Unknown name ' + name);
  6861. }
  6862. return null;
  6863. };
  6864. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6865. if (isName(cs)) {
  6866. var colorSpaces = res.get('ColorSpace');
  6867. if (isDict(colorSpaces)) {
  6868. var refcs = colorSpaces.get(cs.name);
  6869. if (refcs) {
  6870. cs = refcs;
  6871. }
  6872. }
  6873. }
  6874. cs = xref.fetchIfRef(cs);
  6875. var mode;
  6876. if (isName(cs)) {
  6877. mode = cs.name;
  6878. this.mode = mode;
  6879. switch (mode) {
  6880. case 'DeviceGray':
  6881. case 'G':
  6882. return 'DeviceGrayCS';
  6883. case 'DeviceRGB':
  6884. case 'RGB':
  6885. return 'DeviceRgbCS';
  6886. case 'DeviceCMYK':
  6887. case 'CMYK':
  6888. return 'DeviceCmykCS';
  6889. case 'Pattern':
  6890. return ['PatternCS', null];
  6891. default:
  6892. error('unrecognized colorspace ' + mode);
  6893. }
  6894. } else if (isArray(cs)) {
  6895. mode = xref.fetchIfRef(cs[0]).name;
  6896. this.mode = mode;
  6897. var numComps, params, alt;
  6898. switch (mode) {
  6899. case 'DeviceGray':
  6900. case 'G':
  6901. return 'DeviceGrayCS';
  6902. case 'DeviceRGB':
  6903. case 'RGB':
  6904. return 'DeviceRgbCS';
  6905. case 'DeviceCMYK':
  6906. case 'CMYK':
  6907. return 'DeviceCmykCS';
  6908. case 'CalGray':
  6909. params = xref.fetchIfRef(cs[1]).getAll();
  6910. return ['CalGrayCS', params];
  6911. case 'CalRGB':
  6912. params = xref.fetchIfRef(cs[1]).getAll();
  6913. return ['CalRGBCS', params];
  6914. case 'ICCBased':
  6915. var stream = xref.fetchIfRef(cs[1]);
  6916. var dict = stream.dict;
  6917. numComps = dict.get('N');
  6918. alt = dict.get('Alternate');
  6919. if (alt) {
  6920. var altIR = ColorSpace.parseToIR(alt, xref, res);
  6921. // Parse the /Alternate CS to ensure that the number of components
  6922. // are correct, and also (indirectly) that it is not a PatternCS.
  6923. var altCS = ColorSpace.fromIR(altIR);
  6924. if (altCS.numComps === numComps) {
  6925. return altIR;
  6926. }
  6927. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  6928. }
  6929. if (numComps === 1) {
  6930. return 'DeviceGrayCS';
  6931. } else if (numComps === 3) {
  6932. return 'DeviceRgbCS';
  6933. } else if (numComps === 4) {
  6934. return 'DeviceCmykCS';
  6935. }
  6936. break;
  6937. case 'Pattern':
  6938. var basePatternCS = cs[1] || null;
  6939. if (basePatternCS) {
  6940. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6941. }
  6942. return ['PatternCS', basePatternCS];
  6943. case 'Indexed':
  6944. case 'I':
  6945. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6946. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  6947. var lookup = xref.fetchIfRef(cs[3]);
  6948. if (isStream(lookup)) {
  6949. lookup = lookup.getBytes();
  6950. }
  6951. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6952. case 'Separation':
  6953. case 'DeviceN':
  6954. var name = xref.fetchIfRef(cs[1]);
  6955. numComps = 1;
  6956. if (isName(name)) {
  6957. numComps = 1;
  6958. } else if (isArray(name)) {
  6959. numComps = name.length;
  6960. }
  6961. alt = ColorSpace.parseToIR(cs[2], xref, res);
  6962. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6963. return ['AlternateCS', numComps, alt, tintFnIR];
  6964. case 'Lab':
  6965. params = xref.fetchIfRef(cs[1]).getAll();
  6966. return ['LabCS', params];
  6967. default:
  6968. error('unimplemented color space object "' + mode + '"');
  6969. }
  6970. } else {
  6971. error('unrecognized color space object: "' + cs + '"');
  6972. }
  6973. return null;
  6974. };
  6975. /**
  6976. * Checks if a decode map matches the default decode map for a color space.
  6977. * This handles the general decode maps where there are two values per
  6978. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6979. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6980. * slightly different.
  6981. * @param {Array} decode Decode map (usually from an image).
  6982. * @param {Number} n Number of components the color space has.
  6983. */
  6984. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6985. if (!isArray(decode)) {
  6986. return true;
  6987. }
  6988. if (n * 2 !== decode.length) {
  6989. warn('The decode map is not the correct length');
  6990. return true;
  6991. }
  6992. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6993. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6994. return false;
  6995. }
  6996. }
  6997. return true;
  6998. };
  6999. ColorSpace.singletons = {
  7000. get gray() {
  7001. return shadow(this, 'gray', new DeviceGrayCS());
  7002. },
  7003. get rgb() {
  7004. return shadow(this, 'rgb', new DeviceRgbCS());
  7005. },
  7006. get cmyk() {
  7007. return shadow(this, 'cmyk', new DeviceCmykCS());
  7008. }
  7009. };
  7010. return ColorSpace;
  7011. })();
  7012. /**
  7013. * Alternate color space handles both Separation and DeviceN color spaces. A
  7014. * Separation color space is actually just a DeviceN with one color component.
  7015. * Both color spaces use a tinting function to convert colors to a base color
  7016. * space.
  7017. */
  7018. var AlternateCS = (function AlternateCSClosure() {
  7019. function AlternateCS(numComps, base, tintFn) {
  7020. this.name = 'Alternate';
  7021. this.numComps = numComps;
  7022. this.defaultColor = new Float32Array(numComps);
  7023. for (var i = 0; i < numComps; ++i) {
  7024. this.defaultColor[i] = 1;
  7025. }
  7026. this.base = base;
  7027. this.tintFn = tintFn;
  7028. this.tmpBuf = new Float32Array(base.numComps);
  7029. }
  7030. AlternateCS.prototype = {
  7031. getRgb: ColorSpace.prototype.getRgb,
  7032. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  7033. dest, destOffset) {
  7034. var tmpBuf = this.tmpBuf;
  7035. this.tintFn(src, srcOffset, tmpBuf, 0);
  7036. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  7037. },
  7038. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  7039. dest, destOffset, bits,
  7040. alpha01) {
  7041. var tintFn = this.tintFn;
  7042. var base = this.base;
  7043. var scale = 1 / ((1 << bits) - 1);
  7044. var baseNumComps = base.numComps;
  7045. var usesZeroToOneRange = base.usesZeroToOneRange;
  7046. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  7047. alpha01 === 0;
  7048. var pos = isPassthrough ? destOffset : 0;
  7049. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  7050. var numComps = this.numComps;
  7051. var scaled = new Float32Array(numComps);
  7052. var tinted = new Float32Array(baseNumComps);
  7053. var i, j;
  7054. if (usesZeroToOneRange) {
  7055. for (i = 0; i < count; i++) {
  7056. for (j = 0; j < numComps; j++) {
  7057. scaled[j] = src[srcOffset++] * scale;
  7058. }
  7059. tintFn(scaled, 0, tinted, 0);
  7060. for (j = 0; j < baseNumComps; j++) {
  7061. baseBuf[pos++] = tinted[j] * 255;
  7062. }
  7063. }
  7064. } else {
  7065. for (i = 0; i < count; i++) {
  7066. for (j = 0; j < numComps; j++) {
  7067. scaled[j] = src[srcOffset++] * scale;
  7068. }
  7069. tintFn(scaled, 0, tinted, 0);
  7070. base.getRgbItem(tinted, 0, baseBuf, pos);
  7071. pos += baseNumComps;
  7072. }
  7073. }
  7074. if (!isPassthrough) {
  7075. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  7076. }
  7077. },
  7078. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  7079. alpha01) {
  7080. return this.base.getOutputLength(inputLength *
  7081. this.base.numComps / this.numComps,
  7082. alpha01);
  7083. },
  7084. isPassthrough: ColorSpace.prototype.isPassthrough,
  7085. fillRgb: ColorSpace.prototype.fillRgb,
  7086. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  7087. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7088. },
  7089. usesZeroToOneRange: true
  7090. };
  7091. return AlternateCS;
  7092. })();
  7093. var PatternCS = (function PatternCSClosure() {
  7094. function PatternCS(baseCS) {
  7095. this.name = 'Pattern';
  7096. this.base = baseCS;
  7097. }
  7098. PatternCS.prototype = {};
  7099. return PatternCS;
  7100. })();
  7101. var IndexedCS = (function IndexedCSClosure() {
  7102. function IndexedCS(base, highVal, lookup) {
  7103. this.name = 'Indexed';
  7104. this.numComps = 1;
  7105. this.defaultColor = new Uint8Array([0]);
  7106. this.base = base;
  7107. this.highVal = highVal;
  7108. var baseNumComps = base.numComps;
  7109. var length = baseNumComps * highVal;
  7110. var lookupArray;
  7111. if (isStream(lookup)) {
  7112. lookupArray = new Uint8Array(length);
  7113. var bytes = lookup.getBytes(length);
  7114. lookupArray.set(bytes);
  7115. } else if (isString(lookup)) {
  7116. lookupArray = new Uint8Array(length);
  7117. for (var i = 0; i < length; ++i) {
  7118. lookupArray[i] = lookup.charCodeAt(i);
  7119. }
  7120. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  7121. lookupArray = lookup;
  7122. } else {
  7123. error('Unrecognized lookup table: ' + lookup);
  7124. }
  7125. this.lookup = lookupArray;
  7126. }
  7127. IndexedCS.prototype = {
  7128. getRgb: ColorSpace.prototype.getRgb,
  7129. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  7130. dest, destOffset) {
  7131. var numComps = this.base.numComps;
  7132. var start = src[srcOffset] * numComps;
  7133. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  7134. },
  7135. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  7136. dest, destOffset, bits,
  7137. alpha01) {
  7138. var base = this.base;
  7139. var numComps = base.numComps;
  7140. var outputDelta = base.getOutputLength(numComps, alpha01);
  7141. var lookup = this.lookup;
  7142. for (var i = 0; i < count; ++i) {
  7143. var lookupPos = src[srcOffset++] * numComps;
  7144. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  7145. destOffset += outputDelta;
  7146. }
  7147. },
  7148. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  7149. return this.base.getOutputLength(inputLength * this.base.numComps,
  7150. alpha01);
  7151. },
  7152. isPassthrough: ColorSpace.prototype.isPassthrough,
  7153. fillRgb: ColorSpace.prototype.fillRgb,
  7154. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  7155. // indexed color maps shouldn't be changed
  7156. return true;
  7157. },
  7158. usesZeroToOneRange: true
  7159. };
  7160. return IndexedCS;
  7161. })();
  7162. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  7163. function DeviceGrayCS() {
  7164. this.name = 'DeviceGray';
  7165. this.numComps = 1;
  7166. this.defaultColor = new Float32Array([0]);
  7167. }
  7168. DeviceGrayCS.prototype = {
  7169. getRgb: ColorSpace.prototype.getRgb,
  7170. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  7171. dest, destOffset) {
  7172. var c = (src[srcOffset] * 255) | 0;
  7173. c = c < 0 ? 0 : c > 255 ? 255 : c;
  7174. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  7175. },
  7176. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  7177. dest, destOffset, bits,
  7178. alpha01) {
  7179. var scale = 255 / ((1 << bits) - 1);
  7180. var j = srcOffset, q = destOffset;
  7181. for (var i = 0; i < count; ++i) {
  7182. var c = (scale * src[j++]) | 0;
  7183. dest[q++] = c;
  7184. dest[q++] = c;
  7185. dest[q++] = c;
  7186. q += alpha01;
  7187. }
  7188. },
  7189. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  7190. alpha01) {
  7191. return inputLength * (3 + alpha01);
  7192. },
  7193. isPassthrough: ColorSpace.prototype.isPassthrough,
  7194. fillRgb: ColorSpace.prototype.fillRgb,
  7195. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  7196. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7197. },
  7198. usesZeroToOneRange: true
  7199. };
  7200. return DeviceGrayCS;
  7201. })();
  7202. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  7203. function DeviceRgbCS() {
  7204. this.name = 'DeviceRGB';
  7205. this.numComps = 3;
  7206. this.defaultColor = new Float32Array([0, 0, 0]);
  7207. }
  7208. DeviceRgbCS.prototype = {
  7209. getRgb: ColorSpace.prototype.getRgb,
  7210. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  7211. dest, destOffset) {
  7212. var r = (src[srcOffset] * 255) | 0;
  7213. var g = (src[srcOffset + 1] * 255) | 0;
  7214. var b = (src[srcOffset + 2] * 255) | 0;
  7215. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  7216. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  7217. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  7218. },
  7219. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  7220. dest, destOffset, bits,
  7221. alpha01) {
  7222. if (bits === 8 && alpha01 === 0) {
  7223. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  7224. return;
  7225. }
  7226. var scale = 255 / ((1 << bits) - 1);
  7227. var j = srcOffset, q = destOffset;
  7228. for (var i = 0; i < count; ++i) {
  7229. dest[q++] = (scale * src[j++]) | 0;
  7230. dest[q++] = (scale * src[j++]) | 0;
  7231. dest[q++] = (scale * src[j++]) | 0;
  7232. q += alpha01;
  7233. }
  7234. },
  7235. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  7236. alpha01) {
  7237. return (inputLength * (3 + alpha01) / 3) | 0;
  7238. },
  7239. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  7240. return bits === 8;
  7241. },
  7242. fillRgb: ColorSpace.prototype.fillRgb,
  7243. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  7244. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7245. },
  7246. usesZeroToOneRange: true
  7247. };
  7248. return DeviceRgbCS;
  7249. })();
  7250. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  7251. // The coefficients below was found using numerical analysis: the method of
  7252. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  7253. // where color_value is the tabular value from the table of sampled RGB colors
  7254. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  7255. // CMYK color conversion using the estimation below:
  7256. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  7257. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  7258. var c = src[srcOffset + 0] * srcScale;
  7259. var m = src[srcOffset + 1] * srcScale;
  7260. var y = src[srcOffset + 2] * srcScale;
  7261. var k = src[srcOffset + 3] * srcScale;
  7262. var r =
  7263. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  7264. 18.82290502165302 * y + 212.25662451639585 * k +
  7265. -285.2331026137004) +
  7266. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  7267. -17.873870861415444 * k - 5.497006427196366) +
  7268. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  7269. 17.5119270841813) +
  7270. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  7271. var g =
  7272. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  7273. 6.871425592049007 * y + 31.159100130055922 * k +
  7274. -79.2970844816548) +
  7275. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  7276. 131.35250912493976 * k - 190.9453302588951) +
  7277. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  7278. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  7279. var b =
  7280. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  7281. 30.89978309703729 * y - 0.23883238689178934 * k +
  7282. -14.183576799673286) +
  7283. m * (10.49593273432072 * m + 63.02378494754052 * y +
  7284. 50.606957656360734 * k - 112.23884253719248) +
  7285. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  7286. -193.58209356861505) +
  7287. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  7288. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  7289. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  7290. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  7291. }
  7292. function DeviceCmykCS() {
  7293. this.name = 'DeviceCMYK';
  7294. this.numComps = 4;
  7295. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  7296. }
  7297. DeviceCmykCS.prototype = {
  7298. getRgb: ColorSpace.prototype.getRgb,
  7299. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  7300. dest, destOffset) {
  7301. convertToRgb(src, srcOffset, 1, dest, destOffset);
  7302. },
  7303. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  7304. dest, destOffset, bits,
  7305. alpha01) {
  7306. var scale = 1 / ((1 << bits) - 1);
  7307. for (var i = 0; i < count; i++) {
  7308. convertToRgb(src, srcOffset, scale, dest, destOffset);
  7309. srcOffset += 4;
  7310. destOffset += 3 + alpha01;
  7311. }
  7312. },
  7313. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  7314. alpha01) {
  7315. return (inputLength / 4 * (3 + alpha01)) | 0;
  7316. },
  7317. isPassthrough: ColorSpace.prototype.isPassthrough,
  7318. fillRgb: ColorSpace.prototype.fillRgb,
  7319. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  7320. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7321. },
  7322. usesZeroToOneRange: true
  7323. };
  7324. return DeviceCmykCS;
  7325. })();
  7326. //
  7327. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  7328. //
  7329. var CalGrayCS = (function CalGrayCSClosure() {
  7330. function CalGrayCS(whitePoint, blackPoint, gamma) {
  7331. this.name = 'CalGray';
  7332. this.numComps = 1;
  7333. this.defaultColor = new Float32Array([0]);
  7334. if (!whitePoint) {
  7335. error('WhitePoint missing - required for color space CalGray');
  7336. }
  7337. blackPoint = blackPoint || [0, 0, 0];
  7338. gamma = gamma || 1;
  7339. // Translate arguments to spec variables.
  7340. this.XW = whitePoint[0];
  7341. this.YW = whitePoint[1];
  7342. this.ZW = whitePoint[2];
  7343. this.XB = blackPoint[0];
  7344. this.YB = blackPoint[1];
  7345. this.ZB = blackPoint[2];
  7346. this.G = gamma;
  7347. // Validate variables as per spec.
  7348. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7349. error('Invalid WhitePoint components for ' + this.name +
  7350. ', no fallback available');
  7351. }
  7352. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7353. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  7354. this.XB = this.YB = this.ZB = 0;
  7355. }
  7356. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  7357. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  7358. ', ZB: ' + this.ZB + ', only default values are supported.');
  7359. }
  7360. if (this.G < 1) {
  7361. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  7362. ', falling back to default');
  7363. this.G = 1;
  7364. }
  7365. }
  7366. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  7367. // A represents a gray component of a calibrated gray space.
  7368. // A <---> AG in the spec
  7369. var A = src[srcOffset] * scale;
  7370. var AG = Math.pow(A, cs.G);
  7371. // Computes L as per spec. ( = cs.YW * AG )
  7372. // Except if other than default BlackPoint values are used.
  7373. var L = cs.YW * AG;
  7374. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  7375. // Convert values to rgb range [0, 255].
  7376. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  7377. dest[destOffset] = val;
  7378. dest[destOffset + 1] = val;
  7379. dest[destOffset + 2] = val;
  7380. }
  7381. CalGrayCS.prototype = {
  7382. getRgb: ColorSpace.prototype.getRgb,
  7383. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  7384. dest, destOffset) {
  7385. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  7386. },
  7387. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  7388. dest, destOffset, bits,
  7389. alpha01) {
  7390. var scale = 1 / ((1 << bits) - 1);
  7391. for (var i = 0; i < count; ++i) {
  7392. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  7393. srcOffset += 1;
  7394. destOffset += 3 + alpha01;
  7395. }
  7396. },
  7397. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  7398. return inputLength * (3 + alpha01);
  7399. },
  7400. isPassthrough: ColorSpace.prototype.isPassthrough,
  7401. fillRgb: ColorSpace.prototype.fillRgb,
  7402. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  7403. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7404. },
  7405. usesZeroToOneRange: true
  7406. };
  7407. return CalGrayCS;
  7408. })();
  7409. //
  7410. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  7411. //
  7412. var CalRGBCS = (function CalRGBCSClosure() {
  7413. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  7414. // matrices.
  7415. var BRADFORD_SCALE_MATRIX = new Float32Array([
  7416. 0.8951, 0.2664, -0.1614,
  7417. -0.7502, 1.7135, 0.0367,
  7418. 0.0389, -0.0685, 1.0296]);
  7419. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  7420. 0.9869929, -0.1470543, 0.1599627,
  7421. 0.4323053, 0.5183603, 0.0492912,
  7422. -0.0085287, 0.0400428, 0.9684867]);
  7423. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  7424. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  7425. 3.2404542, -1.5371385, -0.4985314,
  7426. -0.9692660, 1.8760108, 0.0415560,
  7427. 0.0556434, -0.2040259, 1.0572252]);
  7428. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  7429. var tempNormalizeMatrix = new Float32Array(3);
  7430. var tempConvertMatrix1 = new Float32Array(3);
  7431. var tempConvertMatrix2 = new Float32Array(3);
  7432. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  7433. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  7434. this.name = 'CalRGB';
  7435. this.numComps = 3;
  7436. this.defaultColor = new Float32Array(3);
  7437. if (!whitePoint) {
  7438. error('WhitePoint missing - required for color space CalRGB');
  7439. }
  7440. blackPoint = blackPoint || new Float32Array(3);
  7441. gamma = gamma || new Float32Array([1, 1, 1]);
  7442. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  7443. // Translate arguments to spec variables.
  7444. var XW = whitePoint[0];
  7445. var YW = whitePoint[1];
  7446. var ZW = whitePoint[2];
  7447. this.whitePoint = whitePoint;
  7448. var XB = blackPoint[0];
  7449. var YB = blackPoint[1];
  7450. var ZB = blackPoint[2];
  7451. this.blackPoint = blackPoint;
  7452. this.GR = gamma[0];
  7453. this.GG = gamma[1];
  7454. this.GB = gamma[2];
  7455. this.MXA = matrix[0];
  7456. this.MYA = matrix[1];
  7457. this.MZA = matrix[2];
  7458. this.MXB = matrix[3];
  7459. this.MYB = matrix[4];
  7460. this.MZB = matrix[5];
  7461. this.MXC = matrix[6];
  7462. this.MYC = matrix[7];
  7463. this.MZC = matrix[8];
  7464. // Validate variables as per spec.
  7465. if (XW < 0 || ZW < 0 || YW !== 1) {
  7466. error('Invalid WhitePoint components for ' + this.name +
  7467. ', no fallback available');
  7468. }
  7469. if (XB < 0 || YB < 0 || ZB < 0) {
  7470. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  7471. ', ' + ZB + '], falling back to default');
  7472. this.blackPoint = new Float32Array(3);
  7473. }
  7474. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  7475. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  7476. '] for ' + this.name + ', falling back to default');
  7477. this.GR = this.GG = this.GB = 1;
  7478. }
  7479. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  7480. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  7481. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  7482. info('Invalid Matrix for ' + this.name + ' [' +
  7483. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  7484. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  7485. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  7486. '], falling back to default');
  7487. this.MXA = this.MYB = this.MZC = 1;
  7488. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  7489. }
  7490. }
  7491. function matrixProduct(a, b, result) {
  7492. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  7493. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  7494. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  7495. }
  7496. function convertToFlat(sourceWhitePoint, LMS, result) {
  7497. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  7498. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  7499. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  7500. }
  7501. function convertToD65(sourceWhitePoint, LMS, result) {
  7502. var D65X = 0.95047;
  7503. var D65Y = 1;
  7504. var D65Z = 1.08883;
  7505. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  7506. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  7507. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  7508. }
  7509. function sRGBTransferFunction(color) {
  7510. // See http://en.wikipedia.org/wiki/SRGB.
  7511. if (color <= 0.0031308){
  7512. return adjustToRange(0, 1, 12.92 * color);
  7513. }
  7514. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  7515. }
  7516. function adjustToRange(min, max, value) {
  7517. return Math.max(min, Math.min(max, value));
  7518. }
  7519. function decodeL(L) {
  7520. if (L < 0) {
  7521. return -decodeL(-L);
  7522. }
  7523. if (L > 8.0) {
  7524. return Math.pow(((L + 16) / 116), 3);
  7525. }
  7526. return L * DECODE_L_CONSTANT;
  7527. }
  7528. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  7529. // In case the blackPoint is already the default blackPoint then there is
  7530. // no need to do compensation.
  7531. if (sourceBlackPoint[0] === 0 &&
  7532. sourceBlackPoint[1] === 0 &&
  7533. sourceBlackPoint[2] === 0) {
  7534. result[0] = XYZ_Flat[0];
  7535. result[1] = XYZ_Flat[1];
  7536. result[2] = XYZ_Flat[2];
  7537. return;
  7538. }
  7539. // For the blackPoint calculation details, please see
  7540. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  7541. // AdobeBPC.pdf.
  7542. // The destination blackPoint is the default blackPoint [0, 0, 0].
  7543. var zeroDecodeL = decodeL(0);
  7544. var X_DST = zeroDecodeL;
  7545. var X_SRC = decodeL(sourceBlackPoint[0]);
  7546. var Y_DST = zeroDecodeL;
  7547. var Y_SRC = decodeL(sourceBlackPoint[1]);
  7548. var Z_DST = zeroDecodeL;
  7549. var Z_SRC = decodeL(sourceBlackPoint[2]);
  7550. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  7551. var X_Offset = 1 - X_Scale;
  7552. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  7553. var Y_Offset = 1 - Y_Scale;
  7554. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  7555. var Z_Offset = 1 - Z_Scale;
  7556. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  7557. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  7558. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  7559. }
  7560. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  7561. // In case the whitePoint is already flat then there is no need to do
  7562. // normalization.
  7563. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  7564. result[0] = XYZ_In[0];
  7565. result[1] = XYZ_In[1];
  7566. result[2] = XYZ_In[2];
  7567. return;
  7568. }
  7569. var LMS = result;
  7570. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  7571. var LMS_Flat = tempNormalizeMatrix;
  7572. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  7573. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  7574. }
  7575. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  7576. var LMS = result;
  7577. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  7578. var LMS_D65 = tempNormalizeMatrix;
  7579. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  7580. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  7581. }
  7582. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  7583. // A, B and C represent a red, green and blue components of a calibrated
  7584. // rgb space.
  7585. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  7586. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  7587. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  7588. // A <---> AGR in the spec
  7589. // B <---> BGG in the spec
  7590. // C <---> CGB in the spec
  7591. var AGR = Math.pow(A, cs.GR);
  7592. var BGG = Math.pow(B, cs.GG);
  7593. var CGB = Math.pow(C, cs.GB);
  7594. // Computes intermediate variables L, M, N as per spec.
  7595. // To decode X, Y, Z values map L, M, N directly to them.
  7596. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  7597. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  7598. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  7599. // The following calculations are based on this document:
  7600. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  7601. // AdobeBPC.pdf.
  7602. var XYZ = tempConvertMatrix1;
  7603. XYZ[0] = X;
  7604. XYZ[1] = Y;
  7605. XYZ[2] = Z;
  7606. var XYZ_Flat = tempConvertMatrix2;
  7607. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  7608. var XYZ_Black = tempConvertMatrix1;
  7609. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  7610. var XYZ_D65 = tempConvertMatrix2;
  7611. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  7612. var SRGB = tempConvertMatrix1;
  7613. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  7614. var sR = sRGBTransferFunction(SRGB[0]);
  7615. var sG = sRGBTransferFunction(SRGB[1]);
  7616. var sB = sRGBTransferFunction(SRGB[2]);
  7617. // Convert the values to rgb range [0, 255].
  7618. dest[destOffset] = Math.round(sR * 255);
  7619. dest[destOffset + 1] = Math.round(sG * 255);
  7620. dest[destOffset + 2] = Math.round(sB * 255);
  7621. }
  7622. CalRGBCS.prototype = {
  7623. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  7624. var rgb = new Uint8Array(3);
  7625. this.getRgbItem(src, srcOffset, rgb, 0);
  7626. return rgb;
  7627. },
  7628. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  7629. dest, destOffset) {
  7630. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  7631. },
  7632. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  7633. dest, destOffset, bits,
  7634. alpha01) {
  7635. var scale = 1 / ((1 << bits) - 1);
  7636. for (var i = 0; i < count; ++i) {
  7637. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  7638. srcOffset += 3;
  7639. destOffset += 3 + alpha01;
  7640. }
  7641. },
  7642. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  7643. return (inputLength * (3 + alpha01) / 3) | 0;
  7644. },
  7645. isPassthrough: ColorSpace.prototype.isPassthrough,
  7646. fillRgb: ColorSpace.prototype.fillRgb,
  7647. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  7648. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  7649. },
  7650. usesZeroToOneRange: true
  7651. };
  7652. return CalRGBCS;
  7653. })();
  7654. //
  7655. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  7656. //
  7657. var LabCS = (function LabCSClosure() {
  7658. function LabCS(whitePoint, blackPoint, range) {
  7659. this.name = 'Lab';
  7660. this.numComps = 3;
  7661. this.defaultColor = new Float32Array([0, 0, 0]);
  7662. if (!whitePoint) {
  7663. error('WhitePoint missing - required for color space Lab');
  7664. }
  7665. blackPoint = blackPoint || [0, 0, 0];
  7666. range = range || [-100, 100, -100, 100];
  7667. // Translate args to spec variables
  7668. this.XW = whitePoint[0];
  7669. this.YW = whitePoint[1];
  7670. this.ZW = whitePoint[2];
  7671. this.amin = range[0];
  7672. this.amax = range[1];
  7673. this.bmin = range[2];
  7674. this.bmax = range[3];
  7675. // These are here just for completeness - the spec doesn't offer any
  7676. // formulas that use BlackPoint in Lab
  7677. this.XB = blackPoint[0];
  7678. this.YB = blackPoint[1];
  7679. this.ZB = blackPoint[2];
  7680. // Validate vars as per spec
  7681. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7682. error('Invalid WhitePoint components, no fallback available');
  7683. }
  7684. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7685. info('Invalid BlackPoint, falling back to default');
  7686. this.XB = this.YB = this.ZB = 0;
  7687. }
  7688. if (this.amin > this.amax || this.bmin > this.bmax) {
  7689. info('Invalid Range, falling back to defaults');
  7690. this.amin = -100;
  7691. this.amax = 100;
  7692. this.bmin = -100;
  7693. this.bmax = 100;
  7694. }
  7695. }
  7696. // Function g(x) from spec
  7697. function fn_g(x) {
  7698. if (x >= 6 / 29) {
  7699. return x * x * x;
  7700. } else {
  7701. return (108 / 841) * (x - 4 / 29);
  7702. }
  7703. }
  7704. function decode(value, high1, low2, high2) {
  7705. return low2 + (value) * (high2 - low2) / (high1);
  7706. }
  7707. // If decoding is needed maxVal should be 2^bits per component - 1.
  7708. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  7709. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  7710. // not the usual [0, 1]. If a command like setFillColor is used the src
  7711. // values will already be within the correct range. However, if we are
  7712. // converting an image we have to map the values to the correct range given
  7713. // above.
  7714. // Ls,as,bs <---> L*,a*,b* in the spec
  7715. var Ls = src[srcOffset];
  7716. var as = src[srcOffset + 1];
  7717. var bs = src[srcOffset + 2];
  7718. if (maxVal !== false) {
  7719. Ls = decode(Ls, maxVal, 0, 100);
  7720. as = decode(as, maxVal, cs.amin, cs.amax);
  7721. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  7722. }
  7723. // Adjust limits of 'as' and 'bs'
  7724. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  7725. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  7726. // Computes intermediate variables X,Y,Z as per spec
  7727. var M = (Ls + 16) / 116;
  7728. var L = M + (as / 500);
  7729. var N = M - (bs / 200);
  7730. var X = cs.XW * fn_g(L);
  7731. var Y = cs.YW * fn_g(M);
  7732. var Z = cs.ZW * fn_g(N);
  7733. var r, g, b;
  7734. // Using different conversions for D50 and D65 white points,
  7735. // per http://www.color.org/srgb.pdf
  7736. if (cs.ZW < 1) {
  7737. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  7738. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  7739. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  7740. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  7741. } else {
  7742. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  7743. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  7744. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  7745. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  7746. }
  7747. // clamp color values to [0,1] range then convert to [0,255] range.
  7748. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  7749. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  7750. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  7751. }
  7752. LabCS.prototype = {
  7753. getRgb: ColorSpace.prototype.getRgb,
  7754. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  7755. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  7756. },
  7757. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  7758. dest, destOffset, bits,
  7759. alpha01) {
  7760. var maxVal = (1 << bits) - 1;
  7761. for (var i = 0; i < count; i++) {
  7762. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  7763. srcOffset += 3;
  7764. destOffset += 3 + alpha01;
  7765. }
  7766. },
  7767. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  7768. return (inputLength * (3 + alpha01) / 3) | 0;
  7769. },
  7770. isPassthrough: ColorSpace.prototype.isPassthrough,
  7771. fillRgb: ColorSpace.prototype.fillRgb,
  7772. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  7773. // XXX: Decoding is handled with the lab conversion because of the strange
  7774. // ranges that are used.
  7775. return true;
  7776. },
  7777. usesZeroToOneRange: false
  7778. };
  7779. return LabCS;
  7780. })();
  7781. var ARCFourCipher = (function ARCFourCipherClosure() {
  7782. function ARCFourCipher(key) {
  7783. this.a = 0;
  7784. this.b = 0;
  7785. var s = new Uint8Array(256);
  7786. var i, j = 0, tmp, keyLength = key.length;
  7787. for (i = 0; i < 256; ++i) {
  7788. s[i] = i;
  7789. }
  7790. for (i = 0; i < 256; ++i) {
  7791. tmp = s[i];
  7792. j = (j + tmp + key[i % keyLength]) & 0xFF;
  7793. s[i] = s[j];
  7794. s[j] = tmp;
  7795. }
  7796. this.s = s;
  7797. }
  7798. ARCFourCipher.prototype = {
  7799. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  7800. var i, n = data.length, tmp, tmp2;
  7801. var a = this.a, b = this.b, s = this.s;
  7802. var output = new Uint8Array(n);
  7803. for (i = 0; i < n; ++i) {
  7804. a = (a + 1) & 0xFF;
  7805. tmp = s[a];
  7806. b = (b + tmp) & 0xFF;
  7807. tmp2 = s[b];
  7808. s[a] = tmp2;
  7809. s[b] = tmp;
  7810. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7811. }
  7812. this.a = a;
  7813. this.b = b;
  7814. return output;
  7815. }
  7816. };
  7817. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7818. return ARCFourCipher;
  7819. })();
  7820. var calculateMD5 = (function calculateMD5Closure() {
  7821. var r = new Uint8Array([
  7822. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7823. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7824. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7825. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7826. var k = new Int32Array([
  7827. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7828. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7829. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7830. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7831. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7832. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7833. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7834. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7835. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7836. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7837. -145523070, -1120210379, 718787259, -343485551]);
  7838. function hash(data, offset, length) {
  7839. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7840. // pre-processing
  7841. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7842. var padded = new Uint8Array(paddedLength);
  7843. var i, j, n;
  7844. for (i = 0; i < length; ++i) {
  7845. padded[i] = data[offset++];
  7846. }
  7847. padded[i++] = 0x80;
  7848. n = paddedLength - 8;
  7849. while (i < n) {
  7850. padded[i++] = 0;
  7851. }
  7852. padded[i++] = (length << 3) & 0xFF;
  7853. padded[i++] = (length >> 5) & 0xFF;
  7854. padded[i++] = (length >> 13) & 0xFF;
  7855. padded[i++] = (length >> 21) & 0xFF;
  7856. padded[i++] = (length >>> 29) & 0xFF;
  7857. padded[i++] = 0;
  7858. padded[i++] = 0;
  7859. padded[i++] = 0;
  7860. var w = new Int32Array(16);
  7861. for (i = 0; i < paddedLength;) {
  7862. for (j = 0; j < 16; ++j, i += 4) {
  7863. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7864. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7865. }
  7866. var a = h0, b = h1, c = h2, d = h3, f, g;
  7867. for (j = 0; j < 64; ++j) {
  7868. if (j < 16) {
  7869. f = (b & c) | ((~b) & d);
  7870. g = j;
  7871. } else if (j < 32) {
  7872. f = (d & b) | ((~d) & c);
  7873. g = (5 * j + 1) & 15;
  7874. } else if (j < 48) {
  7875. f = b ^ c ^ d;
  7876. g = (3 * j + 5) & 15;
  7877. } else {
  7878. f = c ^ (b | (~d));
  7879. g = (7 * j) & 15;
  7880. }
  7881. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7882. d = c;
  7883. c = b;
  7884. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7885. a = tmp;
  7886. }
  7887. h0 = (h0 + a) | 0;
  7888. h1 = (h1 + b) | 0;
  7889. h2 = (h2 + c) | 0;
  7890. h3 = (h3 + d) | 0;
  7891. }
  7892. return new Uint8Array([
  7893. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7894. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7895. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7896. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7897. ]);
  7898. }
  7899. return hash;
  7900. })();
  7901. var Word64 = (function Word64Closure() {
  7902. function Word64(highInteger, lowInteger) {
  7903. this.high = highInteger | 0;
  7904. this.low = lowInteger | 0;
  7905. }
  7906. Word64.prototype = {
  7907. and: function Word64_and(word) {
  7908. this.high &= word.high;
  7909. this.low &= word.low;
  7910. },
  7911. xor: function Word64_xor(word) {
  7912. this.high ^= word.high;
  7913. this.low ^= word.low;
  7914. },
  7915. or: function Word64_or(word) {
  7916. this.high |= word.high;
  7917. this.low |= word.low;
  7918. },
  7919. shiftRight: function Word64_shiftRight(places) {
  7920. if (places >= 32) {
  7921. this.low = (this.high >>> (places - 32)) | 0;
  7922. this.high = 0;
  7923. } else {
  7924. this.low = (this.low >>> places) | (this.high << (32 - places));
  7925. this.high = (this.high >>> places) | 0;
  7926. }
  7927. },
  7928. shiftLeft: function Word64_shiftLeft(places) {
  7929. if (places >= 32) {
  7930. this.high = this.low << (places - 32);
  7931. this.low = 0;
  7932. } else {
  7933. this.high = (this.high << places) | (this.low >>> (32 - places));
  7934. this.low = this.low << places;
  7935. }
  7936. },
  7937. rotateRight: function Word64_rotateRight(places) {
  7938. var low, high;
  7939. if (places & 32) {
  7940. high = this.low;
  7941. low = this.high;
  7942. } else {
  7943. low = this.low;
  7944. high = this.high;
  7945. }
  7946. places &= 31;
  7947. this.low = (low >>> places) | (high << (32 - places));
  7948. this.high = (high >>> places) | (low << (32 - places));
  7949. },
  7950. not: function Word64_not() {
  7951. this.high = ~this.high;
  7952. this.low = ~this.low;
  7953. },
  7954. add: function Word64_add(word) {
  7955. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7956. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7957. if (lowAdd > 0xFFFFFFFF) {
  7958. highAdd += 1;
  7959. }
  7960. this.low = lowAdd | 0;
  7961. this.high = highAdd | 0;
  7962. },
  7963. copyTo: function Word64_copyTo(bytes, offset) {
  7964. bytes[offset] = (this.high >>> 24) & 0xFF;
  7965. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7966. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7967. bytes[offset + 3] = this.high & 0xFF;
  7968. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7969. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7970. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7971. bytes[offset + 7] = this.low & 0xFF;
  7972. },
  7973. assign: function Word64_assign(word) {
  7974. this.high = word.high;
  7975. this.low = word.low;
  7976. }
  7977. };
  7978. return Word64;
  7979. })();
  7980. var calculateSHA256 = (function calculateSHA256Closure() {
  7981. function rotr(x, n) {
  7982. return (x >>> n) | (x << 32 - n);
  7983. }
  7984. function ch(x, y, z) {
  7985. return (x & y) ^ (~x & z);
  7986. }
  7987. function maj(x, y, z) {
  7988. return (x & y) ^ (x & z) ^ (y & z);
  7989. }
  7990. function sigma(x) {
  7991. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7992. }
  7993. function sigmaPrime(x) {
  7994. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7995. }
  7996. function littleSigma(x) {
  7997. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7998. }
  7999. function littleSigmaPrime(x) {
  8000. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  8001. }
  8002. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  8003. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  8004. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  8005. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  8006. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  8007. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  8008. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  8009. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  8010. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  8011. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  8012. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  8013. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  8014. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  8015. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  8016. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  8017. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  8018. function hash(data, offset, length) {
  8019. // initial hash values
  8020. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  8021. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  8022. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  8023. // pre-processing
  8024. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  8025. var padded = new Uint8Array(paddedLength);
  8026. var i, j, n;
  8027. for (i = 0; i < length; ++i) {
  8028. padded[i] = data[offset++];
  8029. }
  8030. padded[i++] = 0x80;
  8031. n = paddedLength - 8;
  8032. while (i < n) {
  8033. padded[i++] = 0;
  8034. }
  8035. padded[i++] = 0;
  8036. padded[i++] = 0;
  8037. padded[i++] = 0;
  8038. padded[i++] = (length >>> 29) & 0xFF;
  8039. padded[i++] = (length >> 21) & 0xFF;
  8040. padded[i++] = (length >> 13) & 0xFF;
  8041. padded[i++] = (length >> 5) & 0xFF;
  8042. padded[i++] = (length << 3) & 0xFF;
  8043. var w = new Uint32Array(64);
  8044. // for each 512 bit block
  8045. for (i = 0; i < paddedLength;) {
  8046. for (j = 0; j < 16; ++j) {
  8047. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  8048. (padded[i + 2] << 8) | (padded[i + 3]));
  8049. i += 4;
  8050. }
  8051. for (j = 16; j < 64; ++j) {
  8052. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  8053. littleSigma(w[j - 15]) + w[j - 16] | 0;
  8054. }
  8055. var a = h0, b = h1, c = h2, d = h3, e = h4,
  8056. f = h5, g = h6, h = h7, t1, t2;
  8057. for (j = 0; j < 64; ++j) {
  8058. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  8059. t2 = sigma(a) + maj(a, b, c);
  8060. h = g;
  8061. g = f;
  8062. f = e;
  8063. e = (d + t1) | 0;
  8064. d = c;
  8065. c = b;
  8066. b = a;
  8067. a = (t1 + t2) | 0;
  8068. }
  8069. h0 = (h0 + a) | 0;
  8070. h1 = (h1 + b) | 0;
  8071. h2 = (h2 + c) | 0;
  8072. h3 = (h3 + d) | 0;
  8073. h4 = (h4 + e) | 0;
  8074. h5 = (h5 + f) | 0;
  8075. h6 = (h6 + g) | 0;
  8076. h7 = (h7 + h) | 0;
  8077. }
  8078. return new Uint8Array([
  8079. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  8080. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  8081. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  8082. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  8083. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  8084. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  8085. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  8086. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  8087. ]);
  8088. }
  8089. return hash;
  8090. })();
  8091. var calculateSHA512 = (function calculateSHA512Closure() {
  8092. function ch(result, x, y, z, tmp) {
  8093. result.assign(x);
  8094. result.and(y);
  8095. tmp.assign(x);
  8096. tmp.not();
  8097. tmp.and(z);
  8098. result.xor(tmp);
  8099. }
  8100. function maj(result, x, y, z, tmp) {
  8101. result.assign(x);
  8102. result.and(y);
  8103. tmp.assign(x);
  8104. tmp.and(z);
  8105. result.xor(tmp);
  8106. tmp.assign(y);
  8107. tmp.and(z);
  8108. result.xor(tmp);
  8109. }
  8110. function sigma(result, x, tmp) {
  8111. result.assign(x);
  8112. result.rotateRight(28);
  8113. tmp.assign(x);
  8114. tmp.rotateRight(34);
  8115. result.xor(tmp);
  8116. tmp.assign(x);
  8117. tmp.rotateRight(39);
  8118. result.xor(tmp);
  8119. }
  8120. function sigmaPrime(result, x, tmp) {
  8121. result.assign(x);
  8122. result.rotateRight(14);
  8123. tmp.assign(x);
  8124. tmp.rotateRight(18);
  8125. result.xor(tmp);
  8126. tmp.assign(x);
  8127. tmp.rotateRight(41);
  8128. result.xor(tmp);
  8129. }
  8130. function littleSigma(result, x, tmp) {
  8131. result.assign(x);
  8132. result.rotateRight(1);
  8133. tmp.assign(x);
  8134. tmp.rotateRight(8);
  8135. result.xor(tmp);
  8136. tmp.assign(x);
  8137. tmp.shiftRight(7);
  8138. result.xor(tmp);
  8139. }
  8140. function littleSigmaPrime(result, x, tmp) {
  8141. result.assign(x);
  8142. result.rotateRight(19);
  8143. tmp.assign(x);
  8144. tmp.rotateRight(61);
  8145. result.xor(tmp);
  8146. tmp.assign(x);
  8147. tmp.shiftRight(6);
  8148. result.xor(tmp);
  8149. }
  8150. var k = [
  8151. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  8152. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  8153. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  8154. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  8155. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  8156. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  8157. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  8158. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  8159. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  8160. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  8161. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  8162. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  8163. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  8164. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  8165. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  8166. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  8167. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  8168. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  8169. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  8170. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  8171. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  8172. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  8173. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  8174. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  8175. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  8176. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  8177. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  8178. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  8179. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  8180. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  8181. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  8182. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  8183. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  8184. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  8185. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  8186. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  8187. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  8188. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  8189. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  8190. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  8191. function hash(data, offset, length, mode384) {
  8192. mode384 = !!mode384;
  8193. // initial hash values
  8194. var h0, h1, h2, h3, h4, h5, h6, h7;
  8195. if (!mode384) {
  8196. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  8197. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  8198. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  8199. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  8200. h4 = new Word64(0x510e527f, 0xade682d1);
  8201. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  8202. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  8203. h7 = new Word64(0x5be0cd19, 0x137e2179);
  8204. }
  8205. else {
  8206. // SHA384 is exactly the same
  8207. // except with different starting values and a trimmed result
  8208. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  8209. h1 = new Word64(0x629a292a, 0x367cd507);
  8210. h2 = new Word64(0x9159015a, 0x3070dd17);
  8211. h3 = new Word64(0x152fecd8, 0xf70e5939);
  8212. h4 = new Word64(0x67332667, 0xffc00b31);
  8213. h5 = new Word64(0x8eb44a87, 0x68581511);
  8214. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  8215. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  8216. }
  8217. // pre-processing
  8218. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  8219. var padded = new Uint8Array(paddedLength);
  8220. var i, j, n;
  8221. for (i = 0; i < length; ++i) {
  8222. padded[i] = data[offset++];
  8223. }
  8224. padded[i++] = 0x80;
  8225. n = paddedLength - 16;
  8226. while (i < n) {
  8227. padded[i++] = 0;
  8228. }
  8229. padded[i++] = 0;
  8230. padded[i++] = 0;
  8231. padded[i++] = 0;
  8232. padded[i++] = 0;
  8233. padded[i++] = 0;
  8234. padded[i++] = 0;
  8235. padded[i++] = 0;
  8236. padded[i++] = 0;
  8237. padded[i++] = 0;
  8238. padded[i++] = 0;
  8239. padded[i++] = 0;
  8240. padded[i++] = (length >>> 29) & 0xFF;
  8241. padded[i++] = (length >> 21) & 0xFF;
  8242. padded[i++] = (length >> 13) & 0xFF;
  8243. padded[i++] = (length >> 5) & 0xFF;
  8244. padded[i++] = (length << 3) & 0xFF;
  8245. var w = new Array(80);
  8246. for (i = 0; i < 80; i++) {
  8247. w[i] = new Word64(0, 0);
  8248. }
  8249. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  8250. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  8251. var g = new Word64(0, 0), h = new Word64(0, 0);
  8252. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  8253. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  8254. // for each 1024 bit block
  8255. for (i = 0; i < paddedLength;) {
  8256. for (j = 0; j < 16; ++j) {
  8257. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  8258. (padded[i + 2] << 8) | (padded[i + 3]);
  8259. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  8260. (padded[i + 6]) << 8 | (padded[i + 7]);
  8261. i += 8;
  8262. }
  8263. for (j = 16; j < 80; ++j) {
  8264. tmp3 = w[j];
  8265. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  8266. tmp3.add(w[j - 7]);
  8267. littleSigma(tmp1, w[j - 15], tmp2);
  8268. tmp3.add(tmp1);
  8269. tmp3.add(w[j - 16]);
  8270. }
  8271. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  8272. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  8273. for (j = 0; j < 80; ++j) {
  8274. t1.assign(h);
  8275. sigmaPrime(tmp1, e, tmp2);
  8276. t1.add(tmp1);
  8277. ch(tmp1, e, f, g, tmp2);
  8278. t1.add(tmp1);
  8279. t1.add(k[j]);
  8280. t1.add(w[j]);
  8281. sigma(t2, a, tmp2);
  8282. maj(tmp1, a, b, c, tmp2);
  8283. t2.add(tmp1);
  8284. tmp3 = h;
  8285. h = g;
  8286. g = f;
  8287. f = e;
  8288. d.add(t1);
  8289. e = d;
  8290. d = c;
  8291. c = b;
  8292. b = a;
  8293. tmp3.assign(t1);
  8294. tmp3.add(t2);
  8295. a = tmp3;
  8296. }
  8297. h0.add(a);
  8298. h1.add(b);
  8299. h2.add(c);
  8300. h3.add(d);
  8301. h4.add(e);
  8302. h5.add(f);
  8303. h6.add(g);
  8304. h7.add(h);
  8305. }
  8306. var result;
  8307. if (!mode384) {
  8308. result = new Uint8Array(64);
  8309. h0.copyTo(result,0);
  8310. h1.copyTo(result,8);
  8311. h2.copyTo(result,16);
  8312. h3.copyTo(result,24);
  8313. h4.copyTo(result,32);
  8314. h5.copyTo(result,40);
  8315. h6.copyTo(result,48);
  8316. h7.copyTo(result,56);
  8317. }
  8318. else {
  8319. result = new Uint8Array(48);
  8320. h0.copyTo(result,0);
  8321. h1.copyTo(result,8);
  8322. h2.copyTo(result,16);
  8323. h3.copyTo(result,24);
  8324. h4.copyTo(result,32);
  8325. h5.copyTo(result,40);
  8326. }
  8327. return result;
  8328. }
  8329. return hash;
  8330. })();
  8331. var calculateSHA384 = (function calculateSHA384Closure() {
  8332. function hash(data, offset, length) {
  8333. return calculateSHA512(data, offset, length, true);
  8334. }
  8335. return hash;
  8336. })();
  8337. var NullCipher = (function NullCipherClosure() {
  8338. function NullCipher() {
  8339. }
  8340. NullCipher.prototype = {
  8341. decryptBlock: function NullCipher_decryptBlock(data) {
  8342. return data;
  8343. }
  8344. };
  8345. return NullCipher;
  8346. })();
  8347. var AES128Cipher = (function AES128CipherClosure() {
  8348. var rcon = new Uint8Array([
  8349. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8350. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8351. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8352. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8353. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8354. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8355. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8356. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8357. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8358. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8359. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8360. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8361. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8362. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8363. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8364. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8365. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8366. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8367. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8368. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8369. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8370. 0x74, 0xe8, 0xcb, 0x8d]);
  8371. var s = new Uint8Array([
  8372. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8373. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8374. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8375. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8376. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8377. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8378. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8379. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8380. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8381. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8382. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8383. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8384. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8385. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8386. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8387. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8388. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8389. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8390. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8391. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8392. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8393. 0xb0, 0x54, 0xbb, 0x16]);
  8394. var inv_s = new Uint8Array([
  8395. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8396. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8397. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8398. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8399. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8400. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8401. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8402. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8403. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8404. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8405. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8406. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8407. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8408. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8409. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8410. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8411. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8412. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8413. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8414. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8415. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8416. 0x55, 0x21, 0x0c, 0x7d]);
  8417. var mixCol = new Uint8Array(256);
  8418. for (var i = 0; i < 256; i++) {
  8419. if (i < 128) {
  8420. mixCol[i] = i << 1;
  8421. } else {
  8422. mixCol[i] = (i << 1) ^ 0x1b;
  8423. }
  8424. }
  8425. var mix = new Uint32Array([
  8426. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8427. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8428. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8429. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8430. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8431. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8432. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8433. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8434. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8435. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8436. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8437. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8438. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8439. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8440. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8441. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8442. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8443. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8444. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8445. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8446. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8447. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8448. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8449. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8450. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8451. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8452. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8453. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8454. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8455. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8456. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8457. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8458. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8459. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8460. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8461. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8462. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8463. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8464. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8465. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8466. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8467. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8468. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8469. function expandKey128(cipherKey) {
  8470. var b = 176, result = new Uint8Array(b);
  8471. result.set(cipherKey);
  8472. for (var j = 16, i = 1; j < b; ++i) {
  8473. // RotWord
  8474. var t1 = result[j - 3], t2 = result[j - 2],
  8475. t3 = result[j - 1], t4 = result[j - 4];
  8476. // SubWord
  8477. t1 = s[t1];
  8478. t2 = s[t2];
  8479. t3 = s[t3];
  8480. t4 = s[t4];
  8481. // Rcon
  8482. t1 = t1 ^ rcon[i];
  8483. for (var n = 0; n < 4; ++n) {
  8484. result[j] = (t1 ^= result[j - 16]);
  8485. j++;
  8486. result[j] = (t2 ^= result[j - 16]);
  8487. j++;
  8488. result[j] = (t3 ^= result[j - 16]);
  8489. j++;
  8490. result[j] = (t4 ^= result[j - 16]);
  8491. j++;
  8492. }
  8493. }
  8494. return result;
  8495. }
  8496. function decrypt128(input, key) {
  8497. var state = new Uint8Array(16);
  8498. state.set(input);
  8499. var i, j, k;
  8500. var t, u, v;
  8501. // AddRoundKey
  8502. for (j = 0, k = 160; j < 16; ++j, ++k) {
  8503. state[j] ^= key[k];
  8504. }
  8505. for (i = 9; i >= 1; --i) {
  8506. // InvShiftRows
  8507. t = state[13];
  8508. state[13] = state[9];
  8509. state[9] = state[5];
  8510. state[5] = state[1];
  8511. state[1] = t;
  8512. t = state[14];
  8513. u = state[10];
  8514. state[14] = state[6];
  8515. state[10] = state[2];
  8516. state[6] = t;
  8517. state[2] = u;
  8518. t = state[15];
  8519. u = state[11];
  8520. v = state[7];
  8521. state[15] = state[3];
  8522. state[11] = t;
  8523. state[7] = u;
  8524. state[3] = v;
  8525. // InvSubBytes
  8526. for (j = 0; j < 16; ++j) {
  8527. state[j] = inv_s[state[j]];
  8528. }
  8529. // AddRoundKey
  8530. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8531. state[j] ^= key[k];
  8532. }
  8533. // InvMixColumns
  8534. for (j = 0; j < 16; j += 4) {
  8535. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8536. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8537. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8538. (s3 >>> 24) ^ (s3 << 8));
  8539. state[j] = (t >>> 24) & 0xFF;
  8540. state[j + 1] = (t >> 16) & 0xFF;
  8541. state[j + 2] = (t >> 8) & 0xFF;
  8542. state[j + 3] = t & 0xFF;
  8543. }
  8544. }
  8545. // InvShiftRows
  8546. t = state[13];
  8547. state[13] = state[9];
  8548. state[9] = state[5];
  8549. state[5] = state[1];
  8550. state[1] = t;
  8551. t = state[14];
  8552. u = state[10];
  8553. state[14] = state[6];
  8554. state[10] = state[2];
  8555. state[6] = t;
  8556. state[2] = u;
  8557. t = state[15];
  8558. u = state[11];
  8559. v = state[7];
  8560. state[15] = state[3];
  8561. state[11] = t;
  8562. state[7] = u;
  8563. state[3] = v;
  8564. for (j = 0; j < 16; ++j) {
  8565. // InvSubBytes
  8566. state[j] = inv_s[state[j]];
  8567. // AddRoundKey
  8568. state[j] ^= key[j];
  8569. }
  8570. return state;
  8571. }
  8572. function encrypt128(input, key) {
  8573. var t, u, v, k;
  8574. var state = new Uint8Array(16);
  8575. state.set(input);
  8576. for (j = 0; j < 16; ++j) {
  8577. // AddRoundKey
  8578. state[j] ^= key[j];
  8579. }
  8580. for (i = 1; i < 10; i++) {
  8581. //SubBytes
  8582. for (j = 0; j < 16; ++j) {
  8583. state[j] = s[state[j]];
  8584. }
  8585. //ShiftRows
  8586. v = state[1];
  8587. state[1] = state[5];
  8588. state[5] = state[9];
  8589. state[9] = state[13];
  8590. state[13] = v;
  8591. v = state[2];
  8592. u = state[6];
  8593. state[2] = state[10];
  8594. state[6] = state[14];
  8595. state[10] = v;
  8596. state[14] = u;
  8597. v = state[3];
  8598. u = state[7];
  8599. t = state[11];
  8600. state[3] = state[15];
  8601. state[7] = v;
  8602. state[11] = u;
  8603. state[15] = t;
  8604. //MixColumns
  8605. for (var j = 0; j < 16; j += 4) {
  8606. var s0 = state[j + 0], s1 = state[j + 1];
  8607. var s2 = state[j + 2], s3 = state[j + 3];
  8608. t = s0 ^ s1 ^ s2 ^ s3;
  8609. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8610. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8611. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8612. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8613. }
  8614. //AddRoundKey
  8615. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8616. state[j] ^= key[k];
  8617. }
  8618. }
  8619. //SubBytes
  8620. for (j = 0; j < 16; ++j) {
  8621. state[j] = s[state[j]];
  8622. }
  8623. //ShiftRows
  8624. v = state[1];
  8625. state[1] = state[5];
  8626. state[5] = state[9];
  8627. state[9] = state[13];
  8628. state[13] = v;
  8629. v = state[2];
  8630. u = state[6];
  8631. state[2] = state[10];
  8632. state[6] = state[14];
  8633. state[10] = v;
  8634. state[14] = u;
  8635. v = state[3];
  8636. u = state[7];
  8637. t = state[11];
  8638. state[3] = state[15];
  8639. state[7] = v;
  8640. state[11] = u;
  8641. state[15] = t;
  8642. //AddRoundKey
  8643. for (j = 0, k = 160; j < 16; ++j, ++k) {
  8644. state[j] ^= key[k];
  8645. }
  8646. return state;
  8647. }
  8648. function AES128Cipher(key) {
  8649. this.key = expandKey128(key);
  8650. this.buffer = new Uint8Array(16);
  8651. this.bufferPosition = 0;
  8652. }
  8653. function decryptBlock2(data, finalize) {
  8654. var i, j, ii, sourceLength = data.length,
  8655. buffer = this.buffer, bufferLength = this.bufferPosition,
  8656. result = [], iv = this.iv;
  8657. for (i = 0; i < sourceLength; ++i) {
  8658. buffer[bufferLength] = data[i];
  8659. ++bufferLength;
  8660. if (bufferLength < 16) {
  8661. continue;
  8662. }
  8663. // buffer is full, decrypting
  8664. var plain = decrypt128(buffer, this.key);
  8665. // xor-ing the IV vector to get plain text
  8666. for (j = 0; j < 16; ++j) {
  8667. plain[j] ^= iv[j];
  8668. }
  8669. iv = buffer;
  8670. result.push(plain);
  8671. buffer = new Uint8Array(16);
  8672. bufferLength = 0;
  8673. }
  8674. // saving incomplete buffer
  8675. this.buffer = buffer;
  8676. this.bufferLength = bufferLength;
  8677. this.iv = iv;
  8678. if (result.length === 0) {
  8679. return new Uint8Array([]);
  8680. }
  8681. // combining plain text blocks into one
  8682. var outputLength = 16 * result.length;
  8683. if (finalize) {
  8684. // undo a padding that is described in RFC 2898
  8685. var lastBlock = result[result.length - 1];
  8686. var psLen = lastBlock[15];
  8687. if (psLen <= 16) {
  8688. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8689. if (lastBlock[i] !== psLen) {
  8690. // Invalid padding, assume that the block has no padding.
  8691. psLen = 0;
  8692. break;
  8693. }
  8694. }
  8695. outputLength -= psLen;
  8696. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8697. }
  8698. }
  8699. var output = new Uint8Array(outputLength);
  8700. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8701. output.set(result[i], j);
  8702. }
  8703. return output;
  8704. }
  8705. AES128Cipher.prototype = {
  8706. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  8707. var i, sourceLength = data.length;
  8708. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8709. // waiting for IV values -- they are at the start of the stream
  8710. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  8711. buffer[bufferLength] = data[i];
  8712. }
  8713. if (bufferLength < 16) {
  8714. // need more data
  8715. this.bufferLength = bufferLength;
  8716. return new Uint8Array([]);
  8717. }
  8718. this.iv = buffer;
  8719. this.buffer = new Uint8Array(16);
  8720. this.bufferLength = 0;
  8721. // starting decryption
  8722. this.decryptBlock = decryptBlock2;
  8723. return this.decryptBlock(data.subarray(16), finalize);
  8724. },
  8725. encrypt: function AES128Cipher_encrypt(data, iv) {
  8726. var i, j, ii, sourceLength = data.length,
  8727. buffer = this.buffer, bufferLength = this.bufferPosition,
  8728. result = [];
  8729. if (!iv) {
  8730. iv = new Uint8Array(16);
  8731. }
  8732. for (i = 0; i < sourceLength; ++i) {
  8733. buffer[bufferLength] = data[i];
  8734. ++bufferLength;
  8735. if (bufferLength < 16) {
  8736. continue;
  8737. }
  8738. for (j = 0; j < 16; ++j) {
  8739. buffer[j] ^= iv[j];
  8740. }
  8741. // buffer is full, encrypting
  8742. var cipher = encrypt128(buffer, this.key);
  8743. iv = cipher;
  8744. result.push(cipher);
  8745. buffer = new Uint8Array(16);
  8746. bufferLength = 0;
  8747. }
  8748. // saving incomplete buffer
  8749. this.buffer = buffer;
  8750. this.bufferLength = bufferLength;
  8751. this.iv = iv;
  8752. if (result.length === 0) {
  8753. return new Uint8Array([]);
  8754. }
  8755. // combining plain text blocks into one
  8756. var outputLength = 16 * result.length;
  8757. var output = new Uint8Array(outputLength);
  8758. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8759. output.set(result[i], j);
  8760. }
  8761. return output;
  8762. }
  8763. };
  8764. return AES128Cipher;
  8765. })();
  8766. var AES256Cipher = (function AES256CipherClosure() {
  8767. var rcon = new Uint8Array([
  8768. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8769. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8770. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8771. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8772. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8773. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8774. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8775. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8776. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8777. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8778. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8779. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8780. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8781. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8782. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8783. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8784. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8785. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8786. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8787. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8788. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8789. 0x74, 0xe8, 0xcb, 0x8d]);
  8790. var s = new Uint8Array([
  8791. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8792. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8793. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8794. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8795. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8796. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8797. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8798. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8799. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8800. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8801. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8802. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8803. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8804. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8805. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8806. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8807. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8808. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8809. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8810. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8811. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8812. 0xb0, 0x54, 0xbb, 0x16]);
  8813. var inv_s = new Uint8Array([
  8814. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8815. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8816. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8817. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8818. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8819. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8820. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8821. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8822. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8823. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8824. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8825. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8826. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8827. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8828. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8829. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8830. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8831. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8832. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8833. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8834. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8835. 0x55, 0x21, 0x0c, 0x7d]);
  8836. var mixCol = new Uint8Array(256);
  8837. for (var i = 0; i < 256; i++) {
  8838. if (i < 128) {
  8839. mixCol[i] = i << 1;
  8840. } else {
  8841. mixCol[i] = (i << 1) ^ 0x1b;
  8842. }
  8843. }
  8844. var mix = new Uint32Array([
  8845. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8846. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8847. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8848. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8849. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8850. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8851. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8852. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8853. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8854. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8855. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8856. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8857. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8858. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8859. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8860. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8861. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8862. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8863. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8864. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8865. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8866. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8867. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8868. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8869. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8870. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8871. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8872. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8873. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8874. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8875. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8876. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8877. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8878. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8879. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8880. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8881. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8882. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8883. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8884. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8885. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8886. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8887. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8888. function expandKey256(cipherKey) {
  8889. var b = 240, result = new Uint8Array(b);
  8890. var r = 1;
  8891. result.set(cipherKey);
  8892. for (var j = 32, i = 1; j < b; ++i) {
  8893. if (j % 32 === 16) {
  8894. t1 = s[t1];
  8895. t2 = s[t2];
  8896. t3 = s[t3];
  8897. t4 = s[t4];
  8898. } else if (j % 32 === 0) {
  8899. // RotWord
  8900. var t1 = result[j - 3], t2 = result[j - 2],
  8901. t3 = result[j - 1], t4 = result[j - 4];
  8902. // SubWord
  8903. t1 = s[t1];
  8904. t2 = s[t2];
  8905. t3 = s[t3];
  8906. t4 = s[t4];
  8907. // Rcon
  8908. t1 = t1 ^ r;
  8909. if ((r <<= 1) >= 256) {
  8910. r = (r ^ 0x1b) & 0xFF;
  8911. }
  8912. }
  8913. for (var n = 0; n < 4; ++n) {
  8914. result[j] = (t1 ^= result[j - 32]);
  8915. j++;
  8916. result[j] = (t2 ^= result[j - 32]);
  8917. j++;
  8918. result[j] = (t3 ^= result[j - 32]);
  8919. j++;
  8920. result[j] = (t4 ^= result[j - 32]);
  8921. j++;
  8922. }
  8923. }
  8924. return result;
  8925. }
  8926. function decrypt256(input, key) {
  8927. var state = new Uint8Array(16);
  8928. state.set(input);
  8929. var i, j, k;
  8930. var t, u, v;
  8931. // AddRoundKey
  8932. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8933. state[j] ^= key[k];
  8934. }
  8935. for (i = 13; i >= 1; --i) {
  8936. // InvShiftRows
  8937. t = state[13];
  8938. state[13] = state[9];
  8939. state[9] = state[5];
  8940. state[5] = state[1];
  8941. state[1] = t;
  8942. t = state[14];
  8943. u = state[10];
  8944. state[14] = state[6];
  8945. state[10] = state[2];
  8946. state[6] = t;
  8947. state[2] = u;
  8948. t = state[15];
  8949. u = state[11];
  8950. v = state[7];
  8951. state[15] = state[3];
  8952. state[11] = t;
  8953. state[7] = u;
  8954. state[3] = v;
  8955. // InvSubBytes
  8956. for (j = 0; j < 16; ++j) {
  8957. state[j] = inv_s[state[j]];
  8958. }
  8959. // AddRoundKey
  8960. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8961. state[j] ^= key[k];
  8962. }
  8963. // InvMixColumns
  8964. for (j = 0; j < 16; j += 4) {
  8965. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8966. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8967. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8968. (s3 >>> 24) ^ (s3 << 8));
  8969. state[j] = (t >>> 24) & 0xFF;
  8970. state[j + 1] = (t >> 16) & 0xFF;
  8971. state[j + 2] = (t >> 8) & 0xFF;
  8972. state[j + 3] = t & 0xFF;
  8973. }
  8974. }
  8975. // InvShiftRows
  8976. t = state[13];
  8977. state[13] = state[9];
  8978. state[9] = state[5];
  8979. state[5] = state[1];
  8980. state[1] = t;
  8981. t = state[14];
  8982. u = state[10];
  8983. state[14] = state[6];
  8984. state[10] = state[2];
  8985. state[6] = t;
  8986. state[2] = u;
  8987. t = state[15];
  8988. u = state[11];
  8989. v = state[7];
  8990. state[15] = state[3];
  8991. state[11] = t;
  8992. state[7] = u;
  8993. state[3] = v;
  8994. for (j = 0; j < 16; ++j) {
  8995. // InvSubBytes
  8996. state[j] = inv_s[state[j]];
  8997. // AddRoundKey
  8998. state[j] ^= key[j];
  8999. }
  9000. return state;
  9001. }
  9002. function encrypt256(input, key) {
  9003. var t, u, v, k;
  9004. var state = new Uint8Array(16);
  9005. state.set(input);
  9006. for (j = 0; j < 16; ++j) {
  9007. // AddRoundKey
  9008. state[j] ^= key[j];
  9009. }
  9010. for (i = 1; i < 14; i++) {
  9011. //SubBytes
  9012. for (j = 0; j < 16; ++j) {
  9013. state[j] = s[state[j]];
  9014. }
  9015. //ShiftRows
  9016. v = state[1];
  9017. state[1] = state[5];
  9018. state[5] = state[9];
  9019. state[9] = state[13];
  9020. state[13] = v;
  9021. v = state[2];
  9022. u = state[6];
  9023. state[2] = state[10];
  9024. state[6] = state[14];
  9025. state[10] = v;
  9026. state[14] = u;
  9027. v = state[3];
  9028. u = state[7];
  9029. t = state[11];
  9030. state[3] = state[15];
  9031. state[7] = v;
  9032. state[11] = u;
  9033. state[15] = t;
  9034. //MixColumns
  9035. for (var j = 0; j < 16; j += 4) {
  9036. var s0 = state[j + 0], s1 = state[j + 1];
  9037. var s2 = state[j + 2], s3 = state[j + 3];
  9038. t = s0 ^ s1 ^ s2 ^ s3;
  9039. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  9040. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  9041. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  9042. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  9043. }
  9044. //AddRoundKey
  9045. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  9046. state[j] ^= key[k];
  9047. }
  9048. }
  9049. //SubBytes
  9050. for (j = 0; j < 16; ++j) {
  9051. state[j] = s[state[j]];
  9052. }
  9053. //ShiftRows
  9054. v = state[1];
  9055. state[1] = state[5];
  9056. state[5] = state[9];
  9057. state[9] = state[13];
  9058. state[13] = v;
  9059. v = state[2];
  9060. u = state[6];
  9061. state[2] = state[10];
  9062. state[6] = state[14];
  9063. state[10] = v;
  9064. state[14] = u;
  9065. v = state[3];
  9066. u = state[7];
  9067. t = state[11];
  9068. state[3] = state[15];
  9069. state[7] = v;
  9070. state[11] = u;
  9071. state[15] = t;
  9072. //AddRoundKey
  9073. for (j = 0, k = 224; j < 16; ++j, ++k) {
  9074. state[j] ^= key[k];
  9075. }
  9076. return state;
  9077. }
  9078. function AES256Cipher(key) {
  9079. this.key = expandKey256(key);
  9080. this.buffer = new Uint8Array(16);
  9081. this.bufferPosition = 0;
  9082. }
  9083. function decryptBlock2(data, finalize) {
  9084. var i, j, ii, sourceLength = data.length,
  9085. buffer = this.buffer, bufferLength = this.bufferPosition,
  9086. result = [], iv = this.iv;
  9087. for (i = 0; i < sourceLength; ++i) {
  9088. buffer[bufferLength] = data[i];
  9089. ++bufferLength;
  9090. if (bufferLength < 16) {
  9091. continue;
  9092. }
  9093. // buffer is full, decrypting
  9094. var plain = decrypt256(buffer, this.key);
  9095. // xor-ing the IV vector to get plain text
  9096. for (j = 0; j < 16; ++j) {
  9097. plain[j] ^= iv[j];
  9098. }
  9099. iv = buffer;
  9100. result.push(plain);
  9101. buffer = new Uint8Array(16);
  9102. bufferLength = 0;
  9103. }
  9104. // saving incomplete buffer
  9105. this.buffer = buffer;
  9106. this.bufferLength = bufferLength;
  9107. this.iv = iv;
  9108. if (result.length === 0) {
  9109. return new Uint8Array([]);
  9110. }
  9111. // combining plain text blocks into one
  9112. var outputLength = 16 * result.length;
  9113. if (finalize) {
  9114. // undo a padding that is described in RFC 2898
  9115. var lastBlock = result[result.length - 1];
  9116. var psLen = lastBlock[15];
  9117. if (psLen <= 16) {
  9118. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  9119. if (lastBlock[i] !== psLen) {
  9120. // Invalid padding, assume that the block has no padding.
  9121. psLen = 0;
  9122. break;
  9123. }
  9124. }
  9125. outputLength -= psLen;
  9126. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  9127. }
  9128. }
  9129. var output = new Uint8Array(outputLength);
  9130. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  9131. output.set(result[i], j);
  9132. }
  9133. return output;
  9134. }
  9135. AES256Cipher.prototype = {
  9136. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  9137. var i, sourceLength = data.length;
  9138. var buffer = this.buffer, bufferLength = this.bufferPosition;
  9139. // if not supplied an IV wait for IV values
  9140. // they are at the start of the stream
  9141. if (iv) {
  9142. this.iv = iv;
  9143. } else {
  9144. for (i = 0; bufferLength < 16 &&
  9145. i < sourceLength; ++i, ++bufferLength) {
  9146. buffer[bufferLength] = data[i];
  9147. }
  9148. if (bufferLength < 16) {
  9149. //need more data
  9150. this.bufferLength = bufferLength;
  9151. return new Uint8Array([]);
  9152. }
  9153. this.iv = buffer;
  9154. data = data.subarray(16);
  9155. }
  9156. this.buffer = new Uint8Array(16);
  9157. this.bufferLength = 0;
  9158. // starting decryption
  9159. this.decryptBlock = decryptBlock2;
  9160. return this.decryptBlock(data, finalize);
  9161. },
  9162. encrypt: function AES256Cipher_encrypt(data, iv) {
  9163. var i, j, ii, sourceLength = data.length,
  9164. buffer = this.buffer, bufferLength = this.bufferPosition,
  9165. result = [];
  9166. if (!iv) {
  9167. iv = new Uint8Array(16);
  9168. }
  9169. for (i = 0; i < sourceLength; ++i) {
  9170. buffer[bufferLength] = data[i];
  9171. ++bufferLength;
  9172. if (bufferLength < 16) {
  9173. continue;
  9174. }
  9175. for (j = 0; j < 16; ++j) {
  9176. buffer[j] ^= iv[j];
  9177. }
  9178. // buffer is full, encrypting
  9179. var cipher = encrypt256(buffer, this.key);
  9180. this.iv = cipher;
  9181. result.push(cipher);
  9182. buffer = new Uint8Array(16);
  9183. bufferLength = 0;
  9184. }
  9185. // saving incomplete buffer
  9186. this.buffer = buffer;
  9187. this.bufferLength = bufferLength;
  9188. this.iv = iv;
  9189. if (result.length === 0) {
  9190. return new Uint8Array([]);
  9191. }
  9192. // combining plain text blocks into one
  9193. var outputLength = 16 * result.length;
  9194. var output = new Uint8Array(outputLength);
  9195. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  9196. output.set(result[i], j);
  9197. }
  9198. return output;
  9199. }
  9200. };
  9201. return AES256Cipher;
  9202. })();
  9203. var PDF17 = (function PDF17Closure() {
  9204. function compareByteArrays(array1, array2) {
  9205. if (array1.length !== array2.length) {
  9206. return false;
  9207. }
  9208. for (var i = 0; i < array1.length; i++) {
  9209. if (array1[i] !== array2[i]) {
  9210. return false;
  9211. }
  9212. }
  9213. return true;
  9214. }
  9215. function PDF17() {
  9216. }
  9217. PDF17.prototype = {
  9218. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  9219. ownerValidationSalt,
  9220. userBytes,
  9221. ownerPassword) {
  9222. var hashData = new Uint8Array(password.length + 56);
  9223. hashData.set(password, 0);
  9224. hashData.set(ownerValidationSalt, password.length);
  9225. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  9226. var result = calculateSHA256(hashData, 0, hashData.length);
  9227. return compareByteArrays(result, ownerPassword);
  9228. },
  9229. checkUserPassword: function PDF17_checkUserPassword(password,
  9230. userValidationSalt,
  9231. userPassword) {
  9232. var hashData = new Uint8Array(password.length + 8);
  9233. hashData.set(password, 0);
  9234. hashData.set(userValidationSalt, password.length);
  9235. var result = calculateSHA256(hashData, 0, hashData.length);
  9236. return compareByteArrays(result, userPassword);
  9237. },
  9238. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  9239. ownerEncryption) {
  9240. var hashData = new Uint8Array(password.length + 56);
  9241. hashData.set(password, 0);
  9242. hashData.set(ownerKeySalt, password.length);
  9243. hashData.set(userBytes, password.length + ownerKeySalt.length);
  9244. var key = calculateSHA256(hashData, 0, hashData.length);
  9245. var cipher = new AES256Cipher(key);
  9246. return cipher.decryptBlock(ownerEncryption,
  9247. false,
  9248. new Uint8Array(16));
  9249. },
  9250. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  9251. userEncryption) {
  9252. var hashData = new Uint8Array(password.length + 8);
  9253. hashData.set(password, 0);
  9254. hashData.set(userKeySalt, password.length);
  9255. //key is the decryption key for the UE string
  9256. var key = calculateSHA256(hashData, 0, hashData.length);
  9257. var cipher = new AES256Cipher(key);
  9258. return cipher.decryptBlock(userEncryption,
  9259. false,
  9260. new Uint8Array(16));
  9261. }
  9262. };
  9263. return PDF17;
  9264. })();
  9265. var PDF20 = (function PDF20Closure() {
  9266. function concatArrays(array1, array2) {
  9267. var t = new Uint8Array(array1.length + array2.length);
  9268. t.set(array1, 0);
  9269. t.set(array2, array1.length);
  9270. return t;
  9271. }
  9272. function calculatePDF20Hash(password, input, userBytes) {
  9273. //This refers to Algorithm 2.B as defined in ISO 32000-2
  9274. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  9275. var e = [0];
  9276. var i = 0;
  9277. while (i < 64 || e[e.length - 1] > i - 32) {
  9278. var arrayLength = password.length + k.length + userBytes.length;
  9279. var k1 = new Uint8Array(arrayLength * 64);
  9280. var array = concatArrays(password, k);
  9281. array = concatArrays(array, userBytes);
  9282. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  9283. k1.set(array, pos);
  9284. }
  9285. //AES128 CBC NO PADDING with
  9286. //first 16 bytes of k as the key and the second 16 as the iv.
  9287. var cipher = new AES128Cipher(k.subarray(0, 16));
  9288. e = cipher.encrypt(k1, k.subarray(16, 32));
  9289. //Now we have to take the first 16 bytes of an unsigned
  9290. //big endian integer... and compute the remainder
  9291. //modulo 3.... That is a fairly large number and
  9292. //JavaScript isn't going to handle that well...
  9293. //So we're using a trick that allows us to perform
  9294. //modulo math byte by byte
  9295. var remainder = 0;
  9296. for (var z = 0; z < 16; z++) {
  9297. remainder *= (256 % 3);
  9298. remainder %= 3;
  9299. remainder += ((e[z] >>> 0) % 3);
  9300. remainder %= 3;
  9301. }
  9302. if (remainder === 0) {
  9303. k = calculateSHA256(e, 0, e.length);
  9304. }
  9305. else if (remainder === 1) {
  9306. k = calculateSHA384(e, 0, e.length);
  9307. }
  9308. else if (remainder === 2) {
  9309. k = calculateSHA512(e, 0, e.length);
  9310. }
  9311. i++;
  9312. }
  9313. return k.subarray(0, 32);
  9314. }
  9315. function PDF20() {
  9316. }
  9317. function compareByteArrays(array1, array2) {
  9318. if (array1.length !== array2.length) {
  9319. return false;
  9320. }
  9321. for (var i = 0; i < array1.length; i++) {
  9322. if (array1[i] !== array2[i]) {
  9323. return false;
  9324. }
  9325. }
  9326. return true;
  9327. }
  9328. PDF20.prototype = {
  9329. hash: function PDF20_hash(password, concatBytes, userBytes) {
  9330. return calculatePDF20Hash(password, concatBytes, userBytes);
  9331. },
  9332. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  9333. ownerValidationSalt,
  9334. userBytes,
  9335. ownerPassword) {
  9336. var hashData = new Uint8Array(password.length + 56);
  9337. hashData.set(password, 0);
  9338. hashData.set(ownerValidationSalt, password.length);
  9339. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  9340. var result = calculatePDF20Hash(password, hashData, userBytes);
  9341. return compareByteArrays(result, ownerPassword);
  9342. },
  9343. checkUserPassword: function PDF20_checkUserPassword(password,
  9344. userValidationSalt,
  9345. userPassword) {
  9346. var hashData = new Uint8Array(password.length + 8);
  9347. hashData.set(password, 0);
  9348. hashData.set(userValidationSalt, password.length);
  9349. var result = calculatePDF20Hash(password, hashData, []);
  9350. return compareByteArrays(result, userPassword);
  9351. },
  9352. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  9353. ownerEncryption) {
  9354. var hashData = new Uint8Array(password.length + 56);
  9355. hashData.set(password, 0);
  9356. hashData.set(ownerKeySalt, password.length);
  9357. hashData.set(userBytes, password.length + ownerKeySalt.length);
  9358. var key = calculatePDF20Hash(password, hashData, userBytes);
  9359. var cipher = new AES256Cipher(key);
  9360. return cipher.decryptBlock(ownerEncryption,
  9361. false,
  9362. new Uint8Array(16));
  9363. },
  9364. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  9365. userEncryption) {
  9366. var hashData = new Uint8Array(password.length + 8);
  9367. hashData.set(password, 0);
  9368. hashData.set(userKeySalt, password.length);
  9369. //key is the decryption key for the UE string
  9370. var key = calculatePDF20Hash(password, hashData, []);
  9371. var cipher = new AES256Cipher(key);
  9372. return cipher.decryptBlock(userEncryption,
  9373. false,
  9374. new Uint8Array(16));
  9375. }
  9376. };
  9377. return PDF20;
  9378. })();
  9379. var CipherTransform = (function CipherTransformClosure() {
  9380. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  9381. this.stringCipherConstructor = stringCipherConstructor;
  9382. this.streamCipherConstructor = streamCipherConstructor;
  9383. }
  9384. CipherTransform.prototype = {
  9385. createStream: function CipherTransform_createStream(stream, length) {
  9386. var cipher = new this.streamCipherConstructor();
  9387. return new DecryptStream(stream, length,
  9388. function cipherTransformDecryptStream(data, finalize) {
  9389. return cipher.decryptBlock(data, finalize);
  9390. }
  9391. );
  9392. },
  9393. decryptString: function CipherTransform_decryptString(s) {
  9394. var cipher = new this.stringCipherConstructor();
  9395. var data = stringToBytes(s);
  9396. data = cipher.decryptBlock(data, true);
  9397. return bytesToString(data);
  9398. }
  9399. };
  9400. return CipherTransform;
  9401. })();
  9402. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  9403. var defaultPasswordBytes = new Uint8Array([
  9404. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  9405. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  9406. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  9407. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  9408. function createEncryptionKey20(revision, password, ownerPassword,
  9409. ownerValidationSalt, ownerKeySalt, uBytes,
  9410. userPassword, userValidationSalt, userKeySalt,
  9411. ownerEncryption, userEncryption, perms) {
  9412. if (password) {
  9413. var passwordLength = Math.min(127, password.length);
  9414. password = password.subarray(0, passwordLength);
  9415. } else {
  9416. password = [];
  9417. }
  9418. var pdfAlgorithm;
  9419. if (revision === 6) {
  9420. pdfAlgorithm = new PDF20();
  9421. } else {
  9422. pdfAlgorithm = new PDF17();
  9423. }
  9424. if (pdfAlgorithm) {
  9425. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  9426. userPassword)) {
  9427. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  9428. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  9429. ownerValidationSalt,
  9430. uBytes,
  9431. ownerPassword)) {
  9432. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  9433. ownerEncryption);
  9434. }
  9435. }
  9436. return null;
  9437. }
  9438. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  9439. flags, revision, keyLength, encryptMetadata) {
  9440. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  9441. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  9442. if (password) {
  9443. n = Math.min(32, password.length);
  9444. for (; i < n; ++i) {
  9445. hashData[i] = password[i];
  9446. }
  9447. }
  9448. j = 0;
  9449. while (i < 32) {
  9450. hashData[i++] = defaultPasswordBytes[j++];
  9451. }
  9452. // as now the padded password in the hashData[0..i]
  9453. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  9454. hashData[i++] = ownerPassword[j];
  9455. }
  9456. hashData[i++] = flags & 0xFF;
  9457. hashData[i++] = (flags >> 8) & 0xFF;
  9458. hashData[i++] = (flags >> 16) & 0xFF;
  9459. hashData[i++] = (flags >>> 24) & 0xFF;
  9460. for (j = 0, n = fileId.length; j < n; ++j) {
  9461. hashData[i++] = fileId[j];
  9462. }
  9463. if (revision >= 4 && !encryptMetadata) {
  9464. hashData[i++] = 0xFF;
  9465. hashData[i++] = 0xFF;
  9466. hashData[i++] = 0xFF;
  9467. hashData[i++] = 0xFF;
  9468. }
  9469. var hash = calculateMD5(hashData, 0, i);
  9470. var keyLengthInBytes = keyLength >> 3;
  9471. if (revision >= 3) {
  9472. for (j = 0; j < 50; ++j) {
  9473. hash = calculateMD5(hash, 0, keyLengthInBytes);
  9474. }
  9475. }
  9476. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  9477. var cipher, checkData;
  9478. if (revision >= 3) {
  9479. for (i = 0; i < 32; ++i) {
  9480. hashData[i] = defaultPasswordBytes[i];
  9481. }
  9482. for (j = 0, n = fileId.length; j < n; ++j) {
  9483. hashData[i++] = fileId[j];
  9484. }
  9485. cipher = new ARCFourCipher(encryptionKey);
  9486. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  9487. n = encryptionKey.length;
  9488. var derivedKey = new Uint8Array(n), k;
  9489. for (j = 1; j <= 19; ++j) {
  9490. for (k = 0; k < n; ++k) {
  9491. derivedKey[k] = encryptionKey[k] ^ j;
  9492. }
  9493. cipher = new ARCFourCipher(derivedKey);
  9494. checkData = cipher.encryptBlock(checkData);
  9495. }
  9496. for (j = 0, n = checkData.length; j < n; ++j) {
  9497. if (userPassword[j] !== checkData[j]) {
  9498. return null;
  9499. }
  9500. }
  9501. } else {
  9502. cipher = new ARCFourCipher(encryptionKey);
  9503. checkData = cipher.encryptBlock(defaultPasswordBytes);
  9504. for (j = 0, n = checkData.length; j < n; ++j) {
  9505. if (userPassword[j] !== checkData[j]) {
  9506. return null;
  9507. }
  9508. }
  9509. }
  9510. return encryptionKey;
  9511. }
  9512. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  9513. var hashData = new Uint8Array(32), i = 0, j, n;
  9514. n = Math.min(32, password.length);
  9515. for (; i < n; ++i) {
  9516. hashData[i] = password[i];
  9517. }
  9518. j = 0;
  9519. while (i < 32) {
  9520. hashData[i++] = defaultPasswordBytes[j++];
  9521. }
  9522. var hash = calculateMD5(hashData, 0, i);
  9523. var keyLengthInBytes = keyLength >> 3;
  9524. if (revision >= 3) {
  9525. for (j = 0; j < 50; ++j) {
  9526. hash = calculateMD5(hash, 0, hash.length);
  9527. }
  9528. }
  9529. var cipher, userPassword;
  9530. if (revision >= 3) {
  9531. userPassword = ownerPassword;
  9532. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  9533. for (j = 19; j >= 0; j--) {
  9534. for (k = 0; k < keyLengthInBytes; ++k) {
  9535. derivedKey[k] = hash[k] ^ j;
  9536. }
  9537. cipher = new ARCFourCipher(derivedKey);
  9538. userPassword = cipher.encryptBlock(userPassword);
  9539. }
  9540. } else {
  9541. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  9542. userPassword = cipher.encryptBlock(ownerPassword);
  9543. }
  9544. return userPassword;
  9545. }
  9546. var identityName = Name.get('Identity');
  9547. function CipherTransformFactory(dict, fileId, password) {
  9548. var filter = dict.get('Filter');
  9549. if (!isName(filter) || filter.name !== 'Standard') {
  9550. error('unknown encryption method');
  9551. }
  9552. this.dict = dict;
  9553. var algorithm = dict.get('V');
  9554. if (!isInt(algorithm) ||
  9555. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  9556. algorithm !== 5)) {
  9557. error('unsupported encryption algorithm');
  9558. }
  9559. this.algorithm = algorithm;
  9560. var keyLength = dict.get('Length') || 40;
  9561. if (!isInt(keyLength) ||
  9562. keyLength < 40 || (keyLength % 8) !== 0) {
  9563. error('invalid key length');
  9564. }
  9565. // prepare keys
  9566. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  9567. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  9568. var flags = dict.get('P');
  9569. var revision = dict.get('R');
  9570. // meaningful when V is 4 or 5
  9571. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  9572. dict.get('EncryptMetadata') !== false);
  9573. this.encryptMetadata = encryptMetadata;
  9574. var fileIdBytes = stringToBytes(fileId);
  9575. var passwordBytes;
  9576. if (password) {
  9577. if (revision === 6) {
  9578. try {
  9579. password = utf8StringToString(password);
  9580. } catch (ex) {
  9581. warn('CipherTransformFactory: ' +
  9582. 'Unable to convert UTF8 encoded password.');
  9583. }
  9584. }
  9585. passwordBytes = stringToBytes(password);
  9586. }
  9587. var encryptionKey;
  9588. if (algorithm !== 5) {
  9589. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  9590. ownerPassword, userPassword, flags,
  9591. revision, keyLength, encryptMetadata);
  9592. }
  9593. else {
  9594. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  9595. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  9596. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  9597. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  9598. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  9599. var ownerEncryption = stringToBytes(dict.get('OE'));
  9600. var userEncryption = stringToBytes(dict.get('UE'));
  9601. var perms = stringToBytes(dict.get('Perms'));
  9602. encryptionKey =
  9603. createEncryptionKey20(revision, passwordBytes,
  9604. ownerPassword, ownerValidationSalt,
  9605. ownerKeySalt, uBytes,
  9606. userPassword, userValidationSalt,
  9607. userKeySalt, ownerEncryption,
  9608. userEncryption, perms);
  9609. }
  9610. if (!encryptionKey && !password) {
  9611. throw new PasswordException('No password given',
  9612. PasswordResponses.NEED_PASSWORD);
  9613. } else if (!encryptionKey && password) {
  9614. // Attempting use the password as an owner password
  9615. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  9616. revision, keyLength);
  9617. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  9618. ownerPassword, userPassword, flags,
  9619. revision, keyLength, encryptMetadata);
  9620. }
  9621. if (!encryptionKey) {
  9622. throw new PasswordException('Incorrect Password',
  9623. PasswordResponses.INCORRECT_PASSWORD);
  9624. }
  9625. this.encryptionKey = encryptionKey;
  9626. if (algorithm >= 4) {
  9627. this.cf = dict.get('CF');
  9628. this.stmf = dict.get('StmF') || identityName;
  9629. this.strf = dict.get('StrF') || identityName;
  9630. this.eff = dict.get('EFF') || this.stmf;
  9631. }
  9632. }
  9633. function buildObjectKey(num, gen, encryptionKey, isAes) {
  9634. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  9635. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  9636. key[i] = encryptionKey[i];
  9637. }
  9638. key[i++] = num & 0xFF;
  9639. key[i++] = (num >> 8) & 0xFF;
  9640. key[i++] = (num >> 16) & 0xFF;
  9641. key[i++] = gen & 0xFF;
  9642. key[i++] = (gen >> 8) & 0xFF;
  9643. if (isAes) {
  9644. key[i++] = 0x73;
  9645. key[i++] = 0x41;
  9646. key[i++] = 0x6C;
  9647. key[i++] = 0x54;
  9648. }
  9649. var hash = calculateMD5(key, 0, i);
  9650. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  9651. }
  9652. function buildCipherConstructor(cf, name, num, gen, key) {
  9653. var cryptFilter = cf.get(name.name);
  9654. var cfm;
  9655. if (cryptFilter !== null && cryptFilter !== undefined) {
  9656. cfm = cryptFilter.get('CFM');
  9657. }
  9658. if (!cfm || cfm.name === 'None') {
  9659. return function cipherTransformFactoryBuildCipherConstructorNone() {
  9660. return new NullCipher();
  9661. };
  9662. }
  9663. if ('V2' === cfm.name) {
  9664. return function cipherTransformFactoryBuildCipherConstructorV2() {
  9665. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  9666. };
  9667. }
  9668. if ('AESV2' === cfm.name) {
  9669. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  9670. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  9671. };
  9672. }
  9673. if ('AESV3' === cfm.name) {
  9674. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  9675. return new AES256Cipher(key);
  9676. };
  9677. }
  9678. error('Unknown crypto method');
  9679. }
  9680. CipherTransformFactory.prototype = {
  9681. createCipherTransform:
  9682. function CipherTransformFactory_createCipherTransform(num, gen) {
  9683. if (this.algorithm === 4 || this.algorithm === 5) {
  9684. return new CipherTransform(
  9685. buildCipherConstructor(this.cf, this.stmf,
  9686. num, gen, this.encryptionKey),
  9687. buildCipherConstructor(this.cf, this.strf,
  9688. num, gen, this.encryptionKey));
  9689. }
  9690. // algorithms 1 and 2
  9691. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  9692. var cipherConstructor = function buildCipherCipherConstructor() {
  9693. return new ARCFourCipher(key);
  9694. };
  9695. return new CipherTransform(cipherConstructor, cipherConstructor);
  9696. }
  9697. };
  9698. return CipherTransformFactory;
  9699. })();
  9700. var ShadingType = {
  9701. FUNCTION_BASED: 1,
  9702. AXIAL: 2,
  9703. RADIAL: 3,
  9704. FREE_FORM_MESH: 4,
  9705. LATTICE_FORM_MESH: 5,
  9706. COONS_PATCH_MESH: 6,
  9707. TENSOR_PATCH_MESH: 7
  9708. };
  9709. var Pattern = (function PatternClosure() {
  9710. // Constructor should define this.getPattern
  9711. function Pattern() {
  9712. error('should not call Pattern constructor');
  9713. }
  9714. Pattern.prototype = {
  9715. // Input: current Canvas context
  9716. // Output: the appropriate fillStyle or strokeStyle
  9717. getPattern: function Pattern_getPattern(ctx) {
  9718. error('Should not call Pattern.getStyle: ' + ctx);
  9719. }
  9720. };
  9721. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  9722. res, handler) {
  9723. var dict = isStream(shading) ? shading.dict : shading;
  9724. var type = dict.get('ShadingType');
  9725. try {
  9726. switch (type) {
  9727. case ShadingType.AXIAL:
  9728. case ShadingType.RADIAL:
  9729. // Both radial and axial shadings are handled by RadialAxial shading.
  9730. return new Shadings.RadialAxial(dict, matrix, xref, res);
  9731. case ShadingType.FREE_FORM_MESH:
  9732. case ShadingType.LATTICE_FORM_MESH:
  9733. case ShadingType.COONS_PATCH_MESH:
  9734. case ShadingType.TENSOR_PATCH_MESH:
  9735. return new Shadings.Mesh(shading, matrix, xref, res);
  9736. default:
  9737. throw new Error('Unsupported ShadingType: ' + type);
  9738. }
  9739. } catch (ex) {
  9740. if (ex instanceof MissingDataException) {
  9741. throw ex;
  9742. }
  9743. handler.send('UnsupportedFeature',
  9744. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  9745. warn(ex);
  9746. return new Shadings.Dummy();
  9747. }
  9748. };
  9749. return Pattern;
  9750. })();
  9751. var Shadings = {};
  9752. // A small number to offset the first/last color stops so we can insert ones to
  9753. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  9754. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  9755. // internally so we have to go bigger.
  9756. Shadings.SMALL_NUMBER = 1e-2;
  9757. // Radial and axial shading have very similar implementations
  9758. // If needed, the implementations can be broken into two classes
  9759. Shadings.RadialAxial = (function RadialAxialClosure() {
  9760. function RadialAxial(dict, matrix, xref, res) {
  9761. this.matrix = matrix;
  9762. this.coordsArr = dict.get('Coords');
  9763. this.shadingType = dict.get('ShadingType');
  9764. this.type = 'Pattern';
  9765. var cs = dict.get('ColorSpace', 'CS');
  9766. cs = ColorSpace.parse(cs, xref, res);
  9767. this.cs = cs;
  9768. var t0 = 0.0, t1 = 1.0;
  9769. if (dict.has('Domain')) {
  9770. var domainArr = dict.get('Domain');
  9771. t0 = domainArr[0];
  9772. t1 = domainArr[1];
  9773. }
  9774. var extendStart = false, extendEnd = false;
  9775. if (dict.has('Extend')) {
  9776. var extendArr = dict.get('Extend');
  9777. extendStart = extendArr[0];
  9778. extendEnd = extendArr[1];
  9779. }
  9780. if (this.shadingType === ShadingType.RADIAL &&
  9781. (!extendStart || !extendEnd)) {
  9782. // Radial gradient only currently works if either circle is fully within
  9783. // the other circle.
  9784. var x1 = this.coordsArr[0];
  9785. var y1 = this.coordsArr[1];
  9786. var r1 = this.coordsArr[2];
  9787. var x2 = this.coordsArr[3];
  9788. var y2 = this.coordsArr[4];
  9789. var r2 = this.coordsArr[5];
  9790. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  9791. if (r1 <= r2 + distance &&
  9792. r2 <= r1 + distance) {
  9793. warn('Unsupported radial gradient.');
  9794. }
  9795. }
  9796. this.extendStart = extendStart;
  9797. this.extendEnd = extendEnd;
  9798. var fnObj = dict.get('Function');
  9799. var fn = PDFFunction.parseArray(xref, fnObj);
  9800. // 10 samples seems good enough for now, but probably won't work
  9801. // if there are sharp color changes. Ideally, we would implement
  9802. // the spec faithfully and add lossless optimizations.
  9803. var diff = t1 - t0;
  9804. var step = diff / 10;
  9805. var colorStops = this.colorStops = [];
  9806. // Protect against bad domains so we don't end up in an infinte loop below.
  9807. if (t0 >= t1 || step <= 0) {
  9808. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9809. // now.
  9810. info('Bad shading domain.');
  9811. return;
  9812. }
  9813. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9814. var rgbColor;
  9815. for (var i = t0; i <= t1; i += step) {
  9816. ratio[0] = i;
  9817. fn(ratio, 0, color, 0);
  9818. rgbColor = cs.getRgb(color, 0);
  9819. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9820. colorStops.push([(i - t0) / diff, cssColor]);
  9821. }
  9822. var background = 'transparent';
  9823. if (dict.has('Background')) {
  9824. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9825. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9826. }
  9827. if (!extendStart) {
  9828. // Insert a color stop at the front and offset the first real color stop
  9829. // so it doesn't conflict with the one we insert.
  9830. colorStops.unshift([0, background]);
  9831. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9832. }
  9833. if (!extendEnd) {
  9834. // Same idea as above in extendStart but for the end.
  9835. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9836. colorStops.push([1, background]);
  9837. }
  9838. this.colorStops = colorStops;
  9839. }
  9840. RadialAxial.prototype = {
  9841. getIR: function RadialAxial_getIR() {
  9842. var coordsArr = this.coordsArr;
  9843. var shadingType = this.shadingType;
  9844. var type, p0, p1, r0, r1;
  9845. if (shadingType === ShadingType.AXIAL) {
  9846. p0 = [coordsArr[0], coordsArr[1]];
  9847. p1 = [coordsArr[2], coordsArr[3]];
  9848. r0 = null;
  9849. r1 = null;
  9850. type = 'axial';
  9851. } else if (shadingType === ShadingType.RADIAL) {
  9852. p0 = [coordsArr[0], coordsArr[1]];
  9853. p1 = [coordsArr[3], coordsArr[4]];
  9854. r0 = coordsArr[2];
  9855. r1 = coordsArr[5];
  9856. type = 'radial';
  9857. } else {
  9858. error('getPattern type unknown: ' + shadingType);
  9859. }
  9860. var matrix = this.matrix;
  9861. if (matrix) {
  9862. p0 = Util.applyTransform(p0, matrix);
  9863. p1 = Util.applyTransform(p1, matrix);
  9864. if (shadingType === ShadingType.RADIAL) {
  9865. var scale = Util.singularValueDecompose2dScale(matrix);
  9866. r0 *= scale[0];
  9867. r1 *= scale[1];
  9868. }
  9869. }
  9870. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9871. }
  9872. };
  9873. return RadialAxial;
  9874. })();
  9875. // All mesh shading. For now, they will be presented as set of the triangles
  9876. // to be drawn on the canvas and rgb color for each vertex.
  9877. Shadings.Mesh = (function MeshClosure() {
  9878. function MeshStreamReader(stream, context) {
  9879. this.stream = stream;
  9880. this.context = context;
  9881. this.buffer = 0;
  9882. this.bufferLength = 0;
  9883. var numComps = context.numComps;
  9884. this.tmpCompsBuf = new Float32Array(numComps);
  9885. var csNumComps = context.colorSpace.numComps;
  9886. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9887. this.tmpCompsBuf;
  9888. }
  9889. MeshStreamReader.prototype = {
  9890. get hasData() {
  9891. if (this.stream.end) {
  9892. return this.stream.pos < this.stream.end;
  9893. }
  9894. if (this.bufferLength > 0) {
  9895. return true;
  9896. }
  9897. var nextByte = this.stream.getByte();
  9898. if (nextByte < 0) {
  9899. return false;
  9900. }
  9901. this.buffer = nextByte;
  9902. this.bufferLength = 8;
  9903. return true;
  9904. },
  9905. readBits: function MeshStreamReader_readBits(n) {
  9906. var buffer = this.buffer;
  9907. var bufferLength = this.bufferLength;
  9908. if (n === 32) {
  9909. if (bufferLength === 0) {
  9910. return ((this.stream.getByte() << 24) |
  9911. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9912. this.stream.getByte()) >>> 0;
  9913. }
  9914. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9915. (this.stream.getByte() << 8) | this.stream.getByte();
  9916. var nextByte = this.stream.getByte();
  9917. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9918. return ((buffer << (8 - bufferLength)) |
  9919. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9920. }
  9921. if (n === 8 && bufferLength === 0) {
  9922. return this.stream.getByte();
  9923. }
  9924. while (bufferLength < n) {
  9925. buffer = (buffer << 8) | this.stream.getByte();
  9926. bufferLength += 8;
  9927. }
  9928. bufferLength -= n;
  9929. this.bufferLength = bufferLength;
  9930. this.buffer = buffer & ((1 << bufferLength) - 1);
  9931. return buffer >> bufferLength;
  9932. },
  9933. align: function MeshStreamReader_align() {
  9934. this.buffer = 0;
  9935. this.bufferLength = 0;
  9936. },
  9937. readFlag: function MeshStreamReader_readFlag() {
  9938. return this.readBits(this.context.bitsPerFlag);
  9939. },
  9940. readCoordinate: function MeshStreamReader_readCoordinate() {
  9941. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9942. var xi = this.readBits(bitsPerCoordinate);
  9943. var yi = this.readBits(bitsPerCoordinate);
  9944. var decode = this.context.decode;
  9945. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9946. 2.3283064365386963e-10; // 2 ^ -32
  9947. return [
  9948. xi * scale * (decode[1] - decode[0]) + decode[0],
  9949. yi * scale * (decode[3] - decode[2]) + decode[2]
  9950. ];
  9951. },
  9952. readComponents: function MeshStreamReader_readComponents() {
  9953. var numComps = this.context.numComps;
  9954. var bitsPerComponent = this.context.bitsPerComponent;
  9955. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9956. 2.3283064365386963e-10; // 2 ^ -32
  9957. var decode = this.context.decode;
  9958. var components = this.tmpCompsBuf;
  9959. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9960. var ci = this.readBits(bitsPerComponent);
  9961. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9962. }
  9963. var color = this.tmpCsCompsBuf;
  9964. if (this.context.colorFn) {
  9965. this.context.colorFn(components, 0, color, 0);
  9966. }
  9967. return this.context.colorSpace.getRgb(color, 0);
  9968. }
  9969. };
  9970. function decodeType4Shading(mesh, reader) {
  9971. var coords = mesh.coords;
  9972. var colors = mesh.colors;
  9973. var operators = [];
  9974. var ps = []; // not maintaining cs since that will match ps
  9975. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9976. while (reader.hasData) {
  9977. var f = reader.readFlag();
  9978. var coord = reader.readCoordinate();
  9979. var color = reader.readComponents();
  9980. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9981. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9982. switch (f) {
  9983. case 0:
  9984. verticesLeft = 3;
  9985. break;
  9986. case 1:
  9987. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9988. verticesLeft = 1;
  9989. break;
  9990. case 2:
  9991. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9992. verticesLeft = 1;
  9993. break;
  9994. }
  9995. operators.push(f);
  9996. }
  9997. ps.push(coords.length);
  9998. coords.push(coord);
  9999. colors.push(color);
  10000. verticesLeft--;
  10001. reader.align();
  10002. }
  10003. mesh.figures.push({
  10004. type: 'triangles',
  10005. coords: new Int32Array(ps),
  10006. colors: new Int32Array(ps),
  10007. });
  10008. }
  10009. function decodeType5Shading(mesh, reader, verticesPerRow) {
  10010. var coords = mesh.coords;
  10011. var colors = mesh.colors;
  10012. var ps = []; // not maintaining cs since that will match ps
  10013. while (reader.hasData) {
  10014. var coord = reader.readCoordinate();
  10015. var color = reader.readComponents();
  10016. ps.push(coords.length);
  10017. coords.push(coord);
  10018. colors.push(color);
  10019. }
  10020. mesh.figures.push({
  10021. type: 'lattice',
  10022. coords: new Int32Array(ps),
  10023. colors: new Int32Array(ps),
  10024. verticesPerRow: verticesPerRow
  10025. });
  10026. }
  10027. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  10028. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  10029. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  10030. var getB = (function getBClosure() {
  10031. function buildB(count) {
  10032. var lut = [];
  10033. for (var i = 0; i <= count; i++) {
  10034. var t = i / count, t_ = 1 - t;
  10035. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  10036. 3 * t * t * t_, t * t * t]));
  10037. }
  10038. return lut;
  10039. }
  10040. var cache = [];
  10041. return function getB(count) {
  10042. if (!cache[count]) {
  10043. cache[count] = buildB(count);
  10044. }
  10045. return cache[count];
  10046. };
  10047. })();
  10048. function buildFigureFromPatch(mesh, index) {
  10049. var figure = mesh.figures[index];
  10050. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  10051. var coords = mesh.coords, colors = mesh.colors;
  10052. var pi = figure.coords;
  10053. var ci = figure.colors;
  10054. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  10055. coords[pi[12]][0], coords[pi[15]][0]);
  10056. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  10057. coords[pi[12]][1], coords[pi[15]][1]);
  10058. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  10059. coords[pi[12]][0], coords[pi[15]][0]);
  10060. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  10061. coords[pi[12]][1], coords[pi[15]][1]);
  10062. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  10063. (mesh.bounds[2] - mesh.bounds[0]));
  10064. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  10065. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  10066. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  10067. (mesh.bounds[3] - mesh.bounds[1]));
  10068. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  10069. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  10070. var verticesPerRow = splitXBy + 1;
  10071. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  10072. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  10073. var k = 0;
  10074. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  10075. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  10076. c2 = colors[ci[2]], c3 = colors[ci[3]];
  10077. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  10078. for (var row = 0; row <= splitYBy; row++) {
  10079. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  10080. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  10081. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  10082. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  10083. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  10084. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  10085. for (var col = 0; col <= splitXBy; col++, k++) {
  10086. if ((row === 0 || row === splitYBy) &&
  10087. (col === 0 || col === splitXBy)) {
  10088. continue;
  10089. }
  10090. var x = 0, y = 0;
  10091. var q = 0;
  10092. for (var i = 0; i <= 3; i++) {
  10093. for (var j = 0; j <= 3; j++, q++) {
  10094. var m = bRow[row][i] * bCol[col][j];
  10095. x += coords[pi[q]][0] * m;
  10096. y += coords[pi[q]][1] * m;
  10097. }
  10098. }
  10099. figureCoords[k] = coords.length;
  10100. coords.push([x, y]);
  10101. figureColors[k] = colors.length;
  10102. var newColor = new Uint8Array(3);
  10103. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  10104. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  10105. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  10106. colors.push(newColor);
  10107. }
  10108. }
  10109. figureCoords[0] = pi[0];
  10110. figureColors[0] = ci[0];
  10111. figureCoords[splitXBy] = pi[3];
  10112. figureColors[splitXBy] = ci[1];
  10113. figureCoords[verticesPerRow * splitYBy] = pi[12];
  10114. figureColors[verticesPerRow * splitYBy] = ci[2];
  10115. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  10116. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  10117. mesh.figures[index] = {
  10118. type: 'lattice',
  10119. coords: figureCoords,
  10120. colors: figureColors,
  10121. verticesPerRow: verticesPerRow
  10122. };
  10123. }
  10124. function decodeType6Shading(mesh, reader) {
  10125. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  10126. var coords = mesh.coords;
  10127. var colors = mesh.colors;
  10128. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  10129. var cs = new Int32Array(4); // c00, c30, c03, c33
  10130. while (reader.hasData) {
  10131. var f = reader.readFlag();
  10132. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  10133. var i, ii;
  10134. var pi = coords.length;
  10135. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  10136. coords.push(reader.readCoordinate());
  10137. }
  10138. var ci = colors.length;
  10139. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  10140. colors.push(reader.readComponents());
  10141. }
  10142. var tmp1, tmp2, tmp3, tmp4;
  10143. switch (f) {
  10144. case 0:
  10145. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  10146. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  10147. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  10148. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  10149. cs[2] = ci + 1; cs[3] = ci + 2;
  10150. cs[0] = ci; cs[1] = ci + 3;
  10151. break;
  10152. case 1:
  10153. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  10154. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10155. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  10156. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  10157. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10158. tmp1 = cs[2]; tmp2 = cs[3];
  10159. cs[2] = tmp2; cs[3] = ci;
  10160. cs[0] = tmp1; cs[1] = ci + 1;
  10161. break;
  10162. case 2:
  10163. tmp1 = ps[15];
  10164. tmp2 = ps[11];
  10165. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10166. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  10167. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  10168. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10169. tmp1 = cs[3];
  10170. cs[2] = cs[1]; cs[3] = ci;
  10171. cs[0] = tmp1; cs[1] = ci + 1;
  10172. break;
  10173. case 3:
  10174. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10175. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  10176. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  10177. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10178. cs[2] = cs[0]; cs[3] = ci;
  10179. cs[0] = cs[1]; cs[1] = ci + 1;
  10180. break;
  10181. }
  10182. // set p11, p12, p21, p22
  10183. ps[5] = coords.length;
  10184. coords.push([
  10185. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  10186. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  10187. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  10188. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  10189. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  10190. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  10191. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  10192. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  10193. ]);
  10194. ps[6] = coords.length;
  10195. coords.push([
  10196. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  10197. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  10198. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  10199. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  10200. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  10201. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  10202. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  10203. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  10204. ]);
  10205. ps[9] = coords.length;
  10206. coords.push([
  10207. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  10208. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  10209. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  10210. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  10211. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  10212. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  10213. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  10214. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  10215. ]);
  10216. ps[10] = coords.length;
  10217. coords.push([
  10218. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  10219. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  10220. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  10221. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  10222. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  10223. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  10224. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  10225. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  10226. ]);
  10227. mesh.figures.push({
  10228. type: 'patch',
  10229. coords: new Int32Array(ps), // making copies of ps and cs
  10230. colors: new Int32Array(cs)
  10231. });
  10232. }
  10233. }
  10234. function decodeType7Shading(mesh, reader) {
  10235. var coords = mesh.coords;
  10236. var colors = mesh.colors;
  10237. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  10238. var cs = new Int32Array(4); // c00, c30, c03, c33
  10239. while (reader.hasData) {
  10240. var f = reader.readFlag();
  10241. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  10242. var i, ii;
  10243. var pi = coords.length;
  10244. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  10245. coords.push(reader.readCoordinate());
  10246. }
  10247. var ci = colors.length;
  10248. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  10249. colors.push(reader.readComponents());
  10250. }
  10251. var tmp1, tmp2, tmp3, tmp4;
  10252. switch (f) {
  10253. case 0:
  10254. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  10255. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  10256. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  10257. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  10258. cs[2] = ci + 1; cs[3] = ci + 2;
  10259. cs[0] = ci; cs[1] = ci + 3;
  10260. break;
  10261. case 1:
  10262. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  10263. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10264. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  10265. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  10266. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10267. tmp1 = cs[2]; tmp2 = cs[3];
  10268. cs[2] = tmp2; cs[3] = ci;
  10269. cs[0] = tmp1; cs[1] = ci + 1;
  10270. break;
  10271. case 2:
  10272. tmp1 = ps[15];
  10273. tmp2 = ps[11];
  10274. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10275. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  10276. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  10277. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10278. tmp1 = cs[3];
  10279. cs[2] = cs[1]; cs[3] = ci;
  10280. cs[0] = tmp1; cs[1] = ci + 1;
  10281. break;
  10282. case 3:
  10283. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  10284. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  10285. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  10286. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  10287. cs[2] = cs[0]; cs[3] = ci;
  10288. cs[0] = cs[1]; cs[1] = ci + 1;
  10289. break;
  10290. }
  10291. mesh.figures.push({
  10292. type: 'patch',
  10293. coords: new Int32Array(ps), // making copies of ps and cs
  10294. colors: new Int32Array(cs)
  10295. });
  10296. }
  10297. }
  10298. function updateBounds(mesh) {
  10299. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  10300. maxX = minX, maxY = minY;
  10301. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  10302. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  10303. minX = minX > x ? x : minX;
  10304. minY = minY > y ? y : minY;
  10305. maxX = maxX < x ? x : maxX;
  10306. maxY = maxY < y ? y : maxY;
  10307. }
  10308. mesh.bounds = [minX, minY, maxX, maxY];
  10309. }
  10310. function packData(mesh) {
  10311. var i, ii, j, jj;
  10312. var coords = mesh.coords;
  10313. var coordsPacked = new Float32Array(coords.length * 2);
  10314. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  10315. var xy = coords[i];
  10316. coordsPacked[j++] = xy[0];
  10317. coordsPacked[j++] = xy[1];
  10318. }
  10319. mesh.coords = coordsPacked;
  10320. var colors = mesh.colors;
  10321. var colorsPacked = new Uint8Array(colors.length * 3);
  10322. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  10323. var c = colors[i];
  10324. colorsPacked[j++] = c[0];
  10325. colorsPacked[j++] = c[1];
  10326. colorsPacked[j++] = c[2];
  10327. }
  10328. mesh.colors = colorsPacked;
  10329. var figures = mesh.figures;
  10330. for (i = 0, ii = figures.length; i < ii; i++) {
  10331. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  10332. for (j = 0, jj = ps.length; j < jj; j++) {
  10333. ps[j] *= 2;
  10334. cs[j] *= 3;
  10335. }
  10336. }
  10337. }
  10338. function Mesh(stream, matrix, xref, res) {
  10339. assert(isStream(stream), 'Mesh data is not a stream');
  10340. var dict = stream.dict;
  10341. this.matrix = matrix;
  10342. this.shadingType = dict.get('ShadingType');
  10343. this.type = 'Pattern';
  10344. this.bbox = dict.get('BBox');
  10345. var cs = dict.get('ColorSpace', 'CS');
  10346. cs = ColorSpace.parse(cs, xref, res);
  10347. this.cs = cs;
  10348. this.background = dict.has('Background') ?
  10349. cs.getRgb(dict.get('Background'), 0) : null;
  10350. var fnObj = dict.get('Function');
  10351. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  10352. this.coords = [];
  10353. this.colors = [];
  10354. this.figures = [];
  10355. var decodeContext = {
  10356. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  10357. bitsPerComponent: dict.get('BitsPerComponent'),
  10358. bitsPerFlag: dict.get('BitsPerFlag'),
  10359. decode: dict.get('Decode'),
  10360. colorFn: fn,
  10361. colorSpace: cs,
  10362. numComps: fn ? 1 : cs.numComps
  10363. };
  10364. var reader = new MeshStreamReader(stream, decodeContext);
  10365. var patchMesh = false;
  10366. switch (this.shadingType) {
  10367. case ShadingType.FREE_FORM_MESH:
  10368. decodeType4Shading(this, reader);
  10369. break;
  10370. case ShadingType.LATTICE_FORM_MESH:
  10371. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  10372. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  10373. decodeType5Shading(this, reader, verticesPerRow);
  10374. break;
  10375. case ShadingType.COONS_PATCH_MESH:
  10376. decodeType6Shading(this, reader);
  10377. patchMesh = true;
  10378. break;
  10379. case ShadingType.TENSOR_PATCH_MESH:
  10380. decodeType7Shading(this, reader);
  10381. patchMesh = true;
  10382. break;
  10383. default:
  10384. error('Unsupported mesh type.');
  10385. break;
  10386. }
  10387. if (patchMesh) {
  10388. // dirty bounds calculation for determining, how dense shall be triangles
  10389. updateBounds(this);
  10390. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  10391. buildFigureFromPatch(this, i);
  10392. }
  10393. }
  10394. // calculate bounds
  10395. updateBounds(this);
  10396. packData(this);
  10397. }
  10398. Mesh.prototype = {
  10399. getIR: function Mesh_getIR() {
  10400. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  10401. this.bounds, this.matrix, this.bbox, this.background];
  10402. }
  10403. };
  10404. return Mesh;
  10405. })();
  10406. Shadings.Dummy = (function DummyClosure() {
  10407. function Dummy() {
  10408. this.type = 'Pattern';
  10409. }
  10410. Dummy.prototype = {
  10411. getIR: function Dummy_getIR() {
  10412. return ['Dummy'];
  10413. }
  10414. };
  10415. return Dummy;
  10416. })();
  10417. function getTilingPatternIR(operatorList, dict, args) {
  10418. var matrix = dict.get('Matrix');
  10419. var bbox = dict.get('BBox');
  10420. var xstep = dict.get('XStep');
  10421. var ystep = dict.get('YStep');
  10422. var paintType = dict.get('PaintType');
  10423. var tilingType = dict.get('TilingType');
  10424. return [
  10425. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  10426. paintType, tilingType
  10427. ];
  10428. }
  10429. var PartialEvaluator = (function PartialEvaluatorClosure() {
  10430. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  10431. uniquePrefix, idCounters, fontCache) {
  10432. this.pdfManager = pdfManager;
  10433. this.xref = xref;
  10434. this.handler = handler;
  10435. this.pageIndex = pageIndex;
  10436. this.uniquePrefix = uniquePrefix;
  10437. this.idCounters = idCounters;
  10438. this.fontCache = fontCache;
  10439. }
  10440. // Trying to minimize Date.now() usage and check every 100 time
  10441. var TIME_SLOT_DURATION_MS = 20;
  10442. var CHECK_TIME_EVERY = 100;
  10443. function TimeSlotManager() {
  10444. this.reset();
  10445. }
  10446. TimeSlotManager.prototype = {
  10447. check: function TimeSlotManager_check() {
  10448. if (++this.checked < CHECK_TIME_EVERY) {
  10449. return false;
  10450. }
  10451. this.checked = 0;
  10452. return this.endTime <= Date.now();
  10453. },
  10454. reset: function TimeSlotManager_reset() {
  10455. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  10456. this.checked = 0;
  10457. }
  10458. };
  10459. var deferred = Promise.resolve();
  10460. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  10461. PartialEvaluator.prototype = {
  10462. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  10463. if (!isDict(resources)) {
  10464. return false;
  10465. }
  10466. var processed = Object.create(null);
  10467. if (resources.objId) {
  10468. processed[resources.objId] = true;
  10469. }
  10470. var nodes = [resources];
  10471. while (nodes.length) {
  10472. var key;
  10473. var node = nodes.shift();
  10474. // First check the current resources for blend modes.
  10475. var graphicStates = node.get('ExtGState');
  10476. if (isDict(graphicStates)) {
  10477. graphicStates = graphicStates.getAll();
  10478. for (key in graphicStates) {
  10479. var graphicState = graphicStates[key];
  10480. var bm = graphicState['BM'];
  10481. if (isName(bm) && bm.name !== 'Normal') {
  10482. return true;
  10483. }
  10484. }
  10485. }
  10486. // Descend into the XObjects to look for more resources and blend modes.
  10487. var xObjects = node.get('XObject');
  10488. if (!isDict(xObjects)) {
  10489. continue;
  10490. }
  10491. xObjects = xObjects.getAll();
  10492. for (key in xObjects) {
  10493. var xObject = xObjects[key];
  10494. if (!isStream(xObject)) {
  10495. continue;
  10496. }
  10497. if (xObject.dict.objId) {
  10498. if (processed[xObject.dict.objId]) {
  10499. // stream has objId and is processed already
  10500. continue;
  10501. }
  10502. processed[xObject.dict.objId] = true;
  10503. }
  10504. var xResources = xObject.dict.get('Resources');
  10505. // Checking objId to detect an infinite loop.
  10506. if (isDict(xResources) &&
  10507. (!xResources.objId || !processed[xResources.objId])) {
  10508. nodes.push(xResources);
  10509. if (xResources.objId) {
  10510. processed[xResources.objId] = true;
  10511. }
  10512. }
  10513. }
  10514. }
  10515. return false;
  10516. },
  10517. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  10518. xobj, smask,
  10519. operatorList,
  10520. task,
  10521. initialState) {
  10522. var matrix = xobj.dict.getArray('Matrix');
  10523. var bbox = xobj.dict.getArray('BBox');
  10524. var group = xobj.dict.get('Group');
  10525. if (group) {
  10526. var groupOptions = {
  10527. matrix: matrix,
  10528. bbox: bbox,
  10529. smask: smask,
  10530. isolated: false,
  10531. knockout: false
  10532. };
  10533. var groupSubtype = group.get('S');
  10534. var colorSpace;
  10535. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  10536. groupOptions.isolated = (group.get('I') || false);
  10537. groupOptions.knockout = (group.get('K') || false);
  10538. colorSpace = (group.has('CS') ?
  10539. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  10540. }
  10541. if (smask && smask.backdrop) {
  10542. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  10543. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  10544. }
  10545. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  10546. }
  10547. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  10548. return this.getOperatorList(xobj, task,
  10549. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  10550. then(function () {
  10551. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  10552. if (group) {
  10553. operatorList.addOp(OPS.endGroup, [groupOptions]);
  10554. }
  10555. });
  10556. },
  10557. buildPaintImageXObject:
  10558. function PartialEvaluator_buildPaintImageXObject(resources, image,
  10559. inline, operatorList,
  10560. cacheKey, imageCache) {
  10561. var self = this;
  10562. var dict = image.dict;
  10563. var w = dict.get('Width', 'W');
  10564. var h = dict.get('Height', 'H');
  10565. if (!(w && isNum(w)) || !(h && isNum(h))) {
  10566. warn('Image dimensions are missing, or not numbers.');
  10567. return;
  10568. }
  10569. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  10570. warn('Image exceeded maximum allowed size and was removed.');
  10571. return;
  10572. }
  10573. var imageMask = (dict.get('ImageMask', 'IM') || false);
  10574. var imgData, args;
  10575. if (imageMask) {
  10576. // This depends on a tmpCanvas being filled with the
  10577. // current fillStyle, such that processing the pixel
  10578. // data can't be done here. Instead of creating a
  10579. // complete PDFImage, only read the information needed
  10580. // for later.
  10581. var width = dict.get('Width', 'W');
  10582. var height = dict.get('Height', 'H');
  10583. var bitStrideLength = (width + 7) >> 3;
  10584. var imgArray = image.getBytes(bitStrideLength * height);
  10585. var decode = dict.get('Decode', 'D');
  10586. var inverseDecode = (!!decode && decode[0] > 0);
  10587. imgData = PDFImage.createMask(imgArray, width, height,
  10588. image instanceof DecodeStream,
  10589. inverseDecode);
  10590. imgData.cached = true;
  10591. args = [imgData];
  10592. operatorList.addOp(OPS.paintImageMaskXObject, args);
  10593. if (cacheKey) {
  10594. imageCache[cacheKey] = {
  10595. fn: OPS.paintImageMaskXObject,
  10596. args: args
  10597. };
  10598. }
  10599. return;
  10600. }
  10601. var softMask = (dict.get('SMask', 'SM') || false);
  10602. var mask = (dict.get('Mask') || false);
  10603. var SMALL_IMAGE_DIMENSIONS = 200;
  10604. // Inlining small images into the queue as RGB data
  10605. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  10606. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  10607. var imageObj = new PDFImage(this.xref, resources, image,
  10608. inline, null, null);
  10609. // We force the use of RGBA_32BPP images here, because we can't handle
  10610. // any other kind.
  10611. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  10612. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  10613. return;
  10614. }
  10615. // If there is no imageMask, create the PDFImage and a lot
  10616. // of image processing can be done here.
  10617. var uniquePrefix = (this.uniquePrefix || '');
  10618. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  10619. operatorList.addDependency(objId);
  10620. args = [objId, w, h];
  10621. if (!softMask && !mask && image instanceof JpegStream &&
  10622. image.isNativelySupported(this.xref, resources)) {
  10623. // These JPEGs don't need any more processing so we can just send it.
  10624. operatorList.addOp(OPS.paintJpegXObject, args);
  10625. this.handler.send('obj',
  10626. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  10627. return;
  10628. }
  10629. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  10630. then(function(imageObj) {
  10631. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  10632. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  10633. [imgData.data.buffer]);
  10634. }).then(undefined, function (reason) {
  10635. warn('Unable to decode image: ' + reason);
  10636. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  10637. });
  10638. operatorList.addOp(OPS.paintImageXObject, args);
  10639. if (cacheKey) {
  10640. imageCache[cacheKey] = {
  10641. fn: OPS.paintImageXObject,
  10642. args: args
  10643. };
  10644. }
  10645. },
  10646. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  10647. operatorList, task,
  10648. stateManager) {
  10649. var smaskContent = smask.get('G');
  10650. var smaskOptions = {
  10651. subtype: smask.get('S').name,
  10652. backdrop: smask.get('BC')
  10653. };
  10654. // The SMask might have a alpha/luminosity value transfer function --
  10655. // we will build a map of integer values in range 0..255 to be fast.
  10656. var transferObj = smask.get('TR');
  10657. if (isPDFFunction(transferObj)) {
  10658. var transferFn = PDFFunction.parse(this.xref, transferObj);
  10659. var transferMap = new Uint8Array(256);
  10660. var tmp = new Float32Array(1);
  10661. for (var i = 0; i < 255; i++) {
  10662. tmp[0] = i / 255;
  10663. transferFn(tmp, 0, tmp, 0);
  10664. transferMap[i] = (tmp[0] * 255) | 0;
  10665. }
  10666. smaskOptions.transferMap = transferMap;
  10667. }
  10668. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  10669. operatorList, task, stateManager.state.clone());
  10670. },
  10671. handleTilingType:
  10672. function PartialEvaluator_handleTilingType(fn, args, resources,
  10673. pattern, patternDict,
  10674. operatorList, task) {
  10675. // Create an IR of the pattern code.
  10676. var tilingOpList = new OperatorList();
  10677. // Merge the available resources, to prevent issues when the patternDict
  10678. // is missing some /Resources entries (fixes issue6541.pdf).
  10679. var resourcesArray = [patternDict.get('Resources'), resources];
  10680. var patternResources = Dict.merge(this.xref, resourcesArray);
  10681. return this.getOperatorList(pattern, task, patternResources,
  10682. tilingOpList).then(function () {
  10683. // Add the dependencies to the parent operator list so they are
  10684. // resolved before sub operator list is executed synchronously.
  10685. operatorList.addDependencies(tilingOpList.dependencies);
  10686. operatorList.addOp(fn, getTilingPatternIR({
  10687. fnArray: tilingOpList.fnArray,
  10688. argsArray: tilingOpList.argsArray
  10689. }, patternDict, args));
  10690. });
  10691. },
  10692. handleSetFont:
  10693. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  10694. operatorList, task, state) {
  10695. // TODO(mack): Not needed?
  10696. var fontName;
  10697. if (fontArgs) {
  10698. fontArgs = fontArgs.slice();
  10699. fontName = fontArgs[0].name;
  10700. }
  10701. var self = this;
  10702. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  10703. function (translated) {
  10704. if (!translated.font.isType3Font) {
  10705. return translated;
  10706. }
  10707. return translated.loadType3Data(self, resources, operatorList, task).
  10708. then(function () {
  10709. return translated;
  10710. }, function (reason) {
  10711. // Error in the font data -- sending unsupported feature notification.
  10712. self.handler.send('UnsupportedFeature',
  10713. {featureId: UNSUPPORTED_FEATURES.font});
  10714. return new TranslatedFont('g_font_error',
  10715. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  10716. });
  10717. }).then(function (translated) {
  10718. state.font = translated.font;
  10719. translated.send(self.handler);
  10720. return translated.loadedName;
  10721. });
  10722. },
  10723. handleText: function PartialEvaluator_handleText(chars, state) {
  10724. var font = state.font;
  10725. var glyphs = font.charsToGlyphs(chars);
  10726. var isAddToPathSet = !!(state.textRenderingMode &
  10727. TextRenderingMode.ADD_TO_PATH_FLAG);
  10728. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  10729. var buildPath = function (fontChar) {
  10730. if (!font.renderer.hasBuiltPath(fontChar)) {
  10731. var path = font.renderer.getPathJs(fontChar);
  10732. this.handler.send('commonobj', [
  10733. font.loadedName + '_path_' + fontChar,
  10734. 'FontPath',
  10735. path
  10736. ]);
  10737. }
  10738. }.bind(this);
  10739. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  10740. var glyph = glyphs[i];
  10741. buildPath(glyph.fontChar);
  10742. // If the glyph has an accent we need to build a path for its
  10743. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  10744. var accent = glyph.accent;
  10745. if (accent && accent.fontChar) {
  10746. buildPath(accent.fontChar);
  10747. }
  10748. }
  10749. }
  10750. return glyphs;
  10751. },
  10752. setGState: function PartialEvaluator_setGState(resources, gState,
  10753. operatorList, task,
  10754. xref, stateManager) {
  10755. // This array holds the converted/processed state data.
  10756. var gStateObj = [];
  10757. var gStateMap = gState.map;
  10758. var self = this;
  10759. var promise = Promise.resolve();
  10760. for (var key in gStateMap) {
  10761. var value = gStateMap[key];
  10762. switch (key) {
  10763. case 'Type':
  10764. break;
  10765. case 'LW':
  10766. case 'LC':
  10767. case 'LJ':
  10768. case 'ML':
  10769. case 'D':
  10770. case 'RI':
  10771. case 'FL':
  10772. case 'CA':
  10773. case 'ca':
  10774. gStateObj.push([key, value]);
  10775. break;
  10776. case 'Font':
  10777. promise = promise.then(function () {
  10778. return self.handleSetFont(resources, null, value[0], operatorList,
  10779. task, stateManager.state).
  10780. then(function (loadedName) {
  10781. operatorList.addDependency(loadedName);
  10782. gStateObj.push([key, [loadedName, value[1]]]);
  10783. });
  10784. });
  10785. break;
  10786. case 'BM':
  10787. gStateObj.push([key, value]);
  10788. break;
  10789. case 'SMask':
  10790. if (isName(value) && value.name === 'None') {
  10791. gStateObj.push([key, false]);
  10792. break;
  10793. }
  10794. var dict = xref.fetchIfRef(value);
  10795. if (isDict(dict)) {
  10796. promise = promise.then(function () {
  10797. return self.handleSMask(dict, resources, operatorList,
  10798. task, stateManager);
  10799. });
  10800. gStateObj.push([key, true]);
  10801. } else {
  10802. warn('Unsupported SMask type');
  10803. }
  10804. break;
  10805. // Only generate info log messages for the following since
  10806. // they are unlikely to have a big impact on the rendering.
  10807. case 'OP':
  10808. case 'op':
  10809. case 'OPM':
  10810. case 'BG':
  10811. case 'BG2':
  10812. case 'UCR':
  10813. case 'UCR2':
  10814. case 'TR':
  10815. case 'TR2':
  10816. case 'HT':
  10817. case 'SM':
  10818. case 'SA':
  10819. case 'AIS':
  10820. case 'TK':
  10821. // TODO implement these operators.
  10822. info('graphic state operator ' + key);
  10823. break;
  10824. default:
  10825. info('Unknown graphic state operator ' + key);
  10826. break;
  10827. }
  10828. }
  10829. return promise.then(function () {
  10830. if (gStateObj.length >= 0) {
  10831. operatorList.addOp(OPS.setGState, [gStateObj]);
  10832. }
  10833. });
  10834. },
  10835. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10836. resources) {
  10837. function errorFont() {
  10838. return Promise.resolve(new TranslatedFont('g_font_error',
  10839. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10840. }
  10841. var fontRef;
  10842. if (font) { // Loading by ref.
  10843. assert(isRef(font));
  10844. fontRef = font;
  10845. } else { // Loading by name.
  10846. var fontRes = resources.get('Font');
  10847. if (fontRes) {
  10848. fontRef = fontRes.getRaw(fontName);
  10849. } else {
  10850. warn('fontRes not available');
  10851. return errorFont();
  10852. }
  10853. }
  10854. if (!fontRef) {
  10855. warn('fontRef not available');
  10856. return errorFont();
  10857. }
  10858. if (this.fontCache.has(fontRef)) {
  10859. return this.fontCache.get(fontRef);
  10860. }
  10861. font = xref.fetchIfRef(fontRef);
  10862. if (!isDict(font)) {
  10863. return errorFont();
  10864. }
  10865. // We are holding font.translated references just for fontRef that are not
  10866. // dictionaries (Dict). See explanation below.
  10867. if (font.translated) {
  10868. return font.translated;
  10869. }
  10870. var fontCapability = createPromiseCapability();
  10871. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10872. var descriptor = preEvaluatedFont.descriptor;
  10873. var fontID = fontRef.num + '_' + fontRef.gen;
  10874. if (isDict(descriptor)) {
  10875. if (!descriptor.fontAliases) {
  10876. descriptor.fontAliases = Object.create(null);
  10877. }
  10878. var fontAliases = descriptor.fontAliases;
  10879. var hash = preEvaluatedFont.hash;
  10880. if (fontAliases[hash]) {
  10881. var aliasFontRef = fontAliases[hash].aliasRef;
  10882. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10883. this.fontCache.putAlias(fontRef, aliasFontRef);
  10884. return this.fontCache.get(fontRef);
  10885. }
  10886. }
  10887. if (!fontAliases[hash]) {
  10888. fontAliases[hash] = {
  10889. fontID: Font.getFontID()
  10890. };
  10891. }
  10892. fontAliases[hash].aliasRef = fontRef;
  10893. fontID = fontAliases[hash].fontID;
  10894. }
  10895. // Workaround for bad PDF generators that don't reference fonts
  10896. // properly, i.e. by not using an object identifier.
  10897. // Check if the fontRef is a Dict (as opposed to a standard object),
  10898. // in which case we don't cache the font and instead reference it by
  10899. // fontName in font.loadedName below.
  10900. var fontRefIsDict = isDict(fontRef);
  10901. if (!fontRefIsDict) {
  10902. this.fontCache.put(fontRef, fontCapability.promise);
  10903. }
  10904. // Keep track of each font we translated so the caller can
  10905. // load them asynchronously before calling display on a page.
  10906. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  10907. fontName.replace(/\W/g, '') : fontID);
  10908. font.translated = fontCapability.promise;
  10909. // TODO move promises into translate font
  10910. var translatedPromise;
  10911. try {
  10912. translatedPromise = Promise.resolve(
  10913. this.translateFont(preEvaluatedFont, xref));
  10914. } catch (e) {
  10915. translatedPromise = Promise.reject(e);
  10916. }
  10917. var self = this;
  10918. translatedPromise.then(function (translatedFont) {
  10919. if (translatedFont.fontType !== undefined) {
  10920. var xrefFontStats = xref.stats.fontTypes;
  10921. xrefFontStats[translatedFont.fontType] = true;
  10922. }
  10923. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10924. translatedFont, font));
  10925. }, function (reason) {
  10926. // TODO fontCapability.reject?
  10927. // Error in the font data -- sending unsupported feature notification.
  10928. self.handler.send('UnsupportedFeature',
  10929. {featureId: UNSUPPORTED_FEATURES.font});
  10930. try {
  10931. // error, but it's still nice to have font type reported
  10932. var descriptor = preEvaluatedFont.descriptor;
  10933. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10934. var subtype = fontFile3 && fontFile3.get('Subtype');
  10935. var fontType = getFontType(preEvaluatedFont.type,
  10936. subtype && subtype.name);
  10937. var xrefFontStats = xref.stats.fontTypes;
  10938. xrefFontStats[fontType] = true;
  10939. } catch (ex) { }
  10940. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10941. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10942. font));
  10943. });
  10944. return fontCapability.promise;
  10945. },
  10946. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10947. var lastIndex = operatorList.length - 1;
  10948. if (!args) {
  10949. args = [];
  10950. }
  10951. if (lastIndex < 0 ||
  10952. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10953. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10954. } else {
  10955. var opArgs = operatorList.argsArray[lastIndex];
  10956. opArgs[0].push(fn);
  10957. Array.prototype.push.apply(opArgs[1], args);
  10958. }
  10959. },
  10960. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10961. cs, patterns, resources, task, xref) {
  10962. // compile tiling patterns
  10963. var patternName = args[args.length - 1];
  10964. // SCN/scn applies patterns along with normal colors
  10965. var pattern;
  10966. if (isName(patternName) &&
  10967. (pattern = patterns.get(patternName.name))) {
  10968. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10969. var typeNum = dict.get('PatternType');
  10970. if (typeNum === TILING_PATTERN) {
  10971. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10972. return this.handleTilingType(fn, color, resources, pattern,
  10973. dict, operatorList, task);
  10974. } else if (typeNum === SHADING_PATTERN) {
  10975. var shading = dict.get('Shading');
  10976. var matrix = dict.get('Matrix');
  10977. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  10978. this.handler);
  10979. operatorList.addOp(fn, pattern.getIR());
  10980. return Promise.resolve();
  10981. } else {
  10982. return Promise.reject('Unknown PatternType: ' + typeNum);
  10983. }
  10984. }
  10985. // TODO shall we fail here?
  10986. operatorList.addOp(fn, args);
  10987. return Promise.resolve();
  10988. },
  10989. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10990. task,
  10991. resources,
  10992. operatorList,
  10993. initialState) {
  10994. var self = this;
  10995. var xref = this.xref;
  10996. var imageCache = {};
  10997. assert(operatorList);
  10998. resources = (resources || Dict.empty);
  10999. var xobjs = (resources.get('XObject') || Dict.empty);
  11000. var patterns = (resources.get('Pattern') || Dict.empty);
  11001. var stateManager = new StateManager(initialState || new EvalState());
  11002. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  11003. var timeSlotManager = new TimeSlotManager();
  11004. return new Promise(function next(resolve, reject) {
  11005. task.ensureNotTerminated();
  11006. timeSlotManager.reset();
  11007. var stop, operation = {}, i, ii, cs;
  11008. while (!(stop = timeSlotManager.check())) {
  11009. // The arguments parsed by read() are used beyond this loop, so we
  11010. // cannot reuse the same array on each iteration. Therefore we pass
  11011. // in |null| as the initial value (see the comment on
  11012. // EvaluatorPreprocessor_read() for why).
  11013. operation.args = null;
  11014. if (!(preprocessor.read(operation))) {
  11015. break;
  11016. }
  11017. var args = operation.args;
  11018. var fn = operation.fn;
  11019. switch (fn | 0) {
  11020. case OPS.paintXObject:
  11021. if (args[0].code) {
  11022. break;
  11023. }
  11024. // eagerly compile XForm objects
  11025. var name = args[0].name;
  11026. if (!name) {
  11027. warn('XObject must be referred to by name.');
  11028. continue;
  11029. }
  11030. if (imageCache[name] !== undefined) {
  11031. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  11032. args = null;
  11033. continue;
  11034. }
  11035. var xobj = xobjs.get(name);
  11036. if (xobj) {
  11037. assert(isStream(xobj), 'XObject should be a stream');
  11038. var type = xobj.dict.get('Subtype');
  11039. assert(isName(type),
  11040. 'XObject should have a Name subtype');
  11041. if (type.name === 'Form') {
  11042. stateManager.save();
  11043. return self.buildFormXObject(resources, xobj, null,
  11044. operatorList, task,
  11045. stateManager.state.clone()).
  11046. then(function () {
  11047. stateManager.restore();
  11048. next(resolve, reject);
  11049. }, reject);
  11050. } else if (type.name === 'Image') {
  11051. self.buildPaintImageXObject(resources, xobj, false,
  11052. operatorList, name, imageCache);
  11053. args = null;
  11054. continue;
  11055. } else if (type.name === 'PS') {
  11056. // PostScript XObjects are unused when viewing documents.
  11057. // See section 4.7.1 of Adobe's PDF reference.
  11058. info('Ignored XObject subtype PS');
  11059. continue;
  11060. } else {
  11061. error('Unhandled XObject subtype ' + type.name);
  11062. }
  11063. }
  11064. break;
  11065. case OPS.setFont:
  11066. var fontSize = args[1];
  11067. // eagerly collect all fonts
  11068. return self.handleSetFont(resources, args, null, operatorList,
  11069. task, stateManager.state).
  11070. then(function (loadedName) {
  11071. operatorList.addDependency(loadedName);
  11072. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  11073. next(resolve, reject);
  11074. }, reject);
  11075. case OPS.endInlineImage:
  11076. var cacheKey = args[0].cacheKey;
  11077. if (cacheKey) {
  11078. var cacheEntry = imageCache[cacheKey];
  11079. if (cacheEntry !== undefined) {
  11080. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  11081. args = null;
  11082. continue;
  11083. }
  11084. }
  11085. self.buildPaintImageXObject(resources, args[0], true,
  11086. operatorList, cacheKey, imageCache);
  11087. args = null;
  11088. continue;
  11089. case OPS.showText:
  11090. args[0] = self.handleText(args[0], stateManager.state);
  11091. break;
  11092. case OPS.showSpacedText:
  11093. var arr = args[0];
  11094. var combinedGlyphs = [];
  11095. var arrLength = arr.length;
  11096. var state = stateManager.state;
  11097. for (i = 0; i < arrLength; ++i) {
  11098. var arrItem = arr[i];
  11099. if (isString(arrItem)) {
  11100. Array.prototype.push.apply(combinedGlyphs,
  11101. self.handleText(arrItem, state));
  11102. } else if (isNum(arrItem)) {
  11103. combinedGlyphs.push(arrItem);
  11104. }
  11105. }
  11106. args[0] = combinedGlyphs;
  11107. fn = OPS.showText;
  11108. break;
  11109. case OPS.nextLineShowText:
  11110. operatorList.addOp(OPS.nextLine);
  11111. args[0] = self.handleText(args[0], stateManager.state);
  11112. fn = OPS.showText;
  11113. break;
  11114. case OPS.nextLineSetSpacingShowText:
  11115. operatorList.addOp(OPS.nextLine);
  11116. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  11117. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  11118. args[0] = self.handleText(args[0], stateManager.state);
  11119. fn = OPS.showText;
  11120. break;
  11121. case OPS.setTextRenderingMode:
  11122. stateManager.state.textRenderingMode = args[0];
  11123. break;
  11124. case OPS.setFillColorSpace:
  11125. stateManager.state.fillColorSpace =
  11126. ColorSpace.parse(args[0], xref, resources);
  11127. continue;
  11128. case OPS.setStrokeColorSpace:
  11129. stateManager.state.strokeColorSpace =
  11130. ColorSpace.parse(args[0], xref, resources);
  11131. continue;
  11132. case OPS.setFillColor:
  11133. cs = stateManager.state.fillColorSpace;
  11134. args = cs.getRgb(args, 0);
  11135. fn = OPS.setFillRGBColor;
  11136. break;
  11137. case OPS.setStrokeColor:
  11138. cs = stateManager.state.strokeColorSpace;
  11139. args = cs.getRgb(args, 0);
  11140. fn = OPS.setStrokeRGBColor;
  11141. break;
  11142. case OPS.setFillGray:
  11143. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  11144. args = ColorSpace.singletons.gray.getRgb(args, 0);
  11145. fn = OPS.setFillRGBColor;
  11146. break;
  11147. case OPS.setStrokeGray:
  11148. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  11149. args = ColorSpace.singletons.gray.getRgb(args, 0);
  11150. fn = OPS.setStrokeRGBColor;
  11151. break;
  11152. case OPS.setFillCMYKColor:
  11153. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  11154. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  11155. fn = OPS.setFillRGBColor;
  11156. break;
  11157. case OPS.setStrokeCMYKColor:
  11158. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  11159. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  11160. fn = OPS.setStrokeRGBColor;
  11161. break;
  11162. case OPS.setFillRGBColor:
  11163. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  11164. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  11165. break;
  11166. case OPS.setStrokeRGBColor:
  11167. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  11168. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  11169. break;
  11170. case OPS.setFillColorN:
  11171. cs = stateManager.state.fillColorSpace;
  11172. if (cs.name === 'Pattern') {
  11173. return self.handleColorN(operatorList, OPS.setFillColorN,
  11174. args, cs, patterns, resources, task, xref).then(function() {
  11175. next(resolve, reject);
  11176. }, reject);
  11177. }
  11178. args = cs.getRgb(args, 0);
  11179. fn = OPS.setFillRGBColor;
  11180. break;
  11181. case OPS.setStrokeColorN:
  11182. cs = stateManager.state.strokeColorSpace;
  11183. if (cs.name === 'Pattern') {
  11184. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  11185. args, cs, patterns, resources, task, xref).then(function() {
  11186. next(resolve, reject);
  11187. }, reject);
  11188. }
  11189. args = cs.getRgb(args, 0);
  11190. fn = OPS.setStrokeRGBColor;
  11191. break;
  11192. case OPS.shadingFill:
  11193. var shadingRes = resources.get('Shading');
  11194. if (!shadingRes) {
  11195. error('No shading resource found');
  11196. }
  11197. var shading = shadingRes.get(args[0].name);
  11198. if (!shading) {
  11199. error('No shading object found');
  11200. }
  11201. var shadingFill = Pattern.parseShading(shading, null, xref,
  11202. resources, self.handler);
  11203. var patternIR = shadingFill.getIR();
  11204. args = [patternIR];
  11205. fn = OPS.shadingFill;
  11206. break;
  11207. case OPS.setGState:
  11208. var dictName = args[0];
  11209. var extGState = resources.get('ExtGState');
  11210. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  11211. break;
  11212. }
  11213. var gState = extGState.get(dictName.name);
  11214. return self.setGState(resources, gState, operatorList, task,
  11215. xref, stateManager).then(function() {
  11216. next(resolve, reject);
  11217. }, reject);
  11218. case OPS.moveTo:
  11219. case OPS.lineTo:
  11220. case OPS.curveTo:
  11221. case OPS.curveTo2:
  11222. case OPS.curveTo3:
  11223. case OPS.closePath:
  11224. self.buildPath(operatorList, fn, args);
  11225. continue;
  11226. case OPS.rectangle:
  11227. self.buildPath(operatorList, fn, args);
  11228. continue;
  11229. case OPS.markPoint:
  11230. case OPS.markPointProps:
  11231. case OPS.beginMarkedContent:
  11232. case OPS.beginMarkedContentProps:
  11233. case OPS.endMarkedContent:
  11234. case OPS.beginCompat:
  11235. case OPS.endCompat:
  11236. // Ignore operators where the corresponding handlers are known to
  11237. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  11238. // serialization errors and is also a bit more efficient.
  11239. // We could also try to serialize all objects in a general way,
  11240. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  11241. // but doing so is meaningless without knowing the semantics.
  11242. continue;
  11243. default:
  11244. // Note: Let's hope that the ignored operator does not have any
  11245. // non-serializable arguments, otherwise postMessage will throw
  11246. // "An object could not be cloned.".
  11247. }
  11248. operatorList.addOp(fn, args);
  11249. }
  11250. if (stop) {
  11251. deferred.then(function () {
  11252. next(resolve, reject);
  11253. }, reject);
  11254. return;
  11255. }
  11256. // Some PDFs don't close all restores inside object/form.
  11257. // Closing those for them.
  11258. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  11259. operatorList.addOp(OPS.restore, []);
  11260. }
  11261. resolve();
  11262. });
  11263. },
  11264. getTextContent:
  11265. function PartialEvaluator_getTextContent(stream, task, resources,
  11266. stateManager,
  11267. normalizeWhitespace) {
  11268. stateManager = (stateManager || new StateManager(new TextState()));
  11269. var WhitespaceRegexp = /\s/g;
  11270. var textContent = {
  11271. items: [],
  11272. styles: Object.create(null)
  11273. };
  11274. var textContentItem = {
  11275. initialized: false,
  11276. str: [],
  11277. width: 0,
  11278. height: 0,
  11279. vertical: false,
  11280. lastAdvanceWidth: 0,
  11281. lastAdvanceHeight: 0,
  11282. textAdvanceScale: 0,
  11283. spaceWidth: 0,
  11284. fakeSpaceMin: Infinity,
  11285. fakeMultiSpaceMin: Infinity,
  11286. fakeMultiSpaceMax: -0,
  11287. textRunBreakAllowed: false,
  11288. transform: null,
  11289. fontName: null
  11290. };
  11291. var SPACE_FACTOR = 0.3;
  11292. var MULTI_SPACE_FACTOR = 1.5;
  11293. var MULTI_SPACE_FACTOR_MAX = 4;
  11294. var self = this;
  11295. var xref = this.xref;
  11296. resources = (xref.fetchIfRef(resources) || Dict.empty);
  11297. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  11298. var xobjs = null;
  11299. var xobjsCache = {};
  11300. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  11301. var textState;
  11302. function ensureTextContentItem() {
  11303. if (textContentItem.initialized) {
  11304. return textContentItem;
  11305. }
  11306. var font = textState.font;
  11307. if (!(font.loadedName in textContent.styles)) {
  11308. textContent.styles[font.loadedName] = {
  11309. fontFamily: font.fallbackName,
  11310. ascent: font.ascent,
  11311. descent: font.descent,
  11312. vertical: font.vertical
  11313. };
  11314. }
  11315. textContentItem.fontName = font.loadedName;
  11316. // 9.4.4 Text Space Details
  11317. var tsm = [textState.fontSize * textState.textHScale, 0,
  11318. 0, textState.fontSize,
  11319. 0, textState.textRise];
  11320. if (font.isType3Font &&
  11321. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  11322. textState.fontSize === 1) {
  11323. var glyphHeight = font.bbox[3] - font.bbox[1];
  11324. if (glyphHeight > 0) {
  11325. glyphHeight = glyphHeight * textState.fontMatrix[3];
  11326. tsm[3] *= glyphHeight;
  11327. }
  11328. }
  11329. var trm = Util.transform(textState.ctm,
  11330. Util.transform(textState.textMatrix, tsm));
  11331. textContentItem.transform = trm;
  11332. if (!font.vertical) {
  11333. textContentItem.width = 0;
  11334. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  11335. textContentItem.vertical = false;
  11336. } else {
  11337. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  11338. textContentItem.height = 0;
  11339. textContentItem.vertical = true;
  11340. }
  11341. var a = textState.textLineMatrix[0];
  11342. var b = textState.textLineMatrix[1];
  11343. var scaleLineX = Math.sqrt(a * a + b * b);
  11344. a = textState.ctm[0];
  11345. b = textState.ctm[1];
  11346. var scaleCtmX = Math.sqrt(a * a + b * b);
  11347. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  11348. textContentItem.lastAdvanceWidth = 0;
  11349. textContentItem.lastAdvanceHeight = 0;
  11350. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  11351. if (spaceWidth) {
  11352. textContentItem.spaceWidth = spaceWidth;
  11353. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  11354. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  11355. textContentItem.fakeMultiSpaceMax =
  11356. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  11357. // It's okay for monospace fonts to fake as much space as needed.
  11358. textContentItem.textRunBreakAllowed = !font.isMonospace;
  11359. } else {
  11360. textContentItem.spaceWidth = 0;
  11361. textContentItem.fakeSpaceMin = Infinity;
  11362. textContentItem.fakeMultiSpaceMin = Infinity;
  11363. textContentItem.fakeMultiSpaceMax = 0;
  11364. textContentItem.textRunBreakAllowed = false;
  11365. }
  11366. textContentItem.initialized = true;
  11367. return textContentItem;
  11368. }
  11369. function replaceWhitespace(str) {
  11370. // Replaces all whitespaces with standard spaces (0x20), to avoid
  11371. // alignment issues between the textLayer and the canvas if the text
  11372. // contains e.g. tabs (fixes issue6612.pdf).
  11373. var i = 0, ii = str.length, code;
  11374. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  11375. i++;
  11376. }
  11377. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  11378. }
  11379. function runBidiTransform(textChunk) {
  11380. var str = textChunk.str.join('');
  11381. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  11382. return {
  11383. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  11384. bidiResult.str),
  11385. dir: bidiResult.dir,
  11386. width: textChunk.width,
  11387. height: textChunk.height,
  11388. transform: textChunk.transform,
  11389. fontName: textChunk.fontName
  11390. };
  11391. }
  11392. function handleSetFont(fontName, fontRef) {
  11393. return self.loadFont(fontName, fontRef, xref, resources).
  11394. then(function (translated) {
  11395. textState.font = translated.font;
  11396. textState.fontMatrix = translated.font.fontMatrix ||
  11397. FONT_IDENTITY_MATRIX;
  11398. });
  11399. }
  11400. function buildTextContentItem(chars) {
  11401. var font = textState.font;
  11402. var textChunk = ensureTextContentItem();
  11403. var width = 0;
  11404. var height = 0;
  11405. var glyphs = font.charsToGlyphs(chars);
  11406. var defaultVMetrics = font.defaultVMetrics;
  11407. for (var i = 0; i < glyphs.length; i++) {
  11408. var glyph = glyphs[i];
  11409. var vMetricX = null;
  11410. var vMetricY = null;
  11411. var glyphWidth = null;
  11412. if (font.vertical) {
  11413. if (glyph.vmetric) {
  11414. glyphWidth = glyph.vmetric[0];
  11415. vMetricX = glyph.vmetric[1];
  11416. vMetricY = glyph.vmetric[2];
  11417. } else {
  11418. glyphWidth = glyph.width;
  11419. vMetricX = glyph.width * 0.5;
  11420. vMetricY = defaultVMetrics[2];
  11421. }
  11422. } else {
  11423. glyphWidth = glyph.width;
  11424. }
  11425. var glyphUnicode = glyph.unicode;
  11426. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  11427. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  11428. }
  11429. glyphUnicode = reverseIfRtl(glyphUnicode);
  11430. // The following will calculate the x and y of the individual glyphs.
  11431. // if (font.vertical) {
  11432. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  11433. // textState.fontMatrix[0];
  11434. // tsm[5] -= vMetricY * textState.fontSize *
  11435. // textState.fontMatrix[0];
  11436. // }
  11437. // var trm = Util.transform(textState.textMatrix, tsm);
  11438. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  11439. // var x = pt[0];
  11440. // var y = pt[1];
  11441. var charSpacing = textState.charSpacing;
  11442. if (glyph.isSpace) {
  11443. var wordSpacing = textState.wordSpacing;
  11444. charSpacing += wordSpacing;
  11445. if (wordSpacing > 0) {
  11446. addFakeSpaces(wordSpacing, textChunk.str);
  11447. }
  11448. }
  11449. var tx = 0;
  11450. var ty = 0;
  11451. if (!font.vertical) {
  11452. var w0 = glyphWidth * textState.fontMatrix[0];
  11453. tx = (w0 * textState.fontSize + charSpacing) *
  11454. textState.textHScale;
  11455. width += tx;
  11456. } else {
  11457. var w1 = glyphWidth * textState.fontMatrix[0];
  11458. ty = w1 * textState.fontSize + charSpacing;
  11459. height += ty;
  11460. }
  11461. textState.translateTextMatrix(tx, ty);
  11462. textChunk.str.push(glyphUnicode);
  11463. }
  11464. if (!font.vertical) {
  11465. textChunk.lastAdvanceWidth = width;
  11466. textChunk.width += width * textChunk.textAdvanceScale;
  11467. } else {
  11468. textChunk.lastAdvanceHeight = height;
  11469. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  11470. }
  11471. return textChunk;
  11472. }
  11473. function addFakeSpaces(width, strBuf) {
  11474. if (width < textContentItem.fakeSpaceMin) {
  11475. return;
  11476. }
  11477. if (width < textContentItem.fakeMultiSpaceMin) {
  11478. strBuf.push(' ');
  11479. return;
  11480. }
  11481. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  11482. while (fakeSpaces-- > 0) {
  11483. strBuf.push(' ');
  11484. }
  11485. }
  11486. function flushTextContentItem() {
  11487. if (!textContentItem.initialized) {
  11488. return;
  11489. }
  11490. textContent.items.push(runBidiTransform(textContentItem));
  11491. textContentItem.initialized = false;
  11492. textContentItem.str.length = 0;
  11493. }
  11494. var timeSlotManager = new TimeSlotManager();
  11495. return new Promise(function next(resolve, reject) {
  11496. task.ensureNotTerminated();
  11497. timeSlotManager.reset();
  11498. var stop, operation = {}, args = [];
  11499. while (!(stop = timeSlotManager.check())) {
  11500. // The arguments parsed by read() are not used beyond this loop, so
  11501. // we can reuse the same array on every iteration, thus avoiding
  11502. // unnecessary allocations.
  11503. args.length = 0;
  11504. operation.args = args;
  11505. if (!(preprocessor.read(operation))) {
  11506. break;
  11507. }
  11508. textState = stateManager.state;
  11509. var fn = operation.fn;
  11510. args = operation.args;
  11511. var advance;
  11512. switch (fn | 0) {
  11513. case OPS.setFont:
  11514. flushTextContentItem();
  11515. textState.fontSize = args[1];
  11516. return handleSetFont(args[0].name).then(function() {
  11517. next(resolve, reject);
  11518. }, reject);
  11519. case OPS.setTextRise:
  11520. flushTextContentItem();
  11521. textState.textRise = args[0];
  11522. break;
  11523. case OPS.setHScale:
  11524. flushTextContentItem();
  11525. textState.textHScale = args[0] / 100;
  11526. break;
  11527. case OPS.setLeading:
  11528. flushTextContentItem();
  11529. textState.leading = args[0];
  11530. break;
  11531. case OPS.moveText:
  11532. // Optimization to treat same line movement as advance
  11533. var isSameTextLine = !textState.font ? false :
  11534. ((textState.font.vertical ? args[0] : args[1]) === 0);
  11535. advance = args[0] - args[1];
  11536. if (isSameTextLine && textContentItem.initialized &&
  11537. advance > 0 &&
  11538. advance <= textContentItem.fakeMultiSpaceMax) {
  11539. textState.translateTextLineMatrix(args[0], args[1]);
  11540. textContentItem.width +=
  11541. (args[0] - textContentItem.lastAdvanceWidth);
  11542. textContentItem.height +=
  11543. (args[1] - textContentItem.lastAdvanceHeight);
  11544. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  11545. (args[1] - textContentItem.lastAdvanceHeight);
  11546. addFakeSpaces(diff, textContentItem.str);
  11547. break;
  11548. }
  11549. flushTextContentItem();
  11550. textState.translateTextLineMatrix(args[0], args[1]);
  11551. textState.textMatrix = textState.textLineMatrix.slice();
  11552. break;
  11553. case OPS.setLeadingMoveText:
  11554. flushTextContentItem();
  11555. textState.leading = -args[1];
  11556. textState.translateTextLineMatrix(args[0], args[1]);
  11557. textState.textMatrix = textState.textLineMatrix.slice();
  11558. break;
  11559. case OPS.nextLine:
  11560. flushTextContentItem();
  11561. textState.carriageReturn();
  11562. break;
  11563. case OPS.setTextMatrix:
  11564. flushTextContentItem();
  11565. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  11566. args[4], args[5]);
  11567. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  11568. args[4], args[5]);
  11569. break;
  11570. case OPS.setCharSpacing:
  11571. textState.charSpacing = args[0];
  11572. break;
  11573. case OPS.setWordSpacing:
  11574. textState.wordSpacing = args[0];
  11575. break;
  11576. case OPS.beginText:
  11577. flushTextContentItem();
  11578. textState.textMatrix = IDENTITY_MATRIX.slice();
  11579. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  11580. break;
  11581. case OPS.showSpacedText:
  11582. var items = args[0];
  11583. var offset;
  11584. for (var j = 0, jj = items.length; j < jj; j++) {
  11585. if (typeof items[j] === 'string') {
  11586. buildTextContentItem(items[j]);
  11587. } else {
  11588. ensureTextContentItem();
  11589. // PDF Specification 5.3.2 states:
  11590. // The number is expressed in thousandths of a unit of text
  11591. // space.
  11592. // This amount is subtracted from the current horizontal or
  11593. // vertical coordinate, depending on the writing mode.
  11594. // In the default coordinate system, a positive adjustment
  11595. // has the effect of moving the next glyph painted either to
  11596. // the left or down by the given amount.
  11597. advance = items[j] * textState.fontSize / 1000;
  11598. var breakTextRun = false;
  11599. if (textState.font.vertical) {
  11600. offset = advance *
  11601. (textState.textHScale * textState.textMatrix[2] +
  11602. textState.textMatrix[3]);
  11603. textState.translateTextMatrix(0, advance);
  11604. breakTextRun = textContentItem.textRunBreakAllowed &&
  11605. advance > textContentItem.fakeMultiSpaceMax;
  11606. if (!breakTextRun) {
  11607. // Value needs to be added to height to paint down.
  11608. textContentItem.height += offset;
  11609. }
  11610. } else {
  11611. advance = -advance;
  11612. offset = advance * (
  11613. textState.textHScale * textState.textMatrix[0] +
  11614. textState.textMatrix[1]);
  11615. textState.translateTextMatrix(advance, 0);
  11616. breakTextRun = textContentItem.textRunBreakAllowed &&
  11617. advance > textContentItem.fakeMultiSpaceMax;
  11618. if (!breakTextRun) {
  11619. // Value needs to be subtracted from width to paint left.
  11620. textContentItem.width += offset;
  11621. }
  11622. }
  11623. if (breakTextRun) {
  11624. flushTextContentItem();
  11625. } else if (advance > 0) {
  11626. addFakeSpaces(advance, textContentItem.str);
  11627. }
  11628. }
  11629. }
  11630. break;
  11631. case OPS.showText:
  11632. buildTextContentItem(args[0]);
  11633. break;
  11634. case OPS.nextLineShowText:
  11635. flushTextContentItem();
  11636. textState.carriageReturn();
  11637. buildTextContentItem(args[0]);
  11638. break;
  11639. case OPS.nextLineSetSpacingShowText:
  11640. flushTextContentItem();
  11641. textState.wordSpacing = args[0];
  11642. textState.charSpacing = args[1];
  11643. textState.carriageReturn();
  11644. buildTextContentItem(args[2]);
  11645. break;
  11646. case OPS.paintXObject:
  11647. flushTextContentItem();
  11648. if (args[0].code) {
  11649. break;
  11650. }
  11651. if (!xobjs) {
  11652. xobjs = (resources.get('XObject') || Dict.empty);
  11653. }
  11654. var name = args[0].name;
  11655. if (xobjsCache.key === name) {
  11656. if (xobjsCache.texts) {
  11657. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  11658. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  11659. }
  11660. break;
  11661. }
  11662. var xobj = xobjs.get(name);
  11663. if (!xobj) {
  11664. break;
  11665. }
  11666. assert(isStream(xobj), 'XObject should be a stream');
  11667. var type = xobj.dict.get('Subtype');
  11668. assert(isName(type),
  11669. 'XObject should have a Name subtype');
  11670. if ('Form' !== type.name) {
  11671. xobjsCache.key = name;
  11672. xobjsCache.texts = null;
  11673. break;
  11674. }
  11675. stateManager.save();
  11676. var matrix = xobj.dict.get('Matrix');
  11677. if (isArray(matrix) && matrix.length === 6) {
  11678. stateManager.transform(matrix);
  11679. }
  11680. return self.getTextContent(xobj, task,
  11681. xobj.dict.get('Resources') || resources, stateManager,
  11682. normalizeWhitespace).then(function (formTextContent) {
  11683. Util.appendToArray(textContent.items, formTextContent.items);
  11684. Util.extendObj(textContent.styles, formTextContent.styles);
  11685. stateManager.restore();
  11686. xobjsCache.key = name;
  11687. xobjsCache.texts = formTextContent;
  11688. next(resolve, reject);
  11689. }, reject);
  11690. case OPS.setGState:
  11691. flushTextContentItem();
  11692. var dictName = args[0];
  11693. var extGState = resources.get('ExtGState');
  11694. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  11695. break;
  11696. }
  11697. var gsStateMap = extGState.get(dictName.name);
  11698. var gsStateFont = null;
  11699. for (var key in gsStateMap) {
  11700. if (key === 'Font') {
  11701. assert(!gsStateFont);
  11702. gsStateFont = gsStateMap[key];
  11703. }
  11704. }
  11705. if (gsStateFont) {
  11706. textState.fontSize = gsStateFont[1];
  11707. return handleSetFont(gsStateFont[0]).then(function() {
  11708. next(resolve, reject);
  11709. }, reject);
  11710. }
  11711. break;
  11712. } // switch
  11713. } // while
  11714. if (stop) {
  11715. deferred.then(function () {
  11716. next(resolve, reject);
  11717. }, reject);
  11718. return;
  11719. }
  11720. flushTextContentItem();
  11721. resolve(textContent);
  11722. });
  11723. },
  11724. extractDataStructures: function
  11725. partialEvaluatorExtractDataStructures(dict, baseDict,
  11726. xref, properties) {
  11727. // 9.10.2
  11728. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  11729. if (toUnicode) {
  11730. properties.toUnicode = this.readToUnicode(toUnicode);
  11731. }
  11732. if (properties.composite) {
  11733. // CIDSystemInfo helps to match CID to glyphs
  11734. var cidSystemInfo = dict.get('CIDSystemInfo');
  11735. if (isDict(cidSystemInfo)) {
  11736. properties.cidSystemInfo = {
  11737. registry: cidSystemInfo.get('Registry'),
  11738. ordering: cidSystemInfo.get('Ordering'),
  11739. supplement: cidSystemInfo.get('Supplement')
  11740. };
  11741. }
  11742. var cidToGidMap = dict.get('CIDToGIDMap');
  11743. if (isStream(cidToGidMap)) {
  11744. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  11745. }
  11746. }
  11747. // Based on 9.6.6 of the spec the encoding can come from multiple places
  11748. // and depends on the font type. The base encoding and differences are
  11749. // read here, but the encoding that is actually used is chosen during
  11750. // glyph mapping in the font.
  11751. // TODO: Loading the built in encoding in the font would allow the
  11752. // differences to be merged in here not require us to hold on to it.
  11753. var differences = [];
  11754. var baseEncodingName = null;
  11755. var encoding;
  11756. if (dict.has('Encoding')) {
  11757. encoding = dict.get('Encoding');
  11758. if (isDict(encoding)) {
  11759. baseEncodingName = encoding.get('BaseEncoding');
  11760. baseEncodingName = (isName(baseEncodingName) ?
  11761. baseEncodingName.name : null);
  11762. // Load the differences between the base and original
  11763. if (encoding.has('Differences')) {
  11764. var diffEncoding = encoding.get('Differences');
  11765. var index = 0;
  11766. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  11767. var data = diffEncoding[j];
  11768. if (isNum(data)) {
  11769. index = data;
  11770. } else if (isName(data)) {
  11771. differences[index++] = data.name;
  11772. } else if (isRef(data)) {
  11773. diffEncoding[j--] = xref.fetch(data);
  11774. continue;
  11775. } else {
  11776. error('Invalid entry in \'Differences\' array: ' + data);
  11777. }
  11778. }
  11779. }
  11780. } else if (isName(encoding)) {
  11781. baseEncodingName = encoding.name;
  11782. } else {
  11783. error('Encoding is not a Name nor a Dict');
  11784. }
  11785. // According to table 114 if the encoding is a named encoding it must be
  11786. // one of these predefined encodings.
  11787. if ((baseEncodingName !== 'MacRomanEncoding' &&
  11788. baseEncodingName !== 'MacExpertEncoding' &&
  11789. baseEncodingName !== 'WinAnsiEncoding')) {
  11790. baseEncodingName = null;
  11791. }
  11792. }
  11793. if (baseEncodingName) {
  11794. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  11795. } else {
  11796. encoding = (properties.type === 'TrueType' ?
  11797. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  11798. // The Symbolic attribute can be misused for regular fonts
  11799. // Heuristic: we have to check if the font is a standard one also
  11800. if (!!(properties.flags & FontFlags.Symbolic)) {
  11801. encoding = Encodings.MacRomanEncoding;
  11802. if (!properties.file) {
  11803. if (/Symbol/i.test(properties.name)) {
  11804. encoding = Encodings.SymbolSetEncoding;
  11805. } else if (/Dingbats/i.test(properties.name)) {
  11806. encoding = Encodings.ZapfDingbatsEncoding;
  11807. }
  11808. }
  11809. }
  11810. properties.defaultEncoding = encoding;
  11811. }
  11812. properties.differences = differences;
  11813. properties.baseEncodingName = baseEncodingName;
  11814. properties.dict = dict;
  11815. },
  11816. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  11817. var cmap, cmapObj = toUnicode;
  11818. if (isName(cmapObj)) {
  11819. cmap = CMapFactory.create(cmapObj,
  11820. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11821. if (cmap instanceof IdentityCMap) {
  11822. return new IdentityToUnicodeMap(0, 0xFFFF);
  11823. }
  11824. return new ToUnicodeMap(cmap.getMap());
  11825. } else if (isStream(cmapObj)) {
  11826. cmap = CMapFactory.create(cmapObj,
  11827. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11828. if (cmap instanceof IdentityCMap) {
  11829. return new IdentityToUnicodeMap(0, 0xFFFF);
  11830. }
  11831. var map = new Array(cmap.length);
  11832. // Convert UTF-16BE
  11833. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  11834. // to iterate over all keys.
  11835. cmap.forEach(function(charCode, token) {
  11836. var str = [];
  11837. for (var k = 0; k < token.length; k += 2) {
  11838. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11839. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  11840. str.push(w1);
  11841. continue;
  11842. }
  11843. k += 2;
  11844. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11845. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  11846. }
  11847. map[charCode] = String.fromCharCode.apply(String, str);
  11848. });
  11849. return new ToUnicodeMap(map);
  11850. }
  11851. return null;
  11852. },
  11853. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  11854. // Extract the encoding from the CIDToGIDMap
  11855. var glyphsData = cidToGidStream.getBytes();
  11856. // Set encoding 0 to later verify the font has an encoding
  11857. var result = [];
  11858. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  11859. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  11860. if (glyphID === 0) {
  11861. continue;
  11862. }
  11863. var code = j >> 1;
  11864. result[code] = glyphID;
  11865. }
  11866. return result;
  11867. },
  11868. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  11869. descriptor,
  11870. properties) {
  11871. var glyphsWidths = [];
  11872. var defaultWidth = 0;
  11873. var glyphsVMetrics = [];
  11874. var defaultVMetrics;
  11875. var i, ii, j, jj, start, code, widths;
  11876. if (properties.composite) {
  11877. defaultWidth = dict.get('DW') || 1000;
  11878. widths = dict.get('W');
  11879. if (widths) {
  11880. for (i = 0, ii = widths.length; i < ii; i++) {
  11881. start = widths[i++];
  11882. code = xref.fetchIfRef(widths[i]);
  11883. if (isArray(code)) {
  11884. for (j = 0, jj = code.length; j < jj; j++) {
  11885. glyphsWidths[start++] = code[j];
  11886. }
  11887. } else {
  11888. var width = widths[++i];
  11889. for (j = start; j <= code; j++) {
  11890. glyphsWidths[j] = width;
  11891. }
  11892. }
  11893. }
  11894. }
  11895. if (properties.vertical) {
  11896. var vmetrics = (dict.get('DW2') || [880, -1000]);
  11897. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  11898. vmetrics = dict.get('W2');
  11899. if (vmetrics) {
  11900. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  11901. start = vmetrics[i++];
  11902. code = xref.fetchIfRef(vmetrics[i]);
  11903. if (isArray(code)) {
  11904. for (j = 0, jj = code.length; j < jj; j++) {
  11905. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  11906. }
  11907. } else {
  11908. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  11909. for (j = start; j <= code; j++) {
  11910. glyphsVMetrics[j] = vmetric;
  11911. }
  11912. }
  11913. }
  11914. }
  11915. }
  11916. } else {
  11917. var firstChar = properties.firstChar;
  11918. widths = dict.get('Widths');
  11919. if (widths) {
  11920. j = firstChar;
  11921. for (i = 0, ii = widths.length; i < ii; i++) {
  11922. glyphsWidths[j++] = widths[i];
  11923. }
  11924. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  11925. } else {
  11926. // Trying get the BaseFont metrics (see comment above).
  11927. var baseFontName = dict.get('BaseFont');
  11928. if (isName(baseFontName)) {
  11929. var metrics = this.getBaseFontMetrics(baseFontName.name);
  11930. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  11931. properties);
  11932. defaultWidth = metrics.defaultWidth;
  11933. }
  11934. }
  11935. }
  11936. // Heuristic: detection of monospace font by checking all non-zero widths
  11937. var isMonospace = true;
  11938. var firstWidth = defaultWidth;
  11939. for (var glyph in glyphsWidths) {
  11940. var glyphWidth = glyphsWidths[glyph];
  11941. if (!glyphWidth) {
  11942. continue;
  11943. }
  11944. if (!firstWidth) {
  11945. firstWidth = glyphWidth;
  11946. continue;
  11947. }
  11948. if (firstWidth !== glyphWidth) {
  11949. isMonospace = false;
  11950. break;
  11951. }
  11952. }
  11953. if (isMonospace) {
  11954. properties.flags |= FontFlags.FixedPitch;
  11955. }
  11956. properties.defaultWidth = defaultWidth;
  11957. properties.widths = glyphsWidths;
  11958. properties.defaultVMetrics = defaultVMetrics;
  11959. properties.vmetrics = glyphsVMetrics;
  11960. },
  11961. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  11962. // Simulating descriptor flags attribute
  11963. var fontNameWoStyle = baseFontName.split('-')[0];
  11964. return (fontNameWoStyle in serifFonts) ||
  11965. (fontNameWoStyle.search(/serif/gi) !== -1);
  11966. },
  11967. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  11968. var defaultWidth = 0;
  11969. var widths = [];
  11970. var monospace = false;
  11971. var lookupName = (stdFontMap[name] || name);
  11972. if (!(lookupName in Metrics)) {
  11973. // Use default fonts for looking up font metrics if the passed
  11974. // font is not a base font
  11975. if (this.isSerifFont(name)) {
  11976. lookupName = 'Times-Roman';
  11977. } else {
  11978. lookupName = 'Helvetica';
  11979. }
  11980. }
  11981. var glyphWidths = Metrics[lookupName];
  11982. if (isNum(glyphWidths)) {
  11983. defaultWidth = glyphWidths;
  11984. monospace = true;
  11985. } else {
  11986. widths = glyphWidths;
  11987. }
  11988. return {
  11989. defaultWidth: defaultWidth,
  11990. monospace: monospace,
  11991. widths: widths
  11992. };
  11993. },
  11994. buildCharCodeToWidth:
  11995. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11996. properties) {
  11997. var widths = Object.create(null);
  11998. var differences = properties.differences;
  11999. var encoding = properties.defaultEncoding;
  12000. for (var charCode = 0; charCode < 256; charCode++) {
  12001. if (charCode in differences &&
  12002. widthsByGlyphName[differences[charCode]]) {
  12003. widths[charCode] = widthsByGlyphName[differences[charCode]];
  12004. continue;
  12005. }
  12006. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  12007. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  12008. continue;
  12009. }
  12010. }
  12011. return widths;
  12012. },
  12013. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  12014. var baseDict = dict;
  12015. var type = dict.get('Subtype');
  12016. assert(isName(type), 'invalid font Subtype');
  12017. var composite = false;
  12018. var uint8array;
  12019. if (type.name === 'Type0') {
  12020. // If font is a composite
  12021. // - get the descendant font
  12022. // - set the type according to the descendant font
  12023. // - get the FontDescriptor from the descendant font
  12024. var df = dict.get('DescendantFonts');
  12025. if (!df) {
  12026. error('Descendant fonts are not specified');
  12027. }
  12028. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  12029. type = dict.get('Subtype');
  12030. assert(isName(type), 'invalid font Subtype');
  12031. composite = true;
  12032. }
  12033. var descriptor = dict.get('FontDescriptor');
  12034. if (descriptor) {
  12035. var hash = new MurmurHash3_64();
  12036. var encoding = baseDict.getRaw('Encoding');
  12037. if (isName(encoding)) {
  12038. hash.update(encoding.name);
  12039. } else if (isRef(encoding)) {
  12040. hash.update(encoding.num + '_' + encoding.gen);
  12041. } else if (isDict(encoding)) {
  12042. var keys = encoding.getKeys();
  12043. for (var i = 0, ii = keys.length; i < ii; i++) {
  12044. var entry = encoding.getRaw(keys[i]);
  12045. if (isName(entry)) {
  12046. hash.update(entry.name);
  12047. } else if (isRef(entry)) {
  12048. hash.update(entry.num + '_' + entry.gen);
  12049. } else if (isArray(entry)) { // 'Differences' entry.
  12050. // Ideally we should check the contents of the array, but to avoid
  12051. // parsing it here and then again in |extractDataStructures|,
  12052. // we only use the array length for now (fixes bug1157493.pdf).
  12053. hash.update(entry.length.toString());
  12054. }
  12055. }
  12056. }
  12057. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  12058. if (isStream(toUnicode)) {
  12059. var stream = toUnicode.str || toUnicode;
  12060. uint8array = stream.buffer ?
  12061. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  12062. new Uint8Array(stream.bytes.buffer,
  12063. stream.start, stream.end - stream.start);
  12064. hash.update(uint8array);
  12065. } else if (isName(toUnicode)) {
  12066. hash.update(toUnicode.name);
  12067. }
  12068. var widths = dict.get('Widths') || baseDict.get('Widths');
  12069. if (widths) {
  12070. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  12071. hash.update(uint8array);
  12072. }
  12073. }
  12074. return {
  12075. descriptor: descriptor,
  12076. dict: dict,
  12077. baseDict: baseDict,
  12078. composite: composite,
  12079. type: type.name,
  12080. hash: hash ? hash.hexdigest() : ''
  12081. };
  12082. },
  12083. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  12084. xref) {
  12085. var baseDict = preEvaluatedFont.baseDict;
  12086. var dict = preEvaluatedFont.dict;
  12087. var composite = preEvaluatedFont.composite;
  12088. var descriptor = preEvaluatedFont.descriptor;
  12089. var type = preEvaluatedFont.type;
  12090. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  12091. var properties;
  12092. if (!descriptor) {
  12093. if (type === 'Type3') {
  12094. // FontDescriptor is only required for Type3 fonts when the document
  12095. // is a tagged pdf. Create a barbebones one to get by.
  12096. descriptor = new Dict(null);
  12097. descriptor.set('FontName', Name.get(type));
  12098. descriptor.set('FontBBox', dict.get('FontBBox'));
  12099. } else {
  12100. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  12101. // FontDescriptor was not required.
  12102. // This case is here for compatibility.
  12103. var baseFontName = dict.get('BaseFont');
  12104. if (!isName(baseFontName)) {
  12105. error('Base font is not specified');
  12106. }
  12107. // Using base font name as a font name.
  12108. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  12109. var metrics = this.getBaseFontMetrics(baseFontName);
  12110. // Simulating descriptor flags attribute
  12111. var fontNameWoStyle = baseFontName.split('-')[0];
  12112. var flags =
  12113. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  12114. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  12115. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  12116. FontFlags.Nonsymbolic);
  12117. properties = {
  12118. type: type,
  12119. name: baseFontName,
  12120. widths: metrics.widths,
  12121. defaultWidth: metrics.defaultWidth,
  12122. flags: flags,
  12123. firstChar: 0,
  12124. lastChar: maxCharIndex
  12125. };
  12126. this.extractDataStructures(dict, dict, xref, properties);
  12127. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  12128. properties);
  12129. return new Font(baseFontName, null, properties);
  12130. }
  12131. }
  12132. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  12133. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  12134. // to ignore this rule when a variant of a standart font is used.
  12135. // TODO Fill the width array depending on which of the base font this is
  12136. // a variant.
  12137. var firstChar = (dict.get('FirstChar') || 0);
  12138. var lastChar = (dict.get('LastChar') || maxCharIndex);
  12139. var fontName = descriptor.get('FontName');
  12140. var baseFont = dict.get('BaseFont');
  12141. // Some bad PDFs have a string as the font name.
  12142. if (isString(fontName)) {
  12143. fontName = Name.get(fontName);
  12144. }
  12145. if (isString(baseFont)) {
  12146. baseFont = Name.get(baseFont);
  12147. }
  12148. if (type !== 'Type3') {
  12149. var fontNameStr = fontName && fontName.name;
  12150. var baseFontStr = baseFont && baseFont.name;
  12151. if (fontNameStr !== baseFontStr) {
  12152. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  12153. '" but should be the same as the Font\'s BaseFont "' +
  12154. baseFontStr + '"');
  12155. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  12156. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  12157. if (fontNameStr && baseFontStr &&
  12158. baseFontStr.indexOf(fontNameStr) === 0) {
  12159. fontName = baseFont;
  12160. }
  12161. }
  12162. }
  12163. fontName = (fontName || baseFont);
  12164. assert(isName(fontName), 'invalid font name');
  12165. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  12166. if (fontFile) {
  12167. if (fontFile.dict) {
  12168. var subtype = fontFile.dict.get('Subtype');
  12169. if (subtype) {
  12170. subtype = subtype.name;
  12171. }
  12172. var length1 = fontFile.dict.get('Length1');
  12173. var length2 = fontFile.dict.get('Length2');
  12174. }
  12175. }
  12176. properties = {
  12177. type: type,
  12178. name: fontName.name,
  12179. subtype: subtype,
  12180. file: fontFile,
  12181. length1: length1,
  12182. length2: length2,
  12183. loadedName: baseDict.loadedName,
  12184. composite: composite,
  12185. wideChars: composite,
  12186. fixedPitch: false,
  12187. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  12188. firstChar: firstChar || 0,
  12189. lastChar: (lastChar || maxCharIndex),
  12190. bbox: descriptor.get('FontBBox'),
  12191. ascent: descriptor.get('Ascent'),
  12192. descent: descriptor.get('Descent'),
  12193. xHeight: descriptor.get('XHeight'),
  12194. capHeight: descriptor.get('CapHeight'),
  12195. flags: descriptor.get('Flags'),
  12196. italicAngle: descriptor.get('ItalicAngle'),
  12197. coded: false
  12198. };
  12199. if (composite) {
  12200. var cidEncoding = baseDict.get('Encoding');
  12201. if (isName(cidEncoding)) {
  12202. properties.cidEncoding = cidEncoding.name;
  12203. }
  12204. properties.cMap = CMapFactory.create(cidEncoding,
  12205. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  12206. properties.vertical = properties.cMap.vertical;
  12207. }
  12208. this.extractDataStructures(dict, baseDict, xref, properties);
  12209. this.extractWidths(dict, xref, descriptor, properties);
  12210. if (type === 'Type3') {
  12211. properties.isType3Font = true;
  12212. }
  12213. return new Font(fontName.name, fontFile, properties);
  12214. }
  12215. };
  12216. return PartialEvaluator;
  12217. })();
  12218. var TranslatedFont = (function TranslatedFontClosure() {
  12219. function TranslatedFont(loadedName, font, dict) {
  12220. this.loadedName = loadedName;
  12221. this.font = font;
  12222. this.dict = dict;
  12223. this.type3Loaded = null;
  12224. this.sent = false;
  12225. }
  12226. TranslatedFont.prototype = {
  12227. send: function (handler) {
  12228. if (this.sent) {
  12229. return;
  12230. }
  12231. var fontData = this.font.exportData();
  12232. handler.send('commonobj', [
  12233. this.loadedName,
  12234. 'Font',
  12235. fontData
  12236. ]);
  12237. this.sent = true;
  12238. },
  12239. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  12240. assert(this.font.isType3Font);
  12241. if (this.type3Loaded) {
  12242. return this.type3Loaded;
  12243. }
  12244. var translatedFont = this.font;
  12245. var loadCharProcsPromise = Promise.resolve();
  12246. var charProcs = this.dict.get('CharProcs').getAll();
  12247. var fontResources = this.dict.get('Resources') || resources;
  12248. var charProcKeys = Object.keys(charProcs);
  12249. var charProcOperatorList = {};
  12250. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  12251. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  12252. var glyphStream = charProcs[key];
  12253. var operatorList = new OperatorList();
  12254. return evaluator.getOperatorList(glyphStream, task, fontResources,
  12255. operatorList).then(function () {
  12256. charProcOperatorList[key] = operatorList.getIR();
  12257. // Add the dependencies to the parent operator list so they are
  12258. // resolved before sub operator list is executed synchronously.
  12259. parentOperatorList.addDependencies(operatorList.dependencies);
  12260. }, function (reason) {
  12261. warn('Type3 font resource \"' + key + '\" is not available');
  12262. var operatorList = new OperatorList();
  12263. charProcOperatorList[key] = operatorList.getIR();
  12264. });
  12265. }.bind(this, charProcKeys[i]));
  12266. }
  12267. this.type3Loaded = loadCharProcsPromise.then(function () {
  12268. translatedFont.charProcOperatorList = charProcOperatorList;
  12269. });
  12270. return this.type3Loaded;
  12271. }
  12272. };
  12273. return TranslatedFont;
  12274. })();
  12275. var OperatorList = (function OperatorListClosure() {
  12276. var CHUNK_SIZE = 1000;
  12277. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  12278. function getTransfers(queue) {
  12279. var transfers = [];
  12280. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12281. for (var i = 0, ii = queue.length; i < ii; i++) {
  12282. switch (fnArray[i]) {
  12283. case OPS.paintInlineImageXObject:
  12284. case OPS.paintInlineImageXObjectGroup:
  12285. case OPS.paintImageMaskXObject:
  12286. var arg = argsArray[i][0]; // first param in imgData
  12287. if (!arg.cached) {
  12288. transfers.push(arg.data.buffer);
  12289. }
  12290. break;
  12291. }
  12292. }
  12293. return transfers;
  12294. }
  12295. function OperatorList(intent, messageHandler, pageIndex) {
  12296. this.messageHandler = messageHandler;
  12297. this.fnArray = [];
  12298. this.argsArray = [];
  12299. this.dependencies = {};
  12300. this._totalLength = 0;
  12301. this.pageIndex = pageIndex;
  12302. this.intent = intent;
  12303. }
  12304. OperatorList.prototype = {
  12305. get length() {
  12306. return this.argsArray.length;
  12307. },
  12308. /**
  12309. * @returns {number} The total length of the entire operator list,
  12310. * since `this.length === 0` after flushing.
  12311. */
  12312. get totalLength() {
  12313. return (this._totalLength + this.length);
  12314. },
  12315. addOp: function(fn, args) {
  12316. this.fnArray.push(fn);
  12317. this.argsArray.push(args);
  12318. if (this.messageHandler) {
  12319. if (this.fnArray.length >= CHUNK_SIZE) {
  12320. this.flush();
  12321. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  12322. (fn === OPS.restore || fn === OPS.endText)) {
  12323. // heuristic to flush on boundary of restore or endText
  12324. this.flush();
  12325. }
  12326. }
  12327. },
  12328. addDependency: function(dependency) {
  12329. if (dependency in this.dependencies) {
  12330. return;
  12331. }
  12332. this.dependencies[dependency] = true;
  12333. this.addOp(OPS.dependency, [dependency]);
  12334. },
  12335. addDependencies: function(dependencies) {
  12336. for (var key in dependencies) {
  12337. this.addDependency(key);
  12338. }
  12339. },
  12340. addOpList: function(opList) {
  12341. Util.extendObj(this.dependencies, opList.dependencies);
  12342. for (var i = 0, ii = opList.length; i < ii; i++) {
  12343. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  12344. }
  12345. },
  12346. getIR: function() {
  12347. return {
  12348. fnArray: this.fnArray,
  12349. argsArray: this.argsArray,
  12350. length: this.length
  12351. };
  12352. },
  12353. flush: function(lastChunk) {
  12354. if (this.intent !== 'oplist') {
  12355. new QueueOptimizer().optimize(this);
  12356. }
  12357. var transfers = getTransfers(this);
  12358. var length = this.length;
  12359. this._totalLength += length;
  12360. this.messageHandler.send('RenderPageChunk', {
  12361. operatorList: {
  12362. fnArray: this.fnArray,
  12363. argsArray: this.argsArray,
  12364. lastChunk: lastChunk,
  12365. length: length
  12366. },
  12367. pageIndex: this.pageIndex,
  12368. intent: this.intent
  12369. }, transfers);
  12370. this.dependencies = {};
  12371. this.fnArray.length = 0;
  12372. this.argsArray.length = 0;
  12373. }
  12374. };
  12375. return OperatorList;
  12376. })();
  12377. var StateManager = (function StateManagerClosure() {
  12378. function StateManager(initialState) {
  12379. this.state = initialState;
  12380. this.stateStack = [];
  12381. }
  12382. StateManager.prototype = {
  12383. save: function () {
  12384. var old = this.state;
  12385. this.stateStack.push(this.state);
  12386. this.state = old.clone();
  12387. },
  12388. restore: function () {
  12389. var prev = this.stateStack.pop();
  12390. if (prev) {
  12391. this.state = prev;
  12392. }
  12393. },
  12394. transform: function (args) {
  12395. this.state.ctm = Util.transform(this.state.ctm, args);
  12396. }
  12397. };
  12398. return StateManager;
  12399. })();
  12400. var TextState = (function TextStateClosure() {
  12401. function TextState() {
  12402. this.ctm = new Float32Array(IDENTITY_MATRIX);
  12403. this.fontSize = 0;
  12404. this.font = null;
  12405. this.fontMatrix = FONT_IDENTITY_MATRIX;
  12406. this.textMatrix = IDENTITY_MATRIX.slice();
  12407. this.textLineMatrix = IDENTITY_MATRIX.slice();
  12408. this.charSpacing = 0;
  12409. this.wordSpacing = 0;
  12410. this.leading = 0;
  12411. this.textHScale = 1;
  12412. this.textRise = 0;
  12413. }
  12414. TextState.prototype = {
  12415. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  12416. var m = this.textMatrix;
  12417. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  12418. },
  12419. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  12420. var m = this.textLineMatrix;
  12421. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  12422. },
  12423. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  12424. var m = this.textMatrix;
  12425. m[4] = m[0] * x + m[2] * y + m[4];
  12426. m[5] = m[1] * x + m[3] * y + m[5];
  12427. },
  12428. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  12429. var m = this.textLineMatrix;
  12430. m[4] = m[0] * x + m[2] * y + m[4];
  12431. m[5] = m[1] * x + m[3] * y + m[5];
  12432. },
  12433. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  12434. // 9.4.4 Text Space Details
  12435. var tsm = [this.fontSize * this.textHScale, 0,
  12436. 0, this.fontSize,
  12437. 0, this.textRise];
  12438. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  12439. },
  12440. carriageReturn: function TextState_carriageReturn() {
  12441. this.translateTextLineMatrix(0, -this.leading);
  12442. this.textMatrix = this.textLineMatrix.slice();
  12443. },
  12444. clone: function TextState_clone() {
  12445. var clone = Object.create(this);
  12446. clone.textMatrix = this.textMatrix.slice();
  12447. clone.textLineMatrix = this.textLineMatrix.slice();
  12448. clone.fontMatrix = this.fontMatrix.slice();
  12449. return clone;
  12450. }
  12451. };
  12452. return TextState;
  12453. })();
  12454. var EvalState = (function EvalStateClosure() {
  12455. function EvalState() {
  12456. this.ctm = new Float32Array(IDENTITY_MATRIX);
  12457. this.font = null;
  12458. this.textRenderingMode = TextRenderingMode.FILL;
  12459. this.fillColorSpace = ColorSpace.singletons.gray;
  12460. this.strokeColorSpace = ColorSpace.singletons.gray;
  12461. }
  12462. EvalState.prototype = {
  12463. clone: function CanvasExtraState_clone() {
  12464. return Object.create(this);
  12465. },
  12466. };
  12467. return EvalState;
  12468. })();
  12469. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  12470. // Specifies properties for each command
  12471. //
  12472. // If variableArgs === true: [0, `numArgs`] expected
  12473. // If variableArgs === false: exactly `numArgs` expected
  12474. var OP_MAP = {
  12475. // Graphic state
  12476. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  12477. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  12478. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  12479. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  12480. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  12481. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  12482. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  12483. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  12484. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  12485. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  12486. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  12487. // Path
  12488. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  12489. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  12490. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  12491. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  12492. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  12493. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  12494. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  12495. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  12496. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  12497. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  12498. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  12499. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  12500. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  12501. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  12502. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  12503. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  12504. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  12505. // Clipping
  12506. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  12507. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  12508. // Text
  12509. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  12510. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  12511. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  12512. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  12513. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  12514. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  12515. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  12516. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  12517. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  12518. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  12519. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  12520. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  12521. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  12522. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  12523. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  12524. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  12525. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  12526. variableArgs: false },
  12527. // Type3 fonts
  12528. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  12529. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  12530. // Color
  12531. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  12532. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  12533. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  12534. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  12535. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  12536. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  12537. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  12538. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  12539. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  12540. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  12541. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  12542. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  12543. // Shading
  12544. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  12545. // Images
  12546. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  12547. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  12548. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  12549. // XObjects
  12550. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  12551. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  12552. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  12553. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  12554. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  12555. variableArgs: false },
  12556. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  12557. // Compatibility
  12558. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  12559. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  12560. // (reserved partial commands for the lexer)
  12561. BM: null,
  12562. BD: null,
  12563. 'true': null,
  12564. fa: null,
  12565. fal: null,
  12566. fals: null,
  12567. 'false': null,
  12568. nu: null,
  12569. nul: null,
  12570. 'null': null
  12571. };
  12572. function EvaluatorPreprocessor(stream, xref, stateManager) {
  12573. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  12574. // dictionary
  12575. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  12576. this.stateManager = stateManager;
  12577. this.nonProcessedArgs = [];
  12578. }
  12579. EvaluatorPreprocessor.prototype = {
  12580. get savedStatesDepth() {
  12581. return this.stateManager.stateStack.length;
  12582. },
  12583. // |operation| is an object with two fields:
  12584. //
  12585. // - |fn| is an out param.
  12586. //
  12587. // - |args| is an inout param. On entry, it should have one of two values.
  12588. //
  12589. // - An empty array. This indicates that the caller is providing the
  12590. // array in which the args will be stored in. The caller should use
  12591. // this value if it can reuse a single array for each call to read().
  12592. //
  12593. // - |null|. This indicates that the caller needs this function to create
  12594. // the array in which any args are stored in. If there are zero args,
  12595. // this function will leave |operation.args| as |null| (thus avoiding
  12596. // allocations that would occur if we used an empty array to represent
  12597. // zero arguments). Otherwise, it will replace |null| with a new array
  12598. // containing the arguments. The caller should use this value if it
  12599. // cannot reuse an array for each call to read().
  12600. //
  12601. // These two modes are present because this function is very hot and so
  12602. // avoiding allocations where possible is worthwhile.
  12603. //
  12604. read: function EvaluatorPreprocessor_read(operation) {
  12605. var args = operation.args;
  12606. while (true) {
  12607. var obj = this.parser.getObj();
  12608. if (isCmd(obj)) {
  12609. var cmd = obj.cmd;
  12610. // Check that the command is valid
  12611. var opSpec = OP_MAP[cmd];
  12612. if (!opSpec) {
  12613. warn('Unknown command "' + cmd + '"');
  12614. continue;
  12615. }
  12616. var fn = opSpec.id;
  12617. var numArgs = opSpec.numArgs;
  12618. var argsLength = args !== null ? args.length : 0;
  12619. if (!opSpec.variableArgs) {
  12620. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  12621. if (argsLength !== numArgs) {
  12622. var nonProcessedArgs = this.nonProcessedArgs;
  12623. while (argsLength > numArgs) {
  12624. nonProcessedArgs.push(args.shift());
  12625. argsLength--;
  12626. }
  12627. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  12628. if (!args) {
  12629. args = [];
  12630. }
  12631. args.unshift(nonProcessedArgs.pop());
  12632. argsLength++;
  12633. }
  12634. }
  12635. if (argsLength < numArgs) {
  12636. // If we receive too few args, it's not possible to possible
  12637. // to execute the command, so skip the command
  12638. info('Command ' + fn + ': because expected ' +
  12639. numArgs + ' args, but received ' + argsLength +
  12640. ' args; skipping');
  12641. args = null;
  12642. continue;
  12643. }
  12644. } else if (argsLength > numArgs) {
  12645. info('Command ' + fn + ': expected [0,' + numArgs +
  12646. '] args, but received ' + argsLength + ' args');
  12647. }
  12648. // TODO figure out how to type-check vararg functions
  12649. this.preprocessCommand(fn, args);
  12650. operation.fn = fn;
  12651. operation.args = args;
  12652. return true;
  12653. } else {
  12654. if (isEOF(obj)) {
  12655. return false; // no more commands
  12656. }
  12657. // argument
  12658. if (obj !== null) {
  12659. if (!args) {
  12660. args = [];
  12661. }
  12662. args.push((obj instanceof Dict ? obj.getAll() : obj));
  12663. assert(args.length <= 33, 'Too many arguments');
  12664. }
  12665. }
  12666. }
  12667. },
  12668. preprocessCommand:
  12669. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  12670. switch (fn | 0) {
  12671. case OPS.save:
  12672. this.stateManager.save();
  12673. break;
  12674. case OPS.restore:
  12675. this.stateManager.restore();
  12676. break;
  12677. case OPS.transform:
  12678. this.stateManager.transform(args);
  12679. break;
  12680. }
  12681. }
  12682. };
  12683. return EvaluatorPreprocessor;
  12684. })();
  12685. var QueueOptimizer = (function QueueOptimizerClosure() {
  12686. function addState(parentState, pattern, fn) {
  12687. var state = parentState;
  12688. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  12689. var item = pattern[i];
  12690. state = (state[item] || (state[item] = []));
  12691. }
  12692. state[pattern[pattern.length - 1]] = fn;
  12693. }
  12694. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12695. argsArray) {
  12696. // Handles special case of mainly LaTeX documents which use image masks to
  12697. // draw lines with the current fill style.
  12698. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  12699. // have been found at iFirstSave.
  12700. var iFirstPIMXO = iFirstSave + 2;
  12701. for (var i = 0; i < count; i++) {
  12702. var arg = argsArray[iFirstPIMXO + 4 * i];
  12703. var imageMask = arg.length === 1 && arg[0];
  12704. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  12705. (!imageMask.data.length ||
  12706. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  12707. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  12708. continue;
  12709. }
  12710. break;
  12711. }
  12712. return count - i;
  12713. }
  12714. var InitialState = [];
  12715. // This replaces (save, transform, paintInlineImageXObject, restore)+
  12716. // sequences with one |paintInlineImageXObjectGroup| operation.
  12717. addState(InitialState,
  12718. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  12719. function foundInlineImageGroup(context) {
  12720. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  12721. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  12722. var MAX_WIDTH = 1000;
  12723. var IMAGE_PADDING = 1;
  12724. var fnArray = context.fnArray, argsArray = context.argsArray;
  12725. var curr = context.iCurr;
  12726. var iFirstSave = curr - 3;
  12727. var iFirstTransform = curr - 2;
  12728. var iFirstPIIXO = curr - 1;
  12729. // Look for the quartets.
  12730. var i = iFirstSave + 4;
  12731. var ii = fnArray.length;
  12732. while (i + 3 < ii) {
  12733. if (fnArray[i] !== OPS.save ||
  12734. fnArray[i + 1] !== OPS.transform ||
  12735. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  12736. fnArray[i + 3] !== OPS.restore) {
  12737. break; // ops don't match
  12738. }
  12739. i += 4;
  12740. }
  12741. // At this point, i is the index of the first op past the last valid
  12742. // quartet.
  12743. var count = Math.min((i - iFirstSave) / 4,
  12744. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  12745. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  12746. return i;
  12747. }
  12748. // assuming that heights of those image is too small (~1 pixel)
  12749. // packing as much as possible by lines
  12750. var maxX = 0;
  12751. var map = [], maxLineHeight = 0;
  12752. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  12753. var q;
  12754. for (q = 0; q < count; q++) {
  12755. var transform = argsArray[iFirstTransform + (q << 2)];
  12756. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  12757. if (currentX + img.width > MAX_WIDTH) {
  12758. // starting new line
  12759. maxX = Math.max(maxX, currentX);
  12760. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  12761. currentX = 0;
  12762. maxLineHeight = 0;
  12763. }
  12764. map.push({
  12765. transform: transform,
  12766. x: currentX, y: currentY,
  12767. w: img.width, h: img.height
  12768. });
  12769. currentX += img.width + 2 * IMAGE_PADDING;
  12770. maxLineHeight = Math.max(maxLineHeight, img.height);
  12771. }
  12772. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  12773. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  12774. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  12775. var imgRowSize = imgWidth << 2;
  12776. for (q = 0; q < count; q++) {
  12777. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  12778. // Copy image by lines and extends pixels into padding.
  12779. var rowSize = map[q].w << 2;
  12780. var dataOffset = 0;
  12781. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  12782. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  12783. for (var k = 0, kk = map[q].h; k < kk; k++) {
  12784. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  12785. dataOffset += rowSize;
  12786. offset += imgRowSize;
  12787. }
  12788. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  12789. while (offset >= 0) {
  12790. data[offset - 4] = data[offset];
  12791. data[offset - 3] = data[offset + 1];
  12792. data[offset - 2] = data[offset + 2];
  12793. data[offset - 1] = data[offset + 3];
  12794. data[offset + rowSize] = data[offset + rowSize - 4];
  12795. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  12796. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  12797. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  12798. offset -= imgRowSize;
  12799. }
  12800. }
  12801. // Replace queue items.
  12802. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  12803. argsArray.splice(iFirstSave, count * 4,
  12804. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  12805. data: imgData }, map]);
  12806. return iFirstSave + 1;
  12807. });
  12808. // This replaces (save, transform, paintImageMaskXObject, restore)+
  12809. // sequences with one |paintImageMaskXObjectGroup| or one
  12810. // |paintImageMaskXObjectRepeat| operation.
  12811. addState(InitialState,
  12812. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  12813. function foundImageMaskGroup(context) {
  12814. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  12815. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  12816. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  12817. var fnArray = context.fnArray, argsArray = context.argsArray;
  12818. var curr = context.iCurr;
  12819. var iFirstSave = curr - 3;
  12820. var iFirstTransform = curr - 2;
  12821. var iFirstPIMXO = curr - 1;
  12822. // Look for the quartets.
  12823. var i = iFirstSave + 4;
  12824. var ii = fnArray.length;
  12825. while (i + 3 < ii) {
  12826. if (fnArray[i] !== OPS.save ||
  12827. fnArray[i + 1] !== OPS.transform ||
  12828. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  12829. fnArray[i + 3] !== OPS.restore) {
  12830. break; // ops don't match
  12831. }
  12832. i += 4;
  12833. }
  12834. // At this point, i is the index of the first op past the last valid
  12835. // quartet.
  12836. var count = (i - iFirstSave) / 4;
  12837. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  12838. argsArray);
  12839. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  12840. return i;
  12841. }
  12842. var q;
  12843. var isSameImage = false;
  12844. var iTransform, transformArgs;
  12845. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  12846. if (argsArray[iFirstTransform][1] === 0 &&
  12847. argsArray[iFirstTransform][2] === 0) {
  12848. isSameImage = true;
  12849. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12850. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12851. iTransform = iFirstTransform + 4;
  12852. var iPIMXO = iFirstPIMXO + 4;
  12853. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  12854. transformArgs = argsArray[iTransform];
  12855. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  12856. transformArgs[0] !== firstTransformArg0 ||
  12857. transformArgs[1] !== 0 ||
  12858. transformArgs[2] !== 0 ||
  12859. transformArgs[3] !== firstTransformArg3) {
  12860. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  12861. isSameImage = false;
  12862. } else {
  12863. count = q;
  12864. }
  12865. break; // different image or transform
  12866. }
  12867. }
  12868. }
  12869. if (isSameImage) {
  12870. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  12871. var positions = new Float32Array(count * 2);
  12872. iTransform = iFirstTransform;
  12873. for (q = 0; q < count; q++, iTransform += 4) {
  12874. transformArgs = argsArray[iTransform];
  12875. positions[(q << 1)] = transformArgs[4];
  12876. positions[(q << 1) + 1] = transformArgs[5];
  12877. }
  12878. // Replace queue items.
  12879. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  12880. argsArray.splice(iFirstSave, count * 4,
  12881. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  12882. } else {
  12883. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  12884. var images = [];
  12885. for (q = 0; q < count; q++) {
  12886. transformArgs = argsArray[iFirstTransform + (q << 2)];
  12887. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  12888. images.push({ data: maskParams.data, width: maskParams.width,
  12889. height: maskParams.height,
  12890. transform: transformArgs });
  12891. }
  12892. // Replace queue items.
  12893. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  12894. argsArray.splice(iFirstSave, count * 4, [images]);
  12895. }
  12896. return iFirstSave + 1;
  12897. });
  12898. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  12899. // with one paintImageXObjectRepeat operation, if the |transform| and
  12900. // |paintImageXObjectRepeat| ops are appropriate.
  12901. addState(InitialState,
  12902. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  12903. function (context) {
  12904. var MIN_IMAGES_IN_BLOCK = 3;
  12905. var MAX_IMAGES_IN_BLOCK = 1000;
  12906. var fnArray = context.fnArray, argsArray = context.argsArray;
  12907. var curr = context.iCurr;
  12908. var iFirstSave = curr - 3;
  12909. var iFirstTransform = curr - 2;
  12910. var iFirstPIXO = curr - 1;
  12911. var iFirstRestore = curr;
  12912. if (argsArray[iFirstTransform][1] !== 0 ||
  12913. argsArray[iFirstTransform][2] !== 0) {
  12914. return iFirstRestore + 1; // transform has the wrong form
  12915. }
  12916. // Look for the quartets.
  12917. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  12918. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12919. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12920. var i = iFirstSave + 4;
  12921. var ii = fnArray.length;
  12922. while (i + 3 < ii) {
  12923. if (fnArray[i] !== OPS.save ||
  12924. fnArray[i + 1] !== OPS.transform ||
  12925. fnArray[i + 2] !== OPS.paintImageXObject ||
  12926. fnArray[i + 3] !== OPS.restore) {
  12927. break; // ops don't match
  12928. }
  12929. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  12930. argsArray[i + 1][1] !== 0 ||
  12931. argsArray[i + 1][2] !== 0 ||
  12932. argsArray[i + 1][3] !== firstTransformArg3) {
  12933. break; // transforms don't match
  12934. }
  12935. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  12936. break; // images don't match
  12937. }
  12938. i += 4;
  12939. }
  12940. // At this point, i is the index of the first op past the last valid
  12941. // quartet.
  12942. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  12943. if (count < MIN_IMAGES_IN_BLOCK) {
  12944. return i;
  12945. }
  12946. // Extract the (x,y) positions from all of the matching transforms.
  12947. var positions = new Float32Array(count * 2);
  12948. var iTransform = iFirstTransform;
  12949. for (var q = 0; q < count; q++, iTransform += 4) {
  12950. var transformArgs = argsArray[iTransform];
  12951. positions[(q << 1)] = transformArgs[4];
  12952. positions[(q << 1) + 1] = transformArgs[5];
  12953. }
  12954. // Replace queue items.
  12955. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  12956. positions];
  12957. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  12958. argsArray.splice(iFirstSave, count * 4, args);
  12959. return iFirstSave + 1;
  12960. });
  12961. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  12962. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  12963. // sequences, if the font for each one is the same.
  12964. addState(InitialState,
  12965. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  12966. function (context) {
  12967. var MIN_CHARS_IN_BLOCK = 3;
  12968. var MAX_CHARS_IN_BLOCK = 1000;
  12969. var fnArray = context.fnArray, argsArray = context.argsArray;
  12970. var curr = context.iCurr;
  12971. var iFirstBeginText = curr - 4;
  12972. var iFirstSetFont = curr - 3;
  12973. var iFirstSetTextMatrix = curr - 2;
  12974. var iFirstShowText = curr - 1;
  12975. var iFirstEndText = curr;
  12976. // Look for the quintets.
  12977. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  12978. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  12979. var i = iFirstBeginText + 5;
  12980. var ii = fnArray.length;
  12981. while (i + 4 < ii) {
  12982. if (fnArray[i] !== OPS.beginText ||
  12983. fnArray[i + 1] !== OPS.setFont ||
  12984. fnArray[i + 2] !== OPS.setTextMatrix ||
  12985. fnArray[i + 3] !== OPS.showText ||
  12986. fnArray[i + 4] !== OPS.endText) {
  12987. break; // ops don't match
  12988. }
  12989. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  12990. argsArray[i + 1][1] !== firstSetFontArg1) {
  12991. break; // fonts don't match
  12992. }
  12993. i += 5;
  12994. }
  12995. // At this point, i is the index of the first op past the last valid
  12996. // quintet.
  12997. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12998. if (count < MIN_CHARS_IN_BLOCK) {
  12999. return i;
  13000. }
  13001. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  13002. // showText, endText), include that as well. (E.g. <something> might be
  13003. // |dependency|.)
  13004. var iFirst = iFirstBeginText;
  13005. if (iFirstBeginText >= 4 &&
  13006. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  13007. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  13008. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  13009. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  13010. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  13011. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  13012. count++;
  13013. iFirst -= 5;
  13014. }
  13015. // Remove (endText, beginText, setFont) trios.
  13016. var iEndText = iFirst + 4;
  13017. for (var q = 1; q < count; q++) {
  13018. fnArray.splice(iEndText, 3);
  13019. argsArray.splice(iEndText, 3);
  13020. iEndText += 2;
  13021. }
  13022. return iEndText + 1;
  13023. });
  13024. function QueueOptimizer() {}
  13025. QueueOptimizer.prototype = {
  13026. optimize: function QueueOptimizer_optimize(queue) {
  13027. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  13028. var context = {
  13029. iCurr: 0,
  13030. fnArray: fnArray,
  13031. argsArray: argsArray
  13032. };
  13033. var state;
  13034. var i = 0, ii = fnArray.length;
  13035. while (i < ii) {
  13036. state = (state || InitialState)[fnArray[i]];
  13037. if (typeof state === 'function') { // we found some handler
  13038. context.iCurr = i;
  13039. // state() returns the index of the first non-matching op (if we
  13040. // didn't match) or the first op past the modified ops (if we did
  13041. // match and replace).
  13042. i = state(context);
  13043. state = undefined; // reset the state machine
  13044. ii = context.fnArray.length;
  13045. } else {
  13046. i++;
  13047. }
  13048. }
  13049. }
  13050. };
  13051. return QueueOptimizer;
  13052. })();
  13053. var BUILT_IN_CMAPS = [
  13054. // << Start unicode maps.
  13055. 'Adobe-GB1-UCS2',
  13056. 'Adobe-CNS1-UCS2',
  13057. 'Adobe-Japan1-UCS2',
  13058. 'Adobe-Korea1-UCS2',
  13059. // >> End unicode maps.
  13060. '78-EUC-H',
  13061. '78-EUC-V',
  13062. '78-H',
  13063. '78-RKSJ-H',
  13064. '78-RKSJ-V',
  13065. '78-V',
  13066. '78ms-RKSJ-H',
  13067. '78ms-RKSJ-V',
  13068. '83pv-RKSJ-H',
  13069. '90ms-RKSJ-H',
  13070. '90ms-RKSJ-V',
  13071. '90msp-RKSJ-H',
  13072. '90msp-RKSJ-V',
  13073. '90pv-RKSJ-H',
  13074. '90pv-RKSJ-V',
  13075. 'Add-H',
  13076. 'Add-RKSJ-H',
  13077. 'Add-RKSJ-V',
  13078. 'Add-V',
  13079. 'Adobe-CNS1-0',
  13080. 'Adobe-CNS1-1',
  13081. 'Adobe-CNS1-2',
  13082. 'Adobe-CNS1-3',
  13083. 'Adobe-CNS1-4',
  13084. 'Adobe-CNS1-5',
  13085. 'Adobe-CNS1-6',
  13086. 'Adobe-GB1-0',
  13087. 'Adobe-GB1-1',
  13088. 'Adobe-GB1-2',
  13089. 'Adobe-GB1-3',
  13090. 'Adobe-GB1-4',
  13091. 'Adobe-GB1-5',
  13092. 'Adobe-Japan1-0',
  13093. 'Adobe-Japan1-1',
  13094. 'Adobe-Japan1-2',
  13095. 'Adobe-Japan1-3',
  13096. 'Adobe-Japan1-4',
  13097. 'Adobe-Japan1-5',
  13098. 'Adobe-Japan1-6',
  13099. 'Adobe-Korea1-0',
  13100. 'Adobe-Korea1-1',
  13101. 'Adobe-Korea1-2',
  13102. 'B5-H',
  13103. 'B5-V',
  13104. 'B5pc-H',
  13105. 'B5pc-V',
  13106. 'CNS-EUC-H',
  13107. 'CNS-EUC-V',
  13108. 'CNS1-H',
  13109. 'CNS1-V',
  13110. 'CNS2-H',
  13111. 'CNS2-V',
  13112. 'ETHK-B5-H',
  13113. 'ETHK-B5-V',
  13114. 'ETen-B5-H',
  13115. 'ETen-B5-V',
  13116. 'ETenms-B5-H',
  13117. 'ETenms-B5-V',
  13118. 'EUC-H',
  13119. 'EUC-V',
  13120. 'Ext-H',
  13121. 'Ext-RKSJ-H',
  13122. 'Ext-RKSJ-V',
  13123. 'Ext-V',
  13124. 'GB-EUC-H',
  13125. 'GB-EUC-V',
  13126. 'GB-H',
  13127. 'GB-V',
  13128. 'GBK-EUC-H',
  13129. 'GBK-EUC-V',
  13130. 'GBK2K-H',
  13131. 'GBK2K-V',
  13132. 'GBKp-EUC-H',
  13133. 'GBKp-EUC-V',
  13134. 'GBT-EUC-H',
  13135. 'GBT-EUC-V',
  13136. 'GBT-H',
  13137. 'GBT-V',
  13138. 'GBTpc-EUC-H',
  13139. 'GBTpc-EUC-V',
  13140. 'GBpc-EUC-H',
  13141. 'GBpc-EUC-V',
  13142. 'H',
  13143. 'HKdla-B5-H',
  13144. 'HKdla-B5-V',
  13145. 'HKdlb-B5-H',
  13146. 'HKdlb-B5-V',
  13147. 'HKgccs-B5-H',
  13148. 'HKgccs-B5-V',
  13149. 'HKm314-B5-H',
  13150. 'HKm314-B5-V',
  13151. 'HKm471-B5-H',
  13152. 'HKm471-B5-V',
  13153. 'HKscs-B5-H',
  13154. 'HKscs-B5-V',
  13155. 'Hankaku',
  13156. 'Hiragana',
  13157. 'KSC-EUC-H',
  13158. 'KSC-EUC-V',
  13159. 'KSC-H',
  13160. 'KSC-Johab-H',
  13161. 'KSC-Johab-V',
  13162. 'KSC-V',
  13163. 'KSCms-UHC-H',
  13164. 'KSCms-UHC-HW-H',
  13165. 'KSCms-UHC-HW-V',
  13166. 'KSCms-UHC-V',
  13167. 'KSCpc-EUC-H',
  13168. 'KSCpc-EUC-V',
  13169. 'Katakana',
  13170. 'NWP-H',
  13171. 'NWP-V',
  13172. 'RKSJ-H',
  13173. 'RKSJ-V',
  13174. 'Roman',
  13175. 'UniCNS-UCS2-H',
  13176. 'UniCNS-UCS2-V',
  13177. 'UniCNS-UTF16-H',
  13178. 'UniCNS-UTF16-V',
  13179. 'UniCNS-UTF32-H',
  13180. 'UniCNS-UTF32-V',
  13181. 'UniCNS-UTF8-H',
  13182. 'UniCNS-UTF8-V',
  13183. 'UniGB-UCS2-H',
  13184. 'UniGB-UCS2-V',
  13185. 'UniGB-UTF16-H',
  13186. 'UniGB-UTF16-V',
  13187. 'UniGB-UTF32-H',
  13188. 'UniGB-UTF32-V',
  13189. 'UniGB-UTF8-H',
  13190. 'UniGB-UTF8-V',
  13191. 'UniJIS-UCS2-H',
  13192. 'UniJIS-UCS2-HW-H',
  13193. 'UniJIS-UCS2-HW-V',
  13194. 'UniJIS-UCS2-V',
  13195. 'UniJIS-UTF16-H',
  13196. 'UniJIS-UTF16-V',
  13197. 'UniJIS-UTF32-H',
  13198. 'UniJIS-UTF32-V',
  13199. 'UniJIS-UTF8-H',
  13200. 'UniJIS-UTF8-V',
  13201. 'UniJIS2004-UTF16-H',
  13202. 'UniJIS2004-UTF16-V',
  13203. 'UniJIS2004-UTF32-H',
  13204. 'UniJIS2004-UTF32-V',
  13205. 'UniJIS2004-UTF8-H',
  13206. 'UniJIS2004-UTF8-V',
  13207. 'UniJISPro-UCS2-HW-V',
  13208. 'UniJISPro-UCS2-V',
  13209. 'UniJISPro-UTF8-V',
  13210. 'UniJISX0213-UTF32-H',
  13211. 'UniJISX0213-UTF32-V',
  13212. 'UniJISX02132004-UTF32-H',
  13213. 'UniJISX02132004-UTF32-V',
  13214. 'UniKS-UCS2-H',
  13215. 'UniKS-UCS2-V',
  13216. 'UniKS-UTF16-H',
  13217. 'UniKS-UTF16-V',
  13218. 'UniKS-UTF32-H',
  13219. 'UniKS-UTF32-V',
  13220. 'UniKS-UTF8-H',
  13221. 'UniKS-UTF8-V',
  13222. 'V',
  13223. 'WP-Symbol'];
  13224. // CMap, not to be confused with TrueType's cmap.
  13225. var CMap = (function CMapClosure() {
  13226. function CMap(builtInCMap) {
  13227. // Codespace ranges are stored as follows:
  13228. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  13229. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  13230. this.codespaceRanges = [[], [], [], []];
  13231. this.numCodespaceRanges = 0;
  13232. // Map entries have one of two forms.
  13233. // - cid chars are 16-bit unsigned integers, stored as integers.
  13234. // - bf chars are variable-length byte sequences, stored as strings, with
  13235. // one byte per character.
  13236. this._map = [];
  13237. this.name = '';
  13238. this.vertical = false;
  13239. this.useCMap = null;
  13240. this.builtInCMap = builtInCMap;
  13241. }
  13242. CMap.prototype = {
  13243. addCodespaceRange: function(n, low, high) {
  13244. this.codespaceRanges[n - 1].push(low, high);
  13245. this.numCodespaceRanges++;
  13246. },
  13247. mapCidRange: function(low, high, dstLow) {
  13248. while (low <= high) {
  13249. this._map[low++] = dstLow++;
  13250. }
  13251. },
  13252. mapBfRange: function(low, high, dstLow) {
  13253. var lastByte = dstLow.length - 1;
  13254. while (low <= high) {
  13255. this._map[low++] = dstLow;
  13256. // Only the last byte has to be incremented.
  13257. dstLow = dstLow.substr(0, lastByte) +
  13258. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  13259. }
  13260. },
  13261. mapBfRangeToArray: function(low, high, array) {
  13262. var i = 0, ii = array.length;
  13263. while (low <= high && i < ii) {
  13264. this._map[low] = array[i++];
  13265. ++low;
  13266. }
  13267. },
  13268. // This is used for both bf and cid chars.
  13269. mapOne: function(src, dst) {
  13270. this._map[src] = dst;
  13271. },
  13272. lookup: function(code) {
  13273. return this._map[code];
  13274. },
  13275. contains: function(code) {
  13276. return this._map[code] !== undefined;
  13277. },
  13278. forEach: function(callback) {
  13279. // Most maps have fewer than 65536 entries, and for those we use normal
  13280. // array iteration. But really sparse tables are possible -- e.g. with
  13281. // indices in the *billions*. For such tables we use for..in, which isn't
  13282. // ideal because it stringifies the indices for all present elements, but
  13283. // it does avoid iterating over every undefined entry.
  13284. var map = this._map;
  13285. var length = map.length;
  13286. var i;
  13287. if (length <= 0x10000) {
  13288. for (i = 0; i < length; i++) {
  13289. if (map[i] !== undefined) {
  13290. callback(i, map[i]);
  13291. }
  13292. }
  13293. } else {
  13294. for (i in this._map) {
  13295. callback(i, map[i]);
  13296. }
  13297. }
  13298. },
  13299. charCodeOf: function(value) {
  13300. return this._map.indexOf(value);
  13301. },
  13302. getMap: function() {
  13303. return this._map;
  13304. },
  13305. readCharCode: function(str, offset, out) {
  13306. var c = 0;
  13307. var codespaceRanges = this.codespaceRanges;
  13308. var codespaceRangesLen = this.codespaceRanges.length;
  13309. // 9.7.6.2 CMap Mapping
  13310. // The code length is at most 4.
  13311. for (var n = 0; n < codespaceRangesLen; n++) {
  13312. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  13313. // Check each codespace range to see if it falls within.
  13314. var codespaceRange = codespaceRanges[n];
  13315. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  13316. var low = codespaceRange[k++];
  13317. var high = codespaceRange[k++];
  13318. if (c >= low && c <= high) {
  13319. out.charcode = c;
  13320. out.length = n + 1;
  13321. return;
  13322. }
  13323. }
  13324. }
  13325. out.charcode = 0;
  13326. out.length = 1;
  13327. },
  13328. get length() {
  13329. return this._map.length;
  13330. },
  13331. get isIdentityCMap() {
  13332. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  13333. return false;
  13334. }
  13335. if (this._map.length !== 0x10000) {
  13336. return false;
  13337. }
  13338. for (var i = 0; i < 0x10000; i++) {
  13339. if (this._map[i] !== i) {
  13340. return false;
  13341. }
  13342. }
  13343. return true;
  13344. }
  13345. };
  13346. return CMap;
  13347. })();
  13348. // A special case of CMap, where the _map array implicitly has a length of
  13349. // 65536 and each element is equal to its index.
  13350. var IdentityCMap = (function IdentityCMapClosure() {
  13351. function IdentityCMap(vertical, n) {
  13352. CMap.call(this);
  13353. this.vertical = vertical;
  13354. this.addCodespaceRange(n, 0, 0xffff);
  13355. }
  13356. Util.inherit(IdentityCMap, CMap, {});
  13357. IdentityCMap.prototype = {
  13358. addCodespaceRange: CMap.prototype.addCodespaceRange,
  13359. mapCidRange: function(low, high, dstLow) {
  13360. error('should not call mapCidRange');
  13361. },
  13362. mapBfRange: function(low, high, dstLow) {
  13363. error('should not call mapBfRange');
  13364. },
  13365. mapBfRangeToArray: function(low, high, array) {
  13366. error('should not call mapBfRangeToArray');
  13367. },
  13368. mapOne: function(src, dst) {
  13369. error('should not call mapCidOne');
  13370. },
  13371. lookup: function(code) {
  13372. return (isInt(code) && code <= 0xffff) ? code : undefined;
  13373. },
  13374. contains: function(code) {
  13375. return isInt(code) && code <= 0xffff;
  13376. },
  13377. forEach: function(callback) {
  13378. for (var i = 0; i <= 0xffff; i++) {
  13379. callback(i, i);
  13380. }
  13381. },
  13382. charCodeOf: function(value) {
  13383. return (isInt(value) && value <= 0xffff) ? value : -1;
  13384. },
  13385. getMap: function() {
  13386. // Sometimes identity maps must be instantiated, but it's rare.
  13387. var map = new Array(0x10000);
  13388. for (var i = 0; i <= 0xffff; i++) {
  13389. map[i] = i;
  13390. }
  13391. return map;
  13392. },
  13393. readCharCode: CMap.prototype.readCharCode,
  13394. get length() {
  13395. return 0x10000;
  13396. },
  13397. get isIdentityCMap() {
  13398. error('should not access .isIdentityCMap');
  13399. }
  13400. };
  13401. return IdentityCMap;
  13402. })();
  13403. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  13404. function fetchBinaryData(url) {
  13405. var nonBinaryRequest = PDFJS.disableWorker;
  13406. var request = new XMLHttpRequest();
  13407. request.open('GET', url, false);
  13408. if (!nonBinaryRequest) {
  13409. try {
  13410. request.responseType = 'arraybuffer';
  13411. nonBinaryRequest = request.responseType !== 'arraybuffer';
  13412. } catch (e) {
  13413. nonBinaryRequest = true;
  13414. }
  13415. }
  13416. if (nonBinaryRequest && request.overrideMimeType) {
  13417. request.overrideMimeType('text/plain; charset=x-user-defined');
  13418. }
  13419. request.send(null);
  13420. if (nonBinaryRequest ? !request.responseText : !request.response) {
  13421. error('Unable to get binary cMap at: ' + url);
  13422. }
  13423. if (nonBinaryRequest) {
  13424. var data = Array.prototype.map.call(request.responseText, function (ch) {
  13425. return ch.charCodeAt(0) & 255;
  13426. });
  13427. return new Uint8Array(data);
  13428. }
  13429. return new Uint8Array(request.response);
  13430. }
  13431. function hexToInt(a, size) {
  13432. var n = 0;
  13433. for (var i = 0; i <= size; i++) {
  13434. n = (n << 8) | a[i];
  13435. }
  13436. return n >>> 0;
  13437. }
  13438. function hexToStr(a, size) {
  13439. // This code is hot. Special-case some common values to avoid creating an
  13440. // object with subarray().
  13441. if (size === 1) {
  13442. return String.fromCharCode(a[0], a[1]);
  13443. }
  13444. if (size === 3) {
  13445. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  13446. }
  13447. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  13448. }
  13449. function addHex(a, b, size) {
  13450. var c = 0;
  13451. for (var i = size; i >= 0; i--) {
  13452. c += a[i] + b[i];
  13453. a[i] = c & 255;
  13454. c >>= 8;
  13455. }
  13456. }
  13457. function incHex(a, size) {
  13458. var c = 1;
  13459. for (var i = size; i >= 0 && c > 0; i--) {
  13460. c += a[i];
  13461. a[i] = c & 255;
  13462. c >>= 8;
  13463. }
  13464. }
  13465. var MAX_NUM_SIZE = 16;
  13466. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  13467. function BinaryCMapStream(data) {
  13468. this.buffer = data;
  13469. this.pos = 0;
  13470. this.end = data.length;
  13471. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  13472. }
  13473. BinaryCMapStream.prototype = {
  13474. readByte: function () {
  13475. if (this.pos >= this.end) {
  13476. return -1;
  13477. }
  13478. return this.buffer[this.pos++];
  13479. },
  13480. readNumber: function () {
  13481. var n = 0;
  13482. var last;
  13483. do {
  13484. var b = this.readByte();
  13485. if (b < 0) {
  13486. error('unexpected EOF in bcmap');
  13487. }
  13488. last = !(b & 0x80);
  13489. n = (n << 7) | (b & 0x7F);
  13490. } while (!last);
  13491. return n;
  13492. },
  13493. readSigned: function () {
  13494. var n = this.readNumber();
  13495. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  13496. },
  13497. readHex: function (num, size) {
  13498. num.set(this.buffer.subarray(this.pos,
  13499. this.pos + size + 1));
  13500. this.pos += size + 1;
  13501. },
  13502. readHexNumber: function (num, size) {
  13503. var last;
  13504. var stack = this.tmpBuf, sp = 0;
  13505. do {
  13506. var b = this.readByte();
  13507. if (b < 0) {
  13508. error('unexpected EOF in bcmap');
  13509. }
  13510. last = !(b & 0x80);
  13511. stack[sp++] = b & 0x7F;
  13512. } while (!last);
  13513. var i = size, buffer = 0, bufferSize = 0;
  13514. while (i >= 0) {
  13515. while (bufferSize < 8 && stack.length > 0) {
  13516. buffer = (stack[--sp] << bufferSize) | buffer;
  13517. bufferSize += 7;
  13518. }
  13519. num[i] = buffer & 255;
  13520. i--;
  13521. buffer >>= 8;
  13522. bufferSize -= 8;
  13523. }
  13524. },
  13525. readHexSigned: function (num, size) {
  13526. this.readHexNumber(num, size);
  13527. var sign = num[size] & 1 ? 255 : 0;
  13528. var c = 0;
  13529. for (var i = 0; i <= size; i++) {
  13530. c = ((c & 1) << 8) | num[i];
  13531. num[i] = (c >> 1) ^ sign;
  13532. }
  13533. },
  13534. readString: function () {
  13535. var len = this.readNumber();
  13536. var s = '';
  13537. for (var i = 0; i < len; i++) {
  13538. s += String.fromCharCode(this.readNumber());
  13539. }
  13540. return s;
  13541. }
  13542. };
  13543. function processBinaryCMap(url, cMap, extend) {
  13544. var data = fetchBinaryData(url);
  13545. var stream = new BinaryCMapStream(data);
  13546. var header = stream.readByte();
  13547. cMap.vertical = !!(header & 1);
  13548. var useCMap = null;
  13549. var start = new Uint8Array(MAX_NUM_SIZE);
  13550. var end = new Uint8Array(MAX_NUM_SIZE);
  13551. var char = new Uint8Array(MAX_NUM_SIZE);
  13552. var charCode = new Uint8Array(MAX_NUM_SIZE);
  13553. var tmp = new Uint8Array(MAX_NUM_SIZE);
  13554. var code;
  13555. var b;
  13556. while ((b = stream.readByte()) >= 0) {
  13557. var type = b >> 5;
  13558. if (type === 7) { // metadata, e.g. comment or usecmap
  13559. switch (b & 0x1F) {
  13560. case 0:
  13561. stream.readString(); // skipping comment
  13562. break;
  13563. case 1:
  13564. useCMap = stream.readString();
  13565. break;
  13566. }
  13567. continue;
  13568. }
  13569. var sequence = !!(b & 0x10);
  13570. var dataSize = b & 15;
  13571. assert(dataSize + 1 <= MAX_NUM_SIZE);
  13572. var ucs2DataSize = 1;
  13573. var subitemsCount = stream.readNumber();
  13574. var i;
  13575. switch (type) {
  13576. case 0: // codespacerange
  13577. stream.readHex(start, dataSize);
  13578. stream.readHexNumber(end, dataSize);
  13579. addHex(end, start, dataSize);
  13580. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  13581. hexToInt(end, dataSize));
  13582. for (i = 1; i < subitemsCount; i++) {
  13583. incHex(end, dataSize);
  13584. stream.readHexNumber(start, dataSize);
  13585. addHex(start, end, dataSize);
  13586. stream.readHexNumber(end, dataSize);
  13587. addHex(end, start, dataSize);
  13588. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  13589. hexToInt(end, dataSize));
  13590. }
  13591. break;
  13592. case 1: // notdefrange
  13593. stream.readHex(start, dataSize);
  13594. stream.readHexNumber(end, dataSize);
  13595. addHex(end, start, dataSize);
  13596. code = stream.readNumber();
  13597. // undefined range, skipping
  13598. for (i = 1; i < subitemsCount; i++) {
  13599. incHex(end, dataSize);
  13600. stream.readHexNumber(start, dataSize);
  13601. addHex(start, end, dataSize);
  13602. stream.readHexNumber(end, dataSize);
  13603. addHex(end, start, dataSize);
  13604. code = stream.readNumber();
  13605. // nop
  13606. }
  13607. break;
  13608. case 2: // cidchar
  13609. stream.readHex(char, dataSize);
  13610. code = stream.readNumber();
  13611. cMap.mapOne(hexToInt(char, dataSize), code);
  13612. for (i = 1; i < subitemsCount; i++) {
  13613. incHex(char, dataSize);
  13614. if (!sequence) {
  13615. stream.readHexNumber(tmp, dataSize);
  13616. addHex(char, tmp, dataSize);
  13617. }
  13618. code = stream.readSigned() + (code + 1);
  13619. cMap.mapOne(hexToInt(char, dataSize), code);
  13620. }
  13621. break;
  13622. case 3: // cidrange
  13623. stream.readHex(start, dataSize);
  13624. stream.readHexNumber(end, dataSize);
  13625. addHex(end, start, dataSize);
  13626. code = stream.readNumber();
  13627. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  13628. code);
  13629. for (i = 1; i < subitemsCount; i++) {
  13630. incHex(end, dataSize);
  13631. if (!sequence) {
  13632. stream.readHexNumber(start, dataSize);
  13633. addHex(start, end, dataSize);
  13634. } else {
  13635. start.set(end);
  13636. }
  13637. stream.readHexNumber(end, dataSize);
  13638. addHex(end, start, dataSize);
  13639. code = stream.readNumber();
  13640. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  13641. code);
  13642. }
  13643. break;
  13644. case 4: // bfchar
  13645. stream.readHex(char, ucs2DataSize);
  13646. stream.readHex(charCode, dataSize);
  13647. cMap.mapOne(hexToInt(char, ucs2DataSize),
  13648. hexToStr(charCode, dataSize));
  13649. for (i = 1; i < subitemsCount; i++) {
  13650. incHex(char, ucs2DataSize);
  13651. if (!sequence) {
  13652. stream.readHexNumber(tmp, ucs2DataSize);
  13653. addHex(char, tmp, ucs2DataSize);
  13654. }
  13655. incHex(charCode, dataSize);
  13656. stream.readHexSigned(tmp, dataSize);
  13657. addHex(charCode, tmp, dataSize);
  13658. cMap.mapOne(hexToInt(char, ucs2DataSize),
  13659. hexToStr(charCode, dataSize));
  13660. }
  13661. break;
  13662. case 5: // bfrange
  13663. stream.readHex(start, ucs2DataSize);
  13664. stream.readHexNumber(end, ucs2DataSize);
  13665. addHex(end, start, ucs2DataSize);
  13666. stream.readHex(charCode, dataSize);
  13667. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  13668. hexToInt(end, ucs2DataSize),
  13669. hexToStr(charCode, dataSize));
  13670. for (i = 1; i < subitemsCount; i++) {
  13671. incHex(end, ucs2DataSize);
  13672. if (!sequence) {
  13673. stream.readHexNumber(start, ucs2DataSize);
  13674. addHex(start, end, ucs2DataSize);
  13675. } else {
  13676. start.set(end);
  13677. }
  13678. stream.readHexNumber(end, ucs2DataSize);
  13679. addHex(end, start, ucs2DataSize);
  13680. stream.readHex(charCode, dataSize);
  13681. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  13682. hexToInt(end, ucs2DataSize),
  13683. hexToStr(charCode, dataSize));
  13684. }
  13685. break;
  13686. default:
  13687. error('Unknown type: ' + type);
  13688. break;
  13689. }
  13690. }
  13691. if (useCMap) {
  13692. extend(useCMap);
  13693. }
  13694. return cMap;
  13695. }
  13696. function BinaryCMapReader() {}
  13697. BinaryCMapReader.prototype = {
  13698. read: processBinaryCMap
  13699. };
  13700. return BinaryCMapReader;
  13701. })();
  13702. var CMapFactory = (function CMapFactoryClosure() {
  13703. function strToInt(str) {
  13704. var a = 0;
  13705. for (var i = 0; i < str.length; i++) {
  13706. a = (a << 8) | str.charCodeAt(i);
  13707. }
  13708. return a >>> 0;
  13709. }
  13710. function expectString(obj) {
  13711. if (!isString(obj)) {
  13712. error('Malformed CMap: expected string.');
  13713. }
  13714. }
  13715. function expectInt(obj) {
  13716. if (!isInt(obj)) {
  13717. error('Malformed CMap: expected int.');
  13718. }
  13719. }
  13720. function parseBfChar(cMap, lexer) {
  13721. while (true) {
  13722. var obj = lexer.getObj();
  13723. if (isEOF(obj)) {
  13724. break;
  13725. }
  13726. if (isCmd(obj, 'endbfchar')) {
  13727. return;
  13728. }
  13729. expectString(obj);
  13730. var src = strToInt(obj);
  13731. obj = lexer.getObj();
  13732. // TODO are /dstName used?
  13733. expectString(obj);
  13734. var dst = obj;
  13735. cMap.mapOne(src, dst);
  13736. }
  13737. }
  13738. function parseBfRange(cMap, lexer) {
  13739. while (true) {
  13740. var obj = lexer.getObj();
  13741. if (isEOF(obj)) {
  13742. break;
  13743. }
  13744. if (isCmd(obj, 'endbfrange')) {
  13745. return;
  13746. }
  13747. expectString(obj);
  13748. var low = strToInt(obj);
  13749. obj = lexer.getObj();
  13750. expectString(obj);
  13751. var high = strToInt(obj);
  13752. obj = lexer.getObj();
  13753. if (isInt(obj) || isString(obj)) {
  13754. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  13755. cMap.mapBfRange(low, high, dstLow);
  13756. } else if (isCmd(obj, '[')) {
  13757. obj = lexer.getObj();
  13758. var array = [];
  13759. while (!isCmd(obj, ']') && !isEOF(obj)) {
  13760. array.push(obj);
  13761. obj = lexer.getObj();
  13762. }
  13763. cMap.mapBfRangeToArray(low, high, array);
  13764. } else {
  13765. break;
  13766. }
  13767. }
  13768. error('Invalid bf range.');
  13769. }
  13770. function parseCidChar(cMap, lexer) {
  13771. while (true) {
  13772. var obj = lexer.getObj();
  13773. if (isEOF(obj)) {
  13774. break;
  13775. }
  13776. if (isCmd(obj, 'endcidchar')) {
  13777. return;
  13778. }
  13779. expectString(obj);
  13780. var src = strToInt(obj);
  13781. obj = lexer.getObj();
  13782. expectInt(obj);
  13783. var dst = obj;
  13784. cMap.mapOne(src, dst);
  13785. }
  13786. }
  13787. function parseCidRange(cMap, lexer) {
  13788. while (true) {
  13789. var obj = lexer.getObj();
  13790. if (isEOF(obj)) {
  13791. break;
  13792. }
  13793. if (isCmd(obj, 'endcidrange')) {
  13794. return;
  13795. }
  13796. expectString(obj);
  13797. var low = strToInt(obj);
  13798. obj = lexer.getObj();
  13799. expectString(obj);
  13800. var high = strToInt(obj);
  13801. obj = lexer.getObj();
  13802. expectInt(obj);
  13803. var dstLow = obj;
  13804. cMap.mapCidRange(low, high, dstLow);
  13805. }
  13806. }
  13807. function parseCodespaceRange(cMap, lexer) {
  13808. while (true) {
  13809. var obj = lexer.getObj();
  13810. if (isEOF(obj)) {
  13811. break;
  13812. }
  13813. if (isCmd(obj, 'endcodespacerange')) {
  13814. return;
  13815. }
  13816. if (!isString(obj)) {
  13817. break;
  13818. }
  13819. var low = strToInt(obj);
  13820. obj = lexer.getObj();
  13821. if (!isString(obj)) {
  13822. break;
  13823. }
  13824. var high = strToInt(obj);
  13825. cMap.addCodespaceRange(obj.length, low, high);
  13826. }
  13827. error('Invalid codespace range.');
  13828. }
  13829. function parseWMode(cMap, lexer) {
  13830. var obj = lexer.getObj();
  13831. if (isInt(obj)) {
  13832. cMap.vertical = !!obj;
  13833. }
  13834. }
  13835. function parseCMapName(cMap, lexer) {
  13836. var obj = lexer.getObj();
  13837. if (isName(obj) && isString(obj.name)) {
  13838. cMap.name = obj.name;
  13839. }
  13840. }
  13841. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  13842. var previous;
  13843. var embededUseCMap;
  13844. objLoop: while (true) {
  13845. var obj = lexer.getObj();
  13846. if (isEOF(obj)) {
  13847. break;
  13848. } else if (isName(obj)) {
  13849. if (obj.name === 'WMode') {
  13850. parseWMode(cMap, lexer);
  13851. } else if (obj.name === 'CMapName') {
  13852. parseCMapName(cMap, lexer);
  13853. }
  13854. previous = obj;
  13855. } else if (isCmd(obj)) {
  13856. switch (obj.cmd) {
  13857. case 'endcmap':
  13858. break objLoop;
  13859. case 'usecmap':
  13860. if (isName(previous)) {
  13861. embededUseCMap = previous.name;
  13862. }
  13863. break;
  13864. case 'begincodespacerange':
  13865. parseCodespaceRange(cMap, lexer);
  13866. break;
  13867. case 'beginbfchar':
  13868. parseBfChar(cMap, lexer);
  13869. break;
  13870. case 'begincidchar':
  13871. parseCidChar(cMap, lexer);
  13872. break;
  13873. case 'beginbfrange':
  13874. parseBfRange(cMap, lexer);
  13875. break;
  13876. case 'begincidrange':
  13877. parseCidRange(cMap, lexer);
  13878. break;
  13879. }
  13880. }
  13881. }
  13882. if (!useCMap && embededUseCMap) {
  13883. // Load the usecmap definition from the file only if there wasn't one
  13884. // specified.
  13885. useCMap = embededUseCMap;
  13886. }
  13887. if (useCMap) {
  13888. extendCMap(cMap, builtInCMapParams, useCMap);
  13889. }
  13890. }
  13891. function extendCMap(cMap, builtInCMapParams, useCMap) {
  13892. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  13893. // If there aren't any code space ranges defined clone all the parent ones
  13894. // into this cMap.
  13895. if (cMap.numCodespaceRanges === 0) {
  13896. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  13897. for (var i = 0; i < useCodespaceRanges.length; i++) {
  13898. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  13899. }
  13900. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  13901. }
  13902. // Merge the map into the current one, making sure not to override
  13903. // any previously defined entries.
  13904. cMap.useCMap.forEach(function(key, value) {
  13905. if (!cMap.contains(key)) {
  13906. cMap.mapOne(key, cMap.useCMap.lookup(key));
  13907. }
  13908. });
  13909. }
  13910. function parseBinaryCMap(name, builtInCMapParams) {
  13911. var url = builtInCMapParams.url + name + '.bcmap';
  13912. var cMap = new CMap(true);
  13913. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  13914. extendCMap(cMap, builtInCMapParams, useCMap);
  13915. });
  13916. return cMap;
  13917. }
  13918. function createBuiltInCMap(name, builtInCMapParams) {
  13919. if (name === 'Identity-H') {
  13920. return new IdentityCMap(false, 2);
  13921. } else if (name === 'Identity-V') {
  13922. return new IdentityCMap(true, 2);
  13923. }
  13924. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  13925. error('Unknown cMap name: ' + name);
  13926. }
  13927. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  13928. if (builtInCMapParams.packed) {
  13929. return parseBinaryCMap(name, builtInCMapParams);
  13930. }
  13931. var request = new XMLHttpRequest();
  13932. var url = builtInCMapParams.url + name;
  13933. request.open('GET', url, false);
  13934. request.send(null);
  13935. if (!request.responseText) {
  13936. error('Unable to get cMap at: ' + url);
  13937. }
  13938. var cMap = new CMap(true);
  13939. var lexer = new Lexer(new StringStream(request.responseText));
  13940. parseCMap(cMap, lexer, builtInCMapParams, null);
  13941. return cMap;
  13942. }
  13943. return {
  13944. create: function (encoding, builtInCMapParams, useCMap) {
  13945. if (isName(encoding)) {
  13946. return createBuiltInCMap(encoding.name, builtInCMapParams);
  13947. } else if (isStream(encoding)) {
  13948. var cMap = new CMap();
  13949. var lexer = new Lexer(encoding);
  13950. try {
  13951. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  13952. } catch (e) {
  13953. warn('Invalid CMap data. ' + e);
  13954. }
  13955. if (cMap.isIdentityCMap) {
  13956. return createBuiltInCMap(cMap.name, builtInCMapParams);
  13957. }
  13958. return cMap;
  13959. }
  13960. error('Encoding required.');
  13961. }
  13962. };
  13963. })();
  13964. // Unicode Private Use Area
  13965. var PRIVATE_USE_OFFSET_START = 0xE000;
  13966. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  13967. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  13968. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  13969. // except for Type 3 fonts
  13970. var PDF_GLYPH_SPACE_UNITS = 1000;
  13971. // Hinting is currently disabled due to unknown problems on windows
  13972. // in tracemonkey and various other pdfs with type1 fonts.
  13973. var HINTING_ENABLED = false;
  13974. // Accented charactars are not displayed properly on windows, using this flag
  13975. // to control analysis of seac charstrings.
  13976. var SEAC_ANALYSIS_ENABLED = false;
  13977. var FontFlags = {
  13978. FixedPitch: 1,
  13979. Serif: 2,
  13980. Symbolic: 4,
  13981. Script: 8,
  13982. Nonsymbolic: 32,
  13983. Italic: 64,
  13984. AllCap: 65536,
  13985. SmallCap: 131072,
  13986. ForceBold: 262144
  13987. };
  13988. var Encodings = {
  13989. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13990. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13991. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  13992. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  13993. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  13994. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  13995. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  13996. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  13997. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  13998. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  13999. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  14000. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  14001. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  14002. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  14003. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  14004. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  14005. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  14006. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  14007. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  14008. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14009. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  14010. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  14011. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  14012. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  14013. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  14014. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  14015. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  14016. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  14017. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  14018. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  14019. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  14020. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  14021. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  14022. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  14023. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  14024. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  14025. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  14026. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  14027. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  14028. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  14029. 'Ydieresissmall'],
  14030. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14031. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14032. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  14033. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  14034. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  14035. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  14036. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  14037. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  14038. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  14039. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  14040. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  14041. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  14042. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  14043. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  14044. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  14045. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  14046. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  14047. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  14048. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  14049. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  14050. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  14051. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  14052. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  14053. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  14054. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  14055. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  14056. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  14057. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  14058. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  14059. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  14060. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  14061. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  14062. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  14063. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  14064. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  14065. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  14066. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  14067. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  14068. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  14069. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  14070. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14071. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14072. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  14073. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  14074. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  14075. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  14076. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  14077. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  14078. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  14079. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  14080. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  14081. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  14082. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  14083. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  14084. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  14085. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  14086. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  14087. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  14088. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  14089. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  14090. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  14091. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  14092. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  14093. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  14094. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  14095. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  14096. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  14097. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  14098. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  14099. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  14100. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  14101. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  14102. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  14103. 'ogonek', 'caron'],
  14104. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14105. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14106. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  14107. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  14108. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  14109. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  14110. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  14111. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  14112. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  14113. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  14114. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  14115. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  14116. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14117. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  14118. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  14119. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  14120. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  14121. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  14122. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  14123. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  14124. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  14125. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  14126. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  14127. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  14128. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  14129. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14130. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14131. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  14132. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  14133. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  14134. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  14135. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  14136. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  14137. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  14138. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  14139. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  14140. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  14141. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  14142. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  14143. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  14144. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  14145. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  14146. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  14147. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  14148. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  14149. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  14150. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  14151. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  14152. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  14153. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  14154. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  14155. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  14156. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  14157. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  14158. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  14159. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  14160. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  14161. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  14162. 'ydieresis'],
  14163. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14164. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14165. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  14166. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  14167. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  14168. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  14169. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  14170. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  14171. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  14172. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  14173. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  14174. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  14175. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  14176. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  14177. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  14178. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14179. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  14180. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  14181. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  14182. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  14183. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  14184. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  14185. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  14186. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  14187. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  14188. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  14189. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  14190. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  14191. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  14192. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  14193. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  14194. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  14195. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  14196. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  14197. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  14198. 'bracerightbt'],
  14199. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14200. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  14201. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  14202. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  14203. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  14204. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  14205. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  14206. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  14207. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  14208. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  14209. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  14210. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  14211. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  14212. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  14213. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  14214. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  14215. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  14216. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  14217. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  14218. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  14219. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  14220. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  14221. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  14222. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  14223. };
  14224. /**
  14225. * Hold a map of decoded fonts and of the standard fourteen Type1
  14226. * fonts and their acronyms.
  14227. */
  14228. var stdFontMap = {
  14229. 'ArialNarrow': 'Helvetica',
  14230. 'ArialNarrow-Bold': 'Helvetica-Bold',
  14231. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  14232. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  14233. 'ArialBlack': 'Helvetica',
  14234. 'ArialBlack-Bold': 'Helvetica-Bold',
  14235. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  14236. 'ArialBlack-Italic': 'Helvetica-Oblique',
  14237. 'Arial': 'Helvetica',
  14238. 'Arial-Bold': 'Helvetica-Bold',
  14239. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  14240. 'Arial-Italic': 'Helvetica-Oblique',
  14241. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  14242. 'Arial-BoldMT': 'Helvetica-Bold',
  14243. 'Arial-ItalicMT': 'Helvetica-Oblique',
  14244. 'ArialMT': 'Helvetica',
  14245. 'Courier-Bold': 'Courier-Bold',
  14246. 'Courier-BoldItalic': 'Courier-BoldOblique',
  14247. 'Courier-Italic': 'Courier-Oblique',
  14248. 'CourierNew': 'Courier',
  14249. 'CourierNew-Bold': 'Courier-Bold',
  14250. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  14251. 'CourierNew-Italic': 'Courier-Oblique',
  14252. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  14253. 'CourierNewPS-BoldMT': 'Courier-Bold',
  14254. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  14255. 'CourierNewPSMT': 'Courier',
  14256. 'Helvetica': 'Helvetica',
  14257. 'Helvetica-Bold': 'Helvetica-Bold',
  14258. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  14259. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  14260. 'Helvetica-Italic': 'Helvetica-Oblique',
  14261. 'Helvetica-Oblique':'Helvetica-Oblique',
  14262. 'Symbol-Bold': 'Symbol',
  14263. 'Symbol-BoldItalic': 'Symbol',
  14264. 'Symbol-Italic': 'Symbol',
  14265. 'TimesNewRoman': 'Times-Roman',
  14266. 'TimesNewRoman-Bold': 'Times-Bold',
  14267. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  14268. 'TimesNewRoman-Italic': 'Times-Italic',
  14269. 'TimesNewRomanPS': 'Times-Roman',
  14270. 'TimesNewRomanPS-Bold': 'Times-Bold',
  14271. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  14272. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  14273. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  14274. 'TimesNewRomanPS-Italic': 'Times-Italic',
  14275. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  14276. 'TimesNewRomanPSMT': 'Times-Roman',
  14277. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  14278. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  14279. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  14280. };
  14281. /**
  14282. * Holds the map of the non-standard fonts that might be included as a standard
  14283. * fonts without glyph data.
  14284. */
  14285. var nonStdFontMap = {
  14286. 'CenturyGothic': 'Helvetica',
  14287. 'CenturyGothic-Bold': 'Helvetica-Bold',
  14288. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  14289. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  14290. 'ComicSansMS': 'Comic Sans MS',
  14291. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  14292. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  14293. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  14294. 'LucidaConsole': 'Courier',
  14295. 'LucidaConsole-Bold': 'Courier-Bold',
  14296. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  14297. 'LucidaConsole-Italic': 'Courier-Oblique',
  14298. 'MS-Gothic': 'MS Gothic',
  14299. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  14300. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  14301. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  14302. 'MS-Mincho': 'MS Mincho',
  14303. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  14304. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  14305. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  14306. 'MS-PGothic': 'MS PGothic',
  14307. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  14308. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  14309. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  14310. 'MS-PMincho': 'MS PMincho',
  14311. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  14312. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  14313. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  14314. 'Wingdings': 'ZapfDingbats'
  14315. };
  14316. var serifFonts = {
  14317. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  14318. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  14319. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  14320. 'Arno': true, 'Aster': true, 'Aurora': true,
  14321. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  14322. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  14323. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  14324. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  14325. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  14326. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  14327. 'Cartier': true, 'Caslon': true, 'Catull': true,
  14328. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  14329. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  14330. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  14331. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  14332. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  14333. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  14334. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  14335. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  14336. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  14337. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  14338. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  14339. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  14340. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  14341. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  14342. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  14343. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  14344. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  14345. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  14346. 'Miller': true, 'Minion': true, 'Modern': true,
  14347. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  14348. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  14349. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  14350. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  14351. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  14352. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  14353. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  14354. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  14355. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  14356. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  14357. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  14358. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  14359. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  14360. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  14361. };
  14362. var symbolsFonts = {
  14363. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  14364. };
  14365. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  14366. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  14367. // glyphs, but common for some set of the standard fonts.
  14368. var GlyphMapForStandardFonts = {
  14369. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  14370. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  14371. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  14372. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  14373. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  14374. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  14375. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  14376. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  14377. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  14378. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  14379. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  14380. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  14381. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  14382. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  14383. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  14384. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  14385. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  14386. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  14387. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  14388. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  14389. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  14390. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  14391. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  14392. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  14393. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  14394. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  14395. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  14396. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  14397. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  14398. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  14399. '298': 380, '305': 963,
  14400. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  14401. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  14402. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  14403. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  14404. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  14405. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  14406. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  14407. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  14408. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  14409. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  14410. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  14411. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  14412. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  14413. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  14414. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  14415. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  14416. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  14417. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  14418. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  14419. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  14420. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  14421. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  14422. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  14423. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  14424. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  14425. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  14426. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  14427. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  14428. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  14429. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  14430. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  14431. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  14432. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  14433. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  14434. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  14435. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  14436. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  14437. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  14438. };
  14439. // The glyph map for ArialBlack differs slightly from the glyph map used for
  14440. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  14441. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  14442. var SupplementalGlyphMapForArialBlack = {
  14443. '227': 322, '264': 261, '291': 346,
  14444. };
  14445. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  14446. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  14447. // to the similar equivalents in the normal characters range.
  14448. var SpecialPUASymbols = {
  14449. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  14450. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  14451. '63720': 0x00AE, // registersans (0xF8E8) => registered
  14452. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  14453. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  14454. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  14455. '63729': 0x23A7, // bracelefttp (0xF8F1)
  14456. '63730': 0x23A8, // braceleftmid (0xF8F2)
  14457. '63731': 0x23A9, // braceleftbt (0xF8F3)
  14458. '63740': 0x23AB, // bracerighttp (0xF8FC)
  14459. '63741': 0x23AC, // bracerightmid (0xF8FD)
  14460. '63742': 0x23AD, // bracerightbt (0xF8FE)
  14461. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  14462. '63727': 0x23A2, // bracketleftex (0xF8EF)
  14463. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  14464. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  14465. '63738': 0x23A5, // bracketrightex (0xF8FA)
  14466. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  14467. '63723': 0x239B, // parenlefttp (0xF8EB)
  14468. '63724': 0x239C, // parenleftex (0xF8EC)
  14469. '63725': 0x239D, // parenleftbt (0xF8ED)
  14470. '63734': 0x239E, // parenrighttp (0xF8F6)
  14471. '63735': 0x239F, // parenrightex (0xF8F7)
  14472. '63736': 0x23A0, // parenrightbt (0xF8F8)
  14473. };
  14474. function mapSpecialUnicodeValues(code) {
  14475. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  14476. return 0;
  14477. } else if (code >= 0xF600 && code <= 0xF8FF) {
  14478. return (SpecialPUASymbols[code] || code);
  14479. }
  14480. return code;
  14481. }
  14482. var UnicodeRanges = [
  14483. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  14484. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  14485. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  14486. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  14487. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  14488. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  14489. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  14490. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  14491. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  14492. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  14493. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  14494. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  14495. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  14496. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  14497. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  14498. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  14499. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  14500. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  14501. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  14502. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  14503. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  14504. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  14505. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  14506. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  14507. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  14508. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  14509. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  14510. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  14511. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  14512. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  14513. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  14514. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  14515. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  14516. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  14517. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  14518. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  14519. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  14520. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  14521. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  14522. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  14523. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  14524. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  14525. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  14526. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  14527. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  14528. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  14529. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  14530. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  14531. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  14532. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  14533. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  14534. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  14535. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  14536. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  14537. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  14538. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  14539. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  14540. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  14541. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  14542. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  14543. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  14544. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  14545. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  14546. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  14547. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  14548. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  14549. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  14550. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  14551. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  14552. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  14553. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  14554. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  14555. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  14556. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  14557. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  14558. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  14559. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  14560. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  14561. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  14562. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  14563. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  14564. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  14565. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  14566. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  14567. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  14568. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  14569. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  14570. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  14571. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  14572. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  14573. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  14574. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  14575. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  14576. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  14577. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  14578. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  14579. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  14580. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  14581. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  14582. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  14583. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  14584. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  14585. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  14586. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  14587. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  14588. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  14589. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  14590. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  14591. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  14592. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  14593. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  14594. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  14595. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  14596. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  14597. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  14598. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  14599. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  14600. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  14601. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  14602. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  14603. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  14604. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  14605. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  14606. ];
  14607. var MacStandardGlyphOrdering = [
  14608. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  14609. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  14610. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  14611. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  14612. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  14613. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  14614. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  14615. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  14616. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  14617. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  14618. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  14619. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  14620. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  14621. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  14622. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  14623. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  14624. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  14625. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  14626. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  14627. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  14628. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  14629. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  14630. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  14631. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  14632. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  14633. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  14634. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  14635. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  14636. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  14637. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  14638. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  14639. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  14640. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  14641. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  14642. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  14643. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  14644. function getUnicodeRangeFor(value) {
  14645. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  14646. var range = UnicodeRanges[i];
  14647. if (value >= range.begin && value < range.end) {
  14648. return i;
  14649. }
  14650. }
  14651. return -1;
  14652. }
  14653. function isRTLRangeFor(value) {
  14654. var range = UnicodeRanges[13];
  14655. if (value >= range.begin && value < range.end) {
  14656. return true;
  14657. }
  14658. range = UnicodeRanges[11];
  14659. if (value >= range.begin && value < range.end) {
  14660. return true;
  14661. }
  14662. return false;
  14663. }
  14664. // The normalization table is obtained by filtering the Unicode characters
  14665. // database with <compat> entries.
  14666. var NormalizedUnicodes = {
  14667. '\u00A8': '\u0020\u0308',
  14668. '\u00AF': '\u0020\u0304',
  14669. '\u00B4': '\u0020\u0301',
  14670. '\u00B5': '\u03BC',
  14671. '\u00B8': '\u0020\u0327',
  14672. '\u0132': '\u0049\u004A',
  14673. '\u0133': '\u0069\u006A',
  14674. '\u013F': '\u004C\u00B7',
  14675. '\u0140': '\u006C\u00B7',
  14676. '\u0149': '\u02BC\u006E',
  14677. '\u017F': '\u0073',
  14678. '\u01C4': '\u0044\u017D',
  14679. '\u01C5': '\u0044\u017E',
  14680. '\u01C6': '\u0064\u017E',
  14681. '\u01C7': '\u004C\u004A',
  14682. '\u01C8': '\u004C\u006A',
  14683. '\u01C9': '\u006C\u006A',
  14684. '\u01CA': '\u004E\u004A',
  14685. '\u01CB': '\u004E\u006A',
  14686. '\u01CC': '\u006E\u006A',
  14687. '\u01F1': '\u0044\u005A',
  14688. '\u01F2': '\u0044\u007A',
  14689. '\u01F3': '\u0064\u007A',
  14690. '\u02D8': '\u0020\u0306',
  14691. '\u02D9': '\u0020\u0307',
  14692. '\u02DA': '\u0020\u030A',
  14693. '\u02DB': '\u0020\u0328',
  14694. '\u02DC': '\u0020\u0303',
  14695. '\u02DD': '\u0020\u030B',
  14696. '\u037A': '\u0020\u0345',
  14697. '\u0384': '\u0020\u0301',
  14698. '\u03D0': '\u03B2',
  14699. '\u03D1': '\u03B8',
  14700. '\u03D2': '\u03A5',
  14701. '\u03D5': '\u03C6',
  14702. '\u03D6': '\u03C0',
  14703. '\u03F0': '\u03BA',
  14704. '\u03F1': '\u03C1',
  14705. '\u03F2': '\u03C2',
  14706. '\u03F4': '\u0398',
  14707. '\u03F5': '\u03B5',
  14708. '\u03F9': '\u03A3',
  14709. '\u0587': '\u0565\u0582',
  14710. '\u0675': '\u0627\u0674',
  14711. '\u0676': '\u0648\u0674',
  14712. '\u0677': '\u06C7\u0674',
  14713. '\u0678': '\u064A\u0674',
  14714. '\u0E33': '\u0E4D\u0E32',
  14715. '\u0EB3': '\u0ECD\u0EB2',
  14716. '\u0EDC': '\u0EAB\u0E99',
  14717. '\u0EDD': '\u0EAB\u0EA1',
  14718. '\u0F77': '\u0FB2\u0F81',
  14719. '\u0F79': '\u0FB3\u0F81',
  14720. '\u1E9A': '\u0061\u02BE',
  14721. '\u1FBD': '\u0020\u0313',
  14722. '\u1FBF': '\u0020\u0313',
  14723. '\u1FC0': '\u0020\u0342',
  14724. '\u1FFE': '\u0020\u0314',
  14725. '\u2002': '\u0020',
  14726. '\u2003': '\u0020',
  14727. '\u2004': '\u0020',
  14728. '\u2005': '\u0020',
  14729. '\u2006': '\u0020',
  14730. '\u2008': '\u0020',
  14731. '\u2009': '\u0020',
  14732. '\u200A': '\u0020',
  14733. '\u2017': '\u0020\u0333',
  14734. '\u2024': '\u002E',
  14735. '\u2025': '\u002E\u002E',
  14736. '\u2026': '\u002E\u002E\u002E',
  14737. '\u2033': '\u2032\u2032',
  14738. '\u2034': '\u2032\u2032\u2032',
  14739. '\u2036': '\u2035\u2035',
  14740. '\u2037': '\u2035\u2035\u2035',
  14741. '\u203C': '\u0021\u0021',
  14742. '\u203E': '\u0020\u0305',
  14743. '\u2047': '\u003F\u003F',
  14744. '\u2048': '\u003F\u0021',
  14745. '\u2049': '\u0021\u003F',
  14746. '\u2057': '\u2032\u2032\u2032\u2032',
  14747. '\u205F': '\u0020',
  14748. '\u20A8': '\u0052\u0073',
  14749. '\u2100': '\u0061\u002F\u0063',
  14750. '\u2101': '\u0061\u002F\u0073',
  14751. '\u2103': '\u00B0\u0043',
  14752. '\u2105': '\u0063\u002F\u006F',
  14753. '\u2106': '\u0063\u002F\u0075',
  14754. '\u2107': '\u0190',
  14755. '\u2109': '\u00B0\u0046',
  14756. '\u2116': '\u004E\u006F',
  14757. '\u2121': '\u0054\u0045\u004C',
  14758. '\u2135': '\u05D0',
  14759. '\u2136': '\u05D1',
  14760. '\u2137': '\u05D2',
  14761. '\u2138': '\u05D3',
  14762. '\u213B': '\u0046\u0041\u0058',
  14763. '\u2160': '\u0049',
  14764. '\u2161': '\u0049\u0049',
  14765. '\u2162': '\u0049\u0049\u0049',
  14766. '\u2163': '\u0049\u0056',
  14767. '\u2164': '\u0056',
  14768. '\u2165': '\u0056\u0049',
  14769. '\u2166': '\u0056\u0049\u0049',
  14770. '\u2167': '\u0056\u0049\u0049\u0049',
  14771. '\u2168': '\u0049\u0058',
  14772. '\u2169': '\u0058',
  14773. '\u216A': '\u0058\u0049',
  14774. '\u216B': '\u0058\u0049\u0049',
  14775. '\u216C': '\u004C',
  14776. '\u216D': '\u0043',
  14777. '\u216E': '\u0044',
  14778. '\u216F': '\u004D',
  14779. '\u2170': '\u0069',
  14780. '\u2171': '\u0069\u0069',
  14781. '\u2172': '\u0069\u0069\u0069',
  14782. '\u2173': '\u0069\u0076',
  14783. '\u2174': '\u0076',
  14784. '\u2175': '\u0076\u0069',
  14785. '\u2176': '\u0076\u0069\u0069',
  14786. '\u2177': '\u0076\u0069\u0069\u0069',
  14787. '\u2178': '\u0069\u0078',
  14788. '\u2179': '\u0078',
  14789. '\u217A': '\u0078\u0069',
  14790. '\u217B': '\u0078\u0069\u0069',
  14791. '\u217C': '\u006C',
  14792. '\u217D': '\u0063',
  14793. '\u217E': '\u0064',
  14794. '\u217F': '\u006D',
  14795. '\u222C': '\u222B\u222B',
  14796. '\u222D': '\u222B\u222B\u222B',
  14797. '\u222F': '\u222E\u222E',
  14798. '\u2230': '\u222E\u222E\u222E',
  14799. '\u2474': '\u0028\u0031\u0029',
  14800. '\u2475': '\u0028\u0032\u0029',
  14801. '\u2476': '\u0028\u0033\u0029',
  14802. '\u2477': '\u0028\u0034\u0029',
  14803. '\u2478': '\u0028\u0035\u0029',
  14804. '\u2479': '\u0028\u0036\u0029',
  14805. '\u247A': '\u0028\u0037\u0029',
  14806. '\u247B': '\u0028\u0038\u0029',
  14807. '\u247C': '\u0028\u0039\u0029',
  14808. '\u247D': '\u0028\u0031\u0030\u0029',
  14809. '\u247E': '\u0028\u0031\u0031\u0029',
  14810. '\u247F': '\u0028\u0031\u0032\u0029',
  14811. '\u2480': '\u0028\u0031\u0033\u0029',
  14812. '\u2481': '\u0028\u0031\u0034\u0029',
  14813. '\u2482': '\u0028\u0031\u0035\u0029',
  14814. '\u2483': '\u0028\u0031\u0036\u0029',
  14815. '\u2484': '\u0028\u0031\u0037\u0029',
  14816. '\u2485': '\u0028\u0031\u0038\u0029',
  14817. '\u2486': '\u0028\u0031\u0039\u0029',
  14818. '\u2487': '\u0028\u0032\u0030\u0029',
  14819. '\u2488': '\u0031\u002E',
  14820. '\u2489': '\u0032\u002E',
  14821. '\u248A': '\u0033\u002E',
  14822. '\u248B': '\u0034\u002E',
  14823. '\u248C': '\u0035\u002E',
  14824. '\u248D': '\u0036\u002E',
  14825. '\u248E': '\u0037\u002E',
  14826. '\u248F': '\u0038\u002E',
  14827. '\u2490': '\u0039\u002E',
  14828. '\u2491': '\u0031\u0030\u002E',
  14829. '\u2492': '\u0031\u0031\u002E',
  14830. '\u2493': '\u0031\u0032\u002E',
  14831. '\u2494': '\u0031\u0033\u002E',
  14832. '\u2495': '\u0031\u0034\u002E',
  14833. '\u2496': '\u0031\u0035\u002E',
  14834. '\u2497': '\u0031\u0036\u002E',
  14835. '\u2498': '\u0031\u0037\u002E',
  14836. '\u2499': '\u0031\u0038\u002E',
  14837. '\u249A': '\u0031\u0039\u002E',
  14838. '\u249B': '\u0032\u0030\u002E',
  14839. '\u249C': '\u0028\u0061\u0029',
  14840. '\u249D': '\u0028\u0062\u0029',
  14841. '\u249E': '\u0028\u0063\u0029',
  14842. '\u249F': '\u0028\u0064\u0029',
  14843. '\u24A0': '\u0028\u0065\u0029',
  14844. '\u24A1': '\u0028\u0066\u0029',
  14845. '\u24A2': '\u0028\u0067\u0029',
  14846. '\u24A3': '\u0028\u0068\u0029',
  14847. '\u24A4': '\u0028\u0069\u0029',
  14848. '\u24A5': '\u0028\u006A\u0029',
  14849. '\u24A6': '\u0028\u006B\u0029',
  14850. '\u24A7': '\u0028\u006C\u0029',
  14851. '\u24A8': '\u0028\u006D\u0029',
  14852. '\u24A9': '\u0028\u006E\u0029',
  14853. '\u24AA': '\u0028\u006F\u0029',
  14854. '\u24AB': '\u0028\u0070\u0029',
  14855. '\u24AC': '\u0028\u0071\u0029',
  14856. '\u24AD': '\u0028\u0072\u0029',
  14857. '\u24AE': '\u0028\u0073\u0029',
  14858. '\u24AF': '\u0028\u0074\u0029',
  14859. '\u24B0': '\u0028\u0075\u0029',
  14860. '\u24B1': '\u0028\u0076\u0029',
  14861. '\u24B2': '\u0028\u0077\u0029',
  14862. '\u24B3': '\u0028\u0078\u0029',
  14863. '\u24B4': '\u0028\u0079\u0029',
  14864. '\u24B5': '\u0028\u007A\u0029',
  14865. '\u2A0C': '\u222B\u222B\u222B\u222B',
  14866. '\u2A74': '\u003A\u003A\u003D',
  14867. '\u2A75': '\u003D\u003D',
  14868. '\u2A76': '\u003D\u003D\u003D',
  14869. '\u2E9F': '\u6BCD',
  14870. '\u2EF3': '\u9F9F',
  14871. '\u2F00': '\u4E00',
  14872. '\u2F01': '\u4E28',
  14873. '\u2F02': '\u4E36',
  14874. '\u2F03': '\u4E3F',
  14875. '\u2F04': '\u4E59',
  14876. '\u2F05': '\u4E85',
  14877. '\u2F06': '\u4E8C',
  14878. '\u2F07': '\u4EA0',
  14879. '\u2F08': '\u4EBA',
  14880. '\u2F09': '\u513F',
  14881. '\u2F0A': '\u5165',
  14882. '\u2F0B': '\u516B',
  14883. '\u2F0C': '\u5182',
  14884. '\u2F0D': '\u5196',
  14885. '\u2F0E': '\u51AB',
  14886. '\u2F0F': '\u51E0',
  14887. '\u2F10': '\u51F5',
  14888. '\u2F11': '\u5200',
  14889. '\u2F12': '\u529B',
  14890. '\u2F13': '\u52F9',
  14891. '\u2F14': '\u5315',
  14892. '\u2F15': '\u531A',
  14893. '\u2F16': '\u5338',
  14894. '\u2F17': '\u5341',
  14895. '\u2F18': '\u535C',
  14896. '\u2F19': '\u5369',
  14897. '\u2F1A': '\u5382',
  14898. '\u2F1B': '\u53B6',
  14899. '\u2F1C': '\u53C8',
  14900. '\u2F1D': '\u53E3',
  14901. '\u2F1E': '\u56D7',
  14902. '\u2F1F': '\u571F',
  14903. '\u2F20': '\u58EB',
  14904. '\u2F21': '\u5902',
  14905. '\u2F22': '\u590A',
  14906. '\u2F23': '\u5915',
  14907. '\u2F24': '\u5927',
  14908. '\u2F25': '\u5973',
  14909. '\u2F26': '\u5B50',
  14910. '\u2F27': '\u5B80',
  14911. '\u2F28': '\u5BF8',
  14912. '\u2F29': '\u5C0F',
  14913. '\u2F2A': '\u5C22',
  14914. '\u2F2B': '\u5C38',
  14915. '\u2F2C': '\u5C6E',
  14916. '\u2F2D': '\u5C71',
  14917. '\u2F2E': '\u5DDB',
  14918. '\u2F2F': '\u5DE5',
  14919. '\u2F30': '\u5DF1',
  14920. '\u2F31': '\u5DFE',
  14921. '\u2F32': '\u5E72',
  14922. '\u2F33': '\u5E7A',
  14923. '\u2F34': '\u5E7F',
  14924. '\u2F35': '\u5EF4',
  14925. '\u2F36': '\u5EFE',
  14926. '\u2F37': '\u5F0B',
  14927. '\u2F38': '\u5F13',
  14928. '\u2F39': '\u5F50',
  14929. '\u2F3A': '\u5F61',
  14930. '\u2F3B': '\u5F73',
  14931. '\u2F3C': '\u5FC3',
  14932. '\u2F3D': '\u6208',
  14933. '\u2F3E': '\u6236',
  14934. '\u2F3F': '\u624B',
  14935. '\u2F40': '\u652F',
  14936. '\u2F41': '\u6534',
  14937. '\u2F42': '\u6587',
  14938. '\u2F43': '\u6597',
  14939. '\u2F44': '\u65A4',
  14940. '\u2F45': '\u65B9',
  14941. '\u2F46': '\u65E0',
  14942. '\u2F47': '\u65E5',
  14943. '\u2F48': '\u66F0',
  14944. '\u2F49': '\u6708',
  14945. '\u2F4A': '\u6728',
  14946. '\u2F4B': '\u6B20',
  14947. '\u2F4C': '\u6B62',
  14948. '\u2F4D': '\u6B79',
  14949. '\u2F4E': '\u6BB3',
  14950. '\u2F4F': '\u6BCB',
  14951. '\u2F50': '\u6BD4',
  14952. '\u2F51': '\u6BDB',
  14953. '\u2F52': '\u6C0F',
  14954. '\u2F53': '\u6C14',
  14955. '\u2F54': '\u6C34',
  14956. '\u2F55': '\u706B',
  14957. '\u2F56': '\u722A',
  14958. '\u2F57': '\u7236',
  14959. '\u2F58': '\u723B',
  14960. '\u2F59': '\u723F',
  14961. '\u2F5A': '\u7247',
  14962. '\u2F5B': '\u7259',
  14963. '\u2F5C': '\u725B',
  14964. '\u2F5D': '\u72AC',
  14965. '\u2F5E': '\u7384',
  14966. '\u2F5F': '\u7389',
  14967. '\u2F60': '\u74DC',
  14968. '\u2F61': '\u74E6',
  14969. '\u2F62': '\u7518',
  14970. '\u2F63': '\u751F',
  14971. '\u2F64': '\u7528',
  14972. '\u2F65': '\u7530',
  14973. '\u2F66': '\u758B',
  14974. '\u2F67': '\u7592',
  14975. '\u2F68': '\u7676',
  14976. '\u2F69': '\u767D',
  14977. '\u2F6A': '\u76AE',
  14978. '\u2F6B': '\u76BF',
  14979. '\u2F6C': '\u76EE',
  14980. '\u2F6D': '\u77DB',
  14981. '\u2F6E': '\u77E2',
  14982. '\u2F6F': '\u77F3',
  14983. '\u2F70': '\u793A',
  14984. '\u2F71': '\u79B8',
  14985. '\u2F72': '\u79BE',
  14986. '\u2F73': '\u7A74',
  14987. '\u2F74': '\u7ACB',
  14988. '\u2F75': '\u7AF9',
  14989. '\u2F76': '\u7C73',
  14990. '\u2F77': '\u7CF8',
  14991. '\u2F78': '\u7F36',
  14992. '\u2F79': '\u7F51',
  14993. '\u2F7A': '\u7F8A',
  14994. '\u2F7B': '\u7FBD',
  14995. '\u2F7C': '\u8001',
  14996. '\u2F7D': '\u800C',
  14997. '\u2F7E': '\u8012',
  14998. '\u2F7F': '\u8033',
  14999. '\u2F80': '\u807F',
  15000. '\u2F81': '\u8089',
  15001. '\u2F82': '\u81E3',
  15002. '\u2F83': '\u81EA',
  15003. '\u2F84': '\u81F3',
  15004. '\u2F85': '\u81FC',
  15005. '\u2F86': '\u820C',
  15006. '\u2F87': '\u821B',
  15007. '\u2F88': '\u821F',
  15008. '\u2F89': '\u826E',
  15009. '\u2F8A': '\u8272',
  15010. '\u2F8B': '\u8278',
  15011. '\u2F8C': '\u864D',
  15012. '\u2F8D': '\u866B',
  15013. '\u2F8E': '\u8840',
  15014. '\u2F8F': '\u884C',
  15015. '\u2F90': '\u8863',
  15016. '\u2F91': '\u897E',
  15017. '\u2F92': '\u898B',
  15018. '\u2F93': '\u89D2',
  15019. '\u2F94': '\u8A00',
  15020. '\u2F95': '\u8C37',
  15021. '\u2F96': '\u8C46',
  15022. '\u2F97': '\u8C55',
  15023. '\u2F98': '\u8C78',
  15024. '\u2F99': '\u8C9D',
  15025. '\u2F9A': '\u8D64',
  15026. '\u2F9B': '\u8D70',
  15027. '\u2F9C': '\u8DB3',
  15028. '\u2F9D': '\u8EAB',
  15029. '\u2F9E': '\u8ECA',
  15030. '\u2F9F': '\u8F9B',
  15031. '\u2FA0': '\u8FB0',
  15032. '\u2FA1': '\u8FB5',
  15033. '\u2FA2': '\u9091',
  15034. '\u2FA3': '\u9149',
  15035. '\u2FA4': '\u91C6',
  15036. '\u2FA5': '\u91CC',
  15037. '\u2FA6': '\u91D1',
  15038. '\u2FA7': '\u9577',
  15039. '\u2FA8': '\u9580',
  15040. '\u2FA9': '\u961C',
  15041. '\u2FAA': '\u96B6',
  15042. '\u2FAB': '\u96B9',
  15043. '\u2FAC': '\u96E8',
  15044. '\u2FAD': '\u9751',
  15045. '\u2FAE': '\u975E',
  15046. '\u2FAF': '\u9762',
  15047. '\u2FB0': '\u9769',
  15048. '\u2FB1': '\u97CB',
  15049. '\u2FB2': '\u97ED',
  15050. '\u2FB3': '\u97F3',
  15051. '\u2FB4': '\u9801',
  15052. '\u2FB5': '\u98A8',
  15053. '\u2FB6': '\u98DB',
  15054. '\u2FB7': '\u98DF',
  15055. '\u2FB8': '\u9996',
  15056. '\u2FB9': '\u9999',
  15057. '\u2FBA': '\u99AC',
  15058. '\u2FBB': '\u9AA8',
  15059. '\u2FBC': '\u9AD8',
  15060. '\u2FBD': '\u9ADF',
  15061. '\u2FBE': '\u9B25',
  15062. '\u2FBF': '\u9B2F',
  15063. '\u2FC0': '\u9B32',
  15064. '\u2FC1': '\u9B3C',
  15065. '\u2FC2': '\u9B5A',
  15066. '\u2FC3': '\u9CE5',
  15067. '\u2FC4': '\u9E75',
  15068. '\u2FC5': '\u9E7F',
  15069. '\u2FC6': '\u9EA5',
  15070. '\u2FC7': '\u9EBB',
  15071. '\u2FC8': '\u9EC3',
  15072. '\u2FC9': '\u9ECD',
  15073. '\u2FCA': '\u9ED1',
  15074. '\u2FCB': '\u9EF9',
  15075. '\u2FCC': '\u9EFD',
  15076. '\u2FCD': '\u9F0E',
  15077. '\u2FCE': '\u9F13',
  15078. '\u2FCF': '\u9F20',
  15079. '\u2FD0': '\u9F3B',
  15080. '\u2FD1': '\u9F4A',
  15081. '\u2FD2': '\u9F52',
  15082. '\u2FD3': '\u9F8D',
  15083. '\u2FD4': '\u9F9C',
  15084. '\u2FD5': '\u9FA0',
  15085. '\u3036': '\u3012',
  15086. '\u3038': '\u5341',
  15087. '\u3039': '\u5344',
  15088. '\u303A': '\u5345',
  15089. '\u309B': '\u0020\u3099',
  15090. '\u309C': '\u0020\u309A',
  15091. '\u3131': '\u1100',
  15092. '\u3132': '\u1101',
  15093. '\u3133': '\u11AA',
  15094. '\u3134': '\u1102',
  15095. '\u3135': '\u11AC',
  15096. '\u3136': '\u11AD',
  15097. '\u3137': '\u1103',
  15098. '\u3138': '\u1104',
  15099. '\u3139': '\u1105',
  15100. '\u313A': '\u11B0',
  15101. '\u313B': '\u11B1',
  15102. '\u313C': '\u11B2',
  15103. '\u313D': '\u11B3',
  15104. '\u313E': '\u11B4',
  15105. '\u313F': '\u11B5',
  15106. '\u3140': '\u111A',
  15107. '\u3141': '\u1106',
  15108. '\u3142': '\u1107',
  15109. '\u3143': '\u1108',
  15110. '\u3144': '\u1121',
  15111. '\u3145': '\u1109',
  15112. '\u3146': '\u110A',
  15113. '\u3147': '\u110B',
  15114. '\u3148': '\u110C',
  15115. '\u3149': '\u110D',
  15116. '\u314A': '\u110E',
  15117. '\u314B': '\u110F',
  15118. '\u314C': '\u1110',
  15119. '\u314D': '\u1111',
  15120. '\u314E': '\u1112',
  15121. '\u314F': '\u1161',
  15122. '\u3150': '\u1162',
  15123. '\u3151': '\u1163',
  15124. '\u3152': '\u1164',
  15125. '\u3153': '\u1165',
  15126. '\u3154': '\u1166',
  15127. '\u3155': '\u1167',
  15128. '\u3156': '\u1168',
  15129. '\u3157': '\u1169',
  15130. '\u3158': '\u116A',
  15131. '\u3159': '\u116B',
  15132. '\u315A': '\u116C',
  15133. '\u315B': '\u116D',
  15134. '\u315C': '\u116E',
  15135. '\u315D': '\u116F',
  15136. '\u315E': '\u1170',
  15137. '\u315F': '\u1171',
  15138. '\u3160': '\u1172',
  15139. '\u3161': '\u1173',
  15140. '\u3162': '\u1174',
  15141. '\u3163': '\u1175',
  15142. '\u3164': '\u1160',
  15143. '\u3165': '\u1114',
  15144. '\u3166': '\u1115',
  15145. '\u3167': '\u11C7',
  15146. '\u3168': '\u11C8',
  15147. '\u3169': '\u11CC',
  15148. '\u316A': '\u11CE',
  15149. '\u316B': '\u11D3',
  15150. '\u316C': '\u11D7',
  15151. '\u316D': '\u11D9',
  15152. '\u316E': '\u111C',
  15153. '\u316F': '\u11DD',
  15154. '\u3170': '\u11DF',
  15155. '\u3171': '\u111D',
  15156. '\u3172': '\u111E',
  15157. '\u3173': '\u1120',
  15158. '\u3174': '\u1122',
  15159. '\u3175': '\u1123',
  15160. '\u3176': '\u1127',
  15161. '\u3177': '\u1129',
  15162. '\u3178': '\u112B',
  15163. '\u3179': '\u112C',
  15164. '\u317A': '\u112D',
  15165. '\u317B': '\u112E',
  15166. '\u317C': '\u112F',
  15167. '\u317D': '\u1132',
  15168. '\u317E': '\u1136',
  15169. '\u317F': '\u1140',
  15170. '\u3180': '\u1147',
  15171. '\u3181': '\u114C',
  15172. '\u3182': '\u11F1',
  15173. '\u3183': '\u11F2',
  15174. '\u3184': '\u1157',
  15175. '\u3185': '\u1158',
  15176. '\u3186': '\u1159',
  15177. '\u3187': '\u1184',
  15178. '\u3188': '\u1185',
  15179. '\u3189': '\u1188',
  15180. '\u318A': '\u1191',
  15181. '\u318B': '\u1192',
  15182. '\u318C': '\u1194',
  15183. '\u318D': '\u119E',
  15184. '\u318E': '\u11A1',
  15185. '\u3200': '\u0028\u1100\u0029',
  15186. '\u3201': '\u0028\u1102\u0029',
  15187. '\u3202': '\u0028\u1103\u0029',
  15188. '\u3203': '\u0028\u1105\u0029',
  15189. '\u3204': '\u0028\u1106\u0029',
  15190. '\u3205': '\u0028\u1107\u0029',
  15191. '\u3206': '\u0028\u1109\u0029',
  15192. '\u3207': '\u0028\u110B\u0029',
  15193. '\u3208': '\u0028\u110C\u0029',
  15194. '\u3209': '\u0028\u110E\u0029',
  15195. '\u320A': '\u0028\u110F\u0029',
  15196. '\u320B': '\u0028\u1110\u0029',
  15197. '\u320C': '\u0028\u1111\u0029',
  15198. '\u320D': '\u0028\u1112\u0029',
  15199. '\u320E': '\u0028\u1100\u1161\u0029',
  15200. '\u320F': '\u0028\u1102\u1161\u0029',
  15201. '\u3210': '\u0028\u1103\u1161\u0029',
  15202. '\u3211': '\u0028\u1105\u1161\u0029',
  15203. '\u3212': '\u0028\u1106\u1161\u0029',
  15204. '\u3213': '\u0028\u1107\u1161\u0029',
  15205. '\u3214': '\u0028\u1109\u1161\u0029',
  15206. '\u3215': '\u0028\u110B\u1161\u0029',
  15207. '\u3216': '\u0028\u110C\u1161\u0029',
  15208. '\u3217': '\u0028\u110E\u1161\u0029',
  15209. '\u3218': '\u0028\u110F\u1161\u0029',
  15210. '\u3219': '\u0028\u1110\u1161\u0029',
  15211. '\u321A': '\u0028\u1111\u1161\u0029',
  15212. '\u321B': '\u0028\u1112\u1161\u0029',
  15213. '\u321C': '\u0028\u110C\u116E\u0029',
  15214. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  15215. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  15216. '\u3220': '\u0028\u4E00\u0029',
  15217. '\u3221': '\u0028\u4E8C\u0029',
  15218. '\u3222': '\u0028\u4E09\u0029',
  15219. '\u3223': '\u0028\u56DB\u0029',
  15220. '\u3224': '\u0028\u4E94\u0029',
  15221. '\u3225': '\u0028\u516D\u0029',
  15222. '\u3226': '\u0028\u4E03\u0029',
  15223. '\u3227': '\u0028\u516B\u0029',
  15224. '\u3228': '\u0028\u4E5D\u0029',
  15225. '\u3229': '\u0028\u5341\u0029',
  15226. '\u322A': '\u0028\u6708\u0029',
  15227. '\u322B': '\u0028\u706B\u0029',
  15228. '\u322C': '\u0028\u6C34\u0029',
  15229. '\u322D': '\u0028\u6728\u0029',
  15230. '\u322E': '\u0028\u91D1\u0029',
  15231. '\u322F': '\u0028\u571F\u0029',
  15232. '\u3230': '\u0028\u65E5\u0029',
  15233. '\u3231': '\u0028\u682A\u0029',
  15234. '\u3232': '\u0028\u6709\u0029',
  15235. '\u3233': '\u0028\u793E\u0029',
  15236. '\u3234': '\u0028\u540D\u0029',
  15237. '\u3235': '\u0028\u7279\u0029',
  15238. '\u3236': '\u0028\u8CA1\u0029',
  15239. '\u3237': '\u0028\u795D\u0029',
  15240. '\u3238': '\u0028\u52B4\u0029',
  15241. '\u3239': '\u0028\u4EE3\u0029',
  15242. '\u323A': '\u0028\u547C\u0029',
  15243. '\u323B': '\u0028\u5B66\u0029',
  15244. '\u323C': '\u0028\u76E3\u0029',
  15245. '\u323D': '\u0028\u4F01\u0029',
  15246. '\u323E': '\u0028\u8CC7\u0029',
  15247. '\u323F': '\u0028\u5354\u0029',
  15248. '\u3240': '\u0028\u796D\u0029',
  15249. '\u3241': '\u0028\u4F11\u0029',
  15250. '\u3242': '\u0028\u81EA\u0029',
  15251. '\u3243': '\u0028\u81F3\u0029',
  15252. '\u32C0': '\u0031\u6708',
  15253. '\u32C1': '\u0032\u6708',
  15254. '\u32C2': '\u0033\u6708',
  15255. '\u32C3': '\u0034\u6708',
  15256. '\u32C4': '\u0035\u6708',
  15257. '\u32C5': '\u0036\u6708',
  15258. '\u32C6': '\u0037\u6708',
  15259. '\u32C7': '\u0038\u6708',
  15260. '\u32C8': '\u0039\u6708',
  15261. '\u32C9': '\u0031\u0030\u6708',
  15262. '\u32CA': '\u0031\u0031\u6708',
  15263. '\u32CB': '\u0031\u0032\u6708',
  15264. '\u3358': '\u0030\u70B9',
  15265. '\u3359': '\u0031\u70B9',
  15266. '\u335A': '\u0032\u70B9',
  15267. '\u335B': '\u0033\u70B9',
  15268. '\u335C': '\u0034\u70B9',
  15269. '\u335D': '\u0035\u70B9',
  15270. '\u335E': '\u0036\u70B9',
  15271. '\u335F': '\u0037\u70B9',
  15272. '\u3360': '\u0038\u70B9',
  15273. '\u3361': '\u0039\u70B9',
  15274. '\u3362': '\u0031\u0030\u70B9',
  15275. '\u3363': '\u0031\u0031\u70B9',
  15276. '\u3364': '\u0031\u0032\u70B9',
  15277. '\u3365': '\u0031\u0033\u70B9',
  15278. '\u3366': '\u0031\u0034\u70B9',
  15279. '\u3367': '\u0031\u0035\u70B9',
  15280. '\u3368': '\u0031\u0036\u70B9',
  15281. '\u3369': '\u0031\u0037\u70B9',
  15282. '\u336A': '\u0031\u0038\u70B9',
  15283. '\u336B': '\u0031\u0039\u70B9',
  15284. '\u336C': '\u0032\u0030\u70B9',
  15285. '\u336D': '\u0032\u0031\u70B9',
  15286. '\u336E': '\u0032\u0032\u70B9',
  15287. '\u336F': '\u0032\u0033\u70B9',
  15288. '\u3370': '\u0032\u0034\u70B9',
  15289. '\u33E0': '\u0031\u65E5',
  15290. '\u33E1': '\u0032\u65E5',
  15291. '\u33E2': '\u0033\u65E5',
  15292. '\u33E3': '\u0034\u65E5',
  15293. '\u33E4': '\u0035\u65E5',
  15294. '\u33E5': '\u0036\u65E5',
  15295. '\u33E6': '\u0037\u65E5',
  15296. '\u33E7': '\u0038\u65E5',
  15297. '\u33E8': '\u0039\u65E5',
  15298. '\u33E9': '\u0031\u0030\u65E5',
  15299. '\u33EA': '\u0031\u0031\u65E5',
  15300. '\u33EB': '\u0031\u0032\u65E5',
  15301. '\u33EC': '\u0031\u0033\u65E5',
  15302. '\u33ED': '\u0031\u0034\u65E5',
  15303. '\u33EE': '\u0031\u0035\u65E5',
  15304. '\u33EF': '\u0031\u0036\u65E5',
  15305. '\u33F0': '\u0031\u0037\u65E5',
  15306. '\u33F1': '\u0031\u0038\u65E5',
  15307. '\u33F2': '\u0031\u0039\u65E5',
  15308. '\u33F3': '\u0032\u0030\u65E5',
  15309. '\u33F4': '\u0032\u0031\u65E5',
  15310. '\u33F5': '\u0032\u0032\u65E5',
  15311. '\u33F6': '\u0032\u0033\u65E5',
  15312. '\u33F7': '\u0032\u0034\u65E5',
  15313. '\u33F8': '\u0032\u0035\u65E5',
  15314. '\u33F9': '\u0032\u0036\u65E5',
  15315. '\u33FA': '\u0032\u0037\u65E5',
  15316. '\u33FB': '\u0032\u0038\u65E5',
  15317. '\u33FC': '\u0032\u0039\u65E5',
  15318. '\u33FD': '\u0033\u0030\u65E5',
  15319. '\u33FE': '\u0033\u0031\u65E5',
  15320. '\uFB00': '\u0066\u0066',
  15321. '\uFB01': '\u0066\u0069',
  15322. '\uFB02': '\u0066\u006C',
  15323. '\uFB03': '\u0066\u0066\u0069',
  15324. '\uFB04': '\u0066\u0066\u006C',
  15325. '\uFB05': '\u017F\u0074',
  15326. '\uFB06': '\u0073\u0074',
  15327. '\uFB13': '\u0574\u0576',
  15328. '\uFB14': '\u0574\u0565',
  15329. '\uFB15': '\u0574\u056B',
  15330. '\uFB16': '\u057E\u0576',
  15331. '\uFB17': '\u0574\u056D',
  15332. '\uFB4F': '\u05D0\u05DC',
  15333. '\uFB50': '\u0671',
  15334. '\uFB51': '\u0671',
  15335. '\uFB52': '\u067B',
  15336. '\uFB53': '\u067B',
  15337. '\uFB54': '\u067B',
  15338. '\uFB55': '\u067B',
  15339. '\uFB56': '\u067E',
  15340. '\uFB57': '\u067E',
  15341. '\uFB58': '\u067E',
  15342. '\uFB59': '\u067E',
  15343. '\uFB5A': '\u0680',
  15344. '\uFB5B': '\u0680',
  15345. '\uFB5C': '\u0680',
  15346. '\uFB5D': '\u0680',
  15347. '\uFB5E': '\u067A',
  15348. '\uFB5F': '\u067A',
  15349. '\uFB60': '\u067A',
  15350. '\uFB61': '\u067A',
  15351. '\uFB62': '\u067F',
  15352. '\uFB63': '\u067F',
  15353. '\uFB64': '\u067F',
  15354. '\uFB65': '\u067F',
  15355. '\uFB66': '\u0679',
  15356. '\uFB67': '\u0679',
  15357. '\uFB68': '\u0679',
  15358. '\uFB69': '\u0679',
  15359. '\uFB6A': '\u06A4',
  15360. '\uFB6B': '\u06A4',
  15361. '\uFB6C': '\u06A4',
  15362. '\uFB6D': '\u06A4',
  15363. '\uFB6E': '\u06A6',
  15364. '\uFB6F': '\u06A6',
  15365. '\uFB70': '\u06A6',
  15366. '\uFB71': '\u06A6',
  15367. '\uFB72': '\u0684',
  15368. '\uFB73': '\u0684',
  15369. '\uFB74': '\u0684',
  15370. '\uFB75': '\u0684',
  15371. '\uFB76': '\u0683',
  15372. '\uFB77': '\u0683',
  15373. '\uFB78': '\u0683',
  15374. '\uFB79': '\u0683',
  15375. '\uFB7A': '\u0686',
  15376. '\uFB7B': '\u0686',
  15377. '\uFB7C': '\u0686',
  15378. '\uFB7D': '\u0686',
  15379. '\uFB7E': '\u0687',
  15380. '\uFB7F': '\u0687',
  15381. '\uFB80': '\u0687',
  15382. '\uFB81': '\u0687',
  15383. '\uFB82': '\u068D',
  15384. '\uFB83': '\u068D',
  15385. '\uFB84': '\u068C',
  15386. '\uFB85': '\u068C',
  15387. '\uFB86': '\u068E',
  15388. '\uFB87': '\u068E',
  15389. '\uFB88': '\u0688',
  15390. '\uFB89': '\u0688',
  15391. '\uFB8A': '\u0698',
  15392. '\uFB8B': '\u0698',
  15393. '\uFB8C': '\u0691',
  15394. '\uFB8D': '\u0691',
  15395. '\uFB8E': '\u06A9',
  15396. '\uFB8F': '\u06A9',
  15397. '\uFB90': '\u06A9',
  15398. '\uFB91': '\u06A9',
  15399. '\uFB92': '\u06AF',
  15400. '\uFB93': '\u06AF',
  15401. '\uFB94': '\u06AF',
  15402. '\uFB95': '\u06AF',
  15403. '\uFB96': '\u06B3',
  15404. '\uFB97': '\u06B3',
  15405. '\uFB98': '\u06B3',
  15406. '\uFB99': '\u06B3',
  15407. '\uFB9A': '\u06B1',
  15408. '\uFB9B': '\u06B1',
  15409. '\uFB9C': '\u06B1',
  15410. '\uFB9D': '\u06B1',
  15411. '\uFB9E': '\u06BA',
  15412. '\uFB9F': '\u06BA',
  15413. '\uFBA0': '\u06BB',
  15414. '\uFBA1': '\u06BB',
  15415. '\uFBA2': '\u06BB',
  15416. '\uFBA3': '\u06BB',
  15417. '\uFBA4': '\u06C0',
  15418. '\uFBA5': '\u06C0',
  15419. '\uFBA6': '\u06C1',
  15420. '\uFBA7': '\u06C1',
  15421. '\uFBA8': '\u06C1',
  15422. '\uFBA9': '\u06C1',
  15423. '\uFBAA': '\u06BE',
  15424. '\uFBAB': '\u06BE',
  15425. '\uFBAC': '\u06BE',
  15426. '\uFBAD': '\u06BE',
  15427. '\uFBAE': '\u06D2',
  15428. '\uFBAF': '\u06D2',
  15429. '\uFBB0': '\u06D3',
  15430. '\uFBB1': '\u06D3',
  15431. '\uFBD3': '\u06AD',
  15432. '\uFBD4': '\u06AD',
  15433. '\uFBD5': '\u06AD',
  15434. '\uFBD6': '\u06AD',
  15435. '\uFBD7': '\u06C7',
  15436. '\uFBD8': '\u06C7',
  15437. '\uFBD9': '\u06C6',
  15438. '\uFBDA': '\u06C6',
  15439. '\uFBDB': '\u06C8',
  15440. '\uFBDC': '\u06C8',
  15441. '\uFBDD': '\u0677',
  15442. '\uFBDE': '\u06CB',
  15443. '\uFBDF': '\u06CB',
  15444. '\uFBE0': '\u06C5',
  15445. '\uFBE1': '\u06C5',
  15446. '\uFBE2': '\u06C9',
  15447. '\uFBE3': '\u06C9',
  15448. '\uFBE4': '\u06D0',
  15449. '\uFBE5': '\u06D0',
  15450. '\uFBE6': '\u06D0',
  15451. '\uFBE7': '\u06D0',
  15452. '\uFBE8': '\u0649',
  15453. '\uFBE9': '\u0649',
  15454. '\uFBEA': '\u0626\u0627',
  15455. '\uFBEB': '\u0626\u0627',
  15456. '\uFBEC': '\u0626\u06D5',
  15457. '\uFBED': '\u0626\u06D5',
  15458. '\uFBEE': '\u0626\u0648',
  15459. '\uFBEF': '\u0626\u0648',
  15460. '\uFBF0': '\u0626\u06C7',
  15461. '\uFBF1': '\u0626\u06C7',
  15462. '\uFBF2': '\u0626\u06C6',
  15463. '\uFBF3': '\u0626\u06C6',
  15464. '\uFBF4': '\u0626\u06C8',
  15465. '\uFBF5': '\u0626\u06C8',
  15466. '\uFBF6': '\u0626\u06D0',
  15467. '\uFBF7': '\u0626\u06D0',
  15468. '\uFBF8': '\u0626\u06D0',
  15469. '\uFBF9': '\u0626\u0649',
  15470. '\uFBFA': '\u0626\u0649',
  15471. '\uFBFB': '\u0626\u0649',
  15472. '\uFBFC': '\u06CC',
  15473. '\uFBFD': '\u06CC',
  15474. '\uFBFE': '\u06CC',
  15475. '\uFBFF': '\u06CC',
  15476. '\uFC00': '\u0626\u062C',
  15477. '\uFC01': '\u0626\u062D',
  15478. '\uFC02': '\u0626\u0645',
  15479. '\uFC03': '\u0626\u0649',
  15480. '\uFC04': '\u0626\u064A',
  15481. '\uFC05': '\u0628\u062C',
  15482. '\uFC06': '\u0628\u062D',
  15483. '\uFC07': '\u0628\u062E',
  15484. '\uFC08': '\u0628\u0645',
  15485. '\uFC09': '\u0628\u0649',
  15486. '\uFC0A': '\u0628\u064A',
  15487. '\uFC0B': '\u062A\u062C',
  15488. '\uFC0C': '\u062A\u062D',
  15489. '\uFC0D': '\u062A\u062E',
  15490. '\uFC0E': '\u062A\u0645',
  15491. '\uFC0F': '\u062A\u0649',
  15492. '\uFC10': '\u062A\u064A',
  15493. '\uFC11': '\u062B\u062C',
  15494. '\uFC12': '\u062B\u0645',
  15495. '\uFC13': '\u062B\u0649',
  15496. '\uFC14': '\u062B\u064A',
  15497. '\uFC15': '\u062C\u062D',
  15498. '\uFC16': '\u062C\u0645',
  15499. '\uFC17': '\u062D\u062C',
  15500. '\uFC18': '\u062D\u0645',
  15501. '\uFC19': '\u062E\u062C',
  15502. '\uFC1A': '\u062E\u062D',
  15503. '\uFC1B': '\u062E\u0645',
  15504. '\uFC1C': '\u0633\u062C',
  15505. '\uFC1D': '\u0633\u062D',
  15506. '\uFC1E': '\u0633\u062E',
  15507. '\uFC1F': '\u0633\u0645',
  15508. '\uFC20': '\u0635\u062D',
  15509. '\uFC21': '\u0635\u0645',
  15510. '\uFC22': '\u0636\u062C',
  15511. '\uFC23': '\u0636\u062D',
  15512. '\uFC24': '\u0636\u062E',
  15513. '\uFC25': '\u0636\u0645',
  15514. '\uFC26': '\u0637\u062D',
  15515. '\uFC27': '\u0637\u0645',
  15516. '\uFC28': '\u0638\u0645',
  15517. '\uFC29': '\u0639\u062C',
  15518. '\uFC2A': '\u0639\u0645',
  15519. '\uFC2B': '\u063A\u062C',
  15520. '\uFC2C': '\u063A\u0645',
  15521. '\uFC2D': '\u0641\u062C',
  15522. '\uFC2E': '\u0641\u062D',
  15523. '\uFC2F': '\u0641\u062E',
  15524. '\uFC30': '\u0641\u0645',
  15525. '\uFC31': '\u0641\u0649',
  15526. '\uFC32': '\u0641\u064A',
  15527. '\uFC33': '\u0642\u062D',
  15528. '\uFC34': '\u0642\u0645',
  15529. '\uFC35': '\u0642\u0649',
  15530. '\uFC36': '\u0642\u064A',
  15531. '\uFC37': '\u0643\u0627',
  15532. '\uFC38': '\u0643\u062C',
  15533. '\uFC39': '\u0643\u062D',
  15534. '\uFC3A': '\u0643\u062E',
  15535. '\uFC3B': '\u0643\u0644',
  15536. '\uFC3C': '\u0643\u0645',
  15537. '\uFC3D': '\u0643\u0649',
  15538. '\uFC3E': '\u0643\u064A',
  15539. '\uFC3F': '\u0644\u062C',
  15540. '\uFC40': '\u0644\u062D',
  15541. '\uFC41': '\u0644\u062E',
  15542. '\uFC42': '\u0644\u0645',
  15543. '\uFC43': '\u0644\u0649',
  15544. '\uFC44': '\u0644\u064A',
  15545. '\uFC45': '\u0645\u062C',
  15546. '\uFC46': '\u0645\u062D',
  15547. '\uFC47': '\u0645\u062E',
  15548. '\uFC48': '\u0645\u0645',
  15549. '\uFC49': '\u0645\u0649',
  15550. '\uFC4A': '\u0645\u064A',
  15551. '\uFC4B': '\u0646\u062C',
  15552. '\uFC4C': '\u0646\u062D',
  15553. '\uFC4D': '\u0646\u062E',
  15554. '\uFC4E': '\u0646\u0645',
  15555. '\uFC4F': '\u0646\u0649',
  15556. '\uFC50': '\u0646\u064A',
  15557. '\uFC51': '\u0647\u062C',
  15558. '\uFC52': '\u0647\u0645',
  15559. '\uFC53': '\u0647\u0649',
  15560. '\uFC54': '\u0647\u064A',
  15561. '\uFC55': '\u064A\u062C',
  15562. '\uFC56': '\u064A\u062D',
  15563. '\uFC57': '\u064A\u062E',
  15564. '\uFC58': '\u064A\u0645',
  15565. '\uFC59': '\u064A\u0649',
  15566. '\uFC5A': '\u064A\u064A',
  15567. '\uFC5B': '\u0630\u0670',
  15568. '\uFC5C': '\u0631\u0670',
  15569. '\uFC5D': '\u0649\u0670',
  15570. '\uFC5E': '\u0020\u064C\u0651',
  15571. '\uFC5F': '\u0020\u064D\u0651',
  15572. '\uFC60': '\u0020\u064E\u0651',
  15573. '\uFC61': '\u0020\u064F\u0651',
  15574. '\uFC62': '\u0020\u0650\u0651',
  15575. '\uFC63': '\u0020\u0651\u0670',
  15576. '\uFC64': '\u0626\u0631',
  15577. '\uFC65': '\u0626\u0632',
  15578. '\uFC66': '\u0626\u0645',
  15579. '\uFC67': '\u0626\u0646',
  15580. '\uFC68': '\u0626\u0649',
  15581. '\uFC69': '\u0626\u064A',
  15582. '\uFC6A': '\u0628\u0631',
  15583. '\uFC6B': '\u0628\u0632',
  15584. '\uFC6C': '\u0628\u0645',
  15585. '\uFC6D': '\u0628\u0646',
  15586. '\uFC6E': '\u0628\u0649',
  15587. '\uFC6F': '\u0628\u064A',
  15588. '\uFC70': '\u062A\u0631',
  15589. '\uFC71': '\u062A\u0632',
  15590. '\uFC72': '\u062A\u0645',
  15591. '\uFC73': '\u062A\u0646',
  15592. '\uFC74': '\u062A\u0649',
  15593. '\uFC75': '\u062A\u064A',
  15594. '\uFC76': '\u062B\u0631',
  15595. '\uFC77': '\u062B\u0632',
  15596. '\uFC78': '\u062B\u0645',
  15597. '\uFC79': '\u062B\u0646',
  15598. '\uFC7A': '\u062B\u0649',
  15599. '\uFC7B': '\u062B\u064A',
  15600. '\uFC7C': '\u0641\u0649',
  15601. '\uFC7D': '\u0641\u064A',
  15602. '\uFC7E': '\u0642\u0649',
  15603. '\uFC7F': '\u0642\u064A',
  15604. '\uFC80': '\u0643\u0627',
  15605. '\uFC81': '\u0643\u0644',
  15606. '\uFC82': '\u0643\u0645',
  15607. '\uFC83': '\u0643\u0649',
  15608. '\uFC84': '\u0643\u064A',
  15609. '\uFC85': '\u0644\u0645',
  15610. '\uFC86': '\u0644\u0649',
  15611. '\uFC87': '\u0644\u064A',
  15612. '\uFC88': '\u0645\u0627',
  15613. '\uFC89': '\u0645\u0645',
  15614. '\uFC8A': '\u0646\u0631',
  15615. '\uFC8B': '\u0646\u0632',
  15616. '\uFC8C': '\u0646\u0645',
  15617. '\uFC8D': '\u0646\u0646',
  15618. '\uFC8E': '\u0646\u0649',
  15619. '\uFC8F': '\u0646\u064A',
  15620. '\uFC90': '\u0649\u0670',
  15621. '\uFC91': '\u064A\u0631',
  15622. '\uFC92': '\u064A\u0632',
  15623. '\uFC93': '\u064A\u0645',
  15624. '\uFC94': '\u064A\u0646',
  15625. '\uFC95': '\u064A\u0649',
  15626. '\uFC96': '\u064A\u064A',
  15627. '\uFC97': '\u0626\u062C',
  15628. '\uFC98': '\u0626\u062D',
  15629. '\uFC99': '\u0626\u062E',
  15630. '\uFC9A': '\u0626\u0645',
  15631. '\uFC9B': '\u0626\u0647',
  15632. '\uFC9C': '\u0628\u062C',
  15633. '\uFC9D': '\u0628\u062D',
  15634. '\uFC9E': '\u0628\u062E',
  15635. '\uFC9F': '\u0628\u0645',
  15636. '\uFCA0': '\u0628\u0647',
  15637. '\uFCA1': '\u062A\u062C',
  15638. '\uFCA2': '\u062A\u062D',
  15639. '\uFCA3': '\u062A\u062E',
  15640. '\uFCA4': '\u062A\u0645',
  15641. '\uFCA5': '\u062A\u0647',
  15642. '\uFCA6': '\u062B\u0645',
  15643. '\uFCA7': '\u062C\u062D',
  15644. '\uFCA8': '\u062C\u0645',
  15645. '\uFCA9': '\u062D\u062C',
  15646. '\uFCAA': '\u062D\u0645',
  15647. '\uFCAB': '\u062E\u062C',
  15648. '\uFCAC': '\u062E\u0645',
  15649. '\uFCAD': '\u0633\u062C',
  15650. '\uFCAE': '\u0633\u062D',
  15651. '\uFCAF': '\u0633\u062E',
  15652. '\uFCB0': '\u0633\u0645',
  15653. '\uFCB1': '\u0635\u062D',
  15654. '\uFCB2': '\u0635\u062E',
  15655. '\uFCB3': '\u0635\u0645',
  15656. '\uFCB4': '\u0636\u062C',
  15657. '\uFCB5': '\u0636\u062D',
  15658. '\uFCB6': '\u0636\u062E',
  15659. '\uFCB7': '\u0636\u0645',
  15660. '\uFCB8': '\u0637\u062D',
  15661. '\uFCB9': '\u0638\u0645',
  15662. '\uFCBA': '\u0639\u062C',
  15663. '\uFCBB': '\u0639\u0645',
  15664. '\uFCBC': '\u063A\u062C',
  15665. '\uFCBD': '\u063A\u0645',
  15666. '\uFCBE': '\u0641\u062C',
  15667. '\uFCBF': '\u0641\u062D',
  15668. '\uFCC0': '\u0641\u062E',
  15669. '\uFCC1': '\u0641\u0645',
  15670. '\uFCC2': '\u0642\u062D',
  15671. '\uFCC3': '\u0642\u0645',
  15672. '\uFCC4': '\u0643\u062C',
  15673. '\uFCC5': '\u0643\u062D',
  15674. '\uFCC6': '\u0643\u062E',
  15675. '\uFCC7': '\u0643\u0644',
  15676. '\uFCC8': '\u0643\u0645',
  15677. '\uFCC9': '\u0644\u062C',
  15678. '\uFCCA': '\u0644\u062D',
  15679. '\uFCCB': '\u0644\u062E',
  15680. '\uFCCC': '\u0644\u0645',
  15681. '\uFCCD': '\u0644\u0647',
  15682. '\uFCCE': '\u0645\u062C',
  15683. '\uFCCF': '\u0645\u062D',
  15684. '\uFCD0': '\u0645\u062E',
  15685. '\uFCD1': '\u0645\u0645',
  15686. '\uFCD2': '\u0646\u062C',
  15687. '\uFCD3': '\u0646\u062D',
  15688. '\uFCD4': '\u0646\u062E',
  15689. '\uFCD5': '\u0646\u0645',
  15690. '\uFCD6': '\u0646\u0647',
  15691. '\uFCD7': '\u0647\u062C',
  15692. '\uFCD8': '\u0647\u0645',
  15693. '\uFCD9': '\u0647\u0670',
  15694. '\uFCDA': '\u064A\u062C',
  15695. '\uFCDB': '\u064A\u062D',
  15696. '\uFCDC': '\u064A\u062E',
  15697. '\uFCDD': '\u064A\u0645',
  15698. '\uFCDE': '\u064A\u0647',
  15699. '\uFCDF': '\u0626\u0645',
  15700. '\uFCE0': '\u0626\u0647',
  15701. '\uFCE1': '\u0628\u0645',
  15702. '\uFCE2': '\u0628\u0647',
  15703. '\uFCE3': '\u062A\u0645',
  15704. '\uFCE4': '\u062A\u0647',
  15705. '\uFCE5': '\u062B\u0645',
  15706. '\uFCE6': '\u062B\u0647',
  15707. '\uFCE7': '\u0633\u0645',
  15708. '\uFCE8': '\u0633\u0647',
  15709. '\uFCE9': '\u0634\u0645',
  15710. '\uFCEA': '\u0634\u0647',
  15711. '\uFCEB': '\u0643\u0644',
  15712. '\uFCEC': '\u0643\u0645',
  15713. '\uFCED': '\u0644\u0645',
  15714. '\uFCEE': '\u0646\u0645',
  15715. '\uFCEF': '\u0646\u0647',
  15716. '\uFCF0': '\u064A\u0645',
  15717. '\uFCF1': '\u064A\u0647',
  15718. '\uFCF2': '\u0640\u064E\u0651',
  15719. '\uFCF3': '\u0640\u064F\u0651',
  15720. '\uFCF4': '\u0640\u0650\u0651',
  15721. '\uFCF5': '\u0637\u0649',
  15722. '\uFCF6': '\u0637\u064A',
  15723. '\uFCF7': '\u0639\u0649',
  15724. '\uFCF8': '\u0639\u064A',
  15725. '\uFCF9': '\u063A\u0649',
  15726. '\uFCFA': '\u063A\u064A',
  15727. '\uFCFB': '\u0633\u0649',
  15728. '\uFCFC': '\u0633\u064A',
  15729. '\uFCFD': '\u0634\u0649',
  15730. '\uFCFE': '\u0634\u064A',
  15731. '\uFCFF': '\u062D\u0649',
  15732. '\uFD00': '\u062D\u064A',
  15733. '\uFD01': '\u062C\u0649',
  15734. '\uFD02': '\u062C\u064A',
  15735. '\uFD03': '\u062E\u0649',
  15736. '\uFD04': '\u062E\u064A',
  15737. '\uFD05': '\u0635\u0649',
  15738. '\uFD06': '\u0635\u064A',
  15739. '\uFD07': '\u0636\u0649',
  15740. '\uFD08': '\u0636\u064A',
  15741. '\uFD09': '\u0634\u062C',
  15742. '\uFD0A': '\u0634\u062D',
  15743. '\uFD0B': '\u0634\u062E',
  15744. '\uFD0C': '\u0634\u0645',
  15745. '\uFD0D': '\u0634\u0631',
  15746. '\uFD0E': '\u0633\u0631',
  15747. '\uFD0F': '\u0635\u0631',
  15748. '\uFD10': '\u0636\u0631',
  15749. '\uFD11': '\u0637\u0649',
  15750. '\uFD12': '\u0637\u064A',
  15751. '\uFD13': '\u0639\u0649',
  15752. '\uFD14': '\u0639\u064A',
  15753. '\uFD15': '\u063A\u0649',
  15754. '\uFD16': '\u063A\u064A',
  15755. '\uFD17': '\u0633\u0649',
  15756. '\uFD18': '\u0633\u064A',
  15757. '\uFD19': '\u0634\u0649',
  15758. '\uFD1A': '\u0634\u064A',
  15759. '\uFD1B': '\u062D\u0649',
  15760. '\uFD1C': '\u062D\u064A',
  15761. '\uFD1D': '\u062C\u0649',
  15762. '\uFD1E': '\u062C\u064A',
  15763. '\uFD1F': '\u062E\u0649',
  15764. '\uFD20': '\u062E\u064A',
  15765. '\uFD21': '\u0635\u0649',
  15766. '\uFD22': '\u0635\u064A',
  15767. '\uFD23': '\u0636\u0649',
  15768. '\uFD24': '\u0636\u064A',
  15769. '\uFD25': '\u0634\u062C',
  15770. '\uFD26': '\u0634\u062D',
  15771. '\uFD27': '\u0634\u062E',
  15772. '\uFD28': '\u0634\u0645',
  15773. '\uFD29': '\u0634\u0631',
  15774. '\uFD2A': '\u0633\u0631',
  15775. '\uFD2B': '\u0635\u0631',
  15776. '\uFD2C': '\u0636\u0631',
  15777. '\uFD2D': '\u0634\u062C',
  15778. '\uFD2E': '\u0634\u062D',
  15779. '\uFD2F': '\u0634\u062E',
  15780. '\uFD30': '\u0634\u0645',
  15781. '\uFD31': '\u0633\u0647',
  15782. '\uFD32': '\u0634\u0647',
  15783. '\uFD33': '\u0637\u0645',
  15784. '\uFD34': '\u0633\u062C',
  15785. '\uFD35': '\u0633\u062D',
  15786. '\uFD36': '\u0633\u062E',
  15787. '\uFD37': '\u0634\u062C',
  15788. '\uFD38': '\u0634\u062D',
  15789. '\uFD39': '\u0634\u062E',
  15790. '\uFD3A': '\u0637\u0645',
  15791. '\uFD3B': '\u0638\u0645',
  15792. '\uFD3C': '\u0627\u064B',
  15793. '\uFD3D': '\u0627\u064B',
  15794. '\uFD50': '\u062A\u062C\u0645',
  15795. '\uFD51': '\u062A\u062D\u062C',
  15796. '\uFD52': '\u062A\u062D\u062C',
  15797. '\uFD53': '\u062A\u062D\u0645',
  15798. '\uFD54': '\u062A\u062E\u0645',
  15799. '\uFD55': '\u062A\u0645\u062C',
  15800. '\uFD56': '\u062A\u0645\u062D',
  15801. '\uFD57': '\u062A\u0645\u062E',
  15802. '\uFD58': '\u062C\u0645\u062D',
  15803. '\uFD59': '\u062C\u0645\u062D',
  15804. '\uFD5A': '\u062D\u0645\u064A',
  15805. '\uFD5B': '\u062D\u0645\u0649',
  15806. '\uFD5C': '\u0633\u062D\u062C',
  15807. '\uFD5D': '\u0633\u062C\u062D',
  15808. '\uFD5E': '\u0633\u062C\u0649',
  15809. '\uFD5F': '\u0633\u0645\u062D',
  15810. '\uFD60': '\u0633\u0645\u062D',
  15811. '\uFD61': '\u0633\u0645\u062C',
  15812. '\uFD62': '\u0633\u0645\u0645',
  15813. '\uFD63': '\u0633\u0645\u0645',
  15814. '\uFD64': '\u0635\u062D\u062D',
  15815. '\uFD65': '\u0635\u062D\u062D',
  15816. '\uFD66': '\u0635\u0645\u0645',
  15817. '\uFD67': '\u0634\u062D\u0645',
  15818. '\uFD68': '\u0634\u062D\u0645',
  15819. '\uFD69': '\u0634\u062C\u064A',
  15820. '\uFD6A': '\u0634\u0645\u062E',
  15821. '\uFD6B': '\u0634\u0645\u062E',
  15822. '\uFD6C': '\u0634\u0645\u0645',
  15823. '\uFD6D': '\u0634\u0645\u0645',
  15824. '\uFD6E': '\u0636\u062D\u0649',
  15825. '\uFD6F': '\u0636\u062E\u0645',
  15826. '\uFD70': '\u0636\u062E\u0645',
  15827. '\uFD71': '\u0637\u0645\u062D',
  15828. '\uFD72': '\u0637\u0645\u062D',
  15829. '\uFD73': '\u0637\u0645\u0645',
  15830. '\uFD74': '\u0637\u0645\u064A',
  15831. '\uFD75': '\u0639\u062C\u0645',
  15832. '\uFD76': '\u0639\u0645\u0645',
  15833. '\uFD77': '\u0639\u0645\u0645',
  15834. '\uFD78': '\u0639\u0645\u0649',
  15835. '\uFD79': '\u063A\u0645\u0645',
  15836. '\uFD7A': '\u063A\u0645\u064A',
  15837. '\uFD7B': '\u063A\u0645\u0649',
  15838. '\uFD7C': '\u0641\u062E\u0645',
  15839. '\uFD7D': '\u0641\u062E\u0645',
  15840. '\uFD7E': '\u0642\u0645\u062D',
  15841. '\uFD7F': '\u0642\u0645\u0645',
  15842. '\uFD80': '\u0644\u062D\u0645',
  15843. '\uFD81': '\u0644\u062D\u064A',
  15844. '\uFD82': '\u0644\u062D\u0649',
  15845. '\uFD83': '\u0644\u062C\u062C',
  15846. '\uFD84': '\u0644\u062C\u062C',
  15847. '\uFD85': '\u0644\u062E\u0645',
  15848. '\uFD86': '\u0644\u062E\u0645',
  15849. '\uFD87': '\u0644\u0645\u062D',
  15850. '\uFD88': '\u0644\u0645\u062D',
  15851. '\uFD89': '\u0645\u062D\u062C',
  15852. '\uFD8A': '\u0645\u062D\u0645',
  15853. '\uFD8B': '\u0645\u062D\u064A',
  15854. '\uFD8C': '\u0645\u062C\u062D',
  15855. '\uFD8D': '\u0645\u062C\u0645',
  15856. '\uFD8E': '\u0645\u062E\u062C',
  15857. '\uFD8F': '\u0645\u062E\u0645',
  15858. '\uFD92': '\u0645\u062C\u062E',
  15859. '\uFD93': '\u0647\u0645\u062C',
  15860. '\uFD94': '\u0647\u0645\u0645',
  15861. '\uFD95': '\u0646\u062D\u0645',
  15862. '\uFD96': '\u0646\u062D\u0649',
  15863. '\uFD97': '\u0646\u062C\u0645',
  15864. '\uFD98': '\u0646\u062C\u0645',
  15865. '\uFD99': '\u0646\u062C\u0649',
  15866. '\uFD9A': '\u0646\u0645\u064A',
  15867. '\uFD9B': '\u0646\u0645\u0649',
  15868. '\uFD9C': '\u064A\u0645\u0645',
  15869. '\uFD9D': '\u064A\u0645\u0645',
  15870. '\uFD9E': '\u0628\u062E\u064A',
  15871. '\uFD9F': '\u062A\u062C\u064A',
  15872. '\uFDA0': '\u062A\u062C\u0649',
  15873. '\uFDA1': '\u062A\u062E\u064A',
  15874. '\uFDA2': '\u062A\u062E\u0649',
  15875. '\uFDA3': '\u062A\u0645\u064A',
  15876. '\uFDA4': '\u062A\u0645\u0649',
  15877. '\uFDA5': '\u062C\u0645\u064A',
  15878. '\uFDA6': '\u062C\u062D\u0649',
  15879. '\uFDA7': '\u062C\u0645\u0649',
  15880. '\uFDA8': '\u0633\u062E\u0649',
  15881. '\uFDA9': '\u0635\u062D\u064A',
  15882. '\uFDAA': '\u0634\u062D\u064A',
  15883. '\uFDAB': '\u0636\u062D\u064A',
  15884. '\uFDAC': '\u0644\u062C\u064A',
  15885. '\uFDAD': '\u0644\u0645\u064A',
  15886. '\uFDAE': '\u064A\u062D\u064A',
  15887. '\uFDAF': '\u064A\u062C\u064A',
  15888. '\uFDB0': '\u064A\u0645\u064A',
  15889. '\uFDB1': '\u0645\u0645\u064A',
  15890. '\uFDB2': '\u0642\u0645\u064A',
  15891. '\uFDB3': '\u0646\u062D\u064A',
  15892. '\uFDB4': '\u0642\u0645\u062D',
  15893. '\uFDB5': '\u0644\u062D\u0645',
  15894. '\uFDB6': '\u0639\u0645\u064A',
  15895. '\uFDB7': '\u0643\u0645\u064A',
  15896. '\uFDB8': '\u0646\u062C\u062D',
  15897. '\uFDB9': '\u0645\u062E\u064A',
  15898. '\uFDBA': '\u0644\u062C\u0645',
  15899. '\uFDBB': '\u0643\u0645\u0645',
  15900. '\uFDBC': '\u0644\u062C\u0645',
  15901. '\uFDBD': '\u0646\u062C\u062D',
  15902. '\uFDBE': '\u062C\u062D\u064A',
  15903. '\uFDBF': '\u062D\u062C\u064A',
  15904. '\uFDC0': '\u0645\u062C\u064A',
  15905. '\uFDC1': '\u0641\u0645\u064A',
  15906. '\uFDC2': '\u0628\u062D\u064A',
  15907. '\uFDC3': '\u0643\u0645\u0645',
  15908. '\uFDC4': '\u0639\u062C\u0645',
  15909. '\uFDC5': '\u0635\u0645\u0645',
  15910. '\uFDC6': '\u0633\u062E\u064A',
  15911. '\uFDC7': '\u0646\u062C\u064A',
  15912. '\uFE49': '\u203E',
  15913. '\uFE4A': '\u203E',
  15914. '\uFE4B': '\u203E',
  15915. '\uFE4C': '\u203E',
  15916. '\uFE4D': '\u005F',
  15917. '\uFE4E': '\u005F',
  15918. '\uFE4F': '\u005F',
  15919. '\uFE80': '\u0621',
  15920. '\uFE81': '\u0622',
  15921. '\uFE82': '\u0622',
  15922. '\uFE83': '\u0623',
  15923. '\uFE84': '\u0623',
  15924. '\uFE85': '\u0624',
  15925. '\uFE86': '\u0624',
  15926. '\uFE87': '\u0625',
  15927. '\uFE88': '\u0625',
  15928. '\uFE89': '\u0626',
  15929. '\uFE8A': '\u0626',
  15930. '\uFE8B': '\u0626',
  15931. '\uFE8C': '\u0626',
  15932. '\uFE8D': '\u0627',
  15933. '\uFE8E': '\u0627',
  15934. '\uFE8F': '\u0628',
  15935. '\uFE90': '\u0628',
  15936. '\uFE91': '\u0628',
  15937. '\uFE92': '\u0628',
  15938. '\uFE93': '\u0629',
  15939. '\uFE94': '\u0629',
  15940. '\uFE95': '\u062A',
  15941. '\uFE96': '\u062A',
  15942. '\uFE97': '\u062A',
  15943. '\uFE98': '\u062A',
  15944. '\uFE99': '\u062B',
  15945. '\uFE9A': '\u062B',
  15946. '\uFE9B': '\u062B',
  15947. '\uFE9C': '\u062B',
  15948. '\uFE9D': '\u062C',
  15949. '\uFE9E': '\u062C',
  15950. '\uFE9F': '\u062C',
  15951. '\uFEA0': '\u062C',
  15952. '\uFEA1': '\u062D',
  15953. '\uFEA2': '\u062D',
  15954. '\uFEA3': '\u062D',
  15955. '\uFEA4': '\u062D',
  15956. '\uFEA5': '\u062E',
  15957. '\uFEA6': '\u062E',
  15958. '\uFEA7': '\u062E',
  15959. '\uFEA8': '\u062E',
  15960. '\uFEA9': '\u062F',
  15961. '\uFEAA': '\u062F',
  15962. '\uFEAB': '\u0630',
  15963. '\uFEAC': '\u0630',
  15964. '\uFEAD': '\u0631',
  15965. '\uFEAE': '\u0631',
  15966. '\uFEAF': '\u0632',
  15967. '\uFEB0': '\u0632',
  15968. '\uFEB1': '\u0633',
  15969. '\uFEB2': '\u0633',
  15970. '\uFEB3': '\u0633',
  15971. '\uFEB4': '\u0633',
  15972. '\uFEB5': '\u0634',
  15973. '\uFEB6': '\u0634',
  15974. '\uFEB7': '\u0634',
  15975. '\uFEB8': '\u0634',
  15976. '\uFEB9': '\u0635',
  15977. '\uFEBA': '\u0635',
  15978. '\uFEBB': '\u0635',
  15979. '\uFEBC': '\u0635',
  15980. '\uFEBD': '\u0636',
  15981. '\uFEBE': '\u0636',
  15982. '\uFEBF': '\u0636',
  15983. '\uFEC0': '\u0636',
  15984. '\uFEC1': '\u0637',
  15985. '\uFEC2': '\u0637',
  15986. '\uFEC3': '\u0637',
  15987. '\uFEC4': '\u0637',
  15988. '\uFEC5': '\u0638',
  15989. '\uFEC6': '\u0638',
  15990. '\uFEC7': '\u0638',
  15991. '\uFEC8': '\u0638',
  15992. '\uFEC9': '\u0639',
  15993. '\uFECA': '\u0639',
  15994. '\uFECB': '\u0639',
  15995. '\uFECC': '\u0639',
  15996. '\uFECD': '\u063A',
  15997. '\uFECE': '\u063A',
  15998. '\uFECF': '\u063A',
  15999. '\uFED0': '\u063A',
  16000. '\uFED1': '\u0641',
  16001. '\uFED2': '\u0641',
  16002. '\uFED3': '\u0641',
  16003. '\uFED4': '\u0641',
  16004. '\uFED5': '\u0642',
  16005. '\uFED6': '\u0642',
  16006. '\uFED7': '\u0642',
  16007. '\uFED8': '\u0642',
  16008. '\uFED9': '\u0643',
  16009. '\uFEDA': '\u0643',
  16010. '\uFEDB': '\u0643',
  16011. '\uFEDC': '\u0643',
  16012. '\uFEDD': '\u0644',
  16013. '\uFEDE': '\u0644',
  16014. '\uFEDF': '\u0644',
  16015. '\uFEE0': '\u0644',
  16016. '\uFEE1': '\u0645',
  16017. '\uFEE2': '\u0645',
  16018. '\uFEE3': '\u0645',
  16019. '\uFEE4': '\u0645',
  16020. '\uFEE5': '\u0646',
  16021. '\uFEE6': '\u0646',
  16022. '\uFEE7': '\u0646',
  16023. '\uFEE8': '\u0646',
  16024. '\uFEE9': '\u0647',
  16025. '\uFEEA': '\u0647',
  16026. '\uFEEB': '\u0647',
  16027. '\uFEEC': '\u0647',
  16028. '\uFEED': '\u0648',
  16029. '\uFEEE': '\u0648',
  16030. '\uFEEF': '\u0649',
  16031. '\uFEF0': '\u0649',
  16032. '\uFEF1': '\u064A',
  16033. '\uFEF2': '\u064A',
  16034. '\uFEF3': '\u064A',
  16035. '\uFEF4': '\u064A',
  16036. '\uFEF5': '\u0644\u0622',
  16037. '\uFEF6': '\u0644\u0622',
  16038. '\uFEF7': '\u0644\u0623',
  16039. '\uFEF8': '\u0644\u0623',
  16040. '\uFEF9': '\u0644\u0625',
  16041. '\uFEFA': '\u0644\u0625',
  16042. '\uFEFB': '\u0644\u0627',
  16043. '\uFEFC': '\u0644\u0627'
  16044. };
  16045. function reverseIfRtl(chars) {
  16046. var charsLength = chars.length;
  16047. //reverse an arabic ligature
  16048. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  16049. return chars;
  16050. }
  16051. var s = '';
  16052. for (var ii = charsLength - 1; ii >= 0; ii--) {
  16053. s += chars[ii];
  16054. }
  16055. return s;
  16056. }
  16057. function adjustWidths(properties) {
  16058. if (!properties.fontMatrix) {
  16059. return;
  16060. }
  16061. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  16062. return;
  16063. }
  16064. // adjusting width to fontMatrix scale
  16065. var scale = 0.001 / properties.fontMatrix[0];
  16066. var glyphsWidths = properties.widths;
  16067. for (var glyph in glyphsWidths) {
  16068. glyphsWidths[glyph] *= scale;
  16069. }
  16070. properties.defaultWidth *= scale;
  16071. }
  16072. function getFontType(type, subtype) {
  16073. switch (type) {
  16074. case 'Type1':
  16075. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  16076. case 'CIDFontType0':
  16077. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  16078. FontType.CIDFONTTYPE0;
  16079. case 'OpenType':
  16080. return FontType.OPENTYPE;
  16081. case 'TrueType':
  16082. return FontType.TRUETYPE;
  16083. case 'CIDFontType2':
  16084. return FontType.CIDFONTTYPE2;
  16085. case 'MMType1':
  16086. return FontType.MMTYPE1;
  16087. case 'Type0':
  16088. return FontType.TYPE0;
  16089. default:
  16090. return FontType.UNKNOWN;
  16091. }
  16092. }
  16093. var Glyph = (function GlyphClosure() {
  16094. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  16095. isSpace) {
  16096. this.fontChar = fontChar;
  16097. this.unicode = unicode;
  16098. this.accent = accent;
  16099. this.width = width;
  16100. this.vmetric = vmetric;
  16101. this.operatorListId = operatorListId;
  16102. this.isSpace = isSpace;
  16103. }
  16104. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  16105. vmetric, operatorListId, isSpace) {
  16106. return this.fontChar === fontChar &&
  16107. this.unicode === unicode &&
  16108. this.accent === accent &&
  16109. this.width === width &&
  16110. this.vmetric === vmetric &&
  16111. this.operatorListId === operatorListId &&
  16112. this.isSpace === isSpace;
  16113. };
  16114. return Glyph;
  16115. })();
  16116. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  16117. function ToUnicodeMap(cmap) {
  16118. // The elements of this._map can be integers or strings, depending on how
  16119. // |cmap| was created.
  16120. this._map = cmap;
  16121. }
  16122. ToUnicodeMap.prototype = {
  16123. get length() {
  16124. return this._map.length;
  16125. },
  16126. forEach: function(callback) {
  16127. for (var charCode in this._map) {
  16128. callback(charCode, this._map[charCode].charCodeAt(0));
  16129. }
  16130. },
  16131. has: function(i) {
  16132. return this._map[i] !== undefined;
  16133. },
  16134. get: function(i) {
  16135. return this._map[i];
  16136. },
  16137. charCodeOf: function(v) {
  16138. return this._map.indexOf(v);
  16139. }
  16140. };
  16141. return ToUnicodeMap;
  16142. })();
  16143. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  16144. function IdentityToUnicodeMap(firstChar, lastChar) {
  16145. this.firstChar = firstChar;
  16146. this.lastChar = lastChar;
  16147. }
  16148. IdentityToUnicodeMap.prototype = {
  16149. get length() {
  16150. return (this.lastChar + 1) - this.firstChar;
  16151. },
  16152. forEach: function (callback) {
  16153. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  16154. callback(i, i);
  16155. }
  16156. },
  16157. has: function (i) {
  16158. return this.firstChar <= i && i <= this.lastChar;
  16159. },
  16160. get: function (i) {
  16161. if (this.firstChar <= i && i <= this.lastChar) {
  16162. return String.fromCharCode(i);
  16163. }
  16164. return undefined;
  16165. },
  16166. charCodeOf: function (v) {
  16167. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  16168. }
  16169. };
  16170. return IdentityToUnicodeMap;
  16171. })();
  16172. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  16173. function writeInt16(dest, offset, num) {
  16174. dest[offset] = (num >> 8) & 0xFF;
  16175. dest[offset + 1] = num & 0xFF;
  16176. }
  16177. function writeInt32(dest, offset, num) {
  16178. dest[offset] = (num >> 24) & 0xFF;
  16179. dest[offset + 1] = (num >> 16) & 0xFF;
  16180. dest[offset + 2] = (num >> 8) & 0xFF;
  16181. dest[offset + 3] = num & 0xFF;
  16182. }
  16183. function writeData(dest, offset, data) {
  16184. var i, ii;
  16185. if (data instanceof Uint8Array) {
  16186. dest.set(data, offset);
  16187. } else if (typeof data === 'string') {
  16188. for (i = 0, ii = data.length; i < ii; i++) {
  16189. dest[offset++] = data.charCodeAt(i) & 0xFF;
  16190. }
  16191. } else {
  16192. // treating everything else as array
  16193. for (i = 0, ii = data.length; i < ii; i++) {
  16194. dest[offset++] = data[i] & 0xFF;
  16195. }
  16196. }
  16197. }
  16198. function OpenTypeFileBuilder(sfnt) {
  16199. this.sfnt = sfnt;
  16200. this.tables = Object.create(null);
  16201. }
  16202. OpenTypeFileBuilder.getSearchParams =
  16203. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  16204. var maxPower2 = 1, log2 = 0;
  16205. while ((maxPower2 ^ entriesCount) > maxPower2) {
  16206. maxPower2 <<= 1;
  16207. log2++;
  16208. }
  16209. var searchRange = maxPower2 * entrySize;
  16210. return {
  16211. range: searchRange,
  16212. entry: log2,
  16213. rangeShift: entrySize * entriesCount - searchRange
  16214. };
  16215. };
  16216. var OTF_HEADER_SIZE = 12;
  16217. var OTF_TABLE_ENTRY_SIZE = 16;
  16218. OpenTypeFileBuilder.prototype = {
  16219. toArray: function OpenTypeFileBuilder_toArray() {
  16220. var sfnt = this.sfnt;
  16221. // Tables needs to be written by ascendant alphabetic order
  16222. var tables = this.tables;
  16223. var tablesNames = Object.keys(tables);
  16224. tablesNames.sort();
  16225. var numTables = tablesNames.length;
  16226. var i, j, jj, table, tableName;
  16227. // layout the tables data
  16228. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  16229. var tableOffsets = [offset];
  16230. for (i = 0; i < numTables; i++) {
  16231. table = tables[tablesNames[i]];
  16232. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  16233. offset += paddedLength;
  16234. tableOffsets.push(offset);
  16235. }
  16236. var file = new Uint8Array(offset);
  16237. // write the table data first (mostly for checksum)
  16238. for (i = 0; i < numTables; i++) {
  16239. table = tables[tablesNames[i]];
  16240. writeData(file, tableOffsets[i], table);
  16241. }
  16242. // sfnt version (4 bytes)
  16243. if (sfnt === 'true') {
  16244. // Windows hates the Mac TrueType sfnt version number
  16245. sfnt = string32(0x00010000);
  16246. }
  16247. file[0] = sfnt.charCodeAt(0) & 0xFF;
  16248. file[1] = sfnt.charCodeAt(1) & 0xFF;
  16249. file[2] = sfnt.charCodeAt(2) & 0xFF;
  16250. file[3] = sfnt.charCodeAt(3) & 0xFF;
  16251. // numTables (2 bytes)
  16252. writeInt16(file, 4, numTables);
  16253. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  16254. // searchRange (2 bytes)
  16255. writeInt16(file, 6, searchParams.range);
  16256. // entrySelector (2 bytes)
  16257. writeInt16(file, 8, searchParams.entry);
  16258. // rangeShift (2 bytes)
  16259. writeInt16(file, 10, searchParams.rangeShift);
  16260. offset = OTF_HEADER_SIZE;
  16261. // writing table entries
  16262. for (i = 0; i < numTables; i++) {
  16263. tableName = tablesNames[i];
  16264. file[offset] = tableName.charCodeAt(0) & 0xFF;
  16265. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  16266. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  16267. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  16268. // checksum
  16269. var checksum = 0;
  16270. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  16271. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  16272. (file[j + 2] << 8) + file[j + 3];
  16273. checksum = (checksum + quad) | 0;
  16274. }
  16275. writeInt32(file, offset + 4, checksum);
  16276. // offset
  16277. writeInt32(file, offset + 8, tableOffsets[i]);
  16278. // length
  16279. writeInt32(file, offset + 12, tables[tableName].length);
  16280. offset += OTF_TABLE_ENTRY_SIZE;
  16281. }
  16282. return file;
  16283. },
  16284. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  16285. if (tag in this.tables) {
  16286. throw new Error('Table ' + tag + ' already exists');
  16287. }
  16288. this.tables[tag] = data;
  16289. }
  16290. };
  16291. return OpenTypeFileBuilder;
  16292. })();
  16293. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  16294. // issues when they are painted on the canvas, e.g. complex-script shaping or
  16295. // control/whitespace characters. The ranges are listed in pairs: the first item
  16296. // is a code of the first problematic code, the second one is the next
  16297. // non-problematic code. The ranges must be in sorted order.
  16298. var ProblematicCharRanges = new Int32Array([
  16299. // Control characters.
  16300. 0x0000, 0x0020,
  16301. 0x007F, 0x00A1,
  16302. 0x00AD, 0x00AE,
  16303. // Chars that is used in complex-script shaping.
  16304. 0x0600, 0x0780,
  16305. 0x08A0, 0x10A0,
  16306. 0x1780, 0x1800,
  16307. // General punctuation chars.
  16308. 0x2000, 0x2010,
  16309. 0x2011, 0x2012,
  16310. 0x2028, 0x2030,
  16311. 0x205F, 0x2070,
  16312. 0x25CC, 0x25CD,
  16313. // Chars that is used in complex-script shaping.
  16314. 0xAA60, 0xAA80,
  16315. // Specials Unicode block.
  16316. 0xFFF0, 0x10000
  16317. ]);
  16318. /**
  16319. * 'Font' is the class the outside world should use, it encapsulate all the font
  16320. * decoding logics whatever type it is (assuming the font type is supported).
  16321. *
  16322. * For example to read a Type1 font and to attach it to the document:
  16323. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  16324. * type1Font.bind();
  16325. */
  16326. var Font = (function FontClosure() {
  16327. function Font(name, file, properties) {
  16328. var charCode, glyphName, fontChar;
  16329. this.name = name;
  16330. this.loadedName = properties.loadedName;
  16331. this.isType3Font = properties.isType3Font;
  16332. this.sizes = [];
  16333. this.glyphCache = {};
  16334. var names = name.split('+');
  16335. names = names.length > 1 ? names[1] : names[0];
  16336. names = names.split(/[-,_]/g)[0];
  16337. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  16338. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  16339. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  16340. var type = properties.type;
  16341. var subtype = properties.subtype;
  16342. this.type = type;
  16343. this.fallbackName = (this.isMonospace ? 'monospace' :
  16344. (this.isSerifFont ? 'serif' : 'sans-serif'));
  16345. this.differences = properties.differences;
  16346. this.widths = properties.widths;
  16347. this.defaultWidth = properties.defaultWidth;
  16348. this.composite = properties.composite;
  16349. this.wideChars = properties.wideChars;
  16350. this.cMap = properties.cMap;
  16351. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  16352. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  16353. this.fontMatrix = properties.fontMatrix;
  16354. this.bbox = properties.bbox;
  16355. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  16356. this.toFontChar = [];
  16357. if (properties.type === 'Type3') {
  16358. for (charCode = 0; charCode < 256; charCode++) {
  16359. this.toFontChar[charCode] = (this.differences[charCode] ||
  16360. properties.defaultEncoding[charCode]);
  16361. }
  16362. this.fontType = FontType.TYPE3;
  16363. return;
  16364. }
  16365. this.cidEncoding = properties.cidEncoding;
  16366. this.vertical = properties.vertical;
  16367. if (this.vertical) {
  16368. this.vmetrics = properties.vmetrics;
  16369. this.defaultVMetrics = properties.defaultVMetrics;
  16370. }
  16371. if (!file || file.isEmpty) {
  16372. if (file) {
  16373. // Some bad PDF generators will include empty font files,
  16374. // attempting to recover by assuming that no file exists.
  16375. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  16376. }
  16377. this.missingFile = true;
  16378. // The file data is not specified. Trying to fix the font name
  16379. // to be used with the canvas.font.
  16380. var fontName = name.replace(/[,_]/g, '-');
  16381. var isStandardFont = !!stdFontMap[fontName] ||
  16382. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  16383. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  16384. this.bold = (fontName.search(/bold/gi) !== -1);
  16385. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  16386. (fontName.search(/italic/gi) !== -1));
  16387. // Use 'name' instead of 'fontName' here because the original
  16388. // name ArialBlack for example will be replaced by Helvetica.
  16389. this.black = (name.search(/Black/g) !== -1);
  16390. // if at least one width is present, remeasure all chars when exists
  16391. this.remeasure = Object.keys(this.widths).length > 0;
  16392. if (isStandardFont && type === 'CIDFontType2' &&
  16393. properties.cidEncoding.indexOf('Identity-') === 0) {
  16394. // Standard fonts might be embedded as CID font without glyph mapping.
  16395. // Building one based on GlyphMapForStandardFonts.
  16396. var map = [];
  16397. for (charCode in GlyphMapForStandardFonts) {
  16398. map[+charCode] = GlyphMapForStandardFonts[charCode];
  16399. }
  16400. if (/ArialBlack/i.test(name)) {
  16401. for (charCode in SupplementalGlyphMapForArialBlack) {
  16402. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  16403. }
  16404. }
  16405. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  16406. if (!isIdentityUnicode) {
  16407. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  16408. map[+charCode] = unicodeCharCode;
  16409. });
  16410. }
  16411. this.toFontChar = map;
  16412. this.toUnicode = new ToUnicodeMap(map);
  16413. } else if (/Symbol/i.test(fontName)) {
  16414. var symbols = Encodings.SymbolSetEncoding;
  16415. for (charCode in symbols) {
  16416. fontChar = GlyphsUnicode[symbols[charCode]];
  16417. if (!fontChar) {
  16418. continue;
  16419. }
  16420. this.toFontChar[charCode] = fontChar;
  16421. }
  16422. for (charCode in properties.differences) {
  16423. fontChar = GlyphsUnicode[properties.differences[charCode]];
  16424. if (!fontChar) {
  16425. continue;
  16426. }
  16427. this.toFontChar[charCode] = fontChar;
  16428. }
  16429. } else if (/Dingbats/i.test(fontName)) {
  16430. if (/Wingdings/i.test(name)) {
  16431. warn('Wingdings font without embedded font file, ' +
  16432. 'falling back to the ZapfDingbats encoding.');
  16433. }
  16434. var dingbats = Encodings.ZapfDingbatsEncoding;
  16435. for (charCode in dingbats) {
  16436. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  16437. if (!fontChar) {
  16438. continue;
  16439. }
  16440. this.toFontChar[charCode] = fontChar;
  16441. }
  16442. for (charCode in properties.differences) {
  16443. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  16444. if (!fontChar) {
  16445. continue;
  16446. }
  16447. this.toFontChar[charCode] = fontChar;
  16448. }
  16449. } else if (isStandardFont) {
  16450. this.toFontChar = [];
  16451. for (charCode in properties.defaultEncoding) {
  16452. glyphName = (properties.differences[charCode] ||
  16453. properties.defaultEncoding[charCode]);
  16454. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  16455. }
  16456. } else {
  16457. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  16458. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  16459. if (notCidFont) {
  16460. glyphName = (properties.differences[charCode] ||
  16461. properties.defaultEncoding[charCode]);
  16462. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  16463. }
  16464. this.toFontChar[charCode] = unicodeCharCode;
  16465. }.bind(this));
  16466. }
  16467. this.loadedName = fontName.split('-')[0];
  16468. this.loading = false;
  16469. this.fontType = getFontType(type, subtype);
  16470. return;
  16471. }
  16472. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  16473. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  16474. // Some TrueType fonts by mistake claim Type1C
  16475. if (isTrueTypeFile(file)) {
  16476. subtype = 'TrueType';
  16477. } else {
  16478. type = 'Type1';
  16479. }
  16480. }
  16481. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  16482. type = 'CIDFontType0';
  16483. }
  16484. if (subtype === 'OpenType') {
  16485. type = 'OpenType';
  16486. }
  16487. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  16488. if (type === 'CIDFontType0') {
  16489. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  16490. }
  16491. var data;
  16492. switch (type) {
  16493. case 'MMType1':
  16494. info('MMType1 font (' + name + '), falling back to Type1.');
  16495. /* falls through */
  16496. case 'Type1':
  16497. case 'CIDFontType0':
  16498. this.mimetype = 'font/opentype';
  16499. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  16500. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  16501. adjustWidths(properties);
  16502. // Wrap the CFF data inside an OTF font file
  16503. data = this.convert(name, cff, properties);
  16504. break;
  16505. case 'OpenType':
  16506. case 'TrueType':
  16507. case 'CIDFontType2':
  16508. this.mimetype = 'font/opentype';
  16509. // Repair the TrueType file. It is can be damaged in the point of
  16510. // view of the sanitizer
  16511. data = this.checkAndRepair(name, file, properties);
  16512. if (this.isOpenType) {
  16513. adjustWidths(properties);
  16514. type = 'OpenType';
  16515. }
  16516. break;
  16517. default:
  16518. error('Font ' + type + ' is not supported');
  16519. break;
  16520. }
  16521. this.data = data;
  16522. this.fontType = getFontType(type, subtype);
  16523. // Transfer some properties again that could change during font conversion
  16524. this.fontMatrix = properties.fontMatrix;
  16525. this.widths = properties.widths;
  16526. this.defaultWidth = properties.defaultWidth;
  16527. this.encoding = properties.baseEncoding;
  16528. this.seacMap = properties.seacMap;
  16529. this.loading = true;
  16530. }
  16531. Font.getFontID = (function () {
  16532. var ID = 1;
  16533. return function Font_getFontID() {
  16534. return String(ID++);
  16535. };
  16536. })();
  16537. function int16(b0, b1) {
  16538. return (b0 << 8) + b1;
  16539. }
  16540. function int32(b0, b1, b2, b3) {
  16541. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  16542. }
  16543. function string16(value) {
  16544. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  16545. }
  16546. function safeString16(value) {
  16547. // clamp value to the 16-bit int range
  16548. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  16549. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  16550. }
  16551. function isTrueTypeFile(file) {
  16552. var header = file.peekBytes(4);
  16553. return readUint32(header, 0) === 0x00010000;
  16554. }
  16555. function isType1File(file) {
  16556. var header = file.peekBytes(2);
  16557. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  16558. if (header[0] === 0x25 && header[1] === 0x21) {
  16559. return true;
  16560. }
  16561. // ... obviously some fonts violate that part of the specification,
  16562. // please refer to the comment in |Type1Font| below.
  16563. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  16564. return true;
  16565. }
  16566. return false;
  16567. }
  16568. /**
  16569. * Helper function for |adjustMapping|.
  16570. * @return {boolean}
  16571. */
  16572. function isProblematicUnicodeLocation(code) {
  16573. // Using binary search to find a range start.
  16574. var i = 0, j = ProblematicCharRanges.length - 1;
  16575. while (i < j) {
  16576. var c = (i + j + 1) >> 1;
  16577. if (code < ProblematicCharRanges[c]) {
  16578. j = c - 1;
  16579. } else {
  16580. i = c;
  16581. }
  16582. }
  16583. // Even index means code in problematic range.
  16584. return !(i & 1);
  16585. }
  16586. /**
  16587. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  16588. * with their unicode value. It also moves char codes that are in known
  16589. * problematic locations.
  16590. * @return {Object} Two properties:
  16591. * 'toFontChar' - maps original char codes(the value that will be read
  16592. * from commands such as show text) to the char codes that will be used in the
  16593. * font that we build
  16594. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  16595. */
  16596. function adjustMapping(charCodeToGlyphId, properties) {
  16597. var toUnicode = properties.toUnicode;
  16598. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  16599. var isIdentityUnicode =
  16600. properties.toUnicode instanceof IdentityToUnicodeMap;
  16601. var newMap = Object.create(null);
  16602. var toFontChar = [];
  16603. var usedFontCharCodes = [];
  16604. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  16605. for (var originalCharCode in charCodeToGlyphId) {
  16606. originalCharCode |= 0;
  16607. var glyphId = charCodeToGlyphId[originalCharCode];
  16608. var fontCharCode = originalCharCode;
  16609. // First try to map the value to a unicode position if a non identity map
  16610. // was created.
  16611. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  16612. var unicode = toUnicode.get(fontCharCode);
  16613. // TODO: Try to map ligatures to the correct spot.
  16614. if (unicode.length === 1) {
  16615. fontCharCode = unicode.charCodeAt(0);
  16616. }
  16617. }
  16618. // Try to move control characters, special characters and already mapped
  16619. // characters to the private use area since they will not be drawn by
  16620. // canvas if left in their current position. Also, move characters if the
  16621. // font was symbolic and there is only an identity unicode map since the
  16622. // characters probably aren't in the correct position (fixes an issue
  16623. // with firefox and thuluthfont).
  16624. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  16625. isProblematicUnicodeLocation(fontCharCode) ||
  16626. (isSymbolic && isIdentityUnicode)) &&
  16627. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  16628. // Loop to try and find a free spot in the private use area.
  16629. do {
  16630. fontCharCode = nextAvailableFontCharCode++;
  16631. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  16632. fontCharCode = 0xF020;
  16633. nextAvailableFontCharCode = fontCharCode + 1;
  16634. }
  16635. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  16636. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  16637. }
  16638. newMap[fontCharCode] = glyphId;
  16639. toFontChar[originalCharCode] = fontCharCode;
  16640. usedFontCharCodes[fontCharCode] = true;
  16641. }
  16642. return {
  16643. toFontChar: toFontChar,
  16644. charCodeToGlyphId: newMap,
  16645. nextAvailableFontCharCode: nextAvailableFontCharCode
  16646. };
  16647. }
  16648. function getRanges(glyphs, numGlyphs) {
  16649. // Array.sort() sorts by characters, not numerically, so convert to an
  16650. // array of characters.
  16651. var codes = [];
  16652. for (var charCode in glyphs) {
  16653. // Remove an invalid glyph ID mappings to make OTS happy.
  16654. if (glyphs[charCode] >= numGlyphs) {
  16655. continue;
  16656. }
  16657. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  16658. }
  16659. codes.sort(function fontGetRangesSort(a, b) {
  16660. return a.fontCharCode - b.fontCharCode;
  16661. });
  16662. // Split the sorted codes into ranges.
  16663. var ranges = [];
  16664. var length = codes.length;
  16665. for (var n = 0; n < length; ) {
  16666. var start = codes[n].fontCharCode;
  16667. var codeIndices = [codes[n].glyphId];
  16668. ++n;
  16669. var end = start;
  16670. while (n < length && end + 1 === codes[n].fontCharCode) {
  16671. codeIndices.push(codes[n].glyphId);
  16672. ++end;
  16673. ++n;
  16674. if (end === 0xFFFF) {
  16675. break;
  16676. }
  16677. }
  16678. ranges.push([start, end, codeIndices]);
  16679. }
  16680. return ranges;
  16681. }
  16682. function createCmapTable(glyphs, numGlyphs) {
  16683. var ranges = getRanges(glyphs, numGlyphs);
  16684. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  16685. var cmap = '\x00\x00' + // version
  16686. string16(numTables) + // numTables
  16687. '\x00\x03' + // platformID
  16688. '\x00\x01' + // encodingID
  16689. string32(4 + numTables * 8); // start of the table record
  16690. var i, ii, j, jj;
  16691. for (i = ranges.length - 1; i >= 0; --i) {
  16692. if (ranges[i][0] <= 0xFFFF) { break; }
  16693. }
  16694. var bmpLength = i + 1;
  16695. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  16696. ranges[i][1] = 0xFFFE;
  16697. }
  16698. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  16699. var segCount = bmpLength + trailingRangesCount;
  16700. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  16701. // Fill up the 4 parallel arrays describing the segments.
  16702. var startCount = '';
  16703. var endCount = '';
  16704. var idDeltas = '';
  16705. var idRangeOffsets = '';
  16706. var glyphsIds = '';
  16707. var bias = 0;
  16708. var range, start, end, codes;
  16709. for (i = 0, ii = bmpLength; i < ii; i++) {
  16710. range = ranges[i];
  16711. start = range[0];
  16712. end = range[1];
  16713. startCount += string16(start);
  16714. endCount += string16(end);
  16715. codes = range[2];
  16716. var contiguous = true;
  16717. for (j = 1, jj = codes.length; j < jj; ++j) {
  16718. if (codes[j] !== codes[j - 1] + 1) {
  16719. contiguous = false;
  16720. break;
  16721. }
  16722. }
  16723. if (!contiguous) {
  16724. var offset = (segCount - i) * 2 + bias * 2;
  16725. bias += (end - start + 1);
  16726. idDeltas += string16(0);
  16727. idRangeOffsets += string16(offset);
  16728. for (j = 0, jj = codes.length; j < jj; ++j) {
  16729. glyphsIds += string16(codes[j]);
  16730. }
  16731. } else {
  16732. var startCode = codes[0];
  16733. idDeltas += string16((startCode - start) & 0xFFFF);
  16734. idRangeOffsets += string16(0);
  16735. }
  16736. }
  16737. if (trailingRangesCount > 0) {
  16738. endCount += '\xFF\xFF';
  16739. startCount += '\xFF\xFF';
  16740. idDeltas += '\x00\x01';
  16741. idRangeOffsets += '\x00\x00';
  16742. }
  16743. var format314 = '\x00\x00' + // language
  16744. string16(2 * segCount) +
  16745. string16(searchParams.range) +
  16746. string16(searchParams.entry) +
  16747. string16(searchParams.rangeShift) +
  16748. endCount + '\x00\x00' + startCount +
  16749. idDeltas + idRangeOffsets + glyphsIds;
  16750. var format31012 = '';
  16751. var header31012 = '';
  16752. if (numTables > 1) {
  16753. cmap += '\x00\x03' + // platformID
  16754. '\x00\x0A' + // encodingID
  16755. string32(4 + numTables * 8 +
  16756. 4 + format314.length); // start of the table record
  16757. format31012 = '';
  16758. for (i = 0, ii = ranges.length; i < ii; i++) {
  16759. range = ranges[i];
  16760. start = range[0];
  16761. codes = range[2];
  16762. var code = codes[0];
  16763. for (j = 1, jj = codes.length; j < jj; ++j) {
  16764. if (codes[j] !== codes[j - 1] + 1) {
  16765. end = range[0] + j - 1;
  16766. format31012 += string32(start) + // startCharCode
  16767. string32(end) + // endCharCode
  16768. string32(code); // startGlyphID
  16769. start = end + 1;
  16770. code = codes[j];
  16771. }
  16772. }
  16773. format31012 += string32(start) + // startCharCode
  16774. string32(range[1]) + // endCharCode
  16775. string32(code); // startGlyphID
  16776. }
  16777. header31012 = '\x00\x0C' + // format
  16778. '\x00\x00' + // reserved
  16779. string32(format31012.length + 16) + // length
  16780. '\x00\x00\x00\x00' + // language
  16781. string32(format31012.length / 12); // nGroups
  16782. }
  16783. return cmap + '\x00\x04' + // format
  16784. string16(format314.length + 4) + // length
  16785. format314 + header31012 + format31012;
  16786. }
  16787. function validateOS2Table(os2) {
  16788. var stream = new Stream(os2.data);
  16789. var version = stream.getUint16();
  16790. // TODO verify all OS/2 tables fields, but currently we validate only those
  16791. // that give us issues
  16792. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  16793. var selection = stream.getUint16();
  16794. if (version < 4 && (selection & 0x0300)) {
  16795. return false;
  16796. }
  16797. var firstChar = stream.getUint16();
  16798. var lastChar = stream.getUint16();
  16799. if (firstChar > lastChar) {
  16800. return false;
  16801. }
  16802. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  16803. var usWinAscent = stream.getUint16();
  16804. if (usWinAscent === 0) { // makes font unreadable by windows
  16805. return false;
  16806. }
  16807. // OS/2 appears to be valid, resetting some fields
  16808. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  16809. return true;
  16810. }
  16811. function createOS2Table(properties, charstrings, override) {
  16812. override = override || {
  16813. unitsPerEm: 0,
  16814. yMax: 0,
  16815. yMin: 0,
  16816. ascent: 0,
  16817. descent: 0
  16818. };
  16819. var ulUnicodeRange1 = 0;
  16820. var ulUnicodeRange2 = 0;
  16821. var ulUnicodeRange3 = 0;
  16822. var ulUnicodeRange4 = 0;
  16823. var firstCharIndex = null;
  16824. var lastCharIndex = 0;
  16825. if (charstrings) {
  16826. for (var code in charstrings) {
  16827. code |= 0;
  16828. if (firstCharIndex > code || !firstCharIndex) {
  16829. firstCharIndex = code;
  16830. }
  16831. if (lastCharIndex < code) {
  16832. lastCharIndex = code;
  16833. }
  16834. var position = getUnicodeRangeFor(code);
  16835. if (position < 32) {
  16836. ulUnicodeRange1 |= 1 << position;
  16837. } else if (position < 64) {
  16838. ulUnicodeRange2 |= 1 << position - 32;
  16839. } else if (position < 96) {
  16840. ulUnicodeRange3 |= 1 << position - 64;
  16841. } else if (position < 123) {
  16842. ulUnicodeRange4 |= 1 << position - 96;
  16843. } else {
  16844. error('Unicode ranges Bits > 123 are reserved for internal usage');
  16845. }
  16846. }
  16847. } else {
  16848. // TODO
  16849. firstCharIndex = 0;
  16850. lastCharIndex = 255;
  16851. }
  16852. var bbox = properties.bbox || [0, 0, 0, 0];
  16853. var unitsPerEm = (override.unitsPerEm ||
  16854. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  16855. // if the font units differ to the PDF glyph space units
  16856. // then scale up the values
  16857. var scale = (properties.ascentScaled ? 1.0 :
  16858. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  16859. var typoAscent = (override.ascent ||
  16860. Math.round(scale * (properties.ascent || bbox[3])));
  16861. var typoDescent = (override.descent ||
  16862. Math.round(scale * (properties.descent || bbox[1])));
  16863. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  16864. typoDescent = -typoDescent; // fixing incorrect descent
  16865. }
  16866. var winAscent = override.yMax || typoAscent;
  16867. var winDescent = -override.yMin || -typoDescent;
  16868. return '\x00\x03' + // version
  16869. '\x02\x24' + // xAvgCharWidth
  16870. '\x01\xF4' + // usWeightClass
  16871. '\x00\x05' + // usWidthClass
  16872. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  16873. '\x02\x8A' + // ySubscriptXSize
  16874. '\x02\xBB' + // ySubscriptYSize
  16875. '\x00\x00' + // ySubscriptXOffset
  16876. '\x00\x8C' + // ySubscriptYOffset
  16877. '\x02\x8A' + // ySuperScriptXSize
  16878. '\x02\xBB' + // ySuperScriptYSize
  16879. '\x00\x00' + // ySuperScriptXOffset
  16880. '\x01\xDF' + // ySuperScriptYOffset
  16881. '\x00\x31' + // yStrikeOutSize
  16882. '\x01\x02' + // yStrikeOutPosition
  16883. '\x00\x00' + // sFamilyClass
  16884. '\x00\x00\x06' +
  16885. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  16886. '\x00\x00\x00\x00\x00\x00' + // Panose
  16887. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  16888. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  16889. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  16890. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  16891. '\x2A\x32\x31\x2A' + // achVendID
  16892. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  16893. string16(firstCharIndex ||
  16894. properties.firstChar) + // usFirstCharIndex
  16895. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  16896. string16(typoAscent) + // sTypoAscender
  16897. string16(typoDescent) + // sTypoDescender
  16898. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  16899. string16(winAscent) + // usWinAscent
  16900. string16(winDescent) + // usWinDescent
  16901. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  16902. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  16903. string16(properties.xHeight) + // sxHeight
  16904. string16(properties.capHeight) + // sCapHeight
  16905. string16(0) + // usDefaultChar
  16906. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  16907. '\x00\x03'; // usMaxContext
  16908. }
  16909. function createPostTable(properties) {
  16910. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  16911. return ('\x00\x03\x00\x00' + // Version number
  16912. string32(angle) + // italicAngle
  16913. '\x00\x00' + // underlinePosition
  16914. '\x00\x00' + // underlineThickness
  16915. string32(properties.fixedPitch) + // isFixedPitch
  16916. '\x00\x00\x00\x00' + // minMemType42
  16917. '\x00\x00\x00\x00' + // maxMemType42
  16918. '\x00\x00\x00\x00' + // minMemType1
  16919. '\x00\x00\x00\x00'); // maxMemType1
  16920. }
  16921. function createNameTable(name, proto) {
  16922. if (!proto) {
  16923. proto = [[], []]; // no strings and unicode strings
  16924. }
  16925. var strings = [
  16926. proto[0][0] || 'Original licence', // 0.Copyright
  16927. proto[0][1] || name, // 1.Font family
  16928. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  16929. proto[0][3] || 'uniqueID', // 3.Unique ID
  16930. proto[0][4] || name, // 4.Full font name
  16931. proto[0][5] || 'Version 0.11', // 5.Version
  16932. proto[0][6] || '', // 6.Postscript name
  16933. proto[0][7] || 'Unknown', // 7.Trademark
  16934. proto[0][8] || 'Unknown', // 8.Manufacturer
  16935. proto[0][9] || 'Unknown' // 9.Designer
  16936. ];
  16937. // Mac want 1-byte per character strings while Windows want
  16938. // 2-bytes per character, so duplicate the names table
  16939. var stringsUnicode = [];
  16940. var i, ii, j, jj, str;
  16941. for (i = 0, ii = strings.length; i < ii; i++) {
  16942. str = proto[1][i] || strings[i];
  16943. var strBufUnicode = [];
  16944. for (j = 0, jj = str.length; j < jj; j++) {
  16945. strBufUnicode.push(string16(str.charCodeAt(j)));
  16946. }
  16947. stringsUnicode.push(strBufUnicode.join(''));
  16948. }
  16949. var names = [strings, stringsUnicode];
  16950. var platforms = ['\x00\x01', '\x00\x03'];
  16951. var encodings = ['\x00\x00', '\x00\x01'];
  16952. var languages = ['\x00\x00', '\x04\x09'];
  16953. var namesRecordCount = strings.length * platforms.length;
  16954. var nameTable =
  16955. '\x00\x00' + // format
  16956. string16(namesRecordCount) + // Number of names Record
  16957. string16(namesRecordCount * 12 + 6); // Storage
  16958. // Build the name records field
  16959. var strOffset = 0;
  16960. for (i = 0, ii = platforms.length; i < ii; i++) {
  16961. var strs = names[i];
  16962. for (j = 0, jj = strs.length; j < jj; j++) {
  16963. str = strs[j];
  16964. var nameRecord =
  16965. platforms[i] + // platform ID
  16966. encodings[i] + // encoding ID
  16967. languages[i] + // language ID
  16968. string16(j) + // name ID
  16969. string16(str.length) +
  16970. string16(strOffset);
  16971. nameTable += nameRecord;
  16972. strOffset += str.length;
  16973. }
  16974. }
  16975. nameTable += strings.join('') + stringsUnicode.join('');
  16976. return nameTable;
  16977. }
  16978. Font.prototype = {
  16979. name: null,
  16980. font: null,
  16981. mimetype: null,
  16982. encoding: null,
  16983. get renderer() {
  16984. var renderer = FontRendererFactory.create(this);
  16985. return shadow(this, 'renderer', renderer);
  16986. },
  16987. exportData: function Font_exportData() {
  16988. var data = {};
  16989. for (var i in this) {
  16990. if (this.hasOwnProperty(i)) {
  16991. data[i] = this[i];
  16992. }
  16993. }
  16994. return data;
  16995. },
  16996. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  16997. function readTableEntry(file) {
  16998. var tag = bytesToString(file.getBytes(4));
  16999. var checksum = file.getInt32();
  17000. var offset = file.getInt32() >>> 0;
  17001. var length = file.getInt32() >>> 0;
  17002. // Read the table associated data
  17003. var previousPosition = file.pos;
  17004. file.pos = file.start ? file.start : 0;
  17005. file.skip(offset);
  17006. var data = file.getBytes(length);
  17007. file.pos = previousPosition;
  17008. if (tag === 'head') {
  17009. // clearing checksum adjustment
  17010. data[8] = data[9] = data[10] = data[11] = 0;
  17011. data[17] |= 0x20; //Set font optimized for cleartype flag
  17012. }
  17013. return {
  17014. tag: tag,
  17015. checksum: checksum,
  17016. length: length,
  17017. offset: offset,
  17018. data: data
  17019. };
  17020. }
  17021. function readOpenTypeHeader(ttf) {
  17022. return {
  17023. version: bytesToString(ttf.getBytes(4)),
  17024. numTables: ttf.getUint16(),
  17025. searchRange: ttf.getUint16(),
  17026. entrySelector: ttf.getUint16(),
  17027. rangeShift: ttf.getUint16()
  17028. };
  17029. }
  17030. /**
  17031. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  17032. * PDF spec
  17033. */
  17034. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  17035. if (!cmap) {
  17036. warn('No cmap table available.');
  17037. return {
  17038. platformId: -1,
  17039. encodingId: -1,
  17040. mappings: [],
  17041. hasShortCmap: false
  17042. };
  17043. }
  17044. var segment;
  17045. var start = (font.start ? font.start : 0) + cmap.offset;
  17046. font.pos = start;
  17047. var version = font.getUint16();
  17048. var numTables = font.getUint16();
  17049. var potentialTable;
  17050. var canBreak = false;
  17051. // There's an order of preference in terms of which cmap subtable to
  17052. // use:
  17053. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  17054. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  17055. // The following takes advantage of the fact that the tables are sorted
  17056. // to work.
  17057. for (var i = 0; i < numTables; i++) {
  17058. var platformId = font.getUint16();
  17059. var encodingId = font.getUint16();
  17060. var offset = font.getInt32() >>> 0;
  17061. var useTable = false;
  17062. if (platformId === 0 && encodingId === 0) {
  17063. useTable = true;
  17064. // Continue the loop since there still may be a higher priority
  17065. // table.
  17066. } else if (platformId === 1 && encodingId === 0) {
  17067. useTable = true;
  17068. // Continue the loop since there still may be a higher priority
  17069. // table.
  17070. } else if (platformId === 3 && encodingId === 1 &&
  17071. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  17072. useTable = true;
  17073. if (!isSymbolicFont) {
  17074. canBreak = true;
  17075. }
  17076. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  17077. useTable = true;
  17078. canBreak = true;
  17079. }
  17080. if (useTable) {
  17081. potentialTable = {
  17082. platformId: platformId,
  17083. encodingId: encodingId,
  17084. offset: offset
  17085. };
  17086. }
  17087. if (canBreak) {
  17088. break;
  17089. }
  17090. }
  17091. if (potentialTable) {
  17092. font.pos = start + potentialTable.offset;
  17093. }
  17094. if (!potentialTable || font.peekByte() === -1) {
  17095. warn('Could not find a preferred cmap table.');
  17096. return {
  17097. platformId: -1,
  17098. encodingId: -1,
  17099. mappings: [],
  17100. hasShortCmap: false
  17101. };
  17102. }
  17103. var format = font.getUint16();
  17104. var length = font.getUint16();
  17105. var language = font.getUint16();
  17106. var hasShortCmap = false;
  17107. var mappings = [];
  17108. var j, glyphId;
  17109. // TODO(mack): refactor this cmap subtable reading logic out
  17110. if (format === 0) {
  17111. for (j = 0; j < 256; j++) {
  17112. var index = font.getByte();
  17113. if (!index) {
  17114. continue;
  17115. }
  17116. mappings.push({
  17117. charCode: j,
  17118. glyphId: index
  17119. });
  17120. }
  17121. hasShortCmap = true;
  17122. } else if (format === 4) {
  17123. // re-creating the table in format 4 since the encoding
  17124. // might be changed
  17125. var segCount = (font.getUint16() >> 1);
  17126. font.getBytes(6); // skipping range fields
  17127. var segIndex, segments = [];
  17128. for (segIndex = 0; segIndex < segCount; segIndex++) {
  17129. segments.push({ end: font.getUint16() });
  17130. }
  17131. font.getUint16();
  17132. for (segIndex = 0; segIndex < segCount; segIndex++) {
  17133. segments[segIndex].start = font.getUint16();
  17134. }
  17135. for (segIndex = 0; segIndex < segCount; segIndex++) {
  17136. segments[segIndex].delta = font.getUint16();
  17137. }
  17138. var offsetsCount = 0;
  17139. for (segIndex = 0; segIndex < segCount; segIndex++) {
  17140. segment = segments[segIndex];
  17141. var rangeOffset = font.getUint16();
  17142. if (!rangeOffset) {
  17143. segment.offsetIndex = -1;
  17144. continue;
  17145. }
  17146. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  17147. segment.offsetIndex = offsetIndex;
  17148. offsetsCount = Math.max(offsetsCount, offsetIndex +
  17149. segment.end - segment.start + 1);
  17150. }
  17151. var offsets = [];
  17152. for (j = 0; j < offsetsCount; j++) {
  17153. offsets.push(font.getUint16());
  17154. }
  17155. for (segIndex = 0; segIndex < segCount; segIndex++) {
  17156. segment = segments[segIndex];
  17157. start = segment.start;
  17158. var end = segment.end;
  17159. var delta = segment.delta;
  17160. offsetIndex = segment.offsetIndex;
  17161. for (j = start; j <= end; j++) {
  17162. if (j === 0xFFFF) {
  17163. continue;
  17164. }
  17165. glyphId = (offsetIndex < 0 ?
  17166. j : offsets[offsetIndex + j - start]);
  17167. glyphId = (glyphId + delta) & 0xFFFF;
  17168. if (glyphId === 0) {
  17169. continue;
  17170. }
  17171. mappings.push({
  17172. charCode: j,
  17173. glyphId: glyphId
  17174. });
  17175. }
  17176. }
  17177. } else if (format === 6) {
  17178. // Format 6 is a 2-bytes dense mapping, which means the font data
  17179. // lives glue together even if they are pretty far in the unicode
  17180. // table. (This looks weird, so I can have missed something), this
  17181. // works on Linux but seems to fails on Mac so let's rewrite the
  17182. // cmap table to a 3-1-4 style
  17183. var firstCode = font.getUint16();
  17184. var entryCount = font.getUint16();
  17185. for (j = 0; j < entryCount; j++) {
  17186. glyphId = font.getUint16();
  17187. var charCode = firstCode + j;
  17188. mappings.push({
  17189. charCode: charCode,
  17190. glyphId: glyphId
  17191. });
  17192. }
  17193. } else {
  17194. warn('cmap table has unsupported format: ' + format);
  17195. return {
  17196. platformId: -1,
  17197. encodingId: -1,
  17198. mappings: [],
  17199. hasShortCmap: false
  17200. };
  17201. }
  17202. // removing duplicate entries
  17203. mappings.sort(function (a, b) {
  17204. return a.charCode - b.charCode;
  17205. });
  17206. for (i = 1; i < mappings.length; i++) {
  17207. if (mappings[i - 1].charCode === mappings[i].charCode) {
  17208. mappings.splice(i, 1);
  17209. i--;
  17210. }
  17211. }
  17212. return {
  17213. platformId: potentialTable.platformId,
  17214. encodingId: potentialTable.encodingId,
  17215. mappings: mappings,
  17216. hasShortCmap: hasShortCmap
  17217. };
  17218. }
  17219. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  17220. if (!header) {
  17221. if (metrics) {
  17222. metrics.data = null;
  17223. }
  17224. return;
  17225. }
  17226. font.pos = (font.start ? font.start : 0) + header.offset;
  17227. font.pos += header.length - 2;
  17228. var numOfMetrics = font.getUint16();
  17229. if (numOfMetrics > numGlyphs) {
  17230. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  17231. 'greater than the numGlyphs (' + numGlyphs + ')');
  17232. // Reduce numOfMetrics if it is greater than numGlyphs
  17233. numOfMetrics = numGlyphs;
  17234. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  17235. header.data[35] = numOfMetrics & 0x00ff;
  17236. }
  17237. var numOfSidebearings = numGlyphs - numOfMetrics;
  17238. var numMissing = numOfSidebearings -
  17239. ((metrics.length - numOfMetrics * 4) >> 1);
  17240. if (numMissing > 0) {
  17241. // For each missing glyph, we set both the width and lsb to 0 (zero).
  17242. // Since we need to add two properties for each glyph, this explains
  17243. // the use of |numMissing * 2| when initializing the typed array.
  17244. var entries = new Uint8Array(metrics.length + numMissing * 2);
  17245. entries.set(metrics.data);
  17246. metrics.data = entries;
  17247. }
  17248. }
  17249. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  17250. hintsValid) {
  17251. if (sourceEnd - sourceStart <= 12) {
  17252. // glyph with data less than 12 is invalid one
  17253. return 0;
  17254. }
  17255. var glyf = source.subarray(sourceStart, sourceEnd);
  17256. var contoursCount = (glyf[0] << 8) | glyf[1];
  17257. if (contoursCount & 0x8000) {
  17258. // complex glyph, writing as is
  17259. dest.set(glyf, destStart);
  17260. return glyf.length;
  17261. }
  17262. var i, j = 10, flagsCount = 0;
  17263. for (i = 0; i < contoursCount; i++) {
  17264. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  17265. flagsCount = endPoint + 1;
  17266. j += 2;
  17267. }
  17268. // skipping instructions
  17269. var instructionsStart = j;
  17270. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  17271. j += 2 + instructionsLength;
  17272. var instructionsEnd = j;
  17273. // validating flags
  17274. var coordinatesLength = 0;
  17275. for (i = 0; i < flagsCount; i++) {
  17276. var flag = glyf[j++];
  17277. if (flag & 0xC0) {
  17278. // reserved flags must be zero, cleaning up
  17279. glyf[j - 1] = flag & 0x3F;
  17280. }
  17281. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  17282. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  17283. coordinatesLength += xyLength;
  17284. if (flag & 8) {
  17285. var repeat = glyf[j++];
  17286. i += repeat;
  17287. coordinatesLength += repeat * xyLength;
  17288. }
  17289. }
  17290. // glyph without coordinates will be rejected
  17291. if (coordinatesLength === 0) {
  17292. return 0;
  17293. }
  17294. var glyphDataLength = j + coordinatesLength;
  17295. if (glyphDataLength > glyf.length) {
  17296. // not enough data for coordinates
  17297. return 0;
  17298. }
  17299. if (!hintsValid && instructionsLength > 0) {
  17300. dest.set(glyf.subarray(0, instructionsStart), destStart);
  17301. dest.set([0, 0], destStart + instructionsStart);
  17302. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  17303. destStart + instructionsStart + 2);
  17304. glyphDataLength -= instructionsLength;
  17305. if (glyf.length - glyphDataLength > 3) {
  17306. glyphDataLength = (glyphDataLength + 3) & ~3;
  17307. }
  17308. return glyphDataLength;
  17309. }
  17310. if (glyf.length - glyphDataLength > 3) {
  17311. // truncating and aligning to 4 bytes the long glyph data
  17312. glyphDataLength = (glyphDataLength + 3) & ~3;
  17313. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  17314. return glyphDataLength;
  17315. }
  17316. // glyph data is fine
  17317. dest.set(glyf, destStart);
  17318. return glyf.length;
  17319. }
  17320. function sanitizeHead(head, numGlyphs, locaLength) {
  17321. var data = head.data;
  17322. // Validate version:
  17323. // Should always be 0x00010000
  17324. var version = int32(data[0], data[1], data[2], data[3]);
  17325. if (version >> 16 !== 1) {
  17326. info('Attempting to fix invalid version in head table: ' + version);
  17327. data[0] = 0;
  17328. data[1] = 1;
  17329. data[2] = 0;
  17330. data[3] = 0;
  17331. }
  17332. var indexToLocFormat = int16(data[50], data[51]);
  17333. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  17334. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  17335. indexToLocFormat);
  17336. // The value of indexToLocFormat should be 0 if the loca table
  17337. // consists of short offsets, and should be 1 if the loca table
  17338. // consists of long offsets.
  17339. //
  17340. // The number of entries in the loca table should be numGlyphs + 1.
  17341. //
  17342. // Using this information, we can work backwards to deduce if the
  17343. // size of each offset in the loca table, and thus figure out the
  17344. // appropriate value for indexToLocFormat.
  17345. var numGlyphsPlusOne = numGlyphs + 1;
  17346. if (locaLength === numGlyphsPlusOne << 1) {
  17347. // 0x0000 indicates the loca table consists of short offsets
  17348. data[50] = 0;
  17349. data[51] = 0;
  17350. } else if (locaLength === numGlyphsPlusOne << 2) {
  17351. // 0x0001 indicates the loca table consists of long offsets
  17352. data[50] = 0;
  17353. data[51] = 1;
  17354. } else {
  17355. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  17356. }
  17357. }
  17358. }
  17359. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  17360. isGlyphLocationsLong, hintsValid,
  17361. dupFirstEntry) {
  17362. var itemSize, itemDecode, itemEncode;
  17363. if (isGlyphLocationsLong) {
  17364. itemSize = 4;
  17365. itemDecode = function fontItemDecodeLong(data, offset) {
  17366. return (data[offset] << 24) | (data[offset + 1] << 16) |
  17367. (data[offset + 2] << 8) | data[offset + 3];
  17368. };
  17369. itemEncode = function fontItemEncodeLong(data, offset, value) {
  17370. data[offset] = (value >>> 24) & 0xFF;
  17371. data[offset + 1] = (value >> 16) & 0xFF;
  17372. data[offset + 2] = (value >> 8) & 0xFF;
  17373. data[offset + 3] = value & 0xFF;
  17374. };
  17375. } else {
  17376. itemSize = 2;
  17377. itemDecode = function fontItemDecode(data, offset) {
  17378. return (data[offset] << 9) | (data[offset + 1] << 1);
  17379. };
  17380. itemEncode = function fontItemEncode(data, offset, value) {
  17381. data[offset] = (value >> 9) & 0xFF;
  17382. data[offset + 1] = (value >> 1) & 0xFF;
  17383. };
  17384. }
  17385. var locaData = loca.data;
  17386. var locaDataSize = itemSize * (1 + numGlyphs);
  17387. // is loca.data too short or long?
  17388. if (locaData.length !== locaDataSize) {
  17389. locaData = new Uint8Array(locaDataSize);
  17390. locaData.set(loca.data.subarray(0, locaDataSize));
  17391. loca.data = locaData;
  17392. }
  17393. // removing the invalid glyphs
  17394. var oldGlyfData = glyf.data;
  17395. var oldGlyfDataLength = oldGlyfData.length;
  17396. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  17397. var startOffset = itemDecode(locaData, 0);
  17398. var writeOffset = 0;
  17399. var missingGlyphData = {};
  17400. itemEncode(locaData, 0, writeOffset);
  17401. var i, j;
  17402. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  17403. var endOffset = itemDecode(locaData, j);
  17404. if (endOffset > oldGlyfDataLength &&
  17405. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  17406. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  17407. // the glyf table size, which makes last glyph out of range.
  17408. endOffset = oldGlyfDataLength;
  17409. }
  17410. if (endOffset > oldGlyfDataLength) {
  17411. // glyph end offset points outside glyf data, rejecting the glyph
  17412. itemEncode(locaData, j, writeOffset);
  17413. startOffset = endOffset;
  17414. continue;
  17415. }
  17416. if (startOffset === endOffset) {
  17417. missingGlyphData[i] = true;
  17418. }
  17419. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  17420. newGlyfData, writeOffset, hintsValid);
  17421. writeOffset += newLength;
  17422. itemEncode(locaData, j, writeOffset);
  17423. startOffset = endOffset;
  17424. }
  17425. if (writeOffset === 0) {
  17426. // glyf table cannot be empty -- redoing the glyf and loca tables
  17427. // to have single glyph with one point
  17428. var simpleGlyph = new Uint8Array(
  17429. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  17430. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  17431. itemEncode(locaData, j, simpleGlyph.length);
  17432. }
  17433. glyf.data = simpleGlyph;
  17434. return missingGlyphData;
  17435. }
  17436. if (dupFirstEntry) {
  17437. var firstEntryLength = itemDecode(locaData, itemSize);
  17438. if (newGlyfData.length > firstEntryLength + writeOffset) {
  17439. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  17440. } else {
  17441. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  17442. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  17443. }
  17444. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  17445. itemEncode(loca.data, locaData.length - itemSize,
  17446. writeOffset + firstEntryLength);
  17447. } else {
  17448. glyf.data = newGlyfData.subarray(0, writeOffset);
  17449. }
  17450. return missingGlyphData;
  17451. }
  17452. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  17453. var start = (font.start ? font.start : 0) + post.offset;
  17454. font.pos = start;
  17455. var length = post.length, end = start + length;
  17456. var version = font.getInt32();
  17457. // skip rest to the tables
  17458. font.getBytes(28);
  17459. var glyphNames;
  17460. var valid = true;
  17461. var i;
  17462. switch (version) {
  17463. case 0x00010000:
  17464. glyphNames = MacStandardGlyphOrdering;
  17465. break;
  17466. case 0x00020000:
  17467. var numGlyphs = font.getUint16();
  17468. if (numGlyphs !== maxpNumGlyphs) {
  17469. valid = false;
  17470. break;
  17471. }
  17472. var glyphNameIndexes = [];
  17473. for (i = 0; i < numGlyphs; ++i) {
  17474. var index = font.getUint16();
  17475. if (index >= 32768) {
  17476. valid = false;
  17477. break;
  17478. }
  17479. glyphNameIndexes.push(index);
  17480. }
  17481. if (!valid) {
  17482. break;
  17483. }
  17484. var customNames = [];
  17485. var strBuf = [];
  17486. while (font.pos < end) {
  17487. var stringLength = font.getByte();
  17488. strBuf.length = stringLength;
  17489. for (i = 0; i < stringLength; ++i) {
  17490. strBuf[i] = String.fromCharCode(font.getByte());
  17491. }
  17492. customNames.push(strBuf.join(''));
  17493. }
  17494. glyphNames = [];
  17495. for (i = 0; i < numGlyphs; ++i) {
  17496. var j = glyphNameIndexes[i];
  17497. if (j < 258) {
  17498. glyphNames.push(MacStandardGlyphOrdering[j]);
  17499. continue;
  17500. }
  17501. glyphNames.push(customNames[j - 258]);
  17502. }
  17503. break;
  17504. case 0x00030000:
  17505. break;
  17506. default:
  17507. warn('Unknown/unsupported post table version ' + version);
  17508. valid = false;
  17509. if (properties.defaultEncoding) {
  17510. glyphNames = properties.defaultEncoding;
  17511. }
  17512. break;
  17513. }
  17514. properties.glyphNames = glyphNames;
  17515. return valid;
  17516. }
  17517. function readNameTable(nameTable) {
  17518. var start = (font.start ? font.start : 0) + nameTable.offset;
  17519. font.pos = start;
  17520. var names = [[], []];
  17521. var length = nameTable.length, end = start + length;
  17522. var format = font.getUint16();
  17523. var FORMAT_0_HEADER_LENGTH = 6;
  17524. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  17525. // unsupported name table format or table "too" small
  17526. return names;
  17527. }
  17528. var numRecords = font.getUint16();
  17529. var stringsStart = font.getUint16();
  17530. var records = [];
  17531. var NAME_RECORD_LENGTH = 12;
  17532. var i, ii;
  17533. for (i = 0; i < numRecords &&
  17534. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  17535. var r = {
  17536. platform: font.getUint16(),
  17537. encoding: font.getUint16(),
  17538. language: font.getUint16(),
  17539. name: font.getUint16(),
  17540. length: font.getUint16(),
  17541. offset: font.getUint16()
  17542. };
  17543. // using only Macintosh and Windows platform/encoding names
  17544. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  17545. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  17546. records.push(r);
  17547. }
  17548. }
  17549. for (i = 0, ii = records.length; i < ii; i++) {
  17550. var record = records[i];
  17551. var pos = start + stringsStart + record.offset;
  17552. if (pos + record.length > end) {
  17553. continue; // outside of name table, ignoring
  17554. }
  17555. font.pos = pos;
  17556. var nameIndex = record.name;
  17557. if (record.encoding) {
  17558. // unicode
  17559. var str = '';
  17560. for (var j = 0, jj = record.length; j < jj; j += 2) {
  17561. str += String.fromCharCode(font.getUint16());
  17562. }
  17563. names[1][nameIndex] = str;
  17564. } else {
  17565. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  17566. }
  17567. }
  17568. return names;
  17569. }
  17570. var TTOpsStackDeltas = [
  17571. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  17572. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  17573. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  17574. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  17575. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  17576. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  17577. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  17578. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  17579. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  17580. // 0xC0-DF == -1 and 0xE0-FF == -2
  17581. function sanitizeTTProgram(table, ttContext) {
  17582. var data = table.data;
  17583. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  17584. var stack = [];
  17585. var callstack = [];
  17586. var functionsCalled = [];
  17587. var tooComplexToFollowFunctions =
  17588. ttContext.tooComplexToFollowFunctions;
  17589. var inFDEF = false, ifLevel = 0, inELSE = 0;
  17590. for (var ii = data.length; i < ii;) {
  17591. var op = data[i++];
  17592. // The TrueType instruction set docs can be found at
  17593. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  17594. if (op === 0x40) { // NPUSHB - pushes n bytes
  17595. n = data[i++];
  17596. if (inFDEF || inELSE) {
  17597. i += n;
  17598. } else {
  17599. for (j = 0; j < n; j++) {
  17600. stack.push(data[i++]);
  17601. }
  17602. }
  17603. } else if (op === 0x41) { // NPUSHW - pushes n words
  17604. n = data[i++];
  17605. if (inFDEF || inELSE) {
  17606. i += n * 2;
  17607. } else {
  17608. for (j = 0; j < n; j++) {
  17609. b = data[i++];
  17610. stack.push((b << 8) | data[i++]);
  17611. }
  17612. }
  17613. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  17614. n = op - 0xB0 + 1;
  17615. if (inFDEF || inELSE) {
  17616. i += n;
  17617. } else {
  17618. for (j = 0; j < n; j++) {
  17619. stack.push(data[i++]);
  17620. }
  17621. }
  17622. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  17623. n = op - 0xB8 + 1;
  17624. if (inFDEF || inELSE) {
  17625. i += n * 2;
  17626. } else {
  17627. for (j = 0; j < n; j++) {
  17628. b = data[i++];
  17629. stack.push((b << 8) | data[i++]);
  17630. }
  17631. }
  17632. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  17633. if (!inFDEF && !inELSE) {
  17634. // collecting inforamtion about which functions are used
  17635. funcId = stack[stack.length - 1];
  17636. ttContext.functionsUsed[funcId] = true;
  17637. if (funcId in ttContext.functionsStackDeltas) {
  17638. stack.length += ttContext.functionsStackDeltas[funcId];
  17639. } else if (funcId in ttContext.functionsDefined &&
  17640. functionsCalled.indexOf(funcId) < 0) {
  17641. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  17642. functionsCalled.push(funcId);
  17643. pc = ttContext.functionsDefined[funcId];
  17644. if (!pc) {
  17645. warn('TT: CALL non-existent function');
  17646. ttContext.hintsValid = false;
  17647. return;
  17648. }
  17649. data = pc.data;
  17650. i = pc.i;
  17651. }
  17652. }
  17653. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  17654. if (inFDEF || inELSE) {
  17655. warn('TT: nested FDEFs not allowed');
  17656. tooComplexToFollowFunctions = true;
  17657. }
  17658. inFDEF = true;
  17659. // collecting inforamtion about which functions are defined
  17660. lastDeff = i;
  17661. funcId = stack.pop();
  17662. ttContext.functionsDefined[funcId] = {data: data, i: i};
  17663. } else if (op === 0x2D) { // ENDF - end of function
  17664. if (inFDEF) {
  17665. inFDEF = false;
  17666. lastEndf = i;
  17667. } else {
  17668. pc = callstack.pop();
  17669. if (!pc) {
  17670. warn('TT: ENDF bad stack');
  17671. ttContext.hintsValid = false;
  17672. return;
  17673. }
  17674. funcId = functionsCalled.pop();
  17675. data = pc.data;
  17676. i = pc.i;
  17677. ttContext.functionsStackDeltas[funcId] =
  17678. stack.length - pc.stackTop;
  17679. }
  17680. } else if (op === 0x89) { // IDEF - instruction definition
  17681. if (inFDEF || inELSE) {
  17682. warn('TT: nested IDEFs not allowed');
  17683. tooComplexToFollowFunctions = true;
  17684. }
  17685. inFDEF = true;
  17686. // recording it as a function to track ENDF
  17687. lastDeff = i;
  17688. } else if (op === 0x58) { // IF
  17689. ++ifLevel;
  17690. } else if (op === 0x1B) { // ELSE
  17691. inELSE = ifLevel;
  17692. } else if (op === 0x59) { // EIF
  17693. if (inELSE === ifLevel) {
  17694. inELSE = 0;
  17695. }
  17696. --ifLevel;
  17697. } else if (op === 0x1C) { // JMPR
  17698. if (!inFDEF && !inELSE) {
  17699. var offset = stack[stack.length - 1];
  17700. // only jumping forward to prevent infinite loop
  17701. if (offset > 0) {
  17702. i += offset - 1;
  17703. }
  17704. }
  17705. }
  17706. // Adjusting stack not extactly, but just enough to get function id
  17707. if (!inFDEF && !inELSE) {
  17708. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  17709. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  17710. if (op >= 0x71 && op <= 0x75) {
  17711. n = stack.pop();
  17712. if (n === n) {
  17713. stackDelta = -n * 2;
  17714. }
  17715. }
  17716. while (stackDelta < 0 && stack.length > 0) {
  17717. stack.pop();
  17718. stackDelta++;
  17719. }
  17720. while (stackDelta > 0) {
  17721. stack.push(NaN); // pushing any number into stack
  17722. stackDelta--;
  17723. }
  17724. }
  17725. }
  17726. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  17727. var content = [data];
  17728. if (i > data.length) {
  17729. content.push(new Uint8Array(i - data.length));
  17730. }
  17731. if (lastDeff > lastEndf) {
  17732. warn('TT: complementing a missing function tail');
  17733. // new function definition started, but not finished
  17734. // complete function by [CLEAR, ENDF]
  17735. content.push(new Uint8Array([0x22, 0x2D]));
  17736. }
  17737. foldTTTable(table, content);
  17738. }
  17739. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  17740. if (ttContext.tooComplexToFollowFunctions) {
  17741. return;
  17742. }
  17743. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  17744. warn('TT: more functions defined than expected');
  17745. ttContext.hintsValid = false;
  17746. return;
  17747. }
  17748. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  17749. if (j > maxFunctionDefs) {
  17750. warn('TT: invalid function id: ' + j);
  17751. ttContext.hintsValid = false;
  17752. return;
  17753. }
  17754. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  17755. warn('TT: undefined function: ' + j);
  17756. ttContext.hintsValid = false;
  17757. return;
  17758. }
  17759. }
  17760. }
  17761. function foldTTTable(table, content) {
  17762. if (content.length > 1) {
  17763. // concatenating the content items
  17764. var newLength = 0;
  17765. var j, jj;
  17766. for (j = 0, jj = content.length; j < jj; j++) {
  17767. newLength += content[j].length;
  17768. }
  17769. newLength = (newLength + 3) & ~3;
  17770. var result = new Uint8Array(newLength);
  17771. var pos = 0;
  17772. for (j = 0, jj = content.length; j < jj; j++) {
  17773. result.set(content[j], pos);
  17774. pos += content[j].length;
  17775. }
  17776. table.data = result;
  17777. table.length = newLength;
  17778. }
  17779. }
  17780. function sanitizeTTPrograms(fpgm, prep, cvt) {
  17781. var ttContext = {
  17782. functionsDefined: [],
  17783. functionsUsed: [],
  17784. functionsStackDeltas: [],
  17785. tooComplexToFollowFunctions: false,
  17786. hintsValid: true
  17787. };
  17788. if (fpgm) {
  17789. sanitizeTTProgram(fpgm, ttContext);
  17790. }
  17791. if (prep) {
  17792. sanitizeTTProgram(prep, ttContext);
  17793. }
  17794. if (fpgm) {
  17795. checkInvalidFunctions(ttContext, maxFunctionDefs);
  17796. }
  17797. if (cvt && (cvt.length & 1)) {
  17798. var cvtData = new Uint8Array(cvt.length + 1);
  17799. cvtData.set(cvt.data);
  17800. cvt.data = cvtData;
  17801. }
  17802. return ttContext.hintsValid;
  17803. }
  17804. // The following steps modify the original font data, making copy
  17805. font = new Stream(new Uint8Array(font.getBytes()));
  17806. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  17807. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  17808. var header = readOpenTypeHeader(font);
  17809. var numTables = header.numTables;
  17810. var cff, cffFile;
  17811. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  17812. hmtx: null, maxp: null, name: null, post: null };
  17813. var table;
  17814. for (var i = 0; i < numTables; i++) {
  17815. table = readTableEntry(font);
  17816. if (VALID_TABLES.indexOf(table.tag) < 0) {
  17817. continue; // skipping table if it's not a required or optional table
  17818. }
  17819. if (table.length === 0) {
  17820. continue; // skipping empty tables
  17821. }
  17822. tables[table.tag] = table;
  17823. }
  17824. var isTrueType = !tables['CFF '];
  17825. if (!isTrueType) {
  17826. // OpenType font
  17827. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  17828. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  17829. // no major tables: throwing everything at CFFFont
  17830. cffFile = new Stream(tables['CFF '].data);
  17831. cff = new CFFFont(cffFile, properties);
  17832. adjustWidths(properties);
  17833. return this.convert(name, cff, properties);
  17834. }
  17835. delete tables.glyf;
  17836. delete tables.loca;
  17837. delete tables.fpgm;
  17838. delete tables.prep;
  17839. delete tables['cvt '];
  17840. this.isOpenType = true;
  17841. } else {
  17842. if (!tables.glyf || !tables.loca) {
  17843. error('Required "glyf" or "loca" tables are not found');
  17844. }
  17845. this.isOpenType = false;
  17846. }
  17847. if (!tables.maxp) {
  17848. error('Required "maxp" table is not found');
  17849. }
  17850. font.pos = (font.start || 0) + tables.maxp.offset;
  17851. var version = font.getInt32();
  17852. var numGlyphs = font.getUint16();
  17853. var maxFunctionDefs = 0;
  17854. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  17855. // maxZones can be invalid
  17856. font.pos += 8;
  17857. var maxZones = font.getUint16();
  17858. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  17859. tables.maxp.data[14] = 0;
  17860. tables.maxp.data[15] = 2;
  17861. }
  17862. font.pos += 4;
  17863. maxFunctionDefs = font.getUint16();
  17864. }
  17865. var dupFirstEntry = false;
  17866. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  17867. properties.toUnicode.get(0) > '\u0000') {
  17868. // oracle's defect (see 3427), duplicating first entry
  17869. dupFirstEntry = true;
  17870. numGlyphs++;
  17871. tables.maxp.data[4] = numGlyphs >> 8;
  17872. tables.maxp.data[5] = numGlyphs & 255;
  17873. }
  17874. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  17875. tables['cvt '], maxFunctionDefs);
  17876. if (!hintsValid) {
  17877. delete tables.fpgm;
  17878. delete tables.prep;
  17879. delete tables['cvt '];
  17880. }
  17881. // Ensure the hmtx table contains the advance width and
  17882. // sidebearings information for numGlyphs in the maxp table
  17883. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  17884. if (!tables.head) {
  17885. error('Required "head" table is not found');
  17886. }
  17887. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  17888. var missingGlyphs = {};
  17889. if (isTrueType) {
  17890. var isGlyphLocationsLong = int16(tables.head.data[50],
  17891. tables.head.data[51]);
  17892. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  17893. numGlyphs, isGlyphLocationsLong,
  17894. hintsValid, dupFirstEntry);
  17895. }
  17896. if (!tables.hhea) {
  17897. error('Required "hhea" table is not found');
  17898. }
  17899. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  17900. // Sometimes it's 0. That needs to be fixed
  17901. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  17902. tables.hhea.data[10] = 0xFF;
  17903. tables.hhea.data[11] = 0xFF;
  17904. }
  17905. // Extract some more font properties from the OpenType head and
  17906. // hhea tables; yMin and descent value are always negative.
  17907. var metricsOverride = {
  17908. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  17909. yMax: int16(tables.head.data[42], tables.head.data[43]),
  17910. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  17911. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  17912. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17913. };
  17914. // PDF FontDescriptor metrics lie -- using data from actual font.
  17915. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  17916. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  17917. // The 'post' table has glyphs names.
  17918. if (tables.post) {
  17919. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  17920. if (!valid) {
  17921. tables.post = null;
  17922. }
  17923. }
  17924. var charCodeToGlyphId = [], charCode;
  17925. var toUnicode = properties.toUnicode, widths = properties.widths;
  17926. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  17927. toUnicode.length === 0x10000);
  17928. // Helper function to try to skip mapping of empty glyphs.
  17929. // Note: In some cases, just relying on the glyph data doesn't work,
  17930. // hence we also use a few heuristics to fix various PDF files.
  17931. function hasGlyph(glyphId, charCode, widthCode) {
  17932. if (!missingGlyphs[glyphId]) {
  17933. return true;
  17934. }
  17935. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  17936. return true;
  17937. }
  17938. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  17939. return true;
  17940. }
  17941. return false;
  17942. }
  17943. if (properties.type === 'CIDFontType2') {
  17944. var cidToGidMap = properties.cidToGidMap || [];
  17945. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  17946. properties.cMap.forEach(function(charCode, cid) {
  17947. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17948. var glyphId = -1;
  17949. if (isCidToGidMapEmpty) {
  17950. glyphId = charCode;
  17951. } else if (cidToGidMap[cid] !== undefined) {
  17952. glyphId = cidToGidMap[cid];
  17953. }
  17954. if (glyphId >= 0 && glyphId < numGlyphs &&
  17955. hasGlyph(glyphId, charCode, cid)) {
  17956. charCodeToGlyphId[charCode] = glyphId;
  17957. }
  17958. });
  17959. if (dupFirstEntry) {
  17960. charCodeToGlyphId[0] = numGlyphs - 1;
  17961. }
  17962. } else {
  17963. // Most of the following logic in this code branch is based on the
  17964. // 9.6.6.4 of the PDF spec.
  17965. var hasEncoding =
  17966. properties.differences.length > 0 || !!properties.baseEncodingName;
  17967. var cmapTable =
  17968. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  17969. var cmapPlatformId = cmapTable.platformId;
  17970. var cmapEncodingId = cmapTable.encodingId;
  17971. var cmapMappings = cmapTable.mappings;
  17972. var cmapMappingsLength = cmapMappings.length;
  17973. // The spec seems to imply that if the font is symbolic the encoding
  17974. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  17975. // where the the font is symbolic and it has an encoding.
  17976. if (hasEncoding &&
  17977. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  17978. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  17979. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  17980. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  17981. // When no preferred cmap table was found and |baseEncodingName| is
  17982. // one of the predefined encodings, we seem to obtain a better
  17983. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  17984. // TODO: Note that this is a hack which should be removed as soon as
  17985. // we have proper support for more exotic cmap tables.
  17986. var baseEncoding = [];
  17987. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  17988. properties.baseEncodingName === 'WinAnsiEncoding') {
  17989. baseEncoding = Encodings[properties.baseEncodingName];
  17990. }
  17991. for (charCode = 0; charCode < 256; charCode++) {
  17992. var glyphName;
  17993. if (this.differences && charCode in this.differences) {
  17994. glyphName = this.differences[charCode];
  17995. } else if (charCode in baseEncoding &&
  17996. baseEncoding[charCode] !== '') {
  17997. glyphName = baseEncoding[charCode];
  17998. } else {
  17999. glyphName = Encodings.StandardEncoding[charCode];
  18000. }
  18001. if (!glyphName) {
  18002. continue;
  18003. }
  18004. var unicodeOrCharCode, isUnicode = false;
  18005. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  18006. unicodeOrCharCode = GlyphsUnicode[glyphName];
  18007. isUnicode = true;
  18008. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  18009. // TODO: the encoding needs to be updated with mac os table.
  18010. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  18011. }
  18012. var found = false;
  18013. for (i = 0; i < cmapMappingsLength; ++i) {
  18014. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  18015. continue;
  18016. }
  18017. var code = isUnicode ? charCode : unicodeOrCharCode;
  18018. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  18019. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  18020. found = true;
  18021. break;
  18022. }
  18023. }
  18024. if (!found && properties.glyphNames) {
  18025. // Try to map using the post table.
  18026. var glyphId = properties.glyphNames.indexOf(glyphName);
  18027. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  18028. charCodeToGlyphId[charCode] = glyphId;
  18029. } else {
  18030. charCodeToGlyphId[charCode] = 0; // notdef
  18031. }
  18032. }
  18033. }
  18034. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  18035. // Default Unicode semantics, use the charcodes as is.
  18036. for (i = 0; i < cmapMappingsLength; ++i) {
  18037. charCodeToGlyphId[cmapMappings[i].charCode] =
  18038. cmapMappings[i].glyphId;
  18039. }
  18040. } else {
  18041. // For (3, 0) cmap tables:
  18042. // The charcode key being stored in charCodeToGlyphId is the lower
  18043. // byte of the two-byte charcodes of the cmap table since according to
  18044. // the spec: 'each byte from the string shall be prepended with the
  18045. // high byte of the range [of charcodes in the cmap table], to form
  18046. // a two-byte character, which shall be used to select the
  18047. // associated glyph description from the subtable'.
  18048. //
  18049. // For (1, 0) cmap tables:
  18050. // 'single bytes from the string shall be used to look up the
  18051. // associated glyph descriptions from the subtable'. This means
  18052. // charcodes in the cmap will be single bytes, so no-op since
  18053. // glyph.charCode & 0xFF === glyph.charCode
  18054. for (i = 0; i < cmapMappingsLength; ++i) {
  18055. charCode = cmapMappings[i].charCode & 0xFF;
  18056. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  18057. }
  18058. }
  18059. }
  18060. if (charCodeToGlyphId.length === 0) {
  18061. // defines at least one glyph
  18062. charCodeToGlyphId[0] = 0;
  18063. }
  18064. // Converting glyphs and ids into font's cmap table
  18065. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  18066. this.toFontChar = newMapping.toFontChar;
  18067. tables.cmap = {
  18068. tag: 'cmap',
  18069. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  18070. };
  18071. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  18072. tables['OS/2'] = {
  18073. tag: 'OS/2',
  18074. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  18075. metricsOverride)
  18076. };
  18077. }
  18078. // Rewrite the 'post' table if needed
  18079. if (!tables.post) {
  18080. tables.post = {
  18081. tag: 'post',
  18082. data: createPostTable(properties)
  18083. };
  18084. }
  18085. if (!isTrueType) {
  18086. try {
  18087. // Trying to repair CFF file
  18088. cffFile = new Stream(tables['CFF '].data);
  18089. var parser = new CFFParser(cffFile, properties);
  18090. cff = parser.parse();
  18091. var compiler = new CFFCompiler(cff);
  18092. tables['CFF '].data = compiler.compile();
  18093. } catch (e) {
  18094. warn('Failed to compile font ' + properties.loadedName);
  18095. }
  18096. }
  18097. // Re-creating 'name' table
  18098. if (!tables.name) {
  18099. tables.name = {
  18100. tag: 'name',
  18101. data: createNameTable(this.name)
  18102. };
  18103. } else {
  18104. // ... using existing 'name' table as prototype
  18105. var namePrototype = readNameTable(tables.name);
  18106. tables.name.data = createNameTable(name, namePrototype);
  18107. }
  18108. var builder = new OpenTypeFileBuilder(header.version);
  18109. for (var tableTag in tables) {
  18110. builder.addTable(tableTag, tables[tableTag].data);
  18111. }
  18112. return builder.toArray();
  18113. },
  18114. convert: function Font_convert(fontName, font, properties) {
  18115. // TODO: Check the charstring widths to determine this.
  18116. properties.fixedPitch = false;
  18117. var mapping = font.getGlyphMapping(properties);
  18118. var newMapping = adjustMapping(mapping, properties);
  18119. this.toFontChar = newMapping.toFontChar;
  18120. var numGlyphs = font.numGlyphs;
  18121. function getCharCodes(charCodeToGlyphId, glyphId) {
  18122. var charCodes = null;
  18123. for (var charCode in charCodeToGlyphId) {
  18124. if (glyphId === charCodeToGlyphId[charCode]) {
  18125. if (!charCodes) {
  18126. charCodes = [];
  18127. }
  18128. charCodes.push(charCode | 0);
  18129. }
  18130. }
  18131. return charCodes;
  18132. }
  18133. function createCharCode(charCodeToGlyphId, glyphId) {
  18134. for (var charCode in charCodeToGlyphId) {
  18135. if (glyphId === charCodeToGlyphId[charCode]) {
  18136. return charCode | 0;
  18137. }
  18138. }
  18139. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  18140. glyphId;
  18141. return newMapping.nextAvailableFontCharCode++;
  18142. }
  18143. var seacs = font.seacs;
  18144. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  18145. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  18146. var charset = font.getCharset();
  18147. var seacMap = Object.create(null);
  18148. for (var glyphId in seacs) {
  18149. glyphId |= 0;
  18150. var seac = seacs[glyphId];
  18151. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  18152. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  18153. var baseGlyphId = charset.indexOf(baseGlyphName);
  18154. var accentGlyphId = charset.indexOf(accentGlyphName);
  18155. if (baseGlyphId < 0 || accentGlyphId < 0) {
  18156. continue;
  18157. }
  18158. var accentOffset = {
  18159. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  18160. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  18161. };
  18162. var charCodes = getCharCodes(mapping, glyphId);
  18163. if (!charCodes) {
  18164. // There's no point in mapping it if the char code was never mapped
  18165. // to begin with.
  18166. continue;
  18167. }
  18168. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  18169. var charCode = charCodes[i];
  18170. // Find a fontCharCode that maps to the base and accent glyphs.
  18171. // If one doesn't exists, create it.
  18172. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  18173. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  18174. baseGlyphId);
  18175. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  18176. accentGlyphId);
  18177. seacMap[charCode] = {
  18178. baseFontCharCode: baseFontCharCode,
  18179. accentFontCharCode: accentFontCharCode,
  18180. accentOffset: accentOffset
  18181. };
  18182. }
  18183. }
  18184. properties.seacMap = seacMap;
  18185. }
  18186. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  18187. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  18188. // PostScript Font Program
  18189. builder.addTable('CFF ', font.data);
  18190. // OS/2 and Windows Specific metrics
  18191. builder.addTable('OS/2', createOS2Table(properties,
  18192. newMapping.charCodeToGlyphId));
  18193. // Character to glyphs mapping
  18194. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  18195. numGlyphs));
  18196. // Font header
  18197. builder.addTable('head',
  18198. '\x00\x01\x00\x00' + // Version number
  18199. '\x00\x00\x10\x00' + // fontRevision
  18200. '\x00\x00\x00\x00' + // checksumAdjustement
  18201. '\x5F\x0F\x3C\xF5' + // magicNumber
  18202. '\x00\x00' + // Flags
  18203. safeString16(unitsPerEm) + // unitsPerEM
  18204. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  18205. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  18206. '\x00\x00' + // xMin
  18207. safeString16(properties.descent) + // yMin
  18208. '\x0F\xFF' + // xMax
  18209. safeString16(properties.ascent) + // yMax
  18210. string16(properties.italicAngle ? 2 : 0) + // macStyle
  18211. '\x00\x11' + // lowestRecPPEM
  18212. '\x00\x00' + // fontDirectionHint
  18213. '\x00\x00' + // indexToLocFormat
  18214. '\x00\x00'); // glyphDataFormat
  18215. // Horizontal header
  18216. builder.addTable('hhea',
  18217. '\x00\x01\x00\x00' + // Version number
  18218. safeString16(properties.ascent) + // Typographic Ascent
  18219. safeString16(properties.descent) + // Typographic Descent
  18220. '\x00\x00' + // Line Gap
  18221. '\xFF\xFF' + // advanceWidthMax
  18222. '\x00\x00' + // minLeftSidebearing
  18223. '\x00\x00' + // minRightSidebearing
  18224. '\x00\x00' + // xMaxExtent
  18225. safeString16(properties.capHeight) + // caretSlopeRise
  18226. safeString16(Math.tan(properties.italicAngle) *
  18227. properties.xHeight) + // caretSlopeRun
  18228. '\x00\x00' + // caretOffset
  18229. '\x00\x00' + // -reserved-
  18230. '\x00\x00' + // -reserved-
  18231. '\x00\x00' + // -reserved-
  18232. '\x00\x00' + // -reserved-
  18233. '\x00\x00' + // metricDataFormat
  18234. string16(numGlyphs)); // Number of HMetrics
  18235. // Horizontal metrics
  18236. builder.addTable('hmtx', (function fontFieldsHmtx() {
  18237. var charstrings = font.charstrings;
  18238. var cffWidths = font.cff ? font.cff.widths : null;
  18239. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  18240. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  18241. var width = 0;
  18242. if (charstrings) {
  18243. var charstring = charstrings[i - 1];
  18244. width = 'width' in charstring ? charstring.width : 0;
  18245. } else if (cffWidths) {
  18246. width = Math.ceil(cffWidths[i] || 0);
  18247. }
  18248. hmtx += string16(width) + string16(0);
  18249. }
  18250. return hmtx;
  18251. })());
  18252. // Maximum profile
  18253. builder.addTable('maxp',
  18254. '\x00\x00\x50\x00' + // Version number
  18255. string16(numGlyphs)); // Num of glyphs
  18256. // Naming tables
  18257. builder.addTable('name', createNameTable(fontName));
  18258. // PostScript informations
  18259. builder.addTable('post', createPostTable(properties));
  18260. return builder.toArray();
  18261. },
  18262. /**
  18263. * Builds a char code to unicode map based on section 9.10 of the spec.
  18264. * @param {Object} properties Font properties object.
  18265. * @return {Object} A ToUnicodeMap object.
  18266. */
  18267. buildToUnicode: function Font_buildToUnicode(properties) {
  18268. // Section 9.10.2 Mapping Character Codes to Unicode Values
  18269. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  18270. return properties.toUnicode;
  18271. }
  18272. // According to the spec if the font is a simple font we should only map
  18273. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  18274. // the differences array only contains adobe standard or symbol set names,
  18275. // in pratice it seems better to always try to create a toUnicode
  18276. // map based of the default encoding.
  18277. var toUnicode, charcode;
  18278. if (!properties.composite /* is simple font */) {
  18279. toUnicode = [];
  18280. var encoding = properties.defaultEncoding.slice();
  18281. var baseEncodingName = properties.baseEncodingName;
  18282. // Merge in the differences array.
  18283. var differences = properties.differences;
  18284. for (charcode in differences) {
  18285. encoding[charcode] = differences[charcode];
  18286. }
  18287. for (charcode in encoding) {
  18288. // a) Map the character code to a character name.
  18289. var glyphName = encoding[charcode];
  18290. // b) Look up the character name in the Adobe Glyph List (see the
  18291. // Bibliography) to obtain the corresponding Unicode value.
  18292. if (glyphName === '') {
  18293. continue;
  18294. } else if (GlyphsUnicode[glyphName] === undefined) {
  18295. // (undocumented) c) Few heuristics to recognize unknown glyphs
  18296. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  18297. var code = 0;
  18298. switch (glyphName[0]) {
  18299. case 'G': // Gxx glyph
  18300. if (glyphName.length === 3) {
  18301. code = parseInt(glyphName.substr(1), 16);
  18302. }
  18303. break;
  18304. case 'g': // g00xx glyph
  18305. if (glyphName.length === 5) {
  18306. code = parseInt(glyphName.substr(1), 16);
  18307. }
  18308. break;
  18309. case 'C': // Cddd glyph
  18310. case 'c': // cddd glyph
  18311. if (glyphName.length >= 3) {
  18312. code = +glyphName.substr(1);
  18313. }
  18314. break;
  18315. }
  18316. if (code) {
  18317. // If |baseEncodingName| is one the predefined encodings,
  18318. // and |code| equals |charcode|, using the glyph defined in the
  18319. // baseEncoding seems to yield a better |toUnicode| mapping
  18320. // (fixes issue 5070).
  18321. if (baseEncodingName && code === +charcode) {
  18322. var baseEncoding = Encodings[baseEncodingName];
  18323. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  18324. toUnicode[charcode] =
  18325. String.fromCharCode(GlyphsUnicode[glyphName]);
  18326. continue;
  18327. }
  18328. }
  18329. toUnicode[charcode] = String.fromCharCode(code);
  18330. }
  18331. continue;
  18332. }
  18333. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  18334. }
  18335. return new ToUnicodeMap(toUnicode);
  18336. }
  18337. // If the font is a composite font that uses one of the predefined CMaps
  18338. // listed in Table 118 (except Identity–H and Identity–V) or whose
  18339. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  18340. // Adobe-Korea1 character collection:
  18341. if (properties.composite && (
  18342. (properties.cMap.builtInCMap &&
  18343. !(properties.cMap instanceof IdentityCMap)) ||
  18344. (properties.cidSystemInfo.registry === 'Adobe' &&
  18345. (properties.cidSystemInfo.ordering === 'GB1' ||
  18346. properties.cidSystemInfo.ordering === 'CNS1' ||
  18347. properties.cidSystemInfo.ordering === 'Japan1' ||
  18348. properties.cidSystemInfo.ordering === 'Korea1')))) {
  18349. // Then:
  18350. // a) Map the character code to a character identifier (CID) according
  18351. // to the font’s CMap.
  18352. // b) Obtain the registry and ordering of the character collection used
  18353. // by the font’s CMap (for example, Adobe and Japan1) from its
  18354. // CIDSystemInfo dictionary.
  18355. var registry = properties.cidSystemInfo.registry;
  18356. var ordering = properties.cidSystemInfo.ordering;
  18357. // c) Construct a second CMap name by concatenating the registry and
  18358. // ordering obtained in step (b) in the format registry–ordering–UCS2
  18359. // (for example, Adobe–Japan1–UCS2).
  18360. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  18361. // d) Obtain the CMap with the name constructed in step (c) (available
  18362. // from the ASN Web site; see the Bibliography).
  18363. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  18364. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  18365. var cMap = properties.cMap;
  18366. toUnicode = [];
  18367. cMap.forEach(function(charcode, cid) {
  18368. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  18369. // e) Map the CID obtained in step (a) according to the CMap obtained
  18370. // in step (d), producing a Unicode value.
  18371. var ucs2 = ucs2CMap.lookup(cid);
  18372. if (ucs2) {
  18373. toUnicode[charcode] =
  18374. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  18375. ucs2.charCodeAt(1));
  18376. }
  18377. });
  18378. return new ToUnicodeMap(toUnicode);
  18379. }
  18380. // The viewer's choice, just use an identity map.
  18381. return new IdentityToUnicodeMap(properties.firstChar,
  18382. properties.lastChar);
  18383. },
  18384. get spaceWidth() {
  18385. if ('_shadowWidth' in this) {
  18386. return this._shadowWidth;
  18387. }
  18388. // trying to estimate space character width
  18389. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  18390. var width;
  18391. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  18392. var glyphName = possibleSpaceReplacements[i];
  18393. // if possible, getting width by glyph name
  18394. if (glyphName in this.widths) {
  18395. width = this.widths[glyphName];
  18396. break;
  18397. }
  18398. var glyphUnicode = GlyphsUnicode[glyphName];
  18399. // finding the charcode via unicodeToCID map
  18400. var charcode = 0;
  18401. if (this.composite) {
  18402. if (this.cMap.contains(glyphUnicode)) {
  18403. charcode = this.cMap.lookup(glyphUnicode);
  18404. }
  18405. }
  18406. // ... via toUnicode map
  18407. if (!charcode && this.toUnicode) {
  18408. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  18409. }
  18410. // setting it to unicode if negative or undefined
  18411. if (charcode <= 0) {
  18412. charcode = glyphUnicode;
  18413. }
  18414. // trying to get width via charcode
  18415. width = this.widths[charcode];
  18416. if (width) {
  18417. break; // the non-zero width found
  18418. }
  18419. }
  18420. width = width || this.defaultWidth;
  18421. // Do not shadow the property here. See discussion:
  18422. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  18423. this._shadowWidth = width;
  18424. return width;
  18425. },
  18426. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  18427. var fontCharCode, width, operatorListId;
  18428. var widthCode = charcode;
  18429. if (this.cMap && this.cMap.contains(charcode)) {
  18430. widthCode = this.cMap.lookup(charcode);
  18431. }
  18432. width = this.widths[widthCode];
  18433. width = isNum(width) ? width : this.defaultWidth;
  18434. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  18435. var unicode = this.toUnicode.get(charcode) || charcode;
  18436. if (typeof unicode === 'number') {
  18437. unicode = String.fromCharCode(unicode);
  18438. }
  18439. // First try the toFontChar map, if it's not there then try falling
  18440. // back to the char code.
  18441. fontCharCode = this.toFontChar[charcode] || charcode;
  18442. if (this.missingFile) {
  18443. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  18444. }
  18445. if (this.isType3Font) {
  18446. // Font char code in this case is actually a glyph name.
  18447. operatorListId = fontCharCode;
  18448. }
  18449. var accent = null;
  18450. if (this.seacMap && this.seacMap[charcode]) {
  18451. var seac = this.seacMap[charcode];
  18452. fontCharCode = seac.baseFontCharCode;
  18453. accent = {
  18454. fontChar: String.fromCharCode(seac.accentFontCharCode),
  18455. offset: seac.accentOffset
  18456. };
  18457. }
  18458. var fontChar = String.fromCharCode(fontCharCode);
  18459. var glyph = this.glyphCache[charcode];
  18460. if (!glyph ||
  18461. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  18462. operatorListId, isSpace)) {
  18463. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  18464. operatorListId, isSpace);
  18465. this.glyphCache[charcode] = glyph;
  18466. }
  18467. return glyph;
  18468. },
  18469. charsToGlyphs: function Font_charsToGlyphs(chars) {
  18470. var charsCache = this.charsCache;
  18471. var glyphs, glyph, charcode;
  18472. // if we translated this string before, just grab it from the cache
  18473. if (charsCache) {
  18474. glyphs = charsCache[chars];
  18475. if (glyphs) {
  18476. return glyphs;
  18477. }
  18478. }
  18479. // lazily create the translation cache
  18480. if (!charsCache) {
  18481. charsCache = this.charsCache = Object.create(null);
  18482. }
  18483. glyphs = [];
  18484. var charsCacheKey = chars;
  18485. var i = 0, ii;
  18486. if (this.cMap) {
  18487. // composite fonts have multi-byte strings convert the string from
  18488. // single-byte to multi-byte
  18489. var c = {};
  18490. while (i < chars.length) {
  18491. this.cMap.readCharCode(chars, i, c);
  18492. charcode = c.charcode;
  18493. var length = c.length;
  18494. i += length;
  18495. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  18496. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  18497. glyph = this.charToGlyph(charcode, isSpace);
  18498. glyphs.push(glyph);
  18499. }
  18500. } else {
  18501. for (i = 0, ii = chars.length; i < ii; ++i) {
  18502. charcode = chars.charCodeAt(i);
  18503. glyph = this.charToGlyph(charcode, charcode === 0x20);
  18504. glyphs.push(glyph);
  18505. }
  18506. }
  18507. // Enter the translated string into the cache
  18508. return (charsCache[charsCacheKey] = glyphs);
  18509. }
  18510. };
  18511. return Font;
  18512. })();
  18513. var ErrorFont = (function ErrorFontClosure() {
  18514. function ErrorFont(error) {
  18515. this.error = error;
  18516. this.loadedName = 'g_font_error';
  18517. this.loading = false;
  18518. }
  18519. ErrorFont.prototype = {
  18520. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  18521. return [];
  18522. },
  18523. exportData: function ErrorFont_exportData() {
  18524. return {error: this.error};
  18525. }
  18526. };
  18527. return ErrorFont;
  18528. })();
  18529. /**
  18530. * Shared logic for building a char code to glyph id mapping for Type1 and
  18531. * simple CFF fonts. See section 9.6.6.2 of the spec.
  18532. * @param {Object} properties Font properties object.
  18533. * @param {Object} builtInEncoding The encoding contained within the actual font
  18534. * data.
  18535. * @param {Array} Array of glyph names where the index is the glyph ID.
  18536. * @returns {Object} A char code to glyph ID map.
  18537. */
  18538. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  18539. var charCodeToGlyphId = Object.create(null);
  18540. var glyphId, charCode, baseEncoding;
  18541. if (properties.baseEncodingName) {
  18542. // If a valid base encoding name was used, the mapping is initialized with
  18543. // that.
  18544. baseEncoding = Encodings[properties.baseEncodingName];
  18545. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  18546. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  18547. if (glyphId >= 0) {
  18548. charCodeToGlyphId[charCode] = glyphId;
  18549. } else {
  18550. charCodeToGlyphId[charCode] = 0; // notdef
  18551. }
  18552. }
  18553. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  18554. // For a symbolic font the encoding should be the fonts built-in
  18555. // encoding.
  18556. for (charCode in builtInEncoding) {
  18557. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  18558. }
  18559. } else {
  18560. // For non-symbolic fonts that don't have a base encoding the standard
  18561. // encoding should be used.
  18562. baseEncoding = Encodings.StandardEncoding;
  18563. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  18564. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  18565. if (glyphId >= 0) {
  18566. charCodeToGlyphId[charCode] = glyphId;
  18567. } else {
  18568. charCodeToGlyphId[charCode] = 0; // notdef
  18569. }
  18570. }
  18571. }
  18572. // Lastly, merge in the differences.
  18573. var differences = properties.differences;
  18574. if (differences) {
  18575. for (charCode in differences) {
  18576. var glyphName = differences[charCode];
  18577. glyphId = glyphNames.indexOf(glyphName);
  18578. if (glyphId >= 0) {
  18579. charCodeToGlyphId[charCode] = glyphId;
  18580. } else {
  18581. charCodeToGlyphId[charCode] = 0; // notdef
  18582. }
  18583. }
  18584. }
  18585. return charCodeToGlyphId;
  18586. }
  18587. /*
  18588. * CharStrings are encoded following the the CharString Encoding sequence
  18589. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  18590. * The value in a byte indicates a command, a number, or subsequent bytes
  18591. * that are to be interpreted in a special way.
  18592. *
  18593. * CharString Number Encoding:
  18594. * A CharString byte containing the values from 32 through 255 inclusive
  18595. * indicate an integer. These values are decoded in four ranges.
  18596. *
  18597. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  18598. * indicate the integer v - 139. Thus, the integer values from -107 through
  18599. * 107 inclusive may be encoded in single byte.
  18600. *
  18601. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  18602. * indicates an integer involving the next byte, w, according to the formula:
  18603. * [(v - 247) x 256] + w + 108
  18604. *
  18605. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  18606. * indicates an integer involving the next byte, w, according to the formula:
  18607. * -[(v - 251) * 256] - w - 108
  18608. *
  18609. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  18610. * are a two complement signed integer. The first of these bytes contains the
  18611. * highest order bits, the second byte contains the next higher order bits
  18612. * and the fourth byte contain the lowest order bits.
  18613. *
  18614. *
  18615. * CharString Command Encoding:
  18616. * CharStrings commands are encoded in 1 or 2 bytes.
  18617. *
  18618. * Single byte commands are encoded in 1 byte that contains a value between
  18619. * 0 and 31 inclusive.
  18620. * If a command byte contains the value 12, then the value in the next byte
  18621. * indicates a command. This "escape" mechanism allows many extra commands
  18622. * to be encoded and this encoding technique helps to minimize the length of
  18623. * the charStrings.
  18624. */
  18625. var Type1CharString = (function Type1CharStringClosure() {
  18626. var COMMAND_MAP = {
  18627. 'hstem': [1],
  18628. 'vstem': [3],
  18629. 'vmoveto': [4],
  18630. 'rlineto': [5],
  18631. 'hlineto': [6],
  18632. 'vlineto': [7],
  18633. 'rrcurveto': [8],
  18634. 'callsubr': [10],
  18635. 'flex': [12, 35],
  18636. 'drop' : [12, 18],
  18637. 'endchar': [14],
  18638. 'rmoveto': [21],
  18639. 'hmoveto': [22],
  18640. 'vhcurveto': [30],
  18641. 'hvcurveto': [31]
  18642. };
  18643. function Type1CharString() {
  18644. this.width = 0;
  18645. this.lsb = 0;
  18646. this.flexing = false;
  18647. this.output = [];
  18648. this.stack = [];
  18649. }
  18650. Type1CharString.prototype = {
  18651. convert: function Type1CharString_convert(encoded, subrs) {
  18652. var count = encoded.length;
  18653. var error = false;
  18654. var wx, sbx, subrNumber;
  18655. for (var i = 0; i < count; i++) {
  18656. var value = encoded[i];
  18657. if (value < 32) {
  18658. if (value === 12) {
  18659. value = (value << 8) + encoded[++i];
  18660. }
  18661. switch (value) {
  18662. case 1: // hstem
  18663. if (!HINTING_ENABLED) {
  18664. this.stack = [];
  18665. break;
  18666. }
  18667. error = this.executeCommand(2, COMMAND_MAP.hstem);
  18668. break;
  18669. case 3: // vstem
  18670. if (!HINTING_ENABLED) {
  18671. this.stack = [];
  18672. break;
  18673. }
  18674. error = this.executeCommand(2, COMMAND_MAP.vstem);
  18675. break;
  18676. case 4: // vmoveto
  18677. if (this.flexing) {
  18678. if (this.stack.length < 1) {
  18679. error = true;
  18680. break;
  18681. }
  18682. // Add the dx for flex and but also swap the values so they are
  18683. // the right order.
  18684. var dy = this.stack.pop();
  18685. this.stack.push(0, dy);
  18686. break;
  18687. }
  18688. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  18689. break;
  18690. case 5: // rlineto
  18691. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  18692. break;
  18693. case 6: // hlineto
  18694. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  18695. break;
  18696. case 7: // vlineto
  18697. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  18698. break;
  18699. case 8: // rrcurveto
  18700. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  18701. break;
  18702. case 9: // closepath
  18703. // closepath is a Type1 command that does not take argument and is
  18704. // useless in Type2 and it can simply be ignored.
  18705. this.stack = [];
  18706. break;
  18707. case 10: // callsubr
  18708. if (this.stack.length < 1) {
  18709. error = true;
  18710. break;
  18711. }
  18712. subrNumber = this.stack.pop();
  18713. error = this.convert(subrs[subrNumber], subrs);
  18714. break;
  18715. case 11: // return
  18716. return error;
  18717. case 13: // hsbw
  18718. if (this.stack.length < 2) {
  18719. error = true;
  18720. break;
  18721. }
  18722. // To convert to type2 we have to move the width value to the
  18723. // first part of the charstring and then use hmoveto with lsb.
  18724. wx = this.stack.pop();
  18725. sbx = this.stack.pop();
  18726. this.lsb = sbx;
  18727. this.width = wx;
  18728. this.stack.push(wx, sbx);
  18729. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  18730. break;
  18731. case 14: // endchar
  18732. this.output.push(COMMAND_MAP.endchar[0]);
  18733. break;
  18734. case 21: // rmoveto
  18735. if (this.flexing) {
  18736. break;
  18737. }
  18738. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  18739. break;
  18740. case 22: // hmoveto
  18741. if (this.flexing) {
  18742. // Add the dy for flex.
  18743. this.stack.push(0);
  18744. break;
  18745. }
  18746. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  18747. break;
  18748. case 30: // vhcurveto
  18749. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  18750. break;
  18751. case 31: // hvcurveto
  18752. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  18753. break;
  18754. case (12 << 8) + 0: // dotsection
  18755. // dotsection is a Type1 command to specify some hinting feature
  18756. // for dots that do not take a parameter and it can safely be
  18757. // ignored for Type2.
  18758. this.stack = [];
  18759. break;
  18760. case (12 << 8) + 1: // vstem3
  18761. if (!HINTING_ENABLED) {
  18762. this.stack = [];
  18763. break;
  18764. }
  18765. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  18766. // multiple parameters, so instead of returning [vh]stem3 take a
  18767. // shortcut and return [vhstem] instead.
  18768. error = this.executeCommand(2, COMMAND_MAP.vstem);
  18769. break;
  18770. case (12 << 8) + 2: // hstem3
  18771. if (!HINTING_ENABLED) {
  18772. this.stack = [];
  18773. break;
  18774. }
  18775. // See vstem3.
  18776. error = this.executeCommand(2, COMMAND_MAP.hstem);
  18777. break;
  18778. case (12 << 8) + 6: // seac
  18779. // seac is like type 2's special endchar but it doesn't use the
  18780. // first argument asb, so remove it.
  18781. if (SEAC_ANALYSIS_ENABLED) {
  18782. this.seac = this.stack.splice(-4, 4);
  18783. error = this.executeCommand(0, COMMAND_MAP.endchar);
  18784. } else {
  18785. error = this.executeCommand(4, COMMAND_MAP.endchar);
  18786. }
  18787. break;
  18788. case (12 << 8) + 7: // sbw
  18789. if (this.stack.length < 4) {
  18790. error = true;
  18791. break;
  18792. }
  18793. // To convert to type2 we have to move the width value to the
  18794. // first part of the charstring and then use rmoveto with
  18795. // (dx, dy). The height argument will not be used for vmtx and
  18796. // vhea tables reconstruction -- ignoring it.
  18797. var wy = this.stack.pop();
  18798. wx = this.stack.pop();
  18799. var sby = this.stack.pop();
  18800. sbx = this.stack.pop();
  18801. this.lsb = sbx;
  18802. this.width = wx;
  18803. this.stack.push(wx, sbx, sby);
  18804. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  18805. break;
  18806. case (12 << 8) + 12: // div
  18807. if (this.stack.length < 2) {
  18808. error = true;
  18809. break;
  18810. }
  18811. var num2 = this.stack.pop();
  18812. var num1 = this.stack.pop();
  18813. this.stack.push(num1 / num2);
  18814. break;
  18815. case (12 << 8) + 16: // callothersubr
  18816. if (this.stack.length < 2) {
  18817. error = true;
  18818. break;
  18819. }
  18820. subrNumber = this.stack.pop();
  18821. var numArgs = this.stack.pop();
  18822. if (subrNumber === 0 && numArgs === 3) {
  18823. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  18824. this.stack.push(
  18825. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  18826. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  18827. flexArgs[4], // bcp2x
  18828. flexArgs[5], // bcp2y
  18829. flexArgs[6], // p2x
  18830. flexArgs[7], // p2y
  18831. flexArgs[8], // bcp3x
  18832. flexArgs[9], // bcp3y
  18833. flexArgs[10], // bcp4x
  18834. flexArgs[11], // bcp4y
  18835. flexArgs[12], // p3x
  18836. flexArgs[13], // p3y
  18837. flexArgs[14] // flexDepth
  18838. // 15 = finalx unused by flex
  18839. // 16 = finaly unused by flex
  18840. );
  18841. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  18842. this.flexing = false;
  18843. this.stack.push(flexArgs[15], flexArgs[16]);
  18844. } else if (subrNumber === 1 && numArgs === 0) {
  18845. this.flexing = true;
  18846. }
  18847. break;
  18848. case (12 << 8) + 17: // pop
  18849. // Ignore this since it is only used with othersubr.
  18850. break;
  18851. case (12 << 8) + 33: // setcurrentpoint
  18852. // Ignore for now.
  18853. this.stack = [];
  18854. break;
  18855. default:
  18856. warn('Unknown type 1 charstring command of "' + value + '"');
  18857. break;
  18858. }
  18859. if (error) {
  18860. break;
  18861. }
  18862. continue;
  18863. } else if (value <= 246) {
  18864. value = value - 139;
  18865. } else if (value <= 250) {
  18866. value = ((value - 247) * 256) + encoded[++i] + 108;
  18867. } else if (value <= 254) {
  18868. value = -((value - 251) * 256) - encoded[++i] - 108;
  18869. } else {
  18870. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  18871. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  18872. }
  18873. this.stack.push(value);
  18874. }
  18875. return error;
  18876. },
  18877. executeCommand: function(howManyArgs, command, keepStack) {
  18878. var stackLength = this.stack.length;
  18879. if (howManyArgs > stackLength) {
  18880. return true;
  18881. }
  18882. var start = stackLength - howManyArgs;
  18883. for (var i = start; i < stackLength; i++) {
  18884. var value = this.stack[i];
  18885. if (value === (value | 0)) { // int
  18886. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  18887. } else { // fixed point
  18888. value = (65536 * value) | 0;
  18889. this.output.push(255,
  18890. (value >> 24) & 0xFF,
  18891. (value >> 16) & 0xFF,
  18892. (value >> 8) & 0xFF,
  18893. value & 0xFF);
  18894. }
  18895. }
  18896. this.output.push.apply(this.output, command);
  18897. if (keepStack) {
  18898. this.stack.splice(start, howManyArgs);
  18899. } else {
  18900. this.stack.length = 0;
  18901. }
  18902. return false;
  18903. }
  18904. };
  18905. return Type1CharString;
  18906. })();
  18907. /*
  18908. * Type1Parser encapsulate the needed code for parsing a Type1 font
  18909. * program. Some of its logic depends on the Type2 charstrings
  18910. * structure.
  18911. * Note: this doesn't really parse the font since that would require evaluation
  18912. * of PostScript, but it is possible in most cases to extract what we need
  18913. * without a full parse.
  18914. */
  18915. var Type1Parser = (function Type1ParserClosure() {
  18916. /*
  18917. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  18918. * of Plaintext Bytes. The function took a key as a parameter which can be
  18919. * for decrypting the eexec block of for decoding charStrings.
  18920. */
  18921. var EEXEC_ENCRYPT_KEY = 55665;
  18922. var CHAR_STRS_ENCRYPT_KEY = 4330;
  18923. function isHexDigit(code) {
  18924. return code >= 48 && code <= 57 || // '0'-'9'
  18925. code >= 65 && code <= 70 || // 'A'-'F'
  18926. code >= 97 && code <= 102; // 'a'-'f'
  18927. }
  18928. function decrypt(data, key, discardNumber) {
  18929. var r = key | 0, c1 = 52845, c2 = 22719;
  18930. var count = data.length;
  18931. var decrypted = new Uint8Array(count);
  18932. for (var i = 0; i < count; i++) {
  18933. var value = data[i];
  18934. decrypted[i] = value ^ (r >> 8);
  18935. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18936. }
  18937. return Array.prototype.slice.call(decrypted, discardNumber);
  18938. }
  18939. function decryptAscii(data, key, discardNumber) {
  18940. var r = key | 0, c1 = 52845, c2 = 22719;
  18941. var count = data.length, maybeLength = count >>> 1;
  18942. var decrypted = new Uint8Array(maybeLength);
  18943. var i, j;
  18944. for (i = 0, j = 0; i < count; i++) {
  18945. var digit1 = data[i];
  18946. if (!isHexDigit(digit1)) {
  18947. continue;
  18948. }
  18949. i++;
  18950. var digit2;
  18951. while (i < count && !isHexDigit(digit2 = data[i])) {
  18952. i++;
  18953. }
  18954. if (i < count) {
  18955. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  18956. decrypted[j++] = value ^ (r >> 8);
  18957. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18958. }
  18959. }
  18960. return Array.prototype.slice.call(decrypted, discardNumber, j);
  18961. }
  18962. function isSpecial(c) {
  18963. return c === 0x2F || // '/'
  18964. c === 0x5B || c === 0x5D || // '[', ']'
  18965. c === 0x7B || c === 0x7D || // '{', '}'
  18966. c === 0x28 || c === 0x29; // '(', ')'
  18967. }
  18968. function Type1Parser(stream, encrypted) {
  18969. if (encrypted) {
  18970. var data = stream.getBytes();
  18971. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  18972. isHexDigit(data[2]) && isHexDigit(data[3]));
  18973. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  18974. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  18975. }
  18976. this.stream = stream;
  18977. this.nextChar();
  18978. }
  18979. Type1Parser.prototype = {
  18980. readNumberArray: function Type1Parser_readNumberArray() {
  18981. this.getToken(); // read '[' or '{' (arrays can start with either)
  18982. var array = [];
  18983. while (true) {
  18984. var token = this.getToken();
  18985. if (token === null || token === ']' || token === '}') {
  18986. break;
  18987. }
  18988. array.push(parseFloat(token || 0));
  18989. }
  18990. return array;
  18991. },
  18992. readNumber: function Type1Parser_readNumber() {
  18993. var token = this.getToken();
  18994. return parseFloat(token || 0);
  18995. },
  18996. readInt: function Type1Parser_readInt() {
  18997. // Use '| 0' to prevent setting a double into length such as the double
  18998. // does not flow into the loop variable.
  18999. var token = this.getToken();
  19000. return parseInt(token || 0, 10) | 0;
  19001. },
  19002. readBoolean: function Type1Parser_readBoolean() {
  19003. var token = this.getToken();
  19004. // Use 1 and 0 since that's what type2 charstrings use.
  19005. return token === 'true' ? 1 : 0;
  19006. },
  19007. nextChar : function Type1_nextChar() {
  19008. return (this.currentChar = this.stream.getByte());
  19009. },
  19010. getToken: function Type1Parser_getToken() {
  19011. // Eat whitespace and comments.
  19012. var comment = false;
  19013. var ch = this.currentChar;
  19014. while (true) {
  19015. if (ch === -1) {
  19016. return null;
  19017. }
  19018. if (comment) {
  19019. if (ch === 0x0A || ch === 0x0D) {
  19020. comment = false;
  19021. }
  19022. } else if (ch === 0x25) { // '%'
  19023. comment = true;
  19024. } else if (!Lexer.isSpace(ch)) {
  19025. break;
  19026. }
  19027. ch = this.nextChar();
  19028. }
  19029. if (isSpecial(ch)) {
  19030. this.nextChar();
  19031. return String.fromCharCode(ch);
  19032. }
  19033. var token = '';
  19034. do {
  19035. token += String.fromCharCode(ch);
  19036. ch = this.nextChar();
  19037. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  19038. return token;
  19039. },
  19040. /*
  19041. * Returns an object containing a Subrs array and a CharStrings
  19042. * array extracted from and eexec encrypted block of data
  19043. */
  19044. extractFontProgram: function Type1Parser_extractFontProgram() {
  19045. var stream = this.stream;
  19046. var subrs = [], charstrings = [];
  19047. var program = {
  19048. subrs: [],
  19049. charstrings: [],
  19050. properties: {
  19051. 'privateData': {
  19052. 'lenIV': 4
  19053. }
  19054. }
  19055. };
  19056. var token, length, data, lenIV, encoded;
  19057. while ((token = this.getToken()) !== null) {
  19058. if (token !== '/') {
  19059. continue;
  19060. }
  19061. token = this.getToken();
  19062. switch (token) {
  19063. case 'CharStrings':
  19064. // The number immediately following CharStrings must be greater or
  19065. // equal to the number of CharStrings.
  19066. this.getToken();
  19067. this.getToken(); // read in 'dict'
  19068. this.getToken(); // read in 'dup'
  19069. this.getToken(); // read in 'begin'
  19070. while(true) {
  19071. token = this.getToken();
  19072. if (token === null || token === 'end') {
  19073. break;
  19074. }
  19075. if (token !== '/') {
  19076. continue;
  19077. }
  19078. var glyph = this.getToken();
  19079. length = this.readInt();
  19080. this.getToken(); // read in 'RD' or '-|'
  19081. data = stream.makeSubStream(stream.pos, length);
  19082. lenIV = program.properties.privateData['lenIV'];
  19083. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  19084. // Skip past the required space and binary data.
  19085. stream.skip(length);
  19086. this.nextChar();
  19087. token = this.getToken(); // read in 'ND' or '|-'
  19088. if (token === 'noaccess') {
  19089. this.getToken(); // read in 'def'
  19090. }
  19091. charstrings.push({
  19092. glyph: glyph,
  19093. encoded: encoded
  19094. });
  19095. }
  19096. break;
  19097. case 'Subrs':
  19098. var num = this.readInt();
  19099. this.getToken(); // read in 'array'
  19100. while ((token = this.getToken()) === 'dup') {
  19101. var index = this.readInt();
  19102. length = this.readInt();
  19103. this.getToken(); // read in 'RD' or '-|'
  19104. data = stream.makeSubStream(stream.pos, length);
  19105. lenIV = program.properties.privateData['lenIV'];
  19106. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  19107. // Skip past the required space and binary data.
  19108. stream.skip(length);
  19109. this.nextChar();
  19110. token = this.getToken(); // read in 'NP' or '|'
  19111. if (token === 'noaccess') {
  19112. this.getToken(); // read in 'put'
  19113. }
  19114. subrs[index] = encoded;
  19115. }
  19116. break;
  19117. case 'BlueValues':
  19118. case 'OtherBlues':
  19119. case 'FamilyBlues':
  19120. case 'FamilyOtherBlues':
  19121. var blueArray = this.readNumberArray();
  19122. // *Blue* values may contain invalid data: disables reading of
  19123. // those values when hinting is disabled.
  19124. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  19125. HINTING_ENABLED) {
  19126. program.properties.privateData[token] = blueArray;
  19127. }
  19128. break;
  19129. case 'StemSnapH':
  19130. case 'StemSnapV':
  19131. program.properties.privateData[token] = this.readNumberArray();
  19132. break;
  19133. case 'StdHW':
  19134. case 'StdVW':
  19135. program.properties.privateData[token] =
  19136. this.readNumberArray()[0];
  19137. break;
  19138. case 'BlueShift':
  19139. case 'lenIV':
  19140. case 'BlueFuzz':
  19141. case 'BlueScale':
  19142. case 'LanguageGroup':
  19143. case 'ExpansionFactor':
  19144. program.properties.privateData[token] = this.readNumber();
  19145. break;
  19146. case 'ForceBold':
  19147. program.properties.privateData[token] = this.readBoolean();
  19148. break;
  19149. }
  19150. }
  19151. for (var i = 0; i < charstrings.length; i++) {
  19152. glyph = charstrings[i].glyph;
  19153. encoded = charstrings[i].encoded;
  19154. var charString = new Type1CharString();
  19155. var error = charString.convert(encoded, subrs);
  19156. var output = charString.output;
  19157. if (error) {
  19158. // It seems when FreeType encounters an error while evaluating a glyph
  19159. // that it completely ignores the glyph so we'll mimic that behaviour
  19160. // here and put an endchar to make the validator happy.
  19161. output = [14];
  19162. }
  19163. program.charstrings.push({
  19164. glyphName: glyph,
  19165. charstring: output,
  19166. width: charString.width,
  19167. lsb: charString.lsb,
  19168. seac: charString.seac
  19169. });
  19170. }
  19171. return program;
  19172. },
  19173. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  19174. var token;
  19175. while ((token = this.getToken()) !== null) {
  19176. if (token !== '/') {
  19177. continue;
  19178. }
  19179. token = this.getToken();
  19180. switch (token) {
  19181. case 'FontMatrix':
  19182. var matrix = this.readNumberArray();
  19183. properties.fontMatrix = matrix;
  19184. break;
  19185. case 'Encoding':
  19186. var encodingArg = this.getToken();
  19187. var encoding;
  19188. if (!/^\d+$/.test(encodingArg)) {
  19189. // encoding name is specified
  19190. encoding = Encodings[encodingArg];
  19191. } else {
  19192. encoding = [];
  19193. var size = parseInt(encodingArg, 10) | 0;
  19194. this.getToken(); // read in 'array'
  19195. for (var j = 0; j < size; j++) {
  19196. token = this.getToken();
  19197. // skipping till first dup or def (e.g. ignoring for statement)
  19198. while (token !== 'dup' && token !== 'def') {
  19199. token = this.getToken();
  19200. if (token === null) {
  19201. return; // invalid header
  19202. }
  19203. }
  19204. if (token === 'def') {
  19205. break; // read all array data
  19206. }
  19207. var index = this.readInt();
  19208. this.getToken(); // read in '/'
  19209. var glyph = this.getToken();
  19210. encoding[index] = glyph;
  19211. this.getToken(); // read the in 'put'
  19212. }
  19213. }
  19214. properties.builtInEncoding = encoding;
  19215. break;
  19216. case 'FontBBox':
  19217. var fontBBox = this.readNumberArray();
  19218. // adjusting ascent/descent
  19219. properties.ascent = fontBBox[3];
  19220. properties.descent = fontBBox[1];
  19221. properties.ascentScaled = true;
  19222. break;
  19223. }
  19224. }
  19225. }
  19226. };
  19227. return Type1Parser;
  19228. })();
  19229. /**
  19230. * The CFF class takes a Type1 file and wrap it into a
  19231. * 'Compact Font Format' which itself embed Type2 charstrings.
  19232. */
  19233. var CFFStandardStrings = [
  19234. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  19235. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  19236. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  19237. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  19238. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  19239. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  19240. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  19241. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  19242. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  19243. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  19244. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  19245. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  19246. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  19247. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  19248. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  19249. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  19250. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  19251. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  19252. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  19253. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  19254. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  19255. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  19256. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  19257. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  19258. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  19259. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  19260. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  19261. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  19262. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  19263. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  19264. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  19265. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  19266. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  19267. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  19268. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  19269. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  19270. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  19271. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  19272. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  19273. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  19274. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  19275. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  19276. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  19277. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  19278. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  19279. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  19280. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  19281. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  19282. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  19283. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  19284. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  19285. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  19286. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  19287. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  19288. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  19289. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  19290. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  19291. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  19292. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  19293. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  19294. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  19295. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  19296. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  19297. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  19298. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  19299. ];
  19300. // Type1Font is also a CIDFontType0.
  19301. var Type1Font = function Type1Font(name, file, properties) {
  19302. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  19303. // Also, length1 and length2 might be off by 6 bytes as well.
  19304. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  19305. var PFB_HEADER_SIZE = 6;
  19306. var headerBlockLength = properties.length1;
  19307. var eexecBlockLength = properties.length2;
  19308. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  19309. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  19310. if (pfbHeaderPresent) {
  19311. file.skip(PFB_HEADER_SIZE);
  19312. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  19313. (pfbHeader[3] << 8) | pfbHeader[2];
  19314. }
  19315. // Get the data block containing glyphs and subrs informations
  19316. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  19317. var headerBlockParser = new Type1Parser(headerBlock);
  19318. headerBlockParser.extractFontHeader(properties);
  19319. if (pfbHeaderPresent) {
  19320. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  19321. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  19322. (pfbHeader[3] << 8) | pfbHeader[2];
  19323. }
  19324. // Decrypt the data blocks and retrieve it's content
  19325. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  19326. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  19327. var data = eexecBlockParser.extractFontProgram();
  19328. for (var info in data.properties) {
  19329. properties[info] = data.properties[info];
  19330. }
  19331. var charstrings = data.charstrings;
  19332. var type2Charstrings = this.getType2Charstrings(charstrings);
  19333. var subrs = this.getType2Subrs(data.subrs);
  19334. this.charstrings = charstrings;
  19335. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  19336. subrs, properties);
  19337. this.seacs = this.getSeacs(data.charstrings);
  19338. };
  19339. Type1Font.prototype = {
  19340. get numGlyphs() {
  19341. return this.charstrings.length + 1;
  19342. },
  19343. getCharset: function Type1Font_getCharset() {
  19344. var charset = ['.notdef'];
  19345. var charstrings = this.charstrings;
  19346. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  19347. charset.push(charstrings[glyphId].glyphName);
  19348. }
  19349. return charset;
  19350. },
  19351. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  19352. var charstrings = this.charstrings;
  19353. var glyphNames = ['.notdef'], glyphId;
  19354. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  19355. glyphNames.push(charstrings[glyphId].glyphName);
  19356. }
  19357. var encoding = properties.builtInEncoding;
  19358. if (encoding) {
  19359. var builtInEncoding = {};
  19360. for (var charCode in encoding) {
  19361. glyphId = glyphNames.indexOf(encoding[charCode]);
  19362. if (glyphId >= 0) {
  19363. builtInEncoding[charCode] = glyphId;
  19364. }
  19365. }
  19366. }
  19367. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  19368. },
  19369. getSeacs: function Type1Font_getSeacs(charstrings) {
  19370. var i, ii;
  19371. var seacMap = [];
  19372. for (i = 0, ii = charstrings.length; i < ii; i++) {
  19373. var charstring = charstrings[i];
  19374. if (charstring.seac) {
  19375. // Offset by 1 for .notdef
  19376. seacMap[i + 1] = charstring.seac;
  19377. }
  19378. }
  19379. return seacMap;
  19380. },
  19381. getType2Charstrings: function Type1Font_getType2Charstrings(
  19382. type1Charstrings) {
  19383. var type2Charstrings = [];
  19384. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  19385. type2Charstrings.push(type1Charstrings[i].charstring);
  19386. }
  19387. return type2Charstrings;
  19388. },
  19389. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  19390. var bias = 0;
  19391. var count = type1Subrs.length;
  19392. if (count < 1133) {
  19393. bias = 107;
  19394. } else if (count < 33769) {
  19395. bias = 1131;
  19396. } else {
  19397. bias = 32768;
  19398. }
  19399. // Add a bunch of empty subrs to deal with the Type2 bias
  19400. var type2Subrs = [];
  19401. var i;
  19402. for (i = 0; i < bias; i++) {
  19403. type2Subrs.push([0x0B]);
  19404. }
  19405. for (i = 0; i < count; i++) {
  19406. type2Subrs.push(type1Subrs[i]);
  19407. }
  19408. return type2Subrs;
  19409. },
  19410. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  19411. var cff = new CFF();
  19412. cff.header = new CFFHeader(1, 0, 4, 4);
  19413. cff.names = [name];
  19414. var topDict = new CFFTopDict();
  19415. // CFF strings IDs 0...390 are predefined names, so refering
  19416. // to entries in our own String INDEX starts at SID 391.
  19417. topDict.setByName('version', 391);
  19418. topDict.setByName('Notice', 392);
  19419. topDict.setByName('FullName', 393);
  19420. topDict.setByName('FamilyName', 394);
  19421. topDict.setByName('Weight', 395);
  19422. topDict.setByName('Encoding', null); // placeholder
  19423. topDict.setByName('FontMatrix', properties.fontMatrix);
  19424. topDict.setByName('FontBBox', properties.bbox);
  19425. topDict.setByName('charset', null); // placeholder
  19426. topDict.setByName('CharStrings', null); // placeholder
  19427. topDict.setByName('Private', null); // placeholder
  19428. cff.topDict = topDict;
  19429. var strings = new CFFStrings();
  19430. strings.add('Version 0.11'); // Version
  19431. strings.add('See original notice'); // Notice
  19432. strings.add(name); // FullName
  19433. strings.add(name); // FamilyName
  19434. strings.add('Medium'); // Weight
  19435. cff.strings = strings;
  19436. cff.globalSubrIndex = new CFFIndex();
  19437. var count = glyphs.length;
  19438. var charsetArray = [0];
  19439. var i, ii;
  19440. for (i = 0; i < count; i++) {
  19441. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  19442. // TODO: Insert the string and correctly map it. Previously it was
  19443. // thought mapping names that aren't in the standard strings to .notdef
  19444. // was fine, however in issue818 when mapping them all to .notdef the
  19445. // adieresis glyph no longer worked.
  19446. if (index === -1) {
  19447. index = 0;
  19448. }
  19449. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  19450. }
  19451. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  19452. var charStringsIndex = new CFFIndex();
  19453. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  19454. for (i = 0; i < count; i++) {
  19455. charStringsIndex.add(glyphs[i]);
  19456. }
  19457. cff.charStrings = charStringsIndex;
  19458. var privateDict = new CFFPrivateDict();
  19459. privateDict.setByName('Subrs', null); // placeholder
  19460. var fields = [
  19461. 'BlueValues',
  19462. 'OtherBlues',
  19463. 'FamilyBlues',
  19464. 'FamilyOtherBlues',
  19465. 'StemSnapH',
  19466. 'StemSnapV',
  19467. 'BlueShift',
  19468. 'BlueFuzz',
  19469. 'BlueScale',
  19470. 'LanguageGroup',
  19471. 'ExpansionFactor',
  19472. 'ForceBold',
  19473. 'StdHW',
  19474. 'StdVW'
  19475. ];
  19476. for (i = 0, ii = fields.length; i < ii; i++) {
  19477. var field = fields[i];
  19478. if (!properties.privateData.hasOwnProperty(field)) {
  19479. continue;
  19480. }
  19481. var value = properties.privateData[field];
  19482. if (isArray(value)) {
  19483. // All of the private dictionary array data in CFF must be stored as
  19484. // "delta-encoded" numbers.
  19485. for (var j = value.length - 1; j > 0; j--) {
  19486. value[j] -= value[j - 1]; // ... difference from previous value
  19487. }
  19488. }
  19489. privateDict.setByName(field, value);
  19490. }
  19491. cff.topDict.privateDict = privateDict;
  19492. var subrIndex = new CFFIndex();
  19493. for (i = 0, ii = subrs.length; i < ii; i++) {
  19494. subrIndex.add(subrs[i]);
  19495. }
  19496. privateDict.subrsIndex = subrIndex;
  19497. var compiler = new CFFCompiler(cff);
  19498. return compiler.compile();
  19499. }
  19500. };
  19501. var CFFFont = (function CFFFontClosure() {
  19502. function CFFFont(file, properties) {
  19503. this.properties = properties;
  19504. var parser = new CFFParser(file, properties);
  19505. this.cff = parser.parse();
  19506. var compiler = new CFFCompiler(this.cff);
  19507. this.seacs = this.cff.seacs;
  19508. try {
  19509. this.data = compiler.compile();
  19510. } catch (e) {
  19511. warn('Failed to compile font ' + properties.loadedName);
  19512. // There may have just been an issue with the compiler, set the data
  19513. // anyway and hope the font loaded.
  19514. this.data = file;
  19515. }
  19516. }
  19517. CFFFont.prototype = {
  19518. get numGlyphs() {
  19519. return this.cff.charStrings.count;
  19520. },
  19521. getCharset: function CFFFont_getCharset() {
  19522. return this.cff.charset.charset;
  19523. },
  19524. getGlyphMapping: function CFFFont_getGlyphMapping() {
  19525. var cff = this.cff;
  19526. var properties = this.properties;
  19527. var charsets = cff.charset.charset;
  19528. var charCodeToGlyphId;
  19529. var glyphId;
  19530. if (properties.composite) {
  19531. charCodeToGlyphId = Object.create(null);
  19532. if (cff.isCIDFont) {
  19533. // If the font is actually a CID font then we should use the charset
  19534. // to map CIDs to GIDs.
  19535. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  19536. var cid = charsets[glyphId];
  19537. var charCode = properties.cMap.charCodeOf(cid);
  19538. charCodeToGlyphId[charCode] = glyphId;
  19539. }
  19540. } else {
  19541. // If it is NOT actually a CID font then CIDs should be mapped
  19542. // directly to GIDs.
  19543. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  19544. charCodeToGlyphId[glyphId] = glyphId;
  19545. }
  19546. }
  19547. return charCodeToGlyphId;
  19548. }
  19549. var encoding = cff.encoding ? cff.encoding.encoding : null;
  19550. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  19551. return charCodeToGlyphId;
  19552. }
  19553. };
  19554. return CFFFont;
  19555. })();
  19556. var CFFParser = (function CFFParserClosure() {
  19557. var CharstringValidationData = [
  19558. null,
  19559. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  19560. null,
  19561. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  19562. { id: 'vmoveto', min: 1, stackClearing: true },
  19563. { id: 'rlineto', min: 2, resetStack: true },
  19564. { id: 'hlineto', min: 1, resetStack: true },
  19565. { id: 'vlineto', min: 1, resetStack: true },
  19566. { id: 'rrcurveto', min: 6, resetStack: true },
  19567. null,
  19568. { id: 'callsubr', min: 1, undefStack: true },
  19569. { id: 'return', min: 0, undefStack: true },
  19570. null, // 12
  19571. null,
  19572. { id: 'endchar', min: 0, stackClearing: true },
  19573. null,
  19574. null,
  19575. null,
  19576. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  19577. { id: 'hintmask', min: 0, stackClearing: true },
  19578. { id: 'cntrmask', min: 0, stackClearing: true },
  19579. { id: 'rmoveto', min: 2, stackClearing: true },
  19580. { id: 'hmoveto', min: 1, stackClearing: true },
  19581. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  19582. { id: 'rcurveline', min: 8, resetStack: true },
  19583. { id: 'rlinecurve', min: 8, resetStack: true },
  19584. { id: 'vvcurveto', min: 4, resetStack: true },
  19585. { id: 'hhcurveto', min: 4, resetStack: true },
  19586. null, // shortint
  19587. { id: 'callgsubr', min: 1, undefStack: true },
  19588. { id: 'vhcurveto', min: 4, resetStack: true },
  19589. { id: 'hvcurveto', min: 4, resetStack: true }
  19590. ];
  19591. var CharstringValidationData12 = [
  19592. null,
  19593. null,
  19594. null,
  19595. { id: 'and', min: 2, stackDelta: -1 },
  19596. { id: 'or', min: 2, stackDelta: -1 },
  19597. { id: 'not', min: 1, stackDelta: 0 },
  19598. null,
  19599. null,
  19600. null,
  19601. { id: 'abs', min: 1, stackDelta: 0 },
  19602. { id: 'add', min: 2, stackDelta: -1,
  19603. stackFn: function stack_div(stack, index) {
  19604. stack[index - 2] = stack[index - 2] + stack[index - 1];
  19605. }
  19606. },
  19607. { id: 'sub', min: 2, stackDelta: -1,
  19608. stackFn: function stack_div(stack, index) {
  19609. stack[index - 2] = stack[index - 2] - stack[index - 1];
  19610. }
  19611. },
  19612. { id: 'div', min: 2, stackDelta: -1,
  19613. stackFn: function stack_div(stack, index) {
  19614. stack[index - 2] = stack[index - 2] / stack[index - 1];
  19615. }
  19616. },
  19617. null,
  19618. { id: 'neg', min: 1, stackDelta: 0,
  19619. stackFn: function stack_div(stack, index) {
  19620. stack[index - 1] = -stack[index - 1];
  19621. }
  19622. },
  19623. { id: 'eq', min: 2, stackDelta: -1 },
  19624. null,
  19625. null,
  19626. { id: 'drop', min: 1, stackDelta: -1 },
  19627. null,
  19628. { id: 'put', min: 2, stackDelta: -2 },
  19629. { id: 'get', min: 1, stackDelta: 0 },
  19630. { id: 'ifelse', min: 4, stackDelta: -3 },
  19631. { id: 'random', min: 0, stackDelta: 1 },
  19632. { id: 'mul', min: 2, stackDelta: -1,
  19633. stackFn: function stack_div(stack, index) {
  19634. stack[index - 2] = stack[index - 2] * stack[index - 1];
  19635. }
  19636. },
  19637. null,
  19638. { id: 'sqrt', min: 1, stackDelta: 0 },
  19639. { id: 'dup', min: 1, stackDelta: 1 },
  19640. { id: 'exch', min: 2, stackDelta: 0 },
  19641. { id: 'index', min: 2, stackDelta: 0 },
  19642. { id: 'roll', min: 3, stackDelta: -2 },
  19643. null,
  19644. null,
  19645. null,
  19646. { id: 'hflex', min: 7, resetStack: true },
  19647. { id: 'flex', min: 13, resetStack: true },
  19648. { id: 'hflex1', min: 9, resetStack: true },
  19649. { id: 'flex1', min: 11, resetStack: true }
  19650. ];
  19651. function CFFParser(file, properties) {
  19652. this.bytes = file.getBytes();
  19653. this.properties = properties;
  19654. }
  19655. CFFParser.prototype = {
  19656. parse: function CFFParser_parse() {
  19657. var properties = this.properties;
  19658. var cff = new CFF();
  19659. this.cff = cff;
  19660. // The first five sections must be in order, all the others are reached
  19661. // via offsets contained in one of the below.
  19662. var header = this.parseHeader();
  19663. var nameIndex = this.parseIndex(header.endPos);
  19664. var topDictIndex = this.parseIndex(nameIndex.endPos);
  19665. var stringIndex = this.parseIndex(topDictIndex.endPos);
  19666. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  19667. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  19668. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  19669. cff.header = header.obj;
  19670. cff.names = this.parseNameIndex(nameIndex.obj);
  19671. cff.strings = this.parseStringIndex(stringIndex.obj);
  19672. cff.topDict = topDict;
  19673. cff.globalSubrIndex = globalSubrIndex.obj;
  19674. this.parsePrivateDict(cff.topDict);
  19675. cff.isCIDFont = topDict.hasName('ROS');
  19676. var charStringOffset = topDict.getByName('CharStrings');
  19677. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  19678. cff.charStrings = charStringsAndSeacs.charStrings;
  19679. cff.seacs = charStringsAndSeacs.seacs;
  19680. cff.widths = charStringsAndSeacs.widths;
  19681. var fontMatrix = topDict.getByName('FontMatrix');
  19682. if (fontMatrix) {
  19683. properties.fontMatrix = fontMatrix;
  19684. }
  19685. var fontBBox = topDict.getByName('FontBBox');
  19686. if (fontBBox) {
  19687. // adjusting ascent/descent
  19688. properties.ascent = fontBBox[3];
  19689. properties.descent = fontBBox[1];
  19690. properties.ascentScaled = true;
  19691. }
  19692. var charset, encoding;
  19693. if (cff.isCIDFont) {
  19694. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  19695. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  19696. var dictRaw = fdArrayIndex.get(i);
  19697. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  19698. cff.strings);
  19699. this.parsePrivateDict(fontDict);
  19700. cff.fdArray.push(fontDict);
  19701. }
  19702. // cid fonts don't have an encoding
  19703. encoding = null;
  19704. charset = this.parseCharsets(topDict.getByName('charset'),
  19705. cff.charStrings.count, cff.strings, true);
  19706. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  19707. cff.charStrings.count);
  19708. } else {
  19709. charset = this.parseCharsets(topDict.getByName('charset'),
  19710. cff.charStrings.count, cff.strings, false);
  19711. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  19712. properties,
  19713. cff.strings, charset.charset);
  19714. }
  19715. cff.charset = charset;
  19716. cff.encoding = encoding;
  19717. return cff;
  19718. },
  19719. parseHeader: function CFFParser_parseHeader() {
  19720. var bytes = this.bytes;
  19721. var bytesLength = bytes.length;
  19722. var offset = 0;
  19723. // Prevent an infinite loop, by checking that the offset is within the
  19724. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  19725. while (offset < bytesLength && bytes[offset] !== 1) {
  19726. ++offset;
  19727. }
  19728. if (offset >= bytesLength) {
  19729. error('Invalid CFF header');
  19730. } else if (offset !== 0) {
  19731. info('cff data is shifted');
  19732. bytes = bytes.subarray(offset);
  19733. this.bytes = bytes;
  19734. }
  19735. var major = bytes[0];
  19736. var minor = bytes[1];
  19737. var hdrSize = bytes[2];
  19738. var offSize = bytes[3];
  19739. var header = new CFFHeader(major, minor, hdrSize, offSize);
  19740. return { obj: header, endPos: hdrSize };
  19741. },
  19742. parseDict: function CFFParser_parseDict(dict) {
  19743. var pos = 0;
  19744. function parseOperand() {
  19745. var value = dict[pos++];
  19746. if (value === 30) {
  19747. return parseFloatOperand(pos);
  19748. } else if (value === 28) {
  19749. value = dict[pos++];
  19750. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  19751. return value;
  19752. } else if (value === 29) {
  19753. value = dict[pos++];
  19754. value = (value << 8) | dict[pos++];
  19755. value = (value << 8) | dict[pos++];
  19756. value = (value << 8) | dict[pos++];
  19757. return value;
  19758. } else if (value >= 32 && value <= 246) {
  19759. return value - 139;
  19760. } else if (value >= 247 && value <= 250) {
  19761. return ((value - 247) * 256) + dict[pos++] + 108;
  19762. } else if (value >= 251 && value <= 254) {
  19763. return -((value - 251) * 256) - dict[pos++] - 108;
  19764. } else {
  19765. error('255 is not a valid DICT command');
  19766. }
  19767. return -1;
  19768. }
  19769. function parseFloatOperand() {
  19770. var str = '';
  19771. var eof = 15;
  19772. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  19773. '9', '.', 'E', 'E-', null, '-'];
  19774. var length = dict.length;
  19775. while (pos < length) {
  19776. var b = dict[pos++];
  19777. var b1 = b >> 4;
  19778. var b2 = b & 15;
  19779. if (b1 === eof) {
  19780. break;
  19781. }
  19782. str += lookup[b1];
  19783. if (b2 === eof) {
  19784. break;
  19785. }
  19786. str += lookup[b2];
  19787. }
  19788. return parseFloat(str);
  19789. }
  19790. var operands = [];
  19791. var entries = [];
  19792. pos = 0;
  19793. var end = dict.length;
  19794. while (pos < end) {
  19795. var b = dict[pos];
  19796. if (b <= 21) {
  19797. if (b === 12) {
  19798. b = (b << 8) | dict[++pos];
  19799. }
  19800. entries.push([b, operands]);
  19801. operands = [];
  19802. ++pos;
  19803. } else {
  19804. operands.push(parseOperand());
  19805. }
  19806. }
  19807. return entries;
  19808. },
  19809. parseIndex: function CFFParser_parseIndex(pos) {
  19810. var cffIndex = new CFFIndex();
  19811. var bytes = this.bytes;
  19812. var count = (bytes[pos++] << 8) | bytes[pos++];
  19813. var offsets = [];
  19814. var end = pos;
  19815. var i, ii;
  19816. if (count !== 0) {
  19817. var offsetSize = bytes[pos++];
  19818. // add 1 for offset to determine size of last object
  19819. var startPos = pos + ((count + 1) * offsetSize) - 1;
  19820. for (i = 0, ii = count + 1; i < ii; ++i) {
  19821. var offset = 0;
  19822. for (var j = 0; j < offsetSize; ++j) {
  19823. offset <<= 8;
  19824. offset += bytes[pos++];
  19825. }
  19826. offsets.push(startPos + offset);
  19827. }
  19828. end = offsets[count];
  19829. }
  19830. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  19831. var offsetStart = offsets[i];
  19832. var offsetEnd = offsets[i + 1];
  19833. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  19834. }
  19835. return {obj: cffIndex, endPos: end};
  19836. },
  19837. parseNameIndex: function CFFParser_parseNameIndex(index) {
  19838. var names = [];
  19839. for (var i = 0, ii = index.count; i < ii; ++i) {
  19840. var name = index.get(i);
  19841. // OTS doesn't allow names to be over 127 characters.
  19842. var length = Math.min(name.length, 127);
  19843. var data = [];
  19844. // OTS also only permits certain characters in the name.
  19845. for (var j = 0; j < length; ++j) {
  19846. var c = name[j];
  19847. if (j === 0 && c === 0) {
  19848. data[j] = c;
  19849. continue;
  19850. }
  19851. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  19852. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  19853. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  19854. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  19855. data[j] = 95;
  19856. continue;
  19857. }
  19858. data[j] = c;
  19859. }
  19860. names.push(bytesToString(data));
  19861. }
  19862. return names;
  19863. },
  19864. parseStringIndex: function CFFParser_parseStringIndex(index) {
  19865. var strings = new CFFStrings();
  19866. for (var i = 0, ii = index.count; i < ii; ++i) {
  19867. var data = index.get(i);
  19868. strings.add(bytesToString(data));
  19869. }
  19870. return strings;
  19871. },
  19872. createDict: function CFFParser_createDict(Type, dict, strings) {
  19873. var cffDict = new Type(strings);
  19874. for (var i = 0, ii = dict.length; i < ii; ++i) {
  19875. var pair = dict[i];
  19876. var key = pair[0];
  19877. var value = pair[1];
  19878. cffDict.setByKey(key, value);
  19879. }
  19880. return cffDict;
  19881. },
  19882. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  19883. var charStrings = this.parseIndex(charStringOffset).obj;
  19884. var seacs = [];
  19885. var widths = [];
  19886. var count = charStrings.count;
  19887. for (var i = 0; i < count; i++) {
  19888. var charstring = charStrings.get(i);
  19889. var stackSize = 0;
  19890. var stack = [];
  19891. var undefStack = true;
  19892. var hints = 0;
  19893. var valid = true;
  19894. var data = charstring;
  19895. var length = data.length;
  19896. var firstStackClearing = true;
  19897. for (var j = 0; j < length;) {
  19898. var value = data[j++];
  19899. var validationCommand = null;
  19900. if (value === 12) {
  19901. var q = data[j++];
  19902. if (q === 0) {
  19903. // The CFF specification state that the 'dotsection' command
  19904. // (12, 0) is deprecated and treated as a no-op, but all Type2
  19905. // charstrings processors should support them. Unfortunately
  19906. // the font sanitizer don't. As a workaround the sequence (12, 0)
  19907. // is replaced by a useless (0, hmoveto).
  19908. data[j - 2] = 139;
  19909. data[j - 1] = 22;
  19910. stackSize = 0;
  19911. } else {
  19912. validationCommand = CharstringValidationData12[q];
  19913. }
  19914. } else if (value === 28) { // number (16 bit)
  19915. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  19916. j += 2;
  19917. stackSize++;
  19918. } else if (value === 14) {
  19919. if (stackSize >= 4) {
  19920. stackSize -= 4;
  19921. if (SEAC_ANALYSIS_ENABLED) {
  19922. seacs[i] = stack.slice(stackSize, stackSize + 4);
  19923. valid = false;
  19924. }
  19925. }
  19926. validationCommand = CharstringValidationData[value];
  19927. } else if (value >= 32 && value <= 246) { // number
  19928. stack[stackSize] = value - 139;
  19929. stackSize++;
  19930. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  19931. stack[stackSize] = (value < 251 ?
  19932. ((value - 247) << 8) + data[j] + 108 :
  19933. -((value - 251) << 8) - data[j] - 108);
  19934. j++;
  19935. stackSize++;
  19936. } else if (value === 255) { // number (32 bit)
  19937. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  19938. (data[j + 2] << 8) | data[j + 3]) / 65536;
  19939. j += 4;
  19940. stackSize++;
  19941. } else if (value === 19 || value === 20) {
  19942. hints += stackSize >> 1;
  19943. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  19944. stackSize %= 2;
  19945. validationCommand = CharstringValidationData[value];
  19946. } else {
  19947. validationCommand = CharstringValidationData[value];
  19948. }
  19949. if (validationCommand) {
  19950. if (validationCommand.stem) {
  19951. hints += stackSize >> 1;
  19952. }
  19953. if ('min' in validationCommand) {
  19954. if (!undefStack && stackSize < validationCommand.min) {
  19955. warn('Not enough parameters for ' + validationCommand.id +
  19956. '; actual: ' + stackSize +
  19957. ', expected: ' + validationCommand.min);
  19958. valid = false;
  19959. break;
  19960. }
  19961. }
  19962. if (firstStackClearing && validationCommand.stackClearing) {
  19963. firstStackClearing = false;
  19964. // the optional character width can be found before the first
  19965. // stack-clearing command arguments
  19966. stackSize -= validationCommand.min;
  19967. if (stackSize >= 2 && validationCommand.stem) {
  19968. // there are even amount of arguments for stem commands
  19969. stackSize %= 2;
  19970. } else if (stackSize > 1) {
  19971. warn('Found too many parameters for stack-clearing command');
  19972. }
  19973. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  19974. widths[i] = stack[stackSize - 1];
  19975. }
  19976. }
  19977. if ('stackDelta' in validationCommand) {
  19978. if ('stackFn' in validationCommand) {
  19979. validationCommand.stackFn(stack, stackSize);
  19980. }
  19981. stackSize += validationCommand.stackDelta;
  19982. } else if (validationCommand.stackClearing) {
  19983. stackSize = 0;
  19984. } else if (validationCommand.resetStack) {
  19985. stackSize = 0;
  19986. undefStack = false;
  19987. } else if (validationCommand.undefStack) {
  19988. stackSize = 0;
  19989. undefStack = true;
  19990. firstStackClearing = false;
  19991. }
  19992. }
  19993. }
  19994. if (!valid) {
  19995. // resetting invalid charstring to single 'endchar'
  19996. charStrings.set(i, new Uint8Array([14]));
  19997. }
  19998. }
  19999. return { charStrings: charStrings, seacs: seacs, widths: widths };
  20000. },
  20001. emptyPrivateDictionary:
  20002. function CFFParser_emptyPrivateDictionary(parentDict) {
  20003. var privateDict = this.createDict(CFFPrivateDict, [],
  20004. parentDict.strings);
  20005. parentDict.setByKey(18, [0, 0]);
  20006. parentDict.privateDict = privateDict;
  20007. },
  20008. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  20009. // no private dict, do nothing
  20010. if (!parentDict.hasName('Private')) {
  20011. this.emptyPrivateDictionary(parentDict);
  20012. return;
  20013. }
  20014. var privateOffset = parentDict.getByName('Private');
  20015. // make sure the params are formatted correctly
  20016. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  20017. parentDict.removeByName('Private');
  20018. return;
  20019. }
  20020. var size = privateOffset[0];
  20021. var offset = privateOffset[1];
  20022. // remove empty dicts or ones that refer to invalid location
  20023. if (size === 0 || offset >= this.bytes.length) {
  20024. this.emptyPrivateDictionary(parentDict);
  20025. return;
  20026. }
  20027. var privateDictEnd = offset + size;
  20028. var dictData = this.bytes.subarray(offset, privateDictEnd);
  20029. var dict = this.parseDict(dictData);
  20030. var privateDict = this.createDict(CFFPrivateDict, dict,
  20031. parentDict.strings);
  20032. parentDict.privateDict = privateDict;
  20033. // Parse the Subrs index also since it's relative to the private dict.
  20034. if (!privateDict.getByName('Subrs')) {
  20035. return;
  20036. }
  20037. var subrsOffset = privateDict.getByName('Subrs');
  20038. var relativeOffset = offset + subrsOffset;
  20039. // Validate the offset.
  20040. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  20041. this.emptyPrivateDictionary(parentDict);
  20042. return;
  20043. }
  20044. var subrsIndex = this.parseIndex(relativeOffset);
  20045. privateDict.subrsIndex = subrsIndex.obj;
  20046. },
  20047. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  20048. if (pos === 0) {
  20049. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  20050. ISOAdobeCharset);
  20051. } else if (pos === 1) {
  20052. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  20053. ExpertCharset);
  20054. } else if (pos === 2) {
  20055. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  20056. ExpertSubsetCharset);
  20057. }
  20058. var bytes = this.bytes;
  20059. var start = pos;
  20060. var format = bytes[pos++];
  20061. var charset = ['.notdef'];
  20062. var id, count, i;
  20063. // subtract 1 for the .notdef glyph
  20064. length -= 1;
  20065. switch (format) {
  20066. case 0:
  20067. for (i = 0; i < length; i++) {
  20068. id = (bytes[pos++] << 8) | bytes[pos++];
  20069. charset.push(cid ? id : strings.get(id));
  20070. }
  20071. break;
  20072. case 1:
  20073. while (charset.length <= length) {
  20074. id = (bytes[pos++] << 8) | bytes[pos++];
  20075. count = bytes[pos++];
  20076. for (i = 0; i <= count; i++) {
  20077. charset.push(cid ? id++ : strings.get(id++));
  20078. }
  20079. }
  20080. break;
  20081. case 2:
  20082. while (charset.length <= length) {
  20083. id = (bytes[pos++] << 8) | bytes[pos++];
  20084. count = (bytes[pos++] << 8) | bytes[pos++];
  20085. for (i = 0; i <= count; i++) {
  20086. charset.push(cid ? id++ : strings.get(id++));
  20087. }
  20088. }
  20089. break;
  20090. default:
  20091. error('Unknown charset format');
  20092. }
  20093. // Raw won't be needed if we actually compile the charset.
  20094. var end = pos;
  20095. var raw = bytes.subarray(start, end);
  20096. return new CFFCharset(false, format, charset, raw);
  20097. },
  20098. parseEncoding: function CFFParser_parseEncoding(pos,
  20099. properties,
  20100. strings,
  20101. charset) {
  20102. var encoding = {};
  20103. var bytes = this.bytes;
  20104. var predefined = false;
  20105. var hasSupplement = false;
  20106. var format, i, ii;
  20107. var raw = null;
  20108. function readSupplement() {
  20109. var supplementsCount = bytes[pos++];
  20110. for (i = 0; i < supplementsCount; i++) {
  20111. var code = bytes[pos++];
  20112. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  20113. encoding[code] = charset.indexOf(strings.get(sid));
  20114. }
  20115. }
  20116. if (pos === 0 || pos === 1) {
  20117. predefined = true;
  20118. format = pos;
  20119. var baseEncoding = pos ? Encodings.ExpertEncoding :
  20120. Encodings.StandardEncoding;
  20121. for (i = 0, ii = charset.length; i < ii; i++) {
  20122. var index = baseEncoding.indexOf(charset[i]);
  20123. if (index !== -1) {
  20124. encoding[index] = i;
  20125. }
  20126. }
  20127. } else {
  20128. var dataStart = pos;
  20129. format = bytes[pos++];
  20130. switch (format & 0x7f) {
  20131. case 0:
  20132. var glyphsCount = bytes[pos++];
  20133. for (i = 1; i <= glyphsCount; i++) {
  20134. encoding[bytes[pos++]] = i;
  20135. }
  20136. break;
  20137. case 1:
  20138. var rangesCount = bytes[pos++];
  20139. var gid = 1;
  20140. for (i = 0; i < rangesCount; i++) {
  20141. var start = bytes[pos++];
  20142. var left = bytes[pos++];
  20143. for (var j = start; j <= start + left; j++) {
  20144. encoding[j] = gid++;
  20145. }
  20146. }
  20147. break;
  20148. default:
  20149. error('Unknow encoding format: ' + format + ' in CFF');
  20150. break;
  20151. }
  20152. var dataEnd = pos;
  20153. if (format & 0x80) {
  20154. // The font sanitizer does not support CFF encoding with a
  20155. // supplement, since the encoding is not really used to map
  20156. // between gid to glyph, let's overwrite what is declared in
  20157. // the top dictionary to let the sanitizer think the font use
  20158. // StandardEncoding, that's a lie but that's ok.
  20159. bytes[dataStart] &= 0x7f;
  20160. readSupplement();
  20161. hasSupplement = true;
  20162. }
  20163. raw = bytes.subarray(dataStart, dataEnd);
  20164. }
  20165. format = format & 0x7f;
  20166. return new CFFEncoding(predefined, format, encoding, raw);
  20167. },
  20168. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  20169. var start = pos;
  20170. var bytes = this.bytes;
  20171. var format = bytes[pos++];
  20172. var fdSelect = [];
  20173. var i;
  20174. switch (format) {
  20175. case 0:
  20176. for (i = 0; i < length; ++i) {
  20177. var id = bytes[pos++];
  20178. fdSelect.push(id);
  20179. }
  20180. break;
  20181. case 3:
  20182. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  20183. for (i = 0; i < rangesCount; ++i) {
  20184. var first = (bytes[pos++] << 8) | bytes[pos++];
  20185. var fdIndex = bytes[pos++];
  20186. var next = (bytes[pos] << 8) | bytes[pos + 1];
  20187. for (var j = first; j < next; ++j) {
  20188. fdSelect.push(fdIndex);
  20189. }
  20190. }
  20191. // Advance past the sentinel(next).
  20192. pos += 2;
  20193. break;
  20194. default:
  20195. error('Unknown fdselect format ' + format);
  20196. break;
  20197. }
  20198. var end = pos;
  20199. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  20200. }
  20201. };
  20202. return CFFParser;
  20203. })();
  20204. // Compact Font Format
  20205. var CFF = (function CFFClosure() {
  20206. function CFF() {
  20207. this.header = null;
  20208. this.names = [];
  20209. this.topDict = null;
  20210. this.strings = new CFFStrings();
  20211. this.globalSubrIndex = null;
  20212. // The following could really be per font, but since we only have one font
  20213. // store them here.
  20214. this.encoding = null;
  20215. this.charset = null;
  20216. this.charStrings = null;
  20217. this.fdArray = [];
  20218. this.fdSelect = null;
  20219. this.isCIDFont = false;
  20220. }
  20221. return CFF;
  20222. })();
  20223. var CFFHeader = (function CFFHeaderClosure() {
  20224. function CFFHeader(major, minor, hdrSize, offSize) {
  20225. this.major = major;
  20226. this.minor = minor;
  20227. this.hdrSize = hdrSize;
  20228. this.offSize = offSize;
  20229. }
  20230. return CFFHeader;
  20231. })();
  20232. var CFFStrings = (function CFFStringsClosure() {
  20233. function CFFStrings() {
  20234. this.strings = [];
  20235. }
  20236. CFFStrings.prototype = {
  20237. get: function CFFStrings_get(index) {
  20238. if (index >= 0 && index <= 390) {
  20239. return CFFStandardStrings[index];
  20240. }
  20241. if (index - 391 <= this.strings.length) {
  20242. return this.strings[index - 391];
  20243. }
  20244. return CFFStandardStrings[0];
  20245. },
  20246. add: function CFFStrings_add(value) {
  20247. this.strings.push(value);
  20248. },
  20249. get count() {
  20250. return this.strings.length;
  20251. }
  20252. };
  20253. return CFFStrings;
  20254. })();
  20255. var CFFIndex = (function CFFIndexClosure() {
  20256. function CFFIndex() {
  20257. this.objects = [];
  20258. this.length = 0;
  20259. }
  20260. CFFIndex.prototype = {
  20261. add: function CFFIndex_add(data) {
  20262. this.length += data.length;
  20263. this.objects.push(data);
  20264. },
  20265. set: function CFFIndex_set(index, data) {
  20266. this.length += data.length - this.objects[index].length;
  20267. this.objects[index] = data;
  20268. },
  20269. get: function CFFIndex_get(index) {
  20270. return this.objects[index];
  20271. },
  20272. get count() {
  20273. return this.objects.length;
  20274. }
  20275. };
  20276. return CFFIndex;
  20277. })();
  20278. var CFFDict = (function CFFDictClosure() {
  20279. function CFFDict(tables, strings) {
  20280. this.keyToNameMap = tables.keyToNameMap;
  20281. this.nameToKeyMap = tables.nameToKeyMap;
  20282. this.defaults = tables.defaults;
  20283. this.types = tables.types;
  20284. this.opcodes = tables.opcodes;
  20285. this.order = tables.order;
  20286. this.strings = strings;
  20287. this.values = {};
  20288. }
  20289. CFFDict.prototype = {
  20290. // value should always be an array
  20291. setByKey: function CFFDict_setByKey(key, value) {
  20292. if (!(key in this.keyToNameMap)) {
  20293. return false;
  20294. }
  20295. // ignore empty values
  20296. if (value.length === 0) {
  20297. return true;
  20298. }
  20299. var type = this.types[key];
  20300. // remove the array wrapping these types of values
  20301. if (type === 'num' || type === 'sid' || type === 'offset') {
  20302. value = value[0];
  20303. }
  20304. this.values[key] = value;
  20305. return true;
  20306. },
  20307. setByName: function CFFDict_setByName(name, value) {
  20308. if (!(name in this.nameToKeyMap)) {
  20309. error('Invalid dictionary name "' + name + '"');
  20310. }
  20311. this.values[this.nameToKeyMap[name]] = value;
  20312. },
  20313. hasName: function CFFDict_hasName(name) {
  20314. return this.nameToKeyMap[name] in this.values;
  20315. },
  20316. getByName: function CFFDict_getByName(name) {
  20317. if (!(name in this.nameToKeyMap)) {
  20318. error('Invalid dictionary name "' + name + '"');
  20319. }
  20320. var key = this.nameToKeyMap[name];
  20321. if (!(key in this.values)) {
  20322. return this.defaults[key];
  20323. }
  20324. return this.values[key];
  20325. },
  20326. removeByName: function CFFDict_removeByName(name) {
  20327. delete this.values[this.nameToKeyMap[name]];
  20328. }
  20329. };
  20330. CFFDict.createTables = function CFFDict_createTables(layout) {
  20331. var tables = {
  20332. keyToNameMap: {},
  20333. nameToKeyMap: {},
  20334. defaults: {},
  20335. types: {},
  20336. opcodes: {},
  20337. order: []
  20338. };
  20339. for (var i = 0, ii = layout.length; i < ii; ++i) {
  20340. var entry = layout[i];
  20341. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  20342. tables.keyToNameMap[key] = entry[1];
  20343. tables.nameToKeyMap[entry[1]] = key;
  20344. tables.types[key] = entry[2];
  20345. tables.defaults[key] = entry[3];
  20346. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  20347. tables.order.push(key);
  20348. }
  20349. return tables;
  20350. };
  20351. return CFFDict;
  20352. })();
  20353. var CFFTopDict = (function CFFTopDictClosure() {
  20354. var layout = [
  20355. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  20356. [[12, 20], 'SyntheticBase', 'num', null],
  20357. [0, 'version', 'sid', null],
  20358. [1, 'Notice', 'sid', null],
  20359. [[12, 0], 'Copyright', 'sid', null],
  20360. [2, 'FullName', 'sid', null],
  20361. [3, 'FamilyName', 'sid', null],
  20362. [4, 'Weight', 'sid', null],
  20363. [[12, 1], 'isFixedPitch', 'num', 0],
  20364. [[12, 2], 'ItalicAngle', 'num', 0],
  20365. [[12, 3], 'UnderlinePosition', 'num', -100],
  20366. [[12, 4], 'UnderlineThickness', 'num', 50],
  20367. [[12, 5], 'PaintType', 'num', 0],
  20368. [[12, 6], 'CharstringType', 'num', 2],
  20369. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  20370. [0.001, 0, 0, 0.001, 0, 0]],
  20371. [13, 'UniqueID', 'num', null],
  20372. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  20373. [[12, 8], 'StrokeWidth', 'num', 0],
  20374. [14, 'XUID', 'array', null],
  20375. [15, 'charset', 'offset', 0],
  20376. [16, 'Encoding', 'offset', 0],
  20377. [17, 'CharStrings', 'offset', 0],
  20378. [18, 'Private', ['offset', 'offset'], null],
  20379. [[12, 21], 'PostScript', 'sid', null],
  20380. [[12, 22], 'BaseFontName', 'sid', null],
  20381. [[12, 23], 'BaseFontBlend', 'delta', null],
  20382. [[12, 31], 'CIDFontVersion', 'num', 0],
  20383. [[12, 32], 'CIDFontRevision', 'num', 0],
  20384. [[12, 33], 'CIDFontType', 'num', 0],
  20385. [[12, 34], 'CIDCount', 'num', 8720],
  20386. [[12, 35], 'UIDBase', 'num', null],
  20387. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  20388. // before FDArray.
  20389. [[12, 37], 'FDSelect', 'offset', null],
  20390. [[12, 36], 'FDArray', 'offset', null],
  20391. [[12, 38], 'FontName', 'sid', null]
  20392. ];
  20393. var tables = null;
  20394. function CFFTopDict(strings) {
  20395. if (tables === null) {
  20396. tables = CFFDict.createTables(layout);
  20397. }
  20398. CFFDict.call(this, tables, strings);
  20399. this.privateDict = null;
  20400. }
  20401. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  20402. return CFFTopDict;
  20403. })();
  20404. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  20405. var layout = [
  20406. [6, 'BlueValues', 'delta', null],
  20407. [7, 'OtherBlues', 'delta', null],
  20408. [8, 'FamilyBlues', 'delta', null],
  20409. [9, 'FamilyOtherBlues', 'delta', null],
  20410. [[12, 9], 'BlueScale', 'num', 0.039625],
  20411. [[12, 10], 'BlueShift', 'num', 7],
  20412. [[12, 11], 'BlueFuzz', 'num', 1],
  20413. [10, 'StdHW', 'num', null],
  20414. [11, 'StdVW', 'num', null],
  20415. [[12, 12], 'StemSnapH', 'delta', null],
  20416. [[12, 13], 'StemSnapV', 'delta', null],
  20417. [[12, 14], 'ForceBold', 'num', 0],
  20418. [[12, 17], 'LanguageGroup', 'num', 0],
  20419. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  20420. [[12, 19], 'initialRandomSeed', 'num', 0],
  20421. [20, 'defaultWidthX', 'num', 0],
  20422. [21, 'nominalWidthX', 'num', 0],
  20423. [19, 'Subrs', 'offset', null]
  20424. ];
  20425. var tables = null;
  20426. function CFFPrivateDict(strings) {
  20427. if (tables === null) {
  20428. tables = CFFDict.createTables(layout);
  20429. }
  20430. CFFDict.call(this, tables, strings);
  20431. this.subrsIndex = null;
  20432. }
  20433. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  20434. return CFFPrivateDict;
  20435. })();
  20436. var CFFCharsetPredefinedTypes = {
  20437. ISO_ADOBE: 0,
  20438. EXPERT: 1,
  20439. EXPERT_SUBSET: 2
  20440. };
  20441. var CFFCharset = (function CFFCharsetClosure() {
  20442. function CFFCharset(predefined, format, charset, raw) {
  20443. this.predefined = predefined;
  20444. this.format = format;
  20445. this.charset = charset;
  20446. this.raw = raw;
  20447. }
  20448. return CFFCharset;
  20449. })();
  20450. var CFFEncoding = (function CFFEncodingClosure() {
  20451. function CFFEncoding(predefined, format, encoding, raw) {
  20452. this.predefined = predefined;
  20453. this.format = format;
  20454. this.encoding = encoding;
  20455. this.raw = raw;
  20456. }
  20457. return CFFEncoding;
  20458. })();
  20459. var CFFFDSelect = (function CFFFDSelectClosure() {
  20460. function CFFFDSelect(fdSelect, raw) {
  20461. this.fdSelect = fdSelect;
  20462. this.raw = raw;
  20463. }
  20464. return CFFFDSelect;
  20465. })();
  20466. // Helper class to keep track of where an offset is within the data and helps
  20467. // filling in that offset once it's known.
  20468. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  20469. function CFFOffsetTracker() {
  20470. this.offsets = {};
  20471. }
  20472. CFFOffsetTracker.prototype = {
  20473. isTracking: function CFFOffsetTracker_isTracking(key) {
  20474. return key in this.offsets;
  20475. },
  20476. track: function CFFOffsetTracker_track(key, location) {
  20477. if (key in this.offsets) {
  20478. error('Already tracking location of ' + key);
  20479. }
  20480. this.offsets[key] = location;
  20481. },
  20482. offset: function CFFOffsetTracker_offset(value) {
  20483. for (var key in this.offsets) {
  20484. this.offsets[key] += value;
  20485. }
  20486. },
  20487. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  20488. values,
  20489. output) {
  20490. if (!(key in this.offsets)) {
  20491. error('Not tracking location of ' + key);
  20492. }
  20493. var data = output.data;
  20494. var dataOffset = this.offsets[key];
  20495. var size = 5;
  20496. for (var i = 0, ii = values.length; i < ii; ++i) {
  20497. var offset0 = i * size + dataOffset;
  20498. var offset1 = offset0 + 1;
  20499. var offset2 = offset0 + 2;
  20500. var offset3 = offset0 + 3;
  20501. var offset4 = offset0 + 4;
  20502. // It's easy to screw up offsets so perform this sanity check.
  20503. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  20504. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  20505. error('writing to an offset that is not empty');
  20506. }
  20507. var value = values[i];
  20508. data[offset0] = 0x1d;
  20509. data[offset1] = (value >> 24) & 0xFF;
  20510. data[offset2] = (value >> 16) & 0xFF;
  20511. data[offset3] = (value >> 8) & 0xFF;
  20512. data[offset4] = value & 0xFF;
  20513. }
  20514. }
  20515. };
  20516. return CFFOffsetTracker;
  20517. })();
  20518. // Takes a CFF and converts it to the binary representation.
  20519. var CFFCompiler = (function CFFCompilerClosure() {
  20520. function CFFCompiler(cff) {
  20521. this.cff = cff;
  20522. }
  20523. CFFCompiler.prototype = {
  20524. compile: function CFFCompiler_compile() {
  20525. var cff = this.cff;
  20526. var output = {
  20527. data: [],
  20528. length: 0,
  20529. add: function CFFCompiler_add(data) {
  20530. this.data = this.data.concat(data);
  20531. this.length = this.data.length;
  20532. }
  20533. };
  20534. // Compile the five entries that must be in order.
  20535. var header = this.compileHeader(cff.header);
  20536. output.add(header);
  20537. var nameIndex = this.compileNameIndex(cff.names);
  20538. output.add(nameIndex);
  20539. if (cff.isCIDFont) {
  20540. // The spec is unclear on how font matrices should relate to each other
  20541. // when there is one in the main top dict and the sub top dicts.
  20542. // Windows handles this differently than linux and osx so we have to
  20543. // normalize to work on all.
  20544. // Rules based off of some mailing list discussions:
  20545. // - If main font has a matrix and subfont doesn't, use the main matrix.
  20546. // - If no main font matrix and there is a subfont matrix, use the
  20547. // subfont matrix.
  20548. // - If both have matrices, concat together.
  20549. // - If neither have matrices, use default.
  20550. // To make this work on all platforms we move the top matrix into each
  20551. // sub top dict and concat if necessary.
  20552. if (cff.topDict.hasName('FontMatrix')) {
  20553. var base = cff.topDict.getByName('FontMatrix');
  20554. cff.topDict.removeByName('FontMatrix');
  20555. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  20556. var subDict = cff.fdArray[i];
  20557. var matrix = base.slice(0);
  20558. if (subDict.hasName('FontMatrix')) {
  20559. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  20560. }
  20561. subDict.setByName('FontMatrix', matrix);
  20562. }
  20563. }
  20564. }
  20565. var compiled = this.compileTopDicts([cff.topDict],
  20566. output.length,
  20567. cff.isCIDFont);
  20568. output.add(compiled.output);
  20569. var topDictTracker = compiled.trackers[0];
  20570. var stringIndex = this.compileStringIndex(cff.strings.strings);
  20571. output.add(stringIndex);
  20572. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  20573. output.add(globalSubrIndex);
  20574. // Now start on the other entries that have no specfic order.
  20575. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  20576. if (cff.encoding.predefined) {
  20577. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  20578. output);
  20579. } else {
  20580. var encoding = this.compileEncoding(cff.encoding);
  20581. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  20582. output.add(encoding);
  20583. }
  20584. }
  20585. if (cff.charset && cff.topDict.hasName('charset')) {
  20586. if (cff.charset.predefined) {
  20587. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  20588. output);
  20589. } else {
  20590. var charset = this.compileCharset(cff.charset);
  20591. topDictTracker.setEntryLocation('charset', [output.length], output);
  20592. output.add(charset);
  20593. }
  20594. }
  20595. var charStrings = this.compileCharStrings(cff.charStrings);
  20596. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  20597. output.add(charStrings);
  20598. if (cff.isCIDFont) {
  20599. // For some reason FDSelect must be in front of FDArray on windows. OSX
  20600. // and linux don't seem to care.
  20601. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  20602. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  20603. output.add(fdSelect);
  20604. // It is unclear if the sub font dictionary can have CID related
  20605. // dictionary keys, but the sanitizer doesn't like them so remove them.
  20606. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  20607. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  20608. output.add(compiled.output);
  20609. var fontDictTrackers = compiled.trackers;
  20610. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  20611. }
  20612. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  20613. // If the font data ends with INDEX whose object data is zero-length,
  20614. // the sanitizer will bail out. Add a dummy byte to avoid that.
  20615. output.add([0]);
  20616. return output.data;
  20617. },
  20618. encodeNumber: function CFFCompiler_encodeNumber(value) {
  20619. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  20620. return this.encodeInteger(value);
  20621. } else {
  20622. return this.encodeFloat(value);
  20623. }
  20624. },
  20625. encodeFloat: function CFFCompiler_encodeFloat(num) {
  20626. var value = num.toString();
  20627. // rounding inaccurate doubles
  20628. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  20629. if (m) {
  20630. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  20631. value = (Math.round(num * epsilon) / epsilon).toString();
  20632. }
  20633. var nibbles = '';
  20634. var i, ii;
  20635. for (i = 0, ii = value.length; i < ii; ++i) {
  20636. var a = value[i];
  20637. if (a === 'e') {
  20638. nibbles += value[++i] === '-' ? 'c' : 'b';
  20639. } else if (a === '.') {
  20640. nibbles += 'a';
  20641. } else if (a === '-') {
  20642. nibbles += 'e';
  20643. } else {
  20644. nibbles += a;
  20645. }
  20646. }
  20647. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  20648. var out = [30];
  20649. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  20650. out.push(parseInt(nibbles.substr(i, 2), 16));
  20651. }
  20652. return out;
  20653. },
  20654. encodeInteger: function CFFCompiler_encodeInteger(value) {
  20655. var code;
  20656. if (value >= -107 && value <= 107) {
  20657. code = [value + 139];
  20658. } else if (value >= 108 && value <= 1131) {
  20659. value = [value - 108];
  20660. code = [(value >> 8) + 247, value & 0xFF];
  20661. } else if (value >= -1131 && value <= -108) {
  20662. value = -value - 108;
  20663. code = [(value >> 8) + 251, value & 0xFF];
  20664. } else if (value >= -32768 && value <= 32767) {
  20665. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  20666. } else {
  20667. code = [0x1d,
  20668. (value >> 24) & 0xFF,
  20669. (value >> 16) & 0xFF,
  20670. (value >> 8) & 0xFF,
  20671. value & 0xFF];
  20672. }
  20673. return code;
  20674. },
  20675. compileHeader: function CFFCompiler_compileHeader(header) {
  20676. return [
  20677. header.major,
  20678. header.minor,
  20679. header.hdrSize,
  20680. header.offSize
  20681. ];
  20682. },
  20683. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  20684. var nameIndex = new CFFIndex();
  20685. for (var i = 0, ii = names.length; i < ii; ++i) {
  20686. nameIndex.add(stringToBytes(names[i]));
  20687. }
  20688. return this.compileIndex(nameIndex);
  20689. },
  20690. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  20691. length,
  20692. removeCidKeys) {
  20693. var fontDictTrackers = [];
  20694. var fdArrayIndex = new CFFIndex();
  20695. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  20696. var fontDict = dicts[i];
  20697. if (removeCidKeys) {
  20698. fontDict.removeByName('CIDFontVersion');
  20699. fontDict.removeByName('CIDFontRevision');
  20700. fontDict.removeByName('CIDFontType');
  20701. fontDict.removeByName('CIDCount');
  20702. fontDict.removeByName('UIDBase');
  20703. }
  20704. var fontDictTracker = new CFFOffsetTracker();
  20705. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  20706. fontDictTrackers.push(fontDictTracker);
  20707. fdArrayIndex.add(fontDictData);
  20708. fontDictTracker.offset(length);
  20709. }
  20710. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  20711. return {
  20712. trackers: fontDictTrackers,
  20713. output: fdArrayIndex
  20714. };
  20715. },
  20716. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  20717. trackers,
  20718. output) {
  20719. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  20720. var fontDict = dicts[i];
  20721. assert(fontDict.privateDict && fontDict.hasName('Private'),
  20722. 'There must be an private dictionary.');
  20723. var privateDict = fontDict.privateDict;
  20724. var privateDictTracker = new CFFOffsetTracker();
  20725. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  20726. var outputLength = output.length;
  20727. privateDictTracker.offset(outputLength);
  20728. if (!privateDictData.length) {
  20729. // The private dictionary was empty, set the output length to zero to
  20730. // ensure the offset length isn't out of bounds in the eyes of the
  20731. // sanitizer.
  20732. outputLength = 0;
  20733. }
  20734. trackers[i].setEntryLocation('Private',
  20735. [privateDictData.length, outputLength],
  20736. output);
  20737. output.add(privateDictData);
  20738. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  20739. var subrs = this.compileIndex(privateDict.subrsIndex);
  20740. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  20741. output);
  20742. output.add(subrs);
  20743. }
  20744. }
  20745. },
  20746. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  20747. var out = [];
  20748. // The dictionary keys must be in a certain order.
  20749. var order = dict.order;
  20750. for (var i = 0; i < order.length; ++i) {
  20751. var key = order[i];
  20752. if (!(key in dict.values)) {
  20753. continue;
  20754. }
  20755. var values = dict.values[key];
  20756. var types = dict.types[key];
  20757. if (!isArray(types)) {
  20758. types = [types];
  20759. }
  20760. if (!isArray(values)) {
  20761. values = [values];
  20762. }
  20763. // Remove any empty dict values.
  20764. if (values.length === 0) {
  20765. continue;
  20766. }
  20767. for (var j = 0, jj = types.length; j < jj; ++j) {
  20768. var type = types[j];
  20769. var value = values[j];
  20770. switch (type) {
  20771. case 'num':
  20772. case 'sid':
  20773. out = out.concat(this.encodeNumber(value));
  20774. break;
  20775. case 'offset':
  20776. // For offsets we just insert a 32bit integer so we don't have to
  20777. // deal with figuring out the length of the offset when it gets
  20778. // replaced later on by the compiler.
  20779. var name = dict.keyToNameMap[key];
  20780. // Some offsets have the offset and the length, so just record the
  20781. // position of the first one.
  20782. if (!offsetTracker.isTracking(name)) {
  20783. offsetTracker.track(name, out.length);
  20784. }
  20785. out = out.concat([0x1d, 0, 0, 0, 0]);
  20786. break;
  20787. case 'array':
  20788. case 'delta':
  20789. out = out.concat(this.encodeNumber(value));
  20790. for (var k = 1, kk = values.length; k < kk; ++k) {
  20791. out = out.concat(this.encodeNumber(values[k]));
  20792. }
  20793. break;
  20794. default:
  20795. error('Unknown data type of ' + type);
  20796. break;
  20797. }
  20798. }
  20799. out = out.concat(dict.opcodes[key]);
  20800. }
  20801. return out;
  20802. },
  20803. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  20804. var stringIndex = new CFFIndex();
  20805. for (var i = 0, ii = strings.length; i < ii; ++i) {
  20806. stringIndex.add(stringToBytes(strings[i]));
  20807. }
  20808. return this.compileIndex(stringIndex);
  20809. },
  20810. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  20811. var globalSubrIndex = this.cff.globalSubrIndex;
  20812. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  20813. },
  20814. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  20815. return this.compileIndex(charStrings);
  20816. },
  20817. compileCharset: function CFFCompiler_compileCharset(charset) {
  20818. return this.compileTypedArray(charset.raw);
  20819. },
  20820. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  20821. return this.compileTypedArray(encoding.raw);
  20822. },
  20823. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  20824. return this.compileTypedArray(fdSelect);
  20825. },
  20826. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  20827. var out = [];
  20828. for (var i = 0, ii = data.length; i < ii; ++i) {
  20829. out[i] = data[i];
  20830. }
  20831. return out;
  20832. },
  20833. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  20834. trackers = trackers || [];
  20835. var objects = index.objects;
  20836. // First 2 bytes contains the number of objects contained into this index
  20837. var count = objects.length;
  20838. // If there is no object, just create an index. This technically
  20839. // should just be [0, 0] but OTS has an issue with that.
  20840. if (count === 0) {
  20841. return [0, 0, 0];
  20842. }
  20843. var data = [(count >> 8) & 0xFF, count & 0xff];
  20844. var lastOffset = 1, i;
  20845. for (i = 0; i < count; ++i) {
  20846. lastOffset += objects[i].length;
  20847. }
  20848. var offsetSize;
  20849. if (lastOffset < 0x100) {
  20850. offsetSize = 1;
  20851. } else if (lastOffset < 0x10000) {
  20852. offsetSize = 2;
  20853. } else if (lastOffset < 0x1000000) {
  20854. offsetSize = 3;
  20855. } else {
  20856. offsetSize = 4;
  20857. }
  20858. // Next byte contains the offset size use to reference object in the file
  20859. data.push(offsetSize);
  20860. // Add another offset after this one because we need a new offset
  20861. var relativeOffset = 1;
  20862. for (i = 0; i < count + 1; i++) {
  20863. if (offsetSize === 1) {
  20864. data.push(relativeOffset & 0xFF);
  20865. } else if (offsetSize === 2) {
  20866. data.push((relativeOffset >> 8) & 0xFF,
  20867. relativeOffset & 0xFF);
  20868. } else if (offsetSize === 3) {
  20869. data.push((relativeOffset >> 16) & 0xFF,
  20870. (relativeOffset >> 8) & 0xFF,
  20871. relativeOffset & 0xFF);
  20872. } else {
  20873. data.push((relativeOffset >>> 24) & 0xFF,
  20874. (relativeOffset >> 16) & 0xFF,
  20875. (relativeOffset >> 8) & 0xFF,
  20876. relativeOffset & 0xFF);
  20877. }
  20878. if (objects[i]) {
  20879. relativeOffset += objects[i].length;
  20880. }
  20881. }
  20882. for (i = 0; i < count; i++) {
  20883. // Notify the tracker where the object will be offset in the data.
  20884. if (trackers[i]) {
  20885. trackers[i].offset(data.length);
  20886. }
  20887. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  20888. data.push(objects[i][j]);
  20889. }
  20890. }
  20891. return data;
  20892. }
  20893. };
  20894. return CFFCompiler;
  20895. })();
  20896. // Workaround for seac on Windows.
  20897. (function checkSeacSupport() {
  20898. if (/Windows/.test(navigator.userAgent)) {
  20899. SEAC_ANALYSIS_ENABLED = true;
  20900. }
  20901. })();
  20902. // Workaround for Private Use Area characters in Chrome on Windows
  20903. // http://code.google.com/p/chromium/issues/detail?id=122465
  20904. // https://github.com/mozilla/pdf.js/issues/1689
  20905. (function checkChromeWindows() {
  20906. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  20907. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  20908. }
  20909. })();
  20910. var FontRendererFactory = (function FontRendererFactoryClosure() {
  20911. function getLong(data, offset) {
  20912. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20913. (data[offset + 2] << 8) | data[offset + 3];
  20914. }
  20915. function getUshort(data, offset) {
  20916. return (data[offset] << 8) | data[offset + 1];
  20917. }
  20918. function parseCmap(data, start, end) {
  20919. var offset = (getUshort(data, start + 2) === 1 ?
  20920. getLong(data, start + 8) : getLong(data, start + 16));
  20921. var format = getUshort(data, start + offset);
  20922. var length, ranges, p, i;
  20923. if (format === 4) {
  20924. length = getUshort(data, start + offset + 2);
  20925. var segCount = getUshort(data, start + offset + 6) >> 1;
  20926. p = start + offset + 14;
  20927. ranges = [];
  20928. for (i = 0; i < segCount; i++, p += 2) {
  20929. ranges[i] = {end: getUshort(data, p)};
  20930. }
  20931. p += 2;
  20932. for (i = 0; i < segCount; i++, p += 2) {
  20933. ranges[i].start = getUshort(data, p);
  20934. }
  20935. for (i = 0; i < segCount; i++, p += 2) {
  20936. ranges[i].idDelta = getUshort(data, p);
  20937. }
  20938. for (i = 0; i < segCount; i++, p += 2) {
  20939. var idOffset = getUshort(data, p);
  20940. if (idOffset === 0) {
  20941. continue;
  20942. }
  20943. ranges[i].ids = [];
  20944. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  20945. ranges[i].ids[j] = getUshort(data, p + idOffset);
  20946. idOffset += 2;
  20947. }
  20948. }
  20949. return ranges;
  20950. } else if (format === 12) {
  20951. length = getLong(data, start + offset + 4);
  20952. var groups = getLong(data, start + offset + 12);
  20953. p = start + offset + 16;
  20954. ranges = [];
  20955. for (i = 0; i < groups; i++) {
  20956. ranges.push({
  20957. start: getLong(data, p),
  20958. end: getLong(data, p + 4),
  20959. idDelta: getLong(data, p + 8) - getLong(data, p)
  20960. });
  20961. p += 12;
  20962. }
  20963. return ranges;
  20964. }
  20965. error('not supported cmap: ' + format);
  20966. }
  20967. function parseCff(data, start, end) {
  20968. var properties = {};
  20969. var parser = new CFFParser(new Stream(data, start, end - start),
  20970. properties);
  20971. var cff = parser.parse();
  20972. return {
  20973. glyphs: cff.charStrings.objects,
  20974. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  20975. cff.topDict.privateDict.subrsIndex.objects),
  20976. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  20977. };
  20978. }
  20979. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  20980. var itemSize, itemDecode;
  20981. if (isGlyphLocationsLong) {
  20982. itemSize = 4;
  20983. itemDecode = function fontItemDecodeLong(data, offset) {
  20984. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20985. (data[offset + 2] << 8) | data[offset + 3];
  20986. };
  20987. } else {
  20988. itemSize = 2;
  20989. itemDecode = function fontItemDecode(data, offset) {
  20990. return (data[offset] << 9) | (data[offset + 1] << 1);
  20991. };
  20992. }
  20993. var glyphs = [];
  20994. var startOffset = itemDecode(loca, 0);
  20995. for (var j = itemSize; j < loca.length; j += itemSize) {
  20996. var endOffset = itemDecode(loca, j);
  20997. glyphs.push(glyf.subarray(startOffset, endOffset));
  20998. startOffset = endOffset;
  20999. }
  21000. return glyphs;
  21001. }
  21002. function lookupCmap(ranges, unicode) {
  21003. var code = unicode.charCodeAt(0);
  21004. var l = 0, r = ranges.length - 1;
  21005. while (l < r) {
  21006. var c = (l + r + 1) >> 1;
  21007. if (code < ranges[c].start) {
  21008. r = c - 1;
  21009. } else {
  21010. l = c;
  21011. }
  21012. }
  21013. if (ranges[l].start <= code && code <= ranges[l].end) {
  21014. return (ranges[l].idDelta + (ranges[l].ids ?
  21015. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  21016. }
  21017. return 0;
  21018. }
  21019. function compileGlyf(code, cmds, font) {
  21020. function moveTo(x, y) {
  21021. cmds.push({cmd: 'moveTo', args: [x, y]});
  21022. }
  21023. function lineTo(x, y) {
  21024. cmds.push({cmd: 'lineTo', args: [x, y]});
  21025. }
  21026. function quadraticCurveTo(xa, ya, x, y) {
  21027. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  21028. }
  21029. var i = 0;
  21030. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21031. var flags;
  21032. var x = 0, y = 0;
  21033. i += 10;
  21034. if (numberOfContours < 0) {
  21035. // composite glyph
  21036. do {
  21037. flags = (code[i] << 8) | code[i + 1];
  21038. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  21039. i += 4;
  21040. var arg1, arg2;
  21041. if ((flags & 0x01)) {
  21042. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21043. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  21044. i += 4;
  21045. } else {
  21046. arg1 = code[i++]; arg2 = code[i++];
  21047. }
  21048. if ((flags & 0x02)) {
  21049. x = arg1;
  21050. y = arg2;
  21051. } else {
  21052. x = 0; y = 0; // TODO "they are points" ?
  21053. }
  21054. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  21055. if ((flags & 0x08)) {
  21056. scaleX =
  21057. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21058. i += 2;
  21059. } else if ((flags & 0x40)) {
  21060. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21061. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21062. i += 4;
  21063. } else if ((flags & 0x80)) {
  21064. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21065. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21066. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  21067. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  21068. i += 8;
  21069. }
  21070. var subglyph = font.glyphs[glyphIndex];
  21071. if (subglyph) {
  21072. cmds.push({cmd: 'save'});
  21073. cmds.push({cmd: 'transform',
  21074. args: [scaleX, scale01, scale10, scaleY, x, y]});
  21075. compileGlyf(subglyph, cmds, font);
  21076. cmds.push({cmd: 'restore'});
  21077. }
  21078. } while ((flags & 0x20));
  21079. } else {
  21080. // simple glyph
  21081. var endPtsOfContours = [];
  21082. var j, jj;
  21083. for (j = 0; j < numberOfContours; j++) {
  21084. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  21085. i += 2;
  21086. }
  21087. var instructionLength = (code[i] << 8) | code[i + 1];
  21088. i += 2 + instructionLength; // skipping the instructions
  21089. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  21090. var points = [];
  21091. while (points.length < numberOfPoints) {
  21092. flags = code[i++];
  21093. var repeat = 1;
  21094. if ((flags & 0x08)) {
  21095. repeat += code[i++];
  21096. }
  21097. while (repeat-- > 0) {
  21098. points.push({flags: flags});
  21099. }
  21100. }
  21101. for (j = 0; j < numberOfPoints; j++) {
  21102. switch (points[j].flags & 0x12) {
  21103. case 0x00:
  21104. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21105. i += 2;
  21106. break;
  21107. case 0x02:
  21108. x -= code[i++];
  21109. break;
  21110. case 0x12:
  21111. x += code[i++];
  21112. break;
  21113. }
  21114. points[j].x = x;
  21115. }
  21116. for (j = 0; j < numberOfPoints; j++) {
  21117. switch (points[j].flags & 0x24) {
  21118. case 0x00:
  21119. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21120. i += 2;
  21121. break;
  21122. case 0x04:
  21123. y -= code[i++];
  21124. break;
  21125. case 0x24:
  21126. y += code[i++];
  21127. break;
  21128. }
  21129. points[j].y = y;
  21130. }
  21131. var startPoint = 0;
  21132. for (i = 0; i < numberOfContours; i++) {
  21133. var endPoint = endPtsOfContours[i];
  21134. // contours might have implicit points, which is located in the middle
  21135. // between two neighboring off-curve points
  21136. var contour = points.slice(startPoint, endPoint + 1);
  21137. if ((contour[0].flags & 1)) {
  21138. contour.push(contour[0]); // using start point at the contour end
  21139. } else if ((contour[contour.length - 1].flags & 1)) {
  21140. // first is off-curve point, trying to use one from the end
  21141. contour.unshift(contour[contour.length - 1]);
  21142. } else {
  21143. // start and end are off-curve points, creating implicit one
  21144. var p = {
  21145. flags: 1,
  21146. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  21147. y: (contour[0].y + contour[contour.length - 1].y) / 2
  21148. };
  21149. contour.unshift(p);
  21150. contour.push(p);
  21151. }
  21152. moveTo(contour[0].x, contour[0].y);
  21153. for (j = 1, jj = contour.length; j < jj; j++) {
  21154. if ((contour[j].flags & 1)) {
  21155. lineTo(contour[j].x, contour[j].y);
  21156. } else if ((contour[j + 1].flags & 1)){
  21157. quadraticCurveTo(contour[j].x, contour[j].y,
  21158. contour[j + 1].x, contour[j + 1].y);
  21159. j++;
  21160. } else {
  21161. quadraticCurveTo(contour[j].x, contour[j].y,
  21162. (contour[j].x + contour[j + 1].x) / 2,
  21163. (contour[j].y + contour[j + 1].y) / 2);
  21164. }
  21165. }
  21166. startPoint = endPoint + 1;
  21167. }
  21168. }
  21169. }
  21170. function compileCharString(code, cmds, font) {
  21171. var stack = [];
  21172. var x = 0, y = 0;
  21173. var stems = 0;
  21174. function moveTo(x, y) {
  21175. cmds.push({cmd: 'moveTo', args: [x, y]});
  21176. }
  21177. function lineTo(x, y) {
  21178. cmds.push({cmd: 'lineTo', args: [x, y]});
  21179. }
  21180. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  21181. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  21182. }
  21183. function parse(code) {
  21184. var i = 0;
  21185. while (i < code.length) {
  21186. var stackClean = false;
  21187. var v = code[i++];
  21188. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  21189. switch (v) {
  21190. case 1: // hstem
  21191. stems += stack.length >> 1;
  21192. stackClean = true;
  21193. break;
  21194. case 3: // vstem
  21195. stems += stack.length >> 1;
  21196. stackClean = true;
  21197. break;
  21198. case 4: // vmoveto
  21199. y += stack.pop();
  21200. moveTo(x, y);
  21201. stackClean = true;
  21202. break;
  21203. case 5: // rlineto
  21204. while (stack.length > 0) {
  21205. x += stack.shift();
  21206. y += stack.shift();
  21207. lineTo(x, y);
  21208. }
  21209. break;
  21210. case 6: // hlineto
  21211. while (stack.length > 0) {
  21212. x += stack.shift();
  21213. lineTo(x, y);
  21214. if (stack.length === 0) {
  21215. break;
  21216. }
  21217. y += stack.shift();
  21218. lineTo(x, y);
  21219. }
  21220. break;
  21221. case 7: // vlineto
  21222. while (stack.length > 0) {
  21223. y += stack.shift();
  21224. lineTo(x, y);
  21225. if (stack.length === 0) {
  21226. break;
  21227. }
  21228. x += stack.shift();
  21229. lineTo(x, y);
  21230. }
  21231. break;
  21232. case 8: // rrcurveto
  21233. while (stack.length > 0) {
  21234. xa = x + stack.shift(); ya = y + stack.shift();
  21235. xb = xa + stack.shift(); yb = ya + stack.shift();
  21236. x = xb + stack.shift(); y = yb + stack.shift();
  21237. bezierCurveTo(xa, ya, xb, yb, x, y);
  21238. }
  21239. break;
  21240. case 10: // callsubr
  21241. n = stack.pop() + font.subrsBias;
  21242. subrCode = font.subrs[n];
  21243. if (subrCode) {
  21244. parse(subrCode);
  21245. }
  21246. break;
  21247. case 11: // return
  21248. return;
  21249. case 12:
  21250. v = code[i++];
  21251. switch (v) {
  21252. case 34: // flex
  21253. xa = x + stack.shift();
  21254. xb = xa + stack.shift(); y1 = y + stack.shift();
  21255. x = xb + stack.shift();
  21256. bezierCurveTo(xa, y, xb, y1, x, y1);
  21257. xa = x + stack.shift();
  21258. xb = xa + stack.shift();
  21259. x = xb + stack.shift();
  21260. bezierCurveTo(xa, y1, xb, y, x, y);
  21261. break;
  21262. case 35: // flex
  21263. xa = x + stack.shift(); ya = y + stack.shift();
  21264. xb = xa + stack.shift(); yb = ya + stack.shift();
  21265. x = xb + stack.shift(); y = yb + stack.shift();
  21266. bezierCurveTo(xa, ya, xb, yb, x, y);
  21267. xa = x + stack.shift(); ya = y + stack.shift();
  21268. xb = xa + stack.shift(); yb = ya + stack.shift();
  21269. x = xb + stack.shift(); y = yb + stack.shift();
  21270. bezierCurveTo(xa, ya, xb, yb, x, y);
  21271. stack.pop(); // fd
  21272. break;
  21273. case 36: // hflex1
  21274. xa = x + stack.shift(); y1 = y + stack.shift();
  21275. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  21276. x = xb + stack.shift();
  21277. bezierCurveTo(xa, y1, xb, y2, x, y2);
  21278. xa = x + stack.shift();
  21279. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  21280. x = xb + stack.shift();
  21281. bezierCurveTo(xa, y2, xb, y3, x, y);
  21282. break;
  21283. case 37: // flex1
  21284. var x0 = x, y0 = y;
  21285. xa = x + stack.shift(); ya = y + stack.shift();
  21286. xb = xa + stack.shift(); yb = ya + stack.shift();
  21287. x = xb + stack.shift(); y = yb + stack.shift();
  21288. bezierCurveTo(xa, ya, xb, yb, x, y);
  21289. xa = x + stack.shift(); ya = y + stack.shift();
  21290. xb = xa + stack.shift(); yb = ya + stack.shift();
  21291. x = xb; y = yb;
  21292. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  21293. x += stack.shift();
  21294. } else {
  21295. y += stack.shift();
  21296. }
  21297. bezierCurveTo(xa, ya, xb, yb, x, y);
  21298. break;
  21299. default:
  21300. error('unknown operator: 12 ' + v);
  21301. }
  21302. break;
  21303. case 14: // endchar
  21304. if (stack.length >= 4) {
  21305. var achar = stack.pop();
  21306. var bchar = stack.pop();
  21307. y = stack.pop();
  21308. x = stack.pop();
  21309. cmds.push({cmd: 'save'});
  21310. cmds.push({cmd: 'translate', args: [x, y]});
  21311. var gid = lookupCmap(font.cmap, String.fromCharCode(
  21312. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  21313. compileCharString(font.glyphs[gid], cmds, font);
  21314. cmds.push({cmd: 'restore'});
  21315. gid = lookupCmap(font.cmap, String.fromCharCode(
  21316. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  21317. compileCharString(font.glyphs[gid], cmds, font);
  21318. }
  21319. return;
  21320. case 18: // hstemhm
  21321. stems += stack.length >> 1;
  21322. stackClean = true;
  21323. break;
  21324. case 19: // hintmask
  21325. stems += stack.length >> 1;
  21326. i += (stems + 7) >> 3;
  21327. stackClean = true;
  21328. break;
  21329. case 20: // cntrmask
  21330. stems += stack.length >> 1;
  21331. i += (stems + 7) >> 3;
  21332. stackClean = true;
  21333. break;
  21334. case 21: // rmoveto
  21335. y += stack.pop();
  21336. x += stack.pop();
  21337. moveTo(x, y);
  21338. stackClean = true;
  21339. break;
  21340. case 22: // hmoveto
  21341. x += stack.pop();
  21342. moveTo(x, y);
  21343. stackClean = true;
  21344. break;
  21345. case 23: // vstemhm
  21346. stems += stack.length >> 1;
  21347. stackClean = true;
  21348. break;
  21349. case 24: // rcurveline
  21350. while (stack.length > 2) {
  21351. xa = x + stack.shift(); ya = y + stack.shift();
  21352. xb = xa + stack.shift(); yb = ya + stack.shift();
  21353. x = xb + stack.shift(); y = yb + stack.shift();
  21354. bezierCurveTo(xa, ya, xb, yb, x, y);
  21355. }
  21356. x += stack.shift();
  21357. y += stack.shift();
  21358. lineTo(x, y);
  21359. break;
  21360. case 25: // rlinecurve
  21361. while (stack.length > 6) {
  21362. x += stack.shift();
  21363. y += stack.shift();
  21364. lineTo(x, y);
  21365. }
  21366. xa = x + stack.shift(); ya = y + stack.shift();
  21367. xb = xa + stack.shift(); yb = ya + stack.shift();
  21368. x = xb + stack.shift(); y = yb + stack.shift();
  21369. bezierCurveTo(xa, ya, xb, yb, x, y);
  21370. break;
  21371. case 26: // vvcurveto
  21372. if (stack.length % 2) {
  21373. x += stack.shift();
  21374. }
  21375. while (stack.length > 0) {
  21376. xa = x; ya = y + stack.shift();
  21377. xb = xa + stack.shift(); yb = ya + stack.shift();
  21378. x = xb; y = yb + stack.shift();
  21379. bezierCurveTo(xa, ya, xb, yb, x, y);
  21380. }
  21381. break;
  21382. case 27: // hhcurveto
  21383. if (stack.length % 2) {
  21384. y += stack.shift();
  21385. }
  21386. while (stack.length > 0) {
  21387. xa = x + stack.shift(); ya = y;
  21388. xb = xa + stack.shift(); yb = ya + stack.shift();
  21389. x = xb + stack.shift(); y = yb;
  21390. bezierCurveTo(xa, ya, xb, yb, x, y);
  21391. }
  21392. break;
  21393. case 28:
  21394. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  21395. i += 2;
  21396. break;
  21397. case 29: // callgsubr
  21398. n = stack.pop() + font.gsubrsBias;
  21399. subrCode = font.gsubrs[n];
  21400. if (subrCode) {
  21401. parse(subrCode);
  21402. }
  21403. break;
  21404. case 30: // vhcurveto
  21405. while (stack.length > 0) {
  21406. xa = x; ya = y + stack.shift();
  21407. xb = xa + stack.shift(); yb = ya + stack.shift();
  21408. x = xb + stack.shift();
  21409. y = yb + (stack.length === 1 ? stack.shift() : 0);
  21410. bezierCurveTo(xa, ya, xb, yb, x, y);
  21411. if (stack.length === 0) {
  21412. break;
  21413. }
  21414. xa = x + stack.shift(); ya = y;
  21415. xb = xa + stack.shift(); yb = ya + stack.shift();
  21416. y = yb + stack.shift();
  21417. x = xb + (stack.length === 1 ? stack.shift() : 0);
  21418. bezierCurveTo(xa, ya, xb, yb, x, y);
  21419. }
  21420. break;
  21421. case 31: // hvcurveto
  21422. while (stack.length > 0) {
  21423. xa = x + stack.shift(); ya = y;
  21424. xb = xa + stack.shift(); yb = ya + stack.shift();
  21425. y = yb + stack.shift();
  21426. x = xb + (stack.length === 1 ? stack.shift() : 0);
  21427. bezierCurveTo(xa, ya, xb, yb, x, y);
  21428. if (stack.length === 0) {
  21429. break;
  21430. }
  21431. xa = x; ya = y + stack.shift();
  21432. xb = xa + stack.shift(); yb = ya + stack.shift();
  21433. x = xb + stack.shift();
  21434. y = yb + (stack.length === 1 ? stack.shift() : 0);
  21435. bezierCurveTo(xa, ya, xb, yb, x, y);
  21436. }
  21437. break;
  21438. default:
  21439. if (v < 32) {
  21440. error('unknown operator: ' + v);
  21441. }
  21442. if (v < 247) {
  21443. stack.push(v - 139);
  21444. } else if (v < 251) {
  21445. stack.push((v - 247) * 256 + code[i++] + 108);
  21446. } else if (v < 255) {
  21447. stack.push(-(v - 251) * 256 - code[i++] - 108);
  21448. } else {
  21449. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  21450. (code[i + 2] << 8) | code[i + 3]) / 65536);
  21451. i += 4;
  21452. }
  21453. break;
  21454. }
  21455. if (stackClean) {
  21456. stack.length = 0;
  21457. }
  21458. }
  21459. }
  21460. parse(code);
  21461. }
  21462. var noop = '';
  21463. function CompiledFont(fontMatrix) {
  21464. this.compiledGlyphs = {};
  21465. this.fontMatrix = fontMatrix;
  21466. }
  21467. CompiledFont.prototype = {
  21468. getPathJs: function (unicode) {
  21469. var gid = lookupCmap(this.cmap, unicode);
  21470. var fn = this.compiledGlyphs[gid];
  21471. if (!fn) {
  21472. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  21473. }
  21474. return fn;
  21475. },
  21476. compileGlyph: function (code) {
  21477. if (!code || code.length === 0 || code[0] === 14) {
  21478. return noop;
  21479. }
  21480. var cmds = [];
  21481. cmds.push({cmd: 'save'});
  21482. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  21483. cmds.push({cmd: 'scale', args: ['size', '-size']});
  21484. this.compileGlyphImpl(code, cmds);
  21485. cmds.push({cmd: 'restore'});
  21486. return cmds;
  21487. },
  21488. compileGlyphImpl: function () {
  21489. error('Children classes should implement this.');
  21490. },
  21491. hasBuiltPath: function (unicode) {
  21492. var gid = lookupCmap(this.cmap, unicode);
  21493. return gid in this.compiledGlyphs;
  21494. }
  21495. };
  21496. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  21497. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  21498. CompiledFont.call(this, fontMatrix);
  21499. this.glyphs = glyphs;
  21500. this.cmap = cmap;
  21501. this.compiledGlyphs = [];
  21502. }
  21503. Util.inherit(TrueTypeCompiled, CompiledFont, {
  21504. compileGlyphImpl: function (code, cmds) {
  21505. compileGlyf(code, cmds, this);
  21506. }
  21507. });
  21508. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  21509. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  21510. CompiledFont.call(this, fontMatrix);
  21511. this.glyphs = cffInfo.glyphs;
  21512. this.gsubrs = cffInfo.gsubrs || [];
  21513. this.subrs = cffInfo.subrs || [];
  21514. this.cmap = cmap;
  21515. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  21516. this.compiledGlyphs = [];
  21517. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  21518. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  21519. this.subrsBias = (this.subrs.length < 1240 ?
  21520. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  21521. }
  21522. Util.inherit(Type2Compiled, CompiledFont, {
  21523. compileGlyphImpl: function (code, cmds) {
  21524. compileCharString(code, cmds, this);
  21525. }
  21526. });
  21527. return {
  21528. create: function FontRendererFactory_create(font) {
  21529. var data = new Uint8Array(font.data);
  21530. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  21531. var numTables = getUshort(data, 4);
  21532. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  21533. var tag = bytesToString(data.subarray(p, p + 4));
  21534. var offset = getLong(data, p + 8);
  21535. var length = getLong(data, p + 12);
  21536. switch (tag) {
  21537. case 'cmap':
  21538. cmap = parseCmap(data, offset, offset + length);
  21539. break;
  21540. case 'glyf':
  21541. glyf = data.subarray(offset, offset + length);
  21542. break;
  21543. case 'loca':
  21544. loca = data.subarray(offset, offset + length);
  21545. break;
  21546. case 'head':
  21547. unitsPerEm = getUshort(data, offset + 18);
  21548. indexToLocFormat = getUshort(data, offset + 50);
  21549. break;
  21550. case 'CFF ':
  21551. cff = parseCff(data, offset, offset + length);
  21552. break;
  21553. }
  21554. }
  21555. if (glyf) {
  21556. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  21557. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  21558. return new TrueTypeCompiled(
  21559. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  21560. } else {
  21561. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  21562. }
  21563. }
  21564. };
  21565. })();
  21566. var GlyphsUnicode = {
  21567. A: 0x0041,
  21568. AE: 0x00C6,
  21569. AEacute: 0x01FC,
  21570. AEmacron: 0x01E2,
  21571. AEsmall: 0xF7E6,
  21572. Aacute: 0x00C1,
  21573. Aacutesmall: 0xF7E1,
  21574. Abreve: 0x0102,
  21575. Abreveacute: 0x1EAE,
  21576. Abrevecyrillic: 0x04D0,
  21577. Abrevedotbelow: 0x1EB6,
  21578. Abrevegrave: 0x1EB0,
  21579. Abrevehookabove: 0x1EB2,
  21580. Abrevetilde: 0x1EB4,
  21581. Acaron: 0x01CD,
  21582. Acircle: 0x24B6,
  21583. Acircumflex: 0x00C2,
  21584. Acircumflexacute: 0x1EA4,
  21585. Acircumflexdotbelow: 0x1EAC,
  21586. Acircumflexgrave: 0x1EA6,
  21587. Acircumflexhookabove: 0x1EA8,
  21588. Acircumflexsmall: 0xF7E2,
  21589. Acircumflextilde: 0x1EAA,
  21590. Acute: 0xF6C9,
  21591. Acutesmall: 0xF7B4,
  21592. Acyrillic: 0x0410,
  21593. Adblgrave: 0x0200,
  21594. Adieresis: 0x00C4,
  21595. Adieresiscyrillic: 0x04D2,
  21596. Adieresismacron: 0x01DE,
  21597. Adieresissmall: 0xF7E4,
  21598. Adotbelow: 0x1EA0,
  21599. Adotmacron: 0x01E0,
  21600. Agrave: 0x00C0,
  21601. Agravesmall: 0xF7E0,
  21602. Ahookabove: 0x1EA2,
  21603. Aiecyrillic: 0x04D4,
  21604. Ainvertedbreve: 0x0202,
  21605. Alpha: 0x0391,
  21606. Alphatonos: 0x0386,
  21607. Amacron: 0x0100,
  21608. Amonospace: 0xFF21,
  21609. Aogonek: 0x0104,
  21610. Aring: 0x00C5,
  21611. Aringacute: 0x01FA,
  21612. Aringbelow: 0x1E00,
  21613. Aringsmall: 0xF7E5,
  21614. Asmall: 0xF761,
  21615. Atilde: 0x00C3,
  21616. Atildesmall: 0xF7E3,
  21617. Aybarmenian: 0x0531,
  21618. B: 0x0042,
  21619. Bcircle: 0x24B7,
  21620. Bdotaccent: 0x1E02,
  21621. Bdotbelow: 0x1E04,
  21622. Becyrillic: 0x0411,
  21623. Benarmenian: 0x0532,
  21624. Beta: 0x0392,
  21625. Bhook: 0x0181,
  21626. Blinebelow: 0x1E06,
  21627. Bmonospace: 0xFF22,
  21628. Brevesmall: 0xF6F4,
  21629. Bsmall: 0xF762,
  21630. Btopbar: 0x0182,
  21631. C: 0x0043,
  21632. Caarmenian: 0x053E,
  21633. Cacute: 0x0106,
  21634. Caron: 0xF6CA,
  21635. Caronsmall: 0xF6F5,
  21636. Ccaron: 0x010C,
  21637. Ccedilla: 0x00C7,
  21638. Ccedillaacute: 0x1E08,
  21639. Ccedillasmall: 0xF7E7,
  21640. Ccircle: 0x24B8,
  21641. Ccircumflex: 0x0108,
  21642. Cdot: 0x010A,
  21643. Cdotaccent: 0x010A,
  21644. Cedillasmall: 0xF7B8,
  21645. Chaarmenian: 0x0549,
  21646. Cheabkhasiancyrillic: 0x04BC,
  21647. Checyrillic: 0x0427,
  21648. Chedescenderabkhasiancyrillic: 0x04BE,
  21649. Chedescendercyrillic: 0x04B6,
  21650. Chedieresiscyrillic: 0x04F4,
  21651. Cheharmenian: 0x0543,
  21652. Chekhakassiancyrillic: 0x04CB,
  21653. Cheverticalstrokecyrillic: 0x04B8,
  21654. Chi: 0x03A7,
  21655. Chook: 0x0187,
  21656. Circumflexsmall: 0xF6F6,
  21657. Cmonospace: 0xFF23,
  21658. Coarmenian: 0x0551,
  21659. Csmall: 0xF763,
  21660. D: 0x0044,
  21661. DZ: 0x01F1,
  21662. DZcaron: 0x01C4,
  21663. Daarmenian: 0x0534,
  21664. Dafrican: 0x0189,
  21665. Dcaron: 0x010E,
  21666. Dcedilla: 0x1E10,
  21667. Dcircle: 0x24B9,
  21668. Dcircumflexbelow: 0x1E12,
  21669. Dcroat: 0x0110,
  21670. Ddotaccent: 0x1E0A,
  21671. Ddotbelow: 0x1E0C,
  21672. Decyrillic: 0x0414,
  21673. Deicoptic: 0x03EE,
  21674. Delta: 0x2206,
  21675. Deltagreek: 0x0394,
  21676. Dhook: 0x018A,
  21677. Dieresis: 0xF6CB,
  21678. DieresisAcute: 0xF6CC,
  21679. DieresisGrave: 0xF6CD,
  21680. Dieresissmall: 0xF7A8,
  21681. Digammagreek: 0x03DC,
  21682. Djecyrillic: 0x0402,
  21683. Dlinebelow: 0x1E0E,
  21684. Dmonospace: 0xFF24,
  21685. Dotaccentsmall: 0xF6F7,
  21686. Dslash: 0x0110,
  21687. Dsmall: 0xF764,
  21688. Dtopbar: 0x018B,
  21689. Dz: 0x01F2,
  21690. Dzcaron: 0x01C5,
  21691. Dzeabkhasiancyrillic: 0x04E0,
  21692. Dzecyrillic: 0x0405,
  21693. Dzhecyrillic: 0x040F,
  21694. E: 0x0045,
  21695. Eacute: 0x00C9,
  21696. Eacutesmall: 0xF7E9,
  21697. Ebreve: 0x0114,
  21698. Ecaron: 0x011A,
  21699. Ecedillabreve: 0x1E1C,
  21700. Echarmenian: 0x0535,
  21701. Ecircle: 0x24BA,
  21702. Ecircumflex: 0x00CA,
  21703. Ecircumflexacute: 0x1EBE,
  21704. Ecircumflexbelow: 0x1E18,
  21705. Ecircumflexdotbelow: 0x1EC6,
  21706. Ecircumflexgrave: 0x1EC0,
  21707. Ecircumflexhookabove: 0x1EC2,
  21708. Ecircumflexsmall: 0xF7EA,
  21709. Ecircumflextilde: 0x1EC4,
  21710. Ecyrillic: 0x0404,
  21711. Edblgrave: 0x0204,
  21712. Edieresis: 0x00CB,
  21713. Edieresissmall: 0xF7EB,
  21714. Edot: 0x0116,
  21715. Edotaccent: 0x0116,
  21716. Edotbelow: 0x1EB8,
  21717. Efcyrillic: 0x0424,
  21718. Egrave: 0x00C8,
  21719. Egravesmall: 0xF7E8,
  21720. Eharmenian: 0x0537,
  21721. Ehookabove: 0x1EBA,
  21722. Eightroman: 0x2167,
  21723. Einvertedbreve: 0x0206,
  21724. Eiotifiedcyrillic: 0x0464,
  21725. Elcyrillic: 0x041B,
  21726. Elevenroman: 0x216A,
  21727. Emacron: 0x0112,
  21728. Emacronacute: 0x1E16,
  21729. Emacrongrave: 0x1E14,
  21730. Emcyrillic: 0x041C,
  21731. Emonospace: 0xFF25,
  21732. Encyrillic: 0x041D,
  21733. Endescendercyrillic: 0x04A2,
  21734. Eng: 0x014A,
  21735. Enghecyrillic: 0x04A4,
  21736. Enhookcyrillic: 0x04C7,
  21737. Eogonek: 0x0118,
  21738. Eopen: 0x0190,
  21739. Epsilon: 0x0395,
  21740. Epsilontonos: 0x0388,
  21741. Ercyrillic: 0x0420,
  21742. Ereversed: 0x018E,
  21743. Ereversedcyrillic: 0x042D,
  21744. Escyrillic: 0x0421,
  21745. Esdescendercyrillic: 0x04AA,
  21746. Esh: 0x01A9,
  21747. Esmall: 0xF765,
  21748. Eta: 0x0397,
  21749. Etarmenian: 0x0538,
  21750. Etatonos: 0x0389,
  21751. Eth: 0x00D0,
  21752. Ethsmall: 0xF7F0,
  21753. Etilde: 0x1EBC,
  21754. Etildebelow: 0x1E1A,
  21755. Euro: 0x20AC,
  21756. Ezh: 0x01B7,
  21757. Ezhcaron: 0x01EE,
  21758. Ezhreversed: 0x01B8,
  21759. F: 0x0046,
  21760. Fcircle: 0x24BB,
  21761. Fdotaccent: 0x1E1E,
  21762. Feharmenian: 0x0556,
  21763. Feicoptic: 0x03E4,
  21764. Fhook: 0x0191,
  21765. Fitacyrillic: 0x0472,
  21766. Fiveroman: 0x2164,
  21767. Fmonospace: 0xFF26,
  21768. Fourroman: 0x2163,
  21769. Fsmall: 0xF766,
  21770. G: 0x0047,
  21771. GBsquare: 0x3387,
  21772. Gacute: 0x01F4,
  21773. Gamma: 0x0393,
  21774. Gammaafrican: 0x0194,
  21775. Gangiacoptic: 0x03EA,
  21776. Gbreve: 0x011E,
  21777. Gcaron: 0x01E6,
  21778. Gcedilla: 0x0122,
  21779. Gcircle: 0x24BC,
  21780. Gcircumflex: 0x011C,
  21781. Gcommaaccent: 0x0122,
  21782. Gdot: 0x0120,
  21783. Gdotaccent: 0x0120,
  21784. Gecyrillic: 0x0413,
  21785. Ghadarmenian: 0x0542,
  21786. Ghemiddlehookcyrillic: 0x0494,
  21787. Ghestrokecyrillic: 0x0492,
  21788. Gheupturncyrillic: 0x0490,
  21789. Ghook: 0x0193,
  21790. Gimarmenian: 0x0533,
  21791. Gjecyrillic: 0x0403,
  21792. Gmacron: 0x1E20,
  21793. Gmonospace: 0xFF27,
  21794. Grave: 0xF6CE,
  21795. Gravesmall: 0xF760,
  21796. Gsmall: 0xF767,
  21797. Gsmallhook: 0x029B,
  21798. Gstroke: 0x01E4,
  21799. H: 0x0048,
  21800. H18533: 0x25CF,
  21801. H18543: 0x25AA,
  21802. H18551: 0x25AB,
  21803. H22073: 0x25A1,
  21804. HPsquare: 0x33CB,
  21805. Haabkhasiancyrillic: 0x04A8,
  21806. Hadescendercyrillic: 0x04B2,
  21807. Hardsigncyrillic: 0x042A,
  21808. Hbar: 0x0126,
  21809. Hbrevebelow: 0x1E2A,
  21810. Hcedilla: 0x1E28,
  21811. Hcircle: 0x24BD,
  21812. Hcircumflex: 0x0124,
  21813. Hdieresis: 0x1E26,
  21814. Hdotaccent: 0x1E22,
  21815. Hdotbelow: 0x1E24,
  21816. Hmonospace: 0xFF28,
  21817. Hoarmenian: 0x0540,
  21818. Horicoptic: 0x03E8,
  21819. Hsmall: 0xF768,
  21820. Hungarumlaut: 0xF6CF,
  21821. Hungarumlautsmall: 0xF6F8,
  21822. Hzsquare: 0x3390,
  21823. I: 0x0049,
  21824. IAcyrillic: 0x042F,
  21825. IJ: 0x0132,
  21826. IUcyrillic: 0x042E,
  21827. Iacute: 0x00CD,
  21828. Iacutesmall: 0xF7ED,
  21829. Ibreve: 0x012C,
  21830. Icaron: 0x01CF,
  21831. Icircle: 0x24BE,
  21832. Icircumflex: 0x00CE,
  21833. Icircumflexsmall: 0xF7EE,
  21834. Icyrillic: 0x0406,
  21835. Idblgrave: 0x0208,
  21836. Idieresis: 0x00CF,
  21837. Idieresisacute: 0x1E2E,
  21838. Idieresiscyrillic: 0x04E4,
  21839. Idieresissmall: 0xF7EF,
  21840. Idot: 0x0130,
  21841. Idotaccent: 0x0130,
  21842. Idotbelow: 0x1ECA,
  21843. Iebrevecyrillic: 0x04D6,
  21844. Iecyrillic: 0x0415,
  21845. Ifraktur: 0x2111,
  21846. Igrave: 0x00CC,
  21847. Igravesmall: 0xF7EC,
  21848. Ihookabove: 0x1EC8,
  21849. Iicyrillic: 0x0418,
  21850. Iinvertedbreve: 0x020A,
  21851. Iishortcyrillic: 0x0419,
  21852. Imacron: 0x012A,
  21853. Imacroncyrillic: 0x04E2,
  21854. Imonospace: 0xFF29,
  21855. Iniarmenian: 0x053B,
  21856. Iocyrillic: 0x0401,
  21857. Iogonek: 0x012E,
  21858. Iota: 0x0399,
  21859. Iotaafrican: 0x0196,
  21860. Iotadieresis: 0x03AA,
  21861. Iotatonos: 0x038A,
  21862. Ismall: 0xF769,
  21863. Istroke: 0x0197,
  21864. Itilde: 0x0128,
  21865. Itildebelow: 0x1E2C,
  21866. Izhitsacyrillic: 0x0474,
  21867. Izhitsadblgravecyrillic: 0x0476,
  21868. J: 0x004A,
  21869. Jaarmenian: 0x0541,
  21870. Jcircle: 0x24BF,
  21871. Jcircumflex: 0x0134,
  21872. Jecyrillic: 0x0408,
  21873. Jheharmenian: 0x054B,
  21874. Jmonospace: 0xFF2A,
  21875. Jsmall: 0xF76A,
  21876. K: 0x004B,
  21877. KBsquare: 0x3385,
  21878. KKsquare: 0x33CD,
  21879. Kabashkircyrillic: 0x04A0,
  21880. Kacute: 0x1E30,
  21881. Kacyrillic: 0x041A,
  21882. Kadescendercyrillic: 0x049A,
  21883. Kahookcyrillic: 0x04C3,
  21884. Kappa: 0x039A,
  21885. Kastrokecyrillic: 0x049E,
  21886. Kaverticalstrokecyrillic: 0x049C,
  21887. Kcaron: 0x01E8,
  21888. Kcedilla: 0x0136,
  21889. Kcircle: 0x24C0,
  21890. Kcommaaccent: 0x0136,
  21891. Kdotbelow: 0x1E32,
  21892. Keharmenian: 0x0554,
  21893. Kenarmenian: 0x053F,
  21894. Khacyrillic: 0x0425,
  21895. Kheicoptic: 0x03E6,
  21896. Khook: 0x0198,
  21897. Kjecyrillic: 0x040C,
  21898. Klinebelow: 0x1E34,
  21899. Kmonospace: 0xFF2B,
  21900. Koppacyrillic: 0x0480,
  21901. Koppagreek: 0x03DE,
  21902. Ksicyrillic: 0x046E,
  21903. Ksmall: 0xF76B,
  21904. L: 0x004C,
  21905. LJ: 0x01C7,
  21906. LL: 0xF6BF,
  21907. Lacute: 0x0139,
  21908. Lambda: 0x039B,
  21909. Lcaron: 0x013D,
  21910. Lcedilla: 0x013B,
  21911. Lcircle: 0x24C1,
  21912. Lcircumflexbelow: 0x1E3C,
  21913. Lcommaaccent: 0x013B,
  21914. Ldot: 0x013F,
  21915. Ldotaccent: 0x013F,
  21916. Ldotbelow: 0x1E36,
  21917. Ldotbelowmacron: 0x1E38,
  21918. Liwnarmenian: 0x053C,
  21919. Lj: 0x01C8,
  21920. Ljecyrillic: 0x0409,
  21921. Llinebelow: 0x1E3A,
  21922. Lmonospace: 0xFF2C,
  21923. Lslash: 0x0141,
  21924. Lslashsmall: 0xF6F9,
  21925. Lsmall: 0xF76C,
  21926. M: 0x004D,
  21927. MBsquare: 0x3386,
  21928. Macron: 0xF6D0,
  21929. Macronsmall: 0xF7AF,
  21930. Macute: 0x1E3E,
  21931. Mcircle: 0x24C2,
  21932. Mdotaccent: 0x1E40,
  21933. Mdotbelow: 0x1E42,
  21934. Menarmenian: 0x0544,
  21935. Mmonospace: 0xFF2D,
  21936. Msmall: 0xF76D,
  21937. Mturned: 0x019C,
  21938. Mu: 0x039C,
  21939. N: 0x004E,
  21940. NJ: 0x01CA,
  21941. Nacute: 0x0143,
  21942. Ncaron: 0x0147,
  21943. Ncedilla: 0x0145,
  21944. Ncircle: 0x24C3,
  21945. Ncircumflexbelow: 0x1E4A,
  21946. Ncommaaccent: 0x0145,
  21947. Ndotaccent: 0x1E44,
  21948. Ndotbelow: 0x1E46,
  21949. Nhookleft: 0x019D,
  21950. Nineroman: 0x2168,
  21951. Nj: 0x01CB,
  21952. Njecyrillic: 0x040A,
  21953. Nlinebelow: 0x1E48,
  21954. Nmonospace: 0xFF2E,
  21955. Nowarmenian: 0x0546,
  21956. Nsmall: 0xF76E,
  21957. Ntilde: 0x00D1,
  21958. Ntildesmall: 0xF7F1,
  21959. Nu: 0x039D,
  21960. O: 0x004F,
  21961. OE: 0x0152,
  21962. OEsmall: 0xF6FA,
  21963. Oacute: 0x00D3,
  21964. Oacutesmall: 0xF7F3,
  21965. Obarredcyrillic: 0x04E8,
  21966. Obarreddieresiscyrillic: 0x04EA,
  21967. Obreve: 0x014E,
  21968. Ocaron: 0x01D1,
  21969. Ocenteredtilde: 0x019F,
  21970. Ocircle: 0x24C4,
  21971. Ocircumflex: 0x00D4,
  21972. Ocircumflexacute: 0x1ED0,
  21973. Ocircumflexdotbelow: 0x1ED8,
  21974. Ocircumflexgrave: 0x1ED2,
  21975. Ocircumflexhookabove: 0x1ED4,
  21976. Ocircumflexsmall: 0xF7F4,
  21977. Ocircumflextilde: 0x1ED6,
  21978. Ocyrillic: 0x041E,
  21979. Odblacute: 0x0150,
  21980. Odblgrave: 0x020C,
  21981. Odieresis: 0x00D6,
  21982. Odieresiscyrillic: 0x04E6,
  21983. Odieresissmall: 0xF7F6,
  21984. Odotbelow: 0x1ECC,
  21985. Ogoneksmall: 0xF6FB,
  21986. Ograve: 0x00D2,
  21987. Ogravesmall: 0xF7F2,
  21988. Oharmenian: 0x0555,
  21989. Ohm: 0x2126,
  21990. Ohookabove: 0x1ECE,
  21991. Ohorn: 0x01A0,
  21992. Ohornacute: 0x1EDA,
  21993. Ohorndotbelow: 0x1EE2,
  21994. Ohorngrave: 0x1EDC,
  21995. Ohornhookabove: 0x1EDE,
  21996. Ohorntilde: 0x1EE0,
  21997. Ohungarumlaut: 0x0150,
  21998. Oi: 0x01A2,
  21999. Oinvertedbreve: 0x020E,
  22000. Omacron: 0x014C,
  22001. Omacronacute: 0x1E52,
  22002. Omacrongrave: 0x1E50,
  22003. Omega: 0x2126,
  22004. Omegacyrillic: 0x0460,
  22005. Omegagreek: 0x03A9,
  22006. Omegaroundcyrillic: 0x047A,
  22007. Omegatitlocyrillic: 0x047C,
  22008. Omegatonos: 0x038F,
  22009. Omicron: 0x039F,
  22010. Omicrontonos: 0x038C,
  22011. Omonospace: 0xFF2F,
  22012. Oneroman: 0x2160,
  22013. Oogonek: 0x01EA,
  22014. Oogonekmacron: 0x01EC,
  22015. Oopen: 0x0186,
  22016. Oslash: 0x00D8,
  22017. Oslashacute: 0x01FE,
  22018. Oslashsmall: 0xF7F8,
  22019. Osmall: 0xF76F,
  22020. Ostrokeacute: 0x01FE,
  22021. Otcyrillic: 0x047E,
  22022. Otilde: 0x00D5,
  22023. Otildeacute: 0x1E4C,
  22024. Otildedieresis: 0x1E4E,
  22025. Otildesmall: 0xF7F5,
  22026. P: 0x0050,
  22027. Pacute: 0x1E54,
  22028. Pcircle: 0x24C5,
  22029. Pdotaccent: 0x1E56,
  22030. Pecyrillic: 0x041F,
  22031. Peharmenian: 0x054A,
  22032. Pemiddlehookcyrillic: 0x04A6,
  22033. Phi: 0x03A6,
  22034. Phook: 0x01A4,
  22035. Pi: 0x03A0,
  22036. Piwrarmenian: 0x0553,
  22037. Pmonospace: 0xFF30,
  22038. Psi: 0x03A8,
  22039. Psicyrillic: 0x0470,
  22040. Psmall: 0xF770,
  22041. Q: 0x0051,
  22042. Qcircle: 0x24C6,
  22043. Qmonospace: 0xFF31,
  22044. Qsmall: 0xF771,
  22045. R: 0x0052,
  22046. Raarmenian: 0x054C,
  22047. Racute: 0x0154,
  22048. Rcaron: 0x0158,
  22049. Rcedilla: 0x0156,
  22050. Rcircle: 0x24C7,
  22051. Rcommaaccent: 0x0156,
  22052. Rdblgrave: 0x0210,
  22053. Rdotaccent: 0x1E58,
  22054. Rdotbelow: 0x1E5A,
  22055. Rdotbelowmacron: 0x1E5C,
  22056. Reharmenian: 0x0550,
  22057. Rfraktur: 0x211C,
  22058. Rho: 0x03A1,
  22059. Ringsmall: 0xF6FC,
  22060. Rinvertedbreve: 0x0212,
  22061. Rlinebelow: 0x1E5E,
  22062. Rmonospace: 0xFF32,
  22063. Rsmall: 0xF772,
  22064. Rsmallinverted: 0x0281,
  22065. Rsmallinvertedsuperior: 0x02B6,
  22066. S: 0x0053,
  22067. SF010000: 0x250C,
  22068. SF020000: 0x2514,
  22069. SF030000: 0x2510,
  22070. SF040000: 0x2518,
  22071. SF050000: 0x253C,
  22072. SF060000: 0x252C,
  22073. SF070000: 0x2534,
  22074. SF080000: 0x251C,
  22075. SF090000: 0x2524,
  22076. SF100000: 0x2500,
  22077. SF110000: 0x2502,
  22078. SF190000: 0x2561,
  22079. SF200000: 0x2562,
  22080. SF210000: 0x2556,
  22081. SF220000: 0x2555,
  22082. SF230000: 0x2563,
  22083. SF240000: 0x2551,
  22084. SF250000: 0x2557,
  22085. SF260000: 0x255D,
  22086. SF270000: 0x255C,
  22087. SF280000: 0x255B,
  22088. SF360000: 0x255E,
  22089. SF370000: 0x255F,
  22090. SF380000: 0x255A,
  22091. SF390000: 0x2554,
  22092. SF400000: 0x2569,
  22093. SF410000: 0x2566,
  22094. SF420000: 0x2560,
  22095. SF430000: 0x2550,
  22096. SF440000: 0x256C,
  22097. SF450000: 0x2567,
  22098. SF460000: 0x2568,
  22099. SF470000: 0x2564,
  22100. SF480000: 0x2565,
  22101. SF490000: 0x2559,
  22102. SF500000: 0x2558,
  22103. SF510000: 0x2552,
  22104. SF520000: 0x2553,
  22105. SF530000: 0x256B,
  22106. SF540000: 0x256A,
  22107. Sacute: 0x015A,
  22108. Sacutedotaccent: 0x1E64,
  22109. Sampigreek: 0x03E0,
  22110. Scaron: 0x0160,
  22111. Scarondotaccent: 0x1E66,
  22112. Scaronsmall: 0xF6FD,
  22113. Scedilla: 0x015E,
  22114. Schwa: 0x018F,
  22115. Schwacyrillic: 0x04D8,
  22116. Schwadieresiscyrillic: 0x04DA,
  22117. Scircle: 0x24C8,
  22118. Scircumflex: 0x015C,
  22119. Scommaaccent: 0x0218,
  22120. Sdotaccent: 0x1E60,
  22121. Sdotbelow: 0x1E62,
  22122. Sdotbelowdotaccent: 0x1E68,
  22123. Seharmenian: 0x054D,
  22124. Sevenroman: 0x2166,
  22125. Shaarmenian: 0x0547,
  22126. Shacyrillic: 0x0428,
  22127. Shchacyrillic: 0x0429,
  22128. Sheicoptic: 0x03E2,
  22129. Shhacyrillic: 0x04BA,
  22130. Shimacoptic: 0x03EC,
  22131. Sigma: 0x03A3,
  22132. Sixroman: 0x2165,
  22133. Smonospace: 0xFF33,
  22134. Softsigncyrillic: 0x042C,
  22135. Ssmall: 0xF773,
  22136. Stigmagreek: 0x03DA,
  22137. T: 0x0054,
  22138. Tau: 0x03A4,
  22139. Tbar: 0x0166,
  22140. Tcaron: 0x0164,
  22141. Tcedilla: 0x0162,
  22142. Tcircle: 0x24C9,
  22143. Tcircumflexbelow: 0x1E70,
  22144. Tcommaaccent: 0x0162,
  22145. Tdotaccent: 0x1E6A,
  22146. Tdotbelow: 0x1E6C,
  22147. Tecyrillic: 0x0422,
  22148. Tedescendercyrillic: 0x04AC,
  22149. Tenroman: 0x2169,
  22150. Tetsecyrillic: 0x04B4,
  22151. Theta: 0x0398,
  22152. Thook: 0x01AC,
  22153. Thorn: 0x00DE,
  22154. Thornsmall: 0xF7FE,
  22155. Threeroman: 0x2162,
  22156. Tildesmall: 0xF6FE,
  22157. Tiwnarmenian: 0x054F,
  22158. Tlinebelow: 0x1E6E,
  22159. Tmonospace: 0xFF34,
  22160. Toarmenian: 0x0539,
  22161. Tonefive: 0x01BC,
  22162. Tonesix: 0x0184,
  22163. Tonetwo: 0x01A7,
  22164. Tretroflexhook: 0x01AE,
  22165. Tsecyrillic: 0x0426,
  22166. Tshecyrillic: 0x040B,
  22167. Tsmall: 0xF774,
  22168. Twelveroman: 0x216B,
  22169. Tworoman: 0x2161,
  22170. U: 0x0055,
  22171. Uacute: 0x00DA,
  22172. Uacutesmall: 0xF7FA,
  22173. Ubreve: 0x016C,
  22174. Ucaron: 0x01D3,
  22175. Ucircle: 0x24CA,
  22176. Ucircumflex: 0x00DB,
  22177. Ucircumflexbelow: 0x1E76,
  22178. Ucircumflexsmall: 0xF7FB,
  22179. Ucyrillic: 0x0423,
  22180. Udblacute: 0x0170,
  22181. Udblgrave: 0x0214,
  22182. Udieresis: 0x00DC,
  22183. Udieresisacute: 0x01D7,
  22184. Udieresisbelow: 0x1E72,
  22185. Udieresiscaron: 0x01D9,
  22186. Udieresiscyrillic: 0x04F0,
  22187. Udieresisgrave: 0x01DB,
  22188. Udieresismacron: 0x01D5,
  22189. Udieresissmall: 0xF7FC,
  22190. Udotbelow: 0x1EE4,
  22191. Ugrave: 0x00D9,
  22192. Ugravesmall: 0xF7F9,
  22193. Uhookabove: 0x1EE6,
  22194. Uhorn: 0x01AF,
  22195. Uhornacute: 0x1EE8,
  22196. Uhorndotbelow: 0x1EF0,
  22197. Uhorngrave: 0x1EEA,
  22198. Uhornhookabove: 0x1EEC,
  22199. Uhorntilde: 0x1EEE,
  22200. Uhungarumlaut: 0x0170,
  22201. Uhungarumlautcyrillic: 0x04F2,
  22202. Uinvertedbreve: 0x0216,
  22203. Ukcyrillic: 0x0478,
  22204. Umacron: 0x016A,
  22205. Umacroncyrillic: 0x04EE,
  22206. Umacrondieresis: 0x1E7A,
  22207. Umonospace: 0xFF35,
  22208. Uogonek: 0x0172,
  22209. Upsilon: 0x03A5,
  22210. Upsilon1: 0x03D2,
  22211. Upsilonacutehooksymbolgreek: 0x03D3,
  22212. Upsilonafrican: 0x01B1,
  22213. Upsilondieresis: 0x03AB,
  22214. Upsilondieresishooksymbolgreek: 0x03D4,
  22215. Upsilonhooksymbol: 0x03D2,
  22216. Upsilontonos: 0x038E,
  22217. Uring: 0x016E,
  22218. Ushortcyrillic: 0x040E,
  22219. Usmall: 0xF775,
  22220. Ustraightcyrillic: 0x04AE,
  22221. Ustraightstrokecyrillic: 0x04B0,
  22222. Utilde: 0x0168,
  22223. Utildeacute: 0x1E78,
  22224. Utildebelow: 0x1E74,
  22225. V: 0x0056,
  22226. Vcircle: 0x24CB,
  22227. Vdotbelow: 0x1E7E,
  22228. Vecyrillic: 0x0412,
  22229. Vewarmenian: 0x054E,
  22230. Vhook: 0x01B2,
  22231. Vmonospace: 0xFF36,
  22232. Voarmenian: 0x0548,
  22233. Vsmall: 0xF776,
  22234. Vtilde: 0x1E7C,
  22235. W: 0x0057,
  22236. Wacute: 0x1E82,
  22237. Wcircle: 0x24CC,
  22238. Wcircumflex: 0x0174,
  22239. Wdieresis: 0x1E84,
  22240. Wdotaccent: 0x1E86,
  22241. Wdotbelow: 0x1E88,
  22242. Wgrave: 0x1E80,
  22243. Wmonospace: 0xFF37,
  22244. Wsmall: 0xF777,
  22245. X: 0x0058,
  22246. Xcircle: 0x24CD,
  22247. Xdieresis: 0x1E8C,
  22248. Xdotaccent: 0x1E8A,
  22249. Xeharmenian: 0x053D,
  22250. Xi: 0x039E,
  22251. Xmonospace: 0xFF38,
  22252. Xsmall: 0xF778,
  22253. Y: 0x0059,
  22254. Yacute: 0x00DD,
  22255. Yacutesmall: 0xF7FD,
  22256. Yatcyrillic: 0x0462,
  22257. Ycircle: 0x24CE,
  22258. Ycircumflex: 0x0176,
  22259. Ydieresis: 0x0178,
  22260. Ydieresissmall: 0xF7FF,
  22261. Ydotaccent: 0x1E8E,
  22262. Ydotbelow: 0x1EF4,
  22263. Yericyrillic: 0x042B,
  22264. Yerudieresiscyrillic: 0x04F8,
  22265. Ygrave: 0x1EF2,
  22266. Yhook: 0x01B3,
  22267. Yhookabove: 0x1EF6,
  22268. Yiarmenian: 0x0545,
  22269. Yicyrillic: 0x0407,
  22270. Yiwnarmenian: 0x0552,
  22271. Ymonospace: 0xFF39,
  22272. Ysmall: 0xF779,
  22273. Ytilde: 0x1EF8,
  22274. Yusbigcyrillic: 0x046A,
  22275. Yusbigiotifiedcyrillic: 0x046C,
  22276. Yuslittlecyrillic: 0x0466,
  22277. Yuslittleiotifiedcyrillic: 0x0468,
  22278. Z: 0x005A,
  22279. Zaarmenian: 0x0536,
  22280. Zacute: 0x0179,
  22281. Zcaron: 0x017D,
  22282. Zcaronsmall: 0xF6FF,
  22283. Zcircle: 0x24CF,
  22284. Zcircumflex: 0x1E90,
  22285. Zdot: 0x017B,
  22286. Zdotaccent: 0x017B,
  22287. Zdotbelow: 0x1E92,
  22288. Zecyrillic: 0x0417,
  22289. Zedescendercyrillic: 0x0498,
  22290. Zedieresiscyrillic: 0x04DE,
  22291. Zeta: 0x0396,
  22292. Zhearmenian: 0x053A,
  22293. Zhebrevecyrillic: 0x04C1,
  22294. Zhecyrillic: 0x0416,
  22295. Zhedescendercyrillic: 0x0496,
  22296. Zhedieresiscyrillic: 0x04DC,
  22297. Zlinebelow: 0x1E94,
  22298. Zmonospace: 0xFF3A,
  22299. Zsmall: 0xF77A,
  22300. Zstroke: 0x01B5,
  22301. a: 0x0061,
  22302. aabengali: 0x0986,
  22303. aacute: 0x00E1,
  22304. aadeva: 0x0906,
  22305. aagujarati: 0x0A86,
  22306. aagurmukhi: 0x0A06,
  22307. aamatragurmukhi: 0x0A3E,
  22308. aarusquare: 0x3303,
  22309. aavowelsignbengali: 0x09BE,
  22310. aavowelsigndeva: 0x093E,
  22311. aavowelsigngujarati: 0x0ABE,
  22312. abbreviationmarkarmenian: 0x055F,
  22313. abbreviationsigndeva: 0x0970,
  22314. abengali: 0x0985,
  22315. abopomofo: 0x311A,
  22316. abreve: 0x0103,
  22317. abreveacute: 0x1EAF,
  22318. abrevecyrillic: 0x04D1,
  22319. abrevedotbelow: 0x1EB7,
  22320. abrevegrave: 0x1EB1,
  22321. abrevehookabove: 0x1EB3,
  22322. abrevetilde: 0x1EB5,
  22323. acaron: 0x01CE,
  22324. acircle: 0x24D0,
  22325. acircumflex: 0x00E2,
  22326. acircumflexacute: 0x1EA5,
  22327. acircumflexdotbelow: 0x1EAD,
  22328. acircumflexgrave: 0x1EA7,
  22329. acircumflexhookabove: 0x1EA9,
  22330. acircumflextilde: 0x1EAB,
  22331. acute: 0x00B4,
  22332. acutebelowcmb: 0x0317,
  22333. acutecmb: 0x0301,
  22334. acutecomb: 0x0301,
  22335. acutedeva: 0x0954,
  22336. acutelowmod: 0x02CF,
  22337. acutetonecmb: 0x0341,
  22338. acyrillic: 0x0430,
  22339. adblgrave: 0x0201,
  22340. addakgurmukhi: 0x0A71,
  22341. adeva: 0x0905,
  22342. adieresis: 0x00E4,
  22343. adieresiscyrillic: 0x04D3,
  22344. adieresismacron: 0x01DF,
  22345. adotbelow: 0x1EA1,
  22346. adotmacron: 0x01E1,
  22347. ae: 0x00E6,
  22348. aeacute: 0x01FD,
  22349. aekorean: 0x3150,
  22350. aemacron: 0x01E3,
  22351. afii00208: 0x2015,
  22352. afii08941: 0x20A4,
  22353. afii10017: 0x0410,
  22354. afii10018: 0x0411,
  22355. afii10019: 0x0412,
  22356. afii10020: 0x0413,
  22357. afii10021: 0x0414,
  22358. afii10022: 0x0415,
  22359. afii10023: 0x0401,
  22360. afii10024: 0x0416,
  22361. afii10025: 0x0417,
  22362. afii10026: 0x0418,
  22363. afii10027: 0x0419,
  22364. afii10028: 0x041A,
  22365. afii10029: 0x041B,
  22366. afii10030: 0x041C,
  22367. afii10031: 0x041D,
  22368. afii10032: 0x041E,
  22369. afii10033: 0x041F,
  22370. afii10034: 0x0420,
  22371. afii10035: 0x0421,
  22372. afii10036: 0x0422,
  22373. afii10037: 0x0423,
  22374. afii10038: 0x0424,
  22375. afii10039: 0x0425,
  22376. afii10040: 0x0426,
  22377. afii10041: 0x0427,
  22378. afii10042: 0x0428,
  22379. afii10043: 0x0429,
  22380. afii10044: 0x042A,
  22381. afii10045: 0x042B,
  22382. afii10046: 0x042C,
  22383. afii10047: 0x042D,
  22384. afii10048: 0x042E,
  22385. afii10049: 0x042F,
  22386. afii10050: 0x0490,
  22387. afii10051: 0x0402,
  22388. afii10052: 0x0403,
  22389. afii10053: 0x0404,
  22390. afii10054: 0x0405,
  22391. afii10055: 0x0406,
  22392. afii10056: 0x0407,
  22393. afii10057: 0x0408,
  22394. afii10058: 0x0409,
  22395. afii10059: 0x040A,
  22396. afii10060: 0x040B,
  22397. afii10061: 0x040C,
  22398. afii10062: 0x040E,
  22399. afii10063: 0xF6C4,
  22400. afii10064: 0xF6C5,
  22401. afii10065: 0x0430,
  22402. afii10066: 0x0431,
  22403. afii10067: 0x0432,
  22404. afii10068: 0x0433,
  22405. afii10069: 0x0434,
  22406. afii10070: 0x0435,
  22407. afii10071: 0x0451,
  22408. afii10072: 0x0436,
  22409. afii10073: 0x0437,
  22410. afii10074: 0x0438,
  22411. afii10075: 0x0439,
  22412. afii10076: 0x043A,
  22413. afii10077: 0x043B,
  22414. afii10078: 0x043C,
  22415. afii10079: 0x043D,
  22416. afii10080: 0x043E,
  22417. afii10081: 0x043F,
  22418. afii10082: 0x0440,
  22419. afii10083: 0x0441,
  22420. afii10084: 0x0442,
  22421. afii10085: 0x0443,
  22422. afii10086: 0x0444,
  22423. afii10087: 0x0445,
  22424. afii10088: 0x0446,
  22425. afii10089: 0x0447,
  22426. afii10090: 0x0448,
  22427. afii10091: 0x0449,
  22428. afii10092: 0x044A,
  22429. afii10093: 0x044B,
  22430. afii10094: 0x044C,
  22431. afii10095: 0x044D,
  22432. afii10096: 0x044E,
  22433. afii10097: 0x044F,
  22434. afii10098: 0x0491,
  22435. afii10099: 0x0452,
  22436. afii10100: 0x0453,
  22437. afii10101: 0x0454,
  22438. afii10102: 0x0455,
  22439. afii10103: 0x0456,
  22440. afii10104: 0x0457,
  22441. afii10105: 0x0458,
  22442. afii10106: 0x0459,
  22443. afii10107: 0x045A,
  22444. afii10108: 0x045B,
  22445. afii10109: 0x045C,
  22446. afii10110: 0x045E,
  22447. afii10145: 0x040F,
  22448. afii10146: 0x0462,
  22449. afii10147: 0x0472,
  22450. afii10148: 0x0474,
  22451. afii10192: 0xF6C6,
  22452. afii10193: 0x045F,
  22453. afii10194: 0x0463,
  22454. afii10195: 0x0473,
  22455. afii10196: 0x0475,
  22456. afii10831: 0xF6C7,
  22457. afii10832: 0xF6C8,
  22458. afii10846: 0x04D9,
  22459. afii299: 0x200E,
  22460. afii300: 0x200F,
  22461. afii301: 0x200D,
  22462. afii57381: 0x066A,
  22463. afii57388: 0x060C,
  22464. afii57392: 0x0660,
  22465. afii57393: 0x0661,
  22466. afii57394: 0x0662,
  22467. afii57395: 0x0663,
  22468. afii57396: 0x0664,
  22469. afii57397: 0x0665,
  22470. afii57398: 0x0666,
  22471. afii57399: 0x0667,
  22472. afii57400: 0x0668,
  22473. afii57401: 0x0669,
  22474. afii57403: 0x061B,
  22475. afii57407: 0x061F,
  22476. afii57409: 0x0621,
  22477. afii57410: 0x0622,
  22478. afii57411: 0x0623,
  22479. afii57412: 0x0624,
  22480. afii57413: 0x0625,
  22481. afii57414: 0x0626,
  22482. afii57415: 0x0627,
  22483. afii57416: 0x0628,
  22484. afii57417: 0x0629,
  22485. afii57418: 0x062A,
  22486. afii57419: 0x062B,
  22487. afii57420: 0x062C,
  22488. afii57421: 0x062D,
  22489. afii57422: 0x062E,
  22490. afii57423: 0x062F,
  22491. afii57424: 0x0630,
  22492. afii57425: 0x0631,
  22493. afii57426: 0x0632,
  22494. afii57427: 0x0633,
  22495. afii57428: 0x0634,
  22496. afii57429: 0x0635,
  22497. afii57430: 0x0636,
  22498. afii57431: 0x0637,
  22499. afii57432: 0x0638,
  22500. afii57433: 0x0639,
  22501. afii57434: 0x063A,
  22502. afii57440: 0x0640,
  22503. afii57441: 0x0641,
  22504. afii57442: 0x0642,
  22505. afii57443: 0x0643,
  22506. afii57444: 0x0644,
  22507. afii57445: 0x0645,
  22508. afii57446: 0x0646,
  22509. afii57448: 0x0648,
  22510. afii57449: 0x0649,
  22511. afii57450: 0x064A,
  22512. afii57451: 0x064B,
  22513. afii57452: 0x064C,
  22514. afii57453: 0x064D,
  22515. afii57454: 0x064E,
  22516. afii57455: 0x064F,
  22517. afii57456: 0x0650,
  22518. afii57457: 0x0651,
  22519. afii57458: 0x0652,
  22520. afii57470: 0x0647,
  22521. afii57505: 0x06A4,
  22522. afii57506: 0x067E,
  22523. afii57507: 0x0686,
  22524. afii57508: 0x0698,
  22525. afii57509: 0x06AF,
  22526. afii57511: 0x0679,
  22527. afii57512: 0x0688,
  22528. afii57513: 0x0691,
  22529. afii57514: 0x06BA,
  22530. afii57519: 0x06D2,
  22531. afii57534: 0x06D5,
  22532. afii57636: 0x20AA,
  22533. afii57645: 0x05BE,
  22534. afii57658: 0x05C3,
  22535. afii57664: 0x05D0,
  22536. afii57665: 0x05D1,
  22537. afii57666: 0x05D2,
  22538. afii57667: 0x05D3,
  22539. afii57668: 0x05D4,
  22540. afii57669: 0x05D5,
  22541. afii57670: 0x05D6,
  22542. afii57671: 0x05D7,
  22543. afii57672: 0x05D8,
  22544. afii57673: 0x05D9,
  22545. afii57674: 0x05DA,
  22546. afii57675: 0x05DB,
  22547. afii57676: 0x05DC,
  22548. afii57677: 0x05DD,
  22549. afii57678: 0x05DE,
  22550. afii57679: 0x05DF,
  22551. afii57680: 0x05E0,
  22552. afii57681: 0x05E1,
  22553. afii57682: 0x05E2,
  22554. afii57683: 0x05E3,
  22555. afii57684: 0x05E4,
  22556. afii57685: 0x05E5,
  22557. afii57686: 0x05E6,
  22558. afii57687: 0x05E7,
  22559. afii57688: 0x05E8,
  22560. afii57689: 0x05E9,
  22561. afii57690: 0x05EA,
  22562. afii57694: 0xFB2A,
  22563. afii57695: 0xFB2B,
  22564. afii57700: 0xFB4B,
  22565. afii57705: 0xFB1F,
  22566. afii57716: 0x05F0,
  22567. afii57717: 0x05F1,
  22568. afii57718: 0x05F2,
  22569. afii57723: 0xFB35,
  22570. afii57793: 0x05B4,
  22571. afii57794: 0x05B5,
  22572. afii57795: 0x05B6,
  22573. afii57796: 0x05BB,
  22574. afii57797: 0x05B8,
  22575. afii57798: 0x05B7,
  22576. afii57799: 0x05B0,
  22577. afii57800: 0x05B2,
  22578. afii57801: 0x05B1,
  22579. afii57802: 0x05B3,
  22580. afii57803: 0x05C2,
  22581. afii57804: 0x05C1,
  22582. afii57806: 0x05B9,
  22583. afii57807: 0x05BC,
  22584. afii57839: 0x05BD,
  22585. afii57841: 0x05BF,
  22586. afii57842: 0x05C0,
  22587. afii57929: 0x02BC,
  22588. afii61248: 0x2105,
  22589. afii61289: 0x2113,
  22590. afii61352: 0x2116,
  22591. afii61573: 0x202C,
  22592. afii61574: 0x202D,
  22593. afii61575: 0x202E,
  22594. afii61664: 0x200C,
  22595. afii63167: 0x066D,
  22596. afii64937: 0x02BD,
  22597. agrave: 0x00E0,
  22598. agujarati: 0x0A85,
  22599. agurmukhi: 0x0A05,
  22600. ahiragana: 0x3042,
  22601. ahookabove: 0x1EA3,
  22602. aibengali: 0x0990,
  22603. aibopomofo: 0x311E,
  22604. aideva: 0x0910,
  22605. aiecyrillic: 0x04D5,
  22606. aigujarati: 0x0A90,
  22607. aigurmukhi: 0x0A10,
  22608. aimatragurmukhi: 0x0A48,
  22609. ainarabic: 0x0639,
  22610. ainfinalarabic: 0xFECA,
  22611. aininitialarabic: 0xFECB,
  22612. ainmedialarabic: 0xFECC,
  22613. ainvertedbreve: 0x0203,
  22614. aivowelsignbengali: 0x09C8,
  22615. aivowelsigndeva: 0x0948,
  22616. aivowelsigngujarati: 0x0AC8,
  22617. akatakana: 0x30A2,
  22618. akatakanahalfwidth: 0xFF71,
  22619. akorean: 0x314F,
  22620. alef: 0x05D0,
  22621. alefarabic: 0x0627,
  22622. alefdageshhebrew: 0xFB30,
  22623. aleffinalarabic: 0xFE8E,
  22624. alefhamzaabovearabic: 0x0623,
  22625. alefhamzaabovefinalarabic: 0xFE84,
  22626. alefhamzabelowarabic: 0x0625,
  22627. alefhamzabelowfinalarabic: 0xFE88,
  22628. alefhebrew: 0x05D0,
  22629. aleflamedhebrew: 0xFB4F,
  22630. alefmaddaabovearabic: 0x0622,
  22631. alefmaddaabovefinalarabic: 0xFE82,
  22632. alefmaksuraarabic: 0x0649,
  22633. alefmaksurafinalarabic: 0xFEF0,
  22634. alefmaksurainitialarabic: 0xFEF3,
  22635. alefmaksuramedialarabic: 0xFEF4,
  22636. alefpatahhebrew: 0xFB2E,
  22637. alefqamatshebrew: 0xFB2F,
  22638. aleph: 0x2135,
  22639. allequal: 0x224C,
  22640. alpha: 0x03B1,
  22641. alphatonos: 0x03AC,
  22642. amacron: 0x0101,
  22643. amonospace: 0xFF41,
  22644. ampersand: 0x0026,
  22645. ampersandmonospace: 0xFF06,
  22646. ampersandsmall: 0xF726,
  22647. amsquare: 0x33C2,
  22648. anbopomofo: 0x3122,
  22649. angbopomofo: 0x3124,
  22650. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  22651. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  22652. angkhankhuthai: 0x0E5A,
  22653. angle: 0x2220,
  22654. anglebracketleft: 0x3008,
  22655. anglebracketleftvertical: 0xFE3F,
  22656. anglebracketright: 0x3009,
  22657. anglebracketrightvertical: 0xFE40,
  22658. angleleft: 0x2329,
  22659. angleright: 0x232A,
  22660. angstrom: 0x212B,
  22661. anoteleia: 0x0387,
  22662. anudattadeva: 0x0952,
  22663. anusvarabengali: 0x0982,
  22664. anusvaradeva: 0x0902,
  22665. anusvaragujarati: 0x0A82,
  22666. aogonek: 0x0105,
  22667. apaatosquare: 0x3300,
  22668. aparen: 0x249C,
  22669. apostrophearmenian: 0x055A,
  22670. apostrophemod: 0x02BC,
  22671. apple: 0xF8FF,
  22672. approaches: 0x2250,
  22673. approxequal: 0x2248,
  22674. approxequalorimage: 0x2252,
  22675. approximatelyequal: 0x2245,
  22676. araeaekorean: 0x318E,
  22677. araeakorean: 0x318D,
  22678. arc: 0x2312,
  22679. arighthalfring: 0x1E9A,
  22680. aring: 0x00E5,
  22681. aringacute: 0x01FB,
  22682. aringbelow: 0x1E01,
  22683. arrowboth: 0x2194,
  22684. arrowdashdown: 0x21E3,
  22685. arrowdashleft: 0x21E0,
  22686. arrowdashright: 0x21E2,
  22687. arrowdashup: 0x21E1,
  22688. arrowdblboth: 0x21D4,
  22689. arrowdbldown: 0x21D3,
  22690. arrowdblleft: 0x21D0,
  22691. arrowdblright: 0x21D2,
  22692. arrowdblup: 0x21D1,
  22693. arrowdown: 0x2193,
  22694. arrowdownleft: 0x2199,
  22695. arrowdownright: 0x2198,
  22696. arrowdownwhite: 0x21E9,
  22697. arrowheaddownmod: 0x02C5,
  22698. arrowheadleftmod: 0x02C2,
  22699. arrowheadrightmod: 0x02C3,
  22700. arrowheadupmod: 0x02C4,
  22701. arrowhorizex: 0xF8E7,
  22702. arrowleft: 0x2190,
  22703. arrowleftdbl: 0x21D0,
  22704. arrowleftdblstroke: 0x21CD,
  22705. arrowleftoverright: 0x21C6,
  22706. arrowleftwhite: 0x21E6,
  22707. arrowright: 0x2192,
  22708. arrowrightdblstroke: 0x21CF,
  22709. arrowrightheavy: 0x279E,
  22710. arrowrightoverleft: 0x21C4,
  22711. arrowrightwhite: 0x21E8,
  22712. arrowtableft: 0x21E4,
  22713. arrowtabright: 0x21E5,
  22714. arrowup: 0x2191,
  22715. arrowupdn: 0x2195,
  22716. arrowupdnbse: 0x21A8,
  22717. arrowupdownbase: 0x21A8,
  22718. arrowupleft: 0x2196,
  22719. arrowupleftofdown: 0x21C5,
  22720. arrowupright: 0x2197,
  22721. arrowupwhite: 0x21E7,
  22722. arrowvertex: 0xF8E6,
  22723. asciicircum: 0x005E,
  22724. asciicircummonospace: 0xFF3E,
  22725. asciitilde: 0x007E,
  22726. asciitildemonospace: 0xFF5E,
  22727. ascript: 0x0251,
  22728. ascriptturned: 0x0252,
  22729. asmallhiragana: 0x3041,
  22730. asmallkatakana: 0x30A1,
  22731. asmallkatakanahalfwidth: 0xFF67,
  22732. asterisk: 0x002A,
  22733. asteriskaltonearabic: 0x066D,
  22734. asteriskarabic: 0x066D,
  22735. asteriskmath: 0x2217,
  22736. asteriskmonospace: 0xFF0A,
  22737. asterisksmall: 0xFE61,
  22738. asterism: 0x2042,
  22739. asuperior: 0xF6E9,
  22740. asymptoticallyequal: 0x2243,
  22741. at: 0x0040,
  22742. atilde: 0x00E3,
  22743. atmonospace: 0xFF20,
  22744. atsmall: 0xFE6B,
  22745. aturned: 0x0250,
  22746. aubengali: 0x0994,
  22747. aubopomofo: 0x3120,
  22748. audeva: 0x0914,
  22749. augujarati: 0x0A94,
  22750. augurmukhi: 0x0A14,
  22751. aulengthmarkbengali: 0x09D7,
  22752. aumatragurmukhi: 0x0A4C,
  22753. auvowelsignbengali: 0x09CC,
  22754. auvowelsigndeva: 0x094C,
  22755. auvowelsigngujarati: 0x0ACC,
  22756. avagrahadeva: 0x093D,
  22757. aybarmenian: 0x0561,
  22758. ayin: 0x05E2,
  22759. ayinaltonehebrew: 0xFB20,
  22760. ayinhebrew: 0x05E2,
  22761. b: 0x0062,
  22762. babengali: 0x09AC,
  22763. backslash: 0x005C,
  22764. backslashmonospace: 0xFF3C,
  22765. badeva: 0x092C,
  22766. bagujarati: 0x0AAC,
  22767. bagurmukhi: 0x0A2C,
  22768. bahiragana: 0x3070,
  22769. bahtthai: 0x0E3F,
  22770. bakatakana: 0x30D0,
  22771. bar: 0x007C,
  22772. barmonospace: 0xFF5C,
  22773. bbopomofo: 0x3105,
  22774. bcircle: 0x24D1,
  22775. bdotaccent: 0x1E03,
  22776. bdotbelow: 0x1E05,
  22777. beamedsixteenthnotes: 0x266C,
  22778. because: 0x2235,
  22779. becyrillic: 0x0431,
  22780. beharabic: 0x0628,
  22781. behfinalarabic: 0xFE90,
  22782. behinitialarabic: 0xFE91,
  22783. behiragana: 0x3079,
  22784. behmedialarabic: 0xFE92,
  22785. behmeeminitialarabic: 0xFC9F,
  22786. behmeemisolatedarabic: 0xFC08,
  22787. behnoonfinalarabic: 0xFC6D,
  22788. bekatakana: 0x30D9,
  22789. benarmenian: 0x0562,
  22790. bet: 0x05D1,
  22791. beta: 0x03B2,
  22792. betasymbolgreek: 0x03D0,
  22793. betdagesh: 0xFB31,
  22794. betdageshhebrew: 0xFB31,
  22795. bethebrew: 0x05D1,
  22796. betrafehebrew: 0xFB4C,
  22797. bhabengali: 0x09AD,
  22798. bhadeva: 0x092D,
  22799. bhagujarati: 0x0AAD,
  22800. bhagurmukhi: 0x0A2D,
  22801. bhook: 0x0253,
  22802. bihiragana: 0x3073,
  22803. bikatakana: 0x30D3,
  22804. bilabialclick: 0x0298,
  22805. bindigurmukhi: 0x0A02,
  22806. birusquare: 0x3331,
  22807. blackcircle: 0x25CF,
  22808. blackdiamond: 0x25C6,
  22809. blackdownpointingtriangle: 0x25BC,
  22810. blackleftpointingpointer: 0x25C4,
  22811. blackleftpointingtriangle: 0x25C0,
  22812. blacklenticularbracketleft: 0x3010,
  22813. blacklenticularbracketleftvertical: 0xFE3B,
  22814. blacklenticularbracketright: 0x3011,
  22815. blacklenticularbracketrightvertical: 0xFE3C,
  22816. blacklowerlefttriangle: 0x25E3,
  22817. blacklowerrighttriangle: 0x25E2,
  22818. blackrectangle: 0x25AC,
  22819. blackrightpointingpointer: 0x25BA,
  22820. blackrightpointingtriangle: 0x25B6,
  22821. blacksmallsquare: 0x25AA,
  22822. blacksmilingface: 0x263B,
  22823. blacksquare: 0x25A0,
  22824. blackstar: 0x2605,
  22825. blackupperlefttriangle: 0x25E4,
  22826. blackupperrighttriangle: 0x25E5,
  22827. blackuppointingsmalltriangle: 0x25B4,
  22828. blackuppointingtriangle: 0x25B2,
  22829. blank: 0x2423,
  22830. blinebelow: 0x1E07,
  22831. block: 0x2588,
  22832. bmonospace: 0xFF42,
  22833. bobaimaithai: 0x0E1A,
  22834. bohiragana: 0x307C,
  22835. bokatakana: 0x30DC,
  22836. bparen: 0x249D,
  22837. bqsquare: 0x33C3,
  22838. braceex: 0xF8F4,
  22839. braceleft: 0x007B,
  22840. braceleftbt: 0xF8F3,
  22841. braceleftmid: 0xF8F2,
  22842. braceleftmonospace: 0xFF5B,
  22843. braceleftsmall: 0xFE5B,
  22844. bracelefttp: 0xF8F1,
  22845. braceleftvertical: 0xFE37,
  22846. braceright: 0x007D,
  22847. bracerightbt: 0xF8FE,
  22848. bracerightmid: 0xF8FD,
  22849. bracerightmonospace: 0xFF5D,
  22850. bracerightsmall: 0xFE5C,
  22851. bracerighttp: 0xF8FC,
  22852. bracerightvertical: 0xFE38,
  22853. bracketleft: 0x005B,
  22854. bracketleftbt: 0xF8F0,
  22855. bracketleftex: 0xF8EF,
  22856. bracketleftmonospace: 0xFF3B,
  22857. bracketlefttp: 0xF8EE,
  22858. bracketright: 0x005D,
  22859. bracketrightbt: 0xF8FB,
  22860. bracketrightex: 0xF8FA,
  22861. bracketrightmonospace: 0xFF3D,
  22862. bracketrighttp: 0xF8F9,
  22863. breve: 0x02D8,
  22864. brevebelowcmb: 0x032E,
  22865. brevecmb: 0x0306,
  22866. breveinvertedbelowcmb: 0x032F,
  22867. breveinvertedcmb: 0x0311,
  22868. breveinverteddoublecmb: 0x0361,
  22869. bridgebelowcmb: 0x032A,
  22870. bridgeinvertedbelowcmb: 0x033A,
  22871. brokenbar: 0x00A6,
  22872. bstroke: 0x0180,
  22873. bsuperior: 0xF6EA,
  22874. btopbar: 0x0183,
  22875. buhiragana: 0x3076,
  22876. bukatakana: 0x30D6,
  22877. bullet: 0x2022,
  22878. bulletinverse: 0x25D8,
  22879. bulletoperator: 0x2219,
  22880. bullseye: 0x25CE,
  22881. c: 0x0063,
  22882. caarmenian: 0x056E,
  22883. cabengali: 0x099A,
  22884. cacute: 0x0107,
  22885. cadeva: 0x091A,
  22886. cagujarati: 0x0A9A,
  22887. cagurmukhi: 0x0A1A,
  22888. calsquare: 0x3388,
  22889. candrabindubengali: 0x0981,
  22890. candrabinducmb: 0x0310,
  22891. candrabindudeva: 0x0901,
  22892. candrabindugujarati: 0x0A81,
  22893. capslock: 0x21EA,
  22894. careof: 0x2105,
  22895. caron: 0x02C7,
  22896. caronbelowcmb: 0x032C,
  22897. caroncmb: 0x030C,
  22898. carriagereturn: 0x21B5,
  22899. cbopomofo: 0x3118,
  22900. ccaron: 0x010D,
  22901. ccedilla: 0x00E7,
  22902. ccedillaacute: 0x1E09,
  22903. ccircle: 0x24D2,
  22904. ccircumflex: 0x0109,
  22905. ccurl: 0x0255,
  22906. cdot: 0x010B,
  22907. cdotaccent: 0x010B,
  22908. cdsquare: 0x33C5,
  22909. cedilla: 0x00B8,
  22910. cedillacmb: 0x0327,
  22911. cent: 0x00A2,
  22912. centigrade: 0x2103,
  22913. centinferior: 0xF6DF,
  22914. centmonospace: 0xFFE0,
  22915. centoldstyle: 0xF7A2,
  22916. centsuperior: 0xF6E0,
  22917. chaarmenian: 0x0579,
  22918. chabengali: 0x099B,
  22919. chadeva: 0x091B,
  22920. chagujarati: 0x0A9B,
  22921. chagurmukhi: 0x0A1B,
  22922. chbopomofo: 0x3114,
  22923. cheabkhasiancyrillic: 0x04BD,
  22924. checkmark: 0x2713,
  22925. checyrillic: 0x0447,
  22926. chedescenderabkhasiancyrillic: 0x04BF,
  22927. chedescendercyrillic: 0x04B7,
  22928. chedieresiscyrillic: 0x04F5,
  22929. cheharmenian: 0x0573,
  22930. chekhakassiancyrillic: 0x04CC,
  22931. cheverticalstrokecyrillic: 0x04B9,
  22932. chi: 0x03C7,
  22933. chieuchacirclekorean: 0x3277,
  22934. chieuchaparenkorean: 0x3217,
  22935. chieuchcirclekorean: 0x3269,
  22936. chieuchkorean: 0x314A,
  22937. chieuchparenkorean: 0x3209,
  22938. chochangthai: 0x0E0A,
  22939. chochanthai: 0x0E08,
  22940. chochingthai: 0x0E09,
  22941. chochoethai: 0x0E0C,
  22942. chook: 0x0188,
  22943. cieucacirclekorean: 0x3276,
  22944. cieucaparenkorean: 0x3216,
  22945. cieuccirclekorean: 0x3268,
  22946. cieuckorean: 0x3148,
  22947. cieucparenkorean: 0x3208,
  22948. cieucuparenkorean: 0x321C,
  22949. circle: 0x25CB,
  22950. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  22951. circlemultiply: 0x2297,
  22952. circleot: 0x2299,
  22953. circleplus: 0x2295,
  22954. circlepostalmark: 0x3036,
  22955. circlewithlefthalfblack: 0x25D0,
  22956. circlewithrighthalfblack: 0x25D1,
  22957. circumflex: 0x02C6,
  22958. circumflexbelowcmb: 0x032D,
  22959. circumflexcmb: 0x0302,
  22960. clear: 0x2327,
  22961. clickalveolar: 0x01C2,
  22962. clickdental: 0x01C0,
  22963. clicklateral: 0x01C1,
  22964. clickretroflex: 0x01C3,
  22965. club: 0x2663,
  22966. clubsuitblack: 0x2663,
  22967. clubsuitwhite: 0x2667,
  22968. cmcubedsquare: 0x33A4,
  22969. cmonospace: 0xFF43,
  22970. cmsquaredsquare: 0x33A0,
  22971. coarmenian: 0x0581,
  22972. colon: 0x003A,
  22973. colonmonetary: 0x20A1,
  22974. colonmonospace: 0xFF1A,
  22975. colonsign: 0x20A1,
  22976. colonsmall: 0xFE55,
  22977. colontriangularhalfmod: 0x02D1,
  22978. colontriangularmod: 0x02D0,
  22979. comma: 0x002C,
  22980. commaabovecmb: 0x0313,
  22981. commaaboverightcmb: 0x0315,
  22982. commaaccent: 0xF6C3,
  22983. commaarabic: 0x060C,
  22984. commaarmenian: 0x055D,
  22985. commainferior: 0xF6E1,
  22986. commamonospace: 0xFF0C,
  22987. commareversedabovecmb: 0x0314,
  22988. commareversedmod: 0x02BD,
  22989. commasmall: 0xFE50,
  22990. commasuperior: 0xF6E2,
  22991. commaturnedabovecmb: 0x0312,
  22992. commaturnedmod: 0x02BB,
  22993. compass: 0x263C,
  22994. congruent: 0x2245,
  22995. contourintegral: 0x222E,
  22996. control: 0x2303,
  22997. controlACK: 0x0006,
  22998. controlBEL: 0x0007,
  22999. controlBS: 0x0008,
  23000. controlCAN: 0x0018,
  23001. controlCR: 0x000D,
  23002. controlDC1: 0x0011,
  23003. controlDC2: 0x0012,
  23004. controlDC3: 0x0013,
  23005. controlDC4: 0x0014,
  23006. controlDEL: 0x007F,
  23007. controlDLE: 0x0010,
  23008. controlEM: 0x0019,
  23009. controlENQ: 0x0005,
  23010. controlEOT: 0x0004,
  23011. controlESC: 0x001B,
  23012. controlETB: 0x0017,
  23013. controlETX: 0x0003,
  23014. controlFF: 0x000C,
  23015. controlFS: 0x001C,
  23016. controlGS: 0x001D,
  23017. controlHT: 0x0009,
  23018. controlLF: 0x000A,
  23019. controlNAK: 0x0015,
  23020. controlRS: 0x001E,
  23021. controlSI: 0x000F,
  23022. controlSO: 0x000E,
  23023. controlSOT: 0x0002,
  23024. controlSTX: 0x0001,
  23025. controlSUB: 0x001A,
  23026. controlSYN: 0x0016,
  23027. controlUS: 0x001F,
  23028. controlVT: 0x000B,
  23029. copyright: 0x00A9,
  23030. copyrightsans: 0xF8E9,
  23031. copyrightserif: 0xF6D9,
  23032. cornerbracketleft: 0x300C,
  23033. cornerbracketlefthalfwidth: 0xFF62,
  23034. cornerbracketleftvertical: 0xFE41,
  23035. cornerbracketright: 0x300D,
  23036. cornerbracketrighthalfwidth: 0xFF63,
  23037. cornerbracketrightvertical: 0xFE42,
  23038. corporationsquare: 0x337F,
  23039. cosquare: 0x33C7,
  23040. coverkgsquare: 0x33C6,
  23041. cparen: 0x249E,
  23042. cruzeiro: 0x20A2,
  23043. cstretched: 0x0297,
  23044. curlyand: 0x22CF,
  23045. curlyor: 0x22CE,
  23046. currency: 0x00A4,
  23047. cyrBreve: 0xF6D1,
  23048. cyrFlex: 0xF6D2,
  23049. cyrbreve: 0xF6D4,
  23050. cyrflex: 0xF6D5,
  23051. d: 0x0064,
  23052. daarmenian: 0x0564,
  23053. dabengali: 0x09A6,
  23054. dadarabic: 0x0636,
  23055. dadeva: 0x0926,
  23056. dadfinalarabic: 0xFEBE,
  23057. dadinitialarabic: 0xFEBF,
  23058. dadmedialarabic: 0xFEC0,
  23059. dagesh: 0x05BC,
  23060. dageshhebrew: 0x05BC,
  23061. dagger: 0x2020,
  23062. daggerdbl: 0x2021,
  23063. dagujarati: 0x0AA6,
  23064. dagurmukhi: 0x0A26,
  23065. dahiragana: 0x3060,
  23066. dakatakana: 0x30C0,
  23067. dalarabic: 0x062F,
  23068. dalet: 0x05D3,
  23069. daletdagesh: 0xFB33,
  23070. daletdageshhebrew: 0xFB33,
  23071. dalethebrew: 0x05D3,
  23072. dalfinalarabic: 0xFEAA,
  23073. dammaarabic: 0x064F,
  23074. dammalowarabic: 0x064F,
  23075. dammatanaltonearabic: 0x064C,
  23076. dammatanarabic: 0x064C,
  23077. danda: 0x0964,
  23078. dargahebrew: 0x05A7,
  23079. dargalefthebrew: 0x05A7,
  23080. dasiapneumatacyrilliccmb: 0x0485,
  23081. dblGrave: 0xF6D3,
  23082. dblanglebracketleft: 0x300A,
  23083. dblanglebracketleftvertical: 0xFE3D,
  23084. dblanglebracketright: 0x300B,
  23085. dblanglebracketrightvertical: 0xFE3E,
  23086. dblarchinvertedbelowcmb: 0x032B,
  23087. dblarrowleft: 0x21D4,
  23088. dblarrowright: 0x21D2,
  23089. dbldanda: 0x0965,
  23090. dblgrave: 0xF6D6,
  23091. dblgravecmb: 0x030F,
  23092. dblintegral: 0x222C,
  23093. dbllowline: 0x2017,
  23094. dbllowlinecmb: 0x0333,
  23095. dbloverlinecmb: 0x033F,
  23096. dblprimemod: 0x02BA,
  23097. dblverticalbar: 0x2016,
  23098. dblverticallineabovecmb: 0x030E,
  23099. dbopomofo: 0x3109,
  23100. dbsquare: 0x33C8,
  23101. dcaron: 0x010F,
  23102. dcedilla: 0x1E11,
  23103. dcircle: 0x24D3,
  23104. dcircumflexbelow: 0x1E13,
  23105. dcroat: 0x0111,
  23106. ddabengali: 0x09A1,
  23107. ddadeva: 0x0921,
  23108. ddagujarati: 0x0AA1,
  23109. ddagurmukhi: 0x0A21,
  23110. ddalarabic: 0x0688,
  23111. ddalfinalarabic: 0xFB89,
  23112. dddhadeva: 0x095C,
  23113. ddhabengali: 0x09A2,
  23114. ddhadeva: 0x0922,
  23115. ddhagujarati: 0x0AA2,
  23116. ddhagurmukhi: 0x0A22,
  23117. ddotaccent: 0x1E0B,
  23118. ddotbelow: 0x1E0D,
  23119. decimalseparatorarabic: 0x066B,
  23120. decimalseparatorpersian: 0x066B,
  23121. decyrillic: 0x0434,
  23122. degree: 0x00B0,
  23123. dehihebrew: 0x05AD,
  23124. dehiragana: 0x3067,
  23125. deicoptic: 0x03EF,
  23126. dekatakana: 0x30C7,
  23127. deleteleft: 0x232B,
  23128. deleteright: 0x2326,
  23129. delta: 0x03B4,
  23130. deltaturned: 0x018D,
  23131. denominatorminusonenumeratorbengali: 0x09F8,
  23132. dezh: 0x02A4,
  23133. dhabengali: 0x09A7,
  23134. dhadeva: 0x0927,
  23135. dhagujarati: 0x0AA7,
  23136. dhagurmukhi: 0x0A27,
  23137. dhook: 0x0257,
  23138. dialytikatonos: 0x0385,
  23139. dialytikatonoscmb: 0x0344,
  23140. diamond: 0x2666,
  23141. diamondsuitwhite: 0x2662,
  23142. dieresis: 0x00A8,
  23143. dieresisacute: 0xF6D7,
  23144. dieresisbelowcmb: 0x0324,
  23145. dieresiscmb: 0x0308,
  23146. dieresisgrave: 0xF6D8,
  23147. dieresistonos: 0x0385,
  23148. dihiragana: 0x3062,
  23149. dikatakana: 0x30C2,
  23150. dittomark: 0x3003,
  23151. divide: 0x00F7,
  23152. divides: 0x2223,
  23153. divisionslash: 0x2215,
  23154. djecyrillic: 0x0452,
  23155. dkshade: 0x2593,
  23156. dlinebelow: 0x1E0F,
  23157. dlsquare: 0x3397,
  23158. dmacron: 0x0111,
  23159. dmonospace: 0xFF44,
  23160. dnblock: 0x2584,
  23161. dochadathai: 0x0E0E,
  23162. dodekthai: 0x0E14,
  23163. dohiragana: 0x3069,
  23164. dokatakana: 0x30C9,
  23165. dollar: 0x0024,
  23166. dollarinferior: 0xF6E3,
  23167. dollarmonospace: 0xFF04,
  23168. dollaroldstyle: 0xF724,
  23169. dollarsmall: 0xFE69,
  23170. dollarsuperior: 0xF6E4,
  23171. dong: 0x20AB,
  23172. dorusquare: 0x3326,
  23173. dotaccent: 0x02D9,
  23174. dotaccentcmb: 0x0307,
  23175. dotbelowcmb: 0x0323,
  23176. dotbelowcomb: 0x0323,
  23177. dotkatakana: 0x30FB,
  23178. dotlessi: 0x0131,
  23179. dotlessj: 0xF6BE,
  23180. dotlessjstrokehook: 0x0284,
  23181. dotmath: 0x22C5,
  23182. dottedcircle: 0x25CC,
  23183. doubleyodpatah: 0xFB1F,
  23184. doubleyodpatahhebrew: 0xFB1F,
  23185. downtackbelowcmb: 0x031E,
  23186. downtackmod: 0x02D5,
  23187. dparen: 0x249F,
  23188. dsuperior: 0xF6EB,
  23189. dtail: 0x0256,
  23190. dtopbar: 0x018C,
  23191. duhiragana: 0x3065,
  23192. dukatakana: 0x30C5,
  23193. dz: 0x01F3,
  23194. dzaltone: 0x02A3,
  23195. dzcaron: 0x01C6,
  23196. dzcurl: 0x02A5,
  23197. dzeabkhasiancyrillic: 0x04E1,
  23198. dzecyrillic: 0x0455,
  23199. dzhecyrillic: 0x045F,
  23200. e: 0x0065,
  23201. eacute: 0x00E9,
  23202. earth: 0x2641,
  23203. ebengali: 0x098F,
  23204. ebopomofo: 0x311C,
  23205. ebreve: 0x0115,
  23206. ecandradeva: 0x090D,
  23207. ecandragujarati: 0x0A8D,
  23208. ecandravowelsigndeva: 0x0945,
  23209. ecandravowelsigngujarati: 0x0AC5,
  23210. ecaron: 0x011B,
  23211. ecedillabreve: 0x1E1D,
  23212. echarmenian: 0x0565,
  23213. echyiwnarmenian: 0x0587,
  23214. ecircle: 0x24D4,
  23215. ecircumflex: 0x00EA,
  23216. ecircumflexacute: 0x1EBF,
  23217. ecircumflexbelow: 0x1E19,
  23218. ecircumflexdotbelow: 0x1EC7,
  23219. ecircumflexgrave: 0x1EC1,
  23220. ecircumflexhookabove: 0x1EC3,
  23221. ecircumflextilde: 0x1EC5,
  23222. ecyrillic: 0x0454,
  23223. edblgrave: 0x0205,
  23224. edeva: 0x090F,
  23225. edieresis: 0x00EB,
  23226. edot: 0x0117,
  23227. edotaccent: 0x0117,
  23228. edotbelow: 0x1EB9,
  23229. eegurmukhi: 0x0A0F,
  23230. eematragurmukhi: 0x0A47,
  23231. efcyrillic: 0x0444,
  23232. egrave: 0x00E8,
  23233. egujarati: 0x0A8F,
  23234. eharmenian: 0x0567,
  23235. ehbopomofo: 0x311D,
  23236. ehiragana: 0x3048,
  23237. ehookabove: 0x1EBB,
  23238. eibopomofo: 0x311F,
  23239. eight: 0x0038,
  23240. eightarabic: 0x0668,
  23241. eightbengali: 0x09EE,
  23242. eightcircle: 0x2467,
  23243. eightcircleinversesansserif: 0x2791,
  23244. eightdeva: 0x096E,
  23245. eighteencircle: 0x2471,
  23246. eighteenparen: 0x2485,
  23247. eighteenperiod: 0x2499,
  23248. eightgujarati: 0x0AEE,
  23249. eightgurmukhi: 0x0A6E,
  23250. eighthackarabic: 0x0668,
  23251. eighthangzhou: 0x3028,
  23252. eighthnotebeamed: 0x266B,
  23253. eightideographicparen: 0x3227,
  23254. eightinferior: 0x2088,
  23255. eightmonospace: 0xFF18,
  23256. eightoldstyle: 0xF738,
  23257. eightparen: 0x247B,
  23258. eightperiod: 0x248F,
  23259. eightpersian: 0x06F8,
  23260. eightroman: 0x2177,
  23261. eightsuperior: 0x2078,
  23262. eightthai: 0x0E58,
  23263. einvertedbreve: 0x0207,
  23264. eiotifiedcyrillic: 0x0465,
  23265. ekatakana: 0x30A8,
  23266. ekatakanahalfwidth: 0xFF74,
  23267. ekonkargurmukhi: 0x0A74,
  23268. ekorean: 0x3154,
  23269. elcyrillic: 0x043B,
  23270. element: 0x2208,
  23271. elevencircle: 0x246A,
  23272. elevenparen: 0x247E,
  23273. elevenperiod: 0x2492,
  23274. elevenroman: 0x217A,
  23275. ellipsis: 0x2026,
  23276. ellipsisvertical: 0x22EE,
  23277. emacron: 0x0113,
  23278. emacronacute: 0x1E17,
  23279. emacrongrave: 0x1E15,
  23280. emcyrillic: 0x043C,
  23281. emdash: 0x2014,
  23282. emdashvertical: 0xFE31,
  23283. emonospace: 0xFF45,
  23284. emphasismarkarmenian: 0x055B,
  23285. emptyset: 0x2205,
  23286. enbopomofo: 0x3123,
  23287. encyrillic: 0x043D,
  23288. endash: 0x2013,
  23289. endashvertical: 0xFE32,
  23290. endescendercyrillic: 0x04A3,
  23291. eng: 0x014B,
  23292. engbopomofo: 0x3125,
  23293. enghecyrillic: 0x04A5,
  23294. enhookcyrillic: 0x04C8,
  23295. enspace: 0x2002,
  23296. eogonek: 0x0119,
  23297. eokorean: 0x3153,
  23298. eopen: 0x025B,
  23299. eopenclosed: 0x029A,
  23300. eopenreversed: 0x025C,
  23301. eopenreversedclosed: 0x025E,
  23302. eopenreversedhook: 0x025D,
  23303. eparen: 0x24A0,
  23304. epsilon: 0x03B5,
  23305. epsilontonos: 0x03AD,
  23306. equal: 0x003D,
  23307. equalmonospace: 0xFF1D,
  23308. equalsmall: 0xFE66,
  23309. equalsuperior: 0x207C,
  23310. equivalence: 0x2261,
  23311. erbopomofo: 0x3126,
  23312. ercyrillic: 0x0440,
  23313. ereversed: 0x0258,
  23314. ereversedcyrillic: 0x044D,
  23315. escyrillic: 0x0441,
  23316. esdescendercyrillic: 0x04AB,
  23317. esh: 0x0283,
  23318. eshcurl: 0x0286,
  23319. eshortdeva: 0x090E,
  23320. eshortvowelsigndeva: 0x0946,
  23321. eshreversedloop: 0x01AA,
  23322. eshsquatreversed: 0x0285,
  23323. esmallhiragana: 0x3047,
  23324. esmallkatakana: 0x30A7,
  23325. esmallkatakanahalfwidth: 0xFF6A,
  23326. estimated: 0x212E,
  23327. esuperior: 0xF6EC,
  23328. eta: 0x03B7,
  23329. etarmenian: 0x0568,
  23330. etatonos: 0x03AE,
  23331. eth: 0x00F0,
  23332. etilde: 0x1EBD,
  23333. etildebelow: 0x1E1B,
  23334. etnahtafoukhhebrew: 0x0591,
  23335. etnahtafoukhlefthebrew: 0x0591,
  23336. etnahtahebrew: 0x0591,
  23337. etnahtalefthebrew: 0x0591,
  23338. eturned: 0x01DD,
  23339. eukorean: 0x3161,
  23340. euro: 0x20AC,
  23341. evowelsignbengali: 0x09C7,
  23342. evowelsigndeva: 0x0947,
  23343. evowelsigngujarati: 0x0AC7,
  23344. exclam: 0x0021,
  23345. exclamarmenian: 0x055C,
  23346. exclamdbl: 0x203C,
  23347. exclamdown: 0x00A1,
  23348. exclamdownsmall: 0xF7A1,
  23349. exclammonospace: 0xFF01,
  23350. exclamsmall: 0xF721,
  23351. existential: 0x2203,
  23352. ezh: 0x0292,
  23353. ezhcaron: 0x01EF,
  23354. ezhcurl: 0x0293,
  23355. ezhreversed: 0x01B9,
  23356. ezhtail: 0x01BA,
  23357. f: 0x0066,
  23358. fadeva: 0x095E,
  23359. fagurmukhi: 0x0A5E,
  23360. fahrenheit: 0x2109,
  23361. fathaarabic: 0x064E,
  23362. fathalowarabic: 0x064E,
  23363. fathatanarabic: 0x064B,
  23364. fbopomofo: 0x3108,
  23365. fcircle: 0x24D5,
  23366. fdotaccent: 0x1E1F,
  23367. feharabic: 0x0641,
  23368. feharmenian: 0x0586,
  23369. fehfinalarabic: 0xFED2,
  23370. fehinitialarabic: 0xFED3,
  23371. fehmedialarabic: 0xFED4,
  23372. feicoptic: 0x03E5,
  23373. female: 0x2640,
  23374. ff: 0xFB00,
  23375. ffi: 0xFB03,
  23376. ffl: 0xFB04,
  23377. fi: 0xFB01,
  23378. fifteencircle: 0x246E,
  23379. fifteenparen: 0x2482,
  23380. fifteenperiod: 0x2496,
  23381. figuredash: 0x2012,
  23382. filledbox: 0x25A0,
  23383. filledrect: 0x25AC,
  23384. finalkaf: 0x05DA,
  23385. finalkafdagesh: 0xFB3A,
  23386. finalkafdageshhebrew: 0xFB3A,
  23387. finalkafhebrew: 0x05DA,
  23388. finalmem: 0x05DD,
  23389. finalmemhebrew: 0x05DD,
  23390. finalnun: 0x05DF,
  23391. finalnunhebrew: 0x05DF,
  23392. finalpe: 0x05E3,
  23393. finalpehebrew: 0x05E3,
  23394. finaltsadi: 0x05E5,
  23395. finaltsadihebrew: 0x05E5,
  23396. firsttonechinese: 0x02C9,
  23397. fisheye: 0x25C9,
  23398. fitacyrillic: 0x0473,
  23399. five: 0x0035,
  23400. fivearabic: 0x0665,
  23401. fivebengali: 0x09EB,
  23402. fivecircle: 0x2464,
  23403. fivecircleinversesansserif: 0x278E,
  23404. fivedeva: 0x096B,
  23405. fiveeighths: 0x215D,
  23406. fivegujarati: 0x0AEB,
  23407. fivegurmukhi: 0x0A6B,
  23408. fivehackarabic: 0x0665,
  23409. fivehangzhou: 0x3025,
  23410. fiveideographicparen: 0x3224,
  23411. fiveinferior: 0x2085,
  23412. fivemonospace: 0xFF15,
  23413. fiveoldstyle: 0xF735,
  23414. fiveparen: 0x2478,
  23415. fiveperiod: 0x248C,
  23416. fivepersian: 0x06F5,
  23417. fiveroman: 0x2174,
  23418. fivesuperior: 0x2075,
  23419. fivethai: 0x0E55,
  23420. fl: 0xFB02,
  23421. florin: 0x0192,
  23422. fmonospace: 0xFF46,
  23423. fmsquare: 0x3399,
  23424. fofanthai: 0x0E1F,
  23425. fofathai: 0x0E1D,
  23426. fongmanthai: 0x0E4F,
  23427. forall: 0x2200,
  23428. four: 0x0034,
  23429. fourarabic: 0x0664,
  23430. fourbengali: 0x09EA,
  23431. fourcircle: 0x2463,
  23432. fourcircleinversesansserif: 0x278D,
  23433. fourdeva: 0x096A,
  23434. fourgujarati: 0x0AEA,
  23435. fourgurmukhi: 0x0A6A,
  23436. fourhackarabic: 0x0664,
  23437. fourhangzhou: 0x3024,
  23438. fourideographicparen: 0x3223,
  23439. fourinferior: 0x2084,
  23440. fourmonospace: 0xFF14,
  23441. fournumeratorbengali: 0x09F7,
  23442. fouroldstyle: 0xF734,
  23443. fourparen: 0x2477,
  23444. fourperiod: 0x248B,
  23445. fourpersian: 0x06F4,
  23446. fourroman: 0x2173,
  23447. foursuperior: 0x2074,
  23448. fourteencircle: 0x246D,
  23449. fourteenparen: 0x2481,
  23450. fourteenperiod: 0x2495,
  23451. fourthai: 0x0E54,
  23452. fourthtonechinese: 0x02CB,
  23453. fparen: 0x24A1,
  23454. fraction: 0x2044,
  23455. franc: 0x20A3,
  23456. g: 0x0067,
  23457. gabengali: 0x0997,
  23458. gacute: 0x01F5,
  23459. gadeva: 0x0917,
  23460. gafarabic: 0x06AF,
  23461. gaffinalarabic: 0xFB93,
  23462. gafinitialarabic: 0xFB94,
  23463. gafmedialarabic: 0xFB95,
  23464. gagujarati: 0x0A97,
  23465. gagurmukhi: 0x0A17,
  23466. gahiragana: 0x304C,
  23467. gakatakana: 0x30AC,
  23468. gamma: 0x03B3,
  23469. gammalatinsmall: 0x0263,
  23470. gammasuperior: 0x02E0,
  23471. gangiacoptic: 0x03EB,
  23472. gbopomofo: 0x310D,
  23473. gbreve: 0x011F,
  23474. gcaron: 0x01E7,
  23475. gcedilla: 0x0123,
  23476. gcircle: 0x24D6,
  23477. gcircumflex: 0x011D,
  23478. gcommaaccent: 0x0123,
  23479. gdot: 0x0121,
  23480. gdotaccent: 0x0121,
  23481. gecyrillic: 0x0433,
  23482. gehiragana: 0x3052,
  23483. gekatakana: 0x30B2,
  23484. geometricallyequal: 0x2251,
  23485. gereshaccenthebrew: 0x059C,
  23486. gereshhebrew: 0x05F3,
  23487. gereshmuqdamhebrew: 0x059D,
  23488. germandbls: 0x00DF,
  23489. gershayimaccenthebrew: 0x059E,
  23490. gershayimhebrew: 0x05F4,
  23491. getamark: 0x3013,
  23492. ghabengali: 0x0998,
  23493. ghadarmenian: 0x0572,
  23494. ghadeva: 0x0918,
  23495. ghagujarati: 0x0A98,
  23496. ghagurmukhi: 0x0A18,
  23497. ghainarabic: 0x063A,
  23498. ghainfinalarabic: 0xFECE,
  23499. ghaininitialarabic: 0xFECF,
  23500. ghainmedialarabic: 0xFED0,
  23501. ghemiddlehookcyrillic: 0x0495,
  23502. ghestrokecyrillic: 0x0493,
  23503. gheupturncyrillic: 0x0491,
  23504. ghhadeva: 0x095A,
  23505. ghhagurmukhi: 0x0A5A,
  23506. ghook: 0x0260,
  23507. ghzsquare: 0x3393,
  23508. gihiragana: 0x304E,
  23509. gikatakana: 0x30AE,
  23510. gimarmenian: 0x0563,
  23511. gimel: 0x05D2,
  23512. gimeldagesh: 0xFB32,
  23513. gimeldageshhebrew: 0xFB32,
  23514. gimelhebrew: 0x05D2,
  23515. gjecyrillic: 0x0453,
  23516. glottalinvertedstroke: 0x01BE,
  23517. glottalstop: 0x0294,
  23518. glottalstopinverted: 0x0296,
  23519. glottalstopmod: 0x02C0,
  23520. glottalstopreversed: 0x0295,
  23521. glottalstopreversedmod: 0x02C1,
  23522. glottalstopreversedsuperior: 0x02E4,
  23523. glottalstopstroke: 0x02A1,
  23524. glottalstopstrokereversed: 0x02A2,
  23525. gmacron: 0x1E21,
  23526. gmonospace: 0xFF47,
  23527. gohiragana: 0x3054,
  23528. gokatakana: 0x30B4,
  23529. gparen: 0x24A2,
  23530. gpasquare: 0x33AC,
  23531. gradient: 0x2207,
  23532. grave: 0x0060,
  23533. gravebelowcmb: 0x0316,
  23534. gravecmb: 0x0300,
  23535. gravecomb: 0x0300,
  23536. gravedeva: 0x0953,
  23537. gravelowmod: 0x02CE,
  23538. gravemonospace: 0xFF40,
  23539. gravetonecmb: 0x0340,
  23540. greater: 0x003E,
  23541. greaterequal: 0x2265,
  23542. greaterequalorless: 0x22DB,
  23543. greatermonospace: 0xFF1E,
  23544. greaterorequivalent: 0x2273,
  23545. greaterorless: 0x2277,
  23546. greateroverequal: 0x2267,
  23547. greatersmall: 0xFE65,
  23548. gscript: 0x0261,
  23549. gstroke: 0x01E5,
  23550. guhiragana: 0x3050,
  23551. guillemotleft: 0x00AB,
  23552. guillemotright: 0x00BB,
  23553. guilsinglleft: 0x2039,
  23554. guilsinglright: 0x203A,
  23555. gukatakana: 0x30B0,
  23556. guramusquare: 0x3318,
  23557. gysquare: 0x33C9,
  23558. h: 0x0068,
  23559. haabkhasiancyrillic: 0x04A9,
  23560. haaltonearabic: 0x06C1,
  23561. habengali: 0x09B9,
  23562. hadescendercyrillic: 0x04B3,
  23563. hadeva: 0x0939,
  23564. hagujarati: 0x0AB9,
  23565. hagurmukhi: 0x0A39,
  23566. haharabic: 0x062D,
  23567. hahfinalarabic: 0xFEA2,
  23568. hahinitialarabic: 0xFEA3,
  23569. hahiragana: 0x306F,
  23570. hahmedialarabic: 0xFEA4,
  23571. haitusquare: 0x332A,
  23572. hakatakana: 0x30CF,
  23573. hakatakanahalfwidth: 0xFF8A,
  23574. halantgurmukhi: 0x0A4D,
  23575. hamzaarabic: 0x0621,
  23576. hamzalowarabic: 0x0621,
  23577. hangulfiller: 0x3164,
  23578. hardsigncyrillic: 0x044A,
  23579. harpoonleftbarbup: 0x21BC,
  23580. harpoonrightbarbup: 0x21C0,
  23581. hasquare: 0x33CA,
  23582. hatafpatah: 0x05B2,
  23583. hatafpatah16: 0x05B2,
  23584. hatafpatah23: 0x05B2,
  23585. hatafpatah2f: 0x05B2,
  23586. hatafpatahhebrew: 0x05B2,
  23587. hatafpatahnarrowhebrew: 0x05B2,
  23588. hatafpatahquarterhebrew: 0x05B2,
  23589. hatafpatahwidehebrew: 0x05B2,
  23590. hatafqamats: 0x05B3,
  23591. hatafqamats1b: 0x05B3,
  23592. hatafqamats28: 0x05B3,
  23593. hatafqamats34: 0x05B3,
  23594. hatafqamatshebrew: 0x05B3,
  23595. hatafqamatsnarrowhebrew: 0x05B3,
  23596. hatafqamatsquarterhebrew: 0x05B3,
  23597. hatafqamatswidehebrew: 0x05B3,
  23598. hatafsegol: 0x05B1,
  23599. hatafsegol17: 0x05B1,
  23600. hatafsegol24: 0x05B1,
  23601. hatafsegol30: 0x05B1,
  23602. hatafsegolhebrew: 0x05B1,
  23603. hatafsegolnarrowhebrew: 0x05B1,
  23604. hatafsegolquarterhebrew: 0x05B1,
  23605. hatafsegolwidehebrew: 0x05B1,
  23606. hbar: 0x0127,
  23607. hbopomofo: 0x310F,
  23608. hbrevebelow: 0x1E2B,
  23609. hcedilla: 0x1E29,
  23610. hcircle: 0x24D7,
  23611. hcircumflex: 0x0125,
  23612. hdieresis: 0x1E27,
  23613. hdotaccent: 0x1E23,
  23614. hdotbelow: 0x1E25,
  23615. he: 0x05D4,
  23616. heart: 0x2665,
  23617. heartsuitblack: 0x2665,
  23618. heartsuitwhite: 0x2661,
  23619. hedagesh: 0xFB34,
  23620. hedageshhebrew: 0xFB34,
  23621. hehaltonearabic: 0x06C1,
  23622. heharabic: 0x0647,
  23623. hehebrew: 0x05D4,
  23624. hehfinalaltonearabic: 0xFBA7,
  23625. hehfinalalttwoarabic: 0xFEEA,
  23626. hehfinalarabic: 0xFEEA,
  23627. hehhamzaabovefinalarabic: 0xFBA5,
  23628. hehhamzaaboveisolatedarabic: 0xFBA4,
  23629. hehinitialaltonearabic: 0xFBA8,
  23630. hehinitialarabic: 0xFEEB,
  23631. hehiragana: 0x3078,
  23632. hehmedialaltonearabic: 0xFBA9,
  23633. hehmedialarabic: 0xFEEC,
  23634. heiseierasquare: 0x337B,
  23635. hekatakana: 0x30D8,
  23636. hekatakanahalfwidth: 0xFF8D,
  23637. hekutaarusquare: 0x3336,
  23638. henghook: 0x0267,
  23639. herutusquare: 0x3339,
  23640. het: 0x05D7,
  23641. hethebrew: 0x05D7,
  23642. hhook: 0x0266,
  23643. hhooksuperior: 0x02B1,
  23644. hieuhacirclekorean: 0x327B,
  23645. hieuhaparenkorean: 0x321B,
  23646. hieuhcirclekorean: 0x326D,
  23647. hieuhkorean: 0x314E,
  23648. hieuhparenkorean: 0x320D,
  23649. hihiragana: 0x3072,
  23650. hikatakana: 0x30D2,
  23651. hikatakanahalfwidth: 0xFF8B,
  23652. hiriq: 0x05B4,
  23653. hiriq14: 0x05B4,
  23654. hiriq21: 0x05B4,
  23655. hiriq2d: 0x05B4,
  23656. hiriqhebrew: 0x05B4,
  23657. hiriqnarrowhebrew: 0x05B4,
  23658. hiriqquarterhebrew: 0x05B4,
  23659. hiriqwidehebrew: 0x05B4,
  23660. hlinebelow: 0x1E96,
  23661. hmonospace: 0xFF48,
  23662. hoarmenian: 0x0570,
  23663. hohipthai: 0x0E2B,
  23664. hohiragana: 0x307B,
  23665. hokatakana: 0x30DB,
  23666. hokatakanahalfwidth: 0xFF8E,
  23667. holam: 0x05B9,
  23668. holam19: 0x05B9,
  23669. holam26: 0x05B9,
  23670. holam32: 0x05B9,
  23671. holamhebrew: 0x05B9,
  23672. holamnarrowhebrew: 0x05B9,
  23673. holamquarterhebrew: 0x05B9,
  23674. holamwidehebrew: 0x05B9,
  23675. honokhukthai: 0x0E2E,
  23676. hookabovecomb: 0x0309,
  23677. hookcmb: 0x0309,
  23678. hookpalatalizedbelowcmb: 0x0321,
  23679. hookretroflexbelowcmb: 0x0322,
  23680. hoonsquare: 0x3342,
  23681. horicoptic: 0x03E9,
  23682. horizontalbar: 0x2015,
  23683. horncmb: 0x031B,
  23684. hotsprings: 0x2668,
  23685. house: 0x2302,
  23686. hparen: 0x24A3,
  23687. hsuperior: 0x02B0,
  23688. hturned: 0x0265,
  23689. huhiragana: 0x3075,
  23690. huiitosquare: 0x3333,
  23691. hukatakana: 0x30D5,
  23692. hukatakanahalfwidth: 0xFF8C,
  23693. hungarumlaut: 0x02DD,
  23694. hungarumlautcmb: 0x030B,
  23695. hv: 0x0195,
  23696. hyphen: 0x002D,
  23697. hypheninferior: 0xF6E5,
  23698. hyphenmonospace: 0xFF0D,
  23699. hyphensmall: 0xFE63,
  23700. hyphensuperior: 0xF6E6,
  23701. hyphentwo: 0x2010,
  23702. i: 0x0069,
  23703. iacute: 0x00ED,
  23704. iacyrillic: 0x044F,
  23705. ibengali: 0x0987,
  23706. ibopomofo: 0x3127,
  23707. ibreve: 0x012D,
  23708. icaron: 0x01D0,
  23709. icircle: 0x24D8,
  23710. icircumflex: 0x00EE,
  23711. icyrillic: 0x0456,
  23712. idblgrave: 0x0209,
  23713. ideographearthcircle: 0x328F,
  23714. ideographfirecircle: 0x328B,
  23715. ideographicallianceparen: 0x323F,
  23716. ideographiccallparen: 0x323A,
  23717. ideographiccentrecircle: 0x32A5,
  23718. ideographicclose: 0x3006,
  23719. ideographiccomma: 0x3001,
  23720. ideographiccommaleft: 0xFF64,
  23721. ideographiccongratulationparen: 0x3237,
  23722. ideographiccorrectcircle: 0x32A3,
  23723. ideographicearthparen: 0x322F,
  23724. ideographicenterpriseparen: 0x323D,
  23725. ideographicexcellentcircle: 0x329D,
  23726. ideographicfestivalparen: 0x3240,
  23727. ideographicfinancialcircle: 0x3296,
  23728. ideographicfinancialparen: 0x3236,
  23729. ideographicfireparen: 0x322B,
  23730. ideographichaveparen: 0x3232,
  23731. ideographichighcircle: 0x32A4,
  23732. ideographiciterationmark: 0x3005,
  23733. ideographiclaborcircle: 0x3298,
  23734. ideographiclaborparen: 0x3238,
  23735. ideographicleftcircle: 0x32A7,
  23736. ideographiclowcircle: 0x32A6,
  23737. ideographicmedicinecircle: 0x32A9,
  23738. ideographicmetalparen: 0x322E,
  23739. ideographicmoonparen: 0x322A,
  23740. ideographicnameparen: 0x3234,
  23741. ideographicperiod: 0x3002,
  23742. ideographicprintcircle: 0x329E,
  23743. ideographicreachparen: 0x3243,
  23744. ideographicrepresentparen: 0x3239,
  23745. ideographicresourceparen: 0x323E,
  23746. ideographicrightcircle: 0x32A8,
  23747. ideographicsecretcircle: 0x3299,
  23748. ideographicselfparen: 0x3242,
  23749. ideographicsocietyparen: 0x3233,
  23750. ideographicspace: 0x3000,
  23751. ideographicspecialparen: 0x3235,
  23752. ideographicstockparen: 0x3231,
  23753. ideographicstudyparen: 0x323B,
  23754. ideographicsunparen: 0x3230,
  23755. ideographicsuperviseparen: 0x323C,
  23756. ideographicwaterparen: 0x322C,
  23757. ideographicwoodparen: 0x322D,
  23758. ideographiczero: 0x3007,
  23759. ideographmetalcircle: 0x328E,
  23760. ideographmooncircle: 0x328A,
  23761. ideographnamecircle: 0x3294,
  23762. ideographsuncircle: 0x3290,
  23763. ideographwatercircle: 0x328C,
  23764. ideographwoodcircle: 0x328D,
  23765. ideva: 0x0907,
  23766. idieresis: 0x00EF,
  23767. idieresisacute: 0x1E2F,
  23768. idieresiscyrillic: 0x04E5,
  23769. idotbelow: 0x1ECB,
  23770. iebrevecyrillic: 0x04D7,
  23771. iecyrillic: 0x0435,
  23772. ieungacirclekorean: 0x3275,
  23773. ieungaparenkorean: 0x3215,
  23774. ieungcirclekorean: 0x3267,
  23775. ieungkorean: 0x3147,
  23776. ieungparenkorean: 0x3207,
  23777. igrave: 0x00EC,
  23778. igujarati: 0x0A87,
  23779. igurmukhi: 0x0A07,
  23780. ihiragana: 0x3044,
  23781. ihookabove: 0x1EC9,
  23782. iibengali: 0x0988,
  23783. iicyrillic: 0x0438,
  23784. iideva: 0x0908,
  23785. iigujarati: 0x0A88,
  23786. iigurmukhi: 0x0A08,
  23787. iimatragurmukhi: 0x0A40,
  23788. iinvertedbreve: 0x020B,
  23789. iishortcyrillic: 0x0439,
  23790. iivowelsignbengali: 0x09C0,
  23791. iivowelsigndeva: 0x0940,
  23792. iivowelsigngujarati: 0x0AC0,
  23793. ij: 0x0133,
  23794. ikatakana: 0x30A4,
  23795. ikatakanahalfwidth: 0xFF72,
  23796. ikorean: 0x3163,
  23797. ilde: 0x02DC,
  23798. iluyhebrew: 0x05AC,
  23799. imacron: 0x012B,
  23800. imacroncyrillic: 0x04E3,
  23801. imageorapproximatelyequal: 0x2253,
  23802. imatragurmukhi: 0x0A3F,
  23803. imonospace: 0xFF49,
  23804. increment: 0x2206,
  23805. infinity: 0x221E,
  23806. iniarmenian: 0x056B,
  23807. integral: 0x222B,
  23808. integralbottom: 0x2321,
  23809. integralbt: 0x2321,
  23810. integralex: 0xF8F5,
  23811. integraltop: 0x2320,
  23812. integraltp: 0x2320,
  23813. intersection: 0x2229,
  23814. intisquare: 0x3305,
  23815. invbullet: 0x25D8,
  23816. invcircle: 0x25D9,
  23817. invsmileface: 0x263B,
  23818. iocyrillic: 0x0451,
  23819. iogonek: 0x012F,
  23820. iota: 0x03B9,
  23821. iotadieresis: 0x03CA,
  23822. iotadieresistonos: 0x0390,
  23823. iotalatin: 0x0269,
  23824. iotatonos: 0x03AF,
  23825. iparen: 0x24A4,
  23826. irigurmukhi: 0x0A72,
  23827. ismallhiragana: 0x3043,
  23828. ismallkatakana: 0x30A3,
  23829. ismallkatakanahalfwidth: 0xFF68,
  23830. issharbengali: 0x09FA,
  23831. istroke: 0x0268,
  23832. isuperior: 0xF6ED,
  23833. iterationhiragana: 0x309D,
  23834. iterationkatakana: 0x30FD,
  23835. itilde: 0x0129,
  23836. itildebelow: 0x1E2D,
  23837. iubopomofo: 0x3129,
  23838. iucyrillic: 0x044E,
  23839. ivowelsignbengali: 0x09BF,
  23840. ivowelsigndeva: 0x093F,
  23841. ivowelsigngujarati: 0x0ABF,
  23842. izhitsacyrillic: 0x0475,
  23843. izhitsadblgravecyrillic: 0x0477,
  23844. j: 0x006A,
  23845. jaarmenian: 0x0571,
  23846. jabengali: 0x099C,
  23847. jadeva: 0x091C,
  23848. jagujarati: 0x0A9C,
  23849. jagurmukhi: 0x0A1C,
  23850. jbopomofo: 0x3110,
  23851. jcaron: 0x01F0,
  23852. jcircle: 0x24D9,
  23853. jcircumflex: 0x0135,
  23854. jcrossedtail: 0x029D,
  23855. jdotlessstroke: 0x025F,
  23856. jecyrillic: 0x0458,
  23857. jeemarabic: 0x062C,
  23858. jeemfinalarabic: 0xFE9E,
  23859. jeeminitialarabic: 0xFE9F,
  23860. jeemmedialarabic: 0xFEA0,
  23861. jeharabic: 0x0698,
  23862. jehfinalarabic: 0xFB8B,
  23863. jhabengali: 0x099D,
  23864. jhadeva: 0x091D,
  23865. jhagujarati: 0x0A9D,
  23866. jhagurmukhi: 0x0A1D,
  23867. jheharmenian: 0x057B,
  23868. jis: 0x3004,
  23869. jmonospace: 0xFF4A,
  23870. jparen: 0x24A5,
  23871. jsuperior: 0x02B2,
  23872. k: 0x006B,
  23873. kabashkircyrillic: 0x04A1,
  23874. kabengali: 0x0995,
  23875. kacute: 0x1E31,
  23876. kacyrillic: 0x043A,
  23877. kadescendercyrillic: 0x049B,
  23878. kadeva: 0x0915,
  23879. kaf: 0x05DB,
  23880. kafarabic: 0x0643,
  23881. kafdagesh: 0xFB3B,
  23882. kafdageshhebrew: 0xFB3B,
  23883. kaffinalarabic: 0xFEDA,
  23884. kafhebrew: 0x05DB,
  23885. kafinitialarabic: 0xFEDB,
  23886. kafmedialarabic: 0xFEDC,
  23887. kafrafehebrew: 0xFB4D,
  23888. kagujarati: 0x0A95,
  23889. kagurmukhi: 0x0A15,
  23890. kahiragana: 0x304B,
  23891. kahookcyrillic: 0x04C4,
  23892. kakatakana: 0x30AB,
  23893. kakatakanahalfwidth: 0xFF76,
  23894. kappa: 0x03BA,
  23895. kappasymbolgreek: 0x03F0,
  23896. kapyeounmieumkorean: 0x3171,
  23897. kapyeounphieuphkorean: 0x3184,
  23898. kapyeounpieupkorean: 0x3178,
  23899. kapyeounssangpieupkorean: 0x3179,
  23900. karoriisquare: 0x330D,
  23901. kashidaautoarabic: 0x0640,
  23902. kashidaautonosidebearingarabic: 0x0640,
  23903. kasmallkatakana: 0x30F5,
  23904. kasquare: 0x3384,
  23905. kasraarabic: 0x0650,
  23906. kasratanarabic: 0x064D,
  23907. kastrokecyrillic: 0x049F,
  23908. katahiraprolongmarkhalfwidth: 0xFF70,
  23909. kaverticalstrokecyrillic: 0x049D,
  23910. kbopomofo: 0x310E,
  23911. kcalsquare: 0x3389,
  23912. kcaron: 0x01E9,
  23913. kcedilla: 0x0137,
  23914. kcircle: 0x24DA,
  23915. kcommaaccent: 0x0137,
  23916. kdotbelow: 0x1E33,
  23917. keharmenian: 0x0584,
  23918. kehiragana: 0x3051,
  23919. kekatakana: 0x30B1,
  23920. kekatakanahalfwidth: 0xFF79,
  23921. kenarmenian: 0x056F,
  23922. kesmallkatakana: 0x30F6,
  23923. kgreenlandic: 0x0138,
  23924. khabengali: 0x0996,
  23925. khacyrillic: 0x0445,
  23926. khadeva: 0x0916,
  23927. khagujarati: 0x0A96,
  23928. khagurmukhi: 0x0A16,
  23929. khaharabic: 0x062E,
  23930. khahfinalarabic: 0xFEA6,
  23931. khahinitialarabic: 0xFEA7,
  23932. khahmedialarabic: 0xFEA8,
  23933. kheicoptic: 0x03E7,
  23934. khhadeva: 0x0959,
  23935. khhagurmukhi: 0x0A59,
  23936. khieukhacirclekorean: 0x3278,
  23937. khieukhaparenkorean: 0x3218,
  23938. khieukhcirclekorean: 0x326A,
  23939. khieukhkorean: 0x314B,
  23940. khieukhparenkorean: 0x320A,
  23941. khokhaithai: 0x0E02,
  23942. khokhonthai: 0x0E05,
  23943. khokhuatthai: 0x0E03,
  23944. khokhwaithai: 0x0E04,
  23945. khomutthai: 0x0E5B,
  23946. khook: 0x0199,
  23947. khorakhangthai: 0x0E06,
  23948. khzsquare: 0x3391,
  23949. kihiragana: 0x304D,
  23950. kikatakana: 0x30AD,
  23951. kikatakanahalfwidth: 0xFF77,
  23952. kiroguramusquare: 0x3315,
  23953. kiromeetorusquare: 0x3316,
  23954. kirosquare: 0x3314,
  23955. kiyeokacirclekorean: 0x326E,
  23956. kiyeokaparenkorean: 0x320E,
  23957. kiyeokcirclekorean: 0x3260,
  23958. kiyeokkorean: 0x3131,
  23959. kiyeokparenkorean: 0x3200,
  23960. kiyeoksioskorean: 0x3133,
  23961. kjecyrillic: 0x045C,
  23962. klinebelow: 0x1E35,
  23963. klsquare: 0x3398,
  23964. kmcubedsquare: 0x33A6,
  23965. kmonospace: 0xFF4B,
  23966. kmsquaredsquare: 0x33A2,
  23967. kohiragana: 0x3053,
  23968. kohmsquare: 0x33C0,
  23969. kokaithai: 0x0E01,
  23970. kokatakana: 0x30B3,
  23971. kokatakanahalfwidth: 0xFF7A,
  23972. kooposquare: 0x331E,
  23973. koppacyrillic: 0x0481,
  23974. koreanstandardsymbol: 0x327F,
  23975. koroniscmb: 0x0343,
  23976. kparen: 0x24A6,
  23977. kpasquare: 0x33AA,
  23978. ksicyrillic: 0x046F,
  23979. ktsquare: 0x33CF,
  23980. kturned: 0x029E,
  23981. kuhiragana: 0x304F,
  23982. kukatakana: 0x30AF,
  23983. kukatakanahalfwidth: 0xFF78,
  23984. kvsquare: 0x33B8,
  23985. kwsquare: 0x33BE,
  23986. l: 0x006C,
  23987. labengali: 0x09B2,
  23988. lacute: 0x013A,
  23989. ladeva: 0x0932,
  23990. lagujarati: 0x0AB2,
  23991. lagurmukhi: 0x0A32,
  23992. lakkhangyaothai: 0x0E45,
  23993. lamaleffinalarabic: 0xFEFC,
  23994. lamalefhamzaabovefinalarabic: 0xFEF8,
  23995. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  23996. lamalefhamzabelowfinalarabic: 0xFEFA,
  23997. lamalefhamzabelowisolatedarabic: 0xFEF9,
  23998. lamalefisolatedarabic: 0xFEFB,
  23999. lamalefmaddaabovefinalarabic: 0xFEF6,
  24000. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  24001. lamarabic: 0x0644,
  24002. lambda: 0x03BB,
  24003. lambdastroke: 0x019B,
  24004. lamed: 0x05DC,
  24005. lameddagesh: 0xFB3C,
  24006. lameddageshhebrew: 0xFB3C,
  24007. lamedhebrew: 0x05DC,
  24008. lamfinalarabic: 0xFEDE,
  24009. lamhahinitialarabic: 0xFCCA,
  24010. laminitialarabic: 0xFEDF,
  24011. lamjeeminitialarabic: 0xFCC9,
  24012. lamkhahinitialarabic: 0xFCCB,
  24013. lamlamhehisolatedarabic: 0xFDF2,
  24014. lammedialarabic: 0xFEE0,
  24015. lammeemhahinitialarabic: 0xFD88,
  24016. lammeeminitialarabic: 0xFCCC,
  24017. largecircle: 0x25EF,
  24018. lbar: 0x019A,
  24019. lbelt: 0x026C,
  24020. lbopomofo: 0x310C,
  24021. lcaron: 0x013E,
  24022. lcedilla: 0x013C,
  24023. lcircle: 0x24DB,
  24024. lcircumflexbelow: 0x1E3D,
  24025. lcommaaccent: 0x013C,
  24026. ldot: 0x0140,
  24027. ldotaccent: 0x0140,
  24028. ldotbelow: 0x1E37,
  24029. ldotbelowmacron: 0x1E39,
  24030. leftangleabovecmb: 0x031A,
  24031. lefttackbelowcmb: 0x0318,
  24032. less: 0x003C,
  24033. lessequal: 0x2264,
  24034. lessequalorgreater: 0x22DA,
  24035. lessmonospace: 0xFF1C,
  24036. lessorequivalent: 0x2272,
  24037. lessorgreater: 0x2276,
  24038. lessoverequal: 0x2266,
  24039. lesssmall: 0xFE64,
  24040. lezh: 0x026E,
  24041. lfblock: 0x258C,
  24042. lhookretroflex: 0x026D,
  24043. lira: 0x20A4,
  24044. liwnarmenian: 0x056C,
  24045. lj: 0x01C9,
  24046. ljecyrillic: 0x0459,
  24047. ll: 0xF6C0,
  24048. lladeva: 0x0933,
  24049. llagujarati: 0x0AB3,
  24050. llinebelow: 0x1E3B,
  24051. llladeva: 0x0934,
  24052. llvocalicbengali: 0x09E1,
  24053. llvocalicdeva: 0x0961,
  24054. llvocalicvowelsignbengali: 0x09E3,
  24055. llvocalicvowelsigndeva: 0x0963,
  24056. lmiddletilde: 0x026B,
  24057. lmonospace: 0xFF4C,
  24058. lmsquare: 0x33D0,
  24059. lochulathai: 0x0E2C,
  24060. logicaland: 0x2227,
  24061. logicalnot: 0x00AC,
  24062. logicalnotreversed: 0x2310,
  24063. logicalor: 0x2228,
  24064. lolingthai: 0x0E25,
  24065. longs: 0x017F,
  24066. lowlinecenterline: 0xFE4E,
  24067. lowlinecmb: 0x0332,
  24068. lowlinedashed: 0xFE4D,
  24069. lozenge: 0x25CA,
  24070. lparen: 0x24A7,
  24071. lslash: 0x0142,
  24072. lsquare: 0x2113,
  24073. lsuperior: 0xF6EE,
  24074. ltshade: 0x2591,
  24075. luthai: 0x0E26,
  24076. lvocalicbengali: 0x098C,
  24077. lvocalicdeva: 0x090C,
  24078. lvocalicvowelsignbengali: 0x09E2,
  24079. lvocalicvowelsigndeva: 0x0962,
  24080. lxsquare: 0x33D3,
  24081. m: 0x006D,
  24082. mabengali: 0x09AE,
  24083. macron: 0x00AF,
  24084. macronbelowcmb: 0x0331,
  24085. macroncmb: 0x0304,
  24086. macronlowmod: 0x02CD,
  24087. macronmonospace: 0xFFE3,
  24088. macute: 0x1E3F,
  24089. madeva: 0x092E,
  24090. magujarati: 0x0AAE,
  24091. magurmukhi: 0x0A2E,
  24092. mahapakhhebrew: 0x05A4,
  24093. mahapakhlefthebrew: 0x05A4,
  24094. mahiragana: 0x307E,
  24095. maichattawalowleftthai: 0xF895,
  24096. maichattawalowrightthai: 0xF894,
  24097. maichattawathai: 0x0E4B,
  24098. maichattawaupperleftthai: 0xF893,
  24099. maieklowleftthai: 0xF88C,
  24100. maieklowrightthai: 0xF88B,
  24101. maiekthai: 0x0E48,
  24102. maiekupperleftthai: 0xF88A,
  24103. maihanakatleftthai: 0xF884,
  24104. maihanakatthai: 0x0E31,
  24105. maitaikhuleftthai: 0xF889,
  24106. maitaikhuthai: 0x0E47,
  24107. maitholowleftthai: 0xF88F,
  24108. maitholowrightthai: 0xF88E,
  24109. maithothai: 0x0E49,
  24110. maithoupperleftthai: 0xF88D,
  24111. maitrilowleftthai: 0xF892,
  24112. maitrilowrightthai: 0xF891,
  24113. maitrithai: 0x0E4A,
  24114. maitriupperleftthai: 0xF890,
  24115. maiyamokthai: 0x0E46,
  24116. makatakana: 0x30DE,
  24117. makatakanahalfwidth: 0xFF8F,
  24118. male: 0x2642,
  24119. mansyonsquare: 0x3347,
  24120. maqafhebrew: 0x05BE,
  24121. mars: 0x2642,
  24122. masoracirclehebrew: 0x05AF,
  24123. masquare: 0x3383,
  24124. mbopomofo: 0x3107,
  24125. mbsquare: 0x33D4,
  24126. mcircle: 0x24DC,
  24127. mcubedsquare: 0x33A5,
  24128. mdotaccent: 0x1E41,
  24129. mdotbelow: 0x1E43,
  24130. meemarabic: 0x0645,
  24131. meemfinalarabic: 0xFEE2,
  24132. meeminitialarabic: 0xFEE3,
  24133. meemmedialarabic: 0xFEE4,
  24134. meemmeeminitialarabic: 0xFCD1,
  24135. meemmeemisolatedarabic: 0xFC48,
  24136. meetorusquare: 0x334D,
  24137. mehiragana: 0x3081,
  24138. meizierasquare: 0x337E,
  24139. mekatakana: 0x30E1,
  24140. mekatakanahalfwidth: 0xFF92,
  24141. mem: 0x05DE,
  24142. memdagesh: 0xFB3E,
  24143. memdageshhebrew: 0xFB3E,
  24144. memhebrew: 0x05DE,
  24145. menarmenian: 0x0574,
  24146. merkhahebrew: 0x05A5,
  24147. merkhakefulahebrew: 0x05A6,
  24148. merkhakefulalefthebrew: 0x05A6,
  24149. merkhalefthebrew: 0x05A5,
  24150. mhook: 0x0271,
  24151. mhzsquare: 0x3392,
  24152. middledotkatakanahalfwidth: 0xFF65,
  24153. middot: 0x00B7,
  24154. mieumacirclekorean: 0x3272,
  24155. mieumaparenkorean: 0x3212,
  24156. mieumcirclekorean: 0x3264,
  24157. mieumkorean: 0x3141,
  24158. mieumpansioskorean: 0x3170,
  24159. mieumparenkorean: 0x3204,
  24160. mieumpieupkorean: 0x316E,
  24161. mieumsioskorean: 0x316F,
  24162. mihiragana: 0x307F,
  24163. mikatakana: 0x30DF,
  24164. mikatakanahalfwidth: 0xFF90,
  24165. minus: 0x2212,
  24166. minusbelowcmb: 0x0320,
  24167. minuscircle: 0x2296,
  24168. minusmod: 0x02D7,
  24169. minusplus: 0x2213,
  24170. minute: 0x2032,
  24171. miribaarusquare: 0x334A,
  24172. mirisquare: 0x3349,
  24173. mlonglegturned: 0x0270,
  24174. mlsquare: 0x3396,
  24175. mmcubedsquare: 0x33A3,
  24176. mmonospace: 0xFF4D,
  24177. mmsquaredsquare: 0x339F,
  24178. mohiragana: 0x3082,
  24179. mohmsquare: 0x33C1,
  24180. mokatakana: 0x30E2,
  24181. mokatakanahalfwidth: 0xFF93,
  24182. molsquare: 0x33D6,
  24183. momathai: 0x0E21,
  24184. moverssquare: 0x33A7,
  24185. moverssquaredsquare: 0x33A8,
  24186. mparen: 0x24A8,
  24187. mpasquare: 0x33AB,
  24188. mssquare: 0x33B3,
  24189. msuperior: 0xF6EF,
  24190. mturned: 0x026F,
  24191. mu: 0x00B5,
  24192. mu1: 0x00B5,
  24193. muasquare: 0x3382,
  24194. muchgreater: 0x226B,
  24195. muchless: 0x226A,
  24196. mufsquare: 0x338C,
  24197. mugreek: 0x03BC,
  24198. mugsquare: 0x338D,
  24199. muhiragana: 0x3080,
  24200. mukatakana: 0x30E0,
  24201. mukatakanahalfwidth: 0xFF91,
  24202. mulsquare: 0x3395,
  24203. multiply: 0x00D7,
  24204. mumsquare: 0x339B,
  24205. munahhebrew: 0x05A3,
  24206. munahlefthebrew: 0x05A3,
  24207. musicalnote: 0x266A,
  24208. musicalnotedbl: 0x266B,
  24209. musicflatsign: 0x266D,
  24210. musicsharpsign: 0x266F,
  24211. mussquare: 0x33B2,
  24212. muvsquare: 0x33B6,
  24213. muwsquare: 0x33BC,
  24214. mvmegasquare: 0x33B9,
  24215. mvsquare: 0x33B7,
  24216. mwmegasquare: 0x33BF,
  24217. mwsquare: 0x33BD,
  24218. n: 0x006E,
  24219. nabengali: 0x09A8,
  24220. nabla: 0x2207,
  24221. nacute: 0x0144,
  24222. nadeva: 0x0928,
  24223. nagujarati: 0x0AA8,
  24224. nagurmukhi: 0x0A28,
  24225. nahiragana: 0x306A,
  24226. nakatakana: 0x30CA,
  24227. nakatakanahalfwidth: 0xFF85,
  24228. napostrophe: 0x0149,
  24229. nasquare: 0x3381,
  24230. nbopomofo: 0x310B,
  24231. nbspace: 0x00A0,
  24232. ncaron: 0x0148,
  24233. ncedilla: 0x0146,
  24234. ncircle: 0x24DD,
  24235. ncircumflexbelow: 0x1E4B,
  24236. ncommaaccent: 0x0146,
  24237. ndotaccent: 0x1E45,
  24238. ndotbelow: 0x1E47,
  24239. nehiragana: 0x306D,
  24240. nekatakana: 0x30CD,
  24241. nekatakanahalfwidth: 0xFF88,
  24242. newsheqelsign: 0x20AA,
  24243. nfsquare: 0x338B,
  24244. ngabengali: 0x0999,
  24245. ngadeva: 0x0919,
  24246. ngagujarati: 0x0A99,
  24247. ngagurmukhi: 0x0A19,
  24248. ngonguthai: 0x0E07,
  24249. nhiragana: 0x3093,
  24250. nhookleft: 0x0272,
  24251. nhookretroflex: 0x0273,
  24252. nieunacirclekorean: 0x326F,
  24253. nieunaparenkorean: 0x320F,
  24254. nieuncieuckorean: 0x3135,
  24255. nieuncirclekorean: 0x3261,
  24256. nieunhieuhkorean: 0x3136,
  24257. nieunkorean: 0x3134,
  24258. nieunpansioskorean: 0x3168,
  24259. nieunparenkorean: 0x3201,
  24260. nieunsioskorean: 0x3167,
  24261. nieuntikeutkorean: 0x3166,
  24262. nihiragana: 0x306B,
  24263. nikatakana: 0x30CB,
  24264. nikatakanahalfwidth: 0xFF86,
  24265. nikhahitleftthai: 0xF899,
  24266. nikhahitthai: 0x0E4D,
  24267. nine: 0x0039,
  24268. ninearabic: 0x0669,
  24269. ninebengali: 0x09EF,
  24270. ninecircle: 0x2468,
  24271. ninecircleinversesansserif: 0x2792,
  24272. ninedeva: 0x096F,
  24273. ninegujarati: 0x0AEF,
  24274. ninegurmukhi: 0x0A6F,
  24275. ninehackarabic: 0x0669,
  24276. ninehangzhou: 0x3029,
  24277. nineideographicparen: 0x3228,
  24278. nineinferior: 0x2089,
  24279. ninemonospace: 0xFF19,
  24280. nineoldstyle: 0xF739,
  24281. nineparen: 0x247C,
  24282. nineperiod: 0x2490,
  24283. ninepersian: 0x06F9,
  24284. nineroman: 0x2178,
  24285. ninesuperior: 0x2079,
  24286. nineteencircle: 0x2472,
  24287. nineteenparen: 0x2486,
  24288. nineteenperiod: 0x249A,
  24289. ninethai: 0x0E59,
  24290. nj: 0x01CC,
  24291. njecyrillic: 0x045A,
  24292. nkatakana: 0x30F3,
  24293. nkatakanahalfwidth: 0xFF9D,
  24294. nlegrightlong: 0x019E,
  24295. nlinebelow: 0x1E49,
  24296. nmonospace: 0xFF4E,
  24297. nmsquare: 0x339A,
  24298. nnabengali: 0x09A3,
  24299. nnadeva: 0x0923,
  24300. nnagujarati: 0x0AA3,
  24301. nnagurmukhi: 0x0A23,
  24302. nnnadeva: 0x0929,
  24303. nohiragana: 0x306E,
  24304. nokatakana: 0x30CE,
  24305. nokatakanahalfwidth: 0xFF89,
  24306. nonbreakingspace: 0x00A0,
  24307. nonenthai: 0x0E13,
  24308. nonuthai: 0x0E19,
  24309. noonarabic: 0x0646,
  24310. noonfinalarabic: 0xFEE6,
  24311. noonghunnaarabic: 0x06BA,
  24312. noonghunnafinalarabic: 0xFB9F,
  24313. nooninitialarabic: 0xFEE7,
  24314. noonjeeminitialarabic: 0xFCD2,
  24315. noonjeemisolatedarabic: 0xFC4B,
  24316. noonmedialarabic: 0xFEE8,
  24317. noonmeeminitialarabic: 0xFCD5,
  24318. noonmeemisolatedarabic: 0xFC4E,
  24319. noonnoonfinalarabic: 0xFC8D,
  24320. notcontains: 0x220C,
  24321. notelement: 0x2209,
  24322. notelementof: 0x2209,
  24323. notequal: 0x2260,
  24324. notgreater: 0x226F,
  24325. notgreaternorequal: 0x2271,
  24326. notgreaternorless: 0x2279,
  24327. notidentical: 0x2262,
  24328. notless: 0x226E,
  24329. notlessnorequal: 0x2270,
  24330. notparallel: 0x2226,
  24331. notprecedes: 0x2280,
  24332. notsubset: 0x2284,
  24333. notsucceeds: 0x2281,
  24334. notsuperset: 0x2285,
  24335. nowarmenian: 0x0576,
  24336. nparen: 0x24A9,
  24337. nssquare: 0x33B1,
  24338. nsuperior: 0x207F,
  24339. ntilde: 0x00F1,
  24340. nu: 0x03BD,
  24341. nuhiragana: 0x306C,
  24342. nukatakana: 0x30CC,
  24343. nukatakanahalfwidth: 0xFF87,
  24344. nuktabengali: 0x09BC,
  24345. nuktadeva: 0x093C,
  24346. nuktagujarati: 0x0ABC,
  24347. nuktagurmukhi: 0x0A3C,
  24348. numbersign: 0x0023,
  24349. numbersignmonospace: 0xFF03,
  24350. numbersignsmall: 0xFE5F,
  24351. numeralsigngreek: 0x0374,
  24352. numeralsignlowergreek: 0x0375,
  24353. numero: 0x2116,
  24354. nun: 0x05E0,
  24355. nundagesh: 0xFB40,
  24356. nundageshhebrew: 0xFB40,
  24357. nunhebrew: 0x05E0,
  24358. nvsquare: 0x33B5,
  24359. nwsquare: 0x33BB,
  24360. nyabengali: 0x099E,
  24361. nyadeva: 0x091E,
  24362. nyagujarati: 0x0A9E,
  24363. nyagurmukhi: 0x0A1E,
  24364. o: 0x006F,
  24365. oacute: 0x00F3,
  24366. oangthai: 0x0E2D,
  24367. obarred: 0x0275,
  24368. obarredcyrillic: 0x04E9,
  24369. obarreddieresiscyrillic: 0x04EB,
  24370. obengali: 0x0993,
  24371. obopomofo: 0x311B,
  24372. obreve: 0x014F,
  24373. ocandradeva: 0x0911,
  24374. ocandragujarati: 0x0A91,
  24375. ocandravowelsigndeva: 0x0949,
  24376. ocandravowelsigngujarati: 0x0AC9,
  24377. ocaron: 0x01D2,
  24378. ocircle: 0x24DE,
  24379. ocircumflex: 0x00F4,
  24380. ocircumflexacute: 0x1ED1,
  24381. ocircumflexdotbelow: 0x1ED9,
  24382. ocircumflexgrave: 0x1ED3,
  24383. ocircumflexhookabove: 0x1ED5,
  24384. ocircumflextilde: 0x1ED7,
  24385. ocyrillic: 0x043E,
  24386. odblacute: 0x0151,
  24387. odblgrave: 0x020D,
  24388. odeva: 0x0913,
  24389. odieresis: 0x00F6,
  24390. odieresiscyrillic: 0x04E7,
  24391. odotbelow: 0x1ECD,
  24392. oe: 0x0153,
  24393. oekorean: 0x315A,
  24394. ogonek: 0x02DB,
  24395. ogonekcmb: 0x0328,
  24396. ograve: 0x00F2,
  24397. ogujarati: 0x0A93,
  24398. oharmenian: 0x0585,
  24399. ohiragana: 0x304A,
  24400. ohookabove: 0x1ECF,
  24401. ohorn: 0x01A1,
  24402. ohornacute: 0x1EDB,
  24403. ohorndotbelow: 0x1EE3,
  24404. ohorngrave: 0x1EDD,
  24405. ohornhookabove: 0x1EDF,
  24406. ohorntilde: 0x1EE1,
  24407. ohungarumlaut: 0x0151,
  24408. oi: 0x01A3,
  24409. oinvertedbreve: 0x020F,
  24410. okatakana: 0x30AA,
  24411. okatakanahalfwidth: 0xFF75,
  24412. okorean: 0x3157,
  24413. olehebrew: 0x05AB,
  24414. omacron: 0x014D,
  24415. omacronacute: 0x1E53,
  24416. omacrongrave: 0x1E51,
  24417. omdeva: 0x0950,
  24418. omega: 0x03C9,
  24419. omega1: 0x03D6,
  24420. omegacyrillic: 0x0461,
  24421. omegalatinclosed: 0x0277,
  24422. omegaroundcyrillic: 0x047B,
  24423. omegatitlocyrillic: 0x047D,
  24424. omegatonos: 0x03CE,
  24425. omgujarati: 0x0AD0,
  24426. omicron: 0x03BF,
  24427. omicrontonos: 0x03CC,
  24428. omonospace: 0xFF4F,
  24429. one: 0x0031,
  24430. onearabic: 0x0661,
  24431. onebengali: 0x09E7,
  24432. onecircle: 0x2460,
  24433. onecircleinversesansserif: 0x278A,
  24434. onedeva: 0x0967,
  24435. onedotenleader: 0x2024,
  24436. oneeighth: 0x215B,
  24437. onefitted: 0xF6DC,
  24438. onegujarati: 0x0AE7,
  24439. onegurmukhi: 0x0A67,
  24440. onehackarabic: 0x0661,
  24441. onehalf: 0x00BD,
  24442. onehangzhou: 0x3021,
  24443. oneideographicparen: 0x3220,
  24444. oneinferior: 0x2081,
  24445. onemonospace: 0xFF11,
  24446. onenumeratorbengali: 0x09F4,
  24447. oneoldstyle: 0xF731,
  24448. oneparen: 0x2474,
  24449. oneperiod: 0x2488,
  24450. onepersian: 0x06F1,
  24451. onequarter: 0x00BC,
  24452. oneroman: 0x2170,
  24453. onesuperior: 0x00B9,
  24454. onethai: 0x0E51,
  24455. onethird: 0x2153,
  24456. oogonek: 0x01EB,
  24457. oogonekmacron: 0x01ED,
  24458. oogurmukhi: 0x0A13,
  24459. oomatragurmukhi: 0x0A4B,
  24460. oopen: 0x0254,
  24461. oparen: 0x24AA,
  24462. openbullet: 0x25E6,
  24463. option: 0x2325,
  24464. ordfeminine: 0x00AA,
  24465. ordmasculine: 0x00BA,
  24466. orthogonal: 0x221F,
  24467. oshortdeva: 0x0912,
  24468. oshortvowelsigndeva: 0x094A,
  24469. oslash: 0x00F8,
  24470. oslashacute: 0x01FF,
  24471. osmallhiragana: 0x3049,
  24472. osmallkatakana: 0x30A9,
  24473. osmallkatakanahalfwidth: 0xFF6B,
  24474. ostrokeacute: 0x01FF,
  24475. osuperior: 0xF6F0,
  24476. otcyrillic: 0x047F,
  24477. otilde: 0x00F5,
  24478. otildeacute: 0x1E4D,
  24479. otildedieresis: 0x1E4F,
  24480. oubopomofo: 0x3121,
  24481. overline: 0x203E,
  24482. overlinecenterline: 0xFE4A,
  24483. overlinecmb: 0x0305,
  24484. overlinedashed: 0xFE49,
  24485. overlinedblwavy: 0xFE4C,
  24486. overlinewavy: 0xFE4B,
  24487. overscore: 0x00AF,
  24488. ovowelsignbengali: 0x09CB,
  24489. ovowelsigndeva: 0x094B,
  24490. ovowelsigngujarati: 0x0ACB,
  24491. p: 0x0070,
  24492. paampssquare: 0x3380,
  24493. paasentosquare: 0x332B,
  24494. pabengali: 0x09AA,
  24495. pacute: 0x1E55,
  24496. padeva: 0x092A,
  24497. pagedown: 0x21DF,
  24498. pageup: 0x21DE,
  24499. pagujarati: 0x0AAA,
  24500. pagurmukhi: 0x0A2A,
  24501. pahiragana: 0x3071,
  24502. paiyannoithai: 0x0E2F,
  24503. pakatakana: 0x30D1,
  24504. palatalizationcyrilliccmb: 0x0484,
  24505. palochkacyrillic: 0x04C0,
  24506. pansioskorean: 0x317F,
  24507. paragraph: 0x00B6,
  24508. parallel: 0x2225,
  24509. parenleft: 0x0028,
  24510. parenleftaltonearabic: 0xFD3E,
  24511. parenleftbt: 0xF8ED,
  24512. parenleftex: 0xF8EC,
  24513. parenleftinferior: 0x208D,
  24514. parenleftmonospace: 0xFF08,
  24515. parenleftsmall: 0xFE59,
  24516. parenleftsuperior: 0x207D,
  24517. parenlefttp: 0xF8EB,
  24518. parenleftvertical: 0xFE35,
  24519. parenright: 0x0029,
  24520. parenrightaltonearabic: 0xFD3F,
  24521. parenrightbt: 0xF8F8,
  24522. parenrightex: 0xF8F7,
  24523. parenrightinferior: 0x208E,
  24524. parenrightmonospace: 0xFF09,
  24525. parenrightsmall: 0xFE5A,
  24526. parenrightsuperior: 0x207E,
  24527. parenrighttp: 0xF8F6,
  24528. parenrightvertical: 0xFE36,
  24529. partialdiff: 0x2202,
  24530. paseqhebrew: 0x05C0,
  24531. pashtahebrew: 0x0599,
  24532. pasquare: 0x33A9,
  24533. patah: 0x05B7,
  24534. patah11: 0x05B7,
  24535. patah1d: 0x05B7,
  24536. patah2a: 0x05B7,
  24537. patahhebrew: 0x05B7,
  24538. patahnarrowhebrew: 0x05B7,
  24539. patahquarterhebrew: 0x05B7,
  24540. patahwidehebrew: 0x05B7,
  24541. pazerhebrew: 0x05A1,
  24542. pbopomofo: 0x3106,
  24543. pcircle: 0x24DF,
  24544. pdotaccent: 0x1E57,
  24545. pe: 0x05E4,
  24546. pecyrillic: 0x043F,
  24547. pedagesh: 0xFB44,
  24548. pedageshhebrew: 0xFB44,
  24549. peezisquare: 0x333B,
  24550. pefinaldageshhebrew: 0xFB43,
  24551. peharabic: 0x067E,
  24552. peharmenian: 0x057A,
  24553. pehebrew: 0x05E4,
  24554. pehfinalarabic: 0xFB57,
  24555. pehinitialarabic: 0xFB58,
  24556. pehiragana: 0x307A,
  24557. pehmedialarabic: 0xFB59,
  24558. pekatakana: 0x30DA,
  24559. pemiddlehookcyrillic: 0x04A7,
  24560. perafehebrew: 0xFB4E,
  24561. percent: 0x0025,
  24562. percentarabic: 0x066A,
  24563. percentmonospace: 0xFF05,
  24564. percentsmall: 0xFE6A,
  24565. period: 0x002E,
  24566. periodarmenian: 0x0589,
  24567. periodcentered: 0x00B7,
  24568. periodhalfwidth: 0xFF61,
  24569. periodinferior: 0xF6E7,
  24570. periodmonospace: 0xFF0E,
  24571. periodsmall: 0xFE52,
  24572. periodsuperior: 0xF6E8,
  24573. perispomenigreekcmb: 0x0342,
  24574. perpendicular: 0x22A5,
  24575. perthousand: 0x2030,
  24576. peseta: 0x20A7,
  24577. pfsquare: 0x338A,
  24578. phabengali: 0x09AB,
  24579. phadeva: 0x092B,
  24580. phagujarati: 0x0AAB,
  24581. phagurmukhi: 0x0A2B,
  24582. phi: 0x03C6,
  24583. phi1: 0x03D5,
  24584. phieuphacirclekorean: 0x327A,
  24585. phieuphaparenkorean: 0x321A,
  24586. phieuphcirclekorean: 0x326C,
  24587. phieuphkorean: 0x314D,
  24588. phieuphparenkorean: 0x320C,
  24589. philatin: 0x0278,
  24590. phinthuthai: 0x0E3A,
  24591. phisymbolgreek: 0x03D5,
  24592. phook: 0x01A5,
  24593. phophanthai: 0x0E1E,
  24594. phophungthai: 0x0E1C,
  24595. phosamphaothai: 0x0E20,
  24596. pi: 0x03C0,
  24597. pieupacirclekorean: 0x3273,
  24598. pieupaparenkorean: 0x3213,
  24599. pieupcieuckorean: 0x3176,
  24600. pieupcirclekorean: 0x3265,
  24601. pieupkiyeokkorean: 0x3172,
  24602. pieupkorean: 0x3142,
  24603. pieupparenkorean: 0x3205,
  24604. pieupsioskiyeokkorean: 0x3174,
  24605. pieupsioskorean: 0x3144,
  24606. pieupsiostikeutkorean: 0x3175,
  24607. pieupthieuthkorean: 0x3177,
  24608. pieuptikeutkorean: 0x3173,
  24609. pihiragana: 0x3074,
  24610. pikatakana: 0x30D4,
  24611. pisymbolgreek: 0x03D6,
  24612. piwrarmenian: 0x0583,
  24613. plus: 0x002B,
  24614. plusbelowcmb: 0x031F,
  24615. pluscircle: 0x2295,
  24616. plusminus: 0x00B1,
  24617. plusmod: 0x02D6,
  24618. plusmonospace: 0xFF0B,
  24619. plussmall: 0xFE62,
  24620. plussuperior: 0x207A,
  24621. pmonospace: 0xFF50,
  24622. pmsquare: 0x33D8,
  24623. pohiragana: 0x307D,
  24624. pointingindexdownwhite: 0x261F,
  24625. pointingindexleftwhite: 0x261C,
  24626. pointingindexrightwhite: 0x261E,
  24627. pointingindexupwhite: 0x261D,
  24628. pokatakana: 0x30DD,
  24629. poplathai: 0x0E1B,
  24630. postalmark: 0x3012,
  24631. postalmarkface: 0x3020,
  24632. pparen: 0x24AB,
  24633. precedes: 0x227A,
  24634. prescription: 0x211E,
  24635. primemod: 0x02B9,
  24636. primereversed: 0x2035,
  24637. product: 0x220F,
  24638. projective: 0x2305,
  24639. prolongedkana: 0x30FC,
  24640. propellor: 0x2318,
  24641. propersubset: 0x2282,
  24642. propersuperset: 0x2283,
  24643. proportion: 0x2237,
  24644. proportional: 0x221D,
  24645. psi: 0x03C8,
  24646. psicyrillic: 0x0471,
  24647. psilipneumatacyrilliccmb: 0x0486,
  24648. pssquare: 0x33B0,
  24649. puhiragana: 0x3077,
  24650. pukatakana: 0x30D7,
  24651. pvsquare: 0x33B4,
  24652. pwsquare: 0x33BA,
  24653. q: 0x0071,
  24654. qadeva: 0x0958,
  24655. qadmahebrew: 0x05A8,
  24656. qafarabic: 0x0642,
  24657. qaffinalarabic: 0xFED6,
  24658. qafinitialarabic: 0xFED7,
  24659. qafmedialarabic: 0xFED8,
  24660. qamats: 0x05B8,
  24661. qamats10: 0x05B8,
  24662. qamats1a: 0x05B8,
  24663. qamats1c: 0x05B8,
  24664. qamats27: 0x05B8,
  24665. qamats29: 0x05B8,
  24666. qamats33: 0x05B8,
  24667. qamatsde: 0x05B8,
  24668. qamatshebrew: 0x05B8,
  24669. qamatsnarrowhebrew: 0x05B8,
  24670. qamatsqatanhebrew: 0x05B8,
  24671. qamatsqatannarrowhebrew: 0x05B8,
  24672. qamatsqatanquarterhebrew: 0x05B8,
  24673. qamatsqatanwidehebrew: 0x05B8,
  24674. qamatsquarterhebrew: 0x05B8,
  24675. qamatswidehebrew: 0x05B8,
  24676. qarneyparahebrew: 0x059F,
  24677. qbopomofo: 0x3111,
  24678. qcircle: 0x24E0,
  24679. qhook: 0x02A0,
  24680. qmonospace: 0xFF51,
  24681. qof: 0x05E7,
  24682. qofdagesh: 0xFB47,
  24683. qofdageshhebrew: 0xFB47,
  24684. qofhebrew: 0x05E7,
  24685. qparen: 0x24AC,
  24686. quarternote: 0x2669,
  24687. qubuts: 0x05BB,
  24688. qubuts18: 0x05BB,
  24689. qubuts25: 0x05BB,
  24690. qubuts31: 0x05BB,
  24691. qubutshebrew: 0x05BB,
  24692. qubutsnarrowhebrew: 0x05BB,
  24693. qubutsquarterhebrew: 0x05BB,
  24694. qubutswidehebrew: 0x05BB,
  24695. question: 0x003F,
  24696. questionarabic: 0x061F,
  24697. questionarmenian: 0x055E,
  24698. questiondown: 0x00BF,
  24699. questiondownsmall: 0xF7BF,
  24700. questiongreek: 0x037E,
  24701. questionmonospace: 0xFF1F,
  24702. questionsmall: 0xF73F,
  24703. quotedbl: 0x0022,
  24704. quotedblbase: 0x201E,
  24705. quotedblleft: 0x201C,
  24706. quotedblmonospace: 0xFF02,
  24707. quotedblprime: 0x301E,
  24708. quotedblprimereversed: 0x301D,
  24709. quotedblright: 0x201D,
  24710. quoteleft: 0x2018,
  24711. quoteleftreversed: 0x201B,
  24712. quotereversed: 0x201B,
  24713. quoteright: 0x2019,
  24714. quoterightn: 0x0149,
  24715. quotesinglbase: 0x201A,
  24716. quotesingle: 0x0027,
  24717. quotesinglemonospace: 0xFF07,
  24718. r: 0x0072,
  24719. raarmenian: 0x057C,
  24720. rabengali: 0x09B0,
  24721. racute: 0x0155,
  24722. radeva: 0x0930,
  24723. radical: 0x221A,
  24724. radicalex: 0xF8E5,
  24725. radoverssquare: 0x33AE,
  24726. radoverssquaredsquare: 0x33AF,
  24727. radsquare: 0x33AD,
  24728. rafe: 0x05BF,
  24729. rafehebrew: 0x05BF,
  24730. ragujarati: 0x0AB0,
  24731. ragurmukhi: 0x0A30,
  24732. rahiragana: 0x3089,
  24733. rakatakana: 0x30E9,
  24734. rakatakanahalfwidth: 0xFF97,
  24735. ralowerdiagonalbengali: 0x09F1,
  24736. ramiddlediagonalbengali: 0x09F0,
  24737. ramshorn: 0x0264,
  24738. ratio: 0x2236,
  24739. rbopomofo: 0x3116,
  24740. rcaron: 0x0159,
  24741. rcedilla: 0x0157,
  24742. rcircle: 0x24E1,
  24743. rcommaaccent: 0x0157,
  24744. rdblgrave: 0x0211,
  24745. rdotaccent: 0x1E59,
  24746. rdotbelow: 0x1E5B,
  24747. rdotbelowmacron: 0x1E5D,
  24748. referencemark: 0x203B,
  24749. reflexsubset: 0x2286,
  24750. reflexsuperset: 0x2287,
  24751. registered: 0x00AE,
  24752. registersans: 0xF8E8,
  24753. registerserif: 0xF6DA,
  24754. reharabic: 0x0631,
  24755. reharmenian: 0x0580,
  24756. rehfinalarabic: 0xFEAE,
  24757. rehiragana: 0x308C,
  24758. rekatakana: 0x30EC,
  24759. rekatakanahalfwidth: 0xFF9A,
  24760. resh: 0x05E8,
  24761. reshdageshhebrew: 0xFB48,
  24762. reshhebrew: 0x05E8,
  24763. reversedtilde: 0x223D,
  24764. reviahebrew: 0x0597,
  24765. reviamugrashhebrew: 0x0597,
  24766. revlogicalnot: 0x2310,
  24767. rfishhook: 0x027E,
  24768. rfishhookreversed: 0x027F,
  24769. rhabengali: 0x09DD,
  24770. rhadeva: 0x095D,
  24771. rho: 0x03C1,
  24772. rhook: 0x027D,
  24773. rhookturned: 0x027B,
  24774. rhookturnedsuperior: 0x02B5,
  24775. rhosymbolgreek: 0x03F1,
  24776. rhotichookmod: 0x02DE,
  24777. rieulacirclekorean: 0x3271,
  24778. rieulaparenkorean: 0x3211,
  24779. rieulcirclekorean: 0x3263,
  24780. rieulhieuhkorean: 0x3140,
  24781. rieulkiyeokkorean: 0x313A,
  24782. rieulkiyeoksioskorean: 0x3169,
  24783. rieulkorean: 0x3139,
  24784. rieulmieumkorean: 0x313B,
  24785. rieulpansioskorean: 0x316C,
  24786. rieulparenkorean: 0x3203,
  24787. rieulphieuphkorean: 0x313F,
  24788. rieulpieupkorean: 0x313C,
  24789. rieulpieupsioskorean: 0x316B,
  24790. rieulsioskorean: 0x313D,
  24791. rieulthieuthkorean: 0x313E,
  24792. rieultikeutkorean: 0x316A,
  24793. rieulyeorinhieuhkorean: 0x316D,
  24794. rightangle: 0x221F,
  24795. righttackbelowcmb: 0x0319,
  24796. righttriangle: 0x22BF,
  24797. rihiragana: 0x308A,
  24798. rikatakana: 0x30EA,
  24799. rikatakanahalfwidth: 0xFF98,
  24800. ring: 0x02DA,
  24801. ringbelowcmb: 0x0325,
  24802. ringcmb: 0x030A,
  24803. ringhalfleft: 0x02BF,
  24804. ringhalfleftarmenian: 0x0559,
  24805. ringhalfleftbelowcmb: 0x031C,
  24806. ringhalfleftcentered: 0x02D3,
  24807. ringhalfright: 0x02BE,
  24808. ringhalfrightbelowcmb: 0x0339,
  24809. ringhalfrightcentered: 0x02D2,
  24810. rinvertedbreve: 0x0213,
  24811. rittorusquare: 0x3351,
  24812. rlinebelow: 0x1E5F,
  24813. rlongleg: 0x027C,
  24814. rlonglegturned: 0x027A,
  24815. rmonospace: 0xFF52,
  24816. rohiragana: 0x308D,
  24817. rokatakana: 0x30ED,
  24818. rokatakanahalfwidth: 0xFF9B,
  24819. roruathai: 0x0E23,
  24820. rparen: 0x24AD,
  24821. rrabengali: 0x09DC,
  24822. rradeva: 0x0931,
  24823. rragurmukhi: 0x0A5C,
  24824. rreharabic: 0x0691,
  24825. rrehfinalarabic: 0xFB8D,
  24826. rrvocalicbengali: 0x09E0,
  24827. rrvocalicdeva: 0x0960,
  24828. rrvocalicgujarati: 0x0AE0,
  24829. rrvocalicvowelsignbengali: 0x09C4,
  24830. rrvocalicvowelsigndeva: 0x0944,
  24831. rrvocalicvowelsigngujarati: 0x0AC4,
  24832. rsuperior: 0xF6F1,
  24833. rtblock: 0x2590,
  24834. rturned: 0x0279,
  24835. rturnedsuperior: 0x02B4,
  24836. ruhiragana: 0x308B,
  24837. rukatakana: 0x30EB,
  24838. rukatakanahalfwidth: 0xFF99,
  24839. rupeemarkbengali: 0x09F2,
  24840. rupeesignbengali: 0x09F3,
  24841. rupiah: 0xF6DD,
  24842. ruthai: 0x0E24,
  24843. rvocalicbengali: 0x098B,
  24844. rvocalicdeva: 0x090B,
  24845. rvocalicgujarati: 0x0A8B,
  24846. rvocalicvowelsignbengali: 0x09C3,
  24847. rvocalicvowelsigndeva: 0x0943,
  24848. rvocalicvowelsigngujarati: 0x0AC3,
  24849. s: 0x0073,
  24850. sabengali: 0x09B8,
  24851. sacute: 0x015B,
  24852. sacutedotaccent: 0x1E65,
  24853. sadarabic: 0x0635,
  24854. sadeva: 0x0938,
  24855. sadfinalarabic: 0xFEBA,
  24856. sadinitialarabic: 0xFEBB,
  24857. sadmedialarabic: 0xFEBC,
  24858. sagujarati: 0x0AB8,
  24859. sagurmukhi: 0x0A38,
  24860. sahiragana: 0x3055,
  24861. sakatakana: 0x30B5,
  24862. sakatakanahalfwidth: 0xFF7B,
  24863. sallallahoualayhewasallamarabic: 0xFDFA,
  24864. samekh: 0x05E1,
  24865. samekhdagesh: 0xFB41,
  24866. samekhdageshhebrew: 0xFB41,
  24867. samekhhebrew: 0x05E1,
  24868. saraaathai: 0x0E32,
  24869. saraaethai: 0x0E41,
  24870. saraaimaimalaithai: 0x0E44,
  24871. saraaimaimuanthai: 0x0E43,
  24872. saraamthai: 0x0E33,
  24873. saraathai: 0x0E30,
  24874. saraethai: 0x0E40,
  24875. saraiileftthai: 0xF886,
  24876. saraiithai: 0x0E35,
  24877. saraileftthai: 0xF885,
  24878. saraithai: 0x0E34,
  24879. saraothai: 0x0E42,
  24880. saraueeleftthai: 0xF888,
  24881. saraueethai: 0x0E37,
  24882. saraueleftthai: 0xF887,
  24883. sarauethai: 0x0E36,
  24884. sarauthai: 0x0E38,
  24885. sarauuthai: 0x0E39,
  24886. sbopomofo: 0x3119,
  24887. scaron: 0x0161,
  24888. scarondotaccent: 0x1E67,
  24889. scedilla: 0x015F,
  24890. schwa: 0x0259,
  24891. schwacyrillic: 0x04D9,
  24892. schwadieresiscyrillic: 0x04DB,
  24893. schwahook: 0x025A,
  24894. scircle: 0x24E2,
  24895. scircumflex: 0x015D,
  24896. scommaaccent: 0x0219,
  24897. sdotaccent: 0x1E61,
  24898. sdotbelow: 0x1E63,
  24899. sdotbelowdotaccent: 0x1E69,
  24900. seagullbelowcmb: 0x033C,
  24901. second: 0x2033,
  24902. secondtonechinese: 0x02CA,
  24903. section: 0x00A7,
  24904. seenarabic: 0x0633,
  24905. seenfinalarabic: 0xFEB2,
  24906. seeninitialarabic: 0xFEB3,
  24907. seenmedialarabic: 0xFEB4,
  24908. segol: 0x05B6,
  24909. segol13: 0x05B6,
  24910. segol1f: 0x05B6,
  24911. segol2c: 0x05B6,
  24912. segolhebrew: 0x05B6,
  24913. segolnarrowhebrew: 0x05B6,
  24914. segolquarterhebrew: 0x05B6,
  24915. segoltahebrew: 0x0592,
  24916. segolwidehebrew: 0x05B6,
  24917. seharmenian: 0x057D,
  24918. sehiragana: 0x305B,
  24919. sekatakana: 0x30BB,
  24920. sekatakanahalfwidth: 0xFF7E,
  24921. semicolon: 0x003B,
  24922. semicolonarabic: 0x061B,
  24923. semicolonmonospace: 0xFF1B,
  24924. semicolonsmall: 0xFE54,
  24925. semivoicedmarkkana: 0x309C,
  24926. semivoicedmarkkanahalfwidth: 0xFF9F,
  24927. sentisquare: 0x3322,
  24928. sentosquare: 0x3323,
  24929. seven: 0x0037,
  24930. sevenarabic: 0x0667,
  24931. sevenbengali: 0x09ED,
  24932. sevencircle: 0x2466,
  24933. sevencircleinversesansserif: 0x2790,
  24934. sevendeva: 0x096D,
  24935. seveneighths: 0x215E,
  24936. sevengujarati: 0x0AED,
  24937. sevengurmukhi: 0x0A6D,
  24938. sevenhackarabic: 0x0667,
  24939. sevenhangzhou: 0x3027,
  24940. sevenideographicparen: 0x3226,
  24941. seveninferior: 0x2087,
  24942. sevenmonospace: 0xFF17,
  24943. sevenoldstyle: 0xF737,
  24944. sevenparen: 0x247A,
  24945. sevenperiod: 0x248E,
  24946. sevenpersian: 0x06F7,
  24947. sevenroman: 0x2176,
  24948. sevensuperior: 0x2077,
  24949. seventeencircle: 0x2470,
  24950. seventeenparen: 0x2484,
  24951. seventeenperiod: 0x2498,
  24952. seventhai: 0x0E57,
  24953. sfthyphen: 0x00AD,
  24954. shaarmenian: 0x0577,
  24955. shabengali: 0x09B6,
  24956. shacyrillic: 0x0448,
  24957. shaddaarabic: 0x0651,
  24958. shaddadammaarabic: 0xFC61,
  24959. shaddadammatanarabic: 0xFC5E,
  24960. shaddafathaarabic: 0xFC60,
  24961. shaddakasraarabic: 0xFC62,
  24962. shaddakasratanarabic: 0xFC5F,
  24963. shade: 0x2592,
  24964. shadedark: 0x2593,
  24965. shadelight: 0x2591,
  24966. shademedium: 0x2592,
  24967. shadeva: 0x0936,
  24968. shagujarati: 0x0AB6,
  24969. shagurmukhi: 0x0A36,
  24970. shalshelethebrew: 0x0593,
  24971. shbopomofo: 0x3115,
  24972. shchacyrillic: 0x0449,
  24973. sheenarabic: 0x0634,
  24974. sheenfinalarabic: 0xFEB6,
  24975. sheeninitialarabic: 0xFEB7,
  24976. sheenmedialarabic: 0xFEB8,
  24977. sheicoptic: 0x03E3,
  24978. sheqel: 0x20AA,
  24979. sheqelhebrew: 0x20AA,
  24980. sheva: 0x05B0,
  24981. sheva115: 0x05B0,
  24982. sheva15: 0x05B0,
  24983. sheva22: 0x05B0,
  24984. sheva2e: 0x05B0,
  24985. shevahebrew: 0x05B0,
  24986. shevanarrowhebrew: 0x05B0,
  24987. shevaquarterhebrew: 0x05B0,
  24988. shevawidehebrew: 0x05B0,
  24989. shhacyrillic: 0x04BB,
  24990. shimacoptic: 0x03ED,
  24991. shin: 0x05E9,
  24992. shindagesh: 0xFB49,
  24993. shindageshhebrew: 0xFB49,
  24994. shindageshshindot: 0xFB2C,
  24995. shindageshshindothebrew: 0xFB2C,
  24996. shindageshsindot: 0xFB2D,
  24997. shindageshsindothebrew: 0xFB2D,
  24998. shindothebrew: 0x05C1,
  24999. shinhebrew: 0x05E9,
  25000. shinshindot: 0xFB2A,
  25001. shinshindothebrew: 0xFB2A,
  25002. shinsindot: 0xFB2B,
  25003. shinsindothebrew: 0xFB2B,
  25004. shook: 0x0282,
  25005. sigma: 0x03C3,
  25006. sigma1: 0x03C2,
  25007. sigmafinal: 0x03C2,
  25008. sigmalunatesymbolgreek: 0x03F2,
  25009. sihiragana: 0x3057,
  25010. sikatakana: 0x30B7,
  25011. sikatakanahalfwidth: 0xFF7C,
  25012. siluqhebrew: 0x05BD,
  25013. siluqlefthebrew: 0x05BD,
  25014. similar: 0x223C,
  25015. sindothebrew: 0x05C2,
  25016. siosacirclekorean: 0x3274,
  25017. siosaparenkorean: 0x3214,
  25018. sioscieuckorean: 0x317E,
  25019. sioscirclekorean: 0x3266,
  25020. sioskiyeokkorean: 0x317A,
  25021. sioskorean: 0x3145,
  25022. siosnieunkorean: 0x317B,
  25023. siosparenkorean: 0x3206,
  25024. siospieupkorean: 0x317D,
  25025. siostikeutkorean: 0x317C,
  25026. six: 0x0036,
  25027. sixarabic: 0x0666,
  25028. sixbengali: 0x09EC,
  25029. sixcircle: 0x2465,
  25030. sixcircleinversesansserif: 0x278F,
  25031. sixdeva: 0x096C,
  25032. sixgujarati: 0x0AEC,
  25033. sixgurmukhi: 0x0A6C,
  25034. sixhackarabic: 0x0666,
  25035. sixhangzhou: 0x3026,
  25036. sixideographicparen: 0x3225,
  25037. sixinferior: 0x2086,
  25038. sixmonospace: 0xFF16,
  25039. sixoldstyle: 0xF736,
  25040. sixparen: 0x2479,
  25041. sixperiod: 0x248D,
  25042. sixpersian: 0x06F6,
  25043. sixroman: 0x2175,
  25044. sixsuperior: 0x2076,
  25045. sixteencircle: 0x246F,
  25046. sixteencurrencydenominatorbengali: 0x09F9,
  25047. sixteenparen: 0x2483,
  25048. sixteenperiod: 0x2497,
  25049. sixthai: 0x0E56,
  25050. slash: 0x002F,
  25051. slashmonospace: 0xFF0F,
  25052. slong: 0x017F,
  25053. slongdotaccent: 0x1E9B,
  25054. smileface: 0x263A,
  25055. smonospace: 0xFF53,
  25056. sofpasuqhebrew: 0x05C3,
  25057. softhyphen: 0x00AD,
  25058. softsigncyrillic: 0x044C,
  25059. sohiragana: 0x305D,
  25060. sokatakana: 0x30BD,
  25061. sokatakanahalfwidth: 0xFF7F,
  25062. soliduslongoverlaycmb: 0x0338,
  25063. solidusshortoverlaycmb: 0x0337,
  25064. sorusithai: 0x0E29,
  25065. sosalathai: 0x0E28,
  25066. sosothai: 0x0E0B,
  25067. sosuathai: 0x0E2A,
  25068. space: 0x0020,
  25069. spacehackarabic: 0x0020,
  25070. spade: 0x2660,
  25071. spadesuitblack: 0x2660,
  25072. spadesuitwhite: 0x2664,
  25073. sparen: 0x24AE,
  25074. squarebelowcmb: 0x033B,
  25075. squarecc: 0x33C4,
  25076. squarecm: 0x339D,
  25077. squarediagonalcrosshatchfill: 0x25A9,
  25078. squarehorizontalfill: 0x25A4,
  25079. squarekg: 0x338F,
  25080. squarekm: 0x339E,
  25081. squarekmcapital: 0x33CE,
  25082. squareln: 0x33D1,
  25083. squarelog: 0x33D2,
  25084. squaremg: 0x338E,
  25085. squaremil: 0x33D5,
  25086. squaremm: 0x339C,
  25087. squaremsquared: 0x33A1,
  25088. squareorthogonalcrosshatchfill: 0x25A6,
  25089. squareupperlefttolowerrightfill: 0x25A7,
  25090. squareupperrighttolowerleftfill: 0x25A8,
  25091. squareverticalfill: 0x25A5,
  25092. squarewhitewithsmallblack: 0x25A3,
  25093. srsquare: 0x33DB,
  25094. ssabengali: 0x09B7,
  25095. ssadeva: 0x0937,
  25096. ssagujarati: 0x0AB7,
  25097. ssangcieuckorean: 0x3149,
  25098. ssanghieuhkorean: 0x3185,
  25099. ssangieungkorean: 0x3180,
  25100. ssangkiyeokkorean: 0x3132,
  25101. ssangnieunkorean: 0x3165,
  25102. ssangpieupkorean: 0x3143,
  25103. ssangsioskorean: 0x3146,
  25104. ssangtikeutkorean: 0x3138,
  25105. ssuperior: 0xF6F2,
  25106. sterling: 0x00A3,
  25107. sterlingmonospace: 0xFFE1,
  25108. strokelongoverlaycmb: 0x0336,
  25109. strokeshortoverlaycmb: 0x0335,
  25110. subset: 0x2282,
  25111. subsetnotequal: 0x228A,
  25112. subsetorequal: 0x2286,
  25113. succeeds: 0x227B,
  25114. suchthat: 0x220B,
  25115. suhiragana: 0x3059,
  25116. sukatakana: 0x30B9,
  25117. sukatakanahalfwidth: 0xFF7D,
  25118. sukunarabic: 0x0652,
  25119. summation: 0x2211,
  25120. sun: 0x263C,
  25121. superset: 0x2283,
  25122. supersetnotequal: 0x228B,
  25123. supersetorequal: 0x2287,
  25124. svsquare: 0x33DC,
  25125. syouwaerasquare: 0x337C,
  25126. t: 0x0074,
  25127. tabengali: 0x09A4,
  25128. tackdown: 0x22A4,
  25129. tackleft: 0x22A3,
  25130. tadeva: 0x0924,
  25131. tagujarati: 0x0AA4,
  25132. tagurmukhi: 0x0A24,
  25133. taharabic: 0x0637,
  25134. tahfinalarabic: 0xFEC2,
  25135. tahinitialarabic: 0xFEC3,
  25136. tahiragana: 0x305F,
  25137. tahmedialarabic: 0xFEC4,
  25138. taisyouerasquare: 0x337D,
  25139. takatakana: 0x30BF,
  25140. takatakanahalfwidth: 0xFF80,
  25141. tatweelarabic: 0x0640,
  25142. tau: 0x03C4,
  25143. tav: 0x05EA,
  25144. tavdages: 0xFB4A,
  25145. tavdagesh: 0xFB4A,
  25146. tavdageshhebrew: 0xFB4A,
  25147. tavhebrew: 0x05EA,
  25148. tbar: 0x0167,
  25149. tbopomofo: 0x310A,
  25150. tcaron: 0x0165,
  25151. tccurl: 0x02A8,
  25152. tcedilla: 0x0163,
  25153. tcheharabic: 0x0686,
  25154. tchehfinalarabic: 0xFB7B,
  25155. tchehinitialarabic: 0xFB7C,
  25156. tchehmedialarabic: 0xFB7D,
  25157. tcircle: 0x24E3,
  25158. tcircumflexbelow: 0x1E71,
  25159. tcommaaccent: 0x0163,
  25160. tdieresis: 0x1E97,
  25161. tdotaccent: 0x1E6B,
  25162. tdotbelow: 0x1E6D,
  25163. tecyrillic: 0x0442,
  25164. tedescendercyrillic: 0x04AD,
  25165. teharabic: 0x062A,
  25166. tehfinalarabic: 0xFE96,
  25167. tehhahinitialarabic: 0xFCA2,
  25168. tehhahisolatedarabic: 0xFC0C,
  25169. tehinitialarabic: 0xFE97,
  25170. tehiragana: 0x3066,
  25171. tehjeeminitialarabic: 0xFCA1,
  25172. tehjeemisolatedarabic: 0xFC0B,
  25173. tehmarbutaarabic: 0x0629,
  25174. tehmarbutafinalarabic: 0xFE94,
  25175. tehmedialarabic: 0xFE98,
  25176. tehmeeminitialarabic: 0xFCA4,
  25177. tehmeemisolatedarabic: 0xFC0E,
  25178. tehnoonfinalarabic: 0xFC73,
  25179. tekatakana: 0x30C6,
  25180. tekatakanahalfwidth: 0xFF83,
  25181. telephone: 0x2121,
  25182. telephoneblack: 0x260E,
  25183. telishagedolahebrew: 0x05A0,
  25184. telishaqetanahebrew: 0x05A9,
  25185. tencircle: 0x2469,
  25186. tenideographicparen: 0x3229,
  25187. tenparen: 0x247D,
  25188. tenperiod: 0x2491,
  25189. tenroman: 0x2179,
  25190. tesh: 0x02A7,
  25191. tet: 0x05D8,
  25192. tetdagesh: 0xFB38,
  25193. tetdageshhebrew: 0xFB38,
  25194. tethebrew: 0x05D8,
  25195. tetsecyrillic: 0x04B5,
  25196. tevirhebrew: 0x059B,
  25197. tevirlefthebrew: 0x059B,
  25198. thabengali: 0x09A5,
  25199. thadeva: 0x0925,
  25200. thagujarati: 0x0AA5,
  25201. thagurmukhi: 0x0A25,
  25202. thalarabic: 0x0630,
  25203. thalfinalarabic: 0xFEAC,
  25204. thanthakhatlowleftthai: 0xF898,
  25205. thanthakhatlowrightthai: 0xF897,
  25206. thanthakhatthai: 0x0E4C,
  25207. thanthakhatupperleftthai: 0xF896,
  25208. theharabic: 0x062B,
  25209. thehfinalarabic: 0xFE9A,
  25210. thehinitialarabic: 0xFE9B,
  25211. thehmedialarabic: 0xFE9C,
  25212. thereexists: 0x2203,
  25213. therefore: 0x2234,
  25214. theta: 0x03B8,
  25215. theta1: 0x03D1,
  25216. thetasymbolgreek: 0x03D1,
  25217. thieuthacirclekorean: 0x3279,
  25218. thieuthaparenkorean: 0x3219,
  25219. thieuthcirclekorean: 0x326B,
  25220. thieuthkorean: 0x314C,
  25221. thieuthparenkorean: 0x320B,
  25222. thirteencircle: 0x246C,
  25223. thirteenparen: 0x2480,
  25224. thirteenperiod: 0x2494,
  25225. thonangmonthothai: 0x0E11,
  25226. thook: 0x01AD,
  25227. thophuthaothai: 0x0E12,
  25228. thorn: 0x00FE,
  25229. thothahanthai: 0x0E17,
  25230. thothanthai: 0x0E10,
  25231. thothongthai: 0x0E18,
  25232. thothungthai: 0x0E16,
  25233. thousandcyrillic: 0x0482,
  25234. thousandsseparatorarabic: 0x066C,
  25235. thousandsseparatorpersian: 0x066C,
  25236. three: 0x0033,
  25237. threearabic: 0x0663,
  25238. threebengali: 0x09E9,
  25239. threecircle: 0x2462,
  25240. threecircleinversesansserif: 0x278C,
  25241. threedeva: 0x0969,
  25242. threeeighths: 0x215C,
  25243. threegujarati: 0x0AE9,
  25244. threegurmukhi: 0x0A69,
  25245. threehackarabic: 0x0663,
  25246. threehangzhou: 0x3023,
  25247. threeideographicparen: 0x3222,
  25248. threeinferior: 0x2083,
  25249. threemonospace: 0xFF13,
  25250. threenumeratorbengali: 0x09F6,
  25251. threeoldstyle: 0xF733,
  25252. threeparen: 0x2476,
  25253. threeperiod: 0x248A,
  25254. threepersian: 0x06F3,
  25255. threequarters: 0x00BE,
  25256. threequartersemdash: 0xF6DE,
  25257. threeroman: 0x2172,
  25258. threesuperior: 0x00B3,
  25259. threethai: 0x0E53,
  25260. thzsquare: 0x3394,
  25261. tihiragana: 0x3061,
  25262. tikatakana: 0x30C1,
  25263. tikatakanahalfwidth: 0xFF81,
  25264. tikeutacirclekorean: 0x3270,
  25265. tikeutaparenkorean: 0x3210,
  25266. tikeutcirclekorean: 0x3262,
  25267. tikeutkorean: 0x3137,
  25268. tikeutparenkorean: 0x3202,
  25269. tilde: 0x02DC,
  25270. tildebelowcmb: 0x0330,
  25271. tildecmb: 0x0303,
  25272. tildecomb: 0x0303,
  25273. tildedoublecmb: 0x0360,
  25274. tildeoperator: 0x223C,
  25275. tildeoverlaycmb: 0x0334,
  25276. tildeverticalcmb: 0x033E,
  25277. timescircle: 0x2297,
  25278. tipehahebrew: 0x0596,
  25279. tipehalefthebrew: 0x0596,
  25280. tippigurmukhi: 0x0A70,
  25281. titlocyrilliccmb: 0x0483,
  25282. tiwnarmenian: 0x057F,
  25283. tlinebelow: 0x1E6F,
  25284. tmonospace: 0xFF54,
  25285. toarmenian: 0x0569,
  25286. tohiragana: 0x3068,
  25287. tokatakana: 0x30C8,
  25288. tokatakanahalfwidth: 0xFF84,
  25289. tonebarextrahighmod: 0x02E5,
  25290. tonebarextralowmod: 0x02E9,
  25291. tonebarhighmod: 0x02E6,
  25292. tonebarlowmod: 0x02E8,
  25293. tonebarmidmod: 0x02E7,
  25294. tonefive: 0x01BD,
  25295. tonesix: 0x0185,
  25296. tonetwo: 0x01A8,
  25297. tonos: 0x0384,
  25298. tonsquare: 0x3327,
  25299. topatakthai: 0x0E0F,
  25300. tortoiseshellbracketleft: 0x3014,
  25301. tortoiseshellbracketleftsmall: 0xFE5D,
  25302. tortoiseshellbracketleftvertical: 0xFE39,
  25303. tortoiseshellbracketright: 0x3015,
  25304. tortoiseshellbracketrightsmall: 0xFE5E,
  25305. tortoiseshellbracketrightvertical: 0xFE3A,
  25306. totaothai: 0x0E15,
  25307. tpalatalhook: 0x01AB,
  25308. tparen: 0x24AF,
  25309. trademark: 0x2122,
  25310. trademarksans: 0xF8EA,
  25311. trademarkserif: 0xF6DB,
  25312. tretroflexhook: 0x0288,
  25313. triagdn: 0x25BC,
  25314. triaglf: 0x25C4,
  25315. triagrt: 0x25BA,
  25316. triagup: 0x25B2,
  25317. ts: 0x02A6,
  25318. tsadi: 0x05E6,
  25319. tsadidagesh: 0xFB46,
  25320. tsadidageshhebrew: 0xFB46,
  25321. tsadihebrew: 0x05E6,
  25322. tsecyrillic: 0x0446,
  25323. tsere: 0x05B5,
  25324. tsere12: 0x05B5,
  25325. tsere1e: 0x05B5,
  25326. tsere2b: 0x05B5,
  25327. tserehebrew: 0x05B5,
  25328. tserenarrowhebrew: 0x05B5,
  25329. tserequarterhebrew: 0x05B5,
  25330. tserewidehebrew: 0x05B5,
  25331. tshecyrillic: 0x045B,
  25332. tsuperior: 0xF6F3,
  25333. ttabengali: 0x099F,
  25334. ttadeva: 0x091F,
  25335. ttagujarati: 0x0A9F,
  25336. ttagurmukhi: 0x0A1F,
  25337. tteharabic: 0x0679,
  25338. ttehfinalarabic: 0xFB67,
  25339. ttehinitialarabic: 0xFB68,
  25340. ttehmedialarabic: 0xFB69,
  25341. tthabengali: 0x09A0,
  25342. tthadeva: 0x0920,
  25343. tthagujarati: 0x0AA0,
  25344. tthagurmukhi: 0x0A20,
  25345. tturned: 0x0287,
  25346. tuhiragana: 0x3064,
  25347. tukatakana: 0x30C4,
  25348. tukatakanahalfwidth: 0xFF82,
  25349. tusmallhiragana: 0x3063,
  25350. tusmallkatakana: 0x30C3,
  25351. tusmallkatakanahalfwidth: 0xFF6F,
  25352. twelvecircle: 0x246B,
  25353. twelveparen: 0x247F,
  25354. twelveperiod: 0x2493,
  25355. twelveroman: 0x217B,
  25356. twentycircle: 0x2473,
  25357. twentyhangzhou: 0x5344,
  25358. twentyparen: 0x2487,
  25359. twentyperiod: 0x249B,
  25360. two: 0x0032,
  25361. twoarabic: 0x0662,
  25362. twobengali: 0x09E8,
  25363. twocircle: 0x2461,
  25364. twocircleinversesansserif: 0x278B,
  25365. twodeva: 0x0968,
  25366. twodotenleader: 0x2025,
  25367. twodotleader: 0x2025,
  25368. twodotleadervertical: 0xFE30,
  25369. twogujarati: 0x0AE8,
  25370. twogurmukhi: 0x0A68,
  25371. twohackarabic: 0x0662,
  25372. twohangzhou: 0x3022,
  25373. twoideographicparen: 0x3221,
  25374. twoinferior: 0x2082,
  25375. twomonospace: 0xFF12,
  25376. twonumeratorbengali: 0x09F5,
  25377. twooldstyle: 0xF732,
  25378. twoparen: 0x2475,
  25379. twoperiod: 0x2489,
  25380. twopersian: 0x06F2,
  25381. tworoman: 0x2171,
  25382. twostroke: 0x01BB,
  25383. twosuperior: 0x00B2,
  25384. twothai: 0x0E52,
  25385. twothirds: 0x2154,
  25386. u: 0x0075,
  25387. uacute: 0x00FA,
  25388. ubar: 0x0289,
  25389. ubengali: 0x0989,
  25390. ubopomofo: 0x3128,
  25391. ubreve: 0x016D,
  25392. ucaron: 0x01D4,
  25393. ucircle: 0x24E4,
  25394. ucircumflex: 0x00FB,
  25395. ucircumflexbelow: 0x1E77,
  25396. ucyrillic: 0x0443,
  25397. udattadeva: 0x0951,
  25398. udblacute: 0x0171,
  25399. udblgrave: 0x0215,
  25400. udeva: 0x0909,
  25401. udieresis: 0x00FC,
  25402. udieresisacute: 0x01D8,
  25403. udieresisbelow: 0x1E73,
  25404. udieresiscaron: 0x01DA,
  25405. udieresiscyrillic: 0x04F1,
  25406. udieresisgrave: 0x01DC,
  25407. udieresismacron: 0x01D6,
  25408. udotbelow: 0x1EE5,
  25409. ugrave: 0x00F9,
  25410. ugujarati: 0x0A89,
  25411. ugurmukhi: 0x0A09,
  25412. uhiragana: 0x3046,
  25413. uhookabove: 0x1EE7,
  25414. uhorn: 0x01B0,
  25415. uhornacute: 0x1EE9,
  25416. uhorndotbelow: 0x1EF1,
  25417. uhorngrave: 0x1EEB,
  25418. uhornhookabove: 0x1EED,
  25419. uhorntilde: 0x1EEF,
  25420. uhungarumlaut: 0x0171,
  25421. uhungarumlautcyrillic: 0x04F3,
  25422. uinvertedbreve: 0x0217,
  25423. ukatakana: 0x30A6,
  25424. ukatakanahalfwidth: 0xFF73,
  25425. ukcyrillic: 0x0479,
  25426. ukorean: 0x315C,
  25427. umacron: 0x016B,
  25428. umacroncyrillic: 0x04EF,
  25429. umacrondieresis: 0x1E7B,
  25430. umatragurmukhi: 0x0A41,
  25431. umonospace: 0xFF55,
  25432. underscore: 0x005F,
  25433. underscoredbl: 0x2017,
  25434. underscoremonospace: 0xFF3F,
  25435. underscorevertical: 0xFE33,
  25436. underscorewavy: 0xFE4F,
  25437. union: 0x222A,
  25438. universal: 0x2200,
  25439. uogonek: 0x0173,
  25440. uparen: 0x24B0,
  25441. upblock: 0x2580,
  25442. upperdothebrew: 0x05C4,
  25443. upsilon: 0x03C5,
  25444. upsilondieresis: 0x03CB,
  25445. upsilondieresistonos: 0x03B0,
  25446. upsilonlatin: 0x028A,
  25447. upsilontonos: 0x03CD,
  25448. uptackbelowcmb: 0x031D,
  25449. uptackmod: 0x02D4,
  25450. uragurmukhi: 0x0A73,
  25451. uring: 0x016F,
  25452. ushortcyrillic: 0x045E,
  25453. usmallhiragana: 0x3045,
  25454. usmallkatakana: 0x30A5,
  25455. usmallkatakanahalfwidth: 0xFF69,
  25456. ustraightcyrillic: 0x04AF,
  25457. ustraightstrokecyrillic: 0x04B1,
  25458. utilde: 0x0169,
  25459. utildeacute: 0x1E79,
  25460. utildebelow: 0x1E75,
  25461. uubengali: 0x098A,
  25462. uudeva: 0x090A,
  25463. uugujarati: 0x0A8A,
  25464. uugurmukhi: 0x0A0A,
  25465. uumatragurmukhi: 0x0A42,
  25466. uuvowelsignbengali: 0x09C2,
  25467. uuvowelsigndeva: 0x0942,
  25468. uuvowelsigngujarati: 0x0AC2,
  25469. uvowelsignbengali: 0x09C1,
  25470. uvowelsigndeva: 0x0941,
  25471. uvowelsigngujarati: 0x0AC1,
  25472. v: 0x0076,
  25473. vadeva: 0x0935,
  25474. vagujarati: 0x0AB5,
  25475. vagurmukhi: 0x0A35,
  25476. vakatakana: 0x30F7,
  25477. vav: 0x05D5,
  25478. vavdagesh: 0xFB35,
  25479. vavdagesh65: 0xFB35,
  25480. vavdageshhebrew: 0xFB35,
  25481. vavhebrew: 0x05D5,
  25482. vavholam: 0xFB4B,
  25483. vavholamhebrew: 0xFB4B,
  25484. vavvavhebrew: 0x05F0,
  25485. vavyodhebrew: 0x05F1,
  25486. vcircle: 0x24E5,
  25487. vdotbelow: 0x1E7F,
  25488. vecyrillic: 0x0432,
  25489. veharabic: 0x06A4,
  25490. vehfinalarabic: 0xFB6B,
  25491. vehinitialarabic: 0xFB6C,
  25492. vehmedialarabic: 0xFB6D,
  25493. vekatakana: 0x30F9,
  25494. venus: 0x2640,
  25495. verticalbar: 0x007C,
  25496. verticallineabovecmb: 0x030D,
  25497. verticallinebelowcmb: 0x0329,
  25498. verticallinelowmod: 0x02CC,
  25499. verticallinemod: 0x02C8,
  25500. vewarmenian: 0x057E,
  25501. vhook: 0x028B,
  25502. vikatakana: 0x30F8,
  25503. viramabengali: 0x09CD,
  25504. viramadeva: 0x094D,
  25505. viramagujarati: 0x0ACD,
  25506. visargabengali: 0x0983,
  25507. visargadeva: 0x0903,
  25508. visargagujarati: 0x0A83,
  25509. vmonospace: 0xFF56,
  25510. voarmenian: 0x0578,
  25511. voicediterationhiragana: 0x309E,
  25512. voicediterationkatakana: 0x30FE,
  25513. voicedmarkkana: 0x309B,
  25514. voicedmarkkanahalfwidth: 0xFF9E,
  25515. vokatakana: 0x30FA,
  25516. vparen: 0x24B1,
  25517. vtilde: 0x1E7D,
  25518. vturned: 0x028C,
  25519. vuhiragana: 0x3094,
  25520. vukatakana: 0x30F4,
  25521. w: 0x0077,
  25522. wacute: 0x1E83,
  25523. waekorean: 0x3159,
  25524. wahiragana: 0x308F,
  25525. wakatakana: 0x30EF,
  25526. wakatakanahalfwidth: 0xFF9C,
  25527. wakorean: 0x3158,
  25528. wasmallhiragana: 0x308E,
  25529. wasmallkatakana: 0x30EE,
  25530. wattosquare: 0x3357,
  25531. wavedash: 0x301C,
  25532. wavyunderscorevertical: 0xFE34,
  25533. wawarabic: 0x0648,
  25534. wawfinalarabic: 0xFEEE,
  25535. wawhamzaabovearabic: 0x0624,
  25536. wawhamzaabovefinalarabic: 0xFE86,
  25537. wbsquare: 0x33DD,
  25538. wcircle: 0x24E6,
  25539. wcircumflex: 0x0175,
  25540. wdieresis: 0x1E85,
  25541. wdotaccent: 0x1E87,
  25542. wdotbelow: 0x1E89,
  25543. wehiragana: 0x3091,
  25544. weierstrass: 0x2118,
  25545. wekatakana: 0x30F1,
  25546. wekorean: 0x315E,
  25547. weokorean: 0x315D,
  25548. wgrave: 0x1E81,
  25549. whitebullet: 0x25E6,
  25550. whitecircle: 0x25CB,
  25551. whitecircleinverse: 0x25D9,
  25552. whitecornerbracketleft: 0x300E,
  25553. whitecornerbracketleftvertical: 0xFE43,
  25554. whitecornerbracketright: 0x300F,
  25555. whitecornerbracketrightvertical: 0xFE44,
  25556. whitediamond: 0x25C7,
  25557. whitediamondcontainingblacksmalldiamond: 0x25C8,
  25558. whitedownpointingsmalltriangle: 0x25BF,
  25559. whitedownpointingtriangle: 0x25BD,
  25560. whiteleftpointingsmalltriangle: 0x25C3,
  25561. whiteleftpointingtriangle: 0x25C1,
  25562. whitelenticularbracketleft: 0x3016,
  25563. whitelenticularbracketright: 0x3017,
  25564. whiterightpointingsmalltriangle: 0x25B9,
  25565. whiterightpointingtriangle: 0x25B7,
  25566. whitesmallsquare: 0x25AB,
  25567. whitesmilingface: 0x263A,
  25568. whitesquare: 0x25A1,
  25569. whitestar: 0x2606,
  25570. whitetelephone: 0x260F,
  25571. whitetortoiseshellbracketleft: 0x3018,
  25572. whitetortoiseshellbracketright: 0x3019,
  25573. whiteuppointingsmalltriangle: 0x25B5,
  25574. whiteuppointingtriangle: 0x25B3,
  25575. wihiragana: 0x3090,
  25576. wikatakana: 0x30F0,
  25577. wikorean: 0x315F,
  25578. wmonospace: 0xFF57,
  25579. wohiragana: 0x3092,
  25580. wokatakana: 0x30F2,
  25581. wokatakanahalfwidth: 0xFF66,
  25582. won: 0x20A9,
  25583. wonmonospace: 0xFFE6,
  25584. wowaenthai: 0x0E27,
  25585. wparen: 0x24B2,
  25586. wring: 0x1E98,
  25587. wsuperior: 0x02B7,
  25588. wturned: 0x028D,
  25589. wynn: 0x01BF,
  25590. x: 0x0078,
  25591. xabovecmb: 0x033D,
  25592. xbopomofo: 0x3112,
  25593. xcircle: 0x24E7,
  25594. xdieresis: 0x1E8D,
  25595. xdotaccent: 0x1E8B,
  25596. xeharmenian: 0x056D,
  25597. xi: 0x03BE,
  25598. xmonospace: 0xFF58,
  25599. xparen: 0x24B3,
  25600. xsuperior: 0x02E3,
  25601. y: 0x0079,
  25602. yaadosquare: 0x334E,
  25603. yabengali: 0x09AF,
  25604. yacute: 0x00FD,
  25605. yadeva: 0x092F,
  25606. yaekorean: 0x3152,
  25607. yagujarati: 0x0AAF,
  25608. yagurmukhi: 0x0A2F,
  25609. yahiragana: 0x3084,
  25610. yakatakana: 0x30E4,
  25611. yakatakanahalfwidth: 0xFF94,
  25612. yakorean: 0x3151,
  25613. yamakkanthai: 0x0E4E,
  25614. yasmallhiragana: 0x3083,
  25615. yasmallkatakana: 0x30E3,
  25616. yasmallkatakanahalfwidth: 0xFF6C,
  25617. yatcyrillic: 0x0463,
  25618. ycircle: 0x24E8,
  25619. ycircumflex: 0x0177,
  25620. ydieresis: 0x00FF,
  25621. ydotaccent: 0x1E8F,
  25622. ydotbelow: 0x1EF5,
  25623. yeharabic: 0x064A,
  25624. yehbarreearabic: 0x06D2,
  25625. yehbarreefinalarabic: 0xFBAF,
  25626. yehfinalarabic: 0xFEF2,
  25627. yehhamzaabovearabic: 0x0626,
  25628. yehhamzaabovefinalarabic: 0xFE8A,
  25629. yehhamzaaboveinitialarabic: 0xFE8B,
  25630. yehhamzaabovemedialarabic: 0xFE8C,
  25631. yehinitialarabic: 0xFEF3,
  25632. yehmedialarabic: 0xFEF4,
  25633. yehmeeminitialarabic: 0xFCDD,
  25634. yehmeemisolatedarabic: 0xFC58,
  25635. yehnoonfinalarabic: 0xFC94,
  25636. yehthreedotsbelowarabic: 0x06D1,
  25637. yekorean: 0x3156,
  25638. yen: 0x00A5,
  25639. yenmonospace: 0xFFE5,
  25640. yeokorean: 0x3155,
  25641. yeorinhieuhkorean: 0x3186,
  25642. yerahbenyomohebrew: 0x05AA,
  25643. yerahbenyomolefthebrew: 0x05AA,
  25644. yericyrillic: 0x044B,
  25645. yerudieresiscyrillic: 0x04F9,
  25646. yesieungkorean: 0x3181,
  25647. yesieungpansioskorean: 0x3183,
  25648. yesieungsioskorean: 0x3182,
  25649. yetivhebrew: 0x059A,
  25650. ygrave: 0x1EF3,
  25651. yhook: 0x01B4,
  25652. yhookabove: 0x1EF7,
  25653. yiarmenian: 0x0575,
  25654. yicyrillic: 0x0457,
  25655. yikorean: 0x3162,
  25656. yinyang: 0x262F,
  25657. yiwnarmenian: 0x0582,
  25658. ymonospace: 0xFF59,
  25659. yod: 0x05D9,
  25660. yoddagesh: 0xFB39,
  25661. yoddageshhebrew: 0xFB39,
  25662. yodhebrew: 0x05D9,
  25663. yodyodhebrew: 0x05F2,
  25664. yodyodpatahhebrew: 0xFB1F,
  25665. yohiragana: 0x3088,
  25666. yoikorean: 0x3189,
  25667. yokatakana: 0x30E8,
  25668. yokatakanahalfwidth: 0xFF96,
  25669. yokorean: 0x315B,
  25670. yosmallhiragana: 0x3087,
  25671. yosmallkatakana: 0x30E7,
  25672. yosmallkatakanahalfwidth: 0xFF6E,
  25673. yotgreek: 0x03F3,
  25674. yoyaekorean: 0x3188,
  25675. yoyakorean: 0x3187,
  25676. yoyakthai: 0x0E22,
  25677. yoyingthai: 0x0E0D,
  25678. yparen: 0x24B4,
  25679. ypogegrammeni: 0x037A,
  25680. ypogegrammenigreekcmb: 0x0345,
  25681. yr: 0x01A6,
  25682. yring: 0x1E99,
  25683. ysuperior: 0x02B8,
  25684. ytilde: 0x1EF9,
  25685. yturned: 0x028E,
  25686. yuhiragana: 0x3086,
  25687. yuikorean: 0x318C,
  25688. yukatakana: 0x30E6,
  25689. yukatakanahalfwidth: 0xFF95,
  25690. yukorean: 0x3160,
  25691. yusbigcyrillic: 0x046B,
  25692. yusbigiotifiedcyrillic: 0x046D,
  25693. yuslittlecyrillic: 0x0467,
  25694. yuslittleiotifiedcyrillic: 0x0469,
  25695. yusmallhiragana: 0x3085,
  25696. yusmallkatakana: 0x30E5,
  25697. yusmallkatakanahalfwidth: 0xFF6D,
  25698. yuyekorean: 0x318B,
  25699. yuyeokorean: 0x318A,
  25700. yyabengali: 0x09DF,
  25701. yyadeva: 0x095F,
  25702. z: 0x007A,
  25703. zaarmenian: 0x0566,
  25704. zacute: 0x017A,
  25705. zadeva: 0x095B,
  25706. zagurmukhi: 0x0A5B,
  25707. zaharabic: 0x0638,
  25708. zahfinalarabic: 0xFEC6,
  25709. zahinitialarabic: 0xFEC7,
  25710. zahiragana: 0x3056,
  25711. zahmedialarabic: 0xFEC8,
  25712. zainarabic: 0x0632,
  25713. zainfinalarabic: 0xFEB0,
  25714. zakatakana: 0x30B6,
  25715. zaqefgadolhebrew: 0x0595,
  25716. zaqefqatanhebrew: 0x0594,
  25717. zarqahebrew: 0x0598,
  25718. zayin: 0x05D6,
  25719. zayindagesh: 0xFB36,
  25720. zayindageshhebrew: 0xFB36,
  25721. zayinhebrew: 0x05D6,
  25722. zbopomofo: 0x3117,
  25723. zcaron: 0x017E,
  25724. zcircle: 0x24E9,
  25725. zcircumflex: 0x1E91,
  25726. zcurl: 0x0291,
  25727. zdot: 0x017C,
  25728. zdotaccent: 0x017C,
  25729. zdotbelow: 0x1E93,
  25730. zecyrillic: 0x0437,
  25731. zedescendercyrillic: 0x0499,
  25732. zedieresiscyrillic: 0x04DF,
  25733. zehiragana: 0x305C,
  25734. zekatakana: 0x30BC,
  25735. zero: 0x0030,
  25736. zeroarabic: 0x0660,
  25737. zerobengali: 0x09E6,
  25738. zerodeva: 0x0966,
  25739. zerogujarati: 0x0AE6,
  25740. zerogurmukhi: 0x0A66,
  25741. zerohackarabic: 0x0660,
  25742. zeroinferior: 0x2080,
  25743. zeromonospace: 0xFF10,
  25744. zerooldstyle: 0xF730,
  25745. zeropersian: 0x06F0,
  25746. zerosuperior: 0x2070,
  25747. zerothai: 0x0E50,
  25748. zerowidthjoiner: 0xFEFF,
  25749. zerowidthnonjoiner: 0x200C,
  25750. zerowidthspace: 0x200B,
  25751. zeta: 0x03B6,
  25752. zhbopomofo: 0x3113,
  25753. zhearmenian: 0x056A,
  25754. zhebrevecyrillic: 0x04C2,
  25755. zhecyrillic: 0x0436,
  25756. zhedescendercyrillic: 0x0497,
  25757. zhedieresiscyrillic: 0x04DD,
  25758. zihiragana: 0x3058,
  25759. zikatakana: 0x30B8,
  25760. zinorhebrew: 0x05AE,
  25761. zlinebelow: 0x1E95,
  25762. zmonospace: 0xFF5A,
  25763. zohiragana: 0x305E,
  25764. zokatakana: 0x30BE,
  25765. zparen: 0x24B5,
  25766. zretroflexhook: 0x0290,
  25767. zstroke: 0x01B6,
  25768. zuhiragana: 0x305A,
  25769. zukatakana: 0x30BA,
  25770. '.notdef': 0x0000
  25771. };
  25772. var DingbatsGlyphsUnicode = {
  25773. space: 0x0020,
  25774. a1: 0x2701,
  25775. a2: 0x2702,
  25776. a202: 0x2703,
  25777. a3: 0x2704,
  25778. a4: 0x260E,
  25779. a5: 0x2706,
  25780. a119: 0x2707,
  25781. a118: 0x2708,
  25782. a117: 0x2709,
  25783. a11: 0x261B,
  25784. a12: 0x261E,
  25785. a13: 0x270C,
  25786. a14: 0x270D,
  25787. a15: 0x270E,
  25788. a16: 0x270F,
  25789. a105: 0x2710,
  25790. a17: 0x2711,
  25791. a18: 0x2712,
  25792. a19: 0x2713,
  25793. a20: 0x2714,
  25794. a21: 0x2715,
  25795. a22: 0x2716,
  25796. a23: 0x2717,
  25797. a24: 0x2718,
  25798. a25: 0x2719,
  25799. a26: 0x271A,
  25800. a27: 0x271B,
  25801. a28: 0x271C,
  25802. a6: 0x271D,
  25803. a7: 0x271E,
  25804. a8: 0x271F,
  25805. a9: 0x2720,
  25806. a10: 0x2721,
  25807. a29: 0x2722,
  25808. a30: 0x2723,
  25809. a31: 0x2724,
  25810. a32: 0x2725,
  25811. a33: 0x2726,
  25812. a34: 0x2727,
  25813. a35: 0x2605,
  25814. a36: 0x2729,
  25815. a37: 0x272A,
  25816. a38: 0x272B,
  25817. a39: 0x272C,
  25818. a40: 0x272D,
  25819. a41: 0x272E,
  25820. a42: 0x272F,
  25821. a43: 0x2730,
  25822. a44: 0x2731,
  25823. a45: 0x2732,
  25824. a46: 0x2733,
  25825. a47: 0x2734,
  25826. a48: 0x2735,
  25827. a49: 0x2736,
  25828. a50: 0x2737,
  25829. a51: 0x2738,
  25830. a52: 0x2739,
  25831. a53: 0x273A,
  25832. a54: 0x273B,
  25833. a55: 0x273C,
  25834. a56: 0x273D,
  25835. a57: 0x273E,
  25836. a58: 0x273F,
  25837. a59: 0x2740,
  25838. a60: 0x2741,
  25839. a61: 0x2742,
  25840. a62: 0x2743,
  25841. a63: 0x2744,
  25842. a64: 0x2745,
  25843. a65: 0x2746,
  25844. a66: 0x2747,
  25845. a67: 0x2748,
  25846. a68: 0x2749,
  25847. a69: 0x274A,
  25848. a70: 0x274B,
  25849. a71: 0x25CF,
  25850. a72: 0x274D,
  25851. a73: 0x25A0,
  25852. a74: 0x274F,
  25853. a203: 0x2750,
  25854. a75: 0x2751,
  25855. a204: 0x2752,
  25856. a76: 0x25B2,
  25857. a77: 0x25BC,
  25858. a78: 0x25C6,
  25859. a79: 0x2756,
  25860. a81: 0x25D7,
  25861. a82: 0x2758,
  25862. a83: 0x2759,
  25863. a84: 0x275A,
  25864. a97: 0x275B,
  25865. a98: 0x275C,
  25866. a99: 0x275D,
  25867. a100: 0x275E,
  25868. a101: 0x2761,
  25869. a102: 0x2762,
  25870. a103: 0x2763,
  25871. a104: 0x2764,
  25872. a106: 0x2765,
  25873. a107: 0x2766,
  25874. a108: 0x2767,
  25875. a112: 0x2663,
  25876. a111: 0x2666,
  25877. a110: 0x2665,
  25878. a109: 0x2660,
  25879. a120: 0x2460,
  25880. a121: 0x2461,
  25881. a122: 0x2462,
  25882. a123: 0x2463,
  25883. a124: 0x2464,
  25884. a125: 0x2465,
  25885. a126: 0x2466,
  25886. a127: 0x2467,
  25887. a128: 0x2468,
  25888. a129: 0x2469,
  25889. a130: 0x2776,
  25890. a131: 0x2777,
  25891. a132: 0x2778,
  25892. a133: 0x2779,
  25893. a134: 0x277A,
  25894. a135: 0x277B,
  25895. a136: 0x277C,
  25896. a137: 0x277D,
  25897. a138: 0x277E,
  25898. a139: 0x277F,
  25899. a140: 0x2780,
  25900. a141: 0x2781,
  25901. a142: 0x2782,
  25902. a143: 0x2783,
  25903. a144: 0x2784,
  25904. a145: 0x2785,
  25905. a146: 0x2786,
  25906. a147: 0x2787,
  25907. a148: 0x2788,
  25908. a149: 0x2789,
  25909. a150: 0x278A,
  25910. a151: 0x278B,
  25911. a152: 0x278C,
  25912. a153: 0x278D,
  25913. a154: 0x278E,
  25914. a155: 0x278F,
  25915. a156: 0x2790,
  25916. a157: 0x2791,
  25917. a158: 0x2792,
  25918. a159: 0x2793,
  25919. a160: 0x2794,
  25920. a161: 0x2192,
  25921. a163: 0x2194,
  25922. a164: 0x2195,
  25923. a196: 0x2798,
  25924. a165: 0x2799,
  25925. a192: 0x279A,
  25926. a166: 0x279B,
  25927. a167: 0x279C,
  25928. a168: 0x279D,
  25929. a169: 0x279E,
  25930. a170: 0x279F,
  25931. a171: 0x27A0,
  25932. a172: 0x27A1,
  25933. a173: 0x27A2,
  25934. a162: 0x27A3,
  25935. a174: 0x27A4,
  25936. a175: 0x27A5,
  25937. a176: 0x27A6,
  25938. a177: 0x27A7,
  25939. a178: 0x27A8,
  25940. a179: 0x27A9,
  25941. a193: 0x27AA,
  25942. a180: 0x27AB,
  25943. a199: 0x27AC,
  25944. a181: 0x27AD,
  25945. a200: 0x27AE,
  25946. a182: 0x27AF,
  25947. a201: 0x27B1,
  25948. a183: 0x27B2,
  25949. a184: 0x27B3,
  25950. a197: 0x27B4,
  25951. a185: 0x27B5,
  25952. a194: 0x27B6,
  25953. a198: 0x27B7,
  25954. a186: 0x27B8,
  25955. a195: 0x27B9,
  25956. a187: 0x27BA,
  25957. a188: 0x27BB,
  25958. a189: 0x27BC,
  25959. a190: 0x27BD,
  25960. a191: 0x27BE,
  25961. a89: 0x2768, // 0xF8D7
  25962. a90: 0x2769, // 0xF8D8
  25963. a93: 0x276A, // 0xF8D9
  25964. a94: 0x276B, // 0xF8DA
  25965. a91: 0x276C, // 0xF8DB
  25966. a92: 0x276D, // 0xF8DC
  25967. a205: 0x276E, // 0xF8DD
  25968. a85: 0x276F, // 0xF8DE
  25969. a206: 0x2770, // 0xF8DF
  25970. a86: 0x2771, // 0xF8E0
  25971. a87: 0x2772, // 0xF8E1
  25972. a88: 0x2773, // 0xF8E2
  25973. a95: 0x2774, // 0xF8E3
  25974. a96: 0x2775, // 0xF8E4
  25975. '.notdef': 0x0000
  25976. };
  25977. var PDFImage = (function PDFImageClosure() {
  25978. /**
  25979. * Decode the image in the main thread if it supported. Resovles the promise
  25980. * when the image data is ready.
  25981. */
  25982. function handleImageData(handler, xref, res, image) {
  25983. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  25984. // For natively supported jpegs send them to the main thread for decoding.
  25985. var dict = image.dict;
  25986. var colorSpace = dict.get('ColorSpace', 'CS');
  25987. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25988. var numComps = colorSpace.numComps;
  25989. var decodePromise = handler.sendWithPromise('JpegDecode',
  25990. [image.getIR(), numComps]);
  25991. return decodePromise.then(function (message) {
  25992. var data = message.data;
  25993. return new Stream(data, 0, data.length, image.dict);
  25994. });
  25995. } else {
  25996. return Promise.resolve(image);
  25997. }
  25998. }
  25999. /**
  26000. * Decode and clamp a value. The formula is different from the spec because we
  26001. * don't decode to float range [0,1], we decode it in the [0,max] range.
  26002. */
  26003. function decodeAndClamp(value, addend, coefficient, max) {
  26004. value = addend + value * coefficient;
  26005. // Clamp the value to the range
  26006. return (value < 0 ? 0 : (value > max ? max : value));
  26007. }
  26008. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  26009. this.image = image;
  26010. var dict = image.dict;
  26011. if (dict.has('Filter')) {
  26012. var filter = dict.get('Filter').name;
  26013. if (filter === 'JPXDecode') {
  26014. var jpxImage = new JpxImage();
  26015. jpxImage.parseImageProperties(image.stream);
  26016. image.stream.reset();
  26017. image.bitsPerComponent = jpxImage.bitsPerComponent;
  26018. image.numComps = jpxImage.componentsCount;
  26019. } else if (filter === 'JBIG2Decode') {
  26020. image.bitsPerComponent = 1;
  26021. image.numComps = 1;
  26022. }
  26023. }
  26024. // TODO cache rendered images?
  26025. this.width = dict.get('Width', 'W');
  26026. this.height = dict.get('Height', 'H');
  26027. if (this.width < 1 || this.height < 1) {
  26028. error('Invalid image width: ' + this.width + ' or height: ' +
  26029. this.height);
  26030. }
  26031. this.interpolate = dict.get('Interpolate', 'I') || false;
  26032. this.imageMask = dict.get('ImageMask', 'IM') || false;
  26033. this.matte = dict.get('Matte') || false;
  26034. var bitsPerComponent = image.bitsPerComponent;
  26035. if (!bitsPerComponent) {
  26036. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  26037. if (!bitsPerComponent) {
  26038. if (this.imageMask) {
  26039. bitsPerComponent = 1;
  26040. } else {
  26041. error('Bits per component missing in image: ' + this.imageMask);
  26042. }
  26043. }
  26044. }
  26045. this.bpc = bitsPerComponent;
  26046. if (!this.imageMask) {
  26047. var colorSpace = dict.get('ColorSpace', 'CS');
  26048. if (!colorSpace) {
  26049. info('JPX images (which do not require color spaces)');
  26050. switch (image.numComps) {
  26051. case 1:
  26052. colorSpace = Name.get('DeviceGray');
  26053. break;
  26054. case 3:
  26055. colorSpace = Name.get('DeviceRGB');
  26056. break;
  26057. case 4:
  26058. colorSpace = Name.get('DeviceCMYK');
  26059. break;
  26060. default:
  26061. error('JPX images with ' + this.numComps +
  26062. ' color components not supported.');
  26063. }
  26064. }
  26065. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  26066. this.numComps = this.colorSpace.numComps;
  26067. }
  26068. this.decode = dict.get('Decode', 'D');
  26069. this.needsDecode = false;
  26070. if (this.decode &&
  26071. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  26072. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  26073. this.needsDecode = true;
  26074. // Do some preprocessing to avoid more math.
  26075. var max = (1 << bitsPerComponent) - 1;
  26076. this.decodeCoefficients = [];
  26077. this.decodeAddends = [];
  26078. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  26079. var dmin = this.decode[i];
  26080. var dmax = this.decode[i + 1];
  26081. this.decodeCoefficients[j] = dmax - dmin;
  26082. this.decodeAddends[j] = max * dmin;
  26083. }
  26084. }
  26085. if (smask) {
  26086. this.smask = new PDFImage(xref, res, smask, false);
  26087. } else if (mask) {
  26088. if (isStream(mask)) {
  26089. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  26090. if (!imageMask) {
  26091. warn('Ignoring /Mask in image without /ImageMask.');
  26092. } else {
  26093. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  26094. }
  26095. } else {
  26096. // Color key mask (just an array).
  26097. this.mask = mask;
  26098. }
  26099. }
  26100. }
  26101. /**
  26102. * Handles processing of image data and returns the Promise that is resolved
  26103. * with a PDFImage when the image is ready to be used.
  26104. */
  26105. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  26106. res, image, inline) {
  26107. var imagePromise = handleImageData(handler, xref, res, image);
  26108. var smaskPromise;
  26109. var maskPromise;
  26110. var smask = image.dict.get('SMask');
  26111. var mask = image.dict.get('Mask');
  26112. if (smask) {
  26113. smaskPromise = handleImageData(handler, xref, res, smask);
  26114. maskPromise = Promise.resolve(null);
  26115. } else {
  26116. smaskPromise = Promise.resolve(null);
  26117. if (mask) {
  26118. if (isStream(mask)) {
  26119. maskPromise = handleImageData(handler, xref, res, mask);
  26120. } else if (isArray(mask)) {
  26121. maskPromise = Promise.resolve(mask);
  26122. } else {
  26123. warn('Unsupported mask format.');
  26124. maskPromise = Promise.resolve(null);
  26125. }
  26126. } else {
  26127. maskPromise = Promise.resolve(null);
  26128. }
  26129. }
  26130. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  26131. function(results) {
  26132. var imageData = results[0];
  26133. var smaskData = results[1];
  26134. var maskData = results[2];
  26135. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  26136. });
  26137. };
  26138. /**
  26139. * Resize an image using the nearest neighbor algorithm. Currently only
  26140. * supports one and three component images.
  26141. * @param {TypedArray} pixels The original image with one component.
  26142. * @param {Number} bpc Number of bits per component.
  26143. * @param {Number} components Number of color components, 1 or 3 is supported.
  26144. * @param {Number} w1 Original width.
  26145. * @param {Number} h1 Original height.
  26146. * @param {Number} w2 New width.
  26147. * @param {Number} h2 New height.
  26148. * @param {TypedArray} dest (Optional) The destination buffer.
  26149. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  26150. * @return {TypedArray} Resized image data.
  26151. */
  26152. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  26153. w1, h1, w2, h2, dest, alpha01) {
  26154. if (components !== 1 && components !== 3) {
  26155. error('Unsupported component count for resizing.');
  26156. }
  26157. var length = w2 * h2 * components;
  26158. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  26159. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  26160. var xRatio = w1 / w2;
  26161. var yRatio = h1 / h2;
  26162. var i, j, py, newIndex = 0, oldIndex;
  26163. var xScaled = new Uint16Array(w2);
  26164. var w1Scanline = w1 * components;
  26165. if (alpha01 !== 1) {
  26166. alpha01 = 0;
  26167. }
  26168. for (j = 0; j < w2; j++) {
  26169. xScaled[j] = Math.floor(j * xRatio) * components;
  26170. }
  26171. if (components === 1) {
  26172. for (i = 0; i < h2; i++) {
  26173. py = Math.floor(i * yRatio) * w1Scanline;
  26174. for (j = 0; j < w2; j++) {
  26175. oldIndex = py + xScaled[j];
  26176. temp[newIndex++] = pixels[oldIndex];
  26177. }
  26178. }
  26179. } else if (components === 3) {
  26180. for (i = 0; i < h2; i++) {
  26181. py = Math.floor(i * yRatio) * w1Scanline;
  26182. for (j = 0; j < w2; j++) {
  26183. oldIndex = py + xScaled[j];
  26184. temp[newIndex++] = pixels[oldIndex++];
  26185. temp[newIndex++] = pixels[oldIndex++];
  26186. temp[newIndex++] = pixels[oldIndex++];
  26187. newIndex += alpha01;
  26188. }
  26189. }
  26190. }
  26191. return temp;
  26192. };
  26193. PDFImage.createMask =
  26194. function PDFImage_createMask(imgArray, width, height,
  26195. imageIsFromDecodeStream, inverseDecode) {
  26196. // |imgArray| might not contain full data for every pixel of the mask, so
  26197. // we need to distinguish between |computedLength| and |actualLength|.
  26198. // In particular, if inverseDecode is true, then the array we return must
  26199. // have a length of |computedLength|.
  26200. var computedLength = ((width + 7) >> 3) * height;
  26201. var actualLength = imgArray.byteLength;
  26202. var haveFullData = computedLength === actualLength;
  26203. var data, i;
  26204. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  26205. // imgArray came from a DecodeStream and its data is in an appropriate
  26206. // form, so we can just transfer it.
  26207. data = imgArray;
  26208. } else if (!inverseDecode) {
  26209. data = new Uint8Array(actualLength);
  26210. data.set(imgArray);
  26211. } else {
  26212. data = new Uint8Array(computedLength);
  26213. data.set(imgArray);
  26214. for (i = actualLength; i < computedLength; i++) {
  26215. data[i] = 0xff;
  26216. }
  26217. }
  26218. // If necessary, invert the original mask data (but not any extra we might
  26219. // have added above). It's safe to modify the array -- whether it's the
  26220. // original or a copy, we're about to transfer it anyway, so nothing else
  26221. // in this thread can be relying on its contents.
  26222. if (inverseDecode) {
  26223. for (i = 0; i < actualLength; i++) {
  26224. data[i] = ~data[i];
  26225. }
  26226. }
  26227. return {data: data, width: width, height: height};
  26228. };
  26229. PDFImage.prototype = {
  26230. get drawWidth() {
  26231. return Math.max(this.width,
  26232. this.smask && this.smask.width || 0,
  26233. this.mask && this.mask.width || 0);
  26234. },
  26235. get drawHeight() {
  26236. return Math.max(this.height,
  26237. this.smask && this.smask.height || 0,
  26238. this.mask && this.mask.height || 0);
  26239. },
  26240. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  26241. var bpc = this.bpc;
  26242. var numComps = this.numComps;
  26243. var decodeAddends = this.decodeAddends;
  26244. var decodeCoefficients = this.decodeCoefficients;
  26245. var max = (1 << bpc) - 1;
  26246. var i, ii;
  26247. if (bpc === 1) {
  26248. // If the buffer needed decode that means it just needs to be inverted.
  26249. for (i = 0, ii = buffer.length; i < ii; i++) {
  26250. buffer[i] = +!(buffer[i]);
  26251. }
  26252. return;
  26253. }
  26254. var index = 0;
  26255. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  26256. for (var j = 0; j < numComps; j++) {
  26257. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  26258. decodeCoefficients[j], max);
  26259. index++;
  26260. }
  26261. }
  26262. },
  26263. getComponents: function PDFImage_getComponents(buffer) {
  26264. var bpc = this.bpc;
  26265. // This image doesn't require any extra work.
  26266. if (bpc === 8) {
  26267. return buffer;
  26268. }
  26269. var width = this.width;
  26270. var height = this.height;
  26271. var numComps = this.numComps;
  26272. var length = width * height * numComps;
  26273. var bufferPos = 0;
  26274. var output = (bpc <= 8 ? new Uint8Array(length) :
  26275. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  26276. var rowComps = width * numComps;
  26277. var max = (1 << bpc) - 1;
  26278. var i = 0, ii, buf;
  26279. if (bpc === 1) {
  26280. // Optimization for reading 1 bpc images.
  26281. var mask, loop1End, loop2End;
  26282. for (var j = 0; j < height; j++) {
  26283. loop1End = i + (rowComps & ~7);
  26284. loop2End = i + rowComps;
  26285. // unroll loop for all full bytes
  26286. while (i < loop1End) {
  26287. buf = buffer[bufferPos++];
  26288. output[i] = (buf >> 7) & 1;
  26289. output[i + 1] = (buf >> 6) & 1;
  26290. output[i + 2] = (buf >> 5) & 1;
  26291. output[i + 3] = (buf >> 4) & 1;
  26292. output[i + 4] = (buf >> 3) & 1;
  26293. output[i + 5] = (buf >> 2) & 1;
  26294. output[i + 6] = (buf >> 1) & 1;
  26295. output[i + 7] = buf & 1;
  26296. i += 8;
  26297. }
  26298. // handle remaing bits
  26299. if (i < loop2End) {
  26300. buf = buffer[bufferPos++];
  26301. mask = 128;
  26302. while (i < loop2End) {
  26303. output[i++] = +!!(buf & mask);
  26304. mask >>= 1;
  26305. }
  26306. }
  26307. }
  26308. } else {
  26309. // The general case that handles all other bpc values.
  26310. var bits = 0;
  26311. buf = 0;
  26312. for (i = 0, ii = length; i < ii; ++i) {
  26313. if (i % rowComps === 0) {
  26314. buf = 0;
  26315. bits = 0;
  26316. }
  26317. while (bits < bpc) {
  26318. buf = (buf << 8) | buffer[bufferPos++];
  26319. bits += 8;
  26320. }
  26321. var remainingBits = bits - bpc;
  26322. var value = buf >> remainingBits;
  26323. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  26324. buf = buf & ((1 << remainingBits) - 1);
  26325. bits = remainingBits;
  26326. }
  26327. }
  26328. return output;
  26329. },
  26330. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  26331. actualHeight, image) {
  26332. var smask = this.smask;
  26333. var mask = this.mask;
  26334. var alphaBuf, sw, sh, i, ii, j;
  26335. if (smask) {
  26336. sw = smask.width;
  26337. sh = smask.height;
  26338. alphaBuf = new Uint8Array(sw * sh);
  26339. smask.fillGrayBuffer(alphaBuf);
  26340. if (sw !== width || sh !== height) {
  26341. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  26342. height);
  26343. }
  26344. } else if (mask) {
  26345. if (mask instanceof PDFImage) {
  26346. sw = mask.width;
  26347. sh = mask.height;
  26348. alphaBuf = new Uint8Array(sw * sh);
  26349. mask.numComps = 1;
  26350. mask.fillGrayBuffer(alphaBuf);
  26351. // Need to invert values in rgbaBuf
  26352. for (i = 0, ii = sw * sh; i < ii; ++i) {
  26353. alphaBuf[i] = 255 - alphaBuf[i];
  26354. }
  26355. if (sw !== width || sh !== height) {
  26356. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  26357. height);
  26358. }
  26359. } else if (isArray(mask)) {
  26360. // Color key mask: if any of the compontents are outside the range
  26361. // then they should be painted.
  26362. alphaBuf = new Uint8Array(width * height);
  26363. var numComps = this.numComps;
  26364. for (i = 0, ii = width * height; i < ii; ++i) {
  26365. var opacity = 0;
  26366. var imageOffset = i * numComps;
  26367. for (j = 0; j < numComps; ++j) {
  26368. var color = image[imageOffset + j];
  26369. var maskOffset = j * 2;
  26370. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  26371. opacity = 255;
  26372. break;
  26373. }
  26374. }
  26375. alphaBuf[i] = opacity;
  26376. }
  26377. } else {
  26378. error('Unknown mask format.');
  26379. }
  26380. }
  26381. if (alphaBuf) {
  26382. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  26383. rgbaBuf[j] = alphaBuf[i];
  26384. }
  26385. } else {
  26386. // No mask.
  26387. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  26388. rgbaBuf[j] = 255;
  26389. }
  26390. }
  26391. },
  26392. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  26393. var matte = this.smask && this.smask.matte;
  26394. if (!matte) {
  26395. return;
  26396. }
  26397. var matteRgb = this.colorSpace.getRgb(matte, 0);
  26398. var matteR = matteRgb[0];
  26399. var matteG = matteRgb[1];
  26400. var matteB = matteRgb[2];
  26401. var length = width * height * 4;
  26402. var r, g, b;
  26403. for (var i = 0; i < length; i += 4) {
  26404. var alpha = buffer[i + 3];
  26405. if (alpha === 0) {
  26406. // according formula we have to get Infinity in all components
  26407. // making it white (typical paper color) should be okay
  26408. buffer[i] = 255;
  26409. buffer[i + 1] = 255;
  26410. buffer[i + 2] = 255;
  26411. continue;
  26412. }
  26413. var k = 255 / alpha;
  26414. r = (buffer[i] - matteR) * k + matteR;
  26415. g = (buffer[i + 1] - matteG) * k + matteG;
  26416. b = (buffer[i + 2] - matteB) * k + matteB;
  26417. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  26418. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  26419. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  26420. }
  26421. },
  26422. createImageData: function PDFImage_createImageData(forceRGBA) {
  26423. var drawWidth = this.drawWidth;
  26424. var drawHeight = this.drawHeight;
  26425. var imgData = { // other fields are filled in below
  26426. width: drawWidth,
  26427. height: drawHeight
  26428. };
  26429. var numComps = this.numComps;
  26430. var originalWidth = this.width;
  26431. var originalHeight = this.height;
  26432. var bpc = this.bpc;
  26433. // Rows start at byte boundary.
  26434. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  26435. var imgArray;
  26436. if (!forceRGBA) {
  26437. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  26438. // without any complications, we pass a same-sized copy to the main
  26439. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  26440. // of memory for many scanned documents. It's also much faster.
  26441. //
  26442. // Similarly, if it is a 24-bit-per pixel RGB image without any
  26443. // complications, we avoid expanding by 1.333x to RGBA form.
  26444. var kind;
  26445. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  26446. kind = ImageKind.GRAYSCALE_1BPP;
  26447. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  26448. !this.needsDecode) {
  26449. kind = ImageKind.RGB_24BPP;
  26450. }
  26451. if (kind && !this.smask && !this.mask &&
  26452. drawWidth === originalWidth && drawHeight === originalHeight) {
  26453. imgData.kind = kind;
  26454. imgArray = this.getImageBytes(originalHeight * rowBytes);
  26455. // If imgArray came from a DecodeStream, we're safe to transfer it
  26456. // (and thus neuter it) because it will constitute the entire
  26457. // DecodeStream's data. But if it came from a Stream, we need to
  26458. // copy it because it'll only be a portion of the Stream's data, and
  26459. // the rest will be read later on.
  26460. if (this.image instanceof DecodeStream) {
  26461. imgData.data = imgArray;
  26462. } else {
  26463. var newArray = new Uint8Array(imgArray.length);
  26464. newArray.set(imgArray);
  26465. imgData.data = newArray;
  26466. }
  26467. if (this.needsDecode) {
  26468. // Invert the buffer (which must be grayscale if we reached here).
  26469. assert(kind === ImageKind.GRAYSCALE_1BPP);
  26470. var buffer = imgData.data;
  26471. for (var i = 0, ii = buffer.length; i < ii; i++) {
  26472. buffer[i] ^= 0xff;
  26473. }
  26474. }
  26475. return imgData;
  26476. }
  26477. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  26478. (this.colorSpace.name === 'DeviceGray' ||
  26479. this.colorSpace.name === 'DeviceRGB' ||
  26480. this.colorSpace.name === 'DeviceCMYK')) {
  26481. imgData.kind = ImageKind.RGB_24BPP;
  26482. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  26483. drawWidth, drawHeight, true);
  26484. return imgData;
  26485. }
  26486. }
  26487. imgArray = this.getImageBytes(originalHeight * rowBytes);
  26488. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  26489. var actualHeight = 0 | (imgArray.length / rowBytes *
  26490. drawHeight / originalHeight);
  26491. var comps = this.getComponents(imgArray);
  26492. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  26493. // more compact RGB_24BPP form if allowable.
  26494. var alpha01, maybeUndoPreblend;
  26495. if (!forceRGBA && !this.smask && !this.mask) {
  26496. imgData.kind = ImageKind.RGB_24BPP;
  26497. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  26498. alpha01 = 0;
  26499. maybeUndoPreblend = false;
  26500. } else {
  26501. imgData.kind = ImageKind.RGBA_32BPP;
  26502. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  26503. alpha01 = 1;
  26504. maybeUndoPreblend = true;
  26505. // Color key masking (opacity) must be performed before decoding.
  26506. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  26507. comps);
  26508. }
  26509. if (this.needsDecode) {
  26510. this.decodeBuffer(comps);
  26511. }
  26512. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  26513. drawWidth, drawHeight, actualHeight, bpc, comps,
  26514. alpha01);
  26515. if (maybeUndoPreblend) {
  26516. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  26517. }
  26518. return imgData;
  26519. },
  26520. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  26521. var numComps = this.numComps;
  26522. if (numComps !== 1) {
  26523. error('Reading gray scale from a color image: ' + numComps);
  26524. }
  26525. var width = this.width;
  26526. var height = this.height;
  26527. var bpc = this.bpc;
  26528. // rows start at byte boundary
  26529. var rowBytes = (width * numComps * bpc + 7) >> 3;
  26530. var imgArray = this.getImageBytes(height * rowBytes);
  26531. var comps = this.getComponents(imgArray);
  26532. var i, length;
  26533. if (bpc === 1) {
  26534. // inline decoding (= inversion) for 1 bpc images
  26535. length = width * height;
  26536. if (this.needsDecode) {
  26537. // invert and scale to {0, 255}
  26538. for (i = 0; i < length; ++i) {
  26539. buffer[i] = (comps[i] - 1) & 255;
  26540. }
  26541. } else {
  26542. // scale to {0, 255}
  26543. for (i = 0; i < length; ++i) {
  26544. buffer[i] = (-comps[i]) & 255;
  26545. }
  26546. }
  26547. return;
  26548. }
  26549. if (this.needsDecode) {
  26550. this.decodeBuffer(comps);
  26551. }
  26552. length = width * height;
  26553. // we aren't using a colorspace so we need to scale the value
  26554. var scale = 255 / ((1 << bpc) - 1);
  26555. for (i = 0; i < length; ++i) {
  26556. buffer[i] = (scale * comps[i]) | 0;
  26557. }
  26558. },
  26559. getImageBytes: function PDFImage_getImageBytes(length,
  26560. drawWidth, drawHeight,
  26561. forceRGB) {
  26562. this.image.reset();
  26563. this.image.drawWidth = drawWidth || this.width;
  26564. this.image.drawHeight = drawHeight || this.height;
  26565. this.image.forceRGB = !!forceRGB;
  26566. return this.image.getBytes(length);
  26567. }
  26568. };
  26569. return PDFImage;
  26570. })();
  26571. // The Metrics object contains glyph widths (in glyph space units).
  26572. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  26573. // space unit corresponds to 1/1000th of text space unit.
  26574. var Metrics = {
  26575. 'Courier': 600,
  26576. 'Courier-Bold': 600,
  26577. 'Courier-BoldOblique': 600,
  26578. 'Courier-Oblique': 600,
  26579. 'Helvetica' : {
  26580. 'space': 278,
  26581. 'exclam': 278,
  26582. 'quotedbl': 355,
  26583. 'numbersign': 556,
  26584. 'dollar': 556,
  26585. 'percent': 889,
  26586. 'ampersand': 667,
  26587. 'quoteright': 222,
  26588. 'parenleft': 333,
  26589. 'parenright': 333,
  26590. 'asterisk': 389,
  26591. 'plus': 584,
  26592. 'comma': 278,
  26593. 'hyphen': 333,
  26594. 'period': 278,
  26595. 'slash': 278,
  26596. 'zero': 556,
  26597. 'one': 556,
  26598. 'two': 556,
  26599. 'three': 556,
  26600. 'four': 556,
  26601. 'five': 556,
  26602. 'six': 556,
  26603. 'seven': 556,
  26604. 'eight': 556,
  26605. 'nine': 556,
  26606. 'colon': 278,
  26607. 'semicolon': 278,
  26608. 'less': 584,
  26609. 'equal': 584,
  26610. 'greater': 584,
  26611. 'question': 556,
  26612. 'at': 1015,
  26613. 'A': 667,
  26614. 'B': 667,
  26615. 'C': 722,
  26616. 'D': 722,
  26617. 'E': 667,
  26618. 'F': 611,
  26619. 'G': 778,
  26620. 'H': 722,
  26621. 'I': 278,
  26622. 'J': 500,
  26623. 'K': 667,
  26624. 'L': 556,
  26625. 'M': 833,
  26626. 'N': 722,
  26627. 'O': 778,
  26628. 'P': 667,
  26629. 'Q': 778,
  26630. 'R': 722,
  26631. 'S': 667,
  26632. 'T': 611,
  26633. 'U': 722,
  26634. 'V': 667,
  26635. 'W': 944,
  26636. 'X': 667,
  26637. 'Y': 667,
  26638. 'Z': 611,
  26639. 'bracketleft': 278,
  26640. 'backslash': 278,
  26641. 'bracketright': 278,
  26642. 'asciicircum': 469,
  26643. 'underscore': 556,
  26644. 'quoteleft': 222,
  26645. 'a': 556,
  26646. 'b': 556,
  26647. 'c': 500,
  26648. 'd': 556,
  26649. 'e': 556,
  26650. 'f': 278,
  26651. 'g': 556,
  26652. 'h': 556,
  26653. 'i': 222,
  26654. 'j': 222,
  26655. 'k': 500,
  26656. 'l': 222,
  26657. 'm': 833,
  26658. 'n': 556,
  26659. 'o': 556,
  26660. 'p': 556,
  26661. 'q': 556,
  26662. 'r': 333,
  26663. 's': 500,
  26664. 't': 278,
  26665. 'u': 556,
  26666. 'v': 500,
  26667. 'w': 722,
  26668. 'x': 500,
  26669. 'y': 500,
  26670. 'z': 500,
  26671. 'braceleft': 334,
  26672. 'bar': 260,
  26673. 'braceright': 334,
  26674. 'asciitilde': 584,
  26675. 'exclamdown': 333,
  26676. 'cent': 556,
  26677. 'sterling': 556,
  26678. 'fraction': 167,
  26679. 'yen': 556,
  26680. 'florin': 556,
  26681. 'section': 556,
  26682. 'currency': 556,
  26683. 'quotesingle': 191,
  26684. 'quotedblleft': 333,
  26685. 'guillemotleft': 556,
  26686. 'guilsinglleft': 333,
  26687. 'guilsinglright': 333,
  26688. 'fi': 500,
  26689. 'fl': 500,
  26690. 'endash': 556,
  26691. 'dagger': 556,
  26692. 'daggerdbl': 556,
  26693. 'periodcentered': 278,
  26694. 'paragraph': 537,
  26695. 'bullet': 350,
  26696. 'quotesinglbase': 222,
  26697. 'quotedblbase': 333,
  26698. 'quotedblright': 333,
  26699. 'guillemotright': 556,
  26700. 'ellipsis': 1000,
  26701. 'perthousand': 1000,
  26702. 'questiondown': 611,
  26703. 'grave': 333,
  26704. 'acute': 333,
  26705. 'circumflex': 333,
  26706. 'tilde': 333,
  26707. 'macron': 333,
  26708. 'breve': 333,
  26709. 'dotaccent': 333,
  26710. 'dieresis': 333,
  26711. 'ring': 333,
  26712. 'cedilla': 333,
  26713. 'hungarumlaut': 333,
  26714. 'ogonek': 333,
  26715. 'caron': 333,
  26716. 'emdash': 1000,
  26717. 'AE': 1000,
  26718. 'ordfeminine': 370,
  26719. 'Lslash': 556,
  26720. 'Oslash': 778,
  26721. 'OE': 1000,
  26722. 'ordmasculine': 365,
  26723. 'ae': 889,
  26724. 'dotlessi': 278,
  26725. 'lslash': 222,
  26726. 'oslash': 611,
  26727. 'oe': 944,
  26728. 'germandbls': 611,
  26729. 'Idieresis': 278,
  26730. 'eacute': 556,
  26731. 'abreve': 556,
  26732. 'uhungarumlaut': 556,
  26733. 'ecaron': 556,
  26734. 'Ydieresis': 667,
  26735. 'divide': 584,
  26736. 'Yacute': 667,
  26737. 'Acircumflex': 667,
  26738. 'aacute': 556,
  26739. 'Ucircumflex': 722,
  26740. 'yacute': 500,
  26741. 'scommaaccent': 500,
  26742. 'ecircumflex': 556,
  26743. 'Uring': 722,
  26744. 'Udieresis': 722,
  26745. 'aogonek': 556,
  26746. 'Uacute': 722,
  26747. 'uogonek': 556,
  26748. 'Edieresis': 667,
  26749. 'Dcroat': 722,
  26750. 'commaaccent': 250,
  26751. 'copyright': 737,
  26752. 'Emacron': 667,
  26753. 'ccaron': 500,
  26754. 'aring': 556,
  26755. 'Ncommaaccent': 722,
  26756. 'lacute': 222,
  26757. 'agrave': 556,
  26758. 'Tcommaaccent': 611,
  26759. 'Cacute': 722,
  26760. 'atilde': 556,
  26761. 'Edotaccent': 667,
  26762. 'scaron': 500,
  26763. 'scedilla': 500,
  26764. 'iacute': 278,
  26765. 'lozenge': 471,
  26766. 'Rcaron': 722,
  26767. 'Gcommaaccent': 778,
  26768. 'ucircumflex': 556,
  26769. 'acircumflex': 556,
  26770. 'Amacron': 667,
  26771. 'rcaron': 333,
  26772. 'ccedilla': 500,
  26773. 'Zdotaccent': 611,
  26774. 'Thorn': 667,
  26775. 'Omacron': 778,
  26776. 'Racute': 722,
  26777. 'Sacute': 667,
  26778. 'dcaron': 643,
  26779. 'Umacron': 722,
  26780. 'uring': 556,
  26781. 'threesuperior': 333,
  26782. 'Ograve': 778,
  26783. 'Agrave': 667,
  26784. 'Abreve': 667,
  26785. 'multiply': 584,
  26786. 'uacute': 556,
  26787. 'Tcaron': 611,
  26788. 'partialdiff': 476,
  26789. 'ydieresis': 500,
  26790. 'Nacute': 722,
  26791. 'icircumflex': 278,
  26792. 'Ecircumflex': 667,
  26793. 'adieresis': 556,
  26794. 'edieresis': 556,
  26795. 'cacute': 500,
  26796. 'nacute': 556,
  26797. 'umacron': 556,
  26798. 'Ncaron': 722,
  26799. 'Iacute': 278,
  26800. 'plusminus': 584,
  26801. 'brokenbar': 260,
  26802. 'registered': 737,
  26803. 'Gbreve': 778,
  26804. 'Idotaccent': 278,
  26805. 'summation': 600,
  26806. 'Egrave': 667,
  26807. 'racute': 333,
  26808. 'omacron': 556,
  26809. 'Zacute': 611,
  26810. 'Zcaron': 611,
  26811. 'greaterequal': 549,
  26812. 'Eth': 722,
  26813. 'Ccedilla': 722,
  26814. 'lcommaaccent': 222,
  26815. 'tcaron': 317,
  26816. 'eogonek': 556,
  26817. 'Uogonek': 722,
  26818. 'Aacute': 667,
  26819. 'Adieresis': 667,
  26820. 'egrave': 556,
  26821. 'zacute': 500,
  26822. 'iogonek': 222,
  26823. 'Oacute': 778,
  26824. 'oacute': 556,
  26825. 'amacron': 556,
  26826. 'sacute': 500,
  26827. 'idieresis': 278,
  26828. 'Ocircumflex': 778,
  26829. 'Ugrave': 722,
  26830. 'Delta': 612,
  26831. 'thorn': 556,
  26832. 'twosuperior': 333,
  26833. 'Odieresis': 778,
  26834. 'mu': 556,
  26835. 'igrave': 278,
  26836. 'ohungarumlaut': 556,
  26837. 'Eogonek': 667,
  26838. 'dcroat': 556,
  26839. 'threequarters': 834,
  26840. 'Scedilla': 667,
  26841. 'lcaron': 299,
  26842. 'Kcommaaccent': 667,
  26843. 'Lacute': 556,
  26844. 'trademark': 1000,
  26845. 'edotaccent': 556,
  26846. 'Igrave': 278,
  26847. 'Imacron': 278,
  26848. 'Lcaron': 556,
  26849. 'onehalf': 834,
  26850. 'lessequal': 549,
  26851. 'ocircumflex': 556,
  26852. 'ntilde': 556,
  26853. 'Uhungarumlaut': 722,
  26854. 'Eacute': 667,
  26855. 'emacron': 556,
  26856. 'gbreve': 556,
  26857. 'onequarter': 834,
  26858. 'Scaron': 667,
  26859. 'Scommaaccent': 667,
  26860. 'Ohungarumlaut': 778,
  26861. 'degree': 400,
  26862. 'ograve': 556,
  26863. 'Ccaron': 722,
  26864. 'ugrave': 556,
  26865. 'radical': 453,
  26866. 'Dcaron': 722,
  26867. 'rcommaaccent': 333,
  26868. 'Ntilde': 722,
  26869. 'otilde': 556,
  26870. 'Rcommaaccent': 722,
  26871. 'Lcommaaccent': 556,
  26872. 'Atilde': 667,
  26873. 'Aogonek': 667,
  26874. 'Aring': 667,
  26875. 'Otilde': 778,
  26876. 'zdotaccent': 500,
  26877. 'Ecaron': 667,
  26878. 'Iogonek': 278,
  26879. 'kcommaaccent': 500,
  26880. 'minus': 584,
  26881. 'Icircumflex': 278,
  26882. 'ncaron': 556,
  26883. 'tcommaaccent': 278,
  26884. 'logicalnot': 584,
  26885. 'odieresis': 556,
  26886. 'udieresis': 556,
  26887. 'notequal': 549,
  26888. 'gcommaaccent': 556,
  26889. 'eth': 556,
  26890. 'zcaron': 500,
  26891. 'ncommaaccent': 556,
  26892. 'onesuperior': 333,
  26893. 'imacron': 278,
  26894. 'Euro': 556
  26895. },
  26896. 'Helvetica-Bold': {
  26897. 'space': 278,
  26898. 'exclam': 333,
  26899. 'quotedbl': 474,
  26900. 'numbersign': 556,
  26901. 'dollar': 556,
  26902. 'percent': 889,
  26903. 'ampersand': 722,
  26904. 'quoteright': 278,
  26905. 'parenleft': 333,
  26906. 'parenright': 333,
  26907. 'asterisk': 389,
  26908. 'plus': 584,
  26909. 'comma': 278,
  26910. 'hyphen': 333,
  26911. 'period': 278,
  26912. 'slash': 278,
  26913. 'zero': 556,
  26914. 'one': 556,
  26915. 'two': 556,
  26916. 'three': 556,
  26917. 'four': 556,
  26918. 'five': 556,
  26919. 'six': 556,
  26920. 'seven': 556,
  26921. 'eight': 556,
  26922. 'nine': 556,
  26923. 'colon': 333,
  26924. 'semicolon': 333,
  26925. 'less': 584,
  26926. 'equal': 584,
  26927. 'greater': 584,
  26928. 'question': 611,
  26929. 'at': 975,
  26930. 'A': 722,
  26931. 'B': 722,
  26932. 'C': 722,
  26933. 'D': 722,
  26934. 'E': 667,
  26935. 'F': 611,
  26936. 'G': 778,
  26937. 'H': 722,
  26938. 'I': 278,
  26939. 'J': 556,
  26940. 'K': 722,
  26941. 'L': 611,
  26942. 'M': 833,
  26943. 'N': 722,
  26944. 'O': 778,
  26945. 'P': 667,
  26946. 'Q': 778,
  26947. 'R': 722,
  26948. 'S': 667,
  26949. 'T': 611,
  26950. 'U': 722,
  26951. 'V': 667,
  26952. 'W': 944,
  26953. 'X': 667,
  26954. 'Y': 667,
  26955. 'Z': 611,
  26956. 'bracketleft': 333,
  26957. 'backslash': 278,
  26958. 'bracketright': 333,
  26959. 'asciicircum': 584,
  26960. 'underscore': 556,
  26961. 'quoteleft': 278,
  26962. 'a': 556,
  26963. 'b': 611,
  26964. 'c': 556,
  26965. 'd': 611,
  26966. 'e': 556,
  26967. 'f': 333,
  26968. 'g': 611,
  26969. 'h': 611,
  26970. 'i': 278,
  26971. 'j': 278,
  26972. 'k': 556,
  26973. 'l': 278,
  26974. 'm': 889,
  26975. 'n': 611,
  26976. 'o': 611,
  26977. 'p': 611,
  26978. 'q': 611,
  26979. 'r': 389,
  26980. 's': 556,
  26981. 't': 333,
  26982. 'u': 611,
  26983. 'v': 556,
  26984. 'w': 778,
  26985. 'x': 556,
  26986. 'y': 556,
  26987. 'z': 500,
  26988. 'braceleft': 389,
  26989. 'bar': 280,
  26990. 'braceright': 389,
  26991. 'asciitilde': 584,
  26992. 'exclamdown': 333,
  26993. 'cent': 556,
  26994. 'sterling': 556,
  26995. 'fraction': 167,
  26996. 'yen': 556,
  26997. 'florin': 556,
  26998. 'section': 556,
  26999. 'currency': 556,
  27000. 'quotesingle': 238,
  27001. 'quotedblleft': 500,
  27002. 'guillemotleft': 556,
  27003. 'guilsinglleft': 333,
  27004. 'guilsinglright': 333,
  27005. 'fi': 611,
  27006. 'fl': 611,
  27007. 'endash': 556,
  27008. 'dagger': 556,
  27009. 'daggerdbl': 556,
  27010. 'periodcentered': 278,
  27011. 'paragraph': 556,
  27012. 'bullet': 350,
  27013. 'quotesinglbase': 278,
  27014. 'quotedblbase': 500,
  27015. 'quotedblright': 500,
  27016. 'guillemotright': 556,
  27017. 'ellipsis': 1000,
  27018. 'perthousand': 1000,
  27019. 'questiondown': 611,
  27020. 'grave': 333,
  27021. 'acute': 333,
  27022. 'circumflex': 333,
  27023. 'tilde': 333,
  27024. 'macron': 333,
  27025. 'breve': 333,
  27026. 'dotaccent': 333,
  27027. 'dieresis': 333,
  27028. 'ring': 333,
  27029. 'cedilla': 333,
  27030. 'hungarumlaut': 333,
  27031. 'ogonek': 333,
  27032. 'caron': 333,
  27033. 'emdash': 1000,
  27034. 'AE': 1000,
  27035. 'ordfeminine': 370,
  27036. 'Lslash': 611,
  27037. 'Oslash': 778,
  27038. 'OE': 1000,
  27039. 'ordmasculine': 365,
  27040. 'ae': 889,
  27041. 'dotlessi': 278,
  27042. 'lslash': 278,
  27043. 'oslash': 611,
  27044. 'oe': 944,
  27045. 'germandbls': 611,
  27046. 'Idieresis': 278,
  27047. 'eacute': 556,
  27048. 'abreve': 556,
  27049. 'uhungarumlaut': 611,
  27050. 'ecaron': 556,
  27051. 'Ydieresis': 667,
  27052. 'divide': 584,
  27053. 'Yacute': 667,
  27054. 'Acircumflex': 722,
  27055. 'aacute': 556,
  27056. 'Ucircumflex': 722,
  27057. 'yacute': 556,
  27058. 'scommaaccent': 556,
  27059. 'ecircumflex': 556,
  27060. 'Uring': 722,
  27061. 'Udieresis': 722,
  27062. 'aogonek': 556,
  27063. 'Uacute': 722,
  27064. 'uogonek': 611,
  27065. 'Edieresis': 667,
  27066. 'Dcroat': 722,
  27067. 'commaaccent': 250,
  27068. 'copyright': 737,
  27069. 'Emacron': 667,
  27070. 'ccaron': 556,
  27071. 'aring': 556,
  27072. 'Ncommaaccent': 722,
  27073. 'lacute': 278,
  27074. 'agrave': 556,
  27075. 'Tcommaaccent': 611,
  27076. 'Cacute': 722,
  27077. 'atilde': 556,
  27078. 'Edotaccent': 667,
  27079. 'scaron': 556,
  27080. 'scedilla': 556,
  27081. 'iacute': 278,
  27082. 'lozenge': 494,
  27083. 'Rcaron': 722,
  27084. 'Gcommaaccent': 778,
  27085. 'ucircumflex': 611,
  27086. 'acircumflex': 556,
  27087. 'Amacron': 722,
  27088. 'rcaron': 389,
  27089. 'ccedilla': 556,
  27090. 'Zdotaccent': 611,
  27091. 'Thorn': 667,
  27092. 'Omacron': 778,
  27093. 'Racute': 722,
  27094. 'Sacute': 667,
  27095. 'dcaron': 743,
  27096. 'Umacron': 722,
  27097. 'uring': 611,
  27098. 'threesuperior': 333,
  27099. 'Ograve': 778,
  27100. 'Agrave': 722,
  27101. 'Abreve': 722,
  27102. 'multiply': 584,
  27103. 'uacute': 611,
  27104. 'Tcaron': 611,
  27105. 'partialdiff': 494,
  27106. 'ydieresis': 556,
  27107. 'Nacute': 722,
  27108. 'icircumflex': 278,
  27109. 'Ecircumflex': 667,
  27110. 'adieresis': 556,
  27111. 'edieresis': 556,
  27112. 'cacute': 556,
  27113. 'nacute': 611,
  27114. 'umacron': 611,
  27115. 'Ncaron': 722,
  27116. 'Iacute': 278,
  27117. 'plusminus': 584,
  27118. 'brokenbar': 280,
  27119. 'registered': 737,
  27120. 'Gbreve': 778,
  27121. 'Idotaccent': 278,
  27122. 'summation': 600,
  27123. 'Egrave': 667,
  27124. 'racute': 389,
  27125. 'omacron': 611,
  27126. 'Zacute': 611,
  27127. 'Zcaron': 611,
  27128. 'greaterequal': 549,
  27129. 'Eth': 722,
  27130. 'Ccedilla': 722,
  27131. 'lcommaaccent': 278,
  27132. 'tcaron': 389,
  27133. 'eogonek': 556,
  27134. 'Uogonek': 722,
  27135. 'Aacute': 722,
  27136. 'Adieresis': 722,
  27137. 'egrave': 556,
  27138. 'zacute': 500,
  27139. 'iogonek': 278,
  27140. 'Oacute': 778,
  27141. 'oacute': 611,
  27142. 'amacron': 556,
  27143. 'sacute': 556,
  27144. 'idieresis': 278,
  27145. 'Ocircumflex': 778,
  27146. 'Ugrave': 722,
  27147. 'Delta': 612,
  27148. 'thorn': 611,
  27149. 'twosuperior': 333,
  27150. 'Odieresis': 778,
  27151. 'mu': 611,
  27152. 'igrave': 278,
  27153. 'ohungarumlaut': 611,
  27154. 'Eogonek': 667,
  27155. 'dcroat': 611,
  27156. 'threequarters': 834,
  27157. 'Scedilla': 667,
  27158. 'lcaron': 400,
  27159. 'Kcommaaccent': 722,
  27160. 'Lacute': 611,
  27161. 'trademark': 1000,
  27162. 'edotaccent': 556,
  27163. 'Igrave': 278,
  27164. 'Imacron': 278,
  27165. 'Lcaron': 611,
  27166. 'onehalf': 834,
  27167. 'lessequal': 549,
  27168. 'ocircumflex': 611,
  27169. 'ntilde': 611,
  27170. 'Uhungarumlaut': 722,
  27171. 'Eacute': 667,
  27172. 'emacron': 556,
  27173. 'gbreve': 611,
  27174. 'onequarter': 834,
  27175. 'Scaron': 667,
  27176. 'Scommaaccent': 667,
  27177. 'Ohungarumlaut': 778,
  27178. 'degree': 400,
  27179. 'ograve': 611,
  27180. 'Ccaron': 722,
  27181. 'ugrave': 611,
  27182. 'radical': 549,
  27183. 'Dcaron': 722,
  27184. 'rcommaaccent': 389,
  27185. 'Ntilde': 722,
  27186. 'otilde': 611,
  27187. 'Rcommaaccent': 722,
  27188. 'Lcommaaccent': 611,
  27189. 'Atilde': 722,
  27190. 'Aogonek': 722,
  27191. 'Aring': 722,
  27192. 'Otilde': 778,
  27193. 'zdotaccent': 500,
  27194. 'Ecaron': 667,
  27195. 'Iogonek': 278,
  27196. 'kcommaaccent': 556,
  27197. 'minus': 584,
  27198. 'Icircumflex': 278,
  27199. 'ncaron': 611,
  27200. 'tcommaaccent': 333,
  27201. 'logicalnot': 584,
  27202. 'odieresis': 611,
  27203. 'udieresis': 611,
  27204. 'notequal': 549,
  27205. 'gcommaaccent': 611,
  27206. 'eth': 611,
  27207. 'zcaron': 500,
  27208. 'ncommaaccent': 611,
  27209. 'onesuperior': 333,
  27210. 'imacron': 278,
  27211. 'Euro': 556
  27212. },
  27213. 'Helvetica-BoldOblique': {
  27214. 'space': 278,
  27215. 'exclam': 333,
  27216. 'quotedbl': 474,
  27217. 'numbersign': 556,
  27218. 'dollar': 556,
  27219. 'percent': 889,
  27220. 'ampersand': 722,
  27221. 'quoteright': 278,
  27222. 'parenleft': 333,
  27223. 'parenright': 333,
  27224. 'asterisk': 389,
  27225. 'plus': 584,
  27226. 'comma': 278,
  27227. 'hyphen': 333,
  27228. 'period': 278,
  27229. 'slash': 278,
  27230. 'zero': 556,
  27231. 'one': 556,
  27232. 'two': 556,
  27233. 'three': 556,
  27234. 'four': 556,
  27235. 'five': 556,
  27236. 'six': 556,
  27237. 'seven': 556,
  27238. 'eight': 556,
  27239. 'nine': 556,
  27240. 'colon': 333,
  27241. 'semicolon': 333,
  27242. 'less': 584,
  27243. 'equal': 584,
  27244. 'greater': 584,
  27245. 'question': 611,
  27246. 'at': 975,
  27247. 'A': 722,
  27248. 'B': 722,
  27249. 'C': 722,
  27250. 'D': 722,
  27251. 'E': 667,
  27252. 'F': 611,
  27253. 'G': 778,
  27254. 'H': 722,
  27255. 'I': 278,
  27256. 'J': 556,
  27257. 'K': 722,
  27258. 'L': 611,
  27259. 'M': 833,
  27260. 'N': 722,
  27261. 'O': 778,
  27262. 'P': 667,
  27263. 'Q': 778,
  27264. 'R': 722,
  27265. 'S': 667,
  27266. 'T': 611,
  27267. 'U': 722,
  27268. 'V': 667,
  27269. 'W': 944,
  27270. 'X': 667,
  27271. 'Y': 667,
  27272. 'Z': 611,
  27273. 'bracketleft': 333,
  27274. 'backslash': 278,
  27275. 'bracketright': 333,
  27276. 'asciicircum': 584,
  27277. 'underscore': 556,
  27278. 'quoteleft': 278,
  27279. 'a': 556,
  27280. 'b': 611,
  27281. 'c': 556,
  27282. 'd': 611,
  27283. 'e': 556,
  27284. 'f': 333,
  27285. 'g': 611,
  27286. 'h': 611,
  27287. 'i': 278,
  27288. 'j': 278,
  27289. 'k': 556,
  27290. 'l': 278,
  27291. 'm': 889,
  27292. 'n': 611,
  27293. 'o': 611,
  27294. 'p': 611,
  27295. 'q': 611,
  27296. 'r': 389,
  27297. 's': 556,
  27298. 't': 333,
  27299. 'u': 611,
  27300. 'v': 556,
  27301. 'w': 778,
  27302. 'x': 556,
  27303. 'y': 556,
  27304. 'z': 500,
  27305. 'braceleft': 389,
  27306. 'bar': 280,
  27307. 'braceright': 389,
  27308. 'asciitilde': 584,
  27309. 'exclamdown': 333,
  27310. 'cent': 556,
  27311. 'sterling': 556,
  27312. 'fraction': 167,
  27313. 'yen': 556,
  27314. 'florin': 556,
  27315. 'section': 556,
  27316. 'currency': 556,
  27317. 'quotesingle': 238,
  27318. 'quotedblleft': 500,
  27319. 'guillemotleft': 556,
  27320. 'guilsinglleft': 333,
  27321. 'guilsinglright': 333,
  27322. 'fi': 611,
  27323. 'fl': 611,
  27324. 'endash': 556,
  27325. 'dagger': 556,
  27326. 'daggerdbl': 556,
  27327. 'periodcentered': 278,
  27328. 'paragraph': 556,
  27329. 'bullet': 350,
  27330. 'quotesinglbase': 278,
  27331. 'quotedblbase': 500,
  27332. 'quotedblright': 500,
  27333. 'guillemotright': 556,
  27334. 'ellipsis': 1000,
  27335. 'perthousand': 1000,
  27336. 'questiondown': 611,
  27337. 'grave': 333,
  27338. 'acute': 333,
  27339. 'circumflex': 333,
  27340. 'tilde': 333,
  27341. 'macron': 333,
  27342. 'breve': 333,
  27343. 'dotaccent': 333,
  27344. 'dieresis': 333,
  27345. 'ring': 333,
  27346. 'cedilla': 333,
  27347. 'hungarumlaut': 333,
  27348. 'ogonek': 333,
  27349. 'caron': 333,
  27350. 'emdash': 1000,
  27351. 'AE': 1000,
  27352. 'ordfeminine': 370,
  27353. 'Lslash': 611,
  27354. 'Oslash': 778,
  27355. 'OE': 1000,
  27356. 'ordmasculine': 365,
  27357. 'ae': 889,
  27358. 'dotlessi': 278,
  27359. 'lslash': 278,
  27360. 'oslash': 611,
  27361. 'oe': 944,
  27362. 'germandbls': 611,
  27363. 'Idieresis': 278,
  27364. 'eacute': 556,
  27365. 'abreve': 556,
  27366. 'uhungarumlaut': 611,
  27367. 'ecaron': 556,
  27368. 'Ydieresis': 667,
  27369. 'divide': 584,
  27370. 'Yacute': 667,
  27371. 'Acircumflex': 722,
  27372. 'aacute': 556,
  27373. 'Ucircumflex': 722,
  27374. 'yacute': 556,
  27375. 'scommaaccent': 556,
  27376. 'ecircumflex': 556,
  27377. 'Uring': 722,
  27378. 'Udieresis': 722,
  27379. 'aogonek': 556,
  27380. 'Uacute': 722,
  27381. 'uogonek': 611,
  27382. 'Edieresis': 667,
  27383. 'Dcroat': 722,
  27384. 'commaaccent': 250,
  27385. 'copyright': 737,
  27386. 'Emacron': 667,
  27387. 'ccaron': 556,
  27388. 'aring': 556,
  27389. 'Ncommaaccent': 722,
  27390. 'lacute': 278,
  27391. 'agrave': 556,
  27392. 'Tcommaaccent': 611,
  27393. 'Cacute': 722,
  27394. 'atilde': 556,
  27395. 'Edotaccent': 667,
  27396. 'scaron': 556,
  27397. 'scedilla': 556,
  27398. 'iacute': 278,
  27399. 'lozenge': 494,
  27400. 'Rcaron': 722,
  27401. 'Gcommaaccent': 778,
  27402. 'ucircumflex': 611,
  27403. 'acircumflex': 556,
  27404. 'Amacron': 722,
  27405. 'rcaron': 389,
  27406. 'ccedilla': 556,
  27407. 'Zdotaccent': 611,
  27408. 'Thorn': 667,
  27409. 'Omacron': 778,
  27410. 'Racute': 722,
  27411. 'Sacute': 667,
  27412. 'dcaron': 743,
  27413. 'Umacron': 722,
  27414. 'uring': 611,
  27415. 'threesuperior': 333,
  27416. 'Ograve': 778,
  27417. 'Agrave': 722,
  27418. 'Abreve': 722,
  27419. 'multiply': 584,
  27420. 'uacute': 611,
  27421. 'Tcaron': 611,
  27422. 'partialdiff': 494,
  27423. 'ydieresis': 556,
  27424. 'Nacute': 722,
  27425. 'icircumflex': 278,
  27426. 'Ecircumflex': 667,
  27427. 'adieresis': 556,
  27428. 'edieresis': 556,
  27429. 'cacute': 556,
  27430. 'nacute': 611,
  27431. 'umacron': 611,
  27432. 'Ncaron': 722,
  27433. 'Iacute': 278,
  27434. 'plusminus': 584,
  27435. 'brokenbar': 280,
  27436. 'registered': 737,
  27437. 'Gbreve': 778,
  27438. 'Idotaccent': 278,
  27439. 'summation': 600,
  27440. 'Egrave': 667,
  27441. 'racute': 389,
  27442. 'omacron': 611,
  27443. 'Zacute': 611,
  27444. 'Zcaron': 611,
  27445. 'greaterequal': 549,
  27446. 'Eth': 722,
  27447. 'Ccedilla': 722,
  27448. 'lcommaaccent': 278,
  27449. 'tcaron': 389,
  27450. 'eogonek': 556,
  27451. 'Uogonek': 722,
  27452. 'Aacute': 722,
  27453. 'Adieresis': 722,
  27454. 'egrave': 556,
  27455. 'zacute': 500,
  27456. 'iogonek': 278,
  27457. 'Oacute': 778,
  27458. 'oacute': 611,
  27459. 'amacron': 556,
  27460. 'sacute': 556,
  27461. 'idieresis': 278,
  27462. 'Ocircumflex': 778,
  27463. 'Ugrave': 722,
  27464. 'Delta': 612,
  27465. 'thorn': 611,
  27466. 'twosuperior': 333,
  27467. 'Odieresis': 778,
  27468. 'mu': 611,
  27469. 'igrave': 278,
  27470. 'ohungarumlaut': 611,
  27471. 'Eogonek': 667,
  27472. 'dcroat': 611,
  27473. 'threequarters': 834,
  27474. 'Scedilla': 667,
  27475. 'lcaron': 400,
  27476. 'Kcommaaccent': 722,
  27477. 'Lacute': 611,
  27478. 'trademark': 1000,
  27479. 'edotaccent': 556,
  27480. 'Igrave': 278,
  27481. 'Imacron': 278,
  27482. 'Lcaron': 611,
  27483. 'onehalf': 834,
  27484. 'lessequal': 549,
  27485. 'ocircumflex': 611,
  27486. 'ntilde': 611,
  27487. 'Uhungarumlaut': 722,
  27488. 'Eacute': 667,
  27489. 'emacron': 556,
  27490. 'gbreve': 611,
  27491. 'onequarter': 834,
  27492. 'Scaron': 667,
  27493. 'Scommaaccent': 667,
  27494. 'Ohungarumlaut': 778,
  27495. 'degree': 400,
  27496. 'ograve': 611,
  27497. 'Ccaron': 722,
  27498. 'ugrave': 611,
  27499. 'radical': 549,
  27500. 'Dcaron': 722,
  27501. 'rcommaaccent': 389,
  27502. 'Ntilde': 722,
  27503. 'otilde': 611,
  27504. 'Rcommaaccent': 722,
  27505. 'Lcommaaccent': 611,
  27506. 'Atilde': 722,
  27507. 'Aogonek': 722,
  27508. 'Aring': 722,
  27509. 'Otilde': 778,
  27510. 'zdotaccent': 500,
  27511. 'Ecaron': 667,
  27512. 'Iogonek': 278,
  27513. 'kcommaaccent': 556,
  27514. 'minus': 584,
  27515. 'Icircumflex': 278,
  27516. 'ncaron': 611,
  27517. 'tcommaaccent': 333,
  27518. 'logicalnot': 584,
  27519. 'odieresis': 611,
  27520. 'udieresis': 611,
  27521. 'notequal': 549,
  27522. 'gcommaaccent': 611,
  27523. 'eth': 611,
  27524. 'zcaron': 500,
  27525. 'ncommaaccent': 611,
  27526. 'onesuperior': 333,
  27527. 'imacron': 278,
  27528. 'Euro': 556
  27529. },
  27530. 'Helvetica-Oblique' : {
  27531. 'space': 278,
  27532. 'exclam': 278,
  27533. 'quotedbl': 355,
  27534. 'numbersign': 556,
  27535. 'dollar': 556,
  27536. 'percent': 889,
  27537. 'ampersand': 667,
  27538. 'quoteright': 222,
  27539. 'parenleft': 333,
  27540. 'parenright': 333,
  27541. 'asterisk': 389,
  27542. 'plus': 584,
  27543. 'comma': 278,
  27544. 'hyphen': 333,
  27545. 'period': 278,
  27546. 'slash': 278,
  27547. 'zero': 556,
  27548. 'one': 556,
  27549. 'two': 556,
  27550. 'three': 556,
  27551. 'four': 556,
  27552. 'five': 556,
  27553. 'six': 556,
  27554. 'seven': 556,
  27555. 'eight': 556,
  27556. 'nine': 556,
  27557. 'colon': 278,
  27558. 'semicolon': 278,
  27559. 'less': 584,
  27560. 'equal': 584,
  27561. 'greater': 584,
  27562. 'question': 556,
  27563. 'at': 1015,
  27564. 'A': 667,
  27565. 'B': 667,
  27566. 'C': 722,
  27567. 'D': 722,
  27568. 'E': 667,
  27569. 'F': 611,
  27570. 'G': 778,
  27571. 'H': 722,
  27572. 'I': 278,
  27573. 'J': 500,
  27574. 'K': 667,
  27575. 'L': 556,
  27576. 'M': 833,
  27577. 'N': 722,
  27578. 'O': 778,
  27579. 'P': 667,
  27580. 'Q': 778,
  27581. 'R': 722,
  27582. 'S': 667,
  27583. 'T': 611,
  27584. 'U': 722,
  27585. 'V': 667,
  27586. 'W': 944,
  27587. 'X': 667,
  27588. 'Y': 667,
  27589. 'Z': 611,
  27590. 'bracketleft': 278,
  27591. 'backslash': 278,
  27592. 'bracketright': 278,
  27593. 'asciicircum': 469,
  27594. 'underscore': 556,
  27595. 'quoteleft': 222,
  27596. 'a': 556,
  27597. 'b': 556,
  27598. 'c': 500,
  27599. 'd': 556,
  27600. 'e': 556,
  27601. 'f': 278,
  27602. 'g': 556,
  27603. 'h': 556,
  27604. 'i': 222,
  27605. 'j': 222,
  27606. 'k': 500,
  27607. 'l': 222,
  27608. 'm': 833,
  27609. 'n': 556,
  27610. 'o': 556,
  27611. 'p': 556,
  27612. 'q': 556,
  27613. 'r': 333,
  27614. 's': 500,
  27615. 't': 278,
  27616. 'u': 556,
  27617. 'v': 500,
  27618. 'w': 722,
  27619. 'x': 500,
  27620. 'y': 500,
  27621. 'z': 500,
  27622. 'braceleft': 334,
  27623. 'bar': 260,
  27624. 'braceright': 334,
  27625. 'asciitilde': 584,
  27626. 'exclamdown': 333,
  27627. 'cent': 556,
  27628. 'sterling': 556,
  27629. 'fraction': 167,
  27630. 'yen': 556,
  27631. 'florin': 556,
  27632. 'section': 556,
  27633. 'currency': 556,
  27634. 'quotesingle': 191,
  27635. 'quotedblleft': 333,
  27636. 'guillemotleft': 556,
  27637. 'guilsinglleft': 333,
  27638. 'guilsinglright': 333,
  27639. 'fi': 500,
  27640. 'fl': 500,
  27641. 'endash': 556,
  27642. 'dagger': 556,
  27643. 'daggerdbl': 556,
  27644. 'periodcentered': 278,
  27645. 'paragraph': 537,
  27646. 'bullet': 350,
  27647. 'quotesinglbase': 222,
  27648. 'quotedblbase': 333,
  27649. 'quotedblright': 333,
  27650. 'guillemotright': 556,
  27651. 'ellipsis': 1000,
  27652. 'perthousand': 1000,
  27653. 'questiondown': 611,
  27654. 'grave': 333,
  27655. 'acute': 333,
  27656. 'circumflex': 333,
  27657. 'tilde': 333,
  27658. 'macron': 333,
  27659. 'breve': 333,
  27660. 'dotaccent': 333,
  27661. 'dieresis': 333,
  27662. 'ring': 333,
  27663. 'cedilla': 333,
  27664. 'hungarumlaut': 333,
  27665. 'ogonek': 333,
  27666. 'caron': 333,
  27667. 'emdash': 1000,
  27668. 'AE': 1000,
  27669. 'ordfeminine': 370,
  27670. 'Lslash': 556,
  27671. 'Oslash': 778,
  27672. 'OE': 1000,
  27673. 'ordmasculine': 365,
  27674. 'ae': 889,
  27675. 'dotlessi': 278,
  27676. 'lslash': 222,
  27677. 'oslash': 611,
  27678. 'oe': 944,
  27679. 'germandbls': 611,
  27680. 'Idieresis': 278,
  27681. 'eacute': 556,
  27682. 'abreve': 556,
  27683. 'uhungarumlaut': 556,
  27684. 'ecaron': 556,
  27685. 'Ydieresis': 667,
  27686. 'divide': 584,
  27687. 'Yacute': 667,
  27688. 'Acircumflex': 667,
  27689. 'aacute': 556,
  27690. 'Ucircumflex': 722,
  27691. 'yacute': 500,
  27692. 'scommaaccent': 500,
  27693. 'ecircumflex': 556,
  27694. 'Uring': 722,
  27695. 'Udieresis': 722,
  27696. 'aogonek': 556,
  27697. 'Uacute': 722,
  27698. 'uogonek': 556,
  27699. 'Edieresis': 667,
  27700. 'Dcroat': 722,
  27701. 'commaaccent': 250,
  27702. 'copyright': 737,
  27703. 'Emacron': 667,
  27704. 'ccaron': 500,
  27705. 'aring': 556,
  27706. 'Ncommaaccent': 722,
  27707. 'lacute': 222,
  27708. 'agrave': 556,
  27709. 'Tcommaaccent': 611,
  27710. 'Cacute': 722,
  27711. 'atilde': 556,
  27712. 'Edotaccent': 667,
  27713. 'scaron': 500,
  27714. 'scedilla': 500,
  27715. 'iacute': 278,
  27716. 'lozenge': 471,
  27717. 'Rcaron': 722,
  27718. 'Gcommaaccent': 778,
  27719. 'ucircumflex': 556,
  27720. 'acircumflex': 556,
  27721. 'Amacron': 667,
  27722. 'rcaron': 333,
  27723. 'ccedilla': 500,
  27724. 'Zdotaccent': 611,
  27725. 'Thorn': 667,
  27726. 'Omacron': 778,
  27727. 'Racute': 722,
  27728. 'Sacute': 667,
  27729. 'dcaron': 643,
  27730. 'Umacron': 722,
  27731. 'uring': 556,
  27732. 'threesuperior': 333,
  27733. 'Ograve': 778,
  27734. 'Agrave': 667,
  27735. 'Abreve': 667,
  27736. 'multiply': 584,
  27737. 'uacute': 556,
  27738. 'Tcaron': 611,
  27739. 'partialdiff': 476,
  27740. 'ydieresis': 500,
  27741. 'Nacute': 722,
  27742. 'icircumflex': 278,
  27743. 'Ecircumflex': 667,
  27744. 'adieresis': 556,
  27745. 'edieresis': 556,
  27746. 'cacute': 500,
  27747. 'nacute': 556,
  27748. 'umacron': 556,
  27749. 'Ncaron': 722,
  27750. 'Iacute': 278,
  27751. 'plusminus': 584,
  27752. 'brokenbar': 260,
  27753. 'registered': 737,
  27754. 'Gbreve': 778,
  27755. 'Idotaccent': 278,
  27756. 'summation': 600,
  27757. 'Egrave': 667,
  27758. 'racute': 333,
  27759. 'omacron': 556,
  27760. 'Zacute': 611,
  27761. 'Zcaron': 611,
  27762. 'greaterequal': 549,
  27763. 'Eth': 722,
  27764. 'Ccedilla': 722,
  27765. 'lcommaaccent': 222,
  27766. 'tcaron': 317,
  27767. 'eogonek': 556,
  27768. 'Uogonek': 722,
  27769. 'Aacute': 667,
  27770. 'Adieresis': 667,
  27771. 'egrave': 556,
  27772. 'zacute': 500,
  27773. 'iogonek': 222,
  27774. 'Oacute': 778,
  27775. 'oacute': 556,
  27776. 'amacron': 556,
  27777. 'sacute': 500,
  27778. 'idieresis': 278,
  27779. 'Ocircumflex': 778,
  27780. 'Ugrave': 722,
  27781. 'Delta': 612,
  27782. 'thorn': 556,
  27783. 'twosuperior': 333,
  27784. 'Odieresis': 778,
  27785. 'mu': 556,
  27786. 'igrave': 278,
  27787. 'ohungarumlaut': 556,
  27788. 'Eogonek': 667,
  27789. 'dcroat': 556,
  27790. 'threequarters': 834,
  27791. 'Scedilla': 667,
  27792. 'lcaron': 299,
  27793. 'Kcommaaccent': 667,
  27794. 'Lacute': 556,
  27795. 'trademark': 1000,
  27796. 'edotaccent': 556,
  27797. 'Igrave': 278,
  27798. 'Imacron': 278,
  27799. 'Lcaron': 556,
  27800. 'onehalf': 834,
  27801. 'lessequal': 549,
  27802. 'ocircumflex': 556,
  27803. 'ntilde': 556,
  27804. 'Uhungarumlaut': 722,
  27805. 'Eacute': 667,
  27806. 'emacron': 556,
  27807. 'gbreve': 556,
  27808. 'onequarter': 834,
  27809. 'Scaron': 667,
  27810. 'Scommaaccent': 667,
  27811. 'Ohungarumlaut': 778,
  27812. 'degree': 400,
  27813. 'ograve': 556,
  27814. 'Ccaron': 722,
  27815. 'ugrave': 556,
  27816. 'radical': 453,
  27817. 'Dcaron': 722,
  27818. 'rcommaaccent': 333,
  27819. 'Ntilde': 722,
  27820. 'otilde': 556,
  27821. 'Rcommaaccent': 722,
  27822. 'Lcommaaccent': 556,
  27823. 'Atilde': 667,
  27824. 'Aogonek': 667,
  27825. 'Aring': 667,
  27826. 'Otilde': 778,
  27827. 'zdotaccent': 500,
  27828. 'Ecaron': 667,
  27829. 'Iogonek': 278,
  27830. 'kcommaaccent': 500,
  27831. 'minus': 584,
  27832. 'Icircumflex': 278,
  27833. 'ncaron': 556,
  27834. 'tcommaaccent': 278,
  27835. 'logicalnot': 584,
  27836. 'odieresis': 556,
  27837. 'udieresis': 556,
  27838. 'notequal': 549,
  27839. 'gcommaaccent': 556,
  27840. 'eth': 556,
  27841. 'zcaron': 500,
  27842. 'ncommaaccent': 556,
  27843. 'onesuperior': 333,
  27844. 'imacron': 278,
  27845. 'Euro': 556
  27846. },
  27847. 'Symbol': {
  27848. 'space': 250,
  27849. 'exclam': 333,
  27850. 'universal': 713,
  27851. 'numbersign': 500,
  27852. 'existential': 549,
  27853. 'percent': 833,
  27854. 'ampersand': 778,
  27855. 'suchthat': 439,
  27856. 'parenleft': 333,
  27857. 'parenright': 333,
  27858. 'asteriskmath': 500,
  27859. 'plus': 549,
  27860. 'comma': 250,
  27861. 'minus': 549,
  27862. 'period': 250,
  27863. 'slash': 278,
  27864. 'zero': 500,
  27865. 'one': 500,
  27866. 'two': 500,
  27867. 'three': 500,
  27868. 'four': 500,
  27869. 'five': 500,
  27870. 'six': 500,
  27871. 'seven': 500,
  27872. 'eight': 500,
  27873. 'nine': 500,
  27874. 'colon': 278,
  27875. 'semicolon': 278,
  27876. 'less': 549,
  27877. 'equal': 549,
  27878. 'greater': 549,
  27879. 'question': 444,
  27880. 'congruent': 549,
  27881. 'Alpha': 722,
  27882. 'Beta': 667,
  27883. 'Chi': 722,
  27884. 'Delta': 612,
  27885. 'Epsilon': 611,
  27886. 'Phi': 763,
  27887. 'Gamma': 603,
  27888. 'Eta': 722,
  27889. 'Iota': 333,
  27890. 'theta1': 631,
  27891. 'Kappa': 722,
  27892. 'Lambda': 686,
  27893. 'Mu': 889,
  27894. 'Nu': 722,
  27895. 'Omicron': 722,
  27896. 'Pi': 768,
  27897. 'Theta': 741,
  27898. 'Rho': 556,
  27899. 'Sigma': 592,
  27900. 'Tau': 611,
  27901. 'Upsilon': 690,
  27902. 'sigma1': 439,
  27903. 'Omega': 768,
  27904. 'Xi': 645,
  27905. 'Psi': 795,
  27906. 'Zeta': 611,
  27907. 'bracketleft': 333,
  27908. 'therefore': 863,
  27909. 'bracketright': 333,
  27910. 'perpendicular': 658,
  27911. 'underscore': 500,
  27912. 'radicalex': 500,
  27913. 'alpha': 631,
  27914. 'beta': 549,
  27915. 'chi': 549,
  27916. 'delta': 494,
  27917. 'epsilon': 439,
  27918. 'phi': 521,
  27919. 'gamma': 411,
  27920. 'eta': 603,
  27921. 'iota': 329,
  27922. 'phi1': 603,
  27923. 'kappa': 549,
  27924. 'lambda': 549,
  27925. 'mu': 576,
  27926. 'nu': 521,
  27927. 'omicron': 549,
  27928. 'pi': 549,
  27929. 'theta': 521,
  27930. 'rho': 549,
  27931. 'sigma': 603,
  27932. 'tau': 439,
  27933. 'upsilon': 576,
  27934. 'omega1': 713,
  27935. 'omega': 686,
  27936. 'xi': 493,
  27937. 'psi': 686,
  27938. 'zeta': 494,
  27939. 'braceleft': 480,
  27940. 'bar': 200,
  27941. 'braceright': 480,
  27942. 'similar': 549,
  27943. 'Euro': 750,
  27944. 'Upsilon1': 620,
  27945. 'minute': 247,
  27946. 'lessequal': 549,
  27947. 'fraction': 167,
  27948. 'infinity': 713,
  27949. 'florin': 500,
  27950. 'club': 753,
  27951. 'diamond': 753,
  27952. 'heart': 753,
  27953. 'spade': 753,
  27954. 'arrowboth': 1042,
  27955. 'arrowleft': 987,
  27956. 'arrowup': 603,
  27957. 'arrowright': 987,
  27958. 'arrowdown': 603,
  27959. 'degree': 400,
  27960. 'plusminus': 549,
  27961. 'second': 411,
  27962. 'greaterequal': 549,
  27963. 'multiply': 549,
  27964. 'proportional': 713,
  27965. 'partialdiff': 494,
  27966. 'bullet': 460,
  27967. 'divide': 549,
  27968. 'notequal': 549,
  27969. 'equivalence': 549,
  27970. 'approxequal': 549,
  27971. 'ellipsis': 1000,
  27972. 'arrowvertex': 603,
  27973. 'arrowhorizex': 1000,
  27974. 'carriagereturn': 658,
  27975. 'aleph': 823,
  27976. 'Ifraktur': 686,
  27977. 'Rfraktur': 795,
  27978. 'weierstrass': 987,
  27979. 'circlemultiply': 768,
  27980. 'circleplus': 768,
  27981. 'emptyset': 823,
  27982. 'intersection': 768,
  27983. 'union': 768,
  27984. 'propersuperset': 713,
  27985. 'reflexsuperset': 713,
  27986. 'notsubset': 713,
  27987. 'propersubset': 713,
  27988. 'reflexsubset': 713,
  27989. 'element': 713,
  27990. 'notelement': 713,
  27991. 'angle': 768,
  27992. 'gradient': 713,
  27993. 'registerserif': 790,
  27994. 'copyrightserif': 790,
  27995. 'trademarkserif': 890,
  27996. 'product': 823,
  27997. 'radical': 549,
  27998. 'dotmath': 250,
  27999. 'logicalnot': 713,
  28000. 'logicaland': 603,
  28001. 'logicalor': 603,
  28002. 'arrowdblboth': 1042,
  28003. 'arrowdblleft': 987,
  28004. 'arrowdblup': 603,
  28005. 'arrowdblright': 987,
  28006. 'arrowdbldown': 603,
  28007. 'lozenge': 494,
  28008. 'angleleft': 329,
  28009. 'registersans': 790,
  28010. 'copyrightsans': 790,
  28011. 'trademarksans': 786,
  28012. 'summation': 713,
  28013. 'parenlefttp': 384,
  28014. 'parenleftex': 384,
  28015. 'parenleftbt': 384,
  28016. 'bracketlefttp': 384,
  28017. 'bracketleftex': 384,
  28018. 'bracketleftbt': 384,
  28019. 'bracelefttp': 494,
  28020. 'braceleftmid': 494,
  28021. 'braceleftbt': 494,
  28022. 'braceex': 494,
  28023. 'angleright': 329,
  28024. 'integral': 274,
  28025. 'integraltp': 686,
  28026. 'integralex': 686,
  28027. 'integralbt': 686,
  28028. 'parenrighttp': 384,
  28029. 'parenrightex': 384,
  28030. 'parenrightbt': 384,
  28031. 'bracketrighttp': 384,
  28032. 'bracketrightex': 384,
  28033. 'bracketrightbt': 384,
  28034. 'bracerighttp': 494,
  28035. 'bracerightmid': 494,
  28036. 'bracerightbt': 494,
  28037. 'apple': 790
  28038. },
  28039. 'Times-Roman': {
  28040. 'space': 250,
  28041. 'exclam': 333,
  28042. 'quotedbl': 408,
  28043. 'numbersign': 500,
  28044. 'dollar': 500,
  28045. 'percent': 833,
  28046. 'ampersand': 778,
  28047. 'quoteright': 333,
  28048. 'parenleft': 333,
  28049. 'parenright': 333,
  28050. 'asterisk': 500,
  28051. 'plus': 564,
  28052. 'comma': 250,
  28053. 'hyphen': 333,
  28054. 'period': 250,
  28055. 'slash': 278,
  28056. 'zero': 500,
  28057. 'one': 500,
  28058. 'two': 500,
  28059. 'three': 500,
  28060. 'four': 500,
  28061. 'five': 500,
  28062. 'six': 500,
  28063. 'seven': 500,
  28064. 'eight': 500,
  28065. 'nine': 500,
  28066. 'colon': 278,
  28067. 'semicolon': 278,
  28068. 'less': 564,
  28069. 'equal': 564,
  28070. 'greater': 564,
  28071. 'question': 444,
  28072. 'at': 921,
  28073. 'A': 722,
  28074. 'B': 667,
  28075. 'C': 667,
  28076. 'D': 722,
  28077. 'E': 611,
  28078. 'F': 556,
  28079. 'G': 722,
  28080. 'H': 722,
  28081. 'I': 333,
  28082. 'J': 389,
  28083. 'K': 722,
  28084. 'L': 611,
  28085. 'M': 889,
  28086. 'N': 722,
  28087. 'O': 722,
  28088. 'P': 556,
  28089. 'Q': 722,
  28090. 'R': 667,
  28091. 'S': 556,
  28092. 'T': 611,
  28093. 'U': 722,
  28094. 'V': 722,
  28095. 'W': 944,
  28096. 'X': 722,
  28097. 'Y': 722,
  28098. 'Z': 611,
  28099. 'bracketleft': 333,
  28100. 'backslash': 278,
  28101. 'bracketright': 333,
  28102. 'asciicircum': 469,
  28103. 'underscore': 500,
  28104. 'quoteleft': 333,
  28105. 'a': 444,
  28106. 'b': 500,
  28107. 'c': 444,
  28108. 'd': 500,
  28109. 'e': 444,
  28110. 'f': 333,
  28111. 'g': 500,
  28112. 'h': 500,
  28113. 'i': 278,
  28114. 'j': 278,
  28115. 'k': 500,
  28116. 'l': 278,
  28117. 'm': 778,
  28118. 'n': 500,
  28119. 'o': 500,
  28120. 'p': 500,
  28121. 'q': 500,
  28122. 'r': 333,
  28123. 's': 389,
  28124. 't': 278,
  28125. 'u': 500,
  28126. 'v': 500,
  28127. 'w': 722,
  28128. 'x': 500,
  28129. 'y': 500,
  28130. 'z': 444,
  28131. 'braceleft': 480,
  28132. 'bar': 200,
  28133. 'braceright': 480,
  28134. 'asciitilde': 541,
  28135. 'exclamdown': 333,
  28136. 'cent': 500,
  28137. 'sterling': 500,
  28138. 'fraction': 167,
  28139. 'yen': 500,
  28140. 'florin': 500,
  28141. 'section': 500,
  28142. 'currency': 500,
  28143. 'quotesingle': 180,
  28144. 'quotedblleft': 444,
  28145. 'guillemotleft': 500,
  28146. 'guilsinglleft': 333,
  28147. 'guilsinglright': 333,
  28148. 'fi': 556,
  28149. 'fl': 556,
  28150. 'endash': 500,
  28151. 'dagger': 500,
  28152. 'daggerdbl': 500,
  28153. 'periodcentered': 250,
  28154. 'paragraph': 453,
  28155. 'bullet': 350,
  28156. 'quotesinglbase': 333,
  28157. 'quotedblbase': 444,
  28158. 'quotedblright': 444,
  28159. 'guillemotright': 500,
  28160. 'ellipsis': 1000,
  28161. 'perthousand': 1000,
  28162. 'questiondown': 444,
  28163. 'grave': 333,
  28164. 'acute': 333,
  28165. 'circumflex': 333,
  28166. 'tilde': 333,
  28167. 'macron': 333,
  28168. 'breve': 333,
  28169. 'dotaccent': 333,
  28170. 'dieresis': 333,
  28171. 'ring': 333,
  28172. 'cedilla': 333,
  28173. 'hungarumlaut': 333,
  28174. 'ogonek': 333,
  28175. 'caron': 333,
  28176. 'emdash': 1000,
  28177. 'AE': 889,
  28178. 'ordfeminine': 276,
  28179. 'Lslash': 611,
  28180. 'Oslash': 722,
  28181. 'OE': 889,
  28182. 'ordmasculine': 310,
  28183. 'ae': 667,
  28184. 'dotlessi': 278,
  28185. 'lslash': 278,
  28186. 'oslash': 500,
  28187. 'oe': 722,
  28188. 'germandbls': 500,
  28189. 'Idieresis': 333,
  28190. 'eacute': 444,
  28191. 'abreve': 444,
  28192. 'uhungarumlaut': 500,
  28193. 'ecaron': 444,
  28194. 'Ydieresis': 722,
  28195. 'divide': 564,
  28196. 'Yacute': 722,
  28197. 'Acircumflex': 722,
  28198. 'aacute': 444,
  28199. 'Ucircumflex': 722,
  28200. 'yacute': 500,
  28201. 'scommaaccent': 389,
  28202. 'ecircumflex': 444,
  28203. 'Uring': 722,
  28204. 'Udieresis': 722,
  28205. 'aogonek': 444,
  28206. 'Uacute': 722,
  28207. 'uogonek': 500,
  28208. 'Edieresis': 611,
  28209. 'Dcroat': 722,
  28210. 'commaaccent': 250,
  28211. 'copyright': 760,
  28212. 'Emacron': 611,
  28213. 'ccaron': 444,
  28214. 'aring': 444,
  28215. 'Ncommaaccent': 722,
  28216. 'lacute': 278,
  28217. 'agrave': 444,
  28218. 'Tcommaaccent': 611,
  28219. 'Cacute': 667,
  28220. 'atilde': 444,
  28221. 'Edotaccent': 611,
  28222. 'scaron': 389,
  28223. 'scedilla': 389,
  28224. 'iacute': 278,
  28225. 'lozenge': 471,
  28226. 'Rcaron': 667,
  28227. 'Gcommaaccent': 722,
  28228. 'ucircumflex': 500,
  28229. 'acircumflex': 444,
  28230. 'Amacron': 722,
  28231. 'rcaron': 333,
  28232. 'ccedilla': 444,
  28233. 'Zdotaccent': 611,
  28234. 'Thorn': 556,
  28235. 'Omacron': 722,
  28236. 'Racute': 667,
  28237. 'Sacute': 556,
  28238. 'dcaron': 588,
  28239. 'Umacron': 722,
  28240. 'uring': 500,
  28241. 'threesuperior': 300,
  28242. 'Ograve': 722,
  28243. 'Agrave': 722,
  28244. 'Abreve': 722,
  28245. 'multiply': 564,
  28246. 'uacute': 500,
  28247. 'Tcaron': 611,
  28248. 'partialdiff': 476,
  28249. 'ydieresis': 500,
  28250. 'Nacute': 722,
  28251. 'icircumflex': 278,
  28252. 'Ecircumflex': 611,
  28253. 'adieresis': 444,
  28254. 'edieresis': 444,
  28255. 'cacute': 444,
  28256. 'nacute': 500,
  28257. 'umacron': 500,
  28258. 'Ncaron': 722,
  28259. 'Iacute': 333,
  28260. 'plusminus': 564,
  28261. 'brokenbar': 200,
  28262. 'registered': 760,
  28263. 'Gbreve': 722,
  28264. 'Idotaccent': 333,
  28265. 'summation': 600,
  28266. 'Egrave': 611,
  28267. 'racute': 333,
  28268. 'omacron': 500,
  28269. 'Zacute': 611,
  28270. 'Zcaron': 611,
  28271. 'greaterequal': 549,
  28272. 'Eth': 722,
  28273. 'Ccedilla': 667,
  28274. 'lcommaaccent': 278,
  28275. 'tcaron': 326,
  28276. 'eogonek': 444,
  28277. 'Uogonek': 722,
  28278. 'Aacute': 722,
  28279. 'Adieresis': 722,
  28280. 'egrave': 444,
  28281. 'zacute': 444,
  28282. 'iogonek': 278,
  28283. 'Oacute': 722,
  28284. 'oacute': 500,
  28285. 'amacron': 444,
  28286. 'sacute': 389,
  28287. 'idieresis': 278,
  28288. 'Ocircumflex': 722,
  28289. 'Ugrave': 722,
  28290. 'Delta': 612,
  28291. 'thorn': 500,
  28292. 'twosuperior': 300,
  28293. 'Odieresis': 722,
  28294. 'mu': 500,
  28295. 'igrave': 278,
  28296. 'ohungarumlaut': 500,
  28297. 'Eogonek': 611,
  28298. 'dcroat': 500,
  28299. 'threequarters': 750,
  28300. 'Scedilla': 556,
  28301. 'lcaron': 344,
  28302. 'Kcommaaccent': 722,
  28303. 'Lacute': 611,
  28304. 'trademark': 980,
  28305. 'edotaccent': 444,
  28306. 'Igrave': 333,
  28307. 'Imacron': 333,
  28308. 'Lcaron': 611,
  28309. 'onehalf': 750,
  28310. 'lessequal': 549,
  28311. 'ocircumflex': 500,
  28312. 'ntilde': 500,
  28313. 'Uhungarumlaut': 722,
  28314. 'Eacute': 611,
  28315. 'emacron': 444,
  28316. 'gbreve': 500,
  28317. 'onequarter': 750,
  28318. 'Scaron': 556,
  28319. 'Scommaaccent': 556,
  28320. 'Ohungarumlaut': 722,
  28321. 'degree': 400,
  28322. 'ograve': 500,
  28323. 'Ccaron': 667,
  28324. 'ugrave': 500,
  28325. 'radical': 453,
  28326. 'Dcaron': 722,
  28327. 'rcommaaccent': 333,
  28328. 'Ntilde': 722,
  28329. 'otilde': 500,
  28330. 'Rcommaaccent': 667,
  28331. 'Lcommaaccent': 611,
  28332. 'Atilde': 722,
  28333. 'Aogonek': 722,
  28334. 'Aring': 722,
  28335. 'Otilde': 722,
  28336. 'zdotaccent': 444,
  28337. 'Ecaron': 611,
  28338. 'Iogonek': 333,
  28339. 'kcommaaccent': 500,
  28340. 'minus': 564,
  28341. 'Icircumflex': 333,
  28342. 'ncaron': 500,
  28343. 'tcommaaccent': 278,
  28344. 'logicalnot': 564,
  28345. 'odieresis': 500,
  28346. 'udieresis': 500,
  28347. 'notequal': 549,
  28348. 'gcommaaccent': 500,
  28349. 'eth': 500,
  28350. 'zcaron': 444,
  28351. 'ncommaaccent': 500,
  28352. 'onesuperior': 300,
  28353. 'imacron': 278,
  28354. 'Euro': 500
  28355. },
  28356. 'Times-Bold': {
  28357. 'space': 250,
  28358. 'exclam': 333,
  28359. 'quotedbl': 555,
  28360. 'numbersign': 500,
  28361. 'dollar': 500,
  28362. 'percent': 1000,
  28363. 'ampersand': 833,
  28364. 'quoteright': 333,
  28365. 'parenleft': 333,
  28366. 'parenright': 333,
  28367. 'asterisk': 500,
  28368. 'plus': 570,
  28369. 'comma': 250,
  28370. 'hyphen': 333,
  28371. 'period': 250,
  28372. 'slash': 278,
  28373. 'zero': 500,
  28374. 'one': 500,
  28375. 'two': 500,
  28376. 'three': 500,
  28377. 'four': 500,
  28378. 'five': 500,
  28379. 'six': 500,
  28380. 'seven': 500,
  28381. 'eight': 500,
  28382. 'nine': 500,
  28383. 'colon': 333,
  28384. 'semicolon': 333,
  28385. 'less': 570,
  28386. 'equal': 570,
  28387. 'greater': 570,
  28388. 'question': 500,
  28389. 'at': 930,
  28390. 'A': 722,
  28391. 'B': 667,
  28392. 'C': 722,
  28393. 'D': 722,
  28394. 'E': 667,
  28395. 'F': 611,
  28396. 'G': 778,
  28397. 'H': 778,
  28398. 'I': 389,
  28399. 'J': 500,
  28400. 'K': 778,
  28401. 'L': 667,
  28402. 'M': 944,
  28403. 'N': 722,
  28404. 'O': 778,
  28405. 'P': 611,
  28406. 'Q': 778,
  28407. 'R': 722,
  28408. 'S': 556,
  28409. 'T': 667,
  28410. 'U': 722,
  28411. 'V': 722,
  28412. 'W': 1000,
  28413. 'X': 722,
  28414. 'Y': 722,
  28415. 'Z': 667,
  28416. 'bracketleft': 333,
  28417. 'backslash': 278,
  28418. 'bracketright': 333,
  28419. 'asciicircum': 581,
  28420. 'underscore': 500,
  28421. 'quoteleft': 333,
  28422. 'a': 500,
  28423. 'b': 556,
  28424. 'c': 444,
  28425. 'd': 556,
  28426. 'e': 444,
  28427. 'f': 333,
  28428. 'g': 500,
  28429. 'h': 556,
  28430. 'i': 278,
  28431. 'j': 333,
  28432. 'k': 556,
  28433. 'l': 278,
  28434. 'm': 833,
  28435. 'n': 556,
  28436. 'o': 500,
  28437. 'p': 556,
  28438. 'q': 556,
  28439. 'r': 444,
  28440. 's': 389,
  28441. 't': 333,
  28442. 'u': 556,
  28443. 'v': 500,
  28444. 'w': 722,
  28445. 'x': 500,
  28446. 'y': 500,
  28447. 'z': 444,
  28448. 'braceleft': 394,
  28449. 'bar': 220,
  28450. 'braceright': 394,
  28451. 'asciitilde': 520,
  28452. 'exclamdown': 333,
  28453. 'cent': 500,
  28454. 'sterling': 500,
  28455. 'fraction': 167,
  28456. 'yen': 500,
  28457. 'florin': 500,
  28458. 'section': 500,
  28459. 'currency': 500,
  28460. 'quotesingle': 278,
  28461. 'quotedblleft': 500,
  28462. 'guillemotleft': 500,
  28463. 'guilsinglleft': 333,
  28464. 'guilsinglright': 333,
  28465. 'fi': 556,
  28466. 'fl': 556,
  28467. 'endash': 500,
  28468. 'dagger': 500,
  28469. 'daggerdbl': 500,
  28470. 'periodcentered': 250,
  28471. 'paragraph': 540,
  28472. 'bullet': 350,
  28473. 'quotesinglbase': 333,
  28474. 'quotedblbase': 500,
  28475. 'quotedblright': 500,
  28476. 'guillemotright': 500,
  28477. 'ellipsis': 1000,
  28478. 'perthousand': 1000,
  28479. 'questiondown': 500,
  28480. 'grave': 333,
  28481. 'acute': 333,
  28482. 'circumflex': 333,
  28483. 'tilde': 333,
  28484. 'macron': 333,
  28485. 'breve': 333,
  28486. 'dotaccent': 333,
  28487. 'dieresis': 333,
  28488. 'ring': 333,
  28489. 'cedilla': 333,
  28490. 'hungarumlaut': 333,
  28491. 'ogonek': 333,
  28492. 'caron': 333,
  28493. 'emdash': 1000,
  28494. 'AE': 1000,
  28495. 'ordfeminine': 300,
  28496. 'Lslash': 667,
  28497. 'Oslash': 778,
  28498. 'OE': 1000,
  28499. 'ordmasculine': 330,
  28500. 'ae': 722,
  28501. 'dotlessi': 278,
  28502. 'lslash': 278,
  28503. 'oslash': 500,
  28504. 'oe': 722,
  28505. 'germandbls': 556,
  28506. 'Idieresis': 389,
  28507. 'eacute': 444,
  28508. 'abreve': 500,
  28509. 'uhungarumlaut': 556,
  28510. 'ecaron': 444,
  28511. 'Ydieresis': 722,
  28512. 'divide': 570,
  28513. 'Yacute': 722,
  28514. 'Acircumflex': 722,
  28515. 'aacute': 500,
  28516. 'Ucircumflex': 722,
  28517. 'yacute': 500,
  28518. 'scommaaccent': 389,
  28519. 'ecircumflex': 444,
  28520. 'Uring': 722,
  28521. 'Udieresis': 722,
  28522. 'aogonek': 500,
  28523. 'Uacute': 722,
  28524. 'uogonek': 556,
  28525. 'Edieresis': 667,
  28526. 'Dcroat': 722,
  28527. 'commaaccent': 250,
  28528. 'copyright': 747,
  28529. 'Emacron': 667,
  28530. 'ccaron': 444,
  28531. 'aring': 500,
  28532. 'Ncommaaccent': 722,
  28533. 'lacute': 278,
  28534. 'agrave': 500,
  28535. 'Tcommaaccent': 667,
  28536. 'Cacute': 722,
  28537. 'atilde': 500,
  28538. 'Edotaccent': 667,
  28539. 'scaron': 389,
  28540. 'scedilla': 389,
  28541. 'iacute': 278,
  28542. 'lozenge': 494,
  28543. 'Rcaron': 722,
  28544. 'Gcommaaccent': 778,
  28545. 'ucircumflex': 556,
  28546. 'acircumflex': 500,
  28547. 'Amacron': 722,
  28548. 'rcaron': 444,
  28549. 'ccedilla': 444,
  28550. 'Zdotaccent': 667,
  28551. 'Thorn': 611,
  28552. 'Omacron': 778,
  28553. 'Racute': 722,
  28554. 'Sacute': 556,
  28555. 'dcaron': 672,
  28556. 'Umacron': 722,
  28557. 'uring': 556,
  28558. 'threesuperior': 300,
  28559. 'Ograve': 778,
  28560. 'Agrave': 722,
  28561. 'Abreve': 722,
  28562. 'multiply': 570,
  28563. 'uacute': 556,
  28564. 'Tcaron': 667,
  28565. 'partialdiff': 494,
  28566. 'ydieresis': 500,
  28567. 'Nacute': 722,
  28568. 'icircumflex': 278,
  28569. 'Ecircumflex': 667,
  28570. 'adieresis': 500,
  28571. 'edieresis': 444,
  28572. 'cacute': 444,
  28573. 'nacute': 556,
  28574. 'umacron': 556,
  28575. 'Ncaron': 722,
  28576. 'Iacute': 389,
  28577. 'plusminus': 570,
  28578. 'brokenbar': 220,
  28579. 'registered': 747,
  28580. 'Gbreve': 778,
  28581. 'Idotaccent': 389,
  28582. 'summation': 600,
  28583. 'Egrave': 667,
  28584. 'racute': 444,
  28585. 'omacron': 500,
  28586. 'Zacute': 667,
  28587. 'Zcaron': 667,
  28588. 'greaterequal': 549,
  28589. 'Eth': 722,
  28590. 'Ccedilla': 722,
  28591. 'lcommaaccent': 278,
  28592. 'tcaron': 416,
  28593. 'eogonek': 444,
  28594. 'Uogonek': 722,
  28595. 'Aacute': 722,
  28596. 'Adieresis': 722,
  28597. 'egrave': 444,
  28598. 'zacute': 444,
  28599. 'iogonek': 278,
  28600. 'Oacute': 778,
  28601. 'oacute': 500,
  28602. 'amacron': 500,
  28603. 'sacute': 389,
  28604. 'idieresis': 278,
  28605. 'Ocircumflex': 778,
  28606. 'Ugrave': 722,
  28607. 'Delta': 612,
  28608. 'thorn': 556,
  28609. 'twosuperior': 300,
  28610. 'Odieresis': 778,
  28611. 'mu': 556,
  28612. 'igrave': 278,
  28613. 'ohungarumlaut': 500,
  28614. 'Eogonek': 667,
  28615. 'dcroat': 556,
  28616. 'threequarters': 750,
  28617. 'Scedilla': 556,
  28618. 'lcaron': 394,
  28619. 'Kcommaaccent': 778,
  28620. 'Lacute': 667,
  28621. 'trademark': 1000,
  28622. 'edotaccent': 444,
  28623. 'Igrave': 389,
  28624. 'Imacron': 389,
  28625. 'Lcaron': 667,
  28626. 'onehalf': 750,
  28627. 'lessequal': 549,
  28628. 'ocircumflex': 500,
  28629. 'ntilde': 556,
  28630. 'Uhungarumlaut': 722,
  28631. 'Eacute': 667,
  28632. 'emacron': 444,
  28633. 'gbreve': 500,
  28634. 'onequarter': 750,
  28635. 'Scaron': 556,
  28636. 'Scommaaccent': 556,
  28637. 'Ohungarumlaut': 778,
  28638. 'degree': 400,
  28639. 'ograve': 500,
  28640. 'Ccaron': 722,
  28641. 'ugrave': 556,
  28642. 'radical': 549,
  28643. 'Dcaron': 722,
  28644. 'rcommaaccent': 444,
  28645. 'Ntilde': 722,
  28646. 'otilde': 500,
  28647. 'Rcommaaccent': 722,
  28648. 'Lcommaaccent': 667,
  28649. 'Atilde': 722,
  28650. 'Aogonek': 722,
  28651. 'Aring': 722,
  28652. 'Otilde': 778,
  28653. 'zdotaccent': 444,
  28654. 'Ecaron': 667,
  28655. 'Iogonek': 389,
  28656. 'kcommaaccent': 556,
  28657. 'minus': 570,
  28658. 'Icircumflex': 389,
  28659. 'ncaron': 556,
  28660. 'tcommaaccent': 333,
  28661. 'logicalnot': 570,
  28662. 'odieresis': 500,
  28663. 'udieresis': 556,
  28664. 'notequal': 549,
  28665. 'gcommaaccent': 500,
  28666. 'eth': 500,
  28667. 'zcaron': 444,
  28668. 'ncommaaccent': 556,
  28669. 'onesuperior': 300,
  28670. 'imacron': 278,
  28671. 'Euro': 500
  28672. },
  28673. 'Times-BoldItalic': {
  28674. 'space': 250,
  28675. 'exclam': 389,
  28676. 'quotedbl': 555,
  28677. 'numbersign': 500,
  28678. 'dollar': 500,
  28679. 'percent': 833,
  28680. 'ampersand': 778,
  28681. 'quoteright': 333,
  28682. 'parenleft': 333,
  28683. 'parenright': 333,
  28684. 'asterisk': 500,
  28685. 'plus': 570,
  28686. 'comma': 250,
  28687. 'hyphen': 333,
  28688. 'period': 250,
  28689. 'slash': 278,
  28690. 'zero': 500,
  28691. 'one': 500,
  28692. 'two': 500,
  28693. 'three': 500,
  28694. 'four': 500,
  28695. 'five': 500,
  28696. 'six': 500,
  28697. 'seven': 500,
  28698. 'eight': 500,
  28699. 'nine': 500,
  28700. 'colon': 333,
  28701. 'semicolon': 333,
  28702. 'less': 570,
  28703. 'equal': 570,
  28704. 'greater': 570,
  28705. 'question': 500,
  28706. 'at': 832,
  28707. 'A': 667,
  28708. 'B': 667,
  28709. 'C': 667,
  28710. 'D': 722,
  28711. 'E': 667,
  28712. 'F': 667,
  28713. 'G': 722,
  28714. 'H': 778,
  28715. 'I': 389,
  28716. 'J': 500,
  28717. 'K': 667,
  28718. 'L': 611,
  28719. 'M': 889,
  28720. 'N': 722,
  28721. 'O': 722,
  28722. 'P': 611,
  28723. 'Q': 722,
  28724. 'R': 667,
  28725. 'S': 556,
  28726. 'T': 611,
  28727. 'U': 722,
  28728. 'V': 667,
  28729. 'W': 889,
  28730. 'X': 667,
  28731. 'Y': 611,
  28732. 'Z': 611,
  28733. 'bracketleft': 333,
  28734. 'backslash': 278,
  28735. 'bracketright': 333,
  28736. 'asciicircum': 570,
  28737. 'underscore': 500,
  28738. 'quoteleft': 333,
  28739. 'a': 500,
  28740. 'b': 500,
  28741. 'c': 444,
  28742. 'd': 500,
  28743. 'e': 444,
  28744. 'f': 333,
  28745. 'g': 500,
  28746. 'h': 556,
  28747. 'i': 278,
  28748. 'j': 278,
  28749. 'k': 500,
  28750. 'l': 278,
  28751. 'm': 778,
  28752. 'n': 556,
  28753. 'o': 500,
  28754. 'p': 500,
  28755. 'q': 500,
  28756. 'r': 389,
  28757. 's': 389,
  28758. 't': 278,
  28759. 'u': 556,
  28760. 'v': 444,
  28761. 'w': 667,
  28762. 'x': 500,
  28763. 'y': 444,
  28764. 'z': 389,
  28765. 'braceleft': 348,
  28766. 'bar': 220,
  28767. 'braceright': 348,
  28768. 'asciitilde': 570,
  28769. 'exclamdown': 389,
  28770. 'cent': 500,
  28771. 'sterling': 500,
  28772. 'fraction': 167,
  28773. 'yen': 500,
  28774. 'florin': 500,
  28775. 'section': 500,
  28776. 'currency': 500,
  28777. 'quotesingle': 278,
  28778. 'quotedblleft': 500,
  28779. 'guillemotleft': 500,
  28780. 'guilsinglleft': 333,
  28781. 'guilsinglright': 333,
  28782. 'fi': 556,
  28783. 'fl': 556,
  28784. 'endash': 500,
  28785. 'dagger': 500,
  28786. 'daggerdbl': 500,
  28787. 'periodcentered': 250,
  28788. 'paragraph': 500,
  28789. 'bullet': 350,
  28790. 'quotesinglbase': 333,
  28791. 'quotedblbase': 500,
  28792. 'quotedblright': 500,
  28793. 'guillemotright': 500,
  28794. 'ellipsis': 1000,
  28795. 'perthousand': 1000,
  28796. 'questiondown': 500,
  28797. 'grave': 333,
  28798. 'acute': 333,
  28799. 'circumflex': 333,
  28800. 'tilde': 333,
  28801. 'macron': 333,
  28802. 'breve': 333,
  28803. 'dotaccent': 333,
  28804. 'dieresis': 333,
  28805. 'ring': 333,
  28806. 'cedilla': 333,
  28807. 'hungarumlaut': 333,
  28808. 'ogonek': 333,
  28809. 'caron': 333,
  28810. 'emdash': 1000,
  28811. 'AE': 944,
  28812. 'ordfeminine': 266,
  28813. 'Lslash': 611,
  28814. 'Oslash': 722,
  28815. 'OE': 944,
  28816. 'ordmasculine': 300,
  28817. 'ae': 722,
  28818. 'dotlessi': 278,
  28819. 'lslash': 278,
  28820. 'oslash': 500,
  28821. 'oe': 722,
  28822. 'germandbls': 500,
  28823. 'Idieresis': 389,
  28824. 'eacute': 444,
  28825. 'abreve': 500,
  28826. 'uhungarumlaut': 556,
  28827. 'ecaron': 444,
  28828. 'Ydieresis': 611,
  28829. 'divide': 570,
  28830. 'Yacute': 611,
  28831. 'Acircumflex': 667,
  28832. 'aacute': 500,
  28833. 'Ucircumflex': 722,
  28834. 'yacute': 444,
  28835. 'scommaaccent': 389,
  28836. 'ecircumflex': 444,
  28837. 'Uring': 722,
  28838. 'Udieresis': 722,
  28839. 'aogonek': 500,
  28840. 'Uacute': 722,
  28841. 'uogonek': 556,
  28842. 'Edieresis': 667,
  28843. 'Dcroat': 722,
  28844. 'commaaccent': 250,
  28845. 'copyright': 747,
  28846. 'Emacron': 667,
  28847. 'ccaron': 444,
  28848. 'aring': 500,
  28849. 'Ncommaaccent': 722,
  28850. 'lacute': 278,
  28851. 'agrave': 500,
  28852. 'Tcommaaccent': 611,
  28853. 'Cacute': 667,
  28854. 'atilde': 500,
  28855. 'Edotaccent': 667,
  28856. 'scaron': 389,
  28857. 'scedilla': 389,
  28858. 'iacute': 278,
  28859. 'lozenge': 494,
  28860. 'Rcaron': 667,
  28861. 'Gcommaaccent': 722,
  28862. 'ucircumflex': 556,
  28863. 'acircumflex': 500,
  28864. 'Amacron': 667,
  28865. 'rcaron': 389,
  28866. 'ccedilla': 444,
  28867. 'Zdotaccent': 611,
  28868. 'Thorn': 611,
  28869. 'Omacron': 722,
  28870. 'Racute': 667,
  28871. 'Sacute': 556,
  28872. 'dcaron': 608,
  28873. 'Umacron': 722,
  28874. 'uring': 556,
  28875. 'threesuperior': 300,
  28876. 'Ograve': 722,
  28877. 'Agrave': 667,
  28878. 'Abreve': 667,
  28879. 'multiply': 570,
  28880. 'uacute': 556,
  28881. 'Tcaron': 611,
  28882. 'partialdiff': 494,
  28883. 'ydieresis': 444,
  28884. 'Nacute': 722,
  28885. 'icircumflex': 278,
  28886. 'Ecircumflex': 667,
  28887. 'adieresis': 500,
  28888. 'edieresis': 444,
  28889. 'cacute': 444,
  28890. 'nacute': 556,
  28891. 'umacron': 556,
  28892. 'Ncaron': 722,
  28893. 'Iacute': 389,
  28894. 'plusminus': 570,
  28895. 'brokenbar': 220,
  28896. 'registered': 747,
  28897. 'Gbreve': 722,
  28898. 'Idotaccent': 389,
  28899. 'summation': 600,
  28900. 'Egrave': 667,
  28901. 'racute': 389,
  28902. 'omacron': 500,
  28903. 'Zacute': 611,
  28904. 'Zcaron': 611,
  28905. 'greaterequal': 549,
  28906. 'Eth': 722,
  28907. 'Ccedilla': 667,
  28908. 'lcommaaccent': 278,
  28909. 'tcaron': 366,
  28910. 'eogonek': 444,
  28911. 'Uogonek': 722,
  28912. 'Aacute': 667,
  28913. 'Adieresis': 667,
  28914. 'egrave': 444,
  28915. 'zacute': 389,
  28916. 'iogonek': 278,
  28917. 'Oacute': 722,
  28918. 'oacute': 500,
  28919. 'amacron': 500,
  28920. 'sacute': 389,
  28921. 'idieresis': 278,
  28922. 'Ocircumflex': 722,
  28923. 'Ugrave': 722,
  28924. 'Delta': 612,
  28925. 'thorn': 500,
  28926. 'twosuperior': 300,
  28927. 'Odieresis': 722,
  28928. 'mu': 576,
  28929. 'igrave': 278,
  28930. 'ohungarumlaut': 500,
  28931. 'Eogonek': 667,
  28932. 'dcroat': 500,
  28933. 'threequarters': 750,
  28934. 'Scedilla': 556,
  28935. 'lcaron': 382,
  28936. 'Kcommaaccent': 667,
  28937. 'Lacute': 611,
  28938. 'trademark': 1000,
  28939. 'edotaccent': 444,
  28940. 'Igrave': 389,
  28941. 'Imacron': 389,
  28942. 'Lcaron': 611,
  28943. 'onehalf': 750,
  28944. 'lessequal': 549,
  28945. 'ocircumflex': 500,
  28946. 'ntilde': 556,
  28947. 'Uhungarumlaut': 722,
  28948. 'Eacute': 667,
  28949. 'emacron': 444,
  28950. 'gbreve': 500,
  28951. 'onequarter': 750,
  28952. 'Scaron': 556,
  28953. 'Scommaaccent': 556,
  28954. 'Ohungarumlaut': 722,
  28955. 'degree': 400,
  28956. 'ograve': 500,
  28957. 'Ccaron': 667,
  28958. 'ugrave': 556,
  28959. 'radical': 549,
  28960. 'Dcaron': 722,
  28961. 'rcommaaccent': 389,
  28962. 'Ntilde': 722,
  28963. 'otilde': 500,
  28964. 'Rcommaaccent': 667,
  28965. 'Lcommaaccent': 611,
  28966. 'Atilde': 667,
  28967. 'Aogonek': 667,
  28968. 'Aring': 667,
  28969. 'Otilde': 722,
  28970. 'zdotaccent': 389,
  28971. 'Ecaron': 667,
  28972. 'Iogonek': 389,
  28973. 'kcommaaccent': 500,
  28974. 'minus': 606,
  28975. 'Icircumflex': 389,
  28976. 'ncaron': 556,
  28977. 'tcommaaccent': 278,
  28978. 'logicalnot': 606,
  28979. 'odieresis': 500,
  28980. 'udieresis': 556,
  28981. 'notequal': 549,
  28982. 'gcommaaccent': 500,
  28983. 'eth': 500,
  28984. 'zcaron': 389,
  28985. 'ncommaaccent': 556,
  28986. 'onesuperior': 300,
  28987. 'imacron': 278,
  28988. 'Euro': 500
  28989. },
  28990. 'Times-Italic': {
  28991. 'space': 250,
  28992. 'exclam': 333,
  28993. 'quotedbl': 420,
  28994. 'numbersign': 500,
  28995. 'dollar': 500,
  28996. 'percent': 833,
  28997. 'ampersand': 778,
  28998. 'quoteright': 333,
  28999. 'parenleft': 333,
  29000. 'parenright': 333,
  29001. 'asterisk': 500,
  29002. 'plus': 675,
  29003. 'comma': 250,
  29004. 'hyphen': 333,
  29005. 'period': 250,
  29006. 'slash': 278,
  29007. 'zero': 500,
  29008. 'one': 500,
  29009. 'two': 500,
  29010. 'three': 500,
  29011. 'four': 500,
  29012. 'five': 500,
  29013. 'six': 500,
  29014. 'seven': 500,
  29015. 'eight': 500,
  29016. 'nine': 500,
  29017. 'colon': 333,
  29018. 'semicolon': 333,
  29019. 'less': 675,
  29020. 'equal': 675,
  29021. 'greater': 675,
  29022. 'question': 500,
  29023. 'at': 920,
  29024. 'A': 611,
  29025. 'B': 611,
  29026. 'C': 667,
  29027. 'D': 722,
  29028. 'E': 611,
  29029. 'F': 611,
  29030. 'G': 722,
  29031. 'H': 722,
  29032. 'I': 333,
  29033. 'J': 444,
  29034. 'K': 667,
  29035. 'L': 556,
  29036. 'M': 833,
  29037. 'N': 667,
  29038. 'O': 722,
  29039. 'P': 611,
  29040. 'Q': 722,
  29041. 'R': 611,
  29042. 'S': 500,
  29043. 'T': 556,
  29044. 'U': 722,
  29045. 'V': 611,
  29046. 'W': 833,
  29047. 'X': 611,
  29048. 'Y': 556,
  29049. 'Z': 556,
  29050. 'bracketleft': 389,
  29051. 'backslash': 278,
  29052. 'bracketright': 389,
  29053. 'asciicircum': 422,
  29054. 'underscore': 500,
  29055. 'quoteleft': 333,
  29056. 'a': 500,
  29057. 'b': 500,
  29058. 'c': 444,
  29059. 'd': 500,
  29060. 'e': 444,
  29061. 'f': 278,
  29062. 'g': 500,
  29063. 'h': 500,
  29064. 'i': 278,
  29065. 'j': 278,
  29066. 'k': 444,
  29067. 'l': 278,
  29068. 'm': 722,
  29069. 'n': 500,
  29070. 'o': 500,
  29071. 'p': 500,
  29072. 'q': 500,
  29073. 'r': 389,
  29074. 's': 389,
  29075. 't': 278,
  29076. 'u': 500,
  29077. 'v': 444,
  29078. 'w': 667,
  29079. 'x': 444,
  29080. 'y': 444,
  29081. 'z': 389,
  29082. 'braceleft': 400,
  29083. 'bar': 275,
  29084. 'braceright': 400,
  29085. 'asciitilde': 541,
  29086. 'exclamdown': 389,
  29087. 'cent': 500,
  29088. 'sterling': 500,
  29089. 'fraction': 167,
  29090. 'yen': 500,
  29091. 'florin': 500,
  29092. 'section': 500,
  29093. 'currency': 500,
  29094. 'quotesingle': 214,
  29095. 'quotedblleft': 556,
  29096. 'guillemotleft': 500,
  29097. 'guilsinglleft': 333,
  29098. 'guilsinglright': 333,
  29099. 'fi': 500,
  29100. 'fl': 500,
  29101. 'endash': 500,
  29102. 'dagger': 500,
  29103. 'daggerdbl': 500,
  29104. 'periodcentered': 250,
  29105. 'paragraph': 523,
  29106. 'bullet': 350,
  29107. 'quotesinglbase': 333,
  29108. 'quotedblbase': 556,
  29109. 'quotedblright': 556,
  29110. 'guillemotright': 500,
  29111. 'ellipsis': 889,
  29112. 'perthousand': 1000,
  29113. 'questiondown': 500,
  29114. 'grave': 333,
  29115. 'acute': 333,
  29116. 'circumflex': 333,
  29117. 'tilde': 333,
  29118. 'macron': 333,
  29119. 'breve': 333,
  29120. 'dotaccent': 333,
  29121. 'dieresis': 333,
  29122. 'ring': 333,
  29123. 'cedilla': 333,
  29124. 'hungarumlaut': 333,
  29125. 'ogonek': 333,
  29126. 'caron': 333,
  29127. 'emdash': 889,
  29128. 'AE': 889,
  29129. 'ordfeminine': 276,
  29130. 'Lslash': 556,
  29131. 'Oslash': 722,
  29132. 'OE': 944,
  29133. 'ordmasculine': 310,
  29134. 'ae': 667,
  29135. 'dotlessi': 278,
  29136. 'lslash': 278,
  29137. 'oslash': 500,
  29138. 'oe': 667,
  29139. 'germandbls': 500,
  29140. 'Idieresis': 333,
  29141. 'eacute': 444,
  29142. 'abreve': 500,
  29143. 'uhungarumlaut': 500,
  29144. 'ecaron': 444,
  29145. 'Ydieresis': 556,
  29146. 'divide': 675,
  29147. 'Yacute': 556,
  29148. 'Acircumflex': 611,
  29149. 'aacute': 500,
  29150. 'Ucircumflex': 722,
  29151. 'yacute': 444,
  29152. 'scommaaccent': 389,
  29153. 'ecircumflex': 444,
  29154. 'Uring': 722,
  29155. 'Udieresis': 722,
  29156. 'aogonek': 500,
  29157. 'Uacute': 722,
  29158. 'uogonek': 500,
  29159. 'Edieresis': 611,
  29160. 'Dcroat': 722,
  29161. 'commaaccent': 250,
  29162. 'copyright': 760,
  29163. 'Emacron': 611,
  29164. 'ccaron': 444,
  29165. 'aring': 500,
  29166. 'Ncommaaccent': 667,
  29167. 'lacute': 278,
  29168. 'agrave': 500,
  29169. 'Tcommaaccent': 556,
  29170. 'Cacute': 667,
  29171. 'atilde': 500,
  29172. 'Edotaccent': 611,
  29173. 'scaron': 389,
  29174. 'scedilla': 389,
  29175. 'iacute': 278,
  29176. 'lozenge': 471,
  29177. 'Rcaron': 611,
  29178. 'Gcommaaccent': 722,
  29179. 'ucircumflex': 500,
  29180. 'acircumflex': 500,
  29181. 'Amacron': 611,
  29182. 'rcaron': 389,
  29183. 'ccedilla': 444,
  29184. 'Zdotaccent': 556,
  29185. 'Thorn': 611,
  29186. 'Omacron': 722,
  29187. 'Racute': 611,
  29188. 'Sacute': 500,
  29189. 'dcaron': 544,
  29190. 'Umacron': 722,
  29191. 'uring': 500,
  29192. 'threesuperior': 300,
  29193. 'Ograve': 722,
  29194. 'Agrave': 611,
  29195. 'Abreve': 611,
  29196. 'multiply': 675,
  29197. 'uacute': 500,
  29198. 'Tcaron': 556,
  29199. 'partialdiff': 476,
  29200. 'ydieresis': 444,
  29201. 'Nacute': 667,
  29202. 'icircumflex': 278,
  29203. 'Ecircumflex': 611,
  29204. 'adieresis': 500,
  29205. 'edieresis': 444,
  29206. 'cacute': 444,
  29207. 'nacute': 500,
  29208. 'umacron': 500,
  29209. 'Ncaron': 667,
  29210. 'Iacute': 333,
  29211. 'plusminus': 675,
  29212. 'brokenbar': 275,
  29213. 'registered': 760,
  29214. 'Gbreve': 722,
  29215. 'Idotaccent': 333,
  29216. 'summation': 600,
  29217. 'Egrave': 611,
  29218. 'racute': 389,
  29219. 'omacron': 500,
  29220. 'Zacute': 556,
  29221. 'Zcaron': 556,
  29222. 'greaterequal': 549,
  29223. 'Eth': 722,
  29224. 'Ccedilla': 667,
  29225. 'lcommaaccent': 278,
  29226. 'tcaron': 300,
  29227. 'eogonek': 444,
  29228. 'Uogonek': 722,
  29229. 'Aacute': 611,
  29230. 'Adieresis': 611,
  29231. 'egrave': 444,
  29232. 'zacute': 389,
  29233. 'iogonek': 278,
  29234. 'Oacute': 722,
  29235. 'oacute': 500,
  29236. 'amacron': 500,
  29237. 'sacute': 389,
  29238. 'idieresis': 278,
  29239. 'Ocircumflex': 722,
  29240. 'Ugrave': 722,
  29241. 'Delta': 612,
  29242. 'thorn': 500,
  29243. 'twosuperior': 300,
  29244. 'Odieresis': 722,
  29245. 'mu': 500,
  29246. 'igrave': 278,
  29247. 'ohungarumlaut': 500,
  29248. 'Eogonek': 611,
  29249. 'dcroat': 500,
  29250. 'threequarters': 750,
  29251. 'Scedilla': 500,
  29252. 'lcaron': 300,
  29253. 'Kcommaaccent': 667,
  29254. 'Lacute': 556,
  29255. 'trademark': 980,
  29256. 'edotaccent': 444,
  29257. 'Igrave': 333,
  29258. 'Imacron': 333,
  29259. 'Lcaron': 611,
  29260. 'onehalf': 750,
  29261. 'lessequal': 549,
  29262. 'ocircumflex': 500,
  29263. 'ntilde': 500,
  29264. 'Uhungarumlaut': 722,
  29265. 'Eacute': 611,
  29266. 'emacron': 444,
  29267. 'gbreve': 500,
  29268. 'onequarter': 750,
  29269. 'Scaron': 500,
  29270. 'Scommaaccent': 500,
  29271. 'Ohungarumlaut': 722,
  29272. 'degree': 400,
  29273. 'ograve': 500,
  29274. 'Ccaron': 667,
  29275. 'ugrave': 500,
  29276. 'radical': 453,
  29277. 'Dcaron': 722,
  29278. 'rcommaaccent': 389,
  29279. 'Ntilde': 667,
  29280. 'otilde': 500,
  29281. 'Rcommaaccent': 611,
  29282. 'Lcommaaccent': 556,
  29283. 'Atilde': 611,
  29284. 'Aogonek': 611,
  29285. 'Aring': 611,
  29286. 'Otilde': 722,
  29287. 'zdotaccent': 389,
  29288. 'Ecaron': 611,
  29289. 'Iogonek': 333,
  29290. 'kcommaaccent': 444,
  29291. 'minus': 675,
  29292. 'Icircumflex': 333,
  29293. 'ncaron': 500,
  29294. 'tcommaaccent': 278,
  29295. 'logicalnot': 675,
  29296. 'odieresis': 500,
  29297. 'udieresis': 500,
  29298. 'notequal': 549,
  29299. 'gcommaaccent': 500,
  29300. 'eth': 500,
  29301. 'zcaron': 389,
  29302. 'ncommaaccent': 500,
  29303. 'onesuperior': 300,
  29304. 'imacron': 278,
  29305. 'Euro': 500
  29306. },
  29307. 'ZapfDingbats': {
  29308. 'space': 278,
  29309. 'a1': 974,
  29310. 'a2': 961,
  29311. 'a202': 974,
  29312. 'a3': 980,
  29313. 'a4': 719,
  29314. 'a5': 789,
  29315. 'a119': 790,
  29316. 'a118': 791,
  29317. 'a117': 690,
  29318. 'a11': 960,
  29319. 'a12': 939,
  29320. 'a13': 549,
  29321. 'a14': 855,
  29322. 'a15': 911,
  29323. 'a16': 933,
  29324. 'a105': 911,
  29325. 'a17': 945,
  29326. 'a18': 974,
  29327. 'a19': 755,
  29328. 'a20': 846,
  29329. 'a21': 762,
  29330. 'a22': 761,
  29331. 'a23': 571,
  29332. 'a24': 677,
  29333. 'a25': 763,
  29334. 'a26': 760,
  29335. 'a27': 759,
  29336. 'a28': 754,
  29337. 'a6': 494,
  29338. 'a7': 552,
  29339. 'a8': 537,
  29340. 'a9': 577,
  29341. 'a10': 692,
  29342. 'a29': 786,
  29343. 'a30': 788,
  29344. 'a31': 788,
  29345. 'a32': 790,
  29346. 'a33': 793,
  29347. 'a34': 794,
  29348. 'a35': 816,
  29349. 'a36': 823,
  29350. 'a37': 789,
  29351. 'a38': 841,
  29352. 'a39': 823,
  29353. 'a40': 833,
  29354. 'a41': 816,
  29355. 'a42': 831,
  29356. 'a43': 923,
  29357. 'a44': 744,
  29358. 'a45': 723,
  29359. 'a46': 749,
  29360. 'a47': 790,
  29361. 'a48': 792,
  29362. 'a49': 695,
  29363. 'a50': 776,
  29364. 'a51': 768,
  29365. 'a52': 792,
  29366. 'a53': 759,
  29367. 'a54': 707,
  29368. 'a55': 708,
  29369. 'a56': 682,
  29370. 'a57': 701,
  29371. 'a58': 826,
  29372. 'a59': 815,
  29373. 'a60': 789,
  29374. 'a61': 789,
  29375. 'a62': 707,
  29376. 'a63': 687,
  29377. 'a64': 696,
  29378. 'a65': 689,
  29379. 'a66': 786,
  29380. 'a67': 787,
  29381. 'a68': 713,
  29382. 'a69': 791,
  29383. 'a70': 785,
  29384. 'a71': 791,
  29385. 'a72': 873,
  29386. 'a73': 761,
  29387. 'a74': 762,
  29388. 'a203': 762,
  29389. 'a75': 759,
  29390. 'a204': 759,
  29391. 'a76': 892,
  29392. 'a77': 892,
  29393. 'a78': 788,
  29394. 'a79': 784,
  29395. 'a81': 438,
  29396. 'a82': 138,
  29397. 'a83': 277,
  29398. 'a84': 415,
  29399. 'a97': 392,
  29400. 'a98': 392,
  29401. 'a99': 668,
  29402. 'a100': 668,
  29403. 'a89': 390,
  29404. 'a90': 390,
  29405. 'a93': 317,
  29406. 'a94': 317,
  29407. 'a91': 276,
  29408. 'a92': 276,
  29409. 'a205': 509,
  29410. 'a85': 509,
  29411. 'a206': 410,
  29412. 'a86': 410,
  29413. 'a87': 234,
  29414. 'a88': 234,
  29415. 'a95': 334,
  29416. 'a96': 334,
  29417. 'a101': 732,
  29418. 'a102': 544,
  29419. 'a103': 544,
  29420. 'a104': 910,
  29421. 'a106': 667,
  29422. 'a107': 760,
  29423. 'a108': 760,
  29424. 'a112': 776,
  29425. 'a111': 595,
  29426. 'a110': 694,
  29427. 'a109': 626,
  29428. 'a120': 788,
  29429. 'a121': 788,
  29430. 'a122': 788,
  29431. 'a123': 788,
  29432. 'a124': 788,
  29433. 'a125': 788,
  29434. 'a126': 788,
  29435. 'a127': 788,
  29436. 'a128': 788,
  29437. 'a129': 788,
  29438. 'a130': 788,
  29439. 'a131': 788,
  29440. 'a132': 788,
  29441. 'a133': 788,
  29442. 'a134': 788,
  29443. 'a135': 788,
  29444. 'a136': 788,
  29445. 'a137': 788,
  29446. 'a138': 788,
  29447. 'a139': 788,
  29448. 'a140': 788,
  29449. 'a141': 788,
  29450. 'a142': 788,
  29451. 'a143': 788,
  29452. 'a144': 788,
  29453. 'a145': 788,
  29454. 'a146': 788,
  29455. 'a147': 788,
  29456. 'a148': 788,
  29457. 'a149': 788,
  29458. 'a150': 788,
  29459. 'a151': 788,
  29460. 'a152': 788,
  29461. 'a153': 788,
  29462. 'a154': 788,
  29463. 'a155': 788,
  29464. 'a156': 788,
  29465. 'a157': 788,
  29466. 'a158': 788,
  29467. 'a159': 788,
  29468. 'a160': 894,
  29469. 'a161': 838,
  29470. 'a163': 1016,
  29471. 'a164': 458,
  29472. 'a196': 748,
  29473. 'a165': 924,
  29474. 'a192': 748,
  29475. 'a166': 918,
  29476. 'a167': 927,
  29477. 'a168': 928,
  29478. 'a169': 928,
  29479. 'a170': 834,
  29480. 'a171': 873,
  29481. 'a172': 828,
  29482. 'a173': 924,
  29483. 'a162': 924,
  29484. 'a174': 917,
  29485. 'a175': 930,
  29486. 'a176': 931,
  29487. 'a177': 463,
  29488. 'a178': 883,
  29489. 'a179': 836,
  29490. 'a193': 836,
  29491. 'a180': 867,
  29492. 'a199': 867,
  29493. 'a181': 696,
  29494. 'a200': 696,
  29495. 'a182': 874,
  29496. 'a201': 874,
  29497. 'a183': 760,
  29498. 'a184': 946,
  29499. 'a197': 771,
  29500. 'a185': 865,
  29501. 'a194': 771,
  29502. 'a198': 888,
  29503. 'a186': 967,
  29504. 'a195': 888,
  29505. 'a187': 831,
  29506. 'a188': 873,
  29507. 'a189': 927,
  29508. 'a190': 970,
  29509. 'a191': 918
  29510. }
  29511. };
  29512. var EOF = {};
  29513. function isEOF(v) {
  29514. return (v === EOF);
  29515. }
  29516. var MAX_LENGTH_TO_CACHE = 1000;
  29517. var Parser = (function ParserClosure() {
  29518. function Parser(lexer, allowStreams, xref) {
  29519. this.lexer = lexer;
  29520. this.allowStreams = allowStreams;
  29521. this.xref = xref;
  29522. this.imageCache = {};
  29523. this.refill();
  29524. }
  29525. Parser.prototype = {
  29526. refill: function Parser_refill() {
  29527. this.buf1 = this.lexer.getObj();
  29528. this.buf2 = this.lexer.getObj();
  29529. },
  29530. shift: function Parser_shift() {
  29531. if (isCmd(this.buf2, 'ID')) {
  29532. this.buf1 = this.buf2;
  29533. this.buf2 = null;
  29534. } else {
  29535. this.buf1 = this.buf2;
  29536. this.buf2 = this.lexer.getObj();
  29537. }
  29538. },
  29539. tryShift: function Parser_tryShift() {
  29540. try {
  29541. this.shift();
  29542. return true;
  29543. } catch (e) {
  29544. if (e instanceof MissingDataException) {
  29545. throw e;
  29546. }
  29547. // Upon failure, the caller should reset this.lexer.pos to a known good
  29548. // state and call this.shift() twice to reset the buffers.
  29549. return false;
  29550. }
  29551. },
  29552. getObj: function Parser_getObj(cipherTransform) {
  29553. var buf1 = this.buf1;
  29554. this.shift();
  29555. if (buf1 instanceof Cmd) {
  29556. switch (buf1.cmd) {
  29557. case 'BI': // inline image
  29558. return this.makeInlineImage(cipherTransform);
  29559. case '[': // array
  29560. var array = [];
  29561. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  29562. array.push(this.getObj(cipherTransform));
  29563. }
  29564. if (isEOF(this.buf1)) {
  29565. error('End of file inside array');
  29566. }
  29567. this.shift();
  29568. return array;
  29569. case '<<': // dictionary or stream
  29570. var dict = new Dict(this.xref);
  29571. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  29572. if (!isName(this.buf1)) {
  29573. info('Malformed dictionary: key must be a name object');
  29574. this.shift();
  29575. continue;
  29576. }
  29577. var key = this.buf1.name;
  29578. this.shift();
  29579. if (isEOF(this.buf1)) {
  29580. break;
  29581. }
  29582. dict.set(key, this.getObj(cipherTransform));
  29583. }
  29584. if (isEOF(this.buf1)) {
  29585. error('End of file inside dictionary');
  29586. }
  29587. // Stream objects are not allowed inside content streams or
  29588. // object streams.
  29589. if (isCmd(this.buf2, 'stream')) {
  29590. return (this.allowStreams ?
  29591. this.makeStream(dict, cipherTransform) : dict);
  29592. }
  29593. this.shift();
  29594. return dict;
  29595. default: // simple object
  29596. return buf1;
  29597. }
  29598. }
  29599. if (isInt(buf1)) { // indirect reference or integer
  29600. var num = buf1;
  29601. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  29602. var ref = new Ref(num, this.buf1);
  29603. this.shift();
  29604. this.shift();
  29605. return ref;
  29606. }
  29607. return num;
  29608. }
  29609. if (isString(buf1)) { // string
  29610. var str = buf1;
  29611. if (cipherTransform) {
  29612. str = cipherTransform.decryptString(str);
  29613. }
  29614. return str;
  29615. }
  29616. // simple object
  29617. return buf1;
  29618. },
  29619. /**
  29620. * Find the end of the stream by searching for the /EI\s/.
  29621. * @returns {number} The inline stream length.
  29622. */
  29623. findDefaultInlineStreamEnd:
  29624. function Parser_findDefaultInlineStreamEnd(stream) {
  29625. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  29626. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  29627. while ((ch = stream.getByte()) !== -1) {
  29628. if (state === 0) {
  29629. state = (ch === E) ? 1 : 0;
  29630. } else if (state === 1) {
  29631. state = (ch === I) ? 2 : 0;
  29632. } else {
  29633. assert(state === 2);
  29634. if (ch === SPACE || ch === LF || ch === CR) {
  29635. // Let's check the next five bytes are ASCII... just be sure.
  29636. n = 5;
  29637. followingBytes = stream.peekBytes(n);
  29638. for (i = 0; i < n; i++) {
  29639. ch = followingBytes[i];
  29640. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  29641. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  29642. // it's binary stuff. Resetting the state.
  29643. state = 0;
  29644. break;
  29645. }
  29646. }
  29647. if (state === 2) {
  29648. break; // Finished!
  29649. }
  29650. } else {
  29651. state = 0;
  29652. }
  29653. }
  29654. }
  29655. return ((stream.pos - 4) - startPos);
  29656. },
  29657. /**
  29658. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  29659. * @returns {number} The inline stream length.
  29660. */
  29661. findDCTDecodeInlineStreamEnd:
  29662. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  29663. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  29664. while ((b = stream.getByte()) !== -1) {
  29665. if (b !== 0xFF) { // Not a valid marker.
  29666. continue;
  29667. }
  29668. switch (stream.getByte()) {
  29669. case 0x00: // Byte stuffing.
  29670. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  29671. break;
  29672. case 0xFF: // Fill byte.
  29673. // Avoid skipping a valid marker, resetting the stream position.
  29674. stream.skip(-1);
  29675. break;
  29676. case 0xD9: // EOI
  29677. foundEOI = true;
  29678. break;
  29679. case 0xC0: // SOF0
  29680. case 0xC1: // SOF1
  29681. case 0xC2: // SOF2
  29682. case 0xC3: // SOF3
  29683. case 0xC5: // SOF5
  29684. case 0xC6: // SOF6
  29685. case 0xC7: // SOF7
  29686. case 0xC9: // SOF9
  29687. case 0xCA: // SOF10
  29688. case 0xCB: // SOF11
  29689. case 0xCD: // SOF13
  29690. case 0xCE: // SOF14
  29691. case 0xCF: // SOF15
  29692. case 0xC4: // DHT
  29693. case 0xCC: // DAC
  29694. case 0xDA: // SOS
  29695. case 0xDB: // DQT
  29696. case 0xDC: // DNL
  29697. case 0xDD: // DRI
  29698. case 0xDE: // DHP
  29699. case 0xDF: // EXP
  29700. case 0xE0: // APP0
  29701. case 0xE1: // APP1
  29702. case 0xE2: // APP2
  29703. case 0xE3: // APP3
  29704. case 0xE4: // APP4
  29705. case 0xE5: // APP5
  29706. case 0xE6: // APP6
  29707. case 0xE7: // APP7
  29708. case 0xE8: // APP8
  29709. case 0xE9: // APP9
  29710. case 0xEA: // APP10
  29711. case 0xEB: // APP11
  29712. case 0xEC: // APP12
  29713. case 0xED: // APP13
  29714. case 0xEE: // APP14
  29715. case 0xEF: // APP15
  29716. case 0xFE: // COM
  29717. // The marker should be followed by the length of the segment.
  29718. markerLength = stream.getUint16();
  29719. if (markerLength > 2) {
  29720. // |markerLength| contains the byte length of the marker segment,
  29721. // including its own length (2 bytes) and excluding the marker.
  29722. stream.skip(markerLength - 2); // Jump to the next marker.
  29723. } else {
  29724. // The marker length is invalid, resetting the stream position.
  29725. stream.skip(-2);
  29726. }
  29727. break;
  29728. }
  29729. if (foundEOI) {
  29730. break;
  29731. }
  29732. }
  29733. length = stream.pos - startPos;
  29734. if (b === -1) {
  29735. warn('Inline DCTDecode image stream: ' +
  29736. 'EOI marker not found, searching for /EI/ instead.');
  29737. stream.skip(-length); // Reset the stream position.
  29738. return this.findDefaultInlineStreamEnd(stream);
  29739. }
  29740. this.inlineStreamSkipEI(stream);
  29741. return length;
  29742. },
  29743. /**
  29744. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  29745. * @returns {number} The inline stream length.
  29746. */
  29747. findASCII85DecodeInlineStreamEnd:
  29748. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  29749. var TILDE = 0x7E, GT = 0x3E;
  29750. var startPos = stream.pos, ch, length;
  29751. while ((ch = stream.getByte()) !== -1) {
  29752. if (ch === TILDE && stream.peekByte() === GT) {
  29753. stream.skip();
  29754. break;
  29755. }
  29756. }
  29757. length = stream.pos - startPos;
  29758. if (ch === -1) {
  29759. warn('Inline ASCII85Decode image stream: ' +
  29760. 'EOD marker not found, searching for /EI/ instead.');
  29761. stream.skip(-length); // Reset the stream position.
  29762. return this.findDefaultInlineStreamEnd(stream);
  29763. }
  29764. this.inlineStreamSkipEI(stream);
  29765. return length;
  29766. },
  29767. /**
  29768. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  29769. * @returns {number} The inline stream length.
  29770. */
  29771. findASCIIHexDecodeInlineStreamEnd:
  29772. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  29773. var GT = 0x3E;
  29774. var startPos = stream.pos, ch, length;
  29775. while ((ch = stream.getByte()) !== -1) {
  29776. if (ch === GT) {
  29777. break;
  29778. }
  29779. }
  29780. length = stream.pos - startPos;
  29781. if (ch === -1) {
  29782. warn('Inline ASCIIHexDecode image stream: ' +
  29783. 'EOD marker not found, searching for /EI/ instead.');
  29784. stream.skip(-length); // Reset the stream position.
  29785. return this.findDefaultInlineStreamEnd(stream);
  29786. }
  29787. this.inlineStreamSkipEI(stream);
  29788. return length;
  29789. },
  29790. /**
  29791. * Skip over the /EI/ for streams where we search for an EOD marker.
  29792. */
  29793. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  29794. var E = 0x45, I = 0x49;
  29795. var state = 0, ch;
  29796. while ((ch = stream.getByte()) !== -1) {
  29797. if (state === 0) {
  29798. state = (ch === E) ? 1 : 0;
  29799. } else if (state === 1) {
  29800. state = (ch === I) ? 2 : 0;
  29801. } else if (state === 2) {
  29802. break;
  29803. }
  29804. }
  29805. },
  29806. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  29807. var lexer = this.lexer;
  29808. var stream = lexer.stream;
  29809. // Parse dictionary.
  29810. var dict = new Dict(this.xref);
  29811. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  29812. if (!isName(this.buf1)) {
  29813. error('Dictionary key must be a name object');
  29814. }
  29815. var key = this.buf1.name;
  29816. this.shift();
  29817. if (isEOF(this.buf1)) {
  29818. break;
  29819. }
  29820. dict.set(key, this.getObj(cipherTransform));
  29821. }
  29822. // Extract the name of the first (i.e. the current) image filter.
  29823. var filter = dict.get('Filter', 'F'), filterName;
  29824. if (isName(filter)) {
  29825. filterName = filter.name;
  29826. } else if (isArray(filter) && isName(filter[0])) {
  29827. filterName = filter[0].name;
  29828. }
  29829. // Parse image stream.
  29830. var startPos = stream.pos, length, i, ii;
  29831. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  29832. length = this.findDCTDecodeInlineStreamEnd(stream);
  29833. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  29834. length = this.findASCII85DecodeInlineStreamEnd(stream);
  29835. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  29836. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  29837. } else {
  29838. length = this.findDefaultInlineStreamEnd(stream);
  29839. }
  29840. var imageStream = stream.makeSubStream(startPos, length, dict);
  29841. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  29842. // adler32 checksum.
  29843. var adler32;
  29844. if (length < MAX_LENGTH_TO_CACHE) {
  29845. var imageBytes = imageStream.getBytes();
  29846. imageStream.reset();
  29847. var a = 1;
  29848. var b = 0;
  29849. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  29850. // No modulo required in the loop if imageBytes.length < 5552.
  29851. a += imageBytes[i] & 0xff;
  29852. b += a;
  29853. }
  29854. adler32 = ((b % 65521) << 16) | (a % 65521);
  29855. if (this.imageCache.adler32 === adler32) {
  29856. this.buf2 = Cmd.get('EI');
  29857. this.shift();
  29858. this.imageCache[adler32].reset();
  29859. return this.imageCache[adler32];
  29860. }
  29861. }
  29862. if (cipherTransform) {
  29863. imageStream = cipherTransform.createStream(imageStream, length);
  29864. }
  29865. imageStream = this.filter(imageStream, dict, length);
  29866. imageStream.dict = dict;
  29867. if (adler32 !== undefined) {
  29868. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  29869. this.imageCache[adler32] = imageStream;
  29870. }
  29871. this.buf2 = Cmd.get('EI');
  29872. this.shift();
  29873. return imageStream;
  29874. },
  29875. makeStream: function Parser_makeStream(dict, cipherTransform) {
  29876. var lexer = this.lexer;
  29877. var stream = lexer.stream;
  29878. // get stream start position
  29879. lexer.skipToNextLine();
  29880. var pos = stream.pos - 1;
  29881. // get length
  29882. var length = dict.get('Length');
  29883. if (!isInt(length)) {
  29884. info('Bad ' + length + ' attribute in stream');
  29885. length = 0;
  29886. }
  29887. // skip over the stream data
  29888. stream.pos = pos + length;
  29889. lexer.nextChar();
  29890. // Shift '>>' and check whether the new object marks the end of the stream
  29891. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  29892. this.shift(); // 'stream'
  29893. } else {
  29894. // bad stream length, scanning for endstream
  29895. stream.pos = pos;
  29896. var SCAN_BLOCK_SIZE = 2048;
  29897. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  29898. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  29899. 0x61, 0x6D];
  29900. var skipped = 0, found = false, i, j;
  29901. while (stream.pos < stream.end) {
  29902. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  29903. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  29904. if (scanLength <= 0) {
  29905. break;
  29906. }
  29907. found = false;
  29908. for (i = 0, j = 0; i < scanLength; i++) {
  29909. var b = scanBytes[i];
  29910. if (b !== ENDSTREAM_SIGNATURE[j]) {
  29911. i -= j;
  29912. j = 0;
  29913. } else {
  29914. j++;
  29915. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  29916. i++;
  29917. found = true;
  29918. break;
  29919. }
  29920. }
  29921. }
  29922. if (found) {
  29923. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  29924. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  29925. break;
  29926. }
  29927. skipped += scanLength;
  29928. stream.pos += scanLength;
  29929. }
  29930. if (!found) {
  29931. error('Missing endstream');
  29932. }
  29933. length = skipped;
  29934. lexer.nextChar();
  29935. this.shift();
  29936. this.shift();
  29937. }
  29938. this.shift(); // 'endstream'
  29939. stream = stream.makeSubStream(pos, length, dict);
  29940. if (cipherTransform) {
  29941. stream = cipherTransform.createStream(stream, length);
  29942. }
  29943. stream = this.filter(stream, dict, length);
  29944. stream.dict = dict;
  29945. return stream;
  29946. },
  29947. filter: function Parser_filter(stream, dict, length) {
  29948. var filter = dict.get('Filter', 'F');
  29949. var params = dict.get('DecodeParms', 'DP');
  29950. if (isName(filter)) {
  29951. return this.makeFilter(stream, filter.name, length, params);
  29952. }
  29953. var maybeLength = length;
  29954. if (isArray(filter)) {
  29955. var filterArray = filter;
  29956. var paramsArray = params;
  29957. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  29958. filter = filterArray[i];
  29959. if (!isName(filter)) {
  29960. error('Bad filter name: ' + filter);
  29961. }
  29962. params = null;
  29963. if (isArray(paramsArray) && (i in paramsArray)) {
  29964. params = paramsArray[i];
  29965. }
  29966. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  29967. // after the first stream the length variable is invalid
  29968. maybeLength = null;
  29969. }
  29970. }
  29971. return stream;
  29972. },
  29973. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  29974. if (stream.dict.get('Length') === 0 && !maybeLength) {
  29975. warn('Empty "' + name + '" stream.');
  29976. return new NullStream(stream);
  29977. }
  29978. try {
  29979. if (params && this.xref) {
  29980. params = this.xref.fetchIfRef(params);
  29981. }
  29982. var xrefStreamStats = this.xref.stats.streamTypes;
  29983. if (name === 'FlateDecode' || name === 'Fl') {
  29984. xrefStreamStats[StreamType.FLATE] = true;
  29985. if (params) {
  29986. return new PredictorStream(new FlateStream(stream, maybeLength),
  29987. maybeLength, params);
  29988. }
  29989. return new FlateStream(stream, maybeLength);
  29990. }
  29991. if (name === 'LZWDecode' || name === 'LZW') {
  29992. xrefStreamStats[StreamType.LZW] = true;
  29993. var earlyChange = 1;
  29994. if (params) {
  29995. if (params.has('EarlyChange')) {
  29996. earlyChange = params.get('EarlyChange');
  29997. }
  29998. return new PredictorStream(
  29999. new LZWStream(stream, maybeLength, earlyChange),
  30000. maybeLength, params);
  30001. }
  30002. return new LZWStream(stream, maybeLength, earlyChange);
  30003. }
  30004. if (name === 'DCTDecode' || name === 'DCT') {
  30005. xrefStreamStats[StreamType.DCT] = true;
  30006. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  30007. }
  30008. if (name === 'JPXDecode' || name === 'JPX') {
  30009. xrefStreamStats[StreamType.JPX] = true;
  30010. return new JpxStream(stream, maybeLength, stream.dict);
  30011. }
  30012. if (name === 'ASCII85Decode' || name === 'A85') {
  30013. xrefStreamStats[StreamType.A85] = true;
  30014. return new Ascii85Stream(stream, maybeLength);
  30015. }
  30016. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  30017. xrefStreamStats[StreamType.AHX] = true;
  30018. return new AsciiHexStream(stream, maybeLength);
  30019. }
  30020. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  30021. xrefStreamStats[StreamType.CCF] = true;
  30022. return new CCITTFaxStream(stream, maybeLength, params);
  30023. }
  30024. if (name === 'RunLengthDecode' || name === 'RL') {
  30025. xrefStreamStats[StreamType.RL] = true;
  30026. return new RunLengthStream(stream, maybeLength);
  30027. }
  30028. if (name === 'JBIG2Decode') {
  30029. xrefStreamStats[StreamType.JBIG] = true;
  30030. return new Jbig2Stream(stream, maybeLength, stream.dict);
  30031. }
  30032. warn('filter "' + name + '" not supported yet');
  30033. return stream;
  30034. } catch (ex) {
  30035. if (ex instanceof MissingDataException) {
  30036. throw ex;
  30037. }
  30038. warn('Invalid stream: \"' + ex + '\"');
  30039. return new NullStream(stream);
  30040. }
  30041. }
  30042. };
  30043. return Parser;
  30044. })();
  30045. var Lexer = (function LexerClosure() {
  30046. function Lexer(stream, knownCommands) {
  30047. this.stream = stream;
  30048. this.nextChar();
  30049. // While lexing, we build up many strings one char at a time. Using += for
  30050. // this can result in lots of garbage strings. It's better to build an
  30051. // array of single-char strings and then join() them together at the end.
  30052. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  30053. // purpose uses less memory than using a new array for each string.
  30054. this.strBuf = [];
  30055. // The PDFs might have "glued" commands with other commands, operands or
  30056. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  30057. // commands and their prefixes. The prefixes are built the following way:
  30058. // if there a command that is a prefix of the other valid command or
  30059. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  30060. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  30061. // other commands or literals as a prefix. The knowCommands is optional.
  30062. this.knownCommands = knownCommands;
  30063. }
  30064. Lexer.isSpace = function Lexer_isSpace(ch) {
  30065. // Space is one of the following characters: SPACE, TAB, CR or LF.
  30066. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  30067. };
  30068. // A '1' in this array means the character is white space. A '1' or
  30069. // '2' means the character ends a name or command.
  30070. var specialChars = [
  30071. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  30072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  30073. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  30074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  30075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  30076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  30077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  30078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  30079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  30080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  30081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  30082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  30083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  30084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  30085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  30086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  30087. ];
  30088. function toHexDigit(ch) {
  30089. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30090. return ch & 0x0F;
  30091. }
  30092. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30093. // 'A'-'F', 'a'-'f'
  30094. return (ch & 0x0F) + 9;
  30095. }
  30096. return -1;
  30097. }
  30098. Lexer.prototype = {
  30099. nextChar: function Lexer_nextChar() {
  30100. return (this.currentChar = this.stream.getByte());
  30101. },
  30102. peekChar: function Lexer_peekChar() {
  30103. return this.stream.peekByte();
  30104. },
  30105. getNumber: function Lexer_getNumber() {
  30106. var ch = this.currentChar;
  30107. var eNotation = false;
  30108. var divideBy = 0; // different from 0 if it's a floating point value
  30109. var sign = 1;
  30110. if (ch === 0x2D) { // '-'
  30111. sign = -1;
  30112. ch = this.nextChar();
  30113. if (ch === 0x2D) { // '-'
  30114. // Ignore double negative (this is consistent with Adobe Reader).
  30115. ch = this.nextChar();
  30116. }
  30117. } else if (ch === 0x2B) { // '+'
  30118. ch = this.nextChar();
  30119. }
  30120. if (ch === 0x2E) { // '.'
  30121. divideBy = 10;
  30122. ch = this.nextChar();
  30123. }
  30124. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  30125. error('Invalid number: ' + String.fromCharCode(ch));
  30126. return 0;
  30127. }
  30128. var baseValue = ch - 0x30; // '0'
  30129. var powerValue = 0;
  30130. var powerValueSign = 1;
  30131. while ((ch = this.nextChar()) >= 0) {
  30132. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  30133. var currentDigit = ch - 0x30; // '0'
  30134. if (eNotation) { // We are after an 'e' or 'E'
  30135. powerValue = powerValue * 10 + currentDigit;
  30136. } else {
  30137. if (divideBy !== 0) { // We are after a point
  30138. divideBy *= 10;
  30139. }
  30140. baseValue = baseValue * 10 + currentDigit;
  30141. }
  30142. } else if (ch === 0x2E) { // '.'
  30143. if (divideBy === 0) {
  30144. divideBy = 1;
  30145. } else {
  30146. // A number can have only one '.'
  30147. break;
  30148. }
  30149. } else if (ch === 0x2D) { // '-'
  30150. // ignore minus signs in the middle of numbers to match
  30151. // Adobe's behavior
  30152. warn('Badly formated number');
  30153. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  30154. // 'E' can be either a scientific notation or the beginning of a new
  30155. // operator
  30156. ch = this.peekChar();
  30157. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  30158. powerValueSign = (ch === 0x2D) ? -1 : 1;
  30159. this.nextChar(); // Consume the sign character
  30160. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  30161. // The 'E' must be the beginning of a new operator
  30162. break;
  30163. }
  30164. eNotation = true;
  30165. } else {
  30166. // the last character doesn't belong to us
  30167. break;
  30168. }
  30169. }
  30170. if (divideBy !== 0) {
  30171. baseValue /= divideBy;
  30172. }
  30173. if (eNotation) {
  30174. baseValue *= Math.pow(10, powerValueSign * powerValue);
  30175. }
  30176. return sign * baseValue;
  30177. },
  30178. getString: function Lexer_getString() {
  30179. var numParen = 1;
  30180. var done = false;
  30181. var strBuf = this.strBuf;
  30182. strBuf.length = 0;
  30183. var ch = this.nextChar();
  30184. while (true) {
  30185. var charBuffered = false;
  30186. switch (ch | 0) {
  30187. case -1:
  30188. warn('Unterminated string');
  30189. done = true;
  30190. break;
  30191. case 0x28: // '('
  30192. ++numParen;
  30193. strBuf.push('(');
  30194. break;
  30195. case 0x29: // ')'
  30196. if (--numParen === 0) {
  30197. this.nextChar(); // consume strings ')'
  30198. done = true;
  30199. } else {
  30200. strBuf.push(')');
  30201. }
  30202. break;
  30203. case 0x5C: // '\\'
  30204. ch = this.nextChar();
  30205. switch (ch) {
  30206. case -1:
  30207. warn('Unterminated string');
  30208. done = true;
  30209. break;
  30210. case 0x6E: // 'n'
  30211. strBuf.push('\n');
  30212. break;
  30213. case 0x72: // 'r'
  30214. strBuf.push('\r');
  30215. break;
  30216. case 0x74: // 't'
  30217. strBuf.push('\t');
  30218. break;
  30219. case 0x62: // 'b'
  30220. strBuf.push('\b');
  30221. break;
  30222. case 0x66: // 'f'
  30223. strBuf.push('\f');
  30224. break;
  30225. case 0x5C: // '\'
  30226. case 0x28: // '('
  30227. case 0x29: // ')'
  30228. strBuf.push(String.fromCharCode(ch));
  30229. break;
  30230. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  30231. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  30232. var x = ch & 0x0F;
  30233. ch = this.nextChar();
  30234. charBuffered = true;
  30235. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  30236. x = (x << 3) + (ch & 0x0F);
  30237. ch = this.nextChar();
  30238. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  30239. charBuffered = false;
  30240. x = (x << 3) + (ch & 0x0F);
  30241. }
  30242. }
  30243. strBuf.push(String.fromCharCode(x));
  30244. break;
  30245. case 0x0D: // CR
  30246. if (this.peekChar() === 0x0A) { // LF
  30247. this.nextChar();
  30248. }
  30249. break;
  30250. case 0x0A: // LF
  30251. break;
  30252. default:
  30253. strBuf.push(String.fromCharCode(ch));
  30254. break;
  30255. }
  30256. break;
  30257. default:
  30258. strBuf.push(String.fromCharCode(ch));
  30259. break;
  30260. }
  30261. if (done) {
  30262. break;
  30263. }
  30264. if (!charBuffered) {
  30265. ch = this.nextChar();
  30266. }
  30267. }
  30268. return strBuf.join('');
  30269. },
  30270. getName: function Lexer_getName() {
  30271. var ch, previousCh;
  30272. var strBuf = this.strBuf;
  30273. strBuf.length = 0;
  30274. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  30275. if (ch === 0x23) { // '#'
  30276. ch = this.nextChar();
  30277. if (specialChars[ch]) {
  30278. warn('Lexer_getName: ' +
  30279. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  30280. strBuf.push('#');
  30281. break;
  30282. }
  30283. var x = toHexDigit(ch);
  30284. if (x !== -1) {
  30285. previousCh = ch;
  30286. ch = this.nextChar();
  30287. var x2 = toHexDigit(ch);
  30288. if (x2 === -1) {
  30289. warn('Lexer_getName: Illegal digit (' +
  30290. String.fromCharCode(ch) +') in hexadecimal number.');
  30291. strBuf.push('#', String.fromCharCode(previousCh));
  30292. if (specialChars[ch]) {
  30293. break;
  30294. }
  30295. strBuf.push(String.fromCharCode(ch));
  30296. continue;
  30297. }
  30298. strBuf.push(String.fromCharCode((x << 4) | x2));
  30299. } else {
  30300. strBuf.push('#', String.fromCharCode(ch));
  30301. }
  30302. } else {
  30303. strBuf.push(String.fromCharCode(ch));
  30304. }
  30305. }
  30306. if (strBuf.length > 127) {
  30307. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  30308. }
  30309. return Name.get(strBuf.join(''));
  30310. },
  30311. getHexString: function Lexer_getHexString() {
  30312. var strBuf = this.strBuf;
  30313. strBuf.length = 0;
  30314. var ch = this.currentChar;
  30315. var isFirstHex = true;
  30316. var firstDigit;
  30317. var secondDigit;
  30318. while (true) {
  30319. if (ch < 0) {
  30320. warn('Unterminated hex string');
  30321. break;
  30322. } else if (ch === 0x3E) { // '>'
  30323. this.nextChar();
  30324. break;
  30325. } else if (specialChars[ch] === 1) {
  30326. ch = this.nextChar();
  30327. continue;
  30328. } else {
  30329. if (isFirstHex) {
  30330. firstDigit = toHexDigit(ch);
  30331. if (firstDigit === -1) {
  30332. warn('Ignoring invalid character "' + ch + '" in hex string');
  30333. ch = this.nextChar();
  30334. continue;
  30335. }
  30336. } else {
  30337. secondDigit = toHexDigit(ch);
  30338. if (secondDigit === -1) {
  30339. warn('Ignoring invalid character "' + ch + '" in hex string');
  30340. ch = this.nextChar();
  30341. continue;
  30342. }
  30343. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  30344. }
  30345. isFirstHex = !isFirstHex;
  30346. ch = this.nextChar();
  30347. }
  30348. }
  30349. return strBuf.join('');
  30350. },
  30351. getObj: function Lexer_getObj() {
  30352. // skip whitespace and comments
  30353. var comment = false;
  30354. var ch = this.currentChar;
  30355. while (true) {
  30356. if (ch < 0) {
  30357. return EOF;
  30358. }
  30359. if (comment) {
  30360. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  30361. comment = false;
  30362. }
  30363. } else if (ch === 0x25) { // '%'
  30364. comment = true;
  30365. } else if (specialChars[ch] !== 1) {
  30366. break;
  30367. }
  30368. ch = this.nextChar();
  30369. }
  30370. // start reading token
  30371. switch (ch | 0) {
  30372. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  30373. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  30374. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  30375. return this.getNumber();
  30376. case 0x28: // '('
  30377. return this.getString();
  30378. case 0x2F: // '/'
  30379. return this.getName();
  30380. // array punctuation
  30381. case 0x5B: // '['
  30382. this.nextChar();
  30383. return Cmd.get('[');
  30384. case 0x5D: // ']'
  30385. this.nextChar();
  30386. return Cmd.get(']');
  30387. // hex string or dict punctuation
  30388. case 0x3C: // '<'
  30389. ch = this.nextChar();
  30390. if (ch === 0x3C) {
  30391. // dict punctuation
  30392. this.nextChar();
  30393. return Cmd.get('<<');
  30394. }
  30395. return this.getHexString();
  30396. // dict punctuation
  30397. case 0x3E: // '>'
  30398. ch = this.nextChar();
  30399. if (ch === 0x3E) {
  30400. this.nextChar();
  30401. return Cmd.get('>>');
  30402. }
  30403. return Cmd.get('>');
  30404. case 0x7B: // '{'
  30405. this.nextChar();
  30406. return Cmd.get('{');
  30407. case 0x7D: // '}'
  30408. this.nextChar();
  30409. return Cmd.get('}');
  30410. case 0x29: // ')'
  30411. error('Illegal character: ' + ch);
  30412. break;
  30413. }
  30414. // command
  30415. var str = String.fromCharCode(ch);
  30416. var knownCommands = this.knownCommands;
  30417. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  30418. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  30419. // stop if known command is found and next character does not make
  30420. // the str a command
  30421. var possibleCommand = str + String.fromCharCode(ch);
  30422. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  30423. break;
  30424. }
  30425. if (str.length === 128) {
  30426. error('Command token too long: ' + str.length);
  30427. }
  30428. str = possibleCommand;
  30429. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  30430. }
  30431. if (str === 'true') {
  30432. return true;
  30433. }
  30434. if (str === 'false') {
  30435. return false;
  30436. }
  30437. if (str === 'null') {
  30438. return null;
  30439. }
  30440. return Cmd.get(str);
  30441. },
  30442. skipToNextLine: function Lexer_skipToNextLine() {
  30443. var ch = this.currentChar;
  30444. while (ch >= 0) {
  30445. if (ch === 0x0D) { // CR
  30446. ch = this.nextChar();
  30447. if (ch === 0x0A) { // LF
  30448. this.nextChar();
  30449. }
  30450. break;
  30451. } else if (ch === 0x0A) { // LF
  30452. this.nextChar();
  30453. break;
  30454. }
  30455. ch = this.nextChar();
  30456. }
  30457. }
  30458. };
  30459. return Lexer;
  30460. })();
  30461. var Linearization = {
  30462. create: function LinearizationCreate(stream) {
  30463. function getInt(name, allowZeroValue) {
  30464. var obj = linDict.get(name);
  30465. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  30466. return obj;
  30467. }
  30468. throw new Error('The "' + name + '" parameter in the linearization ' +
  30469. 'dictionary is invalid.');
  30470. }
  30471. function getHints() {
  30472. var hints = linDict.get('H'), hintsLength, item;
  30473. if (isArray(hints) &&
  30474. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  30475. for (var index = 0; index < hintsLength; index++) {
  30476. if (!(isInt(item = hints[index]) && item > 0)) {
  30477. throw new Error('Hint (' + index +
  30478. ') in the linearization dictionary is invalid.');
  30479. }
  30480. }
  30481. return hints;
  30482. }
  30483. throw new Error('Hint array in the linearization dictionary is invalid.');
  30484. }
  30485. var parser = new Parser(new Lexer(stream), false, null);
  30486. var obj1 = parser.getObj();
  30487. var obj2 = parser.getObj();
  30488. var obj3 = parser.getObj();
  30489. var linDict = parser.getObj();
  30490. var obj, length;
  30491. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  30492. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  30493. return null; // No valid linearization dictionary found.
  30494. } else if ((length = getInt('L')) !== stream.length) {
  30495. throw new Error('The "L" parameter in the linearization dictionary ' +
  30496. 'does not equal the stream length.');
  30497. }
  30498. return {
  30499. length: length,
  30500. hints: getHints(),
  30501. objectNumberFirst: getInt('O'),
  30502. endFirst: getInt('E'),
  30503. numPages: getInt('N'),
  30504. mainXRefEntriesOffset: getInt('T'),
  30505. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  30506. };
  30507. }
  30508. };
  30509. var PostScriptParser = (function PostScriptParserClosure() {
  30510. function PostScriptParser(lexer) {
  30511. this.lexer = lexer;
  30512. this.operators = [];
  30513. this.token = null;
  30514. this.prev = null;
  30515. }
  30516. PostScriptParser.prototype = {
  30517. nextToken: function PostScriptParser_nextToken() {
  30518. this.prev = this.token;
  30519. this.token = this.lexer.getToken();
  30520. },
  30521. accept: function PostScriptParser_accept(type) {
  30522. if (this.token.type === type) {
  30523. this.nextToken();
  30524. return true;
  30525. }
  30526. return false;
  30527. },
  30528. expect: function PostScriptParser_expect(type) {
  30529. if (this.accept(type)) {
  30530. return true;
  30531. }
  30532. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  30533. type + '.');
  30534. },
  30535. parse: function PostScriptParser_parse() {
  30536. this.nextToken();
  30537. this.expect(PostScriptTokenTypes.LBRACE);
  30538. this.parseBlock();
  30539. this.expect(PostScriptTokenTypes.RBRACE);
  30540. return this.operators;
  30541. },
  30542. parseBlock: function PostScriptParser_parseBlock() {
  30543. while (true) {
  30544. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  30545. this.operators.push(this.prev.value);
  30546. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  30547. this.operators.push(this.prev.value);
  30548. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  30549. this.parseCondition();
  30550. } else {
  30551. return;
  30552. }
  30553. }
  30554. },
  30555. parseCondition: function PostScriptParser_parseCondition() {
  30556. // Add two place holders that will be updated later
  30557. var conditionLocation = this.operators.length;
  30558. this.operators.push(null, null);
  30559. this.parseBlock();
  30560. this.expect(PostScriptTokenTypes.RBRACE);
  30561. if (this.accept(PostScriptTokenTypes.IF)) {
  30562. // The true block is right after the 'if' so it just falls through on
  30563. // true else it jumps and skips the true block.
  30564. this.operators[conditionLocation] = this.operators.length;
  30565. this.operators[conditionLocation + 1] = 'jz';
  30566. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  30567. var jumpLocation = this.operators.length;
  30568. this.operators.push(null, null);
  30569. var endOfTrue = this.operators.length;
  30570. this.parseBlock();
  30571. this.expect(PostScriptTokenTypes.RBRACE);
  30572. this.expect(PostScriptTokenTypes.IFELSE);
  30573. // The jump is added at the end of the true block to skip the false
  30574. // block.
  30575. this.operators[jumpLocation] = this.operators.length;
  30576. this.operators[jumpLocation + 1] = 'j';
  30577. this.operators[conditionLocation] = endOfTrue;
  30578. this.operators[conditionLocation + 1] = 'jz';
  30579. } else {
  30580. error('PS Function: error parsing conditional.');
  30581. }
  30582. }
  30583. };
  30584. return PostScriptParser;
  30585. })();
  30586. var PostScriptTokenTypes = {
  30587. LBRACE: 0,
  30588. RBRACE: 1,
  30589. NUMBER: 2,
  30590. OPERATOR: 3,
  30591. IF: 4,
  30592. IFELSE: 5
  30593. };
  30594. var PostScriptToken = (function PostScriptTokenClosure() {
  30595. function PostScriptToken(type, value) {
  30596. this.type = type;
  30597. this.value = value;
  30598. }
  30599. var opCache = {};
  30600. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  30601. var opValue = opCache[op];
  30602. if (opValue) {
  30603. return opValue;
  30604. }
  30605. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  30606. };
  30607. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  30608. '{');
  30609. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  30610. '}');
  30611. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  30612. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  30613. 'IFELSE');
  30614. return PostScriptToken;
  30615. })();
  30616. var PostScriptLexer = (function PostScriptLexerClosure() {
  30617. function PostScriptLexer(stream) {
  30618. this.stream = stream;
  30619. this.nextChar();
  30620. this.strBuf = [];
  30621. }
  30622. PostScriptLexer.prototype = {
  30623. nextChar: function PostScriptLexer_nextChar() {
  30624. return (this.currentChar = this.stream.getByte());
  30625. },
  30626. getToken: function PostScriptLexer_getToken() {
  30627. var comment = false;
  30628. var ch = this.currentChar;
  30629. // skip comments
  30630. while (true) {
  30631. if (ch < 0) {
  30632. return EOF;
  30633. }
  30634. if (comment) {
  30635. if (ch === 0x0A || ch === 0x0D) {
  30636. comment = false;
  30637. }
  30638. } else if (ch === 0x25) { // '%'
  30639. comment = true;
  30640. } else if (!Lexer.isSpace(ch)) {
  30641. break;
  30642. }
  30643. ch = this.nextChar();
  30644. }
  30645. switch (ch | 0) {
  30646. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  30647. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  30648. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  30649. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  30650. this.getNumber());
  30651. case 0x7B: // '{'
  30652. this.nextChar();
  30653. return PostScriptToken.LBRACE;
  30654. case 0x7D: // '}'
  30655. this.nextChar();
  30656. return PostScriptToken.RBRACE;
  30657. }
  30658. // operator
  30659. var strBuf = this.strBuf;
  30660. strBuf.length = 0;
  30661. strBuf[0] = String.fromCharCode(ch);
  30662. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  30663. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  30664. strBuf.push(String.fromCharCode(ch));
  30665. }
  30666. var str = strBuf.join('');
  30667. switch (str.toLowerCase()) {
  30668. case 'if':
  30669. return PostScriptToken.IF;
  30670. case 'ifelse':
  30671. return PostScriptToken.IFELSE;
  30672. default:
  30673. return PostScriptToken.getOperator(str);
  30674. }
  30675. },
  30676. getNumber: function PostScriptLexer_getNumber() {
  30677. var ch = this.currentChar;
  30678. var strBuf = this.strBuf;
  30679. strBuf.length = 0;
  30680. strBuf[0] = String.fromCharCode(ch);
  30681. while ((ch = this.nextChar()) >= 0) {
  30682. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  30683. ch === 0x2D || ch === 0x2E) { // '-', '.'
  30684. strBuf.push(String.fromCharCode(ch));
  30685. } else {
  30686. break;
  30687. }
  30688. }
  30689. var value = parseFloat(strBuf.join(''));
  30690. if (isNaN(value)) {
  30691. error('Invalid floating point number: ' + value);
  30692. }
  30693. return value;
  30694. }
  30695. };
  30696. return PostScriptLexer;
  30697. })();
  30698. var Stream = (function StreamClosure() {
  30699. function Stream(arrayBuffer, start, length, dict) {
  30700. this.bytes = (arrayBuffer instanceof Uint8Array ?
  30701. arrayBuffer : new Uint8Array(arrayBuffer));
  30702. this.start = start || 0;
  30703. this.pos = this.start;
  30704. this.end = (start + length) || this.bytes.length;
  30705. this.dict = dict;
  30706. }
  30707. // required methods for a stream. if a particular stream does not
  30708. // implement these, an error should be thrown
  30709. Stream.prototype = {
  30710. get length() {
  30711. return this.end - this.start;
  30712. },
  30713. get isEmpty() {
  30714. return this.length === 0;
  30715. },
  30716. getByte: function Stream_getByte() {
  30717. if (this.pos >= this.end) {
  30718. return -1;
  30719. }
  30720. return this.bytes[this.pos++];
  30721. },
  30722. getUint16: function Stream_getUint16() {
  30723. var b0 = this.getByte();
  30724. var b1 = this.getByte();
  30725. if (b0 === -1 || b1 === -1) {
  30726. return -1;
  30727. }
  30728. return (b0 << 8) + b1;
  30729. },
  30730. getInt32: function Stream_getInt32() {
  30731. var b0 = this.getByte();
  30732. var b1 = this.getByte();
  30733. var b2 = this.getByte();
  30734. var b3 = this.getByte();
  30735. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30736. },
  30737. // returns subarray of original buffer
  30738. // should only be read
  30739. getBytes: function Stream_getBytes(length) {
  30740. var bytes = this.bytes;
  30741. var pos = this.pos;
  30742. var strEnd = this.end;
  30743. if (!length) {
  30744. return bytes.subarray(pos, strEnd);
  30745. }
  30746. var end = pos + length;
  30747. if (end > strEnd) {
  30748. end = strEnd;
  30749. }
  30750. this.pos = end;
  30751. return bytes.subarray(pos, end);
  30752. },
  30753. peekByte: function Stream_peekByte() {
  30754. var peekedByte = this.getByte();
  30755. this.pos--;
  30756. return peekedByte;
  30757. },
  30758. peekBytes: function Stream_peekBytes(length) {
  30759. var bytes = this.getBytes(length);
  30760. this.pos -= bytes.length;
  30761. return bytes;
  30762. },
  30763. skip: function Stream_skip(n) {
  30764. if (!n) {
  30765. n = 1;
  30766. }
  30767. this.pos += n;
  30768. },
  30769. reset: function Stream_reset() {
  30770. this.pos = this.start;
  30771. },
  30772. moveStart: function Stream_moveStart() {
  30773. this.start = this.pos;
  30774. },
  30775. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  30776. return new Stream(this.bytes.buffer, start, length, dict);
  30777. },
  30778. isStream: true
  30779. };
  30780. return Stream;
  30781. })();
  30782. var StringStream = (function StringStreamClosure() {
  30783. function StringStream(str) {
  30784. var length = str.length;
  30785. var bytes = new Uint8Array(length);
  30786. for (var n = 0; n < length; ++n) {
  30787. bytes[n] = str.charCodeAt(n);
  30788. }
  30789. Stream.call(this, bytes);
  30790. }
  30791. StringStream.prototype = Stream.prototype;
  30792. return StringStream;
  30793. })();
  30794. // super class for the decoding streams
  30795. var DecodeStream = (function DecodeStreamClosure() {
  30796. // Lots of DecodeStreams are created whose buffers are never used. For these
  30797. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  30798. // having special cases that would be required if we used |null| for an empty
  30799. // buffer.
  30800. var emptyBuffer = new Uint8Array(0);
  30801. function DecodeStream(maybeMinBufferLength) {
  30802. this.pos = 0;
  30803. this.bufferLength = 0;
  30804. this.eof = false;
  30805. this.buffer = emptyBuffer;
  30806. this.minBufferLength = 512;
  30807. if (maybeMinBufferLength) {
  30808. // Compute the first power of two that is as big as maybeMinBufferLength.
  30809. while (this.minBufferLength < maybeMinBufferLength) {
  30810. this.minBufferLength *= 2;
  30811. }
  30812. }
  30813. }
  30814. DecodeStream.prototype = {
  30815. get isEmpty() {
  30816. while (!this.eof && this.bufferLength === 0) {
  30817. this.readBlock();
  30818. }
  30819. return this.bufferLength === 0;
  30820. },
  30821. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  30822. var buffer = this.buffer;
  30823. if (requested <= buffer.byteLength) {
  30824. return buffer;
  30825. }
  30826. var size = this.minBufferLength;
  30827. while (size < requested) {
  30828. size *= 2;
  30829. }
  30830. var buffer2 = new Uint8Array(size);
  30831. buffer2.set(buffer);
  30832. return (this.buffer = buffer2);
  30833. },
  30834. getByte: function DecodeStream_getByte() {
  30835. var pos = this.pos;
  30836. while (this.bufferLength <= pos) {
  30837. if (this.eof) {
  30838. return -1;
  30839. }
  30840. this.readBlock();
  30841. }
  30842. return this.buffer[this.pos++];
  30843. },
  30844. getUint16: function DecodeStream_getUint16() {
  30845. var b0 = this.getByte();
  30846. var b1 = this.getByte();
  30847. if (b0 === -1 || b1 === -1) {
  30848. return -1;
  30849. }
  30850. return (b0 << 8) + b1;
  30851. },
  30852. getInt32: function DecodeStream_getInt32() {
  30853. var b0 = this.getByte();
  30854. var b1 = this.getByte();
  30855. var b2 = this.getByte();
  30856. var b3 = this.getByte();
  30857. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  30858. },
  30859. getBytes: function DecodeStream_getBytes(length) {
  30860. var end, pos = this.pos;
  30861. if (length) {
  30862. this.ensureBuffer(pos + length);
  30863. end = pos + length;
  30864. while (!this.eof && this.bufferLength < end) {
  30865. this.readBlock();
  30866. }
  30867. var bufEnd = this.bufferLength;
  30868. if (end > bufEnd) {
  30869. end = bufEnd;
  30870. }
  30871. } else {
  30872. while (!this.eof) {
  30873. this.readBlock();
  30874. }
  30875. end = this.bufferLength;
  30876. }
  30877. this.pos = end;
  30878. return this.buffer.subarray(pos, end);
  30879. },
  30880. peekByte: function DecodeStream_peekByte() {
  30881. var peekedByte = this.getByte();
  30882. this.pos--;
  30883. return peekedByte;
  30884. },
  30885. peekBytes: function DecodeStream_peekBytes(length) {
  30886. var bytes = this.getBytes(length);
  30887. this.pos -= bytes.length;
  30888. return bytes;
  30889. },
  30890. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  30891. var end = start + length;
  30892. while (this.bufferLength <= end && !this.eof) {
  30893. this.readBlock();
  30894. }
  30895. return new Stream(this.buffer, start, length, dict);
  30896. },
  30897. skip: function DecodeStream_skip(n) {
  30898. if (!n) {
  30899. n = 1;
  30900. }
  30901. this.pos += n;
  30902. },
  30903. reset: function DecodeStream_reset() {
  30904. this.pos = 0;
  30905. },
  30906. getBaseStreams: function DecodeStream_getBaseStreams() {
  30907. if (this.str && this.str.getBaseStreams) {
  30908. return this.str.getBaseStreams();
  30909. }
  30910. return [];
  30911. }
  30912. };
  30913. return DecodeStream;
  30914. })();
  30915. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  30916. function StreamsSequenceStream(streams) {
  30917. this.streams = streams;
  30918. DecodeStream.call(this, /* maybeLength = */ null);
  30919. }
  30920. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  30921. StreamsSequenceStream.prototype.readBlock =
  30922. function streamSequenceStreamReadBlock() {
  30923. var streams = this.streams;
  30924. if (streams.length === 0) {
  30925. this.eof = true;
  30926. return;
  30927. }
  30928. var stream = streams.shift();
  30929. var chunk = stream.getBytes();
  30930. var bufferLength = this.bufferLength;
  30931. var newLength = bufferLength + chunk.length;
  30932. var buffer = this.ensureBuffer(newLength);
  30933. buffer.set(chunk, bufferLength);
  30934. this.bufferLength = newLength;
  30935. };
  30936. StreamsSequenceStream.prototype.getBaseStreams =
  30937. function StreamsSequenceStream_getBaseStreams() {
  30938. var baseStreams = [];
  30939. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  30940. var stream = this.streams[i];
  30941. if (stream.getBaseStreams) {
  30942. Util.appendToArray(baseStreams, stream.getBaseStreams());
  30943. }
  30944. }
  30945. return baseStreams;
  30946. };
  30947. return StreamsSequenceStream;
  30948. })();
  30949. var FlateStream = (function FlateStreamClosure() {
  30950. var codeLenCodeMap = new Int32Array([
  30951. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  30952. ]);
  30953. var lengthDecode = new Int32Array([
  30954. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  30955. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  30956. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  30957. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  30958. ]);
  30959. var distDecode = new Int32Array([
  30960. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  30961. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  30962. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  30963. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  30964. ]);
  30965. var fixedLitCodeTab = [new Int32Array([
  30966. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  30967. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  30968. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  30969. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  30970. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  30971. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  30972. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  30973. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  30974. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  30975. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  30976. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  30977. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  30978. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  30979. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  30980. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  30981. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  30982. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  30983. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  30984. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  30985. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  30986. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  30987. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  30988. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  30989. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  30990. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  30991. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  30992. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  30993. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  30994. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  30995. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  30996. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  30997. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  30998. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  30999. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  31000. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  31001. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  31002. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  31003. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  31004. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  31005. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  31006. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  31007. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  31008. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  31009. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  31010. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  31011. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  31012. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  31013. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  31014. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  31015. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  31016. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  31017. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  31018. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  31019. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  31020. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  31021. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  31022. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  31023. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  31024. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  31025. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  31026. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  31027. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  31028. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  31029. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  31030. ]), 9];
  31031. var fixedDistCodeTab = [new Int32Array([
  31032. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  31033. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  31034. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  31035. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  31036. ]), 5];
  31037. function FlateStream(str, maybeLength) {
  31038. this.str = str;
  31039. this.dict = str.dict;
  31040. var cmf = str.getByte();
  31041. var flg = str.getByte();
  31042. if (cmf === -1 || flg === -1) {
  31043. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  31044. }
  31045. if ((cmf & 0x0f) !== 0x08) {
  31046. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  31047. }
  31048. if ((((cmf << 8) + flg) % 31) !== 0) {
  31049. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  31050. }
  31051. if (flg & 0x20) {
  31052. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  31053. }
  31054. this.codeSize = 0;
  31055. this.codeBuf = 0;
  31056. DecodeStream.call(this, maybeLength);
  31057. }
  31058. FlateStream.prototype = Object.create(DecodeStream.prototype);
  31059. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  31060. var str = this.str;
  31061. var codeSize = this.codeSize;
  31062. var codeBuf = this.codeBuf;
  31063. var b;
  31064. while (codeSize < bits) {
  31065. if ((b = str.getByte()) === -1) {
  31066. error('Bad encoding in flate stream');
  31067. }
  31068. codeBuf |= b << codeSize;
  31069. codeSize += 8;
  31070. }
  31071. b = codeBuf & ((1 << bits) - 1);
  31072. this.codeBuf = codeBuf >> bits;
  31073. this.codeSize = codeSize -= bits;
  31074. return b;
  31075. };
  31076. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  31077. var str = this.str;
  31078. var codes = table[0];
  31079. var maxLen = table[1];
  31080. var codeSize = this.codeSize;
  31081. var codeBuf = this.codeBuf;
  31082. var b;
  31083. while (codeSize < maxLen) {
  31084. if ((b = str.getByte()) === -1) {
  31085. // premature end of stream. code might however still be valid.
  31086. // codeSize < codeLen check below guards against incomplete codeVal.
  31087. break;
  31088. }
  31089. codeBuf |= (b << codeSize);
  31090. codeSize += 8;
  31091. }
  31092. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  31093. var codeLen = code >> 16;
  31094. var codeVal = code & 0xffff;
  31095. if (codeLen < 1 || codeSize < codeLen) {
  31096. error('Bad encoding in flate stream');
  31097. }
  31098. this.codeBuf = (codeBuf >> codeLen);
  31099. this.codeSize = (codeSize - codeLen);
  31100. return codeVal;
  31101. };
  31102. FlateStream.prototype.generateHuffmanTable =
  31103. function flateStreamGenerateHuffmanTable(lengths) {
  31104. var n = lengths.length;
  31105. // find max code length
  31106. var maxLen = 0;
  31107. var i;
  31108. for (i = 0; i < n; ++i) {
  31109. if (lengths[i] > maxLen) {
  31110. maxLen = lengths[i];
  31111. }
  31112. }
  31113. // build the table
  31114. var size = 1 << maxLen;
  31115. var codes = new Int32Array(size);
  31116. for (var len = 1, code = 0, skip = 2;
  31117. len <= maxLen;
  31118. ++len, code <<= 1, skip <<= 1) {
  31119. for (var val = 0; val < n; ++val) {
  31120. if (lengths[val] === len) {
  31121. // bit-reverse the code
  31122. var code2 = 0;
  31123. var t = code;
  31124. for (i = 0; i < len; ++i) {
  31125. code2 = (code2 << 1) | (t & 1);
  31126. t >>= 1;
  31127. }
  31128. // fill the table entries
  31129. for (i = code2; i < size; i += skip) {
  31130. codes[i] = (len << 16) | val;
  31131. }
  31132. ++code;
  31133. }
  31134. }
  31135. }
  31136. return [codes, maxLen];
  31137. };
  31138. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  31139. var buffer, len;
  31140. var str = this.str;
  31141. // read block header
  31142. var hdr = this.getBits(3);
  31143. if (hdr & 1) {
  31144. this.eof = true;
  31145. }
  31146. hdr >>= 1;
  31147. if (hdr === 0) { // uncompressed block
  31148. var b;
  31149. if ((b = str.getByte()) === -1) {
  31150. error('Bad block header in flate stream');
  31151. }
  31152. var blockLen = b;
  31153. if ((b = str.getByte()) === -1) {
  31154. error('Bad block header in flate stream');
  31155. }
  31156. blockLen |= (b << 8);
  31157. if ((b = str.getByte()) === -1) {
  31158. error('Bad block header in flate stream');
  31159. }
  31160. var check = b;
  31161. if ((b = str.getByte()) === -1) {
  31162. error('Bad block header in flate stream');
  31163. }
  31164. check |= (b << 8);
  31165. if (check !== (~blockLen & 0xffff) &&
  31166. (blockLen !== 0 || check !== 0)) {
  31167. // Ignoring error for bad "empty" block (see issue 1277)
  31168. error('Bad uncompressed block length in flate stream');
  31169. }
  31170. this.codeBuf = 0;
  31171. this.codeSize = 0;
  31172. var bufferLength = this.bufferLength;
  31173. buffer = this.ensureBuffer(bufferLength + blockLen);
  31174. var end = bufferLength + blockLen;
  31175. this.bufferLength = end;
  31176. if (blockLen === 0) {
  31177. if (str.peekByte() === -1) {
  31178. this.eof = true;
  31179. }
  31180. } else {
  31181. for (var n = bufferLength; n < end; ++n) {
  31182. if ((b = str.getByte()) === -1) {
  31183. this.eof = true;
  31184. break;
  31185. }
  31186. buffer[n] = b;
  31187. }
  31188. }
  31189. return;
  31190. }
  31191. var litCodeTable;
  31192. var distCodeTable;
  31193. if (hdr === 1) { // compressed block, fixed codes
  31194. litCodeTable = fixedLitCodeTab;
  31195. distCodeTable = fixedDistCodeTab;
  31196. } else if (hdr === 2) { // compressed block, dynamic codes
  31197. var numLitCodes = this.getBits(5) + 257;
  31198. var numDistCodes = this.getBits(5) + 1;
  31199. var numCodeLenCodes = this.getBits(4) + 4;
  31200. // build the code lengths code table
  31201. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  31202. var i;
  31203. for (i = 0; i < numCodeLenCodes; ++i) {
  31204. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  31205. }
  31206. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  31207. // build the literal and distance code tables
  31208. len = 0;
  31209. i = 0;
  31210. var codes = numLitCodes + numDistCodes;
  31211. var codeLengths = new Uint8Array(codes);
  31212. var bitsLength, bitsOffset, what;
  31213. while (i < codes) {
  31214. var code = this.getCode(codeLenCodeTab);
  31215. if (code === 16) {
  31216. bitsLength = 2; bitsOffset = 3; what = len;
  31217. } else if (code === 17) {
  31218. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  31219. } else if (code === 18) {
  31220. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  31221. } else {
  31222. codeLengths[i++] = len = code;
  31223. continue;
  31224. }
  31225. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  31226. while (repeatLength-- > 0) {
  31227. codeLengths[i++] = what;
  31228. }
  31229. }
  31230. litCodeTable =
  31231. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  31232. distCodeTable =
  31233. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  31234. } else {
  31235. error('Unknown block type in flate stream');
  31236. }
  31237. buffer = this.buffer;
  31238. var limit = buffer ? buffer.length : 0;
  31239. var pos = this.bufferLength;
  31240. while (true) {
  31241. var code1 = this.getCode(litCodeTable);
  31242. if (code1 < 256) {
  31243. if (pos + 1 >= limit) {
  31244. buffer = this.ensureBuffer(pos + 1);
  31245. limit = buffer.length;
  31246. }
  31247. buffer[pos++] = code1;
  31248. continue;
  31249. }
  31250. if (code1 === 256) {
  31251. this.bufferLength = pos;
  31252. return;
  31253. }
  31254. code1 -= 257;
  31255. code1 = lengthDecode[code1];
  31256. var code2 = code1 >> 16;
  31257. if (code2 > 0) {
  31258. code2 = this.getBits(code2);
  31259. }
  31260. len = (code1 & 0xffff) + code2;
  31261. code1 = this.getCode(distCodeTable);
  31262. code1 = distDecode[code1];
  31263. code2 = code1 >> 16;
  31264. if (code2 > 0) {
  31265. code2 = this.getBits(code2);
  31266. }
  31267. var dist = (code1 & 0xffff) + code2;
  31268. if (pos + len >= limit) {
  31269. buffer = this.ensureBuffer(pos + len);
  31270. limit = buffer.length;
  31271. }
  31272. for (var k = 0; k < len; ++k, ++pos) {
  31273. buffer[pos] = buffer[pos - dist];
  31274. }
  31275. }
  31276. };
  31277. return FlateStream;
  31278. })();
  31279. var PredictorStream = (function PredictorStreamClosure() {
  31280. function PredictorStream(str, maybeLength, params) {
  31281. var predictor = this.predictor = params.get('Predictor') || 1;
  31282. if (predictor <= 1) {
  31283. return str; // no prediction
  31284. }
  31285. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  31286. error('Unsupported predictor: ' + predictor);
  31287. }
  31288. if (predictor === 2) {
  31289. this.readBlock = this.readBlockTiff;
  31290. } else {
  31291. this.readBlock = this.readBlockPng;
  31292. }
  31293. this.str = str;
  31294. this.dict = str.dict;
  31295. var colors = this.colors = params.get('Colors') || 1;
  31296. var bits = this.bits = params.get('BitsPerComponent') || 8;
  31297. var columns = this.columns = params.get('Columns') || 1;
  31298. this.pixBytes = (colors * bits + 7) >> 3;
  31299. this.rowBytes = (columns * colors * bits + 7) >> 3;
  31300. DecodeStream.call(this, maybeLength);
  31301. return this;
  31302. }
  31303. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  31304. PredictorStream.prototype.readBlockTiff =
  31305. function predictorStreamReadBlockTiff() {
  31306. var rowBytes = this.rowBytes;
  31307. var bufferLength = this.bufferLength;
  31308. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  31309. var bits = this.bits;
  31310. var colors = this.colors;
  31311. var rawBytes = this.str.getBytes(rowBytes);
  31312. this.eof = !rawBytes.length;
  31313. if (this.eof) {
  31314. return;
  31315. }
  31316. var inbuf = 0, outbuf = 0;
  31317. var inbits = 0, outbits = 0;
  31318. var pos = bufferLength;
  31319. var i;
  31320. if (bits === 1) {
  31321. for (i = 0; i < rowBytes; ++i) {
  31322. var c = rawBytes[i];
  31323. inbuf = (inbuf << 8) | c;
  31324. // bitwise addition is exclusive or
  31325. // first shift inbuf and then add
  31326. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  31327. // truncate inbuf (assumes colors < 16)
  31328. inbuf &= 0xFFFF;
  31329. }
  31330. } else if (bits === 8) {
  31331. for (i = 0; i < colors; ++i) {
  31332. buffer[pos++] = rawBytes[i];
  31333. }
  31334. for (; i < rowBytes; ++i) {
  31335. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  31336. pos++;
  31337. }
  31338. } else {
  31339. var compArray = new Uint8Array(colors + 1);
  31340. var bitMask = (1 << bits) - 1;
  31341. var j = 0, k = bufferLength;
  31342. var columns = this.columns;
  31343. for (i = 0; i < columns; ++i) {
  31344. for (var kk = 0; kk < colors; ++kk) {
  31345. if (inbits < bits) {
  31346. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  31347. inbits += 8;
  31348. }
  31349. compArray[kk] = (compArray[kk] +
  31350. (inbuf >> (inbits - bits))) & bitMask;
  31351. inbits -= bits;
  31352. outbuf = (outbuf << bits) | compArray[kk];
  31353. outbits += bits;
  31354. if (outbits >= 8) {
  31355. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  31356. outbits -= 8;
  31357. }
  31358. }
  31359. }
  31360. if (outbits > 0) {
  31361. buffer[k++] = (outbuf << (8 - outbits)) +
  31362. (inbuf & ((1 << (8 - outbits)) - 1));
  31363. }
  31364. }
  31365. this.bufferLength += rowBytes;
  31366. };
  31367. PredictorStream.prototype.readBlockPng =
  31368. function predictorStreamReadBlockPng() {
  31369. var rowBytes = this.rowBytes;
  31370. var pixBytes = this.pixBytes;
  31371. var predictor = this.str.getByte();
  31372. var rawBytes = this.str.getBytes(rowBytes);
  31373. this.eof = !rawBytes.length;
  31374. if (this.eof) {
  31375. return;
  31376. }
  31377. var bufferLength = this.bufferLength;
  31378. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  31379. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  31380. if (prevRow.length === 0) {
  31381. prevRow = new Uint8Array(rowBytes);
  31382. }
  31383. var i, j = bufferLength, up, c;
  31384. switch (predictor) {
  31385. case 0:
  31386. for (i = 0; i < rowBytes; ++i) {
  31387. buffer[j++] = rawBytes[i];
  31388. }
  31389. break;
  31390. case 1:
  31391. for (i = 0; i < pixBytes; ++i) {
  31392. buffer[j++] = rawBytes[i];
  31393. }
  31394. for (; i < rowBytes; ++i) {
  31395. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  31396. j++;
  31397. }
  31398. break;
  31399. case 2:
  31400. for (i = 0; i < rowBytes; ++i) {
  31401. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  31402. }
  31403. break;
  31404. case 3:
  31405. for (i = 0; i < pixBytes; ++i) {
  31406. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  31407. }
  31408. for (; i < rowBytes; ++i) {
  31409. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  31410. rawBytes[i]) & 0xFF;
  31411. j++;
  31412. }
  31413. break;
  31414. case 4:
  31415. // we need to save the up left pixels values. the simplest way
  31416. // is to create a new buffer
  31417. for (i = 0; i < pixBytes; ++i) {
  31418. up = prevRow[i];
  31419. c = rawBytes[i];
  31420. buffer[j++] = up + c;
  31421. }
  31422. for (; i < rowBytes; ++i) {
  31423. up = prevRow[i];
  31424. var upLeft = prevRow[i - pixBytes];
  31425. var left = buffer[j - pixBytes];
  31426. var p = left + up - upLeft;
  31427. var pa = p - left;
  31428. if (pa < 0) {
  31429. pa = -pa;
  31430. }
  31431. var pb = p - up;
  31432. if (pb < 0) {
  31433. pb = -pb;
  31434. }
  31435. var pc = p - upLeft;
  31436. if (pc < 0) {
  31437. pc = -pc;
  31438. }
  31439. c = rawBytes[i];
  31440. if (pa <= pb && pa <= pc) {
  31441. buffer[j++] = left + c;
  31442. } else if (pb <= pc) {
  31443. buffer[j++] = up + c;
  31444. } else {
  31445. buffer[j++] = upLeft + c;
  31446. }
  31447. }
  31448. break;
  31449. default:
  31450. error('Unsupported predictor: ' + predictor);
  31451. }
  31452. this.bufferLength += rowBytes;
  31453. };
  31454. return PredictorStream;
  31455. })();
  31456. /**
  31457. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  31458. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  31459. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  31460. * a library to decode these images and the stream behaves like all the other
  31461. * DecodeStreams.
  31462. */
  31463. var JpegStream = (function JpegStreamClosure() {
  31464. function JpegStream(stream, maybeLength, dict, xref) {
  31465. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  31466. // Note: this seems to mainly affect inline images.
  31467. var ch;
  31468. while ((ch = stream.getByte()) !== -1) {
  31469. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  31470. stream.skip(-1); // Reset the stream position to the SOI.
  31471. break;
  31472. }
  31473. }
  31474. this.stream = stream;
  31475. this.maybeLength = maybeLength;
  31476. this.dict = dict;
  31477. DecodeStream.call(this, maybeLength);
  31478. }
  31479. JpegStream.prototype = Object.create(DecodeStream.prototype);
  31480. Object.defineProperty(JpegStream.prototype, 'bytes', {
  31481. get: function JpegStream_bytes() {
  31482. // If this.maybeLength is null, we'll get the entire stream.
  31483. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  31484. },
  31485. configurable: true
  31486. });
  31487. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  31488. if (this.bufferLength) {
  31489. return;
  31490. }
  31491. try {
  31492. var jpegImage = new JpegImage();
  31493. // checking if values needs to be transformed before conversion
  31494. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  31495. var decodeArr = this.dict.get('Decode');
  31496. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  31497. var decodeArrLength = decodeArr.length;
  31498. var transform = new Int32Array(decodeArrLength);
  31499. var transformNeeded = false;
  31500. var maxValue = (1 << bitsPerComponent) - 1;
  31501. for (var i = 0; i < decodeArrLength; i += 2) {
  31502. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  31503. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  31504. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  31505. transformNeeded = true;
  31506. }
  31507. }
  31508. if (transformNeeded) {
  31509. jpegImage.decodeTransform = transform;
  31510. }
  31511. }
  31512. jpegImage.parse(this.bytes);
  31513. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  31514. this.forceRGB);
  31515. this.buffer = data;
  31516. this.bufferLength = data.length;
  31517. this.eof = true;
  31518. } catch (e) {
  31519. error('JPEG error: ' + e);
  31520. }
  31521. };
  31522. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  31523. this.ensureBuffer();
  31524. return this.buffer;
  31525. };
  31526. JpegStream.prototype.getIR = function JpegStream_getIR() {
  31527. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  31528. };
  31529. /**
  31530. * Checks if the image can be decoded and displayed by the browser without any
  31531. * further processing such as color space conversions.
  31532. */
  31533. JpegStream.prototype.isNativelySupported =
  31534. function JpegStream_isNativelySupported(xref, res) {
  31535. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  31536. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  31537. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  31538. };
  31539. /**
  31540. * Checks if the image can be decoded by the browser.
  31541. */
  31542. JpegStream.prototype.isNativelyDecodable =
  31543. function JpegStream_isNativelyDecodable(xref, res) {
  31544. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  31545. return (cs.numComps === 1 || cs.numComps === 3) &&
  31546. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  31547. };
  31548. return JpegStream;
  31549. })();
  31550. /**
  31551. * For JPEG 2000's we use a library to decode these images and
  31552. * the stream behaves like all the other DecodeStreams.
  31553. */
  31554. var JpxStream = (function JpxStreamClosure() {
  31555. function JpxStream(stream, maybeLength, dict) {
  31556. this.stream = stream;
  31557. this.maybeLength = maybeLength;
  31558. this.dict = dict;
  31559. DecodeStream.call(this, maybeLength);
  31560. }
  31561. JpxStream.prototype = Object.create(DecodeStream.prototype);
  31562. Object.defineProperty(JpxStream.prototype, 'bytes', {
  31563. get: function JpxStream_bytes() {
  31564. // If this.maybeLength is null, we'll get the entire stream.
  31565. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  31566. },
  31567. configurable: true
  31568. });
  31569. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  31570. if (this.bufferLength) {
  31571. return;
  31572. }
  31573. var jpxImage = new JpxImage();
  31574. jpxImage.parse(this.bytes);
  31575. var width = jpxImage.width;
  31576. var height = jpxImage.height;
  31577. var componentsCount = jpxImage.componentsCount;
  31578. var tileCount = jpxImage.tiles.length;
  31579. if (tileCount === 1) {
  31580. this.buffer = jpxImage.tiles[0].items;
  31581. } else {
  31582. var data = new Uint8Array(width * height * componentsCount);
  31583. for (var k = 0; k < tileCount; k++) {
  31584. var tileComponents = jpxImage.tiles[k];
  31585. var tileWidth = tileComponents.width;
  31586. var tileHeight = tileComponents.height;
  31587. var tileLeft = tileComponents.left;
  31588. var tileTop = tileComponents.top;
  31589. var src = tileComponents.items;
  31590. var srcPosition = 0;
  31591. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  31592. var imgRowSize = width * componentsCount;
  31593. var tileRowSize = tileWidth * componentsCount;
  31594. for (var j = 0; j < tileHeight; j++) {
  31595. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  31596. data.set(rowBytes, dataPosition);
  31597. srcPosition += tileRowSize;
  31598. dataPosition += imgRowSize;
  31599. }
  31600. }
  31601. this.buffer = data;
  31602. }
  31603. this.bufferLength = this.buffer.length;
  31604. this.eof = true;
  31605. };
  31606. return JpxStream;
  31607. })();
  31608. /**
  31609. * For JBIG2's we use a library to decode these images and
  31610. * the stream behaves like all the other DecodeStreams.
  31611. */
  31612. var Jbig2Stream = (function Jbig2StreamClosure() {
  31613. function Jbig2Stream(stream, maybeLength, dict) {
  31614. this.stream = stream;
  31615. this.maybeLength = maybeLength;
  31616. this.dict = dict;
  31617. DecodeStream.call(this, maybeLength);
  31618. }
  31619. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  31620. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  31621. get: function Jbig2Stream_bytes() {
  31622. // If this.maybeLength is null, we'll get the entire stream.
  31623. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  31624. },
  31625. configurable: true
  31626. });
  31627. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  31628. if (this.bufferLength) {
  31629. return;
  31630. }
  31631. var jbig2Image = new Jbig2Image();
  31632. var chunks = [], xref = this.dict.xref;
  31633. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  31634. // According to the PDF specification, DecodeParms can be either
  31635. // a dictionary, or an array whose elements are dictionaries.
  31636. if (isArray(decodeParams)) {
  31637. if (decodeParams.length > 1) {
  31638. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  31639. 'not supported.');
  31640. }
  31641. decodeParams = xref.fetchIfRef(decodeParams[0]);
  31642. }
  31643. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  31644. var globalsStream = decodeParams.get('JBIG2Globals');
  31645. var globals = globalsStream.getBytes();
  31646. chunks.push({data: globals, start: 0, end: globals.length});
  31647. }
  31648. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  31649. var data = jbig2Image.parseChunks(chunks);
  31650. var dataLength = data.length;
  31651. // JBIG2 had black as 1 and white as 0, inverting the colors
  31652. for (var i = 0; i < dataLength; i++) {
  31653. data[i] ^= 0xFF;
  31654. }
  31655. this.buffer = data;
  31656. this.bufferLength = dataLength;
  31657. this.eof = true;
  31658. };
  31659. return Jbig2Stream;
  31660. })();
  31661. var DecryptStream = (function DecryptStreamClosure() {
  31662. function DecryptStream(str, maybeLength, decrypt) {
  31663. this.str = str;
  31664. this.dict = str.dict;
  31665. this.decrypt = decrypt;
  31666. this.nextChunk = null;
  31667. this.initialized = false;
  31668. DecodeStream.call(this, maybeLength);
  31669. }
  31670. var chunkSize = 512;
  31671. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  31672. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  31673. var chunk;
  31674. if (this.initialized) {
  31675. chunk = this.nextChunk;
  31676. } else {
  31677. chunk = this.str.getBytes(chunkSize);
  31678. this.initialized = true;
  31679. }
  31680. if (!chunk || chunk.length === 0) {
  31681. this.eof = true;
  31682. return;
  31683. }
  31684. this.nextChunk = this.str.getBytes(chunkSize);
  31685. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  31686. var decrypt = this.decrypt;
  31687. chunk = decrypt(chunk, !hasMoreData);
  31688. var bufferLength = this.bufferLength;
  31689. var i, n = chunk.length;
  31690. var buffer = this.ensureBuffer(bufferLength + n);
  31691. for (i = 0; i < n; i++) {
  31692. buffer[bufferLength++] = chunk[i];
  31693. }
  31694. this.bufferLength = bufferLength;
  31695. };
  31696. return DecryptStream;
  31697. })();
  31698. var Ascii85Stream = (function Ascii85StreamClosure() {
  31699. function Ascii85Stream(str, maybeLength) {
  31700. this.str = str;
  31701. this.dict = str.dict;
  31702. this.input = new Uint8Array(5);
  31703. // Most streams increase in size when decoded, but Ascii85 streams
  31704. // typically shrink by ~20%.
  31705. if (maybeLength) {
  31706. maybeLength = 0.8 * maybeLength;
  31707. }
  31708. DecodeStream.call(this, maybeLength);
  31709. }
  31710. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  31711. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  31712. var TILDA_CHAR = 0x7E; // '~'
  31713. var Z_LOWER_CHAR = 0x7A; // 'z'
  31714. var EOF = -1;
  31715. var str = this.str;
  31716. var c = str.getByte();
  31717. while (Lexer.isSpace(c)) {
  31718. c = str.getByte();
  31719. }
  31720. if (c === EOF || c === TILDA_CHAR) {
  31721. this.eof = true;
  31722. return;
  31723. }
  31724. var bufferLength = this.bufferLength, buffer;
  31725. var i;
  31726. // special code for z
  31727. if (c === Z_LOWER_CHAR) {
  31728. buffer = this.ensureBuffer(bufferLength + 4);
  31729. for (i = 0; i < 4; ++i) {
  31730. buffer[bufferLength + i] = 0;
  31731. }
  31732. this.bufferLength += 4;
  31733. } else {
  31734. var input = this.input;
  31735. input[0] = c;
  31736. for (i = 1; i < 5; ++i) {
  31737. c = str.getByte();
  31738. while (Lexer.isSpace(c)) {
  31739. c = str.getByte();
  31740. }
  31741. input[i] = c;
  31742. if (c === EOF || c === TILDA_CHAR) {
  31743. break;
  31744. }
  31745. }
  31746. buffer = this.ensureBuffer(bufferLength + i - 1);
  31747. this.bufferLength += i - 1;
  31748. // partial ending;
  31749. if (i < 5) {
  31750. for (; i < 5; ++i) {
  31751. input[i] = 0x21 + 84;
  31752. }
  31753. this.eof = true;
  31754. }
  31755. var t = 0;
  31756. for (i = 0; i < 5; ++i) {
  31757. t = t * 85 + (input[i] - 0x21);
  31758. }
  31759. for (i = 3; i >= 0; --i) {
  31760. buffer[bufferLength + i] = t & 0xFF;
  31761. t >>= 8;
  31762. }
  31763. }
  31764. };
  31765. return Ascii85Stream;
  31766. })();
  31767. var AsciiHexStream = (function AsciiHexStreamClosure() {
  31768. function AsciiHexStream(str, maybeLength) {
  31769. this.str = str;
  31770. this.dict = str.dict;
  31771. this.firstDigit = -1;
  31772. // Most streams increase in size when decoded, but AsciiHex streams shrink
  31773. // by 50%.
  31774. if (maybeLength) {
  31775. maybeLength = 0.5 * maybeLength;
  31776. }
  31777. DecodeStream.call(this, maybeLength);
  31778. }
  31779. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  31780. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  31781. var UPSTREAM_BLOCK_SIZE = 8000;
  31782. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  31783. if (!bytes.length) {
  31784. this.eof = true;
  31785. return;
  31786. }
  31787. var maxDecodeLength = (bytes.length + 1) >> 1;
  31788. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  31789. var bufferLength = this.bufferLength;
  31790. var firstDigit = this.firstDigit;
  31791. for (var i = 0, ii = bytes.length; i < ii; i++) {
  31792. var ch = bytes[i], digit;
  31793. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  31794. digit = ch & 0x0F;
  31795. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  31796. // 'A'-'Z', 'a'-'z'
  31797. digit = (ch & 0x0F) + 9;
  31798. } else if (ch === 0x3E) { // '>'
  31799. this.eof = true;
  31800. break;
  31801. } else { // probably whitespace
  31802. continue; // ignoring
  31803. }
  31804. if (firstDigit < 0) {
  31805. firstDigit = digit;
  31806. } else {
  31807. buffer[bufferLength++] = (firstDigit << 4) | digit;
  31808. firstDigit = -1;
  31809. }
  31810. }
  31811. if (firstDigit >= 0 && this.eof) {
  31812. // incomplete byte
  31813. buffer[bufferLength++] = (firstDigit << 4);
  31814. firstDigit = -1;
  31815. }
  31816. this.firstDigit = firstDigit;
  31817. this.bufferLength = bufferLength;
  31818. };
  31819. return AsciiHexStream;
  31820. })();
  31821. var RunLengthStream = (function RunLengthStreamClosure() {
  31822. function RunLengthStream(str, maybeLength) {
  31823. this.str = str;
  31824. this.dict = str.dict;
  31825. DecodeStream.call(this, maybeLength);
  31826. }
  31827. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  31828. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  31829. // The repeatHeader has following format. The first byte defines type of run
  31830. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  31831. // (in addition to the second byte from the header), n = 129 through 255 -
  31832. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  31833. var repeatHeader = this.str.getBytes(2);
  31834. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  31835. this.eof = true;
  31836. return;
  31837. }
  31838. var buffer;
  31839. var bufferLength = this.bufferLength;
  31840. var n = repeatHeader[0];
  31841. if (n < 128) {
  31842. // copy n bytes
  31843. buffer = this.ensureBuffer(bufferLength + n + 1);
  31844. buffer[bufferLength++] = repeatHeader[1];
  31845. if (n > 0) {
  31846. var source = this.str.getBytes(n);
  31847. buffer.set(source, bufferLength);
  31848. bufferLength += n;
  31849. }
  31850. } else {
  31851. n = 257 - n;
  31852. var b = repeatHeader[1];
  31853. buffer = this.ensureBuffer(bufferLength + n + 1);
  31854. for (var i = 0; i < n; i++) {
  31855. buffer[bufferLength++] = b;
  31856. }
  31857. }
  31858. this.bufferLength = bufferLength;
  31859. };
  31860. return RunLengthStream;
  31861. })();
  31862. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  31863. var ccittEOL = -2;
  31864. var twoDimPass = 0;
  31865. var twoDimHoriz = 1;
  31866. var twoDimVert0 = 2;
  31867. var twoDimVertR1 = 3;
  31868. var twoDimVertL1 = 4;
  31869. var twoDimVertR2 = 5;
  31870. var twoDimVertL2 = 6;
  31871. var twoDimVertR3 = 7;
  31872. var twoDimVertL3 = 8;
  31873. var twoDimTable = [
  31874. [-1, -1], [-1, -1], // 000000x
  31875. [7, twoDimVertL3], // 0000010
  31876. [7, twoDimVertR3], // 0000011
  31877. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  31878. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  31879. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  31880. [4, twoDimPass], [4, twoDimPass],
  31881. [4, twoDimPass], [4, twoDimPass],
  31882. [4, twoDimPass], [4, twoDimPass],
  31883. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  31884. [3, twoDimHoriz], [3, twoDimHoriz],
  31885. [3, twoDimHoriz], [3, twoDimHoriz],
  31886. [3, twoDimHoriz], [3, twoDimHoriz],
  31887. [3, twoDimHoriz], [3, twoDimHoriz],
  31888. [3, twoDimHoriz], [3, twoDimHoriz],
  31889. [3, twoDimHoriz], [3, twoDimHoriz],
  31890. [3, twoDimHoriz], [3, twoDimHoriz],
  31891. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  31892. [3, twoDimVertL1], [3, twoDimVertL1],
  31893. [3, twoDimVertL1], [3, twoDimVertL1],
  31894. [3, twoDimVertL1], [3, twoDimVertL1],
  31895. [3, twoDimVertL1], [3, twoDimVertL1],
  31896. [3, twoDimVertL1], [3, twoDimVertL1],
  31897. [3, twoDimVertL1], [3, twoDimVertL1],
  31898. [3, twoDimVertL1], [3, twoDimVertL1],
  31899. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  31900. [3, twoDimVertR1], [3, twoDimVertR1],
  31901. [3, twoDimVertR1], [3, twoDimVertR1],
  31902. [3, twoDimVertR1], [3, twoDimVertR1],
  31903. [3, twoDimVertR1], [3, twoDimVertR1],
  31904. [3, twoDimVertR1], [3, twoDimVertR1],
  31905. [3, twoDimVertR1], [3, twoDimVertR1],
  31906. [3, twoDimVertR1], [3, twoDimVertR1],
  31907. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  31908. [1, twoDimVert0], [1, twoDimVert0],
  31909. [1, twoDimVert0], [1, twoDimVert0],
  31910. [1, twoDimVert0], [1, twoDimVert0],
  31911. [1, twoDimVert0], [1, twoDimVert0],
  31912. [1, twoDimVert0], [1, twoDimVert0],
  31913. [1, twoDimVert0], [1, twoDimVert0],
  31914. [1, twoDimVert0], [1, twoDimVert0],
  31915. [1, twoDimVert0], [1, twoDimVert0],
  31916. [1, twoDimVert0], [1, twoDimVert0],
  31917. [1, twoDimVert0], [1, twoDimVert0],
  31918. [1, twoDimVert0], [1, twoDimVert0],
  31919. [1, twoDimVert0], [1, twoDimVert0],
  31920. [1, twoDimVert0], [1, twoDimVert0],
  31921. [1, twoDimVert0], [1, twoDimVert0],
  31922. [1, twoDimVert0], [1, twoDimVert0],
  31923. [1, twoDimVert0], [1, twoDimVert0],
  31924. [1, twoDimVert0], [1, twoDimVert0],
  31925. [1, twoDimVert0], [1, twoDimVert0],
  31926. [1, twoDimVert0], [1, twoDimVert0],
  31927. [1, twoDimVert0], [1, twoDimVert0],
  31928. [1, twoDimVert0], [1, twoDimVert0],
  31929. [1, twoDimVert0], [1, twoDimVert0],
  31930. [1, twoDimVert0], [1, twoDimVert0],
  31931. [1, twoDimVert0], [1, twoDimVert0],
  31932. [1, twoDimVert0], [1, twoDimVert0],
  31933. [1, twoDimVert0], [1, twoDimVert0],
  31934. [1, twoDimVert0], [1, twoDimVert0],
  31935. [1, twoDimVert0], [1, twoDimVert0],
  31936. [1, twoDimVert0], [1, twoDimVert0],
  31937. [1, twoDimVert0], [1, twoDimVert0],
  31938. [1, twoDimVert0], [1, twoDimVert0]
  31939. ];
  31940. var whiteTable1 = [
  31941. [-1, -1], // 00000
  31942. [12, ccittEOL], // 00001
  31943. [-1, -1], [-1, -1], // 0001x
  31944. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  31945. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  31946. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  31947. [11, 1792], [11, 1792], // 1000x
  31948. [12, 1984], // 10010
  31949. [12, 2048], // 10011
  31950. [12, 2112], // 10100
  31951. [12, 2176], // 10101
  31952. [12, 2240], // 10110
  31953. [12, 2304], // 10111
  31954. [11, 1856], [11, 1856], // 1100x
  31955. [11, 1920], [11, 1920], // 1101x
  31956. [12, 2368], // 11100
  31957. [12, 2432], // 11101
  31958. [12, 2496], // 11110
  31959. [12, 2560] // 11111
  31960. ];
  31961. var whiteTable2 = [
  31962. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  31963. [8, 29], [8, 29], // 00000010x
  31964. [8, 30], [8, 30], // 00000011x
  31965. [8, 45], [8, 45], // 00000100x
  31966. [8, 46], [8, 46], // 00000101x
  31967. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  31968. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  31969. [8, 47], [8, 47], // 00001010x
  31970. [8, 48], [8, 48], // 00001011x
  31971. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  31972. [6, 13], [6, 13], [6, 13], [6, 13],
  31973. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  31974. [8, 33], [8, 33], // 00010010x
  31975. [8, 34], [8, 34], // 00010011x
  31976. [8, 35], [8, 35], // 00010100x
  31977. [8, 36], [8, 36], // 00010101x
  31978. [8, 37], [8, 37], // 00010110x
  31979. [8, 38], [8, 38], // 00010111x
  31980. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  31981. [8, 31], [8, 31], // 00011010x
  31982. [8, 32], [8, 32], // 00011011x
  31983. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  31984. [6, 1], [6, 1], [6, 1], [6, 1],
  31985. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  31986. [6, 12], [6, 12], [6, 12], [6, 12],
  31987. [8, 53], [8, 53], // 00100100x
  31988. [8, 54], [8, 54], // 00100101x
  31989. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  31990. [8, 39], [8, 39], // 00101000x
  31991. [8, 40], [8, 40], // 00101001x
  31992. [8, 41], [8, 41], // 00101010x
  31993. [8, 42], [8, 42], // 00101011x
  31994. [8, 43], [8, 43], // 00101100x
  31995. [8, 44], [8, 44], // 00101101x
  31996. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  31997. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  31998. [8, 61], [8, 61], // 00110010x
  31999. [8, 62], [8, 62], // 00110011x
  32000. [8, 63], [8, 63], // 00110100x
  32001. [8, 0], [8, 0], // 00110101x
  32002. [8, 320], [8, 320], // 00110110x
  32003. [8, 384], [8, 384], // 00110111x
  32004. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  32005. [5, 10], [5, 10], [5, 10], [5, 10],
  32006. [5, 10], [5, 10], [5, 10], [5, 10],
  32007. [5, 10], [5, 10], [5, 10], [5, 10],
  32008. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  32009. [5, 11], [5, 11], [5, 11], [5, 11],
  32010. [5, 11], [5, 11], [5, 11], [5, 11],
  32011. [5, 11], [5, 11], [5, 11], [5, 11],
  32012. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  32013. [8, 59], [8, 59], // 01001010x
  32014. [8, 60], [8, 60], // 01001011x
  32015. [9, 1472], // 010011000
  32016. [9, 1536], // 010011001
  32017. [9, 1600], // 010011010
  32018. [9, 1728], // 010011011
  32019. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  32020. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  32021. [8, 49], [8, 49], // 01010010x
  32022. [8, 50], [8, 50], // 01010011x
  32023. [8, 51], [8, 51], // 01010100x
  32024. [8, 52], [8, 52], // 01010101x
  32025. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  32026. [8, 55], [8, 55], // 01011000x
  32027. [8, 56], [8, 56], // 01011001x
  32028. [8, 57], [8, 57], // 01011010x
  32029. [8, 58], [8, 58], // 01011011x
  32030. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  32031. [6, 192], [6, 192], [6, 192], [6, 192],
  32032. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  32033. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  32034. [8, 448], [8, 448], // 01100100x
  32035. [8, 512], [8, 512], // 01100101x
  32036. [9, 704], // 011001100
  32037. [9, 768], // 011001101
  32038. [8, 640], [8, 640], // 01100111x
  32039. [8, 576], [8, 576], // 01101000x
  32040. [9, 832], // 011010010
  32041. [9, 896], // 011010011
  32042. [9, 960], // 011010100
  32043. [9, 1024], // 011010101
  32044. [9, 1088], // 011010110
  32045. [9, 1152], // 011010111
  32046. [9, 1216], // 011011000
  32047. [9, 1280], // 011011001
  32048. [9, 1344], // 011011010
  32049. [9, 1408], // 011011011
  32050. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  32051. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  32052. [4, 2], [4, 2], [4, 2], [4, 2],
  32053. [4, 2], [4, 2], [4, 2], [4, 2],
  32054. [4, 2], [4, 2], [4, 2], [4, 2],
  32055. [4, 2], [4, 2], [4, 2], [4, 2],
  32056. [4, 2], [4, 2], [4, 2], [4, 2],
  32057. [4, 2], [4, 2], [4, 2], [4, 2],
  32058. [4, 2], [4, 2], [4, 2], [4, 2],
  32059. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  32060. [4, 3], [4, 3], [4, 3], [4, 3],
  32061. [4, 3], [4, 3], [4, 3], [4, 3],
  32062. [4, 3], [4, 3], [4, 3], [4, 3],
  32063. [4, 3], [4, 3], [4, 3], [4, 3],
  32064. [4, 3], [4, 3], [4, 3], [4, 3],
  32065. [4, 3], [4, 3], [4, 3], [4, 3],
  32066. [4, 3], [4, 3], [4, 3], [4, 3],
  32067. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  32068. [5, 128], [5, 128], [5, 128], [5, 128],
  32069. [5, 128], [5, 128], [5, 128], [5, 128],
  32070. [5, 128], [5, 128], [5, 128], [5, 128],
  32071. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  32072. [5, 8], [5, 8], [5, 8], [5, 8],
  32073. [5, 8], [5, 8], [5, 8], [5, 8],
  32074. [5, 8], [5, 8], [5, 8], [5, 8],
  32075. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  32076. [5, 9], [5, 9], [5, 9], [5, 9],
  32077. [5, 9], [5, 9], [5, 9], [5, 9],
  32078. [5, 9], [5, 9], [5, 9], [5, 9],
  32079. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  32080. [6, 16], [6, 16], [6, 16], [6, 16],
  32081. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  32082. [6, 17], [6, 17], [6, 17], [6, 17],
  32083. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  32084. [4, 4], [4, 4], [4, 4], [4, 4],
  32085. [4, 4], [4, 4], [4, 4], [4, 4],
  32086. [4, 4], [4, 4], [4, 4], [4, 4],
  32087. [4, 4], [4, 4], [4, 4], [4, 4],
  32088. [4, 4], [4, 4], [4, 4], [4, 4],
  32089. [4, 4], [4, 4], [4, 4], [4, 4],
  32090. [4, 4], [4, 4], [4, 4], [4, 4],
  32091. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  32092. [4, 5], [4, 5], [4, 5], [4, 5],
  32093. [4, 5], [4, 5], [4, 5], [4, 5],
  32094. [4, 5], [4, 5], [4, 5], [4, 5],
  32095. [4, 5], [4, 5], [4, 5], [4, 5],
  32096. [4, 5], [4, 5], [4, 5], [4, 5],
  32097. [4, 5], [4, 5], [4, 5], [4, 5],
  32098. [4, 5], [4, 5], [4, 5], [4, 5],
  32099. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  32100. [6, 14], [6, 14], [6, 14], [6, 14],
  32101. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  32102. [6, 15], [6, 15], [6, 15], [6, 15],
  32103. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  32104. [5, 64], [5, 64], [5, 64], [5, 64],
  32105. [5, 64], [5, 64], [5, 64], [5, 64],
  32106. [5, 64], [5, 64], [5, 64], [5, 64],
  32107. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  32108. [4, 6], [4, 6], [4, 6], [4, 6],
  32109. [4, 6], [4, 6], [4, 6], [4, 6],
  32110. [4, 6], [4, 6], [4, 6], [4, 6],
  32111. [4, 6], [4, 6], [4, 6], [4, 6],
  32112. [4, 6], [4, 6], [4, 6], [4, 6],
  32113. [4, 6], [4, 6], [4, 6], [4, 6],
  32114. [4, 6], [4, 6], [4, 6], [4, 6],
  32115. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  32116. [4, 7], [4, 7], [4, 7], [4, 7],
  32117. [4, 7], [4, 7], [4, 7], [4, 7],
  32118. [4, 7], [4, 7], [4, 7], [4, 7],
  32119. [4, 7], [4, 7], [4, 7], [4, 7],
  32120. [4, 7], [4, 7], [4, 7], [4, 7],
  32121. [4, 7], [4, 7], [4, 7], [4, 7],
  32122. [4, 7], [4, 7], [4, 7], [4, 7]
  32123. ];
  32124. var blackTable1 = [
  32125. [-1, -1], [-1, -1], // 000000000000x
  32126. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  32127. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  32128. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  32129. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  32130. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  32131. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  32132. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  32133. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  32134. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  32135. [12, 1984], [12, 1984], // 000000010010x
  32136. [12, 2048], [12, 2048], // 000000010011x
  32137. [12, 2112], [12, 2112], // 000000010100x
  32138. [12, 2176], [12, 2176], // 000000010101x
  32139. [12, 2240], [12, 2240], // 000000010110x
  32140. [12, 2304], [12, 2304], // 000000010111x
  32141. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  32142. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  32143. [12, 2368], [12, 2368], // 000000011100x
  32144. [12, 2432], [12, 2432], // 000000011101x
  32145. [12, 2496], [12, 2496], // 000000011110x
  32146. [12, 2560], [12, 2560], // 000000011111x
  32147. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  32148. [10, 18], [10, 18], [10, 18], [10, 18],
  32149. [12, 52], [12, 52], // 000000100100x
  32150. [13, 640], // 0000001001010
  32151. [13, 704], // 0000001001011
  32152. [13, 768], // 0000001001100
  32153. [13, 832], // 0000001001101
  32154. [12, 55], [12, 55], // 000000100111x
  32155. [12, 56], [12, 56], // 000000101000x
  32156. [13, 1280], // 0000001010010
  32157. [13, 1344], // 0000001010011
  32158. [13, 1408], // 0000001010100
  32159. [13, 1472], // 0000001010101
  32160. [12, 59], [12, 59], // 000000101011x
  32161. [12, 60], [12, 60], // 000000101100x
  32162. [13, 1536], // 0000001011010
  32163. [13, 1600], // 0000001011011
  32164. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  32165. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  32166. [13, 1664], // 0000001100100
  32167. [13, 1728], // 0000001100101
  32168. [12, 320], [12, 320], // 000000110011x
  32169. [12, 384], [12, 384], // 000000110100x
  32170. [12, 448], [12, 448], // 000000110101x
  32171. [13, 512], // 0000001101100
  32172. [13, 576], // 0000001101101
  32173. [12, 53], [12, 53], // 000000110111x
  32174. [12, 54], [12, 54], // 000000111000x
  32175. [13, 896], // 0000001110010
  32176. [13, 960], // 0000001110011
  32177. [13, 1024], // 0000001110100
  32178. [13, 1088], // 0000001110101
  32179. [13, 1152], // 0000001110110
  32180. [13, 1216], // 0000001110111
  32181. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  32182. [10, 64], [10, 64], [10, 64], [10, 64]
  32183. ];
  32184. var blackTable2 = [
  32185. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  32186. [8, 13], [8, 13], [8, 13], [8, 13],
  32187. [8, 13], [8, 13], [8, 13], [8, 13],
  32188. [8, 13], [8, 13], [8, 13], [8, 13],
  32189. [11, 23], [11, 23], // 00000101000x
  32190. [12, 50], // 000001010010
  32191. [12, 51], // 000001010011
  32192. [12, 44], // 000001010100
  32193. [12, 45], // 000001010101
  32194. [12, 46], // 000001010110
  32195. [12, 47], // 000001010111
  32196. [12, 57], // 000001011000
  32197. [12, 58], // 000001011001
  32198. [12, 61], // 000001011010
  32199. [12, 256], // 000001011011
  32200. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  32201. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  32202. [12, 48], // 000001100100
  32203. [12, 49], // 000001100101
  32204. [12, 62], // 000001100110
  32205. [12, 63], // 000001100111
  32206. [12, 30], // 000001101000
  32207. [12, 31], // 000001101001
  32208. [12, 32], // 000001101010
  32209. [12, 33], // 000001101011
  32210. [12, 40], // 000001101100
  32211. [12, 41], // 000001101101
  32212. [11, 22], [11, 22], // 00000110111x
  32213. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  32214. [8, 14], [8, 14], [8, 14], [8, 14],
  32215. [8, 14], [8, 14], [8, 14], [8, 14],
  32216. [8, 14], [8, 14], [8, 14], [8, 14],
  32217. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  32218. [7, 10], [7, 10], [7, 10], [7, 10],
  32219. [7, 10], [7, 10], [7, 10], [7, 10],
  32220. [7, 10], [7, 10], [7, 10], [7, 10],
  32221. [7, 10], [7, 10], [7, 10], [7, 10],
  32222. [7, 10], [7, 10], [7, 10], [7, 10],
  32223. [7, 10], [7, 10], [7, 10], [7, 10],
  32224. [7, 10], [7, 10], [7, 10], [7, 10],
  32225. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  32226. [7, 11], [7, 11], [7, 11], [7, 11],
  32227. [7, 11], [7, 11], [7, 11], [7, 11],
  32228. [7, 11], [7, 11], [7, 11], [7, 11],
  32229. [7, 11], [7, 11], [7, 11], [7, 11],
  32230. [7, 11], [7, 11], [7, 11], [7, 11],
  32231. [7, 11], [7, 11], [7, 11], [7, 11],
  32232. [7, 11], [7, 11], [7, 11], [7, 11],
  32233. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  32234. [9, 15], [9, 15], [9, 15], [9, 15],
  32235. [12, 128], // 000011001000
  32236. [12, 192], // 000011001001
  32237. [12, 26], // 000011001010
  32238. [12, 27], // 000011001011
  32239. [12, 28], // 000011001100
  32240. [12, 29], // 000011001101
  32241. [11, 19], [11, 19], // 00001100111x
  32242. [11, 20], [11, 20], // 00001101000x
  32243. [12, 34], // 000011010010
  32244. [12, 35], // 000011010011
  32245. [12, 36], // 000011010100
  32246. [12, 37], // 000011010101
  32247. [12, 38], // 000011010110
  32248. [12, 39], // 000011010111
  32249. [11, 21], [11, 21], // 00001101100x
  32250. [12, 42], // 000011011010
  32251. [12, 43], // 000011011011
  32252. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  32253. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  32254. [7, 12], [7, 12], [7, 12], [7, 12],
  32255. [7, 12], [7, 12], [7, 12], [7, 12],
  32256. [7, 12], [7, 12], [7, 12], [7, 12],
  32257. [7, 12], [7, 12], [7, 12], [7, 12],
  32258. [7, 12], [7, 12], [7, 12], [7, 12],
  32259. [7, 12], [7, 12], [7, 12], [7, 12],
  32260. [7, 12], [7, 12], [7, 12], [7, 12]
  32261. ];
  32262. var blackTable3 = [
  32263. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  32264. [6, 9], // 000100
  32265. [6, 8], // 000101
  32266. [5, 7], [5, 7], // 00011x
  32267. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  32268. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  32269. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  32270. [3, 1], [3, 1], [3, 1], [3, 1],
  32271. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  32272. [3, 4], [3, 4], [3, 4], [3, 4],
  32273. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  32274. [2, 3], [2, 3], [2, 3], [2, 3],
  32275. [2, 3], [2, 3], [2, 3], [2, 3],
  32276. [2, 3], [2, 3], [2, 3], [2, 3],
  32277. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  32278. [2, 2], [2, 2], [2, 2], [2, 2],
  32279. [2, 2], [2, 2], [2, 2], [2, 2],
  32280. [2, 2], [2, 2], [2, 2], [2, 2]
  32281. ];
  32282. function CCITTFaxStream(str, maybeLength, params) {
  32283. this.str = str;
  32284. this.dict = str.dict;
  32285. params = params || Dict.empty;
  32286. this.encoding = params.get('K') || 0;
  32287. this.eoline = params.get('EndOfLine') || false;
  32288. this.byteAlign = params.get('EncodedByteAlign') || false;
  32289. this.columns = params.get('Columns') || 1728;
  32290. this.rows = params.get('Rows') || 0;
  32291. var eoblock = params.get('EndOfBlock');
  32292. if (eoblock === null || eoblock === undefined) {
  32293. eoblock = true;
  32294. }
  32295. this.eoblock = eoblock;
  32296. this.black = params.get('BlackIs1') || false;
  32297. this.codingLine = new Uint32Array(this.columns + 1);
  32298. this.refLine = new Uint32Array(this.columns + 2);
  32299. this.codingLine[0] = this.columns;
  32300. this.codingPos = 0;
  32301. this.row = 0;
  32302. this.nextLine2D = this.encoding < 0;
  32303. this.inputBits = 0;
  32304. this.inputBuf = 0;
  32305. this.outputBits = 0;
  32306. var code1;
  32307. while ((code1 = this.lookBits(12)) === 0) {
  32308. this.eatBits(1);
  32309. }
  32310. if (code1 === 1) {
  32311. this.eatBits(12);
  32312. }
  32313. if (this.encoding > 0) {
  32314. this.nextLine2D = !this.lookBits(1);
  32315. this.eatBits(1);
  32316. }
  32317. DecodeStream.call(this, maybeLength);
  32318. }
  32319. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  32320. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  32321. while (!this.eof) {
  32322. var c = this.lookChar();
  32323. this.ensureBuffer(this.bufferLength + 1);
  32324. this.buffer[this.bufferLength++] = c;
  32325. }
  32326. };
  32327. CCITTFaxStream.prototype.addPixels =
  32328. function ccittFaxStreamAddPixels(a1, blackPixels) {
  32329. var codingLine = this.codingLine;
  32330. var codingPos = this.codingPos;
  32331. if (a1 > codingLine[codingPos]) {
  32332. if (a1 > this.columns) {
  32333. info('row is wrong length');
  32334. this.err = true;
  32335. a1 = this.columns;
  32336. }
  32337. if ((codingPos & 1) ^ blackPixels) {
  32338. ++codingPos;
  32339. }
  32340. codingLine[codingPos] = a1;
  32341. }
  32342. this.codingPos = codingPos;
  32343. };
  32344. CCITTFaxStream.prototype.addPixelsNeg =
  32345. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  32346. var codingLine = this.codingLine;
  32347. var codingPos = this.codingPos;
  32348. if (a1 > codingLine[codingPos]) {
  32349. if (a1 > this.columns) {
  32350. info('row is wrong length');
  32351. this.err = true;
  32352. a1 = this.columns;
  32353. }
  32354. if ((codingPos & 1) ^ blackPixels) {
  32355. ++codingPos;
  32356. }
  32357. codingLine[codingPos] = a1;
  32358. } else if (a1 < codingLine[codingPos]) {
  32359. if (a1 < 0) {
  32360. info('invalid code');
  32361. this.err = true;
  32362. a1 = 0;
  32363. }
  32364. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  32365. --codingPos;
  32366. }
  32367. codingLine[codingPos] = a1;
  32368. }
  32369. this.codingPos = codingPos;
  32370. };
  32371. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  32372. var refLine = this.refLine;
  32373. var codingLine = this.codingLine;
  32374. var columns = this.columns;
  32375. var refPos, blackPixels, bits, i;
  32376. if (this.outputBits === 0) {
  32377. if (this.eof) {
  32378. return null;
  32379. }
  32380. this.err = false;
  32381. var code1, code2, code3;
  32382. if (this.nextLine2D) {
  32383. for (i = 0; codingLine[i] < columns; ++i) {
  32384. refLine[i] = codingLine[i];
  32385. }
  32386. refLine[i++] = columns;
  32387. refLine[i] = columns;
  32388. codingLine[0] = 0;
  32389. this.codingPos = 0;
  32390. refPos = 0;
  32391. blackPixels = 0;
  32392. while (codingLine[this.codingPos] < columns) {
  32393. code1 = this.getTwoDimCode();
  32394. switch (code1) {
  32395. case twoDimPass:
  32396. this.addPixels(refLine[refPos + 1], blackPixels);
  32397. if (refLine[refPos + 1] < columns) {
  32398. refPos += 2;
  32399. }
  32400. break;
  32401. case twoDimHoriz:
  32402. code1 = code2 = 0;
  32403. if (blackPixels) {
  32404. do {
  32405. code1 += (code3 = this.getBlackCode());
  32406. } while (code3 >= 64);
  32407. do {
  32408. code2 += (code3 = this.getWhiteCode());
  32409. } while (code3 >= 64);
  32410. } else {
  32411. do {
  32412. code1 += (code3 = this.getWhiteCode());
  32413. } while (code3 >= 64);
  32414. do {
  32415. code2 += (code3 = this.getBlackCode());
  32416. } while (code3 >= 64);
  32417. }
  32418. this.addPixels(codingLine[this.codingPos] +
  32419. code1, blackPixels);
  32420. if (codingLine[this.codingPos] < columns) {
  32421. this.addPixels(codingLine[this.codingPos] + code2,
  32422. blackPixels ^ 1);
  32423. }
  32424. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32425. refLine[refPos] < columns) {
  32426. refPos += 2;
  32427. }
  32428. break;
  32429. case twoDimVertR3:
  32430. this.addPixels(refLine[refPos] + 3, blackPixels);
  32431. blackPixels ^= 1;
  32432. if (codingLine[this.codingPos] < columns) {
  32433. ++refPos;
  32434. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32435. refLine[refPos] < columns) {
  32436. refPos += 2;
  32437. }
  32438. }
  32439. break;
  32440. case twoDimVertR2:
  32441. this.addPixels(refLine[refPos] + 2, blackPixels);
  32442. blackPixels ^= 1;
  32443. if (codingLine[this.codingPos] < columns) {
  32444. ++refPos;
  32445. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32446. refLine[refPos] < columns) {
  32447. refPos += 2;
  32448. }
  32449. }
  32450. break;
  32451. case twoDimVertR1:
  32452. this.addPixels(refLine[refPos] + 1, blackPixels);
  32453. blackPixels ^= 1;
  32454. if (codingLine[this.codingPos] < columns) {
  32455. ++refPos;
  32456. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32457. refLine[refPos] < columns) {
  32458. refPos += 2;
  32459. }
  32460. }
  32461. break;
  32462. case twoDimVert0:
  32463. this.addPixels(refLine[refPos], blackPixels);
  32464. blackPixels ^= 1;
  32465. if (codingLine[this.codingPos] < columns) {
  32466. ++refPos;
  32467. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32468. refLine[refPos] < columns) {
  32469. refPos += 2;
  32470. }
  32471. }
  32472. break;
  32473. case twoDimVertL3:
  32474. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  32475. blackPixels ^= 1;
  32476. if (codingLine[this.codingPos] < columns) {
  32477. if (refPos > 0) {
  32478. --refPos;
  32479. } else {
  32480. ++refPos;
  32481. }
  32482. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32483. refLine[refPos] < columns) {
  32484. refPos += 2;
  32485. }
  32486. }
  32487. break;
  32488. case twoDimVertL2:
  32489. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  32490. blackPixels ^= 1;
  32491. if (codingLine[this.codingPos] < columns) {
  32492. if (refPos > 0) {
  32493. --refPos;
  32494. } else {
  32495. ++refPos;
  32496. }
  32497. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32498. refLine[refPos] < columns) {
  32499. refPos += 2;
  32500. }
  32501. }
  32502. break;
  32503. case twoDimVertL1:
  32504. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  32505. blackPixels ^= 1;
  32506. if (codingLine[this.codingPos] < columns) {
  32507. if (refPos > 0) {
  32508. --refPos;
  32509. } else {
  32510. ++refPos;
  32511. }
  32512. while (refLine[refPos] <= codingLine[this.codingPos] &&
  32513. refLine[refPos] < columns) {
  32514. refPos += 2;
  32515. }
  32516. }
  32517. break;
  32518. case EOF:
  32519. this.addPixels(columns, 0);
  32520. this.eof = true;
  32521. break;
  32522. default:
  32523. info('bad 2d code');
  32524. this.addPixels(columns, 0);
  32525. this.err = true;
  32526. }
  32527. }
  32528. } else {
  32529. codingLine[0] = 0;
  32530. this.codingPos = 0;
  32531. blackPixels = 0;
  32532. while (codingLine[this.codingPos] < columns) {
  32533. code1 = 0;
  32534. if (blackPixels) {
  32535. do {
  32536. code1 += (code3 = this.getBlackCode());
  32537. } while (code3 >= 64);
  32538. } else {
  32539. do {
  32540. code1 += (code3 = this.getWhiteCode());
  32541. } while (code3 >= 64);
  32542. }
  32543. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  32544. blackPixels ^= 1;
  32545. }
  32546. }
  32547. var gotEOL = false;
  32548. if (this.byteAlign) {
  32549. this.inputBits &= ~7;
  32550. }
  32551. if (!this.eoblock && this.row === this.rows - 1) {
  32552. this.eof = true;
  32553. } else {
  32554. code1 = this.lookBits(12);
  32555. if (this.eoline) {
  32556. while (code1 !== EOF && code1 !== 1) {
  32557. this.eatBits(1);
  32558. code1 = this.lookBits(12);
  32559. }
  32560. } else {
  32561. while (code1 === 0) {
  32562. this.eatBits(1);
  32563. code1 = this.lookBits(12);
  32564. }
  32565. }
  32566. if (code1 === 1) {
  32567. this.eatBits(12);
  32568. gotEOL = true;
  32569. } else if (code1 === EOF) {
  32570. this.eof = true;
  32571. }
  32572. }
  32573. if (!this.eof && this.encoding > 0) {
  32574. this.nextLine2D = !this.lookBits(1);
  32575. this.eatBits(1);
  32576. }
  32577. if (this.eoblock && gotEOL && this.byteAlign) {
  32578. code1 = this.lookBits(12);
  32579. if (code1 === 1) {
  32580. this.eatBits(12);
  32581. if (this.encoding > 0) {
  32582. this.lookBits(1);
  32583. this.eatBits(1);
  32584. }
  32585. if (this.encoding >= 0) {
  32586. for (i = 0; i < 4; ++i) {
  32587. code1 = this.lookBits(12);
  32588. if (code1 !== 1) {
  32589. info('bad rtc code: ' + code1);
  32590. }
  32591. this.eatBits(12);
  32592. if (this.encoding > 0) {
  32593. this.lookBits(1);
  32594. this.eatBits(1);
  32595. }
  32596. }
  32597. }
  32598. this.eof = true;
  32599. }
  32600. } else if (this.err && this.eoline) {
  32601. while (true) {
  32602. code1 = this.lookBits(13);
  32603. if (code1 === EOF) {
  32604. this.eof = true;
  32605. return null;
  32606. }
  32607. if ((code1 >> 1) === 1) {
  32608. break;
  32609. }
  32610. this.eatBits(1);
  32611. }
  32612. this.eatBits(12);
  32613. if (this.encoding > 0) {
  32614. this.eatBits(1);
  32615. this.nextLine2D = !(code1 & 1);
  32616. }
  32617. }
  32618. if (codingLine[0] > 0) {
  32619. this.outputBits = codingLine[this.codingPos = 0];
  32620. } else {
  32621. this.outputBits = codingLine[this.codingPos = 1];
  32622. }
  32623. this.row++;
  32624. }
  32625. var c;
  32626. if (this.outputBits >= 8) {
  32627. c = (this.codingPos & 1) ? 0 : 0xFF;
  32628. this.outputBits -= 8;
  32629. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  32630. this.codingPos++;
  32631. this.outputBits = (codingLine[this.codingPos] -
  32632. codingLine[this.codingPos - 1]);
  32633. }
  32634. } else {
  32635. bits = 8;
  32636. c = 0;
  32637. do {
  32638. if (this.outputBits > bits) {
  32639. c <<= bits;
  32640. if (!(this.codingPos & 1)) {
  32641. c |= 0xFF >> (8 - bits);
  32642. }
  32643. this.outputBits -= bits;
  32644. bits = 0;
  32645. } else {
  32646. c <<= this.outputBits;
  32647. if (!(this.codingPos & 1)) {
  32648. c |= 0xFF >> (8 - this.outputBits);
  32649. }
  32650. bits -= this.outputBits;
  32651. this.outputBits = 0;
  32652. if (codingLine[this.codingPos] < columns) {
  32653. this.codingPos++;
  32654. this.outputBits = (codingLine[this.codingPos] -
  32655. codingLine[this.codingPos - 1]);
  32656. } else if (bits > 0) {
  32657. c <<= bits;
  32658. bits = 0;
  32659. }
  32660. }
  32661. } while (bits);
  32662. }
  32663. if (this.black) {
  32664. c ^= 0xFF;
  32665. }
  32666. return c;
  32667. };
  32668. // This functions returns the code found from the table.
  32669. // The start and end parameters set the boundaries for searching the table.
  32670. // The limit parameter is optional. Function returns an array with three
  32671. // values. The first array element indicates whether a valid code is being
  32672. // returned. The second array element is the actual code. The third array
  32673. // element indicates whether EOF was reached.
  32674. CCITTFaxStream.prototype.findTableCode =
  32675. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  32676. var limitValue = limit || 0;
  32677. for (var i = start; i <= end; ++i) {
  32678. var code = this.lookBits(i);
  32679. if (code === EOF) {
  32680. return [true, 1, false];
  32681. }
  32682. if (i < end) {
  32683. code <<= end - i;
  32684. }
  32685. if (!limitValue || code >= limitValue) {
  32686. var p = table[code - limitValue];
  32687. if (p[0] === i) {
  32688. this.eatBits(i);
  32689. return [true, p[1], true];
  32690. }
  32691. }
  32692. }
  32693. return [false, 0, false];
  32694. };
  32695. CCITTFaxStream.prototype.getTwoDimCode =
  32696. function ccittFaxStreamGetTwoDimCode() {
  32697. var code = 0;
  32698. var p;
  32699. if (this.eoblock) {
  32700. code = this.lookBits(7);
  32701. p = twoDimTable[code];
  32702. if (p && p[0] > 0) {
  32703. this.eatBits(p[0]);
  32704. return p[1];
  32705. }
  32706. } else {
  32707. var result = this.findTableCode(1, 7, twoDimTable);
  32708. if (result[0] && result[2]) {
  32709. return result[1];
  32710. }
  32711. }
  32712. info('Bad two dim code');
  32713. return EOF;
  32714. };
  32715. CCITTFaxStream.prototype.getWhiteCode =
  32716. function ccittFaxStreamGetWhiteCode() {
  32717. var code = 0;
  32718. var p;
  32719. if (this.eoblock) {
  32720. code = this.lookBits(12);
  32721. if (code === EOF) {
  32722. return 1;
  32723. }
  32724. if ((code >> 5) === 0) {
  32725. p = whiteTable1[code];
  32726. } else {
  32727. p = whiteTable2[code >> 3];
  32728. }
  32729. if (p[0] > 0) {
  32730. this.eatBits(p[0]);
  32731. return p[1];
  32732. }
  32733. } else {
  32734. var result = this.findTableCode(1, 9, whiteTable2);
  32735. if (result[0]) {
  32736. return result[1];
  32737. }
  32738. result = this.findTableCode(11, 12, whiteTable1);
  32739. if (result[0]) {
  32740. return result[1];
  32741. }
  32742. }
  32743. info('bad white code');
  32744. this.eatBits(1);
  32745. return 1;
  32746. };
  32747. CCITTFaxStream.prototype.getBlackCode =
  32748. function ccittFaxStreamGetBlackCode() {
  32749. var code, p;
  32750. if (this.eoblock) {
  32751. code = this.lookBits(13);
  32752. if (code === EOF) {
  32753. return 1;
  32754. }
  32755. if ((code >> 7) === 0) {
  32756. p = blackTable1[code];
  32757. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  32758. p = blackTable2[(code >> 1) - 64];
  32759. } else {
  32760. p = blackTable3[code >> 7];
  32761. }
  32762. if (p[0] > 0) {
  32763. this.eatBits(p[0]);
  32764. return p[1];
  32765. }
  32766. } else {
  32767. var result = this.findTableCode(2, 6, blackTable3);
  32768. if (result[0]) {
  32769. return result[1];
  32770. }
  32771. result = this.findTableCode(7, 12, blackTable2, 64);
  32772. if (result[0]) {
  32773. return result[1];
  32774. }
  32775. result = this.findTableCode(10, 13, blackTable1);
  32776. if (result[0]) {
  32777. return result[1];
  32778. }
  32779. }
  32780. info('bad black code');
  32781. this.eatBits(1);
  32782. return 1;
  32783. };
  32784. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  32785. var c;
  32786. while (this.inputBits < n) {
  32787. if ((c = this.str.getByte()) === -1) {
  32788. if (this.inputBits === 0) {
  32789. return EOF;
  32790. }
  32791. return ((this.inputBuf << (n - this.inputBits)) &
  32792. (0xFFFF >> (16 - n)));
  32793. }
  32794. this.inputBuf = (this.inputBuf << 8) + c;
  32795. this.inputBits += 8;
  32796. }
  32797. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  32798. };
  32799. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  32800. if ((this.inputBits -= n) < 0) {
  32801. this.inputBits = 0;
  32802. }
  32803. };
  32804. return CCITTFaxStream;
  32805. })();
  32806. var LZWStream = (function LZWStreamClosure() {
  32807. function LZWStream(str, maybeLength, earlyChange) {
  32808. this.str = str;
  32809. this.dict = str.dict;
  32810. this.cachedData = 0;
  32811. this.bitsCached = 0;
  32812. var maxLzwDictionarySize = 4096;
  32813. var lzwState = {
  32814. earlyChange: earlyChange,
  32815. codeLength: 9,
  32816. nextCode: 258,
  32817. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  32818. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  32819. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  32820. currentSequence: new Uint8Array(maxLzwDictionarySize),
  32821. currentSequenceLength: 0
  32822. };
  32823. for (var i = 0; i < 256; ++i) {
  32824. lzwState.dictionaryValues[i] = i;
  32825. lzwState.dictionaryLengths[i] = 1;
  32826. }
  32827. this.lzwState = lzwState;
  32828. DecodeStream.call(this, maybeLength);
  32829. }
  32830. LZWStream.prototype = Object.create(DecodeStream.prototype);
  32831. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  32832. var bitsCached = this.bitsCached;
  32833. var cachedData = this.cachedData;
  32834. while (bitsCached < n) {
  32835. var c = this.str.getByte();
  32836. if (c === -1) {
  32837. this.eof = true;
  32838. return null;
  32839. }
  32840. cachedData = (cachedData << 8) | c;
  32841. bitsCached += 8;
  32842. }
  32843. this.bitsCached = (bitsCached -= n);
  32844. this.cachedData = cachedData;
  32845. this.lastCode = null;
  32846. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  32847. };
  32848. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  32849. var blockSize = 512;
  32850. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  32851. var i, j, q;
  32852. var lzwState = this.lzwState;
  32853. if (!lzwState) {
  32854. return; // eof was found
  32855. }
  32856. var earlyChange = lzwState.earlyChange;
  32857. var nextCode = lzwState.nextCode;
  32858. var dictionaryValues = lzwState.dictionaryValues;
  32859. var dictionaryLengths = lzwState.dictionaryLengths;
  32860. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  32861. var codeLength = lzwState.codeLength;
  32862. var prevCode = lzwState.prevCode;
  32863. var currentSequence = lzwState.currentSequence;
  32864. var currentSequenceLength = lzwState.currentSequenceLength;
  32865. var decodedLength = 0;
  32866. var currentBufferLength = this.bufferLength;
  32867. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32868. for (i = 0; i < blockSize; i++) {
  32869. var code = this.readBits(codeLength);
  32870. var hasPrev = currentSequenceLength > 0;
  32871. if (code < 256) {
  32872. currentSequence[0] = code;
  32873. currentSequenceLength = 1;
  32874. } else if (code >= 258) {
  32875. if (code < nextCode) {
  32876. currentSequenceLength = dictionaryLengths[code];
  32877. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  32878. currentSequence[j] = dictionaryValues[q];
  32879. q = dictionaryPrevCodes[q];
  32880. }
  32881. } else {
  32882. currentSequence[currentSequenceLength++] = currentSequence[0];
  32883. }
  32884. } else if (code === 256) {
  32885. codeLength = 9;
  32886. nextCode = 258;
  32887. currentSequenceLength = 0;
  32888. continue;
  32889. } else {
  32890. this.eof = true;
  32891. delete this.lzwState;
  32892. break;
  32893. }
  32894. if (hasPrev) {
  32895. dictionaryPrevCodes[nextCode] = prevCode;
  32896. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  32897. dictionaryValues[nextCode] = currentSequence[0];
  32898. nextCode++;
  32899. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  32900. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  32901. 0.6931471805599453 + 1, 12) | 0;
  32902. }
  32903. prevCode = code;
  32904. decodedLength += currentSequenceLength;
  32905. if (estimatedDecodedSize < decodedLength) {
  32906. do {
  32907. estimatedDecodedSize += decodedSizeDelta;
  32908. } while (estimatedDecodedSize < decodedLength);
  32909. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  32910. }
  32911. for (j = 0; j < currentSequenceLength; j++) {
  32912. buffer[currentBufferLength++] = currentSequence[j];
  32913. }
  32914. }
  32915. lzwState.nextCode = nextCode;
  32916. lzwState.codeLength = codeLength;
  32917. lzwState.prevCode = prevCode;
  32918. lzwState.currentSequenceLength = currentSequenceLength;
  32919. this.bufferLength = currentBufferLength;
  32920. };
  32921. return LZWStream;
  32922. })();
  32923. var NullStream = (function NullStreamClosure() {
  32924. function NullStream() {
  32925. Stream.call(this, new Uint8Array(0));
  32926. }
  32927. NullStream.prototype = Stream.prototype;
  32928. return NullStream;
  32929. })();
  32930. var WorkerTask = (function WorkerTaskClosure() {
  32931. function WorkerTask(name) {
  32932. this.name = name;
  32933. this.terminated = false;
  32934. this._capability = createPromiseCapability();
  32935. }
  32936. WorkerTask.prototype = {
  32937. get finished() {
  32938. return this._capability.promise;
  32939. },
  32940. finish: function () {
  32941. this._capability.resolve();
  32942. },
  32943. terminate: function () {
  32944. this.terminated = true;
  32945. },
  32946. ensureNotTerminated: function () {
  32947. if (this.terminated) {
  32948. throw new Error('Worker task was terminated');
  32949. }
  32950. }
  32951. };
  32952. return WorkerTask;
  32953. })();
  32954. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  32955. setup: function wphSetup(handler, port) {
  32956. handler.on('test', function wphSetupTest(data) {
  32957. // check if Uint8Array can be sent to worker
  32958. if (!(data instanceof Uint8Array)) {
  32959. handler.send('test', 'main', false);
  32960. return;
  32961. }
  32962. // making sure postMessage transfers are working
  32963. var supportTransfers = data[0] === 255;
  32964. handler.postMessageTransfers = supportTransfers;
  32965. // check if the response property is supported by xhr
  32966. var xhr = new XMLHttpRequest();
  32967. var responseExists = 'response' in xhr;
  32968. // check if the property is actually implemented
  32969. try {
  32970. var dummy = xhr.responseType;
  32971. } catch (e) {
  32972. responseExists = false;
  32973. }
  32974. if (!responseExists) {
  32975. handler.send('test', false);
  32976. return;
  32977. }
  32978. handler.send('test', {
  32979. supportTypedArray: true,
  32980. supportTransfers: supportTransfers
  32981. });
  32982. });
  32983. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32984. return WorkerMessageHandler.createDocumentHandler(data, port);
  32985. });
  32986. },
  32987. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  32988. // This context is actually holds references on pdfManager and handler,
  32989. // until the latter is destroyed.
  32990. var pdfManager;
  32991. var terminated = false;
  32992. var cancelXHRs = null;
  32993. var WorkerTasks = [];
  32994. var docId = docParams.docId;
  32995. var workerHandlerName = docParams.docId + '_worker';
  32996. var handler = new MessageHandler(workerHandlerName, docId, port);
  32997. function ensureNotTerminated() {
  32998. if (terminated) {
  32999. throw new Error('Worker was terminated');
  33000. }
  33001. }
  33002. function startWorkerTask(task) {
  33003. WorkerTasks.push(task);
  33004. }
  33005. function finishWorkerTask(task) {
  33006. task.finish();
  33007. var i = WorkerTasks.indexOf(task);
  33008. WorkerTasks.splice(i, 1);
  33009. }
  33010. function loadDocument(recoveryMode) {
  33011. var loadDocumentCapability = createPromiseCapability();
  33012. var parseSuccess = function parseSuccess() {
  33013. var numPagesPromise = pdfManager.ensureDoc('numPages');
  33014. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  33015. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  33016. Promise.all([numPagesPromise, fingerprintPromise,
  33017. encryptedPromise]).then(function onDocReady(results) {
  33018. var doc = {
  33019. numPages: results[0],
  33020. fingerprint: results[1],
  33021. encrypted: !!results[2],
  33022. };
  33023. loadDocumentCapability.resolve(doc);
  33024. },
  33025. parseFailure);
  33026. };
  33027. var parseFailure = function parseFailure(e) {
  33028. loadDocumentCapability.reject(e);
  33029. };
  33030. pdfManager.ensureDoc('checkHeader', []).then(function() {
  33031. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  33032. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  33033. parseSuccess, parseFailure);
  33034. }, parseFailure);
  33035. }, parseFailure);
  33036. return loadDocumentCapability.promise;
  33037. }
  33038. function getPdfManager(data) {
  33039. var pdfManagerCapability = createPromiseCapability();
  33040. var pdfManager;
  33041. var source = data.source;
  33042. var disableRange = data.disableRange;
  33043. if (source.data) {
  33044. try {
  33045. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  33046. pdfManagerCapability.resolve(pdfManager);
  33047. } catch (ex) {
  33048. pdfManagerCapability.reject(ex);
  33049. }
  33050. return pdfManagerCapability.promise;
  33051. } else if (source.chunkedViewerLoading) {
  33052. try {
  33053. pdfManager = new NetworkPdfManager(docId, source, handler);
  33054. pdfManagerCapability.resolve(pdfManager);
  33055. } catch (ex) {
  33056. pdfManagerCapability.reject(ex);
  33057. }
  33058. return pdfManagerCapability.promise;
  33059. }
  33060. var networkManager = new NetworkManager(source.url, {
  33061. httpHeaders: source.httpHeaders,
  33062. withCredentials: source.withCredentials
  33063. });
  33064. var cachedChunks = [];
  33065. var fullRequestXhrId = networkManager.requestFull({
  33066. onHeadersReceived: function onHeadersReceived() {
  33067. if (disableRange) {
  33068. return;
  33069. }
  33070. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  33071. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  33072. return;
  33073. }
  33074. var contentEncoding =
  33075. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  33076. if (contentEncoding !== 'identity') {
  33077. return;
  33078. }
  33079. var length = fullRequestXhr.getResponseHeader('Content-Length');
  33080. length = parseInt(length, 10);
  33081. if (!isInt(length)) {
  33082. return;
  33083. }
  33084. source.length = length;
  33085. if (length <= 2 * source.rangeChunkSize) {
  33086. // The file size is smaller than the size of two chunks, so it does
  33087. // not make any sense to abort the request and retry with a range
  33088. // request.
  33089. return;
  33090. }
  33091. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  33092. // We can continue fetching when progressive loading is enabled,
  33093. // and we don't need the autoFetch feature.
  33094. source.disableAutoFetch = true;
  33095. } else {
  33096. // NOTE: by cancelling the full request, and then issuing range
  33097. // requests, there will be an issue for sites where you can only
  33098. // request the pdf once. However, if this is the case, then the
  33099. // server should not be returning that it can support range
  33100. // requests.
  33101. networkManager.abortRequest(fullRequestXhrId);
  33102. }
  33103. try {
  33104. pdfManager = new NetworkPdfManager(docId, source, handler);
  33105. pdfManagerCapability.resolve(pdfManager);
  33106. } catch (ex) {
  33107. pdfManagerCapability.reject(ex);
  33108. }
  33109. cancelXHRs = null;
  33110. },
  33111. onProgressiveData: source.disableStream ? null :
  33112. function onProgressiveData(chunk) {
  33113. if (!pdfManager) {
  33114. cachedChunks.push(chunk);
  33115. return;
  33116. }
  33117. pdfManager.sendProgressiveData(chunk);
  33118. },
  33119. onDone: function onDone(args) {
  33120. if (pdfManager) {
  33121. return; // already processed
  33122. }
  33123. var pdfFile;
  33124. if (args === null) {
  33125. // TODO add some streaming manager, e.g. for unknown length files.
  33126. // The data was returned in the onProgressiveData, combining...
  33127. var pdfFileLength = 0, pos = 0;
  33128. cachedChunks.forEach(function (chunk) {
  33129. pdfFileLength += chunk.byteLength;
  33130. });
  33131. if (source.length && pdfFileLength !== source.length) {
  33132. warn('reported HTTP length is different from actual');
  33133. }
  33134. var pdfFileArray = new Uint8Array(pdfFileLength);
  33135. cachedChunks.forEach(function (chunk) {
  33136. pdfFileArray.set(new Uint8Array(chunk), pos);
  33137. pos += chunk.byteLength;
  33138. });
  33139. pdfFile = pdfFileArray.buffer;
  33140. } else {
  33141. pdfFile = args.chunk;
  33142. }
  33143. // the data is array, instantiating directly from it
  33144. try {
  33145. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  33146. pdfManagerCapability.resolve(pdfManager);
  33147. } catch (ex) {
  33148. pdfManagerCapability.reject(ex);
  33149. }
  33150. cancelXHRs = null;
  33151. },
  33152. onError: function onError(status) {
  33153. var exception;
  33154. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  33155. exception = new MissingPDFException('Missing PDF "' +
  33156. source.url + '".');
  33157. handler.send('MissingPDF', exception);
  33158. } else {
  33159. exception = new UnexpectedResponseException(
  33160. 'Unexpected server response (' + status +
  33161. ') while retrieving PDF "' + source.url + '".', status);
  33162. handler.send('UnexpectedResponse', exception);
  33163. }
  33164. cancelXHRs = null;
  33165. },
  33166. onProgress: function onProgress(evt) {
  33167. handler.send('DocProgress', {
  33168. loaded: evt.loaded,
  33169. total: evt.lengthComputable ? evt.total : source.length
  33170. });
  33171. }
  33172. });
  33173. cancelXHRs = function () {
  33174. networkManager.abortRequest(fullRequestXhrId);
  33175. };
  33176. return pdfManagerCapability.promise;
  33177. }
  33178. var setupDoc = function(data) {
  33179. var onSuccess = function(doc) {
  33180. ensureNotTerminated();
  33181. handler.send('GetDoc', { pdfInfo: doc });
  33182. };
  33183. var onFailure = function(e) {
  33184. if (e instanceof PasswordException) {
  33185. if (e.code === PasswordResponses.NEED_PASSWORD) {
  33186. handler.send('NeedPassword', e);
  33187. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  33188. handler.send('IncorrectPassword', e);
  33189. }
  33190. } else if (e instanceof InvalidPDFException) {
  33191. handler.send('InvalidPDF', e);
  33192. } else if (e instanceof MissingPDFException) {
  33193. handler.send('MissingPDF', e);
  33194. } else if (e instanceof UnexpectedResponseException) {
  33195. handler.send('UnexpectedResponse', e);
  33196. } else {
  33197. handler.send('UnknownError',
  33198. new UnknownErrorException(e.message, e.toString()));
  33199. }
  33200. };
  33201. ensureNotTerminated();
  33202. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  33203. -1 : data.maxImageSize;
  33204. PDFJS.disableFontFace = data.disableFontFace;
  33205. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  33206. PDFJS.verbosity = data.verbosity;
  33207. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  33208. null : data.cMapUrl;
  33209. PDFJS.cMapPacked = data.cMapPacked === true;
  33210. getPdfManager(data).then(function (newPdfManager) {
  33211. if (terminated) {
  33212. // We were in a process of setting up the manager, but it got
  33213. // terminated in the middle.
  33214. newPdfManager.terminate();
  33215. throw new Error('Worker was terminated');
  33216. }
  33217. pdfManager = newPdfManager;
  33218. handler.send('PDFManagerReady', null);
  33219. pdfManager.onLoadedStream().then(function(stream) {
  33220. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  33221. });
  33222. }).then(function pdfManagerReady() {
  33223. ensureNotTerminated();
  33224. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  33225. ensureNotTerminated();
  33226. // Try again with recoveryMode == true
  33227. if (!(ex instanceof XRefParseException)) {
  33228. if (ex instanceof PasswordException) {
  33229. // after password exception prepare to receive a new password
  33230. // to repeat loading
  33231. pdfManager.passwordChanged().then(pdfManagerReady);
  33232. }
  33233. onFailure(ex);
  33234. return;
  33235. }
  33236. pdfManager.requestLoadedStream();
  33237. pdfManager.onLoadedStream().then(function() {
  33238. ensureNotTerminated();
  33239. loadDocument(true).then(onSuccess, onFailure);
  33240. });
  33241. }, onFailure);
  33242. }, onFailure);
  33243. };
  33244. handler.on('GetPage', function wphSetupGetPage(data) {
  33245. return pdfManager.getPage(data.pageIndex).then(function(page) {
  33246. var rotatePromise = pdfManager.ensure(page, 'rotate');
  33247. var refPromise = pdfManager.ensure(page, 'ref');
  33248. var viewPromise = pdfManager.ensure(page, 'view');
  33249. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  33250. function(results) {
  33251. return {
  33252. rotate: results[0],
  33253. ref: results[1],
  33254. view: results[2]
  33255. };
  33256. });
  33257. });
  33258. });
  33259. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  33260. var ref = new Ref(data.ref.num, data.ref.gen);
  33261. var catalog = pdfManager.pdfDocument.catalog;
  33262. return catalog.getPageIndex(ref);
  33263. });
  33264. handler.on('GetDestinations',
  33265. function wphSetupGetDestinations(data) {
  33266. return pdfManager.ensureCatalog('destinations');
  33267. }
  33268. );
  33269. handler.on('GetDestination',
  33270. function wphSetupGetDestination(data) {
  33271. return pdfManager.ensureCatalog('getDestination', [data.id]);
  33272. }
  33273. );
  33274. handler.on('GetAttachments',
  33275. function wphSetupGetAttachments(data) {
  33276. return pdfManager.ensureCatalog('attachments');
  33277. }
  33278. );
  33279. handler.on('GetJavaScript',
  33280. function wphSetupGetJavaScript(data) {
  33281. return pdfManager.ensureCatalog('javaScript');
  33282. }
  33283. );
  33284. handler.on('GetOutline',
  33285. function wphSetupGetOutline(data) {
  33286. return pdfManager.ensureCatalog('documentOutline');
  33287. }
  33288. );
  33289. handler.on('GetMetadata',
  33290. function wphSetupGetMetadata(data) {
  33291. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  33292. pdfManager.ensureCatalog('metadata')]);
  33293. }
  33294. );
  33295. handler.on('GetData', function wphSetupGetData(data) {
  33296. pdfManager.requestLoadedStream();
  33297. return pdfManager.onLoadedStream().then(function(stream) {
  33298. return stream.bytes;
  33299. });
  33300. });
  33301. handler.on('GetStats',
  33302. function wphSetupGetStats(data) {
  33303. return pdfManager.pdfDocument.xref.stats;
  33304. }
  33305. );
  33306. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  33307. pdfManager.updatePassword(data);
  33308. });
  33309. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  33310. return pdfManager.getPage(data.pageIndex).then(function(page) {
  33311. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  33312. });
  33313. });
  33314. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  33315. var pageIndex = data.pageIndex;
  33316. pdfManager.getPage(pageIndex).then(function(page) {
  33317. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  33318. startWorkerTask(task);
  33319. var pageNum = pageIndex + 1;
  33320. var start = Date.now();
  33321. // Pre compile the pdf page and fetch the fonts/images.
  33322. page.getOperatorList(handler, task, data.intent).then(
  33323. function(operatorList) {
  33324. finishWorkerTask(task);
  33325. info('page=' + pageNum + ' - getOperatorList: time=' +
  33326. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  33327. }, function(e) {
  33328. finishWorkerTask(task);
  33329. if (task.terminated) {
  33330. return; // ignoring errors from the terminated thread
  33331. }
  33332. // For compatibility with older behavior, generating unknown
  33333. // unsupported feature notification on errors.
  33334. handler.send('UnsupportedFeature',
  33335. {featureId: UNSUPPORTED_FEATURES.unknown});
  33336. var minimumStackMessage =
  33337. 'worker.js: while trying to getPage() and getOperatorList()';
  33338. var wrappedException;
  33339. // Turn the error into an obj that can be serialized
  33340. if (typeof e === 'string') {
  33341. wrappedException = {
  33342. message: e,
  33343. stack: minimumStackMessage
  33344. };
  33345. } else if (typeof e === 'object') {
  33346. wrappedException = {
  33347. message: e.message || e.toString(),
  33348. stack: e.stack || minimumStackMessage
  33349. };
  33350. } else {
  33351. wrappedException = {
  33352. message: 'Unknown exception type: ' + (typeof e),
  33353. stack: minimumStackMessage
  33354. };
  33355. }
  33356. handler.send('PageError', {
  33357. pageNum: pageNum,
  33358. error: wrappedException,
  33359. intent: data.intent
  33360. });
  33361. });
  33362. });
  33363. }, this);
  33364. handler.on('GetTextContent', function wphExtractText(data) {
  33365. var pageIndex = data.pageIndex;
  33366. var normalizeWhitespace = data.normalizeWhitespace;
  33367. return pdfManager.getPage(pageIndex).then(function(page) {
  33368. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  33369. startWorkerTask(task);
  33370. var pageNum = pageIndex + 1;
  33371. var start = Date.now();
  33372. return page.extractTextContent(task, normalizeWhitespace).then(
  33373. function(textContent) {
  33374. finishWorkerTask(task);
  33375. info('text indexing: page=' + pageNum + ' - time=' +
  33376. (Date.now() - start) + 'ms');
  33377. return textContent;
  33378. }, function (reason) {
  33379. finishWorkerTask(task);
  33380. if (task.terminated) {
  33381. return; // ignoring errors from the terminated thread
  33382. }
  33383. throw reason;
  33384. });
  33385. });
  33386. });
  33387. handler.on('Cleanup', function wphCleanup(data) {
  33388. return pdfManager.cleanup();
  33389. });
  33390. handler.on('Terminate', function wphTerminate(data) {
  33391. terminated = true;
  33392. if (pdfManager) {
  33393. pdfManager.terminate();
  33394. pdfManager = null;
  33395. }
  33396. if (cancelXHRs) {
  33397. cancelXHRs();
  33398. }
  33399. var waitOn = [];
  33400. WorkerTasks.forEach(function (task) {
  33401. waitOn.push(task.finished);
  33402. task.terminate();
  33403. });
  33404. return Promise.all(waitOn).then(function () {
  33405. // Notice that even if we destroying handler, resolved response promise
  33406. // must be sent back.
  33407. handler.destroy();
  33408. handler = null;
  33409. });
  33410. });
  33411. handler.on('Ready', function wphReady(data) {
  33412. setupDoc(docParams);
  33413. docParams = null; // we don't need docParams anymore -- saving memory.
  33414. });
  33415. return workerHandlerName;
  33416. }
  33417. };
  33418. var consoleTimer = {};
  33419. var workerConsole = {
  33420. log: function log() {
  33421. var args = Array.prototype.slice.call(arguments);
  33422. globalScope.postMessage({
  33423. targetName: 'main',
  33424. action: 'console_log',
  33425. data: args
  33426. });
  33427. },
  33428. error: function error() {
  33429. var args = Array.prototype.slice.call(arguments);
  33430. globalScope.postMessage({
  33431. targetName: 'main',
  33432. action: 'console_error',
  33433. data: args
  33434. });
  33435. throw 'pdf.js execution error';
  33436. },
  33437. time: function time(name) {
  33438. consoleTimer[name] = Date.now();
  33439. },
  33440. timeEnd: function timeEnd(name) {
  33441. var time = consoleTimer[name];
  33442. if (!time) {
  33443. error('Unknown timer name ' + name);
  33444. }
  33445. this.log('Timer:', name, Date.now() - time);
  33446. }
  33447. };
  33448. // Worker thread?
  33449. if (typeof window === 'undefined') {
  33450. if (!('console' in globalScope)) {
  33451. globalScope.console = workerConsole;
  33452. }
  33453. var handler = new MessageHandler('worker', 'main', this);
  33454. WorkerMessageHandler.setup(handler, this);
  33455. }
  33456. /* This class implements the QM Coder decoding as defined in
  33457. * JPEG 2000 Part I Final Committee Draft Version 1.0
  33458. * Annex C.3 Arithmetic decoding procedure
  33459. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  33460. *
  33461. * The arithmetic decoder is used in conjunction with context models to decode
  33462. * JPEG2000 and JBIG2 streams.
  33463. */
  33464. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  33465. // Table C-2
  33466. var QeTable = [
  33467. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  33468. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  33469. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  33470. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  33471. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  33472. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  33473. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  33474. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  33475. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  33476. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  33477. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  33478. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  33479. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  33480. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  33481. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  33482. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  33483. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  33484. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  33485. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  33486. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  33487. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  33488. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  33489. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  33490. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  33491. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  33492. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  33493. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  33494. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  33495. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  33496. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  33497. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  33498. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  33499. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  33500. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  33501. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  33502. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  33503. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  33504. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  33505. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  33506. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  33507. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  33508. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  33509. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  33510. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  33511. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  33512. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  33513. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  33514. ];
  33515. // C.3.5 Initialisation of the decoder (INITDEC)
  33516. function ArithmeticDecoder(data, start, end) {
  33517. this.data = data;
  33518. this.bp = start;
  33519. this.dataEnd = end;
  33520. this.chigh = data[start];
  33521. this.clow = 0;
  33522. this.byteIn();
  33523. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  33524. this.clow = (this.clow << 7) & 0xFFFF;
  33525. this.ct -= 7;
  33526. this.a = 0x8000;
  33527. }
  33528. ArithmeticDecoder.prototype = {
  33529. // C.3.4 Compressed data input (BYTEIN)
  33530. byteIn: function ArithmeticDecoder_byteIn() {
  33531. var data = this.data;
  33532. var bp = this.bp;
  33533. if (data[bp] === 0xFF) {
  33534. var b1 = data[bp + 1];
  33535. if (b1 > 0x8F) {
  33536. this.clow += 0xFF00;
  33537. this.ct = 8;
  33538. } else {
  33539. bp++;
  33540. this.clow += (data[bp] << 9);
  33541. this.ct = 7;
  33542. this.bp = bp;
  33543. }
  33544. } else {
  33545. bp++;
  33546. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  33547. this.ct = 8;
  33548. this.bp = bp;
  33549. }
  33550. if (this.clow > 0xFFFF) {
  33551. this.chigh += (this.clow >> 16);
  33552. this.clow &= 0xFFFF;
  33553. }
  33554. },
  33555. // C.3.2 Decoding a decision (DECODE)
  33556. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  33557. // contexts are packed into 1 byte:
  33558. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  33559. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  33560. var qeTableIcx = QeTable[cx_index];
  33561. var qeIcx = qeTableIcx.qe;
  33562. var d;
  33563. var a = this.a - qeIcx;
  33564. if (this.chigh < qeIcx) {
  33565. // exchangeLps
  33566. if (a < qeIcx) {
  33567. a = qeIcx;
  33568. d = cx_mps;
  33569. cx_index = qeTableIcx.nmps;
  33570. } else {
  33571. a = qeIcx;
  33572. d = 1 ^ cx_mps;
  33573. if (qeTableIcx.switchFlag === 1) {
  33574. cx_mps = d;
  33575. }
  33576. cx_index = qeTableIcx.nlps;
  33577. }
  33578. } else {
  33579. this.chigh -= qeIcx;
  33580. if ((a & 0x8000) !== 0) {
  33581. this.a = a;
  33582. return cx_mps;
  33583. }
  33584. // exchangeMps
  33585. if (a < qeIcx) {
  33586. d = 1 ^ cx_mps;
  33587. if (qeTableIcx.switchFlag === 1) {
  33588. cx_mps = d;
  33589. }
  33590. cx_index = qeTableIcx.nlps;
  33591. } else {
  33592. d = cx_mps;
  33593. cx_index = qeTableIcx.nmps;
  33594. }
  33595. }
  33596. // C.3.3 renormD;
  33597. do {
  33598. if (this.ct === 0) {
  33599. this.byteIn();
  33600. }
  33601. a <<= 1;
  33602. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  33603. this.clow = (this.clow << 1) & 0xFFFF;
  33604. this.ct--;
  33605. } while ((a & 0x8000) === 0);
  33606. this.a = a;
  33607. contexts[pos] = cx_index << 1 | cx_mps;
  33608. return d;
  33609. }
  33610. };
  33611. return ArithmeticDecoder;
  33612. })();
  33613. var JpegImage = (function jpegImage() {
  33614. var dctZigZag = new Uint8Array([
  33615. 0,
  33616. 1, 8,
  33617. 16, 9, 2,
  33618. 3, 10, 17, 24,
  33619. 32, 25, 18, 11, 4,
  33620. 5, 12, 19, 26, 33, 40,
  33621. 48, 41, 34, 27, 20, 13, 6,
  33622. 7, 14, 21, 28, 35, 42, 49, 56,
  33623. 57, 50, 43, 36, 29, 22, 15,
  33624. 23, 30, 37, 44, 51, 58,
  33625. 59, 52, 45, 38, 31,
  33626. 39, 46, 53, 60,
  33627. 61, 54, 47,
  33628. 55, 62,
  33629. 63
  33630. ]);
  33631. var dctCos1 = 4017; // cos(pi/16)
  33632. var dctSin1 = 799; // sin(pi/16)
  33633. var dctCos3 = 3406; // cos(3*pi/16)
  33634. var dctSin3 = 2276; // sin(3*pi/16)
  33635. var dctCos6 = 1567; // cos(6*pi/16)
  33636. var dctSin6 = 3784; // sin(6*pi/16)
  33637. var dctSqrt2 = 5793; // sqrt(2)
  33638. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  33639. function constructor() {
  33640. }
  33641. function buildHuffmanTable(codeLengths, values) {
  33642. var k = 0, code = [], i, j, length = 16;
  33643. while (length > 0 && !codeLengths[length - 1]) {
  33644. length--;
  33645. }
  33646. code.push({children: [], index: 0});
  33647. var p = code[0], q;
  33648. for (i = 0; i < length; i++) {
  33649. for (j = 0; j < codeLengths[i]; j++) {
  33650. p = code.pop();
  33651. p.children[p.index] = values[k];
  33652. while (p.index > 0) {
  33653. p = code.pop();
  33654. }
  33655. p.index++;
  33656. code.push(p);
  33657. while (code.length <= i) {
  33658. code.push(q = {children: [], index: 0});
  33659. p.children[p.index] = q.children;
  33660. p = q;
  33661. }
  33662. k++;
  33663. }
  33664. if (i + 1 < length) {
  33665. // p here points to last code
  33666. code.push(q = {children: [], index: 0});
  33667. p.children[p.index] = q.children;
  33668. p = q;
  33669. }
  33670. }
  33671. return code[0].children;
  33672. }
  33673. function getBlockBufferOffset(component, row, col) {
  33674. return 64 * ((component.blocksPerLine + 1) * row + col);
  33675. }
  33676. function decodeScan(data, offset, frame, components, resetInterval,
  33677. spectralStart, spectralEnd, successivePrev, successive) {
  33678. var precision = frame.precision;
  33679. var samplesPerLine = frame.samplesPerLine;
  33680. var scanLines = frame.scanLines;
  33681. var mcusPerLine = frame.mcusPerLine;
  33682. var progressive = frame.progressive;
  33683. var maxH = frame.maxH, maxV = frame.maxV;
  33684. var startOffset = offset, bitsData = 0, bitsCount = 0;
  33685. function readBit() {
  33686. if (bitsCount > 0) {
  33687. bitsCount--;
  33688. return (bitsData >> bitsCount) & 1;
  33689. }
  33690. bitsData = data[offset++];
  33691. if (bitsData === 0xFF) {
  33692. var nextByte = data[offset++];
  33693. if (nextByte) {
  33694. throw 'unexpected marker: ' +
  33695. ((bitsData << 8) | nextByte).toString(16);
  33696. }
  33697. // unstuff 0
  33698. }
  33699. bitsCount = 7;
  33700. return bitsData >>> 7;
  33701. }
  33702. function decodeHuffman(tree) {
  33703. var node = tree;
  33704. while (true) {
  33705. node = node[readBit()];
  33706. if (typeof node === 'number') {
  33707. return node;
  33708. }
  33709. if (typeof node !== 'object') {
  33710. throw 'invalid huffman sequence';
  33711. }
  33712. }
  33713. }
  33714. function receive(length) {
  33715. var n = 0;
  33716. while (length > 0) {
  33717. n = (n << 1) | readBit();
  33718. length--;
  33719. }
  33720. return n;
  33721. }
  33722. function receiveAndExtend(length) {
  33723. if (length === 1) {
  33724. return readBit() === 1 ? 1 : -1;
  33725. }
  33726. var n = receive(length);
  33727. if (n >= 1 << (length - 1)) {
  33728. return n;
  33729. }
  33730. return n + (-1 << length) + 1;
  33731. }
  33732. function decodeBaseline(component, offset) {
  33733. var t = decodeHuffman(component.huffmanTableDC);
  33734. var diff = t === 0 ? 0 : receiveAndExtend(t);
  33735. component.blockData[offset] = (component.pred += diff);
  33736. var k = 1;
  33737. while (k < 64) {
  33738. var rs = decodeHuffman(component.huffmanTableAC);
  33739. var s = rs & 15, r = rs >> 4;
  33740. if (s === 0) {
  33741. if (r < 15) {
  33742. break;
  33743. }
  33744. k += 16;
  33745. continue;
  33746. }
  33747. k += r;
  33748. var z = dctZigZag[k];
  33749. component.blockData[offset + z] = receiveAndExtend(s);
  33750. k++;
  33751. }
  33752. }
  33753. function decodeDCFirst(component, offset) {
  33754. var t = decodeHuffman(component.huffmanTableDC);
  33755. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  33756. component.blockData[offset] = (component.pred += diff);
  33757. }
  33758. function decodeDCSuccessive(component, offset) {
  33759. component.blockData[offset] |= readBit() << successive;
  33760. }
  33761. var eobrun = 0;
  33762. function decodeACFirst(component, offset) {
  33763. if (eobrun > 0) {
  33764. eobrun--;
  33765. return;
  33766. }
  33767. var k = spectralStart, e = spectralEnd;
  33768. while (k <= e) {
  33769. var rs = decodeHuffman(component.huffmanTableAC);
  33770. var s = rs & 15, r = rs >> 4;
  33771. if (s === 0) {
  33772. if (r < 15) {
  33773. eobrun = receive(r) + (1 << r) - 1;
  33774. break;
  33775. }
  33776. k += 16;
  33777. continue;
  33778. }
  33779. k += r;
  33780. var z = dctZigZag[k];
  33781. component.blockData[offset + z] =
  33782. receiveAndExtend(s) * (1 << successive);
  33783. k++;
  33784. }
  33785. }
  33786. var successiveACState = 0, successiveACNextValue;
  33787. function decodeACSuccessive(component, offset) {
  33788. var k = spectralStart;
  33789. var e = spectralEnd;
  33790. var r = 0;
  33791. var s;
  33792. var rs;
  33793. while (k <= e) {
  33794. var z = dctZigZag[k];
  33795. switch (successiveACState) {
  33796. case 0: // initial state
  33797. rs = decodeHuffman(component.huffmanTableAC);
  33798. s = rs & 15;
  33799. r = rs >> 4;
  33800. if (s === 0) {
  33801. if (r < 15) {
  33802. eobrun = receive(r) + (1 << r);
  33803. successiveACState = 4;
  33804. } else {
  33805. r = 16;
  33806. successiveACState = 1;
  33807. }
  33808. } else {
  33809. if (s !== 1) {
  33810. throw 'invalid ACn encoding';
  33811. }
  33812. successiveACNextValue = receiveAndExtend(s);
  33813. successiveACState = r ? 2 : 3;
  33814. }
  33815. continue;
  33816. case 1: // skipping r zero items
  33817. case 2:
  33818. if (component.blockData[offset + z]) {
  33819. component.blockData[offset + z] += (readBit() << successive);
  33820. } else {
  33821. r--;
  33822. if (r === 0) {
  33823. successiveACState = successiveACState === 2 ? 3 : 0;
  33824. }
  33825. }
  33826. break;
  33827. case 3: // set value for a zero item
  33828. if (component.blockData[offset + z]) {
  33829. component.blockData[offset + z] += (readBit() << successive);
  33830. } else {
  33831. component.blockData[offset + z] =
  33832. successiveACNextValue << successive;
  33833. successiveACState = 0;
  33834. }
  33835. break;
  33836. case 4: // eob
  33837. if (component.blockData[offset + z]) {
  33838. component.blockData[offset + z] += (readBit() << successive);
  33839. }
  33840. break;
  33841. }
  33842. k++;
  33843. }
  33844. if (successiveACState === 4) {
  33845. eobrun--;
  33846. if (eobrun === 0) {
  33847. successiveACState = 0;
  33848. }
  33849. }
  33850. }
  33851. function decodeMcu(component, decode, mcu, row, col) {
  33852. var mcuRow = (mcu / mcusPerLine) | 0;
  33853. var mcuCol = mcu % mcusPerLine;
  33854. var blockRow = mcuRow * component.v + row;
  33855. var blockCol = mcuCol * component.h + col;
  33856. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33857. decode(component, offset);
  33858. }
  33859. function decodeBlock(component, decode, mcu) {
  33860. var blockRow = (mcu / component.blocksPerLine) | 0;
  33861. var blockCol = mcu % component.blocksPerLine;
  33862. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33863. decode(component, offset);
  33864. }
  33865. var componentsLength = components.length;
  33866. var component, i, j, k, n;
  33867. var decodeFn;
  33868. if (progressive) {
  33869. if (spectralStart === 0) {
  33870. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  33871. } else {
  33872. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  33873. }
  33874. } else {
  33875. decodeFn = decodeBaseline;
  33876. }
  33877. var mcu = 0, marker;
  33878. var mcuExpected;
  33879. if (componentsLength === 1) {
  33880. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  33881. } else {
  33882. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  33883. }
  33884. if (!resetInterval) {
  33885. resetInterval = mcuExpected;
  33886. }
  33887. var h, v;
  33888. while (mcu < mcuExpected) {
  33889. // reset interval stuff
  33890. for (i = 0; i < componentsLength; i++) {
  33891. components[i].pred = 0;
  33892. }
  33893. eobrun = 0;
  33894. if (componentsLength === 1) {
  33895. component = components[0];
  33896. for (n = 0; n < resetInterval; n++) {
  33897. decodeBlock(component, decodeFn, mcu);
  33898. mcu++;
  33899. }
  33900. } else {
  33901. for (n = 0; n < resetInterval; n++) {
  33902. for (i = 0; i < componentsLength; i++) {
  33903. component = components[i];
  33904. h = component.h;
  33905. v = component.v;
  33906. for (j = 0; j < v; j++) {
  33907. for (k = 0; k < h; k++) {
  33908. decodeMcu(component, decodeFn, mcu, j, k);
  33909. }
  33910. }
  33911. }
  33912. mcu++;
  33913. }
  33914. }
  33915. // find marker
  33916. bitsCount = 0;
  33917. marker = (data[offset] << 8) | data[offset + 1];
  33918. if (marker <= 0xFF00) {
  33919. throw 'marker was not found';
  33920. }
  33921. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  33922. offset += 2;
  33923. } else {
  33924. break;
  33925. }
  33926. }
  33927. return offset - startOffset;
  33928. }
  33929. // A port of poppler's IDCT method which in turn is taken from:
  33930. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  33931. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  33932. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  33933. // 988-991.
  33934. function quantizeAndInverse(component, blockBufferOffset, p) {
  33935. var qt = component.quantizationTable, blockData = component.blockData;
  33936. var v0, v1, v2, v3, v4, v5, v6, v7;
  33937. var p0, p1, p2, p3, p4, p5, p6, p7;
  33938. var t;
  33939. // inverse DCT on rows
  33940. for (var row = 0; row < 64; row += 8) {
  33941. // gather block data
  33942. p0 = blockData[blockBufferOffset + row];
  33943. p1 = blockData[blockBufferOffset + row + 1];
  33944. p2 = blockData[blockBufferOffset + row + 2];
  33945. p3 = blockData[blockBufferOffset + row + 3];
  33946. p4 = blockData[blockBufferOffset + row + 4];
  33947. p5 = blockData[blockBufferOffset + row + 5];
  33948. p6 = blockData[blockBufferOffset + row + 6];
  33949. p7 = blockData[blockBufferOffset + row + 7];
  33950. // dequant p0
  33951. p0 *= qt[row];
  33952. // check for all-zero AC coefficients
  33953. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  33954. t = (dctSqrt2 * p0 + 512) >> 10;
  33955. p[row] = t;
  33956. p[row + 1] = t;
  33957. p[row + 2] = t;
  33958. p[row + 3] = t;
  33959. p[row + 4] = t;
  33960. p[row + 5] = t;
  33961. p[row + 6] = t;
  33962. p[row + 7] = t;
  33963. continue;
  33964. }
  33965. // dequant p1 ... p7
  33966. p1 *= qt[row + 1];
  33967. p2 *= qt[row + 2];
  33968. p3 *= qt[row + 3];
  33969. p4 *= qt[row + 4];
  33970. p5 *= qt[row + 5];
  33971. p6 *= qt[row + 6];
  33972. p7 *= qt[row + 7];
  33973. // stage 4
  33974. v0 = (dctSqrt2 * p0 + 128) >> 8;
  33975. v1 = (dctSqrt2 * p4 + 128) >> 8;
  33976. v2 = p2;
  33977. v3 = p6;
  33978. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  33979. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  33980. v5 = p3 << 4;
  33981. v6 = p5 << 4;
  33982. // stage 3
  33983. v0 = (v0 + v1 + 1) >> 1;
  33984. v1 = v0 - v1;
  33985. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  33986. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  33987. v3 = t;
  33988. v4 = (v4 + v6 + 1) >> 1;
  33989. v6 = v4 - v6;
  33990. v7 = (v7 + v5 + 1) >> 1;
  33991. v5 = v7 - v5;
  33992. // stage 2
  33993. v0 = (v0 + v3 + 1) >> 1;
  33994. v3 = v0 - v3;
  33995. v1 = (v1 + v2 + 1) >> 1;
  33996. v2 = v1 - v2;
  33997. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33998. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33999. v7 = t;
  34000. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  34001. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  34002. v6 = t;
  34003. // stage 1
  34004. p[row] = v0 + v7;
  34005. p[row + 7] = v0 - v7;
  34006. p[row + 1] = v1 + v6;
  34007. p[row + 6] = v1 - v6;
  34008. p[row + 2] = v2 + v5;
  34009. p[row + 5] = v2 - v5;
  34010. p[row + 3] = v3 + v4;
  34011. p[row + 4] = v3 - v4;
  34012. }
  34013. // inverse DCT on columns
  34014. for (var col = 0; col < 8; ++col) {
  34015. p0 = p[col];
  34016. p1 = p[col + 8];
  34017. p2 = p[col + 16];
  34018. p3 = p[col + 24];
  34019. p4 = p[col + 32];
  34020. p5 = p[col + 40];
  34021. p6 = p[col + 48];
  34022. p7 = p[col + 56];
  34023. // check for all-zero AC coefficients
  34024. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  34025. t = (dctSqrt2 * p0 + 8192) >> 14;
  34026. // convert to 8 bit
  34027. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  34028. blockData[blockBufferOffset + col] = t;
  34029. blockData[blockBufferOffset + col + 8] = t;
  34030. blockData[blockBufferOffset + col + 16] = t;
  34031. blockData[blockBufferOffset + col + 24] = t;
  34032. blockData[blockBufferOffset + col + 32] = t;
  34033. blockData[blockBufferOffset + col + 40] = t;
  34034. blockData[blockBufferOffset + col + 48] = t;
  34035. blockData[blockBufferOffset + col + 56] = t;
  34036. continue;
  34037. }
  34038. // stage 4
  34039. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  34040. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  34041. v2 = p2;
  34042. v3 = p6;
  34043. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  34044. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  34045. v5 = p3;
  34046. v6 = p5;
  34047. // stage 3
  34048. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  34049. // converting to UInt8 range later.
  34050. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  34051. v1 = v0 - v1;
  34052. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  34053. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  34054. v3 = t;
  34055. v4 = (v4 + v6 + 1) >> 1;
  34056. v6 = v4 - v6;
  34057. v7 = (v7 + v5 + 1) >> 1;
  34058. v5 = v7 - v5;
  34059. // stage 2
  34060. v0 = (v0 + v3 + 1) >> 1;
  34061. v3 = v0 - v3;
  34062. v1 = (v1 + v2 + 1) >> 1;
  34063. v2 = v1 - v2;
  34064. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  34065. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  34066. v7 = t;
  34067. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  34068. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  34069. v6 = t;
  34070. // stage 1
  34071. p0 = v0 + v7;
  34072. p7 = v0 - v7;
  34073. p1 = v1 + v6;
  34074. p6 = v1 - v6;
  34075. p2 = v2 + v5;
  34076. p5 = v2 - v5;
  34077. p3 = v3 + v4;
  34078. p4 = v3 - v4;
  34079. // convert to 8-bit integers
  34080. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  34081. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  34082. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  34083. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  34084. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  34085. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  34086. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  34087. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  34088. // store block data
  34089. blockData[blockBufferOffset + col] = p0;
  34090. blockData[blockBufferOffset + col + 8] = p1;
  34091. blockData[blockBufferOffset + col + 16] = p2;
  34092. blockData[blockBufferOffset + col + 24] = p3;
  34093. blockData[blockBufferOffset + col + 32] = p4;
  34094. blockData[blockBufferOffset + col + 40] = p5;
  34095. blockData[blockBufferOffset + col + 48] = p6;
  34096. blockData[blockBufferOffset + col + 56] = p7;
  34097. }
  34098. }
  34099. function buildComponentData(frame, component) {
  34100. var blocksPerLine = component.blocksPerLine;
  34101. var blocksPerColumn = component.blocksPerColumn;
  34102. var computationBuffer = new Int16Array(64);
  34103. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  34104. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  34105. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  34106. quantizeAndInverse(component, offset, computationBuffer);
  34107. }
  34108. }
  34109. return component.blockData;
  34110. }
  34111. function clamp0to255(a) {
  34112. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  34113. }
  34114. constructor.prototype = {
  34115. parse: function parse(data) {
  34116. function readUint16() {
  34117. var value = (data[offset] << 8) | data[offset + 1];
  34118. offset += 2;
  34119. return value;
  34120. }
  34121. function readDataBlock() {
  34122. var length = readUint16();
  34123. var array = data.subarray(offset, offset + length - 2);
  34124. offset += array.length;
  34125. return array;
  34126. }
  34127. function prepareComponents(frame) {
  34128. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  34129. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  34130. for (var i = 0; i < frame.components.length; i++) {
  34131. component = frame.components[i];
  34132. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  34133. component.h / frame.maxH);
  34134. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  34135. component.v / frame.maxV);
  34136. var blocksPerLineForMcu = mcusPerLine * component.h;
  34137. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  34138. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  34139. (blocksPerLineForMcu + 1);
  34140. component.blockData = new Int16Array(blocksBufferSize);
  34141. component.blocksPerLine = blocksPerLine;
  34142. component.blocksPerColumn = blocksPerColumn;
  34143. }
  34144. frame.mcusPerLine = mcusPerLine;
  34145. frame.mcusPerColumn = mcusPerColumn;
  34146. }
  34147. var offset = 0, length = data.length;
  34148. var jfif = null;
  34149. var adobe = null;
  34150. var pixels = null;
  34151. var frame, resetInterval;
  34152. var quantizationTables = [];
  34153. var huffmanTablesAC = [], huffmanTablesDC = [];
  34154. var fileMarker = readUint16();
  34155. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  34156. throw 'SOI not found';
  34157. }
  34158. fileMarker = readUint16();
  34159. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  34160. var i, j, l;
  34161. switch(fileMarker) {
  34162. case 0xFFE0: // APP0 (Application Specific)
  34163. case 0xFFE1: // APP1
  34164. case 0xFFE2: // APP2
  34165. case 0xFFE3: // APP3
  34166. case 0xFFE4: // APP4
  34167. case 0xFFE5: // APP5
  34168. case 0xFFE6: // APP6
  34169. case 0xFFE7: // APP7
  34170. case 0xFFE8: // APP8
  34171. case 0xFFE9: // APP9
  34172. case 0xFFEA: // APP10
  34173. case 0xFFEB: // APP11
  34174. case 0xFFEC: // APP12
  34175. case 0xFFED: // APP13
  34176. case 0xFFEE: // APP14
  34177. case 0xFFEF: // APP15
  34178. case 0xFFFE: // COM (Comment)
  34179. var appData = readDataBlock();
  34180. if (fileMarker === 0xFFE0) {
  34181. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  34182. appData[2] === 0x49 && appData[3] === 0x46 &&
  34183. appData[4] === 0) { // 'JFIF\x00'
  34184. jfif = {
  34185. version: { major: appData[5], minor: appData[6] },
  34186. densityUnits: appData[7],
  34187. xDensity: (appData[8] << 8) | appData[9],
  34188. yDensity: (appData[10] << 8) | appData[11],
  34189. thumbWidth: appData[12],
  34190. thumbHeight: appData[13],
  34191. thumbData: appData.subarray(14, 14 +
  34192. 3 * appData[12] * appData[13])
  34193. };
  34194. }
  34195. }
  34196. // TODO APP1 - Exif
  34197. if (fileMarker === 0xFFEE) {
  34198. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  34199. appData[2] === 0x6F && appData[3] === 0x62 &&
  34200. appData[4] === 0x65) { // 'Adobe'
  34201. adobe = {
  34202. version: (appData[5] << 8) | appData[6],
  34203. flags0: (appData[7] << 8) | appData[8],
  34204. flags1: (appData[9] << 8) | appData[10],
  34205. transformCode: appData[11]
  34206. };
  34207. }
  34208. }
  34209. break;
  34210. case 0xFFDB: // DQT (Define Quantization Tables)
  34211. var quantizationTablesLength = readUint16();
  34212. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  34213. var z;
  34214. while (offset < quantizationTablesEnd) {
  34215. var quantizationTableSpec = data[offset++];
  34216. var tableData = new Uint16Array(64);
  34217. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  34218. for (j = 0; j < 64; j++) {
  34219. z = dctZigZag[j];
  34220. tableData[z] = data[offset++];
  34221. }
  34222. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  34223. for (j = 0; j < 64; j++) {
  34224. z = dctZigZag[j];
  34225. tableData[z] = readUint16();
  34226. }
  34227. } else {
  34228. throw 'DQT: invalid table spec';
  34229. }
  34230. quantizationTables[quantizationTableSpec & 15] = tableData;
  34231. }
  34232. break;
  34233. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  34234. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  34235. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  34236. if (frame) {
  34237. throw 'Only single frame JPEGs supported';
  34238. }
  34239. readUint16(); // skip data length
  34240. frame = {};
  34241. frame.extended = (fileMarker === 0xFFC1);
  34242. frame.progressive = (fileMarker === 0xFFC2);
  34243. frame.precision = data[offset++];
  34244. frame.scanLines = readUint16();
  34245. frame.samplesPerLine = readUint16();
  34246. frame.components = [];
  34247. frame.componentIds = {};
  34248. var componentsCount = data[offset++], componentId;
  34249. var maxH = 0, maxV = 0;
  34250. for (i = 0; i < componentsCount; i++) {
  34251. componentId = data[offset];
  34252. var h = data[offset + 1] >> 4;
  34253. var v = data[offset + 1] & 15;
  34254. if (maxH < h) {
  34255. maxH = h;
  34256. }
  34257. if (maxV < v) {
  34258. maxV = v;
  34259. }
  34260. var qId = data[offset + 2];
  34261. l = frame.components.push({
  34262. h: h,
  34263. v: v,
  34264. quantizationTable: quantizationTables[qId]
  34265. });
  34266. frame.componentIds[componentId] = l - 1;
  34267. offset += 3;
  34268. }
  34269. frame.maxH = maxH;
  34270. frame.maxV = maxV;
  34271. prepareComponents(frame);
  34272. break;
  34273. case 0xFFC4: // DHT (Define Huffman Tables)
  34274. var huffmanLength = readUint16();
  34275. for (i = 2; i < huffmanLength;) {
  34276. var huffmanTableSpec = data[offset++];
  34277. var codeLengths = new Uint8Array(16);
  34278. var codeLengthSum = 0;
  34279. for (j = 0; j < 16; j++, offset++) {
  34280. codeLengthSum += (codeLengths[j] = data[offset]);
  34281. }
  34282. var huffmanValues = new Uint8Array(codeLengthSum);
  34283. for (j = 0; j < codeLengthSum; j++, offset++) {
  34284. huffmanValues[j] = data[offset];
  34285. }
  34286. i += 17 + codeLengthSum;
  34287. ((huffmanTableSpec >> 4) === 0 ?
  34288. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  34289. buildHuffmanTable(codeLengths, huffmanValues);
  34290. }
  34291. break;
  34292. case 0xFFDD: // DRI (Define Restart Interval)
  34293. readUint16(); // skip data length
  34294. resetInterval = readUint16();
  34295. break;
  34296. case 0xFFDA: // SOS (Start of Scan)
  34297. var scanLength = readUint16();
  34298. var selectorsCount = data[offset++];
  34299. var components = [], component;
  34300. for (i = 0; i < selectorsCount; i++) {
  34301. var componentIndex = frame.componentIds[data[offset++]];
  34302. component = frame.components[componentIndex];
  34303. var tableSpec = data[offset++];
  34304. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  34305. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  34306. components.push(component);
  34307. }
  34308. var spectralStart = data[offset++];
  34309. var spectralEnd = data[offset++];
  34310. var successiveApproximation = data[offset++];
  34311. var processed = decodeScan(data, offset,
  34312. frame, components, resetInterval,
  34313. spectralStart, spectralEnd,
  34314. successiveApproximation >> 4, successiveApproximation & 15);
  34315. offset += processed;
  34316. break;
  34317. case 0xFFFF: // Fill bytes
  34318. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  34319. offset--;
  34320. }
  34321. break;
  34322. default:
  34323. if (data[offset - 3] === 0xFF &&
  34324. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  34325. // could be incorrect encoding -- last 0xFF byte of the previous
  34326. // block was eaten by the encoder
  34327. offset -= 3;
  34328. break;
  34329. }
  34330. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  34331. }
  34332. fileMarker = readUint16();
  34333. }
  34334. this.width = frame.samplesPerLine;
  34335. this.height = frame.scanLines;
  34336. this.jfif = jfif;
  34337. this.adobe = adobe;
  34338. this.components = [];
  34339. for (i = 0; i < frame.components.length; i++) {
  34340. component = frame.components[i];
  34341. this.components.push({
  34342. output: buildComponentData(frame, component),
  34343. scaleX: component.h / frame.maxH,
  34344. scaleY: component.v / frame.maxV,
  34345. blocksPerLine: component.blocksPerLine,
  34346. blocksPerColumn: component.blocksPerColumn
  34347. });
  34348. }
  34349. this.numComponents = this.components.length;
  34350. },
  34351. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  34352. var scaleX = this.width / width, scaleY = this.height / height;
  34353. var component, componentScaleX, componentScaleY, blocksPerScanline;
  34354. var x, y, i, j, k;
  34355. var index;
  34356. var offset = 0;
  34357. var output;
  34358. var numComponents = this.components.length;
  34359. var dataLength = width * height * numComponents;
  34360. var data = new Uint8Array(dataLength);
  34361. var xScaleBlockOffset = new Uint32Array(width);
  34362. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  34363. for (i = 0; i < numComponents; i++) {
  34364. component = this.components[i];
  34365. componentScaleX = component.scaleX * scaleX;
  34366. componentScaleY = component.scaleY * scaleY;
  34367. offset = i;
  34368. output = component.output;
  34369. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  34370. // precalculate the xScaleBlockOffset
  34371. for (x = 0; x < width; x++) {
  34372. j = 0 | (x * componentScaleX);
  34373. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  34374. }
  34375. // linearize the blocks of the component
  34376. for (y = 0; y < height; y++) {
  34377. j = 0 | (y * componentScaleY);
  34378. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  34379. for (x = 0; x < width; x++) {
  34380. data[offset] = output[index + xScaleBlockOffset[x]];
  34381. offset += numComponents;
  34382. }
  34383. }
  34384. }
  34385. // decodeTransform contains pairs of multiplier (-256..256) and additive
  34386. var transform = this.decodeTransform;
  34387. if (transform) {
  34388. for (i = 0; i < dataLength;) {
  34389. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  34390. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  34391. }
  34392. }
  34393. }
  34394. return data;
  34395. },
  34396. _isColorConversionNeeded: function isColorConversionNeeded() {
  34397. if (this.adobe && this.adobe.transformCode) {
  34398. // The adobe transform marker overrides any previous setting
  34399. return true;
  34400. } else if (this.numComponents === 3) {
  34401. return true;
  34402. } else {
  34403. return false;
  34404. }
  34405. },
  34406. _convertYccToRgb: function convertYccToRgb(data) {
  34407. var Y, Cb, Cr;
  34408. for (var i = 0, length = data.length; i < length; i += 3) {
  34409. Y = data[i ];
  34410. Cb = data[i + 1];
  34411. Cr = data[i + 2];
  34412. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  34413. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  34414. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  34415. }
  34416. return data;
  34417. },
  34418. _convertYcckToRgb: function convertYcckToRgb(data) {
  34419. var Y, Cb, Cr, k;
  34420. var offset = 0;
  34421. for (var i = 0, length = data.length; i < length; i += 4) {
  34422. Y = data[i];
  34423. Cb = data[i + 1];
  34424. Cr = data[i + 2];
  34425. k = data[i + 3];
  34426. var r = -122.67195406894 +
  34427. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  34428. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  34429. 0.154362151871126) +
  34430. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  34431. 0.00477271405408747 * k + 1.53380253221734) +
  34432. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  34433. 0.48357088451265) +
  34434. k * (-0.000336197177618394 * k + 0.484791561490776);
  34435. var g = 107.268039397724 +
  34436. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  34437. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  34438. 0.176491792462875) +
  34439. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  34440. 0.000770482631801132 * k - 0.151051492775562) +
  34441. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  34442. 0.25802910206845) +
  34443. k * (-0.000318913117588328 * k - 0.213742400323665);
  34444. var b = -20.810012546947 +
  34445. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  34446. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  34447. 0.814272968359295) +
  34448. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  34449. 0.000560833691242812 * k - 0.195152027534049) +
  34450. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  34451. 0.116935020465145) +
  34452. k * (-0.000343531996510555 * k + 0.24165260232407);
  34453. data[offset++] = clamp0to255(r);
  34454. data[offset++] = clamp0to255(g);
  34455. data[offset++] = clamp0to255(b);
  34456. }
  34457. return data;
  34458. },
  34459. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  34460. var Y, Cb, Cr;
  34461. for (var i = 0, length = data.length; i < length; i += 4) {
  34462. Y = data[i];
  34463. Cb = data[i + 1];
  34464. Cr = data[i + 2];
  34465. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  34466. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  34467. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  34468. // K in data[i + 3] is unchanged
  34469. }
  34470. return data;
  34471. },
  34472. _convertCmykToRgb: function convertCmykToRgb(data) {
  34473. var c, m, y, k;
  34474. var offset = 0;
  34475. var min = -255 * 255 * 255;
  34476. var scale = 1 / 255 / 255;
  34477. for (var i = 0, length = data.length; i < length; i += 4) {
  34478. c = data[i];
  34479. m = data[i + 1];
  34480. y = data[i + 2];
  34481. k = data[i + 3];
  34482. var r =
  34483. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  34484. 18.82290502165302 * y + 212.25662451639585 * k -
  34485. 72734.4411664936) +
  34486. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  34487. 17.873870861415444 * k - 1401.7366389350734) +
  34488. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  34489. 4465.541406466231) -
  34490. k * (21.86122147463605 * k + 48317.86113160301);
  34491. var g =
  34492. c * (8.841041422036149 * c + 60.118027045597366 * m +
  34493. 6.871425592049007 * y + 31.159100130055922 * k -
  34494. 20220.756542821975) +
  34495. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  34496. 131.35250912493976 * k - 48691.05921601825) +
  34497. y * (4.444339102852739 * y + 9.8632861493405 * k -
  34498. 6341.191035517494) -
  34499. k * (20.737325471181034 * k + 47890.15695978492);
  34500. var b =
  34501. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  34502. 30.89978309703729 * y - 0.23883238689178934 * k -
  34503. 3616.812083916688) +
  34504. m * (10.49593273432072 * m + 63.02378494754052 * y +
  34505. 50.606957656360734 * k - 28620.90484698408) +
  34506. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  34507. 49363.43385999684) -
  34508. k * (22.33816807309886 * k + 45932.16563550634);
  34509. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  34510. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  34511. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  34512. }
  34513. return data;
  34514. },
  34515. getData: function getData(width, height, forceRGBoutput) {
  34516. if (this.numComponents > 4) {
  34517. throw 'Unsupported color mode';
  34518. }
  34519. // type of data: Uint8Array(width * height * numComponents)
  34520. var data = this._getLinearizedBlockData(width, height);
  34521. if (this.numComponents === 3) {
  34522. return this._convertYccToRgb(data);
  34523. } else if (this.numComponents === 4) {
  34524. if (this._isColorConversionNeeded()) {
  34525. if (forceRGBoutput) {
  34526. return this._convertYcckToRgb(data);
  34527. } else {
  34528. return this._convertYcckToCmyk(data);
  34529. }
  34530. } else if (forceRGBoutput) {
  34531. return this._convertCmykToRgb(data);
  34532. }
  34533. }
  34534. return data;
  34535. }
  34536. };
  34537. return constructor;
  34538. })();
  34539. var JpxImage = (function JpxImageClosure() {
  34540. // Table E.1
  34541. var SubbandsGainLog2 = {
  34542. 'LL': 0,
  34543. 'LH': 1,
  34544. 'HL': 1,
  34545. 'HH': 2
  34546. };
  34547. function JpxImage() {
  34548. this.failOnCorruptedImage = false;
  34549. }
  34550. JpxImage.prototype = {
  34551. parse: function JpxImage_parse(data) {
  34552. var head = readUint16(data, 0);
  34553. // No box header, immediate start of codestream (SOC)
  34554. if (head === 0xFF4F) {
  34555. this.parseCodestream(data, 0, data.length);
  34556. return;
  34557. }
  34558. var position = 0, length = data.length;
  34559. while (position < length) {
  34560. var headerSize = 8;
  34561. var lbox = readUint32(data, position);
  34562. var tbox = readUint32(data, position + 4);
  34563. position += headerSize;
  34564. if (lbox === 1) {
  34565. // XLBox: read UInt64 according to spec.
  34566. // JavaScript's int precision of 53 bit should be sufficient here.
  34567. lbox = readUint32(data, position) * 4294967296 +
  34568. readUint32(data, position + 4);
  34569. position += 8;
  34570. headerSize += 8;
  34571. }
  34572. if (lbox === 0) {
  34573. lbox = length - position + headerSize;
  34574. }
  34575. if (lbox < headerSize) {
  34576. throw new Error('JPX Error: Invalid box field size');
  34577. }
  34578. var dataLength = lbox - headerSize;
  34579. var jumpDataLength = true;
  34580. switch (tbox) {
  34581. case 0x6A703268: // 'jp2h'
  34582. jumpDataLength = false; // parsing child boxes
  34583. break;
  34584. case 0x636F6C72: // 'colr'
  34585. // Colorspaces are not used, the CS from the PDF is used.
  34586. var method = data[position];
  34587. var precedence = data[position + 1];
  34588. var approximation = data[position + 2];
  34589. if (method === 1) {
  34590. // enumerated colorspace
  34591. var colorspace = readUint32(data, position + 3);
  34592. switch (colorspace) {
  34593. case 16: // this indicates a sRGB colorspace
  34594. case 17: // this indicates a grayscale colorspace
  34595. case 18: // this indicates a YUV colorspace
  34596. break;
  34597. default:
  34598. warn('Unknown colorspace ' + colorspace);
  34599. break;
  34600. }
  34601. } else if (method === 2) {
  34602. info('ICC profile not supported');
  34603. }
  34604. break;
  34605. case 0x6A703263: // 'jp2c'
  34606. this.parseCodestream(data, position, position + dataLength);
  34607. break;
  34608. case 0x6A502020: // 'jP\024\024'
  34609. if (0x0d0a870a !== readUint32(data, position)) {
  34610. warn('Invalid JP2 signature');
  34611. }
  34612. break;
  34613. // The following header types are valid but currently not used:
  34614. case 0x6A501A1A: // 'jP\032\032'
  34615. case 0x66747970: // 'ftyp'
  34616. case 0x72726571: // 'rreq'
  34617. case 0x72657320: // 'res '
  34618. case 0x69686472: // 'ihdr'
  34619. break;
  34620. default:
  34621. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  34622. (tbox >> 16) & 0xFF,
  34623. (tbox >> 8) & 0xFF,
  34624. tbox & 0xFF);
  34625. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  34626. break;
  34627. }
  34628. if (jumpDataLength) {
  34629. position += dataLength;
  34630. }
  34631. }
  34632. },
  34633. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  34634. var newByte = stream.getByte();
  34635. while (newByte >= 0) {
  34636. var oldByte = newByte;
  34637. newByte = stream.getByte();
  34638. var code = (oldByte << 8) | newByte;
  34639. // Image and tile size (SIZ)
  34640. if (code === 0xFF51) {
  34641. stream.skip(4);
  34642. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  34643. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  34644. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  34645. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  34646. stream.skip(16);
  34647. var Csiz = stream.getUint16(); // Byte 36
  34648. this.width = Xsiz - XOsiz;
  34649. this.height = Ysiz - YOsiz;
  34650. this.componentsCount = Csiz;
  34651. // Results are always returned as Uint8Arrays
  34652. this.bitsPerComponent = 8;
  34653. return;
  34654. }
  34655. }
  34656. throw new Error('JPX Error: No size marker found in JPX stream');
  34657. },
  34658. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  34659. var context = {};
  34660. try {
  34661. var doNotRecover = false;
  34662. var position = start;
  34663. while (position + 1 < end) {
  34664. var code = readUint16(data, position);
  34665. position += 2;
  34666. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  34667. switch (code) {
  34668. case 0xFF4F: // Start of codestream (SOC)
  34669. context.mainHeader = true;
  34670. break;
  34671. case 0xFFD9: // End of codestream (EOC)
  34672. break;
  34673. case 0xFF51: // Image and tile size (SIZ)
  34674. length = readUint16(data, position);
  34675. var siz = {};
  34676. siz.Xsiz = readUint32(data, position + 4);
  34677. siz.Ysiz = readUint32(data, position + 8);
  34678. siz.XOsiz = readUint32(data, position + 12);
  34679. siz.YOsiz = readUint32(data, position + 16);
  34680. siz.XTsiz = readUint32(data, position + 20);
  34681. siz.YTsiz = readUint32(data, position + 24);
  34682. siz.XTOsiz = readUint32(data, position + 28);
  34683. siz.YTOsiz = readUint32(data, position + 32);
  34684. var componentsCount = readUint16(data, position + 36);
  34685. siz.Csiz = componentsCount;
  34686. var components = [];
  34687. j = position + 38;
  34688. for (var i = 0; i < componentsCount; i++) {
  34689. var component = {
  34690. precision: (data[j] & 0x7F) + 1,
  34691. isSigned: !!(data[j] & 0x80),
  34692. XRsiz: data[j + 1],
  34693. YRsiz: data[j + 1]
  34694. };
  34695. calculateComponentDimensions(component, siz);
  34696. components.push(component);
  34697. }
  34698. context.SIZ = siz;
  34699. context.components = components;
  34700. calculateTileGrids(context, components);
  34701. context.QCC = [];
  34702. context.COC = [];
  34703. break;
  34704. case 0xFF5C: // Quantization default (QCD)
  34705. length = readUint16(data, position);
  34706. var qcd = {};
  34707. j = position + 2;
  34708. sqcd = data[j++];
  34709. switch (sqcd & 0x1F) {
  34710. case 0:
  34711. spqcdSize = 8;
  34712. scalarExpounded = true;
  34713. break;
  34714. case 1:
  34715. spqcdSize = 16;
  34716. scalarExpounded = false;
  34717. break;
  34718. case 2:
  34719. spqcdSize = 16;
  34720. scalarExpounded = true;
  34721. break;
  34722. default:
  34723. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  34724. }
  34725. qcd.noQuantization = (spqcdSize === 8);
  34726. qcd.scalarExpounded = scalarExpounded;
  34727. qcd.guardBits = sqcd >> 5;
  34728. spqcds = [];
  34729. while (j < length + position) {
  34730. var spqcd = {};
  34731. if (spqcdSize === 8) {
  34732. spqcd.epsilon = data[j++] >> 3;
  34733. spqcd.mu = 0;
  34734. } else {
  34735. spqcd.epsilon = data[j] >> 3;
  34736. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  34737. j += 2;
  34738. }
  34739. spqcds.push(spqcd);
  34740. }
  34741. qcd.SPqcds = spqcds;
  34742. if (context.mainHeader) {
  34743. context.QCD = qcd;
  34744. } else {
  34745. context.currentTile.QCD = qcd;
  34746. context.currentTile.QCC = [];
  34747. }
  34748. break;
  34749. case 0xFF5D: // Quantization component (QCC)
  34750. length = readUint16(data, position);
  34751. var qcc = {};
  34752. j = position + 2;
  34753. var cqcc;
  34754. if (context.SIZ.Csiz < 257) {
  34755. cqcc = data[j++];
  34756. } else {
  34757. cqcc = readUint16(data, j);
  34758. j += 2;
  34759. }
  34760. sqcd = data[j++];
  34761. switch (sqcd & 0x1F) {
  34762. case 0:
  34763. spqcdSize = 8;
  34764. scalarExpounded = true;
  34765. break;
  34766. case 1:
  34767. spqcdSize = 16;
  34768. scalarExpounded = false;
  34769. break;
  34770. case 2:
  34771. spqcdSize = 16;
  34772. scalarExpounded = true;
  34773. break;
  34774. default:
  34775. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  34776. }
  34777. qcc.noQuantization = (spqcdSize === 8);
  34778. qcc.scalarExpounded = scalarExpounded;
  34779. qcc.guardBits = sqcd >> 5;
  34780. spqcds = [];
  34781. while (j < (length + position)) {
  34782. spqcd = {};
  34783. if (spqcdSize === 8) {
  34784. spqcd.epsilon = data[j++] >> 3;
  34785. spqcd.mu = 0;
  34786. } else {
  34787. spqcd.epsilon = data[j] >> 3;
  34788. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  34789. j += 2;
  34790. }
  34791. spqcds.push(spqcd);
  34792. }
  34793. qcc.SPqcds = spqcds;
  34794. if (context.mainHeader) {
  34795. context.QCC[cqcc] = qcc;
  34796. } else {
  34797. context.currentTile.QCC[cqcc] = qcc;
  34798. }
  34799. break;
  34800. case 0xFF52: // Coding style default (COD)
  34801. length = readUint16(data, position);
  34802. var cod = {};
  34803. j = position + 2;
  34804. var scod = data[j++];
  34805. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  34806. cod.sopMarkerUsed = !!(scod & 2);
  34807. cod.ephMarkerUsed = !!(scod & 4);
  34808. cod.progressionOrder = data[j++];
  34809. cod.layersCount = readUint16(data, j);
  34810. j += 2;
  34811. cod.multipleComponentTransform = data[j++];
  34812. cod.decompositionLevelsCount = data[j++];
  34813. cod.xcb = (data[j++] & 0xF) + 2;
  34814. cod.ycb = (data[j++] & 0xF) + 2;
  34815. var blockStyle = data[j++];
  34816. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  34817. cod.resetContextProbabilities = !!(blockStyle & 2);
  34818. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  34819. cod.verticalyStripe = !!(blockStyle & 8);
  34820. cod.predictableTermination = !!(blockStyle & 16);
  34821. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  34822. cod.reversibleTransformation = data[j++];
  34823. if (cod.entropyCoderWithCustomPrecincts) {
  34824. var precinctsSizes = [];
  34825. while (j < length + position) {
  34826. var precinctsSize = data[j++];
  34827. precinctsSizes.push({
  34828. PPx: precinctsSize & 0xF,
  34829. PPy: precinctsSize >> 4
  34830. });
  34831. }
  34832. cod.precinctsSizes = precinctsSizes;
  34833. }
  34834. var unsupported = [];
  34835. if (cod.selectiveArithmeticCodingBypass) {
  34836. unsupported.push('selectiveArithmeticCodingBypass');
  34837. }
  34838. if (cod.resetContextProbabilities) {
  34839. unsupported.push('resetContextProbabilities');
  34840. }
  34841. if (cod.terminationOnEachCodingPass) {
  34842. unsupported.push('terminationOnEachCodingPass');
  34843. }
  34844. if (cod.verticalyStripe) {
  34845. unsupported.push('verticalyStripe');
  34846. }
  34847. if (cod.predictableTermination) {
  34848. unsupported.push('predictableTermination');
  34849. }
  34850. if (unsupported.length > 0) {
  34851. doNotRecover = true;
  34852. throw new Error('JPX Error: Unsupported COD options (' +
  34853. unsupported.join(', ') + ')');
  34854. }
  34855. if (context.mainHeader) {
  34856. context.COD = cod;
  34857. } else {
  34858. context.currentTile.COD = cod;
  34859. context.currentTile.COC = [];
  34860. }
  34861. break;
  34862. case 0xFF90: // Start of tile-part (SOT)
  34863. length = readUint16(data, position);
  34864. tile = {};
  34865. tile.index = readUint16(data, position + 2);
  34866. tile.length = readUint32(data, position + 4);
  34867. tile.dataEnd = tile.length + position - 2;
  34868. tile.partIndex = data[position + 8];
  34869. tile.partsCount = data[position + 9];
  34870. context.mainHeader = false;
  34871. if (tile.partIndex === 0) {
  34872. // reset component specific settings
  34873. tile.COD = context.COD;
  34874. tile.COC = context.COC.slice(0); // clone of the global COC
  34875. tile.QCD = context.QCD;
  34876. tile.QCC = context.QCC.slice(0); // clone of the global COC
  34877. }
  34878. context.currentTile = tile;
  34879. break;
  34880. case 0xFF93: // Start of data (SOD)
  34881. tile = context.currentTile;
  34882. if (tile.partIndex === 0) {
  34883. initializeTile(context, tile.index);
  34884. buildPackets(context);
  34885. }
  34886. // moving to the end of the data
  34887. length = tile.dataEnd - position;
  34888. parseTilePackets(context, data, position, length);
  34889. break;
  34890. case 0xFF55: // Tile-part lengths, main header (TLM)
  34891. case 0xFF57: // Packet length, main header (PLM)
  34892. case 0xFF58: // Packet length, tile-part header (PLT)
  34893. case 0xFF64: // Comment (COM)
  34894. length = readUint16(data, position);
  34895. // skipping content
  34896. break;
  34897. case 0xFF53: // Coding style component (COC)
  34898. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  34899. 'not implemented');
  34900. default:
  34901. throw new Error('JPX Error: Unknown codestream code: ' +
  34902. code.toString(16));
  34903. }
  34904. position += length;
  34905. }
  34906. } catch (e) {
  34907. if (doNotRecover || this.failOnCorruptedImage) {
  34908. throw e;
  34909. } else {
  34910. warn('Trying to recover from ' + e.message);
  34911. }
  34912. }
  34913. this.tiles = transformComponents(context);
  34914. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  34915. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  34916. this.componentsCount = context.SIZ.Csiz;
  34917. }
  34918. };
  34919. function calculateComponentDimensions(component, siz) {
  34920. // Section B.2 Component mapping
  34921. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  34922. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  34923. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  34924. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  34925. component.width = component.x1 - component.x0;
  34926. component.height = component.y1 - component.y0;
  34927. }
  34928. function calculateTileGrids(context, components) {
  34929. var siz = context.SIZ;
  34930. // Section B.3 Division into tile and tile-components
  34931. var tile, tiles = [];
  34932. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  34933. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  34934. for (var q = 0; q < numYtiles; q++) {
  34935. for (var p = 0; p < numXtiles; p++) {
  34936. tile = {};
  34937. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  34938. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  34939. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  34940. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  34941. tile.width = tile.tx1 - tile.tx0;
  34942. tile.height = tile.ty1 - tile.ty0;
  34943. tile.components = [];
  34944. tiles.push(tile);
  34945. }
  34946. }
  34947. context.tiles = tiles;
  34948. var componentsCount = siz.Csiz;
  34949. for (var i = 0, ii = componentsCount; i < ii; i++) {
  34950. var component = components[i];
  34951. for (var j = 0, jj = tiles.length; j < jj; j++) {
  34952. var tileComponent = {};
  34953. tile = tiles[j];
  34954. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  34955. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  34956. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  34957. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  34958. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  34959. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  34960. tile.components[i] = tileComponent;
  34961. }
  34962. }
  34963. }
  34964. function getBlocksDimensions(context, component, r) {
  34965. var codOrCoc = component.codingStyleParameters;
  34966. var result = {};
  34967. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  34968. result.PPx = 15;
  34969. result.PPy = 15;
  34970. } else {
  34971. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  34972. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  34973. }
  34974. // calculate codeblock size as described in section B.7
  34975. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  34976. Math.min(codOrCoc.xcb, result.PPx));
  34977. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  34978. Math.min(codOrCoc.ycb, result.PPy));
  34979. return result;
  34980. }
  34981. function buildPrecincts(context, resolution, dimensions) {
  34982. // Section B.6 Division resolution to precincts
  34983. var precinctWidth = 1 << dimensions.PPx;
  34984. var precinctHeight = 1 << dimensions.PPy;
  34985. // Jasper introduces codeblock groups for mapping each subband codeblocks
  34986. // to precincts. Precinct partition divides a resolution according to width
  34987. // and height parameters. The subband that belongs to the resolution level
  34988. // has a different size than the level, unless it is the zero resolution.
  34989. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  34990. // The precinct partitioning for a particular subband is derived from a
  34991. // partitioning of its parent LL band (i.e., the LL band at the next higher
  34992. // resolution level)... The LL band associated with each resolution level is
  34993. // divided into precincts... Each of the resulting precinct regions is then
  34994. // mapped into its child subbands (if any) at the next lower resolution
  34995. // level. This is accomplished by using the coordinate transformation
  34996. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  34997. // coordinates of a point in the LL band and child subband, respectively.
  34998. var isZeroRes = resolution.resLevel === 0;
  34999. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  35000. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  35001. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  35002. Math.ceil(resolution.trx1 / precinctWidth) -
  35003. Math.floor(resolution.trx0 / precinctWidth) : 0);
  35004. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  35005. Math.ceil(resolution.try1 / precinctHeight) -
  35006. Math.floor(resolution.try0 / precinctHeight) : 0);
  35007. var numprecincts = numprecinctswide * numprecinctshigh;
  35008. resolution.precinctParameters = {
  35009. precinctWidth: precinctWidth,
  35010. precinctHeight: precinctHeight,
  35011. numprecinctswide: numprecinctswide,
  35012. numprecinctshigh: numprecinctshigh,
  35013. numprecincts: numprecincts,
  35014. precinctWidthInSubband: precinctWidthInSubband,
  35015. precinctHeightInSubband: precinctHeightInSubband
  35016. };
  35017. }
  35018. function buildCodeblocks(context, subband, dimensions) {
  35019. // Section B.7 Division sub-band into code-blocks
  35020. var xcb_ = dimensions.xcb_;
  35021. var ycb_ = dimensions.ycb_;
  35022. var codeblockWidth = 1 << xcb_;
  35023. var codeblockHeight = 1 << ycb_;
  35024. var cbx0 = subband.tbx0 >> xcb_;
  35025. var cby0 = subband.tby0 >> ycb_;
  35026. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  35027. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  35028. var precinctParameters = subband.resolution.precinctParameters;
  35029. var codeblocks = [];
  35030. var precincts = [];
  35031. var i, j, codeblock, precinctNumber;
  35032. for (j = cby0; j < cby1; j++) {
  35033. for (i = cbx0; i < cbx1; i++) {
  35034. codeblock = {
  35035. cbx: i,
  35036. cby: j,
  35037. tbx0: codeblockWidth * i,
  35038. tby0: codeblockHeight * j,
  35039. tbx1: codeblockWidth * (i + 1),
  35040. tby1: codeblockHeight * (j + 1)
  35041. };
  35042. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  35043. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  35044. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  35045. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  35046. // Calculate precinct number for this codeblock, codeblock position
  35047. // should be relative to its subband, use actual dimension and position
  35048. // See comment about codeblock group width and height
  35049. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  35050. precinctParameters.precinctWidthInSubband);
  35051. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  35052. precinctParameters.precinctHeightInSubband);
  35053. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  35054. codeblock.precinctNumber = precinctNumber;
  35055. codeblock.subbandType = subband.type;
  35056. codeblock.Lblock = 3;
  35057. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  35058. codeblock.tby1_ <= codeblock.tby0_) {
  35059. continue;
  35060. }
  35061. codeblocks.push(codeblock);
  35062. // building precinct for the sub-band
  35063. var precinct = precincts[precinctNumber];
  35064. if (precinct !== undefined) {
  35065. if (i < precinct.cbxMin) {
  35066. precinct.cbxMin = i;
  35067. } else if (i > precinct.cbxMax) {
  35068. precinct.cbxMax = i;
  35069. }
  35070. if (j < precinct.cbyMin) {
  35071. precinct.cbxMin = j;
  35072. } else if (j > precinct.cbyMax) {
  35073. precinct.cbyMax = j;
  35074. }
  35075. } else {
  35076. precincts[precinctNumber] = precinct = {
  35077. cbxMin: i,
  35078. cbyMin: j,
  35079. cbxMax: i,
  35080. cbyMax: j
  35081. };
  35082. }
  35083. codeblock.precinct = precinct;
  35084. }
  35085. }
  35086. subband.codeblockParameters = {
  35087. codeblockWidth: xcb_,
  35088. codeblockHeight: ycb_,
  35089. numcodeblockwide: cbx1 - cbx0 + 1,
  35090. numcodeblockhigh: cby1 - cby0 + 1
  35091. };
  35092. subband.codeblocks = codeblocks;
  35093. subband.precincts = precincts;
  35094. }
  35095. function createPacket(resolution, precinctNumber, layerNumber) {
  35096. var precinctCodeblocks = [];
  35097. // Section B.10.8 Order of info in packet
  35098. var subbands = resolution.subbands;
  35099. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  35100. for (var i = 0, ii = subbands.length; i < ii; i++) {
  35101. var subband = subbands[i];
  35102. var codeblocks = subband.codeblocks;
  35103. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  35104. var codeblock = codeblocks[j];
  35105. if (codeblock.precinctNumber !== precinctNumber) {
  35106. continue;
  35107. }
  35108. precinctCodeblocks.push(codeblock);
  35109. }
  35110. }
  35111. return {
  35112. layerNumber: layerNumber,
  35113. codeblocks: precinctCodeblocks
  35114. };
  35115. }
  35116. function LayerResolutionComponentPositionIterator(context) {
  35117. var siz = context.SIZ;
  35118. var tileIndex = context.currentTile.index;
  35119. var tile = context.tiles[tileIndex];
  35120. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  35121. var componentsCount = siz.Csiz;
  35122. var maxDecompositionLevelsCount = 0;
  35123. for (var q = 0; q < componentsCount; q++) {
  35124. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  35125. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  35126. }
  35127. var l = 0, r = 0, i = 0, k = 0;
  35128. this.nextPacket = function JpxImage_nextPacket() {
  35129. // Section B.12.1.1 Layer-resolution-component-position
  35130. for (; l < layersCount; l++) {
  35131. for (; r <= maxDecompositionLevelsCount; r++) {
  35132. for (; i < componentsCount; i++) {
  35133. var component = tile.components[i];
  35134. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  35135. continue;
  35136. }
  35137. var resolution = component.resolutions[r];
  35138. var numprecincts = resolution.precinctParameters.numprecincts;
  35139. for (; k < numprecincts;) {
  35140. var packet = createPacket(resolution, k, l);
  35141. k++;
  35142. return packet;
  35143. }
  35144. k = 0;
  35145. }
  35146. i = 0;
  35147. }
  35148. r = 0;
  35149. }
  35150. throw new Error('JPX Error: Out of packets');
  35151. };
  35152. }
  35153. function ResolutionLayerComponentPositionIterator(context) {
  35154. var siz = context.SIZ;
  35155. var tileIndex = context.currentTile.index;
  35156. var tile = context.tiles[tileIndex];
  35157. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  35158. var componentsCount = siz.Csiz;
  35159. var maxDecompositionLevelsCount = 0;
  35160. for (var q = 0; q < componentsCount; q++) {
  35161. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  35162. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  35163. }
  35164. var r = 0, l = 0, i = 0, k = 0;
  35165. this.nextPacket = function JpxImage_nextPacket() {
  35166. // Section B.12.1.2 Resolution-layer-component-position
  35167. for (; r <= maxDecompositionLevelsCount; r++) {
  35168. for (; l < layersCount; l++) {
  35169. for (; i < componentsCount; i++) {
  35170. var component = tile.components[i];
  35171. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  35172. continue;
  35173. }
  35174. var resolution = component.resolutions[r];
  35175. var numprecincts = resolution.precinctParameters.numprecincts;
  35176. for (; k < numprecincts;) {
  35177. var packet = createPacket(resolution, k, l);
  35178. k++;
  35179. return packet;
  35180. }
  35181. k = 0;
  35182. }
  35183. i = 0;
  35184. }
  35185. l = 0;
  35186. }
  35187. throw new Error('JPX Error: Out of packets');
  35188. };
  35189. }
  35190. function ResolutionPositionComponentLayerIterator(context) {
  35191. var siz = context.SIZ;
  35192. var tileIndex = context.currentTile.index;
  35193. var tile = context.tiles[tileIndex];
  35194. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  35195. var componentsCount = siz.Csiz;
  35196. var l, r, c, p;
  35197. var maxDecompositionLevelsCount = 0;
  35198. for (c = 0; c < componentsCount; c++) {
  35199. var component = tile.components[c];
  35200. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  35201. component.codingStyleParameters.decompositionLevelsCount);
  35202. }
  35203. var maxNumPrecinctsInLevel = new Int32Array(
  35204. maxDecompositionLevelsCount + 1);
  35205. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  35206. var maxNumPrecincts = 0;
  35207. for (c = 0; c < componentsCount; ++c) {
  35208. var resolutions = tile.components[c].resolutions;
  35209. if (r < resolutions.length) {
  35210. maxNumPrecincts = Math.max(maxNumPrecincts,
  35211. resolutions[r].precinctParameters.numprecincts);
  35212. }
  35213. }
  35214. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  35215. }
  35216. l = 0;
  35217. r = 0;
  35218. c = 0;
  35219. p = 0;
  35220. this.nextPacket = function JpxImage_nextPacket() {
  35221. // Section B.12.1.3 Resolution-position-component-layer
  35222. for (; r <= maxDecompositionLevelsCount; r++) {
  35223. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  35224. for (; c < componentsCount; c++) {
  35225. var component = tile.components[c];
  35226. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  35227. continue;
  35228. }
  35229. var resolution = component.resolutions[r];
  35230. var numprecincts = resolution.precinctParameters.numprecincts;
  35231. if (p >= numprecincts) {
  35232. continue;
  35233. }
  35234. for (; l < layersCount;) {
  35235. var packet = createPacket(resolution, p, l);
  35236. l++;
  35237. return packet;
  35238. }
  35239. l = 0;
  35240. }
  35241. c = 0;
  35242. }
  35243. p = 0;
  35244. }
  35245. throw new Error('JPX Error: Out of packets');
  35246. };
  35247. }
  35248. function PositionComponentResolutionLayerIterator(context) {
  35249. var siz = context.SIZ;
  35250. var tileIndex = context.currentTile.index;
  35251. var tile = context.tiles[tileIndex];
  35252. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  35253. var componentsCount = siz.Csiz;
  35254. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  35255. var precinctsIterationSizes = precinctsSizes;
  35256. var l = 0, r = 0, c = 0, px = 0, py = 0;
  35257. this.nextPacket = function JpxImage_nextPacket() {
  35258. // Section B.12.1.4 Position-component-resolution-layer
  35259. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  35260. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  35261. for (; c < componentsCount; c++) {
  35262. var component = tile.components[c];
  35263. var decompositionLevelsCount =
  35264. component.codingStyleParameters.decompositionLevelsCount;
  35265. for (; r <= decompositionLevelsCount; r++) {
  35266. var resolution = component.resolutions[r];
  35267. var sizeInImageScale =
  35268. precinctsSizes.components[c].resolutions[r];
  35269. var k = getPrecinctIndexIfExist(
  35270. px,
  35271. py,
  35272. sizeInImageScale,
  35273. precinctsIterationSizes,
  35274. resolution);
  35275. if (k === null) {
  35276. continue;
  35277. }
  35278. for (; l < layersCount;) {
  35279. var packet = createPacket(resolution, k, l);
  35280. l++;
  35281. return packet;
  35282. }
  35283. l = 0;
  35284. }
  35285. r = 0;
  35286. }
  35287. c = 0;
  35288. }
  35289. px = 0;
  35290. }
  35291. throw new Error('JPX Error: Out of packets');
  35292. };
  35293. }
  35294. function ComponentPositionResolutionLayerIterator(context) {
  35295. var siz = context.SIZ;
  35296. var tileIndex = context.currentTile.index;
  35297. var tile = context.tiles[tileIndex];
  35298. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  35299. var componentsCount = siz.Csiz;
  35300. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  35301. var l = 0, r = 0, c = 0, px = 0, py = 0;
  35302. this.nextPacket = function JpxImage_nextPacket() {
  35303. // Section B.12.1.5 Component-position-resolution-layer
  35304. for (; c < componentsCount; ++c) {
  35305. var component = tile.components[c];
  35306. var precinctsIterationSizes = precinctsSizes.components[c];
  35307. var decompositionLevelsCount =
  35308. component.codingStyleParameters.decompositionLevelsCount;
  35309. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  35310. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  35311. for (; r <= decompositionLevelsCount; r++) {
  35312. var resolution = component.resolutions[r];
  35313. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  35314. var k = getPrecinctIndexIfExist(
  35315. px,
  35316. py,
  35317. sizeInImageScale,
  35318. precinctsIterationSizes,
  35319. resolution);
  35320. if (k === null) {
  35321. continue;
  35322. }
  35323. for (; l < layersCount;) {
  35324. var packet = createPacket(resolution, k, l);
  35325. l++;
  35326. return packet;
  35327. }
  35328. l = 0;
  35329. }
  35330. r = 0;
  35331. }
  35332. px = 0;
  35333. }
  35334. py = 0;
  35335. }
  35336. throw new Error('JPX Error: Out of packets');
  35337. };
  35338. }
  35339. function getPrecinctIndexIfExist(
  35340. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  35341. var posX = pxIndex * precinctIterationSizes.minWidth;
  35342. var posY = pyIndex * precinctIterationSizes.minHeight;
  35343. if (posX % sizeInImageScale.width !== 0 ||
  35344. posY % sizeInImageScale.height !== 0) {
  35345. return null;
  35346. }
  35347. var startPrecinctRowIndex =
  35348. (posY / sizeInImageScale.width) *
  35349. resolution.precinctParameters.numprecinctswide;
  35350. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  35351. }
  35352. function getPrecinctSizesInImageScale(tile) {
  35353. var componentsCount = tile.components.length;
  35354. var minWidth = Number.MAX_VALUE;
  35355. var minHeight = Number.MAX_VALUE;
  35356. var maxNumWide = 0;
  35357. var maxNumHigh = 0;
  35358. var sizePerComponent = new Array(componentsCount);
  35359. for (var c = 0; c < componentsCount; c++) {
  35360. var component = tile.components[c];
  35361. var decompositionLevelsCount =
  35362. component.codingStyleParameters.decompositionLevelsCount;
  35363. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  35364. var minWidthCurrentComponent = Number.MAX_VALUE;
  35365. var minHeightCurrentComponent = Number.MAX_VALUE;
  35366. var maxNumWideCurrentComponent = 0;
  35367. var maxNumHighCurrentComponent = 0;
  35368. var scale = 1;
  35369. for (var r = decompositionLevelsCount; r >= 0; --r) {
  35370. var resolution = component.resolutions[r];
  35371. var widthCurrentResolution =
  35372. scale * resolution.precinctParameters.precinctWidth;
  35373. var heightCurrentResolution =
  35374. scale * resolution.precinctParameters.precinctHeight;
  35375. minWidthCurrentComponent = Math.min(
  35376. minWidthCurrentComponent,
  35377. widthCurrentResolution);
  35378. minHeightCurrentComponent = Math.min(
  35379. minHeightCurrentComponent,
  35380. heightCurrentResolution);
  35381. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  35382. resolution.precinctParameters.numprecinctswide);
  35383. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  35384. resolution.precinctParameters.numprecinctshigh);
  35385. sizePerResolution[r] = {
  35386. width: widthCurrentResolution,
  35387. height: heightCurrentResolution
  35388. };
  35389. scale <<= 1;
  35390. }
  35391. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  35392. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  35393. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  35394. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  35395. sizePerComponent[c] = {
  35396. resolutions: sizePerResolution,
  35397. minWidth: minWidthCurrentComponent,
  35398. minHeight: minHeightCurrentComponent,
  35399. maxNumWide: maxNumWideCurrentComponent,
  35400. maxNumHigh: maxNumHighCurrentComponent
  35401. };
  35402. }
  35403. return {
  35404. components: sizePerComponent,
  35405. minWidth: minWidth,
  35406. minHeight: minHeight,
  35407. maxNumWide: maxNumWide,
  35408. maxNumHigh: maxNumHigh
  35409. };
  35410. }
  35411. function buildPackets(context) {
  35412. var siz = context.SIZ;
  35413. var tileIndex = context.currentTile.index;
  35414. var tile = context.tiles[tileIndex];
  35415. var componentsCount = siz.Csiz;
  35416. // Creating resolutions and sub-bands for each component
  35417. for (var c = 0; c < componentsCount; c++) {
  35418. var component = tile.components[c];
  35419. var decompositionLevelsCount =
  35420. component.codingStyleParameters.decompositionLevelsCount;
  35421. // Section B.5 Resolution levels and sub-bands
  35422. var resolutions = [];
  35423. var subbands = [];
  35424. for (var r = 0; r <= decompositionLevelsCount; r++) {
  35425. var blocksDimensions = getBlocksDimensions(context, component, r);
  35426. var resolution = {};
  35427. var scale = 1 << (decompositionLevelsCount - r);
  35428. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  35429. resolution.try0 = Math.ceil(component.tcy0 / scale);
  35430. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  35431. resolution.try1 = Math.ceil(component.tcy1 / scale);
  35432. resolution.resLevel = r;
  35433. buildPrecincts(context, resolution, blocksDimensions);
  35434. resolutions.push(resolution);
  35435. var subband;
  35436. if (r === 0) {
  35437. // one sub-band (LL) with last decomposition
  35438. subband = {};
  35439. subband.type = 'LL';
  35440. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  35441. subband.tby0 = Math.ceil(component.tcy0 / scale);
  35442. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  35443. subband.tby1 = Math.ceil(component.tcy1 / scale);
  35444. subband.resolution = resolution;
  35445. buildCodeblocks(context, subband, blocksDimensions);
  35446. subbands.push(subband);
  35447. resolution.subbands = [subband];
  35448. } else {
  35449. var bscale = 1 << (decompositionLevelsCount - r + 1);
  35450. var resolutionSubbands = [];
  35451. // three sub-bands (HL, LH and HH) with rest of decompositions
  35452. subband = {};
  35453. subband.type = 'HL';
  35454. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  35455. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  35456. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  35457. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  35458. subband.resolution = resolution;
  35459. buildCodeblocks(context, subband, blocksDimensions);
  35460. subbands.push(subband);
  35461. resolutionSubbands.push(subband);
  35462. subband = {};
  35463. subband.type = 'LH';
  35464. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  35465. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  35466. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  35467. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  35468. subband.resolution = resolution;
  35469. buildCodeblocks(context, subband, blocksDimensions);
  35470. subbands.push(subband);
  35471. resolutionSubbands.push(subband);
  35472. subband = {};
  35473. subband.type = 'HH';
  35474. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  35475. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  35476. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  35477. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  35478. subband.resolution = resolution;
  35479. buildCodeblocks(context, subband, blocksDimensions);
  35480. subbands.push(subband);
  35481. resolutionSubbands.push(subband);
  35482. resolution.subbands = resolutionSubbands;
  35483. }
  35484. }
  35485. component.resolutions = resolutions;
  35486. component.subbands = subbands;
  35487. }
  35488. // Generate the packets sequence
  35489. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  35490. switch (progressionOrder) {
  35491. case 0:
  35492. tile.packetsIterator =
  35493. new LayerResolutionComponentPositionIterator(context);
  35494. break;
  35495. case 1:
  35496. tile.packetsIterator =
  35497. new ResolutionLayerComponentPositionIterator(context);
  35498. break;
  35499. case 2:
  35500. tile.packetsIterator =
  35501. new ResolutionPositionComponentLayerIterator(context);
  35502. break;
  35503. case 3:
  35504. tile.packetsIterator =
  35505. new PositionComponentResolutionLayerIterator(context);
  35506. break;
  35507. case 4:
  35508. tile.packetsIterator =
  35509. new ComponentPositionResolutionLayerIterator(context);
  35510. break;
  35511. default:
  35512. throw new Error('JPX Error: Unsupported progression order ' +
  35513. progressionOrder);
  35514. }
  35515. }
  35516. function parseTilePackets(context, data, offset, dataLength) {
  35517. var position = 0;
  35518. var buffer, bufferSize = 0, skipNextBit = false;
  35519. function readBits(count) {
  35520. while (bufferSize < count) {
  35521. var b = data[offset + position];
  35522. position++;
  35523. if (skipNextBit) {
  35524. buffer = (buffer << 7) | b;
  35525. bufferSize += 7;
  35526. skipNextBit = false;
  35527. } else {
  35528. buffer = (buffer << 8) | b;
  35529. bufferSize += 8;
  35530. }
  35531. if (b === 0xFF) {
  35532. skipNextBit = true;
  35533. }
  35534. }
  35535. bufferSize -= count;
  35536. return (buffer >>> bufferSize) & ((1 << count) - 1);
  35537. }
  35538. function skipMarkerIfEqual(value) {
  35539. if (data[offset + position - 1] === 0xFF &&
  35540. data[offset + position] === value) {
  35541. skipBytes(1);
  35542. return true;
  35543. } else if (data[offset + position] === 0xFF &&
  35544. data[offset + position + 1] === value) {
  35545. skipBytes(2);
  35546. return true;
  35547. }
  35548. return false;
  35549. }
  35550. function skipBytes(count) {
  35551. position += count;
  35552. }
  35553. function alignToByte() {
  35554. bufferSize = 0;
  35555. if (skipNextBit) {
  35556. position++;
  35557. skipNextBit = false;
  35558. }
  35559. }
  35560. function readCodingpasses() {
  35561. if (readBits(1) === 0) {
  35562. return 1;
  35563. }
  35564. if (readBits(1) === 0) {
  35565. return 2;
  35566. }
  35567. var value = readBits(2);
  35568. if (value < 3) {
  35569. return value + 3;
  35570. }
  35571. value = readBits(5);
  35572. if (value < 31) {
  35573. return value + 6;
  35574. }
  35575. value = readBits(7);
  35576. return value + 37;
  35577. }
  35578. var tileIndex = context.currentTile.index;
  35579. var tile = context.tiles[tileIndex];
  35580. var sopMarkerUsed = context.COD.sopMarkerUsed;
  35581. var ephMarkerUsed = context.COD.ephMarkerUsed;
  35582. var packetsIterator = tile.packetsIterator;
  35583. while (position < dataLength) {
  35584. alignToByte();
  35585. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  35586. // Skip also marker segment length and packet sequence ID
  35587. skipBytes(4);
  35588. }
  35589. var packet = packetsIterator.nextPacket();
  35590. if (!readBits(1)) {
  35591. continue;
  35592. }
  35593. var layerNumber = packet.layerNumber;
  35594. var queue = [], codeblock;
  35595. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  35596. codeblock = packet.codeblocks[i];
  35597. var precinct = codeblock.precinct;
  35598. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  35599. var codeblockRow = codeblock.cby - precinct.cbyMin;
  35600. var codeblockIncluded = false;
  35601. var firstTimeInclusion = false;
  35602. var valueReady;
  35603. if (codeblock['included'] !== undefined) {
  35604. codeblockIncluded = !!readBits(1);
  35605. } else {
  35606. // reading inclusion tree
  35607. precinct = codeblock.precinct;
  35608. var inclusionTree, zeroBitPlanesTree;
  35609. if (precinct['inclusionTree'] !== undefined) {
  35610. inclusionTree = precinct.inclusionTree;
  35611. } else {
  35612. // building inclusion and zero bit-planes trees
  35613. var width = precinct.cbxMax - precinct.cbxMin + 1;
  35614. var height = precinct.cbyMax - precinct.cbyMin + 1;
  35615. inclusionTree = new InclusionTree(width, height, layerNumber);
  35616. zeroBitPlanesTree = new TagTree(width, height);
  35617. precinct.inclusionTree = inclusionTree;
  35618. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  35619. }
  35620. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  35621. while (true) {
  35622. if (readBits(1)) {
  35623. valueReady = !inclusionTree.nextLevel();
  35624. if (valueReady) {
  35625. codeblock.included = true;
  35626. codeblockIncluded = firstTimeInclusion = true;
  35627. break;
  35628. }
  35629. } else {
  35630. inclusionTree.incrementValue(layerNumber);
  35631. break;
  35632. }
  35633. }
  35634. }
  35635. }
  35636. if (!codeblockIncluded) {
  35637. continue;
  35638. }
  35639. if (firstTimeInclusion) {
  35640. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  35641. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  35642. while (true) {
  35643. if (readBits(1)) {
  35644. valueReady = !zeroBitPlanesTree.nextLevel();
  35645. if (valueReady) {
  35646. break;
  35647. }
  35648. } else {
  35649. zeroBitPlanesTree.incrementValue();
  35650. }
  35651. }
  35652. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  35653. }
  35654. var codingpasses = readCodingpasses();
  35655. while (readBits(1)) {
  35656. codeblock.Lblock++;
  35657. }
  35658. var codingpassesLog2 = log2(codingpasses);
  35659. // rounding down log2
  35660. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  35661. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  35662. var codedDataLength = readBits(bits);
  35663. queue.push({
  35664. codeblock: codeblock,
  35665. codingpasses: codingpasses,
  35666. dataLength: codedDataLength
  35667. });
  35668. }
  35669. alignToByte();
  35670. if (ephMarkerUsed) {
  35671. skipMarkerIfEqual(0x92);
  35672. }
  35673. while (queue.length > 0) {
  35674. var packetItem = queue.shift();
  35675. codeblock = packetItem.codeblock;
  35676. if (codeblock['data'] === undefined) {
  35677. codeblock.data = [];
  35678. }
  35679. codeblock.data.push({
  35680. data: data,
  35681. start: offset + position,
  35682. end: offset + position + packetItem.dataLength,
  35683. codingpasses: packetItem.codingpasses
  35684. });
  35685. position += packetItem.dataLength;
  35686. }
  35687. }
  35688. return position;
  35689. }
  35690. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  35691. delta, mb, reversible, segmentationSymbolUsed) {
  35692. var x0 = subband.tbx0;
  35693. var y0 = subband.tby0;
  35694. var width = subband.tbx1 - subband.tbx0;
  35695. var codeblocks = subband.codeblocks;
  35696. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  35697. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  35698. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  35699. var codeblock = codeblocks[i];
  35700. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  35701. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  35702. if (blockWidth === 0 || blockHeight === 0) {
  35703. continue;
  35704. }
  35705. if (codeblock['data'] === undefined) {
  35706. continue;
  35707. }
  35708. var bitModel, currentCodingpassType;
  35709. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  35710. codeblock.zeroBitPlanes, mb);
  35711. currentCodingpassType = 2; // first bit plane starts from cleanup
  35712. // collect data
  35713. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  35714. var j, jj, dataItem;
  35715. for (j = 0, jj = data.length; j < jj; j++) {
  35716. dataItem = data[j];
  35717. totalLength += dataItem.end - dataItem.start;
  35718. codingpasses += dataItem.codingpasses;
  35719. }
  35720. var encodedData = new Uint8Array(totalLength);
  35721. var position = 0;
  35722. for (j = 0, jj = data.length; j < jj; j++) {
  35723. dataItem = data[j];
  35724. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  35725. encodedData.set(chunk, position);
  35726. position += chunk.length;
  35727. }
  35728. // decoding the item
  35729. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  35730. bitModel.setDecoder(decoder);
  35731. for (j = 0; j < codingpasses; j++) {
  35732. switch (currentCodingpassType) {
  35733. case 0:
  35734. bitModel.runSignificancePropogationPass();
  35735. break;
  35736. case 1:
  35737. bitModel.runMagnitudeRefinementPass();
  35738. break;
  35739. case 2:
  35740. bitModel.runCleanupPass();
  35741. if (segmentationSymbolUsed) {
  35742. bitModel.checkSegmentationSymbol();
  35743. }
  35744. break;
  35745. }
  35746. currentCodingpassType = (currentCodingpassType + 1) % 3;
  35747. }
  35748. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  35749. var sign = bitModel.coefficentsSign;
  35750. var magnitude = bitModel.coefficentsMagnitude;
  35751. var bitsDecoded = bitModel.bitsDecoded;
  35752. var magnitudeCorrection = reversible ? 0 : 0.5;
  35753. var k, n, nb;
  35754. position = 0;
  35755. // Do the interleaving of Section F.3.3 here, so we do not need
  35756. // to copy later. LL level is not interleaved, just copied.
  35757. var interleave = (subband.type !== 'LL');
  35758. for (j = 0; j < blockHeight; j++) {
  35759. var row = (offset / width) | 0; // row in the non-interleaved subband
  35760. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  35761. for (k = 0; k < blockWidth; k++) {
  35762. n = magnitude[position];
  35763. if (n !== 0) {
  35764. n = (n + magnitudeCorrection) * delta;
  35765. if (sign[position] !== 0) {
  35766. n = -n;
  35767. }
  35768. nb = bitsDecoded[position];
  35769. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  35770. if (reversible && (nb >= mb)) {
  35771. coefficients[pos] = n;
  35772. } else {
  35773. coefficients[pos] = n * (1 << (mb - nb));
  35774. }
  35775. }
  35776. offset++;
  35777. position++;
  35778. }
  35779. offset += width - blockWidth;
  35780. }
  35781. }
  35782. }
  35783. function transformTile(context, tile, c) {
  35784. var component = tile.components[c];
  35785. var codingStyleParameters = component.codingStyleParameters;
  35786. var quantizationParameters = component.quantizationParameters;
  35787. var decompositionLevelsCount =
  35788. codingStyleParameters.decompositionLevelsCount;
  35789. var spqcds = quantizationParameters.SPqcds;
  35790. var scalarExpounded = quantizationParameters.scalarExpounded;
  35791. var guardBits = quantizationParameters.guardBits;
  35792. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  35793. var precision = context.components[c].precision;
  35794. var reversible = codingStyleParameters.reversibleTransformation;
  35795. var transform = (reversible ? new ReversibleTransform() :
  35796. new IrreversibleTransform());
  35797. var subbandCoefficients = [];
  35798. var b = 0;
  35799. for (var i = 0; i <= decompositionLevelsCount; i++) {
  35800. var resolution = component.resolutions[i];
  35801. var width = resolution.trx1 - resolution.trx0;
  35802. var height = resolution.try1 - resolution.try0;
  35803. // Allocate space for the whole sublevel.
  35804. var coefficients = new Float32Array(width * height);
  35805. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  35806. var mu, epsilon;
  35807. if (!scalarExpounded) {
  35808. // formula E-5
  35809. mu = spqcds[0].mu;
  35810. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  35811. } else {
  35812. mu = spqcds[b].mu;
  35813. epsilon = spqcds[b].epsilon;
  35814. b++;
  35815. }
  35816. var subband = resolution.subbands[j];
  35817. var gainLog2 = SubbandsGainLog2[subband.type];
  35818. // calulate quantization coefficient (Section E.1.1.1)
  35819. var delta = (reversible ? 1 :
  35820. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  35821. var mb = (guardBits + epsilon - 1);
  35822. // In the first resolution level, copyCoefficients will fill the
  35823. // whole array with coefficients. In the succeding passes,
  35824. // copyCoefficients will consecutively fill in the values that belong
  35825. // to the interleaved positions of the HL, LH, and HH coefficients.
  35826. // The LL coefficients will then be interleaved in Transform.iterate().
  35827. copyCoefficients(coefficients, width, height, subband, delta, mb,
  35828. reversible, segmentationSymbolUsed);
  35829. }
  35830. subbandCoefficients.push({
  35831. width: width,
  35832. height: height,
  35833. items: coefficients
  35834. });
  35835. }
  35836. var result = transform.calculate(subbandCoefficients,
  35837. component.tcx0, component.tcy0);
  35838. return {
  35839. left: component.tcx0,
  35840. top: component.tcy0,
  35841. width: result.width,
  35842. height: result.height,
  35843. items: result.items
  35844. };
  35845. }
  35846. function transformComponents(context) {
  35847. var siz = context.SIZ;
  35848. var components = context.components;
  35849. var componentsCount = siz.Csiz;
  35850. var resultImages = [];
  35851. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  35852. var tile = context.tiles[i];
  35853. var transformedTiles = [];
  35854. var c;
  35855. for (c = 0; c < componentsCount; c++) {
  35856. transformedTiles[c] = transformTile(context, tile, c);
  35857. }
  35858. var tile0 = transformedTiles[0];
  35859. var out = new Uint8Array(tile0.items.length * componentsCount);
  35860. var result = {
  35861. left: tile0.left,
  35862. top: tile0.top,
  35863. width: tile0.width,
  35864. height: tile0.height,
  35865. items: out
  35866. };
  35867. // Section G.2.2 Inverse multi component transform
  35868. var shift, offset, max, min, maxK;
  35869. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  35870. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  35871. var fourComponents = componentsCount === 4;
  35872. var y0items = transformedTiles[0].items;
  35873. var y1items = transformedTiles[1].items;
  35874. var y2items = transformedTiles[2].items;
  35875. var y3items = fourComponents ? transformedTiles[3].items : null;
  35876. // HACK: The multiple component transform formulas below assume that
  35877. // all components have the same precision. With this in mind, we
  35878. // compute shift and offset only once.
  35879. shift = components[0].precision - 8;
  35880. offset = (128 << shift) + 0.5;
  35881. max = 255 * (1 << shift);
  35882. maxK = max * 0.5;
  35883. min = -maxK;
  35884. var component0 = tile.components[0];
  35885. var alpha01 = componentsCount - 3;
  35886. jj = y0items.length;
  35887. if (!component0.codingStyleParameters.reversibleTransformation) {
  35888. // inverse irreversible multiple component transform
  35889. for (j = 0; j < jj; j++, pos += alpha01) {
  35890. y0 = y0items[j] + offset;
  35891. y1 = y1items[j];
  35892. y2 = y2items[j];
  35893. r = y0 + 1.402 * y2;
  35894. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  35895. b = y0 + 1.772 * y1;
  35896. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  35897. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  35898. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  35899. }
  35900. } else {
  35901. // inverse reversible multiple component transform
  35902. for (j = 0; j < jj; j++, pos += alpha01) {
  35903. y0 = y0items[j] + offset;
  35904. y1 = y1items[j];
  35905. y2 = y2items[j];
  35906. g = y0 - ((y2 + y1) >> 2);
  35907. r = g + y2;
  35908. b = g + y1;
  35909. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  35910. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  35911. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  35912. }
  35913. }
  35914. if (fourComponents) {
  35915. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  35916. k = y3items[j];
  35917. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  35918. }
  35919. }
  35920. } else { // no multi-component transform
  35921. for (c = 0; c < componentsCount; c++) {
  35922. var items = transformedTiles[c].items;
  35923. shift = components[c].precision - 8;
  35924. offset = (128 << shift) + 0.5;
  35925. max = (127.5 * (1 << shift));
  35926. min = -max;
  35927. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  35928. val = items[j];
  35929. out[pos] = val <= min ? 0 :
  35930. val >= max ? 255 : (val + offset) >> shift;
  35931. pos += componentsCount;
  35932. }
  35933. }
  35934. }
  35935. resultImages.push(result);
  35936. }
  35937. return resultImages;
  35938. }
  35939. function initializeTile(context, tileIndex) {
  35940. var siz = context.SIZ;
  35941. var componentsCount = siz.Csiz;
  35942. var tile = context.tiles[tileIndex];
  35943. for (var c = 0; c < componentsCount; c++) {
  35944. var component = tile.components[c];
  35945. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  35946. context.currentTile.QCC[c] : context.currentTile.QCD);
  35947. component.quantizationParameters = qcdOrQcc;
  35948. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  35949. context.currentTile.COC[c] : context.currentTile.COD);
  35950. component.codingStyleParameters = codOrCoc;
  35951. }
  35952. tile.codingStyleDefaultParameters = context.currentTile.COD;
  35953. }
  35954. // Section B.10.2 Tag trees
  35955. var TagTree = (function TagTreeClosure() {
  35956. function TagTree(width, height) {
  35957. var levelsLength = log2(Math.max(width, height)) + 1;
  35958. this.levels = [];
  35959. for (var i = 0; i < levelsLength; i++) {
  35960. var level = {
  35961. width: width,
  35962. height: height,
  35963. items: []
  35964. };
  35965. this.levels.push(level);
  35966. width = Math.ceil(width / 2);
  35967. height = Math.ceil(height / 2);
  35968. }
  35969. }
  35970. TagTree.prototype = {
  35971. reset: function TagTree_reset(i, j) {
  35972. var currentLevel = 0, value = 0, level;
  35973. while (currentLevel < this.levels.length) {
  35974. level = this.levels[currentLevel];
  35975. var index = i + j * level.width;
  35976. if (level.items[index] !== undefined) {
  35977. value = level.items[index];
  35978. break;
  35979. }
  35980. level.index = index;
  35981. i >>= 1;
  35982. j >>= 1;
  35983. currentLevel++;
  35984. }
  35985. currentLevel--;
  35986. level = this.levels[currentLevel];
  35987. level.items[level.index] = value;
  35988. this.currentLevel = currentLevel;
  35989. delete this.value;
  35990. },
  35991. incrementValue: function TagTree_incrementValue() {
  35992. var level = this.levels[this.currentLevel];
  35993. level.items[level.index]++;
  35994. },
  35995. nextLevel: function TagTree_nextLevel() {
  35996. var currentLevel = this.currentLevel;
  35997. var level = this.levels[currentLevel];
  35998. var value = level.items[level.index];
  35999. currentLevel--;
  36000. if (currentLevel < 0) {
  36001. this.value = value;
  36002. return false;
  36003. }
  36004. this.currentLevel = currentLevel;
  36005. level = this.levels[currentLevel];
  36006. level.items[level.index] = value;
  36007. return true;
  36008. }
  36009. };
  36010. return TagTree;
  36011. })();
  36012. var InclusionTree = (function InclusionTreeClosure() {
  36013. function InclusionTree(width, height, defaultValue) {
  36014. var levelsLength = log2(Math.max(width, height)) + 1;
  36015. this.levels = [];
  36016. for (var i = 0; i < levelsLength; i++) {
  36017. var items = new Uint8Array(width * height);
  36018. for (var j = 0, jj = items.length; j < jj; j++) {
  36019. items[j] = defaultValue;
  36020. }
  36021. var level = {
  36022. width: width,
  36023. height: height,
  36024. items: items
  36025. };
  36026. this.levels.push(level);
  36027. width = Math.ceil(width / 2);
  36028. height = Math.ceil(height / 2);
  36029. }
  36030. }
  36031. InclusionTree.prototype = {
  36032. reset: function InclusionTree_reset(i, j, stopValue) {
  36033. var currentLevel = 0;
  36034. while (currentLevel < this.levels.length) {
  36035. var level = this.levels[currentLevel];
  36036. var index = i + j * level.width;
  36037. level.index = index;
  36038. var value = level.items[index];
  36039. if (value === 0xFF) {
  36040. break;
  36041. }
  36042. if (value > stopValue) {
  36043. this.currentLevel = currentLevel;
  36044. // already know about this one, propagating the value to top levels
  36045. this.propagateValues();
  36046. return false;
  36047. }
  36048. i >>= 1;
  36049. j >>= 1;
  36050. currentLevel++;
  36051. }
  36052. this.currentLevel = currentLevel - 1;
  36053. return true;
  36054. },
  36055. incrementValue: function InclusionTree_incrementValue(stopValue) {
  36056. var level = this.levels[this.currentLevel];
  36057. level.items[level.index] = stopValue + 1;
  36058. this.propagateValues();
  36059. },
  36060. propagateValues: function InclusionTree_propagateValues() {
  36061. var levelIndex = this.currentLevel;
  36062. var level = this.levels[levelIndex];
  36063. var currentValue = level.items[level.index];
  36064. while (--levelIndex >= 0) {
  36065. level = this.levels[levelIndex];
  36066. level.items[level.index] = currentValue;
  36067. }
  36068. },
  36069. nextLevel: function InclusionTree_nextLevel() {
  36070. var currentLevel = this.currentLevel;
  36071. var level = this.levels[currentLevel];
  36072. var value = level.items[level.index];
  36073. level.items[level.index] = 0xFF;
  36074. currentLevel--;
  36075. if (currentLevel < 0) {
  36076. return false;
  36077. }
  36078. this.currentLevel = currentLevel;
  36079. level = this.levels[currentLevel];
  36080. level.items[level.index] = value;
  36081. return true;
  36082. }
  36083. };
  36084. return InclusionTree;
  36085. })();
  36086. // Section D. Coefficient bit modeling
  36087. var BitModel = (function BitModelClosure() {
  36088. var UNIFORM_CONTEXT = 17;
  36089. var RUNLENGTH_CONTEXT = 18;
  36090. // Table D-1
  36091. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  36092. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  36093. var LLAndLHContextsLabel = new Uint8Array([
  36094. 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,
  36095. 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,
  36096. 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
  36097. ]);
  36098. var HLContextLabel = new Uint8Array([
  36099. 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,
  36100. 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,
  36101. 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
  36102. ]);
  36103. var HHContextLabel = new Uint8Array([
  36104. 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,
  36105. 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,
  36106. 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
  36107. ]);
  36108. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  36109. this.width = width;
  36110. this.height = height;
  36111. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  36112. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  36113. var coefficientCount = width * height;
  36114. // coefficients outside the encoding region treated as insignificant
  36115. // add border state cells for significanceState
  36116. this.neighborsSignificance = new Uint8Array(coefficientCount);
  36117. this.coefficentsSign = new Uint8Array(coefficientCount);
  36118. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  36119. mb > 6 ? new Uint16Array(coefficientCount) :
  36120. new Uint8Array(coefficientCount);
  36121. this.processingFlags = new Uint8Array(coefficientCount);
  36122. var bitsDecoded = new Uint8Array(coefficientCount);
  36123. if (zeroBitPlanes !== 0) {
  36124. for (var i = 0; i < coefficientCount; i++) {
  36125. bitsDecoded[i] = zeroBitPlanes;
  36126. }
  36127. }
  36128. this.bitsDecoded = bitsDecoded;
  36129. this.reset();
  36130. }
  36131. BitModel.prototype = {
  36132. setDecoder: function BitModel_setDecoder(decoder) {
  36133. this.decoder = decoder;
  36134. },
  36135. reset: function BitModel_reset() {
  36136. // We have 17 contexts that are accessed via context labels,
  36137. // plus the uniform and runlength context.
  36138. this.contexts = new Int8Array(19);
  36139. // Contexts are packed into 1 byte:
  36140. // highest 7 bits carry the index, lowest bit carries mps
  36141. this.contexts[0] = (4 << 1) | 0;
  36142. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  36143. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  36144. },
  36145. setNeighborsSignificance:
  36146. function BitModel_setNeighborsSignificance(row, column, index) {
  36147. var neighborsSignificance = this.neighborsSignificance;
  36148. var width = this.width, height = this.height;
  36149. var left = (column > 0);
  36150. var right = (column + 1 < width);
  36151. var i;
  36152. if (row > 0) {
  36153. i = index - width;
  36154. if (left) {
  36155. neighborsSignificance[i - 1] += 0x10;
  36156. }
  36157. if (right) {
  36158. neighborsSignificance[i + 1] += 0x10;
  36159. }
  36160. neighborsSignificance[i] += 0x04;
  36161. }
  36162. if (row + 1 < height) {
  36163. i = index + width;
  36164. if (left) {
  36165. neighborsSignificance[i - 1] += 0x10;
  36166. }
  36167. if (right) {
  36168. neighborsSignificance[i + 1] += 0x10;
  36169. }
  36170. neighborsSignificance[i] += 0x04;
  36171. }
  36172. if (left) {
  36173. neighborsSignificance[index - 1] += 0x01;
  36174. }
  36175. if (right) {
  36176. neighborsSignificance[index + 1] += 0x01;
  36177. }
  36178. neighborsSignificance[index] |= 0x80;
  36179. },
  36180. runSignificancePropogationPass:
  36181. function BitModel_runSignificancePropogationPass() {
  36182. var decoder = this.decoder;
  36183. var width = this.width, height = this.height;
  36184. var coefficentsMagnitude = this.coefficentsMagnitude;
  36185. var coefficentsSign = this.coefficentsSign;
  36186. var neighborsSignificance = this.neighborsSignificance;
  36187. var processingFlags = this.processingFlags;
  36188. var contexts = this.contexts;
  36189. var labels = this.contextLabelTable;
  36190. var bitsDecoded = this.bitsDecoded;
  36191. var processedInverseMask = ~1;
  36192. var processedMask = 1;
  36193. var firstMagnitudeBitMask = 2;
  36194. for (var i0 = 0; i0 < height; i0 += 4) {
  36195. for (var j = 0; j < width; j++) {
  36196. var index = i0 * width + j;
  36197. for (var i1 = 0; i1 < 4; i1++, index += width) {
  36198. var i = i0 + i1;
  36199. if (i >= height) {
  36200. break;
  36201. }
  36202. // clear processed flag first
  36203. processingFlags[index] &= processedInverseMask;
  36204. if (coefficentsMagnitude[index] ||
  36205. !neighborsSignificance[index]) {
  36206. continue;
  36207. }
  36208. var contextLabel = labels[neighborsSignificance[index]];
  36209. var decision = decoder.readBit(contexts, contextLabel);
  36210. if (decision) {
  36211. var sign = this.decodeSignBit(i, j, index);
  36212. coefficentsSign[index] = sign;
  36213. coefficentsMagnitude[index] = 1;
  36214. this.setNeighborsSignificance(i, j, index);
  36215. processingFlags[index] |= firstMagnitudeBitMask;
  36216. }
  36217. bitsDecoded[index]++;
  36218. processingFlags[index] |= processedMask;
  36219. }
  36220. }
  36221. }
  36222. },
  36223. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  36224. var width = this.width, height = this.height;
  36225. var coefficentsMagnitude = this.coefficentsMagnitude;
  36226. var coefficentsSign = this.coefficentsSign;
  36227. var contribution, sign0, sign1, significance1;
  36228. var contextLabel, decoded;
  36229. // calculate horizontal contribution
  36230. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  36231. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  36232. sign1 = coefficentsSign[index + 1];
  36233. if (significance1) {
  36234. sign0 = coefficentsSign[index - 1];
  36235. contribution = 1 - sign1 - sign0;
  36236. } else {
  36237. contribution = 1 - sign1 - sign1;
  36238. }
  36239. } else if (significance1) {
  36240. sign0 = coefficentsSign[index - 1];
  36241. contribution = 1 - sign0 - sign0;
  36242. } else {
  36243. contribution = 0;
  36244. }
  36245. var horizontalContribution = 3 * contribution;
  36246. // calculate vertical contribution and combine with the horizontal
  36247. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  36248. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  36249. sign1 = coefficentsSign[index + width];
  36250. if (significance1) {
  36251. sign0 = coefficentsSign[index - width];
  36252. contribution = 1 - sign1 - sign0 + horizontalContribution;
  36253. } else {
  36254. contribution = 1 - sign1 - sign1 + horizontalContribution;
  36255. }
  36256. } else if (significance1) {
  36257. sign0 = coefficentsSign[index - width];
  36258. contribution = 1 - sign0 - sign0 + horizontalContribution;
  36259. } else {
  36260. contribution = horizontalContribution;
  36261. }
  36262. if (contribution >= 0) {
  36263. contextLabel = 9 + contribution;
  36264. decoded = this.decoder.readBit(this.contexts, contextLabel);
  36265. } else {
  36266. contextLabel = 9 - contribution;
  36267. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  36268. }
  36269. return decoded;
  36270. },
  36271. runMagnitudeRefinementPass:
  36272. function BitModel_runMagnitudeRefinementPass() {
  36273. var decoder = this.decoder;
  36274. var width = this.width, height = this.height;
  36275. var coefficentsMagnitude = this.coefficentsMagnitude;
  36276. var neighborsSignificance = this.neighborsSignificance;
  36277. var contexts = this.contexts;
  36278. var bitsDecoded = this.bitsDecoded;
  36279. var processingFlags = this.processingFlags;
  36280. var processedMask = 1;
  36281. var firstMagnitudeBitMask = 2;
  36282. var length = width * height;
  36283. var width4 = width * 4;
  36284. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  36285. indexNext = Math.min(length, index0 + width4);
  36286. for (var j = 0; j < width; j++) {
  36287. for (var index = index0 + j; index < indexNext; index += width) {
  36288. // significant but not those that have just become
  36289. if (!coefficentsMagnitude[index] ||
  36290. (processingFlags[index] & processedMask) !== 0) {
  36291. continue;
  36292. }
  36293. var contextLabel = 16;
  36294. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  36295. processingFlags[index] ^= firstMagnitudeBitMask;
  36296. // first refinement
  36297. var significance = neighborsSignificance[index] & 127;
  36298. contextLabel = significance === 0 ? 15 : 14;
  36299. }
  36300. var bit = decoder.readBit(contexts, contextLabel);
  36301. coefficentsMagnitude[index] =
  36302. (coefficentsMagnitude[index] << 1) | bit;
  36303. bitsDecoded[index]++;
  36304. processingFlags[index] |= processedMask;
  36305. }
  36306. }
  36307. }
  36308. },
  36309. runCleanupPass: function BitModel_runCleanupPass() {
  36310. var decoder = this.decoder;
  36311. var width = this.width, height = this.height;
  36312. var neighborsSignificance = this.neighborsSignificance;
  36313. var coefficentsMagnitude = this.coefficentsMagnitude;
  36314. var coefficentsSign = this.coefficentsSign;
  36315. var contexts = this.contexts;
  36316. var labels = this.contextLabelTable;
  36317. var bitsDecoded = this.bitsDecoded;
  36318. var processingFlags = this.processingFlags;
  36319. var processedMask = 1;
  36320. var firstMagnitudeBitMask = 2;
  36321. var oneRowDown = width;
  36322. var twoRowsDown = width * 2;
  36323. var threeRowsDown = width * 3;
  36324. var iNext;
  36325. for (var i0 = 0; i0 < height; i0 = iNext) {
  36326. iNext = Math.min(i0 + 4, height);
  36327. var indexBase = i0 * width;
  36328. var checkAllEmpty = i0 + 3 < height;
  36329. for (var j = 0; j < width; j++) {
  36330. var index0 = indexBase + j;
  36331. // using the property: labels[neighborsSignificance[index]] === 0
  36332. // when neighborsSignificance[index] === 0
  36333. var allEmpty = (checkAllEmpty &&
  36334. processingFlags[index0] === 0 &&
  36335. processingFlags[index0 + oneRowDown] === 0 &&
  36336. processingFlags[index0 + twoRowsDown] === 0 &&
  36337. processingFlags[index0 + threeRowsDown] === 0 &&
  36338. neighborsSignificance[index0] === 0 &&
  36339. neighborsSignificance[index0 + oneRowDown] === 0 &&
  36340. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  36341. neighborsSignificance[index0 + threeRowsDown] === 0);
  36342. var i1 = 0, index = index0;
  36343. var i = i0, sign;
  36344. if (allEmpty) {
  36345. var hasSignificantCoefficent =
  36346. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  36347. if (!hasSignificantCoefficent) {
  36348. bitsDecoded[index0]++;
  36349. bitsDecoded[index0 + oneRowDown]++;
  36350. bitsDecoded[index0 + twoRowsDown]++;
  36351. bitsDecoded[index0 + threeRowsDown]++;
  36352. continue; // next column
  36353. }
  36354. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  36355. decoder.readBit(contexts, UNIFORM_CONTEXT);
  36356. if (i1 !== 0) {
  36357. i = i0 + i1;
  36358. index += i1 * width;
  36359. }
  36360. sign = this.decodeSignBit(i, j, index);
  36361. coefficentsSign[index] = sign;
  36362. coefficentsMagnitude[index] = 1;
  36363. this.setNeighborsSignificance(i, j, index);
  36364. processingFlags[index] |= firstMagnitudeBitMask;
  36365. index = index0;
  36366. for (var i2 = i0; i2 <= i; i2++, index += width) {
  36367. bitsDecoded[index]++;
  36368. }
  36369. i1++;
  36370. }
  36371. for (i = i0 + i1; i < iNext; i++, index += width) {
  36372. if (coefficentsMagnitude[index] ||
  36373. (processingFlags[index] & processedMask) !== 0) {
  36374. continue;
  36375. }
  36376. var contextLabel = labels[neighborsSignificance[index]];
  36377. var decision = decoder.readBit(contexts, contextLabel);
  36378. if (decision === 1) {
  36379. sign = this.decodeSignBit(i, j, index);
  36380. coefficentsSign[index] = sign;
  36381. coefficentsMagnitude[index] = 1;
  36382. this.setNeighborsSignificance(i, j, index);
  36383. processingFlags[index] |= firstMagnitudeBitMask;
  36384. }
  36385. bitsDecoded[index]++;
  36386. }
  36387. }
  36388. }
  36389. },
  36390. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  36391. var decoder = this.decoder;
  36392. var contexts = this.contexts;
  36393. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  36394. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  36395. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  36396. decoder.readBit(contexts, UNIFORM_CONTEXT);
  36397. if (symbol !== 0xA) {
  36398. throw new Error('JPX Error: Invalid segmentation symbol');
  36399. }
  36400. }
  36401. };
  36402. return BitModel;
  36403. })();
  36404. // Section F, Discrete wavelet transformation
  36405. var Transform = (function TransformClosure() {
  36406. function Transform() {}
  36407. Transform.prototype.calculate =
  36408. function transformCalculate(subbands, u0, v0) {
  36409. var ll = subbands[0];
  36410. for (var i = 1, ii = subbands.length; i < ii; i++) {
  36411. ll = this.iterate(ll, subbands[i], u0, v0);
  36412. }
  36413. return ll;
  36414. };
  36415. Transform.prototype.extend = function extend(buffer, offset, size) {
  36416. // Section F.3.7 extending... using max extension of 4
  36417. var i1 = offset - 1, j1 = offset + 1;
  36418. var i2 = offset + size - 2, j2 = offset + size;
  36419. buffer[i1--] = buffer[j1++];
  36420. buffer[j2++] = buffer[i2--];
  36421. buffer[i1--] = buffer[j1++];
  36422. buffer[j2++] = buffer[i2--];
  36423. buffer[i1--] = buffer[j1++];
  36424. buffer[j2++] = buffer[i2--];
  36425. buffer[i1] = buffer[j1];
  36426. buffer[j2] = buffer[i2];
  36427. };
  36428. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  36429. u0, v0) {
  36430. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  36431. var width = hl_lh_hh.width;
  36432. var height = hl_lh_hh.height;
  36433. var items = hl_lh_hh.items;
  36434. var i, j, k, l, u, v;
  36435. // Interleave LL according to Section F.3.3
  36436. for (k = 0, i = 0; i < llHeight; i++) {
  36437. l = i * 2 * width;
  36438. for (j = 0; j < llWidth; j++, k++, l += 2) {
  36439. items[l] = llItems[k];
  36440. }
  36441. }
  36442. // The LL band is not needed anymore.
  36443. llItems = ll.items = null;
  36444. var bufferPadding = 4;
  36445. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  36446. // Section F.3.4 HOR_SR
  36447. if (width === 1) {
  36448. // if width = 1, when u0 even keep items as is, when odd divide by 2
  36449. if ((u0 & 1) !== 0) {
  36450. for (v = 0, k = 0; v < height; v++, k += width) {
  36451. items[k] *= 0.5;
  36452. }
  36453. }
  36454. } else {
  36455. for (v = 0, k = 0; v < height; v++, k += width) {
  36456. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  36457. this.extend(rowBuffer, bufferPadding, width);
  36458. this.filter(rowBuffer, bufferPadding, width);
  36459. items.set(
  36460. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  36461. k);
  36462. }
  36463. }
  36464. // Accesses to the items array can take long, because it may not fit into
  36465. // CPU cache and has to be fetched from main memory. Since subsequent
  36466. // accesses to the items array are not local when reading columns, we
  36467. // have a cache miss every time. To reduce cache misses, get up to
  36468. // 'numBuffers' items at a time and store them into the individual
  36469. // buffers. The colBuffers should be small enough to fit into CPU cache.
  36470. var numBuffers = 16;
  36471. var colBuffers = [];
  36472. for (i = 0; i < numBuffers; i++) {
  36473. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  36474. }
  36475. var b, currentBuffer = 0;
  36476. ll = bufferPadding + height;
  36477. // Section F.3.5 VER_SR
  36478. if (height === 1) {
  36479. // if height = 1, when v0 even keep items as is, when odd divide by 2
  36480. if ((v0 & 1) !== 0) {
  36481. for (u = 0; u < width; u++) {
  36482. items[u] *= 0.5;
  36483. }
  36484. }
  36485. } else {
  36486. for (u = 0; u < width; u++) {
  36487. // if we ran out of buffers, copy several image columns at once
  36488. if (currentBuffer === 0) {
  36489. numBuffers = Math.min(width - u, numBuffers);
  36490. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  36491. for (b = 0; b < numBuffers; b++) {
  36492. colBuffers[b][l] = items[k + b];
  36493. }
  36494. }
  36495. currentBuffer = numBuffers;
  36496. }
  36497. currentBuffer--;
  36498. var buffer = colBuffers[currentBuffer];
  36499. this.extend(buffer, bufferPadding, height);
  36500. this.filter(buffer, bufferPadding, height);
  36501. // If this is last buffer in this group of buffers, flush all buffers.
  36502. if (currentBuffer === 0) {
  36503. k = u - numBuffers + 1;
  36504. for (l = bufferPadding; l < ll; k += width, l++) {
  36505. for (b = 0; b < numBuffers; b++) {
  36506. items[k + b] = colBuffers[b][l];
  36507. }
  36508. }
  36509. }
  36510. }
  36511. }
  36512. return {
  36513. width: width,
  36514. height: height,
  36515. items: items
  36516. };
  36517. };
  36518. return Transform;
  36519. })();
  36520. // Section 3.8.2 Irreversible 9-7 filter
  36521. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  36522. function IrreversibleTransform() {
  36523. Transform.call(this);
  36524. }
  36525. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  36526. IrreversibleTransform.prototype.filter =
  36527. function irreversibleTransformFilter(x, offset, length) {
  36528. var len = length >> 1;
  36529. offset = offset | 0;
  36530. var j, n, current, next;
  36531. var alpha = -1.586134342059924;
  36532. var beta = -0.052980118572961;
  36533. var gamma = 0.882911075530934;
  36534. var delta = 0.443506852043971;
  36535. var K = 1.230174104914001;
  36536. var K_ = 1 / K;
  36537. // step 1 is combined with step 3
  36538. // step 2
  36539. j = offset - 3;
  36540. for (n = len + 4; n--; j += 2) {
  36541. x[j] *= K_;
  36542. }
  36543. // step 1 & 3
  36544. j = offset - 2;
  36545. current = delta * x[j -1];
  36546. for (n = len + 3; n--; j += 2) {
  36547. next = delta * x[j + 1];
  36548. x[j] = K * x[j] - current - next;
  36549. if (n--) {
  36550. j += 2;
  36551. current = delta * x[j + 1];
  36552. x[j] = K * x[j] - current - next;
  36553. } else {
  36554. break;
  36555. }
  36556. }
  36557. // step 4
  36558. j = offset - 1;
  36559. current = gamma * x[j - 1];
  36560. for (n = len + 2; n--; j += 2) {
  36561. next = gamma * x[j + 1];
  36562. x[j] -= current + next;
  36563. if (n--) {
  36564. j += 2;
  36565. current = gamma * x[j + 1];
  36566. x[j] -= current + next;
  36567. } else {
  36568. break;
  36569. }
  36570. }
  36571. // step 5
  36572. j = offset;
  36573. current = beta * x[j - 1];
  36574. for (n = len + 1; n--; j += 2) {
  36575. next = beta * x[j + 1];
  36576. x[j] -= current + next;
  36577. if (n--) {
  36578. j += 2;
  36579. current = beta * x[j + 1];
  36580. x[j] -= current + next;
  36581. } else {
  36582. break;
  36583. }
  36584. }
  36585. // step 6
  36586. if (len !== 0) {
  36587. j = offset + 1;
  36588. current = alpha * x[j - 1];
  36589. for (n = len; n--; j += 2) {
  36590. next = alpha * x[j + 1];
  36591. x[j] -= current + next;
  36592. if (n--) {
  36593. j += 2;
  36594. current = alpha * x[j + 1];
  36595. x[j] -= current + next;
  36596. } else {
  36597. break;
  36598. }
  36599. }
  36600. }
  36601. };
  36602. return IrreversibleTransform;
  36603. })();
  36604. // Section 3.8.1 Reversible 5-3 filter
  36605. var ReversibleTransform = (function ReversibleTransformClosure() {
  36606. function ReversibleTransform() {
  36607. Transform.call(this);
  36608. }
  36609. ReversibleTransform.prototype = Object.create(Transform.prototype);
  36610. ReversibleTransform.prototype.filter =
  36611. function reversibleTransformFilter(x, offset, length) {
  36612. var len = length >> 1;
  36613. offset = offset | 0;
  36614. var j, n;
  36615. for (j = offset, n = len + 1; n--; j += 2) {
  36616. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  36617. }
  36618. for (j = offset + 1, n = len; n--; j += 2) {
  36619. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  36620. }
  36621. };
  36622. return ReversibleTransform;
  36623. })();
  36624. return JpxImage;
  36625. })();
  36626. var Jbig2Image = (function Jbig2ImageClosure() {
  36627. // Utility data structures
  36628. function ContextCache() {}
  36629. ContextCache.prototype = {
  36630. getContexts: function(id) {
  36631. if (id in this) {
  36632. return this[id];
  36633. }
  36634. return (this[id] = new Int8Array(1 << 16));
  36635. }
  36636. };
  36637. function DecodingContext(data, start, end) {
  36638. this.data = data;
  36639. this.start = start;
  36640. this.end = end;
  36641. }
  36642. DecodingContext.prototype = {
  36643. get decoder() {
  36644. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  36645. return shadow(this, 'decoder', decoder);
  36646. },
  36647. get contextCache() {
  36648. var cache = new ContextCache();
  36649. return shadow(this, 'contextCache', cache);
  36650. }
  36651. };
  36652. // Annex A. Arithmetic Integer Decoding Procedure
  36653. // A.2 Procedure for decoding values
  36654. function decodeInteger(contextCache, procedure, decoder) {
  36655. var contexts = contextCache.getContexts(procedure);
  36656. var prev = 1;
  36657. function readBits(length) {
  36658. var v = 0;
  36659. for (var i = 0; i < length; i++) {
  36660. var bit = decoder.readBit(contexts, prev);
  36661. prev = (prev < 256 ? (prev << 1) | bit :
  36662. (((prev << 1) | bit) & 511) | 256);
  36663. v = (v << 1) | bit;
  36664. }
  36665. return v >>> 0;
  36666. }
  36667. var sign = readBits(1);
  36668. var value = readBits(1) ?
  36669. (readBits(1) ?
  36670. (readBits(1) ?
  36671. (readBits(1) ?
  36672. (readBits(1) ?
  36673. (readBits(32) + 4436) :
  36674. readBits(12) + 340) :
  36675. readBits(8) + 84) :
  36676. readBits(6) + 20) :
  36677. readBits(4) + 4) :
  36678. readBits(2);
  36679. return (sign === 0 ? value : (value > 0 ? -value : null));
  36680. }
  36681. // A.3 The IAID decoding procedure
  36682. function decodeIAID(contextCache, decoder, codeLength) {
  36683. var contexts = contextCache.getContexts('IAID');
  36684. var prev = 1;
  36685. for (var i = 0; i < codeLength; i++) {
  36686. var bit = decoder.readBit(contexts, prev);
  36687. prev = (prev << 1) | bit;
  36688. }
  36689. if (codeLength < 31) {
  36690. return prev & ((1 << codeLength) - 1);
  36691. }
  36692. return prev & 0x7FFFFFFF;
  36693. }
  36694. // 7.3 Segment types
  36695. var SegmentTypes = [
  36696. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  36697. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  36698. null, null, null, null, null, 'patternDictionary', null, null, null,
  36699. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  36700. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  36701. null, null, null, null, null, 'IntermediateGenericRegion', null,
  36702. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  36703. 'IntermediateGenericRefinementRegion', null,
  36704. 'ImmediateGenericRefinementRegion',
  36705. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  36706. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  36707. 'Tables', null, null, null, null, null, null, null, null,
  36708. 'Extension'
  36709. ];
  36710. var CodingTemplates = [
  36711. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  36712. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  36713. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  36714. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  36715. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  36716. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  36717. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  36718. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  36719. {x: -1, y: 0}],
  36720. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  36721. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  36722. ];
  36723. var RefinementTemplates = [
  36724. {
  36725. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  36726. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  36727. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  36728. },
  36729. {
  36730. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  36731. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  36732. {x: 0, y: 1}, {x: 1, y: 1}]
  36733. }
  36734. ];
  36735. // See 6.2.5.7 Decoding the bitmap.
  36736. var ReusedContexts = [
  36737. 0x9B25, // 10011 0110010 0101
  36738. 0x0795, // 0011 110010 101
  36739. 0x00E5, // 001 11001 01
  36740. 0x0195 // 011001 0101
  36741. ];
  36742. var RefinementReusedContexts = [
  36743. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  36744. 0x0008 // '0000' + '001000'
  36745. ];
  36746. function decodeBitmapTemplate0(width, height, decodingContext) {
  36747. var decoder = decodingContext.decoder;
  36748. var contexts = decodingContext.contextCache.getContexts('GB');
  36749. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  36750. // ...ooooo....
  36751. // ..ooooooo... Context template for current pixel (X)
  36752. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  36753. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  36754. for (i = 0; i < height; i++) {
  36755. row = bitmap[i] = new Uint8Array(width);
  36756. row1 = (i < 1) ? row : bitmap[i - 1];
  36757. row2 = (i < 2) ? row : bitmap[i - 2];
  36758. // At the beginning of each row:
  36759. // Fill contextLabel with pixels that are above/right of (X)
  36760. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  36761. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  36762. (row1[3] << 4);
  36763. for (j = 0; j < width; j++) {
  36764. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  36765. // At each pixel: Clear contextLabel pixels that are shifted
  36766. // out of the context, then add new ones.
  36767. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  36768. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  36769. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  36770. }
  36771. }
  36772. return bitmap;
  36773. }
  36774. // 6.2 Generic Region Decoding Procedure
  36775. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  36776. decodingContext) {
  36777. if (mmr) {
  36778. error('JBIG2 error: MMR encoding is not supported');
  36779. }
  36780. // Use optimized version for the most common case
  36781. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  36782. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  36783. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  36784. return decodeBitmapTemplate0(width, height, decodingContext);
  36785. }
  36786. var useskip = !!skip;
  36787. var template = CodingTemplates[templateIndex].concat(at);
  36788. // Sorting is non-standard, and it is not required. But sorting increases
  36789. // the number of template bits that can be reused from the previous
  36790. // contextLabel in the main loop.
  36791. template.sort(function (a, b) {
  36792. return (a.y - b.y) || (a.x - b.x);
  36793. });
  36794. var templateLength = template.length;
  36795. var templateX = new Int8Array(templateLength);
  36796. var templateY = new Int8Array(templateLength);
  36797. var changingTemplateEntries = [];
  36798. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  36799. var c, k;
  36800. for (k = 0; k < templateLength; k++) {
  36801. templateX[k] = template[k].x;
  36802. templateY[k] = template[k].y;
  36803. minX = Math.min(minX, template[k].x);
  36804. maxX = Math.max(maxX, template[k].x);
  36805. minY = Math.min(minY, template[k].y);
  36806. // Check if the template pixel appears in two consecutive context labels,
  36807. // so it can be reused. Otherwise, we add it to the list of changing
  36808. // template entries.
  36809. if (k < templateLength - 1 &&
  36810. template[k].y === template[k + 1].y &&
  36811. template[k].x === template[k + 1].x - 1) {
  36812. reuseMask |= 1 << (templateLength - 1 - k);
  36813. } else {
  36814. changingTemplateEntries.push(k);
  36815. }
  36816. }
  36817. var changingEntriesLength = changingTemplateEntries.length;
  36818. var changingTemplateX = new Int8Array(changingEntriesLength);
  36819. var changingTemplateY = new Int8Array(changingEntriesLength);
  36820. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  36821. for (c = 0; c < changingEntriesLength; c++) {
  36822. k = changingTemplateEntries[c];
  36823. changingTemplateX[c] = template[k].x;
  36824. changingTemplateY[c] = template[k].y;
  36825. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  36826. }
  36827. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  36828. var sbb_left = -minX;
  36829. var sbb_top = -minY;
  36830. var sbb_right = width - maxX;
  36831. var pseudoPixelContext = ReusedContexts[templateIndex];
  36832. var row = new Uint8Array(width);
  36833. var bitmap = [];
  36834. var decoder = decodingContext.decoder;
  36835. var contexts = decodingContext.contextCache.getContexts('GB');
  36836. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  36837. for (var i = 0; i < height; i++) {
  36838. if (prediction) {
  36839. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  36840. ltp ^= sltp;
  36841. if (ltp) {
  36842. bitmap.push(row); // duplicate previous row
  36843. continue;
  36844. }
  36845. }
  36846. row = new Uint8Array(row);
  36847. bitmap.push(row);
  36848. for (j = 0; j < width; j++) {
  36849. if (useskip && skip[i][j]) {
  36850. row[j] = 0;
  36851. continue;
  36852. }
  36853. // Are we in the middle of a scanline, so we can reuse contextLabel
  36854. // bits?
  36855. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  36856. // If yes, we can just shift the bits that are reusable and only
  36857. // fetch the remaining ones.
  36858. contextLabel = (contextLabel << 1) & reuseMask;
  36859. for (k = 0; k < changingEntriesLength; k++) {
  36860. i0 = i + changingTemplateY[k];
  36861. j0 = j + changingTemplateX[k];
  36862. bit = bitmap[i0][j0];
  36863. if (bit) {
  36864. bit = changingTemplateBit[k];
  36865. contextLabel |= bit;
  36866. }
  36867. }
  36868. } else {
  36869. // compute the contextLabel from scratch
  36870. contextLabel = 0;
  36871. shift = templateLength - 1;
  36872. for (k = 0; k < templateLength; k++, shift--) {
  36873. j0 = j + templateX[k];
  36874. if (j0 >= 0 && j0 < width) {
  36875. i0 = i + templateY[k];
  36876. if (i0 >= 0) {
  36877. bit = bitmap[i0][j0];
  36878. if (bit) {
  36879. contextLabel |= bit << shift;
  36880. }
  36881. }
  36882. }
  36883. }
  36884. }
  36885. var pixel = decoder.readBit(contexts, contextLabel);
  36886. row[j] = pixel;
  36887. }
  36888. }
  36889. return bitmap;
  36890. }
  36891. // 6.3.2 Generic Refinement Region Decoding Procedure
  36892. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  36893. offsetX, offsetY, prediction, at,
  36894. decodingContext) {
  36895. var codingTemplate = RefinementTemplates[templateIndex].coding;
  36896. if (templateIndex === 0) {
  36897. codingTemplate = codingTemplate.concat([at[0]]);
  36898. }
  36899. var codingTemplateLength = codingTemplate.length;
  36900. var codingTemplateX = new Int32Array(codingTemplateLength);
  36901. var codingTemplateY = new Int32Array(codingTemplateLength);
  36902. var k;
  36903. for (k = 0; k < codingTemplateLength; k++) {
  36904. codingTemplateX[k] = codingTemplate[k].x;
  36905. codingTemplateY[k] = codingTemplate[k].y;
  36906. }
  36907. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  36908. if (templateIndex === 0) {
  36909. referenceTemplate = referenceTemplate.concat([at[1]]);
  36910. }
  36911. var referenceTemplateLength = referenceTemplate.length;
  36912. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  36913. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  36914. for (k = 0; k < referenceTemplateLength; k++) {
  36915. referenceTemplateX[k] = referenceTemplate[k].x;
  36916. referenceTemplateY[k] = referenceTemplate[k].y;
  36917. }
  36918. var referenceWidth = referenceBitmap[0].length;
  36919. var referenceHeight = referenceBitmap.length;
  36920. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  36921. var bitmap = [];
  36922. var decoder = decodingContext.decoder;
  36923. var contexts = decodingContext.contextCache.getContexts('GR');
  36924. var ltp = 0;
  36925. for (var i = 0; i < height; i++) {
  36926. if (prediction) {
  36927. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  36928. ltp ^= sltp;
  36929. if (ltp) {
  36930. error('JBIG2 error: prediction is not supported');
  36931. }
  36932. }
  36933. var row = new Uint8Array(width);
  36934. bitmap.push(row);
  36935. for (var j = 0; j < width; j++) {
  36936. var i0, j0;
  36937. var contextLabel = 0;
  36938. for (k = 0; k < codingTemplateLength; k++) {
  36939. i0 = i + codingTemplateY[k];
  36940. j0 = j + codingTemplateX[k];
  36941. if (i0 < 0 || j0 < 0 || j0 >= width) {
  36942. contextLabel <<= 1; // out of bound pixel
  36943. } else {
  36944. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  36945. }
  36946. }
  36947. for (k = 0; k < referenceTemplateLength; k++) {
  36948. i0 = i + referenceTemplateY[k] + offsetY;
  36949. j0 = j + referenceTemplateX[k] + offsetX;
  36950. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  36951. j0 >= referenceWidth) {
  36952. contextLabel <<= 1; // out of bound pixel
  36953. } else {
  36954. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  36955. }
  36956. }
  36957. var pixel = decoder.readBit(contexts, contextLabel);
  36958. row[j] = pixel;
  36959. }
  36960. }
  36961. return bitmap;
  36962. }
  36963. // 6.5.5 Decoding the symbol dictionary
  36964. function decodeSymbolDictionary(huffman, refinement, symbols,
  36965. numberOfNewSymbols, numberOfExportedSymbols,
  36966. huffmanTables, templateIndex, at,
  36967. refinementTemplateIndex, refinementAt,
  36968. decodingContext) {
  36969. if (huffman) {
  36970. error('JBIG2 error: huffman is not supported');
  36971. }
  36972. var newSymbols = [];
  36973. var currentHeight = 0;
  36974. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  36975. var decoder = decodingContext.decoder;
  36976. var contextCache = decodingContext.contextCache;
  36977. while (newSymbols.length < numberOfNewSymbols) {
  36978. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  36979. currentHeight += deltaHeight;
  36980. var currentWidth = 0;
  36981. var totalWidth = 0;
  36982. while (true) {
  36983. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  36984. if (deltaWidth === null) {
  36985. break; // OOB
  36986. }
  36987. currentWidth += deltaWidth;
  36988. totalWidth += currentWidth;
  36989. var bitmap;
  36990. if (refinement) {
  36991. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  36992. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  36993. if (numberOfInstances > 1) {
  36994. bitmap = decodeTextRegion(huffman, refinement,
  36995. currentWidth, currentHeight, 0,
  36996. numberOfInstances, 1, //strip size
  36997. symbols.concat(newSymbols),
  36998. symbolCodeLength,
  36999. 0, //transposed
  37000. 0, //ds offset
  37001. 1, //top left 7.4.3.1.1
  37002. 0, //OR operator
  37003. huffmanTables,
  37004. refinementTemplateIndex, refinementAt,
  37005. decodingContext);
  37006. } else {
  37007. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  37008. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  37009. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  37010. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  37011. newSymbols[symbolId - symbols.length]);
  37012. bitmap = decodeRefinement(currentWidth, currentHeight,
  37013. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  37014. decodingContext);
  37015. }
  37016. } else {
  37017. // 6.5.8.1 Direct-coded symbol bitmap
  37018. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  37019. templateIndex, false, null, at, decodingContext);
  37020. }
  37021. newSymbols.push(bitmap);
  37022. }
  37023. }
  37024. // 6.5.10 Exported symbols
  37025. var exportedSymbols = [];
  37026. var flags = [], currentFlag = false;
  37027. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  37028. while (flags.length < totalSymbolsLength) {
  37029. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  37030. while (runLength--) {
  37031. flags.push(currentFlag);
  37032. }
  37033. currentFlag = !currentFlag;
  37034. }
  37035. for (var i = 0, ii = symbols.length; i < ii; i++) {
  37036. if (flags[i]) {
  37037. exportedSymbols.push(symbols[i]);
  37038. }
  37039. }
  37040. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  37041. if (flags[i]) {
  37042. exportedSymbols.push(newSymbols[j]);
  37043. }
  37044. }
  37045. return exportedSymbols;
  37046. }
  37047. function decodeTextRegion(huffman, refinement, width, height,
  37048. defaultPixelValue, numberOfSymbolInstances,
  37049. stripSize, inputSymbols, symbolCodeLength,
  37050. transposed, dsOffset, referenceCorner,
  37051. combinationOperator, huffmanTables,
  37052. refinementTemplateIndex, refinementAt,
  37053. decodingContext) {
  37054. if (huffman) {
  37055. error('JBIG2 error: huffman is not supported');
  37056. }
  37057. // Prepare bitmap
  37058. var bitmap = [];
  37059. var i, row;
  37060. for (i = 0; i < height; i++) {
  37061. row = new Uint8Array(width);
  37062. if (defaultPixelValue) {
  37063. for (var j = 0; j < width; j++) {
  37064. row[j] = defaultPixelValue;
  37065. }
  37066. }
  37067. bitmap.push(row);
  37068. }
  37069. var decoder = decodingContext.decoder;
  37070. var contextCache = decodingContext.contextCache;
  37071. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  37072. var firstS = 0;
  37073. i = 0;
  37074. while (i < numberOfSymbolInstances) {
  37075. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  37076. stripT += deltaT;
  37077. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  37078. firstS += deltaFirstS;
  37079. var currentS = firstS;
  37080. do {
  37081. var currentT = (stripSize === 1 ? 0 :
  37082. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  37083. var t = stripSize * stripT + currentT;
  37084. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  37085. var applyRefinement = (refinement &&
  37086. decodeInteger(contextCache, 'IARI', decoder));
  37087. var symbolBitmap = inputSymbols[symbolId];
  37088. var symbolWidth = symbolBitmap[0].length;
  37089. var symbolHeight = symbolBitmap.length;
  37090. if (applyRefinement) {
  37091. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  37092. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  37093. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  37094. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  37095. symbolWidth += rdw;
  37096. symbolHeight += rdh;
  37097. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  37098. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  37099. (rdh >> 1) + rdy, false, refinementAt,
  37100. decodingContext);
  37101. }
  37102. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  37103. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  37104. var s2, t2, symbolRow;
  37105. if (transposed) {
  37106. // Place Symbol Bitmap from T1,S1
  37107. for (s2 = 0; s2 < symbolHeight; s2++) {
  37108. row = bitmap[offsetS + s2];
  37109. if (!row) {
  37110. continue;
  37111. }
  37112. symbolRow = symbolBitmap[s2];
  37113. // To ignore Parts of Symbol bitmap which goes
  37114. // outside bitmap region
  37115. var maxWidth = Math.min(width - offsetT, symbolWidth);
  37116. switch (combinationOperator) {
  37117. case 0: // OR
  37118. for (t2 = 0; t2 < maxWidth; t2++) {
  37119. row[offsetT + t2] |= symbolRow[t2];
  37120. }
  37121. break;
  37122. case 2: // XOR
  37123. for (t2 = 0; t2 < maxWidth; t2++) {
  37124. row[offsetT + t2] ^= symbolRow[t2];
  37125. }
  37126. break;
  37127. default:
  37128. error('JBIG2 error: operator ' + combinationOperator +
  37129. ' is not supported');
  37130. }
  37131. }
  37132. currentS += symbolHeight - 1;
  37133. } else {
  37134. for (t2 = 0; t2 < symbolHeight; t2++) {
  37135. row = bitmap[offsetT + t2];
  37136. if (!row) {
  37137. continue;
  37138. }
  37139. symbolRow = symbolBitmap[t2];
  37140. switch (combinationOperator) {
  37141. case 0: // OR
  37142. for (s2 = 0; s2 < symbolWidth; s2++) {
  37143. row[offsetS + s2] |= symbolRow[s2];
  37144. }
  37145. break;
  37146. case 2: // XOR
  37147. for (s2 = 0; s2 < symbolWidth; s2++) {
  37148. row[offsetS + s2] ^= symbolRow[s2];
  37149. }
  37150. break;
  37151. default:
  37152. error('JBIG2 error: operator ' + combinationOperator +
  37153. ' is not supported');
  37154. }
  37155. }
  37156. currentS += symbolWidth - 1;
  37157. }
  37158. i++;
  37159. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  37160. if (deltaS === null) {
  37161. break; // OOB
  37162. }
  37163. currentS += deltaS + dsOffset;
  37164. } while (true);
  37165. }
  37166. return bitmap;
  37167. }
  37168. function readSegmentHeader(data, start) {
  37169. var segmentHeader = {};
  37170. segmentHeader.number = readUint32(data, start);
  37171. var flags = data[start + 4];
  37172. var segmentType = flags & 0x3F;
  37173. if (!SegmentTypes[segmentType]) {
  37174. error('JBIG2 error: invalid segment type: ' + segmentType);
  37175. }
  37176. segmentHeader.type = segmentType;
  37177. segmentHeader.typeName = SegmentTypes[segmentType];
  37178. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  37179. var pageAssociationFieldSize = !!(flags & 0x40);
  37180. var referredFlags = data[start + 5];
  37181. var referredToCount = (referredFlags >> 5) & 7;
  37182. var retainBits = [referredFlags & 31];
  37183. var position = start + 6;
  37184. if (referredFlags === 7) {
  37185. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  37186. position += 3;
  37187. var bytes = (referredToCount + 7) >> 3;
  37188. retainBits[0] = data[position++];
  37189. while (--bytes > 0) {
  37190. retainBits.push(data[position++]);
  37191. }
  37192. } else if (referredFlags === 5 || referredFlags === 6) {
  37193. error('JBIG2 error: invalid referred-to flags');
  37194. }
  37195. segmentHeader.retainBits = retainBits;
  37196. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  37197. (segmentHeader.number <= 65536 ? 2 : 4));
  37198. var referredTo = [];
  37199. var i, ii;
  37200. for (i = 0; i < referredToCount; i++) {
  37201. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  37202. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  37203. readUint32(data, position)));
  37204. referredTo.push(number);
  37205. position += referredToSegmentNumberSize;
  37206. }
  37207. segmentHeader.referredTo = referredTo;
  37208. if (!pageAssociationFieldSize) {
  37209. segmentHeader.pageAssociation = data[position++];
  37210. } else {
  37211. segmentHeader.pageAssociation = readUint32(data, position);
  37212. position += 4;
  37213. }
  37214. segmentHeader.length = readUint32(data, position);
  37215. position += 4;
  37216. if (segmentHeader.length === 0xFFFFFFFF) {
  37217. // 7.2.7 Segment data length, unknown segment length
  37218. if (segmentType === 38) { // ImmediateGenericRegion
  37219. var genericRegionInfo = readRegionSegmentInformation(data, position);
  37220. var genericRegionSegmentFlags = data[position +
  37221. RegionSegmentInformationFieldLength];
  37222. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  37223. // searching for the segment end
  37224. var searchPatternLength = 6;
  37225. var searchPattern = new Uint8Array(searchPatternLength);
  37226. if (!genericRegionMmr) {
  37227. searchPattern[0] = 0xFF;
  37228. searchPattern[1] = 0xAC;
  37229. }
  37230. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  37231. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  37232. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  37233. searchPattern[5] = genericRegionInfo.height & 0xFF;
  37234. for (i = position, ii = data.length; i < ii; i++) {
  37235. var j = 0;
  37236. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  37237. j++;
  37238. }
  37239. if (j === searchPatternLength) {
  37240. segmentHeader.length = i + searchPatternLength;
  37241. break;
  37242. }
  37243. }
  37244. if (segmentHeader.length === 0xFFFFFFFF) {
  37245. error('JBIG2 error: segment end was not found');
  37246. }
  37247. } else {
  37248. error('JBIG2 error: invalid unknown segment length');
  37249. }
  37250. }
  37251. segmentHeader.headerEnd = position;
  37252. return segmentHeader;
  37253. }
  37254. function readSegments(header, data, start, end) {
  37255. var segments = [];
  37256. var position = start;
  37257. while (position < end) {
  37258. var segmentHeader = readSegmentHeader(data, position);
  37259. position = segmentHeader.headerEnd;
  37260. var segment = {
  37261. header: segmentHeader,
  37262. data: data
  37263. };
  37264. if (!header.randomAccess) {
  37265. segment.start = position;
  37266. position += segmentHeader.length;
  37267. segment.end = position;
  37268. }
  37269. segments.push(segment);
  37270. if (segmentHeader.type === 51) {
  37271. break; // end of file is found
  37272. }
  37273. }
  37274. if (header.randomAccess) {
  37275. for (var i = 0, ii = segments.length; i < ii; i++) {
  37276. segments[i].start = position;
  37277. position += segments[i].header.length;
  37278. segments[i].end = position;
  37279. }
  37280. }
  37281. return segments;
  37282. }
  37283. // 7.4.1 Region segment information field
  37284. function readRegionSegmentInformation(data, start) {
  37285. return {
  37286. width: readUint32(data, start),
  37287. height: readUint32(data, start + 4),
  37288. x: readUint32(data, start + 8),
  37289. y: readUint32(data, start + 12),
  37290. combinationOperator: data[start + 16] & 7
  37291. };
  37292. }
  37293. var RegionSegmentInformationFieldLength = 17;
  37294. function processSegment(segment, visitor) {
  37295. var header = segment.header;
  37296. var data = segment.data, position = segment.start, end = segment.end;
  37297. var args, at, i, atLength;
  37298. switch (header.type) {
  37299. case 0: // SymbolDictionary
  37300. // 7.4.2 Symbol dictionary segment syntax
  37301. var dictionary = {};
  37302. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  37303. dictionary.huffman = !!(dictionaryFlags & 1);
  37304. dictionary.refinement = !!(dictionaryFlags & 2);
  37305. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  37306. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  37307. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  37308. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  37309. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  37310. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  37311. dictionary.template = (dictionaryFlags >> 10) & 3;
  37312. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  37313. position += 2;
  37314. if (!dictionary.huffman) {
  37315. atLength = dictionary.template === 0 ? 4 : 1;
  37316. at = [];
  37317. for (i = 0; i < atLength; i++) {
  37318. at.push({
  37319. x: readInt8(data, position),
  37320. y: readInt8(data, position + 1)
  37321. });
  37322. position += 2;
  37323. }
  37324. dictionary.at = at;
  37325. }
  37326. if (dictionary.refinement && !dictionary.refinementTemplate) {
  37327. at = [];
  37328. for (i = 0; i < 2; i++) {
  37329. at.push({
  37330. x: readInt8(data, position),
  37331. y: readInt8(data, position + 1)
  37332. });
  37333. position += 2;
  37334. }
  37335. dictionary.refinementAt = at;
  37336. }
  37337. dictionary.numberOfExportedSymbols = readUint32(data, position);
  37338. position += 4;
  37339. dictionary.numberOfNewSymbols = readUint32(data, position);
  37340. position += 4;
  37341. args = [dictionary, header.number, header.referredTo,
  37342. data, position, end];
  37343. break;
  37344. case 6: // ImmediateTextRegion
  37345. case 7: // ImmediateLosslessTextRegion
  37346. var textRegion = {};
  37347. textRegion.info = readRegionSegmentInformation(data, position);
  37348. position += RegionSegmentInformationFieldLength;
  37349. var textRegionSegmentFlags = readUint16(data, position);
  37350. position += 2;
  37351. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  37352. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  37353. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  37354. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  37355. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  37356. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  37357. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  37358. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  37359. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  37360. if (textRegion.huffman) {
  37361. var textRegionHuffmanFlags = readUint16(data, position);
  37362. position += 2;
  37363. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  37364. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  37365. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  37366. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  37367. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  37368. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  37369. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  37370. textRegion.huffmanRefinementSizeSelector =
  37371. !!(textRegionHuffmanFlags & 14);
  37372. }
  37373. if (textRegion.refinement && !textRegion.refinementTemplate) {
  37374. at = [];
  37375. for (i = 0; i < 2; i++) {
  37376. at.push({
  37377. x: readInt8(data, position),
  37378. y: readInt8(data, position + 1)
  37379. });
  37380. position += 2;
  37381. }
  37382. textRegion.refinementAt = at;
  37383. }
  37384. textRegion.numberOfSymbolInstances = readUint32(data, position);
  37385. position += 4;
  37386. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  37387. if (textRegion.huffman) {
  37388. error('JBIG2 error: huffman is not supported');
  37389. }
  37390. args = [textRegion, header.referredTo, data, position, end];
  37391. break;
  37392. case 38: // ImmediateGenericRegion
  37393. case 39: // ImmediateLosslessGenericRegion
  37394. var genericRegion = {};
  37395. genericRegion.info = readRegionSegmentInformation(data, position);
  37396. position += RegionSegmentInformationFieldLength;
  37397. var genericRegionSegmentFlags = data[position++];
  37398. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  37399. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  37400. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  37401. if (!genericRegion.mmr) {
  37402. atLength = genericRegion.template === 0 ? 4 : 1;
  37403. at = [];
  37404. for (i = 0; i < atLength; i++) {
  37405. at.push({
  37406. x: readInt8(data, position),
  37407. y: readInt8(data, position + 1)
  37408. });
  37409. position += 2;
  37410. }
  37411. genericRegion.at = at;
  37412. }
  37413. args = [genericRegion, data, position, end];
  37414. break;
  37415. case 48: // PageInformation
  37416. var pageInfo = {
  37417. width: readUint32(data, position),
  37418. height: readUint32(data, position + 4),
  37419. resolutionX: readUint32(data, position + 8),
  37420. resolutionY: readUint32(data, position + 12)
  37421. };
  37422. if (pageInfo.height === 0xFFFFFFFF) {
  37423. delete pageInfo.height;
  37424. }
  37425. var pageSegmentFlags = data[position + 16];
  37426. var pageStripingInformatiom = readUint16(data, position + 17);
  37427. pageInfo.lossless = !!(pageSegmentFlags & 1);
  37428. pageInfo.refinement = !!(pageSegmentFlags & 2);
  37429. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  37430. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  37431. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  37432. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  37433. args = [pageInfo];
  37434. break;
  37435. case 49: // EndOfPage
  37436. break;
  37437. case 50: // EndOfStripe
  37438. break;
  37439. case 51: // EndOfFile
  37440. break;
  37441. case 62: // 7.4.15 defines 2 extension types which
  37442. // are comments and can be ignored.
  37443. break;
  37444. default:
  37445. error('JBIG2 error: segment type ' + header.typeName + '(' +
  37446. header.type + ') is not implemented');
  37447. }
  37448. var callbackName = 'on' + header.typeName;
  37449. if (callbackName in visitor) {
  37450. visitor[callbackName].apply(visitor, args);
  37451. }
  37452. }
  37453. function processSegments(segments, visitor) {
  37454. for (var i = 0, ii = segments.length; i < ii; i++) {
  37455. processSegment(segments[i], visitor);
  37456. }
  37457. }
  37458. function parseJbig2(data, start, end) {
  37459. var position = start;
  37460. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  37461. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  37462. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  37463. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  37464. error('JBIG2 error: invalid header');
  37465. }
  37466. var header = {};
  37467. position += 8;
  37468. var flags = data[position++];
  37469. header.randomAccess = !(flags & 1);
  37470. if (!(flags & 2)) {
  37471. header.numberOfPages = readUint32(data, position);
  37472. position += 4;
  37473. }
  37474. var segments = readSegments(header, data, position, end);
  37475. error('Not implemented');
  37476. // processSegments(segments, new SimpleSegmentVisitor());
  37477. }
  37478. function parseJbig2Chunks(chunks) {
  37479. var visitor = new SimpleSegmentVisitor();
  37480. for (var i = 0, ii = chunks.length; i < ii; i++) {
  37481. var chunk = chunks[i];
  37482. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  37483. processSegments(segments, visitor);
  37484. }
  37485. return visitor.buffer;
  37486. }
  37487. function SimpleSegmentVisitor() {}
  37488. SimpleSegmentVisitor.prototype = {
  37489. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  37490. this.currentPageInfo = info;
  37491. var rowSize = (info.width + 7) >> 3;
  37492. var buffer = new Uint8Array(rowSize * info.height);
  37493. // The contents of ArrayBuffers are initialized to 0.
  37494. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  37495. if (info.defaultPixelValue) {
  37496. for (var i = 0, ii = buffer.length; i < ii; i++) {
  37497. buffer[i] = 0xFF;
  37498. }
  37499. }
  37500. this.buffer = buffer;
  37501. },
  37502. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  37503. var pageInfo = this.currentPageInfo;
  37504. var width = regionInfo.width, height = regionInfo.height;
  37505. var rowSize = (pageInfo.width + 7) >> 3;
  37506. var combinationOperator = pageInfo.combinationOperatorOverride ?
  37507. regionInfo.combinationOperator : pageInfo.combinationOperator;
  37508. var buffer = this.buffer;
  37509. var mask0 = 128 >> (regionInfo.x & 7);
  37510. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  37511. var i, j, mask, offset;
  37512. switch (combinationOperator) {
  37513. case 0: // OR
  37514. for (i = 0; i < height; i++) {
  37515. mask = mask0;
  37516. offset = offset0;
  37517. for (j = 0; j < width; j++) {
  37518. if (bitmap[i][j]) {
  37519. buffer[offset] |= mask;
  37520. }
  37521. mask >>= 1;
  37522. if (!mask) {
  37523. mask = 128;
  37524. offset++;
  37525. }
  37526. }
  37527. offset0 += rowSize;
  37528. }
  37529. break;
  37530. case 2: // XOR
  37531. for (i = 0; i < height; i++) {
  37532. mask = mask0;
  37533. offset = offset0;
  37534. for (j = 0; j < width; j++) {
  37535. if (bitmap[i][j]) {
  37536. buffer[offset] ^= mask;
  37537. }
  37538. mask >>= 1;
  37539. if (!mask) {
  37540. mask = 128;
  37541. offset++;
  37542. }
  37543. }
  37544. offset0 += rowSize;
  37545. }
  37546. break;
  37547. default:
  37548. error('JBIG2 error: operator ' + combinationOperator +
  37549. ' is not supported');
  37550. }
  37551. },
  37552. onImmediateGenericRegion:
  37553. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  37554. start, end) {
  37555. var regionInfo = region.info;
  37556. var decodingContext = new DecodingContext(data, start, end);
  37557. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  37558. region.template, region.prediction, null,
  37559. region.at, decodingContext);
  37560. this.drawBitmap(regionInfo, bitmap);
  37561. },
  37562. onImmediateLosslessGenericRegion:
  37563. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  37564. this.onImmediateGenericRegion.apply(this, arguments);
  37565. },
  37566. onSymbolDictionary:
  37567. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  37568. currentSegment,
  37569. referredSegments,
  37570. data, start, end) {
  37571. var huffmanTables;
  37572. if (dictionary.huffman) {
  37573. error('JBIG2 error: huffman is not supported');
  37574. }
  37575. // Combines exported symbols from all referred segments
  37576. var symbols = this.symbols;
  37577. if (!symbols) {
  37578. this.symbols = symbols = {};
  37579. }
  37580. var inputSymbols = [];
  37581. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  37582. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  37583. }
  37584. var decodingContext = new DecodingContext(data, start, end);
  37585. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  37586. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  37587. dictionary.numberOfExportedSymbols, huffmanTables,
  37588. dictionary.template, dictionary.at,
  37589. dictionary.refinementTemplate, dictionary.refinementAt,
  37590. decodingContext);
  37591. },
  37592. onImmediateTextRegion:
  37593. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  37594. referredSegments,
  37595. data, start, end) {
  37596. var regionInfo = region.info;
  37597. var huffmanTables;
  37598. // Combines exported symbols from all referred segments
  37599. var symbols = this.symbols;
  37600. var inputSymbols = [];
  37601. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  37602. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  37603. }
  37604. var symbolCodeLength = log2(inputSymbols.length);
  37605. var decodingContext = new DecodingContext(data, start, end);
  37606. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  37607. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  37608. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  37609. symbolCodeLength, region.transposed, region.dsOffset,
  37610. region.referenceCorner, region.combinationOperator, huffmanTables,
  37611. region.refinementTemplate, region.refinementAt, decodingContext);
  37612. this.drawBitmap(regionInfo, bitmap);
  37613. },
  37614. onImmediateLosslessTextRegion:
  37615. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  37616. this.onImmediateTextRegion.apply(this, arguments);
  37617. }
  37618. };
  37619. function Jbig2Image() {}
  37620. Jbig2Image.prototype = {
  37621. parseChunks: function Jbig2Image_parseChunks(chunks) {
  37622. return parseJbig2Chunks(chunks);
  37623. }
  37624. };
  37625. return Jbig2Image;
  37626. })();
  37627. var bidi = PDFJS.bidi = (function bidiClosure() {
  37628. // Character types for symbols from 0000 to 00FF.
  37629. var baseTypes = [
  37630. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  37631. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  37632. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  37633. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  37634. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  37635. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37636. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  37637. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37638. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37639. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  37640. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  37641. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  37642. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  37643. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  37644. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37645. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37646. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37647. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  37648. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  37649. ];
  37650. // Character types for symbols from 0600 to 06FF
  37651. var arabicTypes = [
  37652. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37653. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  37654. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37655. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37656. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37657. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37658. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  37659. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  37660. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  37661. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  37662. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37663. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37664. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37665. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37666. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37667. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37668. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37669. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37670. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  37671. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  37672. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  37673. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  37674. ];
  37675. function isOdd(i) {
  37676. return (i & 1) !== 0;
  37677. }
  37678. function isEven(i) {
  37679. return (i & 1) === 0;
  37680. }
  37681. function findUnequal(arr, start, value) {
  37682. for (var j = start, jj = arr.length; j < jj; ++j) {
  37683. if (arr[j] !== value) {
  37684. return j;
  37685. }
  37686. }
  37687. return j;
  37688. }
  37689. function setValues(arr, start, end, value) {
  37690. for (var j = start; j < end; ++j) {
  37691. arr[j] = value;
  37692. }
  37693. }
  37694. function reverseValues(arr, start, end) {
  37695. for (var i = start, j = end - 1; i < j; ++i, --j) {
  37696. var temp = arr[i];
  37697. arr[i] = arr[j];
  37698. arr[j] = temp;
  37699. }
  37700. }
  37701. function createBidiText(str, isLTR, vertical) {
  37702. return {
  37703. str: str,
  37704. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  37705. };
  37706. }
  37707. // These are used in bidi(), which is called frequently. We re-use them on
  37708. // each call to avoid unnecessary allocations.
  37709. var chars = [];
  37710. var types = [];
  37711. function bidi(str, startLevel, vertical) {
  37712. var isLTR = true;
  37713. var strLength = str.length;
  37714. if (strLength === 0 || vertical) {
  37715. return createBidiText(str, isLTR, vertical);
  37716. }
  37717. // Get types and fill arrays
  37718. chars.length = strLength;
  37719. types.length = strLength;
  37720. var numBidi = 0;
  37721. var i, ii;
  37722. for (i = 0; i < strLength; ++i) {
  37723. chars[i] = str.charAt(i);
  37724. var charCode = str.charCodeAt(i);
  37725. var charType = 'L';
  37726. if (charCode <= 0x00ff) {
  37727. charType = baseTypes[charCode];
  37728. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  37729. charType = 'R';
  37730. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  37731. charType = arabicTypes[charCode & 0xff];
  37732. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  37733. charType = 'AL';
  37734. }
  37735. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  37736. numBidi++;
  37737. }
  37738. types[i] = charType;
  37739. }
  37740. // Detect the bidi method
  37741. // - If there are no rtl characters then no bidi needed
  37742. // - If less than 30% chars are rtl then string is primarily ltr
  37743. // - If more than 30% chars are rtl then string is primarily rtl
  37744. if (numBidi === 0) {
  37745. isLTR = true;
  37746. return createBidiText(str, isLTR);
  37747. }
  37748. if (startLevel === -1) {
  37749. if ((strLength / numBidi) < 0.3) {
  37750. isLTR = true;
  37751. startLevel = 0;
  37752. } else {
  37753. isLTR = false;
  37754. startLevel = 1;
  37755. }
  37756. }
  37757. var levels = [];
  37758. for (i = 0; i < strLength; ++i) {
  37759. levels[i] = startLevel;
  37760. }
  37761. /*
  37762. X1-X10: skip most of this, since we are NOT doing the embeddings.
  37763. */
  37764. var e = (isOdd(startLevel) ? 'R' : 'L');
  37765. var sor = e;
  37766. var eor = sor;
  37767. /*
  37768. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  37769. type of the NSM to the type of the previous character. If the NSM is at the
  37770. start of the level run, it will get the type of sor.
  37771. */
  37772. var lastType = sor;
  37773. for (i = 0; i < strLength; ++i) {
  37774. if (types[i] === 'NSM') {
  37775. types[i] = lastType;
  37776. } else {
  37777. lastType = types[i];
  37778. }
  37779. }
  37780. /*
  37781. W2. Search backwards from each instance of a European number until the
  37782. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  37783. the type of the European number to Arabic number.
  37784. */
  37785. lastType = sor;
  37786. var t;
  37787. for (i = 0; i < strLength; ++i) {
  37788. t = types[i];
  37789. if (t === 'EN') {
  37790. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  37791. } else if (t === 'R' || t === 'L' || t === 'AL') {
  37792. lastType = t;
  37793. }
  37794. }
  37795. /*
  37796. W3. Change all ALs to R.
  37797. */
  37798. for (i = 0; i < strLength; ++i) {
  37799. t = types[i];
  37800. if (t === 'AL') {
  37801. types[i] = 'R';
  37802. }
  37803. }
  37804. /*
  37805. W4. A single European separator between two European numbers changes to a
  37806. European number. A single common separator between two numbers of the same
  37807. type changes to that type:
  37808. */
  37809. for (i = 1; i < strLength - 1; ++i) {
  37810. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  37811. types[i] = 'EN';
  37812. }
  37813. if (types[i] === 'CS' &&
  37814. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  37815. types[i + 1] === types[i - 1]) {
  37816. types[i] = types[i - 1];
  37817. }
  37818. }
  37819. /*
  37820. W5. A sequence of European terminators adjacent to European numbers changes
  37821. to all European numbers:
  37822. */
  37823. for (i = 0; i < strLength; ++i) {
  37824. if (types[i] === 'EN') {
  37825. // do before
  37826. var j;
  37827. for (j = i - 1; j >= 0; --j) {
  37828. if (types[j] !== 'ET') {
  37829. break;
  37830. }
  37831. types[j] = 'EN';
  37832. }
  37833. // do after
  37834. for (j = i + 1; j < strLength; --j) {
  37835. if (types[j] !== 'ET') {
  37836. break;
  37837. }
  37838. types[j] = 'EN';
  37839. }
  37840. }
  37841. }
  37842. /*
  37843. W6. Otherwise, separators and terminators change to Other Neutral:
  37844. */
  37845. for (i = 0; i < strLength; ++i) {
  37846. t = types[i];
  37847. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  37848. types[i] = 'ON';
  37849. }
  37850. }
  37851. /*
  37852. W7. Search backwards from each instance of a European number until the
  37853. first strong type (R, L, or sor) is found. If an L is found, then change
  37854. the type of the European number to L.
  37855. */
  37856. lastType = sor;
  37857. for (i = 0; i < strLength; ++i) {
  37858. t = types[i];
  37859. if (t === 'EN') {
  37860. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  37861. } else if (t === 'R' || t === 'L') {
  37862. lastType = t;
  37863. }
  37864. }
  37865. /*
  37866. N1. A sequence of neutrals takes the direction of the surrounding strong
  37867. text if the text on both sides has the same direction. European and Arabic
  37868. numbers are treated as though they were R. Start-of-level-run (sor) and
  37869. end-of-level-run (eor) are used at level run boundaries.
  37870. */
  37871. for (i = 0; i < strLength; ++i) {
  37872. if (types[i] === 'ON') {
  37873. var end = findUnequal(types, i + 1, 'ON');
  37874. var before = sor;
  37875. if (i > 0) {
  37876. before = types[i - 1];
  37877. }
  37878. var after = eor;
  37879. if (end + 1 < strLength) {
  37880. after = types[end + 1];
  37881. }
  37882. if (before !== 'L') {
  37883. before = 'R';
  37884. }
  37885. if (after !== 'L') {
  37886. after = 'R';
  37887. }
  37888. if (before === after) {
  37889. setValues(types, i, end, before);
  37890. }
  37891. i = end - 1; // reset to end (-1 so next iteration is ok)
  37892. }
  37893. }
  37894. /*
  37895. N2. Any remaining neutrals take the embedding direction.
  37896. */
  37897. for (i = 0; i < strLength; ++i) {
  37898. if (types[i] === 'ON') {
  37899. types[i] = e;
  37900. }
  37901. }
  37902. /*
  37903. I1. For all characters with an even (left-to-right) embedding direction,
  37904. those of type R go up one level and those of type AN or EN go up two
  37905. levels.
  37906. I2. For all characters with an odd (right-to-left) embedding direction,
  37907. those of type L, EN or AN go up one level.
  37908. */
  37909. for (i = 0; i < strLength; ++i) {
  37910. t = types[i];
  37911. if (isEven(levels[i])) {
  37912. if (t === 'R') {
  37913. levels[i] += 1;
  37914. } else if (t === 'AN' || t === 'EN') {
  37915. levels[i] += 2;
  37916. }
  37917. } else { // isOdd
  37918. if (t === 'L' || t === 'AN' || t === 'EN') {
  37919. levels[i] += 1;
  37920. }
  37921. }
  37922. }
  37923. /*
  37924. L1. On each line, reset the embedding level of the following characters to
  37925. the paragraph embedding level:
  37926. segment separators,
  37927. paragraph separators,
  37928. any sequence of whitespace characters preceding a segment separator or
  37929. paragraph separator, and any sequence of white space characters at the end
  37930. of the line.
  37931. */
  37932. // don't bother as text is only single line
  37933. /*
  37934. L2. From the highest level found in the text to the lowest odd level on
  37935. each line, reverse any contiguous sequence of characters that are at that
  37936. level or higher.
  37937. */
  37938. // find highest level & lowest odd level
  37939. var highestLevel = -1;
  37940. var lowestOddLevel = 99;
  37941. var level;
  37942. for (i = 0, ii = levels.length; i < ii; ++i) {
  37943. level = levels[i];
  37944. if (highestLevel < level) {
  37945. highestLevel = level;
  37946. }
  37947. if (lowestOddLevel > level && isOdd(level)) {
  37948. lowestOddLevel = level;
  37949. }
  37950. }
  37951. // now reverse between those limits
  37952. for (level = highestLevel; level >= lowestOddLevel; --level) {
  37953. // find segments to reverse
  37954. var start = -1;
  37955. for (i = 0, ii = levels.length; i < ii; ++i) {
  37956. if (levels[i] < level) {
  37957. if (start >= 0) {
  37958. reverseValues(chars, start, i);
  37959. start = -1;
  37960. }
  37961. } else if (start < 0) {
  37962. start = i;
  37963. }
  37964. }
  37965. if (start >= 0) {
  37966. reverseValues(chars, start, levels.length);
  37967. }
  37968. }
  37969. /*
  37970. L3. Combining marks applied to a right-to-left base character will at this
  37971. point precede their base character. If the rendering engine expects them to
  37972. follow the base characters in the final display process, then the ordering
  37973. of the marks and the base character must be reversed.
  37974. */
  37975. // don't bother for now
  37976. /*
  37977. L4. A character that possesses the mirrored property as specified by
  37978. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  37979. directionality of that character is R.
  37980. */
  37981. // don't mirror as characters are already mirrored in the pdf
  37982. // Finally, return string
  37983. for (i = 0, ii = chars.length; i < ii; ++i) {
  37984. var ch = chars[i];
  37985. if (ch === '<' || ch === '>') {
  37986. chars[i] = '';
  37987. }
  37988. }
  37989. return createBidiText(chars.join(''), isLTR);
  37990. }
  37991. return bidi;
  37992. })();
  37993. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  37994. // Workaround for missing math precison in JS.
  37995. var MASK_HIGH = 0xffff0000;
  37996. var MASK_LOW = 0xffff;
  37997. function MurmurHash3_64 (seed) {
  37998. var SEED = 0xc3d2e1f0;
  37999. this.h1 = seed ? seed & 0xffffffff : SEED;
  38000. this.h2 = seed ? seed & 0xffffffff : SEED;
  38001. }
  38002. var alwaysUseUint32ArrayView = false;
  38003. // old webkits have issues with non-aligned arrays
  38004. try {
  38005. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  38006. } catch (e) {
  38007. alwaysUseUint32ArrayView = true;
  38008. }
  38009. MurmurHash3_64.prototype = {
  38010. update: function MurmurHash3_64_update(input) {
  38011. var useUint32ArrayView = alwaysUseUint32ArrayView;
  38012. var i;
  38013. if (typeof input === 'string') {
  38014. var data = new Uint8Array(input.length * 2);
  38015. var length = 0;
  38016. for (i = 0; i < input.length; i++) {
  38017. var code = input.charCodeAt(i);
  38018. if (code <= 0xff) {
  38019. data[length++] = code;
  38020. }
  38021. else {
  38022. data[length++] = code >>> 8;
  38023. data[length++] = code & 0xff;
  38024. }
  38025. }
  38026. } else if (input instanceof Uint8Array) {
  38027. data = input;
  38028. length = data.length;
  38029. } else if (typeof input === 'object' && ('length' in input)) {
  38030. // processing regular arrays as well, e.g. for IE9
  38031. data = input;
  38032. length = data.length;
  38033. useUint32ArrayView = true;
  38034. } else {
  38035. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  38036. 'Input must be a string or array.');
  38037. }
  38038. var blockCounts = length >> 2;
  38039. var tailLength = length - blockCounts * 4;
  38040. // we don't care about endianness here
  38041. var dataUint32 = useUint32ArrayView ?
  38042. new Uint32ArrayView(data, blockCounts) :
  38043. new Uint32Array(data.buffer, 0, blockCounts);
  38044. var k1 = 0;
  38045. var k2 = 0;
  38046. var h1 = this.h1;
  38047. var h2 = this.h2;
  38048. var C1 = 0xcc9e2d51;
  38049. var C2 = 0x1b873593;
  38050. var C1_LOW = C1 & MASK_LOW;
  38051. var C2_LOW = C2 & MASK_LOW;
  38052. for (i = 0; i < blockCounts; i++) {
  38053. if (i & 1) {
  38054. k1 = dataUint32[i];
  38055. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  38056. k1 = k1 << 15 | k1 >>> 17;
  38057. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  38058. h1 ^= k1;
  38059. h1 = h1 << 13 | h1 >>> 19;
  38060. h1 = h1 * 5 + 0xe6546b64;
  38061. } else {
  38062. k2 = dataUint32[i];
  38063. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  38064. k2 = k2 << 15 | k2 >>> 17;
  38065. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  38066. h2 ^= k2;
  38067. h2 = h2 << 13 | h2 >>> 19;
  38068. h2 = h2 * 5 + 0xe6546b64;
  38069. }
  38070. }
  38071. k1 = 0;
  38072. switch (tailLength) {
  38073. case 3:
  38074. k1 ^= data[blockCounts * 4 + 2] << 16;
  38075. /* falls through */
  38076. case 2:
  38077. k1 ^= data[blockCounts * 4 + 1] << 8;
  38078. /* falls through */
  38079. case 1:
  38080. k1 ^= data[blockCounts * 4];
  38081. /* falls through */
  38082. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  38083. k1 = k1 << 15 | k1 >>> 17;
  38084. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  38085. if (blockCounts & 1) {
  38086. h1 ^= k1;
  38087. } else {
  38088. h2 ^= k1;
  38089. }
  38090. }
  38091. this.h1 = h1;
  38092. this.h2 = h2;
  38093. return this;
  38094. },
  38095. hexdigest: function MurmurHash3_64_hexdigest () {
  38096. var h1 = this.h1;
  38097. var h2 = this.h2;
  38098. h1 ^= h2 >>> 1;
  38099. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  38100. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  38101. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  38102. h1 ^= h2 >>> 1;
  38103. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  38104. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  38105. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  38106. h1 ^= h2 >>> 1;
  38107. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  38108. var hex = (arr[i] >>> 0).toString(16);
  38109. while (hex.length < 8) {
  38110. hex = '0' + hex;
  38111. }
  38112. str += hex;
  38113. }
  38114. return str;
  38115. }
  38116. };
  38117. return MurmurHash3_64;
  38118. })();
  38119. }).call((typeof window === 'undefined') ? this : window);
  38120. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  38121. // workerSrc is not set -- using last script url to define default location
  38122. PDFJS.workerSrc = (function () {
  38123. 'use strict';
  38124. var pdfJsSrc = document.currentScript.src;
  38125. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  38126. })();
  38127. }