pdf.worker.js 1.2 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.0.706';
  24. PDFJS.build = 'f543e86';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window === 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) === '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToBytes(str) {
  417. var length = str.length;
  418. var bytes = new Uint8Array(length);
  419. for (var i = 0; i < length; ++i) {
  420. bytes[i] = str.charCodeAt(i) & 0xFF;
  421. }
  422. return bytes;
  423. }
  424. function string32(value) {
  425. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  426. (value >> 8) & 0xff, value & 0xff);
  427. }
  428. function log2(x) {
  429. var n = 1, i = 0;
  430. while (x > n) {
  431. n <<= 1;
  432. i++;
  433. }
  434. return i;
  435. }
  436. function readInt8(data, start) {
  437. return (data[start] << 24) >> 24;
  438. }
  439. function readUint16(data, offset) {
  440. return (data[offset] << 8) | data[offset + 1];
  441. }
  442. function readUint32(data, offset) {
  443. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  444. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  445. }
  446. // Lazy test the endianness of the platform
  447. // NOTE: This will be 'true' for simulated TypedArrays
  448. function isLittleEndian() {
  449. var buffer8 = new Uint8Array(2);
  450. buffer8[0] = 1;
  451. var buffer16 = new Uint16Array(buffer8.buffer);
  452. return (buffer16[0] === 1);
  453. }
  454. Object.defineProperty(PDFJS, 'isLittleEndian', {
  455. configurable: true,
  456. get: function PDFJS_isLittleEndian() {
  457. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  458. }
  459. });
  460. // Lazy test if the userAgant support CanvasTypedArrays
  461. function hasCanvasTypedArrays() {
  462. var canvas = document.createElement('canvas');
  463. canvas.width = canvas.height = 1;
  464. var ctx = canvas.getContext('2d');
  465. var imageData = ctx.createImageData(1, 1);
  466. return (typeof imageData.data.buffer !== 'undefined');
  467. }
  468. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  469. configurable: true,
  470. get: function PDFJS_hasCanvasTypedArrays() {
  471. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  472. }
  473. });
  474. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  475. function Uint32ArrayView(buffer, length) {
  476. this.buffer = buffer;
  477. this.byteLength = buffer.length;
  478. this.length = length === undefined ? (this.byteLength >> 2) : length;
  479. ensureUint32ArrayViewProps(this.length);
  480. }
  481. Uint32ArrayView.prototype = Object.create(null);
  482. var uint32ArrayViewSetters = 0;
  483. function createUint32ArrayProp(index) {
  484. return {
  485. get: function () {
  486. var buffer = this.buffer, offset = index << 2;
  487. return (buffer[offset] | (buffer[offset + 1] << 8) |
  488. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  489. },
  490. set: function (value) {
  491. var buffer = this.buffer, offset = index << 2;
  492. buffer[offset] = value & 255;
  493. buffer[offset + 1] = (value >> 8) & 255;
  494. buffer[offset + 2] = (value >> 16) & 255;
  495. buffer[offset + 3] = (value >>> 24) & 255;
  496. }
  497. };
  498. }
  499. function ensureUint32ArrayViewProps(length) {
  500. while (uint32ArrayViewSetters < length) {
  501. Object.defineProperty(Uint32ArrayView.prototype,
  502. uint32ArrayViewSetters,
  503. createUint32ArrayProp(uint32ArrayViewSetters));
  504. uint32ArrayViewSetters++;
  505. }
  506. }
  507. return Uint32ArrayView;
  508. })();
  509. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  510. var Util = PDFJS.Util = (function UtilClosure() {
  511. function Util() {}
  512. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  513. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  514. // creating many intermediate strings.
  515. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  516. rgbBuf[1] = rgb[0];
  517. rgbBuf[3] = rgb[1];
  518. rgbBuf[5] = rgb[2];
  519. return rgbBuf.join('');
  520. };
  521. // Concatenates two transformation matrices together and returns the result.
  522. Util.transform = function Util_transform(m1, m2) {
  523. return [
  524. m1[0] * m2[0] + m1[2] * m2[1],
  525. m1[1] * m2[0] + m1[3] * m2[1],
  526. m1[0] * m2[2] + m1[2] * m2[3],
  527. m1[1] * m2[2] + m1[3] * m2[3],
  528. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  529. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  530. ];
  531. };
  532. // For 2d affine transforms
  533. Util.applyTransform = function Util_applyTransform(p, m) {
  534. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  535. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  536. return [xt, yt];
  537. };
  538. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  539. var d = m[0] * m[3] - m[1] * m[2];
  540. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  541. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  542. return [xt, yt];
  543. };
  544. // Applies the transform to the rectangle and finds the minimum axially
  545. // aligned bounding box.
  546. Util.getAxialAlignedBoundingBox =
  547. function Util_getAxialAlignedBoundingBox(r, m) {
  548. var p1 = Util.applyTransform(r, m);
  549. var p2 = Util.applyTransform(r.slice(2, 4), m);
  550. var p3 = Util.applyTransform([r[0], r[3]], m);
  551. var p4 = Util.applyTransform([r[2], r[1]], m);
  552. return [
  553. Math.min(p1[0], p2[0], p3[0], p4[0]),
  554. Math.min(p1[1], p2[1], p3[1], p4[1]),
  555. Math.max(p1[0], p2[0], p3[0], p4[0]),
  556. Math.max(p1[1], p2[1], p3[1], p4[1])
  557. ];
  558. };
  559. Util.inverseTransform = function Util_inverseTransform(m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  562. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  563. };
  564. // Apply a generic 3d matrix M on a 3-vector v:
  565. // | a b c | | X |
  566. // | d e f | x | Y |
  567. // | g h i | | Z |
  568. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  569. // with v as [X,Y,Z]
  570. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  571. return [
  572. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  573. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  574. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  575. ];
  576. };
  577. // This calculation uses Singular Value Decomposition.
  578. // The SVD can be represented with formula A = USV. We are interested in the
  579. // matrix S here because it represents the scale values.
  580. Util.singularValueDecompose2dScale =
  581. function Util_singularValueDecompose2dScale(m) {
  582. var transpose = [m[0], m[2], m[1], m[3]];
  583. // Multiply matrix m with its transpose.
  584. var a = m[0] * transpose[0] + m[1] * transpose[2];
  585. var b = m[0] * transpose[1] + m[1] * transpose[3];
  586. var c = m[2] * transpose[0] + m[3] * transpose[2];
  587. var d = m[2] * transpose[1] + m[3] * transpose[3];
  588. // Solve the second degree polynomial to get roots.
  589. var first = (a + d) / 2;
  590. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  591. var sx = first + second || 1;
  592. var sy = first - second || 1;
  593. // Scale values are the square roots of the eigenvalues.
  594. return [Math.sqrt(sx), Math.sqrt(sy)];
  595. };
  596. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  597. // For coordinate systems whose origin lies in the bottom-left, this
  598. // means normalization to (BL,TR) ordering. For systems with origin in the
  599. // top-left, this means (TL,BR) ordering.
  600. Util.normalizeRect = function Util_normalizeRect(rect) {
  601. var r = rect.slice(0); // clone rect
  602. if (rect[0] > rect[2]) {
  603. r[0] = rect[2];
  604. r[2] = rect[0];
  605. }
  606. if (rect[1] > rect[3]) {
  607. r[1] = rect[3];
  608. r[3] = rect[1];
  609. }
  610. return r;
  611. };
  612. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  613. // intersection of rect1 and rect2. If no intersection, returns 'false'
  614. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  615. Util.intersect = function Util_intersect(rect1, rect2) {
  616. function compare(a, b) {
  617. return a - b;
  618. }
  619. // Order points along the axes
  620. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  621. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  622. result = [];
  623. rect1 = Util.normalizeRect(rect1);
  624. rect2 = Util.normalizeRect(rect2);
  625. // X: first and second points belong to different rectangles?
  626. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  627. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  628. // Intersection must be between second and third points
  629. result[0] = orderedX[1];
  630. result[2] = orderedX[2];
  631. } else {
  632. return false;
  633. }
  634. // Y: first and second points belong to different rectangles?
  635. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  636. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  637. // Intersection must be between second and third points
  638. result[1] = orderedY[1];
  639. result[3] = orderedY[2];
  640. } else {
  641. return false;
  642. }
  643. return result;
  644. };
  645. Util.sign = function Util_sign(num) {
  646. return num < 0 ? -1 : 1;
  647. };
  648. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  649. Array.prototype.push.apply(arr1, arr2);
  650. };
  651. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  652. Array.prototype.unshift.apply(arr1, arr2);
  653. };
  654. Util.extendObj = function extendObj(obj1, obj2) {
  655. for (var key in obj2) {
  656. obj1[key] = obj2[key];
  657. }
  658. };
  659. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  660. name) {
  661. while (dict && !dict.has(name)) {
  662. dict = dict.get('Parent');
  663. }
  664. if (!dict) {
  665. return null;
  666. }
  667. return dict.get(name);
  668. };
  669. Util.inherit = function Util_inherit(sub, base, prototype) {
  670. sub.prototype = Object.create(base.prototype);
  671. sub.prototype.constructor = sub;
  672. for (var prop in prototype) {
  673. sub.prototype[prop] = prototype[prop];
  674. }
  675. };
  676. Util.loadScript = function Util_loadScript(src, callback) {
  677. var script = document.createElement('script');
  678. var loaded = false;
  679. script.setAttribute('src', src);
  680. if (callback) {
  681. script.onload = function() {
  682. if (!loaded) {
  683. callback();
  684. }
  685. loaded = true;
  686. };
  687. }
  688. document.getElementsByTagName('head')[0].appendChild(script);
  689. };
  690. return Util;
  691. })();
  692. /**
  693. * PDF page viewport created based on scale, rotation and offset.
  694. * @class
  695. * @alias PDFJS.PageViewport
  696. */
  697. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  698. /**
  699. * @constructor
  700. * @private
  701. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  702. * @param scale {number} scale of the viewport.
  703. * @param rotation {number} rotations of the viewport in degrees.
  704. * @param offsetX {number} offset X
  705. * @param offsetY {number} offset Y
  706. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  707. */
  708. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  709. this.viewBox = viewBox;
  710. this.scale = scale;
  711. this.rotation = rotation;
  712. this.offsetX = offsetX;
  713. this.offsetY = offsetY;
  714. // creating transform to convert pdf coordinate system to the normal
  715. // canvas like coordinates taking in account scale and rotation
  716. var centerX = (viewBox[2] + viewBox[0]) / 2;
  717. var centerY = (viewBox[3] + viewBox[1]) / 2;
  718. var rotateA, rotateB, rotateC, rotateD;
  719. rotation = rotation % 360;
  720. rotation = rotation < 0 ? rotation + 360 : rotation;
  721. switch (rotation) {
  722. case 180:
  723. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  724. break;
  725. case 90:
  726. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  727. break;
  728. case 270:
  729. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  730. break;
  731. //case 0:
  732. default:
  733. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  734. break;
  735. }
  736. if (dontFlip) {
  737. rotateC = -rotateC; rotateD = -rotateD;
  738. }
  739. var offsetCanvasX, offsetCanvasY;
  740. var width, height;
  741. if (rotateA === 0) {
  742. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  743. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  744. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  745. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  746. } else {
  747. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  748. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  749. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  750. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  751. }
  752. // creating transform for the following operations:
  753. // translate(-centerX, -centerY), rotate and flip vertically,
  754. // scale, and translate(offsetCanvasX, offsetCanvasY)
  755. this.transform = [
  756. rotateA * scale,
  757. rotateB * scale,
  758. rotateC * scale,
  759. rotateD * scale,
  760. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  761. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  762. ];
  763. this.width = width;
  764. this.height = height;
  765. this.fontScale = scale;
  766. }
  767. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  768. /**
  769. * Clones viewport with additional properties.
  770. * @param args {Object} (optional) If specified, may contain the 'scale' or
  771. * 'rotation' properties to override the corresponding properties in
  772. * the cloned viewport.
  773. * @returns {PDFJS.PageViewport} Cloned viewport.
  774. */
  775. clone: function PageViewPort_clone(args) {
  776. args = args || {};
  777. var scale = 'scale' in args ? args.scale : this.scale;
  778. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  779. return new PageViewport(this.viewBox.slice(), scale, rotation,
  780. this.offsetX, this.offsetY, args.dontFlip);
  781. },
  782. /**
  783. * Converts PDF point to the viewport coordinates. For examples, useful for
  784. * converting PDF location into canvas pixel coordinates.
  785. * @param x {number} X coordinate.
  786. * @param y {number} Y coordinate.
  787. * @returns {Object} Object that contains 'x' and 'y' properties of the
  788. * point in the viewport coordinate space.
  789. * @see {@link convertToPdfPoint}
  790. * @see {@link convertToViewportRectangle}
  791. */
  792. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  793. return Util.applyTransform([x, y], this.transform);
  794. },
  795. /**
  796. * Converts PDF rectangle to the viewport coordinates.
  797. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  798. * @returns {Array} Contains corresponding coordinates of the rectangle
  799. * in the viewport coordinate space.
  800. * @see {@link convertToViewportPoint}
  801. */
  802. convertToViewportRectangle:
  803. function PageViewport_convertToViewportRectangle(rect) {
  804. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  805. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  806. return [tl[0], tl[1], br[0], br[1]];
  807. },
  808. /**
  809. * Converts viewport coordinates to the PDF location. For examples, useful
  810. * for converting canvas pixel location into PDF one.
  811. * @param x {number} X coordinate.
  812. * @param y {number} Y coordinate.
  813. * @returns {Object} Object that contains 'x' and 'y' properties of the
  814. * point in the PDF coordinate space.
  815. * @see {@link convertToViewportPoint}
  816. */
  817. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  818. return Util.applyInverseTransform([x, y], this.transform);
  819. }
  820. };
  821. return PageViewport;
  822. })();
  823. var PDFStringTranslateTable = [
  824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  825. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  826. 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,
  827. 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,
  828. 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,
  829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  830. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  831. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  832. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  833. ];
  834. function stringToPDFString(str) {
  835. var i, n = str.length, strBuf = [];
  836. if (str[0] === '\xFE' && str[1] === '\xFF') {
  837. // UTF16BE BOM
  838. for (i = 2; i < n; i += 2) {
  839. strBuf.push(String.fromCharCode(
  840. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  841. }
  842. } else {
  843. for (i = 0; i < n; ++i) {
  844. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  845. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  846. }
  847. }
  848. return strBuf.join('');
  849. }
  850. function stringToUTF8String(str) {
  851. return decodeURIComponent(escape(str));
  852. }
  853. function isEmptyObj(obj) {
  854. for (var key in obj) {
  855. return false;
  856. }
  857. return true;
  858. }
  859. function isBool(v) {
  860. return typeof v === 'boolean';
  861. }
  862. function isInt(v) {
  863. return typeof v === 'number' && ((v | 0) === v);
  864. }
  865. function isNum(v) {
  866. return typeof v === 'number';
  867. }
  868. function isString(v) {
  869. return typeof v === 'string';
  870. }
  871. function isNull(v) {
  872. return v === null;
  873. }
  874. function isName(v) {
  875. return v instanceof Name;
  876. }
  877. function isCmd(v, cmd) {
  878. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  879. }
  880. function isDict(v, type) {
  881. if (!(v instanceof Dict)) {
  882. return false;
  883. }
  884. if (!type) {
  885. return true;
  886. }
  887. var dictType = v.get('Type');
  888. return isName(dictType) && dictType.name === type;
  889. }
  890. function isArray(v) {
  891. return v instanceof Array;
  892. }
  893. function isStream(v) {
  894. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  895. }
  896. function isArrayBuffer(v) {
  897. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  898. }
  899. function isRef(v) {
  900. return v instanceof Ref;
  901. }
  902. /**
  903. * Promise Capability object.
  904. *
  905. * @typedef {Object} PromiseCapability
  906. * @property {Promise} promise - A promise object.
  907. * @property {function} resolve - Fullfills the promise.
  908. * @property {function} reject - Rejects the promise.
  909. */
  910. /**
  911. * Creates a promise capability object.
  912. * @alias PDFJS.createPromiseCapability
  913. *
  914. * @return {PromiseCapability} A capability object contains:
  915. * - a Promise, resolve and reject methods.
  916. */
  917. function createPromiseCapability() {
  918. var capability = {};
  919. capability.promise = new Promise(function (resolve, reject) {
  920. capability.resolve = resolve;
  921. capability.reject = reject;
  922. });
  923. return capability;
  924. }
  925. PDFJS.createPromiseCapability = createPromiseCapability;
  926. /**
  927. * Polyfill for Promises:
  928. * The following promise implementation tries to generally implement the
  929. * Promise/A+ spec. Some notable differences from other promise libaries are:
  930. * - There currently isn't a seperate deferred and promise object.
  931. * - Unhandled rejections eventually show an error if they aren't handled.
  932. *
  933. * Based off of the work in:
  934. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  935. */
  936. (function PromiseClosure() {
  937. if (globalScope.Promise) {
  938. // Promises existing in the DOM/Worker, checking presence of all/resolve
  939. if (typeof globalScope.Promise.all !== 'function') {
  940. globalScope.Promise.all = function (iterable) {
  941. var count = 0, results = [], resolve, reject;
  942. var promise = new globalScope.Promise(function (resolve_, reject_) {
  943. resolve = resolve_;
  944. reject = reject_;
  945. });
  946. iterable.forEach(function (p, i) {
  947. count++;
  948. p.then(function (result) {
  949. results[i] = result;
  950. count--;
  951. if (count === 0) {
  952. resolve(results);
  953. }
  954. }, reject);
  955. });
  956. if (count === 0) {
  957. resolve(results);
  958. }
  959. return promise;
  960. };
  961. }
  962. if (typeof globalScope.Promise.resolve !== 'function') {
  963. globalScope.Promise.resolve = function (value) {
  964. return new globalScope.Promise(function (resolve) { resolve(value); });
  965. };
  966. }
  967. if (typeof globalScope.Promise.reject !== 'function') {
  968. globalScope.Promise.reject = function (reason) {
  969. return new globalScope.Promise(function (resolve, reject) {
  970. reject(reason);
  971. });
  972. };
  973. }
  974. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  975. globalScope.Promise.prototype.catch = function (onReject) {
  976. return globalScope.Promise.prototype.then(undefined, onReject);
  977. };
  978. }
  979. return;
  980. }
  981. var STATUS_PENDING = 0;
  982. var STATUS_RESOLVED = 1;
  983. var STATUS_REJECTED = 2;
  984. // In an attempt to avoid silent exceptions, unhandled rejections are
  985. // tracked and if they aren't handled in a certain amount of time an
  986. // error is logged.
  987. var REJECTION_TIMEOUT = 500;
  988. var HandlerManager = {
  989. handlers: [],
  990. running: false,
  991. unhandledRejections: [],
  992. pendingRejectionCheck: false,
  993. scheduleHandlers: function scheduleHandlers(promise) {
  994. if (promise._status === STATUS_PENDING) {
  995. return;
  996. }
  997. this.handlers = this.handlers.concat(promise._handlers);
  998. promise._handlers = [];
  999. if (this.running) {
  1000. return;
  1001. }
  1002. this.running = true;
  1003. setTimeout(this.runHandlers.bind(this), 0);
  1004. },
  1005. runHandlers: function runHandlers() {
  1006. var RUN_TIMEOUT = 1; // ms
  1007. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1008. while (this.handlers.length > 0) {
  1009. var handler = this.handlers.shift();
  1010. var nextStatus = handler.thisPromise._status;
  1011. var nextValue = handler.thisPromise._value;
  1012. try {
  1013. if (nextStatus === STATUS_RESOLVED) {
  1014. if (typeof handler.onResolve === 'function') {
  1015. nextValue = handler.onResolve(nextValue);
  1016. }
  1017. } else if (typeof handler.onReject === 'function') {
  1018. nextValue = handler.onReject(nextValue);
  1019. nextStatus = STATUS_RESOLVED;
  1020. if (handler.thisPromise._unhandledRejection) {
  1021. this.removeUnhandeledRejection(handler.thisPromise);
  1022. }
  1023. }
  1024. } catch (ex) {
  1025. nextStatus = STATUS_REJECTED;
  1026. nextValue = ex;
  1027. }
  1028. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1029. if (Date.now() >= timeoutAt) {
  1030. break;
  1031. }
  1032. }
  1033. if (this.handlers.length > 0) {
  1034. setTimeout(this.runHandlers.bind(this), 0);
  1035. return;
  1036. }
  1037. this.running = false;
  1038. },
  1039. addUnhandledRejection: function addUnhandledRejection(promise) {
  1040. this.unhandledRejections.push({
  1041. promise: promise,
  1042. time: Date.now()
  1043. });
  1044. this.scheduleRejectionCheck();
  1045. },
  1046. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1047. promise._unhandledRejection = false;
  1048. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1049. if (this.unhandledRejections[i].promise === promise) {
  1050. this.unhandledRejections.splice(i);
  1051. i--;
  1052. }
  1053. }
  1054. },
  1055. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1056. if (this.pendingRejectionCheck) {
  1057. return;
  1058. }
  1059. this.pendingRejectionCheck = true;
  1060. setTimeout(function rejectionCheck() {
  1061. this.pendingRejectionCheck = false;
  1062. var now = Date.now();
  1063. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1064. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1065. var unhandled = this.unhandledRejections[i].promise._value;
  1066. var msg = 'Unhandled rejection: ' + unhandled;
  1067. if (unhandled.stack) {
  1068. msg += '\n' + unhandled.stack;
  1069. }
  1070. warn(msg);
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. if (this.unhandledRejections.length) {
  1076. this.scheduleRejectionCheck();
  1077. }
  1078. }.bind(this), REJECTION_TIMEOUT);
  1079. }
  1080. };
  1081. function Promise(resolver) {
  1082. this._status = STATUS_PENDING;
  1083. this._handlers = [];
  1084. try {
  1085. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1086. } catch (e) {
  1087. this._reject(e);
  1088. }
  1089. }
  1090. /**
  1091. * Builds a promise that is resolved when all the passed in promises are
  1092. * resolved.
  1093. * @param {array} array of data and/or promises to wait for.
  1094. * @return {Promise} New dependant promise.
  1095. */
  1096. Promise.all = function Promise_all(promises) {
  1097. var resolveAll, rejectAll;
  1098. var deferred = new Promise(function (resolve, reject) {
  1099. resolveAll = resolve;
  1100. rejectAll = reject;
  1101. });
  1102. var unresolved = promises.length;
  1103. var results = [];
  1104. if (unresolved === 0) {
  1105. resolveAll(results);
  1106. return deferred;
  1107. }
  1108. function reject(reason) {
  1109. if (deferred._status === STATUS_REJECTED) {
  1110. return;
  1111. }
  1112. results = [];
  1113. rejectAll(reason);
  1114. }
  1115. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1116. var promise = promises[i];
  1117. var resolve = (function(i) {
  1118. return function(value) {
  1119. if (deferred._status === STATUS_REJECTED) {
  1120. return;
  1121. }
  1122. results[i] = value;
  1123. unresolved--;
  1124. if (unresolved === 0) {
  1125. resolveAll(results);
  1126. }
  1127. };
  1128. })(i);
  1129. if (Promise.isPromise(promise)) {
  1130. promise.then(resolve, reject);
  1131. } else {
  1132. resolve(promise);
  1133. }
  1134. }
  1135. return deferred;
  1136. };
  1137. /**
  1138. * Checks if the value is likely a promise (has a 'then' function).
  1139. * @return {boolean} true if value is thenable
  1140. */
  1141. Promise.isPromise = function Promise_isPromise(value) {
  1142. return value && typeof value.then === 'function';
  1143. };
  1144. /**
  1145. * Creates resolved promise
  1146. * @param value resolve value
  1147. * @returns {Promise}
  1148. */
  1149. Promise.resolve = function Promise_resolve(value) {
  1150. return new Promise(function (resolve) { resolve(value); });
  1151. };
  1152. /**
  1153. * Creates rejected promise
  1154. * @param reason rejection value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.reject = function Promise_reject(reason) {
  1158. return new Promise(function (resolve, reject) { reject(reason); });
  1159. };
  1160. Promise.prototype = {
  1161. _status: null,
  1162. _value: null,
  1163. _handlers: null,
  1164. _unhandledRejection: null,
  1165. _updateStatus: function Promise__updateStatus(status, value) {
  1166. if (this._status === STATUS_RESOLVED ||
  1167. this._status === STATUS_REJECTED) {
  1168. return;
  1169. }
  1170. if (status === STATUS_RESOLVED &&
  1171. Promise.isPromise(value)) {
  1172. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1173. this._updateStatus.bind(this, STATUS_REJECTED));
  1174. return;
  1175. }
  1176. this._status = status;
  1177. this._value = value;
  1178. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1179. this._unhandledRejection = true;
  1180. HandlerManager.addUnhandledRejection(this);
  1181. }
  1182. HandlerManager.scheduleHandlers(this);
  1183. },
  1184. _resolve: function Promise_resolve(value) {
  1185. this._updateStatus(STATUS_RESOLVED, value);
  1186. },
  1187. _reject: function Promise_reject(reason) {
  1188. this._updateStatus(STATUS_REJECTED, reason);
  1189. },
  1190. then: function Promise_then(onResolve, onReject) {
  1191. var nextPromise = new Promise(function (resolve, reject) {
  1192. this.resolve = resolve;
  1193. this.reject = reject;
  1194. });
  1195. this._handlers.push({
  1196. thisPromise: this,
  1197. onResolve: onResolve,
  1198. onReject: onReject,
  1199. nextPromise: nextPromise
  1200. });
  1201. HandlerManager.scheduleHandlers(this);
  1202. return nextPromise;
  1203. },
  1204. catch: function Promise_catch(onReject) {
  1205. return this.then(undefined, onReject);
  1206. }
  1207. };
  1208. globalScope.Promise = Promise;
  1209. })();
  1210. var StatTimer = (function StatTimerClosure() {
  1211. function rpad(str, pad, length) {
  1212. while (str.length < length) {
  1213. str += pad;
  1214. }
  1215. return str;
  1216. }
  1217. function StatTimer() {
  1218. this.started = {};
  1219. this.times = [];
  1220. this.enabled = true;
  1221. }
  1222. StatTimer.prototype = {
  1223. time: function StatTimer_time(name) {
  1224. if (!this.enabled) {
  1225. return;
  1226. }
  1227. if (name in this.started) {
  1228. warn('Timer is already running for ' + name);
  1229. }
  1230. this.started[name] = Date.now();
  1231. },
  1232. timeEnd: function StatTimer_timeEnd(name) {
  1233. if (!this.enabled) {
  1234. return;
  1235. }
  1236. if (!(name in this.started)) {
  1237. warn('Timer has not been started for ' + name);
  1238. }
  1239. this.times.push({
  1240. 'name': name,
  1241. 'start': this.started[name],
  1242. 'end': Date.now()
  1243. });
  1244. // Remove timer from started so it can be called again.
  1245. delete this.started[name];
  1246. },
  1247. toString: function StatTimer_toString() {
  1248. var i, ii;
  1249. var times = this.times;
  1250. var out = '';
  1251. // Find the longest name for padding purposes.
  1252. var longest = 0;
  1253. for (i = 0, ii = times.length; i < ii; ++i) {
  1254. var name = times[i]['name'];
  1255. if (name.length > longest) {
  1256. longest = name.length;
  1257. }
  1258. }
  1259. for (i = 0, ii = times.length; i < ii; ++i) {
  1260. var span = times[i];
  1261. var duration = span.end - span.start;
  1262. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1263. }
  1264. return out;
  1265. }
  1266. };
  1267. return StatTimer;
  1268. })();
  1269. PDFJS.createBlob = function createBlob(data, contentType) {
  1270. if (typeof Blob !== 'undefined') {
  1271. return new Blob([data], { type: contentType });
  1272. }
  1273. // Blob builder is deprecated in FF14 and removed in FF18.
  1274. var bb = new MozBlobBuilder();
  1275. bb.append(data);
  1276. return bb.getBlob(contentType);
  1277. };
  1278. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1279. // Blob/createObjectURL is not available, falling back to data schema.
  1280. var digits =
  1281. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1282. return function createObjectURL(data, contentType) {
  1283. if (!PDFJS.disableCreateObjectURL &&
  1284. typeof URL !== 'undefined' && URL.createObjectURL) {
  1285. var blob = PDFJS.createBlob(data, contentType);
  1286. return URL.createObjectURL(blob);
  1287. }
  1288. var buffer = 'data:' + contentType + ';base64,';
  1289. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1290. var b1 = data[i] & 0xFF;
  1291. var b2 = data[i + 1] & 0xFF;
  1292. var b3 = data[i + 2] & 0xFF;
  1293. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1294. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1295. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1296. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1297. }
  1298. return buffer;
  1299. };
  1300. })();
  1301. function MessageHandler(name, comObj) {
  1302. this.name = name;
  1303. this.comObj = comObj;
  1304. this.callbackIndex = 1;
  1305. this.postMessageTransfers = true;
  1306. var callbacksCapabilities = this.callbacksCapabilities = {};
  1307. var ah = this.actionHandler = {};
  1308. ah['console_log'] = [function ahConsoleLog(data) {
  1309. console.log.apply(console, data);
  1310. }];
  1311. ah['console_error'] = [function ahConsoleError(data) {
  1312. console.error.apply(console, data);
  1313. }];
  1314. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1315. UnsupportedManager.notify(data);
  1316. }];
  1317. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1318. var data = event.data;
  1319. if (data.isReply) {
  1320. var callbackId = data.callbackId;
  1321. if (data.callbackId in callbacksCapabilities) {
  1322. var callback = callbacksCapabilities[callbackId];
  1323. delete callbacksCapabilities[callbackId];
  1324. if ('error' in data) {
  1325. callback.reject(data.error);
  1326. } else {
  1327. callback.resolve(data.data);
  1328. }
  1329. } else {
  1330. error('Cannot resolve callback ' + callbackId);
  1331. }
  1332. } else if (data.action in ah) {
  1333. var action = ah[data.action];
  1334. if (data.callbackId) {
  1335. Promise.resolve().then(function () {
  1336. return action[0].call(action[1], data.data);
  1337. }).then(function (result) {
  1338. comObj.postMessage({
  1339. isReply: true,
  1340. callbackId: data.callbackId,
  1341. data: result
  1342. });
  1343. }, function (reason) {
  1344. comObj.postMessage({
  1345. isReply: true,
  1346. callbackId: data.callbackId,
  1347. error: reason
  1348. });
  1349. });
  1350. } else {
  1351. action[0].call(action[1], data.data);
  1352. }
  1353. } else {
  1354. error('Unknown action from worker: ' + data.action);
  1355. }
  1356. };
  1357. }
  1358. MessageHandler.prototype = {
  1359. on: function messageHandlerOn(actionName, handler, scope) {
  1360. var ah = this.actionHandler;
  1361. if (ah[actionName]) {
  1362. error('There is already an actionName called "' + actionName + '"');
  1363. }
  1364. ah[actionName] = [handler, scope];
  1365. },
  1366. /**
  1367. * Sends a message to the comObj to invoke the action with the supplied data.
  1368. * @param {String} actionName Action to call.
  1369. * @param {JSON} data JSON data to send.
  1370. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1371. */
  1372. send: function messageHandlerSend(actionName, data, transfers) {
  1373. var message = {
  1374. action: actionName,
  1375. data: data
  1376. };
  1377. this.postMessage(message, transfers);
  1378. },
  1379. /**
  1380. * Sends a message to the comObj to invoke the action with the supplied data.
  1381. * Expects that other side will callback with the response.
  1382. * @param {String} actionName Action to call.
  1383. * @param {JSON} data JSON data to send.
  1384. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1385. * @returns {Promise} Promise to be resolved with response data.
  1386. */
  1387. sendWithPromise:
  1388. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1389. var callbackId = this.callbackIndex++;
  1390. var message = {
  1391. action: actionName,
  1392. data: data,
  1393. callbackId: callbackId
  1394. };
  1395. var capability = createPromiseCapability();
  1396. this.callbacksCapabilities[callbackId] = capability;
  1397. try {
  1398. this.postMessage(message, transfers);
  1399. } catch (e) {
  1400. capability.reject(e);
  1401. }
  1402. return capability.promise;
  1403. },
  1404. /**
  1405. * Sends raw message to the comObj.
  1406. * @private
  1407. * @param message {Object} Raw message.
  1408. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1409. */
  1410. postMessage: function (message, transfers) {
  1411. if (transfers && this.postMessageTransfers) {
  1412. this.comObj.postMessage(message, transfers);
  1413. } else {
  1414. this.comObj.postMessage(message);
  1415. }
  1416. }
  1417. };
  1418. function loadJpegStream(id, imageUrl, objs) {
  1419. var img = new Image();
  1420. img.onload = (function loadJpegStream_onloadClosure() {
  1421. objs.resolve(id, img);
  1422. });
  1423. img.onerror = (function loadJpegStream_onerrorClosure() {
  1424. objs.resolve(id, null);
  1425. warn('Error during JPEG image loading');
  1426. });
  1427. img.src = imageUrl;
  1428. }
  1429. var NetworkManager = (function NetworkManagerClosure() {
  1430. var OK_RESPONSE = 200;
  1431. var PARTIAL_CONTENT_RESPONSE = 206;
  1432. function NetworkManager(url, args) {
  1433. this.url = url;
  1434. args = args || {};
  1435. this.isHttp = /^https?:/i.test(url);
  1436. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1437. this.withCredentials = args.withCredentials || false;
  1438. this.getXhr = args.getXhr ||
  1439. function NetworkManager_getXhr() {
  1440. return new XMLHttpRequest();
  1441. };
  1442. this.currXhrId = 0;
  1443. this.pendingRequests = {};
  1444. this.loadedRequests = {};
  1445. }
  1446. function getArrayBuffer(xhr) {
  1447. var data = xhr.response;
  1448. if (typeof data !== 'string') {
  1449. return data;
  1450. }
  1451. var length = data.length;
  1452. var buffer = new Uint8Array(length);
  1453. for (var i = 0; i < length; i++) {
  1454. buffer[i] = data.charCodeAt(i) & 0xFF;
  1455. }
  1456. return buffer;
  1457. }
  1458. NetworkManager.prototype = {
  1459. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1460. var args = {
  1461. begin: begin,
  1462. end: end
  1463. };
  1464. for (var prop in listeners) {
  1465. args[prop] = listeners[prop];
  1466. }
  1467. return this.request(args);
  1468. },
  1469. requestFull: function NetworkManager_requestRange(listeners) {
  1470. return this.request(listeners);
  1471. },
  1472. request: function NetworkManager_requestRange(args) {
  1473. var xhr = this.getXhr();
  1474. var xhrId = this.currXhrId++;
  1475. var pendingRequest = this.pendingRequests[xhrId] = {
  1476. xhr: xhr
  1477. };
  1478. xhr.open('GET', this.url);
  1479. xhr.withCredentials = this.withCredentials;
  1480. for (var property in this.httpHeaders) {
  1481. var value = this.httpHeaders[property];
  1482. if (typeof value === 'undefined') {
  1483. continue;
  1484. }
  1485. xhr.setRequestHeader(property, value);
  1486. }
  1487. if (this.isHttp && 'begin' in args && 'end' in args) {
  1488. var rangeStr = args.begin + '-' + (args.end - 1);
  1489. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1490. pendingRequest.expectedStatus = 206;
  1491. } else {
  1492. pendingRequest.expectedStatus = 200;
  1493. }
  1494. xhr.responseType = 'arraybuffer';
  1495. if (args.onProgress) {
  1496. xhr.onprogress = args.onProgress;
  1497. }
  1498. if (args.onError) {
  1499. xhr.onerror = function(evt) {
  1500. args.onError(xhr.status);
  1501. };
  1502. }
  1503. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1504. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1505. pendingRequest.onDone = args.onDone;
  1506. pendingRequest.onError = args.onError;
  1507. xhr.send(null);
  1508. return xhrId;
  1509. },
  1510. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1511. var pendingRequest = this.pendingRequests[xhrId];
  1512. if (!pendingRequest) {
  1513. // Maybe abortRequest was called...
  1514. return;
  1515. }
  1516. var xhr = pendingRequest.xhr;
  1517. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1518. pendingRequest.onHeadersReceived();
  1519. delete pendingRequest.onHeadersReceived;
  1520. }
  1521. if (xhr.readyState !== 4) {
  1522. return;
  1523. }
  1524. if (!(xhrId in this.pendingRequests)) {
  1525. // The XHR request might have been aborted in onHeadersReceived()
  1526. // callback, in which case we should abort request
  1527. return;
  1528. }
  1529. delete this.pendingRequests[xhrId];
  1530. // success status == 0 can be on ftp, file and other protocols
  1531. if (xhr.status === 0 && this.isHttp) {
  1532. if (pendingRequest.onError) {
  1533. pendingRequest.onError(xhr.status);
  1534. }
  1535. return;
  1536. }
  1537. var xhrStatus = xhr.status || OK_RESPONSE;
  1538. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1539. // "A server MAY ignore the Range header". This means it's possible to
  1540. // get a 200 rather than a 206 response from a range request.
  1541. var ok_response_on_range_request =
  1542. xhrStatus === OK_RESPONSE &&
  1543. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1544. if (!ok_response_on_range_request &&
  1545. xhrStatus !== pendingRequest.expectedStatus) {
  1546. if (pendingRequest.onError) {
  1547. pendingRequest.onError(xhr.status);
  1548. }
  1549. return;
  1550. }
  1551. this.loadedRequests[xhrId] = true;
  1552. var chunk = getArrayBuffer(xhr);
  1553. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1554. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1555. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1556. var begin = parseInt(matches[1], 10);
  1557. pendingRequest.onDone({
  1558. begin: begin,
  1559. chunk: chunk
  1560. });
  1561. } else {
  1562. pendingRequest.onDone({
  1563. begin: 0,
  1564. chunk: chunk
  1565. });
  1566. }
  1567. },
  1568. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1569. for (var xhrId in this.pendingRequests) {
  1570. return true;
  1571. }
  1572. return false;
  1573. },
  1574. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1575. return this.pendingRequests[xhrId].xhr;
  1576. },
  1577. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1578. return xhrId in this.pendingRequests;
  1579. },
  1580. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1581. return xhrId in this.loadedRequests;
  1582. },
  1583. abortAllRequests: function NetworkManager_abortAllRequests() {
  1584. for (var xhrId in this.pendingRequests) {
  1585. this.abortRequest(xhrId | 0);
  1586. }
  1587. },
  1588. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1589. var xhr = this.pendingRequests[xhrId].xhr;
  1590. delete this.pendingRequests[xhrId];
  1591. xhr.abort();
  1592. }
  1593. };
  1594. return NetworkManager;
  1595. })();
  1596. var ChunkedStream = (function ChunkedStreamClosure() {
  1597. function ChunkedStream(length, chunkSize, manager) {
  1598. this.bytes = new Uint8Array(length);
  1599. this.start = 0;
  1600. this.pos = 0;
  1601. this.end = length;
  1602. this.chunkSize = chunkSize;
  1603. this.loadedChunks = [];
  1604. this.numChunksLoaded = 0;
  1605. this.numChunks = Math.ceil(length / chunkSize);
  1606. this.manager = manager;
  1607. this.initialDataLength = 0;
  1608. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1609. }
  1610. // required methods for a stream. if a particular stream does not
  1611. // implement these, an error should be thrown
  1612. ChunkedStream.prototype = {
  1613. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1614. var chunks = [];
  1615. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1616. if (!(chunk in this.loadedChunks)) {
  1617. chunks.push(chunk);
  1618. }
  1619. }
  1620. return chunks;
  1621. },
  1622. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1623. return [this];
  1624. },
  1625. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1626. return this.numChunksLoaded === this.numChunks;
  1627. },
  1628. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1629. var end = begin + chunk.byteLength;
  1630. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1631. // Using this.length is inaccurate here since this.start can be moved
  1632. // See ChunkedStream.moveStart()
  1633. var length = this.bytes.length;
  1634. assert(end % this.chunkSize === 0 || end === length,
  1635. 'Bad end offset: ' + end);
  1636. this.bytes.set(new Uint8Array(chunk), begin);
  1637. var chunkSize = this.chunkSize;
  1638. var beginChunk = Math.floor(begin / chunkSize);
  1639. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1640. var curChunk;
  1641. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1642. if (!(curChunk in this.loadedChunks)) {
  1643. this.loadedChunks[curChunk] = true;
  1644. ++this.numChunksLoaded;
  1645. }
  1646. }
  1647. },
  1648. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  1649. this.bytes.set(data);
  1650. this.initialDataLength = data.length;
  1651. var endChunk = (this.end === data.length ?
  1652. this.numChunks : Math.floor(data.length / this.chunkSize));
  1653. for (var i = 0; i < endChunk; i++) {
  1654. this.loadedChunks[i] = true;
  1655. ++this.numChunksLoaded;
  1656. }
  1657. },
  1658. ensureByte: function ChunkedStream_ensureRange(pos) {
  1659. var chunk = Math.floor(pos / this.chunkSize);
  1660. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1661. return;
  1662. }
  1663. if (!(chunk in this.loadedChunks)) {
  1664. throw new MissingDataException(pos, pos + 1);
  1665. }
  1666. this.lastSuccessfulEnsureByteChunk = chunk;
  1667. },
  1668. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1669. if (begin >= end) {
  1670. return;
  1671. }
  1672. if (end <= this.initialDataLength) {
  1673. return;
  1674. }
  1675. var chunkSize = this.chunkSize;
  1676. var beginChunk = Math.floor(begin / chunkSize);
  1677. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1678. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1679. if (!(chunk in this.loadedChunks)) {
  1680. throw new MissingDataException(begin, end);
  1681. }
  1682. }
  1683. },
  1684. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1685. var chunk, n;
  1686. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1687. if (!(chunk in this.loadedChunks)) {
  1688. return chunk;
  1689. }
  1690. }
  1691. // Wrap around to beginning
  1692. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1693. if (!(chunk in this.loadedChunks)) {
  1694. return chunk;
  1695. }
  1696. }
  1697. return null;
  1698. },
  1699. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1700. return chunk in this.loadedChunks;
  1701. },
  1702. get length() {
  1703. return this.end - this.start;
  1704. },
  1705. get isEmpty() {
  1706. return this.length === 0;
  1707. },
  1708. getByte: function ChunkedStream_getByte() {
  1709. var pos = this.pos;
  1710. if (pos >= this.end) {
  1711. return -1;
  1712. }
  1713. this.ensureByte(pos);
  1714. return this.bytes[this.pos++];
  1715. },
  1716. getUint16: function ChunkedStream_getUint16() {
  1717. var b0 = this.getByte();
  1718. var b1 = this.getByte();
  1719. return (b0 << 8) + b1;
  1720. },
  1721. getInt32: function ChunkedStream_getInt32() {
  1722. var b0 = this.getByte();
  1723. var b1 = this.getByte();
  1724. var b2 = this.getByte();
  1725. var b3 = this.getByte();
  1726. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1727. },
  1728. // returns subarray of original buffer
  1729. // should only be read
  1730. getBytes: function ChunkedStream_getBytes(length) {
  1731. var bytes = this.bytes;
  1732. var pos = this.pos;
  1733. var strEnd = this.end;
  1734. if (!length) {
  1735. this.ensureRange(pos, strEnd);
  1736. return bytes.subarray(pos, strEnd);
  1737. }
  1738. var end = pos + length;
  1739. if (end > strEnd) {
  1740. end = strEnd;
  1741. }
  1742. this.ensureRange(pos, end);
  1743. this.pos = end;
  1744. return bytes.subarray(pos, end);
  1745. },
  1746. peekBytes: function ChunkedStream_peekBytes(length) {
  1747. var bytes = this.getBytes(length);
  1748. this.pos -= bytes.length;
  1749. return bytes;
  1750. },
  1751. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1752. this.ensureRange(begin, end);
  1753. return this.bytes.subarray(begin, end);
  1754. },
  1755. skip: function ChunkedStream_skip(n) {
  1756. if (!n) {
  1757. n = 1;
  1758. }
  1759. this.pos += n;
  1760. },
  1761. reset: function ChunkedStream_reset() {
  1762. this.pos = this.start;
  1763. },
  1764. moveStart: function ChunkedStream_moveStart() {
  1765. this.start = this.pos;
  1766. },
  1767. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1768. this.ensureRange(start, start + length);
  1769. function ChunkedStreamSubstream() {}
  1770. ChunkedStreamSubstream.prototype = Object.create(this);
  1771. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1772. var chunkSize = this.chunkSize;
  1773. var beginChunk = Math.floor(this.start / chunkSize);
  1774. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1775. var missingChunks = [];
  1776. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1777. if (!(chunk in this.loadedChunks)) {
  1778. missingChunks.push(chunk);
  1779. }
  1780. }
  1781. return missingChunks;
  1782. };
  1783. var subStream = new ChunkedStreamSubstream();
  1784. subStream.pos = subStream.start = start;
  1785. subStream.end = start + length || this.end;
  1786. subStream.dict = dict;
  1787. return subStream;
  1788. },
  1789. isStream: true
  1790. };
  1791. return ChunkedStream;
  1792. })();
  1793. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1794. function ChunkedStreamManager(length, chunkSize, url, args) {
  1795. this.stream = new ChunkedStream(length, chunkSize, this);
  1796. this.length = length;
  1797. this.chunkSize = chunkSize;
  1798. this.url = url;
  1799. this.disableAutoFetch = args.disableAutoFetch;
  1800. var msgHandler = this.msgHandler = args.msgHandler;
  1801. if (args.chunkedViewerLoading) {
  1802. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1803. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1804. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1805. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1806. };
  1807. } else {
  1808. var getXhr = function getXhr() {
  1809. return new XMLHttpRequest();
  1810. };
  1811. this.networkManager = new NetworkManager(this.url, {
  1812. getXhr: getXhr,
  1813. httpHeaders: args.httpHeaders,
  1814. withCredentials: args.withCredentials
  1815. });
  1816. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1817. this.networkManager.requestRange(begin, end, {
  1818. onDone: this.onReceiveData.bind(this),
  1819. onProgress: this.onProgress.bind(this)
  1820. });
  1821. };
  1822. }
  1823. this.currRequestId = 0;
  1824. this.chunksNeededByRequest = {};
  1825. this.requestsByChunk = {};
  1826. this.callbacksByRequest = {};
  1827. this._loadedStreamCapability = createPromiseCapability();
  1828. if (args.initialData) {
  1829. this.setInitialData(args.initialData);
  1830. }
  1831. }
  1832. ChunkedStreamManager.prototype = {
  1833. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  1834. this.stream.onReceiveInitialData(data);
  1835. if (this.stream.allChunksLoaded()) {
  1836. this._loadedStreamCapability.resolve(this.stream);
  1837. } else if (this.msgHandler) {
  1838. this.msgHandler.send('DocProgress', {
  1839. loaded: data.length,
  1840. total: this.length
  1841. });
  1842. }
  1843. },
  1844. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1845. return this._loadedStreamCapability.promise;
  1846. },
  1847. // Get all the chunks that are not yet loaded and groups them into
  1848. // contiguous ranges to load in as few requests as possible
  1849. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1850. var missingChunks = this.stream.getMissingChunks();
  1851. this.requestChunks(missingChunks);
  1852. return this._loadedStreamCapability.promise;
  1853. },
  1854. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1855. callback) {
  1856. var requestId = this.currRequestId++;
  1857. var chunksNeeded;
  1858. var i, ii;
  1859. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1860. for (i = 0, ii = chunks.length; i < ii; i++) {
  1861. if (!this.stream.hasChunk(chunks[i])) {
  1862. chunksNeeded[chunks[i]] = true;
  1863. }
  1864. }
  1865. if (isEmptyObj(chunksNeeded)) {
  1866. if (callback) {
  1867. callback();
  1868. }
  1869. return;
  1870. }
  1871. this.callbacksByRequest[requestId] = callback;
  1872. var chunksToRequest = [];
  1873. for (var chunk in chunksNeeded) {
  1874. chunk = chunk | 0;
  1875. if (!(chunk in this.requestsByChunk)) {
  1876. this.requestsByChunk[chunk] = [];
  1877. chunksToRequest.push(chunk);
  1878. }
  1879. this.requestsByChunk[chunk].push(requestId);
  1880. }
  1881. if (!chunksToRequest.length) {
  1882. return;
  1883. }
  1884. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1885. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1886. var groupedChunk = groupedChunksToRequest[i];
  1887. var begin = groupedChunk.beginChunk * this.chunkSize;
  1888. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1889. this.sendRequest(begin, end);
  1890. }
  1891. },
  1892. getStream: function ChunkedStreamManager_getStream() {
  1893. return this.stream;
  1894. },
  1895. // Loads any chunks in the requested range that are not yet loaded
  1896. requestRange: function ChunkedStreamManager_requestRange(
  1897. begin, end, callback) {
  1898. end = Math.min(end, this.length);
  1899. var beginChunk = this.getBeginChunk(begin);
  1900. var endChunk = this.getEndChunk(end);
  1901. var chunks = [];
  1902. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1903. chunks.push(chunk);
  1904. }
  1905. this.requestChunks(chunks, callback);
  1906. },
  1907. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1908. callback) {
  1909. ranges = ranges || [];
  1910. var chunksToRequest = [];
  1911. for (var i = 0; i < ranges.length; i++) {
  1912. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1913. var endChunk = this.getEndChunk(ranges[i].end);
  1914. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1915. if (chunksToRequest.indexOf(chunk) < 0) {
  1916. chunksToRequest.push(chunk);
  1917. }
  1918. }
  1919. }
  1920. chunksToRequest.sort(function(a, b) { return a - b; });
  1921. this.requestChunks(chunksToRequest, callback);
  1922. },
  1923. // Groups a sorted array of chunks into as few continguous larger
  1924. // chunks as possible
  1925. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1926. var groupedChunks = [];
  1927. var beginChunk = -1;
  1928. var prevChunk = -1;
  1929. for (var i = 0; i < chunks.length; ++i) {
  1930. var chunk = chunks[i];
  1931. if (beginChunk < 0) {
  1932. beginChunk = chunk;
  1933. }
  1934. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1935. groupedChunks.push({ beginChunk: beginChunk,
  1936. endChunk: prevChunk + 1 });
  1937. beginChunk = chunk;
  1938. }
  1939. if (i + 1 === chunks.length) {
  1940. groupedChunks.push({ beginChunk: beginChunk,
  1941. endChunk: chunk + 1 });
  1942. }
  1943. prevChunk = chunk;
  1944. }
  1945. return groupedChunks;
  1946. },
  1947. onProgress: function ChunkedStreamManager_onProgress(args) {
  1948. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1949. args.loaded);
  1950. this.msgHandler.send('DocProgress', {
  1951. loaded: bytesLoaded,
  1952. total: this.length
  1953. });
  1954. },
  1955. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  1956. var chunk = args.chunk;
  1957. var begin = args.begin;
  1958. var end = begin + chunk.byteLength;
  1959. var beginChunk = this.getBeginChunk(begin);
  1960. var endChunk = this.getEndChunk(end);
  1961. this.stream.onReceiveData(begin, chunk);
  1962. if (this.stream.allChunksLoaded()) {
  1963. this._loadedStreamCapability.resolve(this.stream);
  1964. }
  1965. var loadedRequests = [];
  1966. var i, requestId;
  1967. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  1968. // The server might return more chunks than requested
  1969. var requestIds = this.requestsByChunk[chunk] || [];
  1970. delete this.requestsByChunk[chunk];
  1971. for (i = 0; i < requestIds.length; ++i) {
  1972. requestId = requestIds[i];
  1973. var chunksNeeded = this.chunksNeededByRequest[requestId];
  1974. if (chunk in chunksNeeded) {
  1975. delete chunksNeeded[chunk];
  1976. }
  1977. if (!isEmptyObj(chunksNeeded)) {
  1978. continue;
  1979. }
  1980. loadedRequests.push(requestId);
  1981. }
  1982. }
  1983. // If there are no pending requests, automatically fetch the next
  1984. // unfetched chunk of the PDF
  1985. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  1986. var nextEmptyChunk;
  1987. if (this.stream.numChunksLoaded === 1) {
  1988. // This is a special optimization so that after fetching the first
  1989. // chunk, rather than fetching the second chunk, we fetch the last
  1990. // chunk.
  1991. var lastChunk = this.stream.numChunks - 1;
  1992. if (!this.stream.hasChunk(lastChunk)) {
  1993. nextEmptyChunk = lastChunk;
  1994. }
  1995. } else {
  1996. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  1997. }
  1998. if (isInt(nextEmptyChunk)) {
  1999. this.requestChunks([nextEmptyChunk]);
  2000. }
  2001. }
  2002. for (i = 0; i < loadedRequests.length; ++i) {
  2003. requestId = loadedRequests[i];
  2004. var callback = this.callbacksByRequest[requestId];
  2005. delete this.callbacksByRequest[requestId];
  2006. if (callback) {
  2007. callback();
  2008. }
  2009. }
  2010. this.msgHandler.send('DocProgress', {
  2011. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2012. total: this.length
  2013. });
  2014. },
  2015. onError: function ChunkedStreamManager_onError(err) {
  2016. this._loadedStreamCapability.reject(err);
  2017. },
  2018. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2019. var chunk = Math.floor(begin / this.chunkSize);
  2020. return chunk;
  2021. },
  2022. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2023. if (end % this.chunkSize === 0) {
  2024. return end / this.chunkSize;
  2025. }
  2026. // 0 -> 0
  2027. // 1 -> 1
  2028. // 99 -> 1
  2029. // 100 -> 1
  2030. // 101 -> 2
  2031. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2032. return chunk;
  2033. }
  2034. };
  2035. return ChunkedStreamManager;
  2036. })();
  2037. // The maximum number of bytes fetched per range request
  2038. var RANGE_CHUNK_SIZE = 65536;
  2039. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2040. var BasePdfManager = (function BasePdfManagerClosure() {
  2041. function BasePdfManager() {
  2042. throw new Error('Cannot initialize BaseManagerManager');
  2043. }
  2044. BasePdfManager.prototype = {
  2045. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2046. throw new NotImplementedException();
  2047. },
  2048. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2049. return this.ensure(this.pdfDocument, prop, args);
  2050. },
  2051. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2052. return this.ensure(this.pdfDocument.xref, prop, args);
  2053. },
  2054. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2055. return this.ensure(this.pdfDocument.catalog, prop, args);
  2056. },
  2057. getPage: function BasePdfManager_pagePage(pageIndex) {
  2058. return this.pdfDocument.getPage(pageIndex);
  2059. },
  2060. cleanup: function BasePdfManager_cleanup() {
  2061. return this.pdfDocument.cleanup();
  2062. },
  2063. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2064. return new NotImplementedException();
  2065. },
  2066. requestRange: function BasePdfManager_ensure(begin, end) {
  2067. return new NotImplementedException();
  2068. },
  2069. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2070. return new NotImplementedException();
  2071. },
  2072. updatePassword: function BasePdfManager_updatePassword(password) {
  2073. this.pdfDocument.xref.password = this.password = password;
  2074. if (this._passwordChangedCapability) {
  2075. this._passwordChangedCapability.resolve();
  2076. }
  2077. },
  2078. passwordChanged: function BasePdfManager_passwordChanged() {
  2079. this._passwordChangedCapability = createPromiseCapability();
  2080. return this._passwordChangedCapability.promise;
  2081. },
  2082. terminate: function BasePdfManager_terminate() {
  2083. return new NotImplementedException();
  2084. }
  2085. };
  2086. return BasePdfManager;
  2087. })();
  2088. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2089. function LocalPdfManager(data, password) {
  2090. var stream = new Stream(data);
  2091. this.pdfDocument = new PDFDocument(this, stream, password);
  2092. this._loadedStreamCapability = createPromiseCapability();
  2093. this._loadedStreamCapability.resolve(stream);
  2094. }
  2095. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2096. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2097. LocalPdfManager.prototype.ensure =
  2098. function LocalPdfManager_ensure(obj, prop, args) {
  2099. return new Promise(function (resolve, reject) {
  2100. try {
  2101. var value = obj[prop];
  2102. var result;
  2103. if (typeof value === 'function') {
  2104. result = value.apply(obj, args);
  2105. } else {
  2106. result = value;
  2107. }
  2108. resolve(result);
  2109. } catch (e) {
  2110. reject(e);
  2111. }
  2112. });
  2113. };
  2114. LocalPdfManager.prototype.requestRange =
  2115. function LocalPdfManager_requestRange(begin, end) {
  2116. return Promise.resolve();
  2117. };
  2118. LocalPdfManager.prototype.requestLoadedStream =
  2119. function LocalPdfManager_requestLoadedStream() {
  2120. };
  2121. LocalPdfManager.prototype.onLoadedStream =
  2122. function LocalPdfManager_getLoadedStream() {
  2123. return this._loadedStreamCapability.promise;
  2124. };
  2125. LocalPdfManager.prototype.terminate =
  2126. function LocalPdfManager_terminate() {
  2127. return;
  2128. };
  2129. return LocalPdfManager;
  2130. })();
  2131. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2132. function NetworkPdfManager(args, msgHandler) {
  2133. this.msgHandler = msgHandler;
  2134. var params = {
  2135. msgHandler: msgHandler,
  2136. httpHeaders: args.httpHeaders,
  2137. withCredentials: args.withCredentials,
  2138. chunkedViewerLoading: args.chunkedViewerLoading,
  2139. disableAutoFetch: args.disableAutoFetch,
  2140. initialData: args.initialData
  2141. };
  2142. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2143. args.url, params);
  2144. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2145. args.password);
  2146. }
  2147. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2148. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2149. NetworkPdfManager.prototype.ensure =
  2150. function NetworkPdfManager_ensure(obj, prop, args) {
  2151. var pdfManager = this;
  2152. return new Promise(function (resolve, reject) {
  2153. function ensureHelper() {
  2154. try {
  2155. var result;
  2156. var value = obj[prop];
  2157. if (typeof value === 'function') {
  2158. result = value.apply(obj, args);
  2159. } else {
  2160. result = value;
  2161. }
  2162. resolve(result);
  2163. } catch(e) {
  2164. if (!(e instanceof MissingDataException)) {
  2165. reject(e);
  2166. return;
  2167. }
  2168. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2169. }
  2170. }
  2171. ensureHelper();
  2172. });
  2173. };
  2174. NetworkPdfManager.prototype.requestRange =
  2175. function NetworkPdfManager_requestRange(begin, end) {
  2176. return new Promise(function (resolve) {
  2177. this.streamManager.requestRange(begin, end, function() {
  2178. resolve();
  2179. });
  2180. }.bind(this));
  2181. };
  2182. NetworkPdfManager.prototype.requestLoadedStream =
  2183. function NetworkPdfManager_requestLoadedStream() {
  2184. this.streamManager.requestAllChunks();
  2185. };
  2186. NetworkPdfManager.prototype.onLoadedStream =
  2187. function NetworkPdfManager_getLoadedStream() {
  2188. return this.streamManager.onLoadedStream();
  2189. };
  2190. NetworkPdfManager.prototype.terminate =
  2191. function NetworkPdfManager_terminate() {
  2192. this.streamManager.networkManager.abortAllRequests();
  2193. };
  2194. return NetworkPdfManager;
  2195. })();
  2196. var Page = (function PageClosure() {
  2197. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2198. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2199. this.pdfManager = pdfManager;
  2200. this.pageIndex = pageIndex;
  2201. this.pageDict = pageDict;
  2202. this.xref = xref;
  2203. this.ref = ref;
  2204. this.fontCache = fontCache;
  2205. this.idCounters = {
  2206. obj: 0
  2207. };
  2208. this.resourcesPromise = null;
  2209. }
  2210. Page.prototype = {
  2211. getPageProp: function Page_getPageProp(key) {
  2212. return this.pageDict.get(key);
  2213. },
  2214. getInheritedPageProp: function Page_inheritPageProp(key) {
  2215. var dict = this.pageDict;
  2216. var value = dict.get(key);
  2217. while (value === undefined) {
  2218. dict = dict.get('Parent');
  2219. if (!dict) {
  2220. break;
  2221. }
  2222. value = dict.get(key);
  2223. }
  2224. return value;
  2225. },
  2226. get content() {
  2227. return this.getPageProp('Contents');
  2228. },
  2229. get resources() {
  2230. var value = this.getInheritedPageProp('Resources');
  2231. // For robustness: The spec states that a \Resources entry has to be
  2232. // present, but can be empty. Some document omit it still. In this case
  2233. // return an empty dictionary:
  2234. if (value === undefined) {
  2235. value = Dict.empty;
  2236. }
  2237. return shadow(this, 'resources', value);
  2238. },
  2239. get mediaBox() {
  2240. var obj = this.getInheritedPageProp('MediaBox');
  2241. // Reset invalid media box to letter size.
  2242. if (!isArray(obj) || obj.length !== 4) {
  2243. obj = LETTER_SIZE_MEDIABOX;
  2244. }
  2245. return shadow(this, 'mediaBox', obj);
  2246. },
  2247. get view() {
  2248. var mediaBox = this.mediaBox;
  2249. var cropBox = this.getInheritedPageProp('CropBox');
  2250. if (!isArray(cropBox) || cropBox.length !== 4) {
  2251. return shadow(this, 'view', mediaBox);
  2252. }
  2253. // From the spec, 6th ed., p.963:
  2254. // "The crop, bleed, trim, and art boxes should not ordinarily
  2255. // extend beyond the boundaries of the media box. If they do, they are
  2256. // effectively reduced to their intersection with the media box."
  2257. cropBox = Util.intersect(cropBox, mediaBox);
  2258. if (!cropBox) {
  2259. return shadow(this, 'view', mediaBox);
  2260. }
  2261. return shadow(this, 'view', cropBox);
  2262. },
  2263. get annotationRefs() {
  2264. return shadow(this, 'annotationRefs',
  2265. this.getInheritedPageProp('Annots'));
  2266. },
  2267. get rotate() {
  2268. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2269. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2270. if (rotate % 90 !== 0) {
  2271. rotate = 0;
  2272. } else if (rotate >= 360) {
  2273. rotate = rotate % 360;
  2274. } else if (rotate < 0) {
  2275. // The spec doesn't cover negatives, assume its counterclockwise
  2276. // rotation. The following is the other implementation of modulo.
  2277. rotate = ((rotate % 360) + 360) % 360;
  2278. }
  2279. return shadow(this, 'rotate', rotate);
  2280. },
  2281. getContentStream: function Page_getContentStream() {
  2282. var content = this.content;
  2283. var stream;
  2284. if (isArray(content)) {
  2285. // fetching items
  2286. var xref = this.xref;
  2287. var i, n = content.length;
  2288. var streams = [];
  2289. for (i = 0; i < n; ++i) {
  2290. streams.push(xref.fetchIfRef(content[i]));
  2291. }
  2292. stream = new StreamsSequenceStream(streams);
  2293. } else if (isStream(content)) {
  2294. stream = content;
  2295. } else {
  2296. // replacing non-existent page content with empty one
  2297. stream = new NullStream();
  2298. }
  2299. return stream;
  2300. },
  2301. loadResources: function Page_loadResources(keys) {
  2302. if (!this.resourcesPromise) {
  2303. // TODO: add async getInheritedPageProp and remove this.
  2304. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2305. }
  2306. return this.resourcesPromise.then(function resourceSuccess() {
  2307. var objectLoader = new ObjectLoader(this.resources.map,
  2308. keys,
  2309. this.xref);
  2310. return objectLoader.load();
  2311. }.bind(this));
  2312. },
  2313. getOperatorList: function Page_getOperatorList(handler, intent) {
  2314. var self = this;
  2315. var pdfManager = this.pdfManager;
  2316. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2317. []);
  2318. var resourcesPromise = this.loadResources([
  2319. 'ExtGState',
  2320. 'ColorSpace',
  2321. 'Pattern',
  2322. 'Shading',
  2323. 'XObject',
  2324. 'Font'
  2325. // ProcSet
  2326. // Properties
  2327. ]);
  2328. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2329. handler, this.pageIndex,
  2330. 'p' + this.pageIndex + '_',
  2331. this.idCounters,
  2332. this.fontCache);
  2333. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2334. var pageListPromise = dataPromises.then(function(data) {
  2335. var contentStream = data[0];
  2336. var opList = new OperatorList(intent, handler, self.pageIndex);
  2337. handler.send('StartRenderPage', {
  2338. transparency: partialEvaluator.hasBlendModes(self.resources),
  2339. pageIndex: self.pageIndex,
  2340. intent: intent
  2341. });
  2342. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2343. opList).then(function () {
  2344. return opList;
  2345. });
  2346. });
  2347. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2348. return Promise.all([pageListPromise, annotationsPromise]).then(
  2349. function(datas) {
  2350. var pageOpList = datas[0];
  2351. var annotations = datas[1];
  2352. if (annotations.length === 0) {
  2353. pageOpList.flush(true);
  2354. return pageOpList;
  2355. }
  2356. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2357. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2358. return annotationsReadyPromise.then(function () {
  2359. pageOpList.flush(true);
  2360. return pageOpList;
  2361. });
  2362. });
  2363. },
  2364. extractTextContent: function Page_extractTextContent() {
  2365. var handler = {
  2366. on: function nullHandlerOn() {},
  2367. send: function nullHandlerSend() {}
  2368. };
  2369. var self = this;
  2370. var pdfManager = this.pdfManager;
  2371. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2372. []);
  2373. var resourcesPromise = this.loadResources([
  2374. 'ExtGState',
  2375. 'XObject',
  2376. 'Font'
  2377. ]);
  2378. var dataPromises = Promise.all([contentStreamPromise,
  2379. resourcesPromise]);
  2380. return dataPromises.then(function(data) {
  2381. var contentStream = data[0];
  2382. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2383. handler, self.pageIndex,
  2384. 'p' + self.pageIndex + '_',
  2385. self.idCounters,
  2386. self.fontCache);
  2387. return partialEvaluator.getTextContent(contentStream,
  2388. self.resources);
  2389. });
  2390. },
  2391. getAnnotationsData: function Page_getAnnotationsData() {
  2392. var annotations = this.annotations;
  2393. var annotationsData = [];
  2394. for (var i = 0, n = annotations.length; i < n; ++i) {
  2395. annotationsData.push(annotations[i].getData());
  2396. }
  2397. return annotationsData;
  2398. },
  2399. get annotations() {
  2400. var annotations = [];
  2401. var annotationRefs = (this.annotationRefs || []);
  2402. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2403. var annotationRef = annotationRefs[i];
  2404. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2405. if (annotation) {
  2406. annotations.push(annotation);
  2407. }
  2408. }
  2409. return shadow(this, 'annotations', annotations);
  2410. }
  2411. };
  2412. return Page;
  2413. })();
  2414. /**
  2415. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2416. * `PDFDoc`, this one doesn't have any job management code.
  2417. * Right now there exists one PDFDocument on the main thread + one object
  2418. * for each worker. If there is no worker support enabled, there are two
  2419. * `PDFDocument` objects on the main thread created.
  2420. */
  2421. var PDFDocument = (function PDFDocumentClosure() {
  2422. function PDFDocument(pdfManager, arg, password) {
  2423. if (isStream(arg)) {
  2424. init.call(this, pdfManager, arg, password);
  2425. } else if (isArrayBuffer(arg)) {
  2426. init.call(this, pdfManager, new Stream(arg), password);
  2427. } else {
  2428. error('PDFDocument: Unknown argument type');
  2429. }
  2430. }
  2431. function init(pdfManager, stream, password) {
  2432. assert(stream.length > 0, 'stream must have data');
  2433. this.pdfManager = pdfManager;
  2434. this.stream = stream;
  2435. var xref = new XRef(this.stream, password, pdfManager);
  2436. this.xref = xref;
  2437. }
  2438. function find(stream, needle, limit, backwards) {
  2439. var pos = stream.pos;
  2440. var end = stream.end;
  2441. var strBuf = [];
  2442. if (pos + limit > end) {
  2443. limit = end - pos;
  2444. }
  2445. for (var n = 0; n < limit; ++n) {
  2446. strBuf.push(String.fromCharCode(stream.getByte()));
  2447. }
  2448. var str = strBuf.join('');
  2449. stream.pos = pos;
  2450. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2451. if (index === -1) {
  2452. return false; /* not found */
  2453. }
  2454. stream.pos += index;
  2455. return true; /* found */
  2456. }
  2457. var DocumentInfoValidators = {
  2458. get entries() {
  2459. // Lazily build this since all the validation functions below are not
  2460. // defined until after this file loads.
  2461. return shadow(this, 'entries', {
  2462. Title: isString,
  2463. Author: isString,
  2464. Subject: isString,
  2465. Keywords: isString,
  2466. Creator: isString,
  2467. Producer: isString,
  2468. CreationDate: isString,
  2469. ModDate: isString,
  2470. Trapped: isName
  2471. });
  2472. }
  2473. };
  2474. PDFDocument.prototype = {
  2475. parse: function PDFDocument_parse(recoveryMode) {
  2476. this.setup(recoveryMode);
  2477. try {
  2478. // checking if AcroForm is present
  2479. this.acroForm = this.catalog.catDict.get('AcroForm');
  2480. if (this.acroForm) {
  2481. this.xfa = this.acroForm.get('XFA');
  2482. var fields = this.acroForm.get('Fields');
  2483. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2484. !this.xfa) {
  2485. // no fields and no XFA -- not a form (?)
  2486. this.acroForm = null;
  2487. }
  2488. }
  2489. } catch (ex) {
  2490. info('Something wrong with AcroForm entry');
  2491. this.acroForm = null;
  2492. }
  2493. },
  2494. get linearization() {
  2495. var linearization = null;
  2496. if (this.stream.length) {
  2497. try {
  2498. linearization = Linearization.create(this.stream);
  2499. } catch (err) {
  2500. if (err instanceof MissingDataException) {
  2501. throw err;
  2502. }
  2503. info(err);
  2504. }
  2505. }
  2506. // shadow the prototype getter with a data property
  2507. return shadow(this, 'linearization', linearization);
  2508. },
  2509. get startXRef() {
  2510. var stream = this.stream;
  2511. var startXRef = 0;
  2512. var linearization = this.linearization;
  2513. if (linearization) {
  2514. // Find end of first obj.
  2515. stream.reset();
  2516. if (find(stream, 'endobj', 1024)) {
  2517. startXRef = stream.pos + 6;
  2518. }
  2519. } else {
  2520. // Find startxref by jumping backward from the end of the file.
  2521. var step = 1024;
  2522. var found = false, pos = stream.end;
  2523. while (!found && pos > 0) {
  2524. pos -= step - 'startxref'.length;
  2525. if (pos < 0) {
  2526. pos = 0;
  2527. }
  2528. stream.pos = pos;
  2529. found = find(stream, 'startxref', step, true);
  2530. }
  2531. if (found) {
  2532. stream.skip(9);
  2533. var ch;
  2534. do {
  2535. ch = stream.getByte();
  2536. } while (Lexer.isSpace(ch));
  2537. var str = '';
  2538. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2539. str += String.fromCharCode(ch);
  2540. ch = stream.getByte();
  2541. }
  2542. startXRef = parseInt(str, 10);
  2543. if (isNaN(startXRef)) {
  2544. startXRef = 0;
  2545. }
  2546. }
  2547. }
  2548. // shadow the prototype getter with a data property
  2549. return shadow(this, 'startXRef', startXRef);
  2550. },
  2551. get mainXRefEntriesOffset() {
  2552. var mainXRefEntriesOffset = 0;
  2553. var linearization = this.linearization;
  2554. if (linearization) {
  2555. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2556. }
  2557. // shadow the prototype getter with a data property
  2558. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2559. },
  2560. // Find the header, remove leading garbage and setup the stream
  2561. // starting from the header.
  2562. checkHeader: function PDFDocument_checkHeader() {
  2563. var stream = this.stream;
  2564. stream.reset();
  2565. if (find(stream, '%PDF-', 1024)) {
  2566. // Found the header, trim off any garbage before it.
  2567. stream.moveStart();
  2568. // Reading file format version
  2569. var MAX_VERSION_LENGTH = 12;
  2570. var version = '', ch;
  2571. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2572. if (version.length >= MAX_VERSION_LENGTH) {
  2573. break;
  2574. }
  2575. version += String.fromCharCode(ch);
  2576. }
  2577. // removing "%PDF-"-prefix
  2578. this.pdfFormatVersion = version.substring(5);
  2579. return;
  2580. }
  2581. // May not be a PDF file, continue anyway.
  2582. },
  2583. parseStartXRef: function PDFDocument_parseStartXRef() {
  2584. var startXRef = this.startXRef;
  2585. this.xref.setStartXRef(startXRef);
  2586. },
  2587. setup: function PDFDocument_setup(recoveryMode) {
  2588. this.xref.parse(recoveryMode);
  2589. this.catalog = new Catalog(this.pdfManager, this.xref);
  2590. },
  2591. get numPages() {
  2592. var linearization = this.linearization;
  2593. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2594. // shadow the prototype getter
  2595. return shadow(this, 'numPages', num);
  2596. },
  2597. get documentInfo() {
  2598. var docInfo = {
  2599. PDFFormatVersion: this.pdfFormatVersion,
  2600. IsAcroFormPresent: !!this.acroForm,
  2601. IsXFAPresent: !!this.xfa
  2602. };
  2603. var infoDict;
  2604. try {
  2605. infoDict = this.xref.trailer.get('Info');
  2606. } catch (err) {
  2607. info('The document information dictionary is invalid.');
  2608. }
  2609. if (infoDict) {
  2610. var validEntries = DocumentInfoValidators.entries;
  2611. // Only fill the document info with valid entries from the spec.
  2612. for (var key in validEntries) {
  2613. if (infoDict.has(key)) {
  2614. var value = infoDict.get(key);
  2615. // Make sure the value conforms to the spec.
  2616. if (validEntries[key](value)) {
  2617. docInfo[key] = (typeof value !== 'string' ?
  2618. value : stringToPDFString(value));
  2619. } else {
  2620. info('Bad value in document info for "' + key + '"');
  2621. }
  2622. }
  2623. }
  2624. }
  2625. return shadow(this, 'documentInfo', docInfo);
  2626. },
  2627. get fingerprint() {
  2628. var xref = this.xref, hash, fileID = '';
  2629. if (xref.trailer.has('ID')) {
  2630. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2631. } else {
  2632. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  2633. }
  2634. for (var i = 0, n = hash.length; i < n; i++) {
  2635. fileID += hash[i].toString(16);
  2636. }
  2637. return shadow(this, 'fingerprint', fileID);
  2638. },
  2639. getPage: function PDFDocument_getPage(pageIndex) {
  2640. return this.catalog.getPage(pageIndex);
  2641. },
  2642. cleanup: function PDFDocument_cleanup() {
  2643. return this.catalog.cleanup();
  2644. }
  2645. };
  2646. return PDFDocument;
  2647. })();
  2648. var Name = (function NameClosure() {
  2649. function Name(name) {
  2650. this.name = name;
  2651. }
  2652. Name.prototype = {};
  2653. var nameCache = {};
  2654. Name.get = function Name_get(name) {
  2655. var nameValue = nameCache[name];
  2656. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2657. };
  2658. return Name;
  2659. })();
  2660. var Cmd = (function CmdClosure() {
  2661. function Cmd(cmd) {
  2662. this.cmd = cmd;
  2663. }
  2664. Cmd.prototype = {};
  2665. var cmdCache = {};
  2666. Cmd.get = function Cmd_get(cmd) {
  2667. var cmdValue = cmdCache[cmd];
  2668. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2669. };
  2670. return Cmd;
  2671. })();
  2672. var Dict = (function DictClosure() {
  2673. var nonSerializable = function nonSerializableClosure() {
  2674. return nonSerializable; // creating closure on some variable
  2675. };
  2676. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2677. 'Background': true,
  2678. 'ExtGState': true,
  2679. 'Halftone': true,
  2680. 'Layout': true,
  2681. 'Mask': true,
  2682. 'Pagination': true,
  2683. 'Printing': true
  2684. };
  2685. function isRecursionAllowedFor(dict) {
  2686. if (!isName(dict.Type)) {
  2687. return true;
  2688. }
  2689. var dictType = dict.Type.name;
  2690. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2691. }
  2692. // xref is optional
  2693. function Dict(xref) {
  2694. // Map should only be used internally, use functions below to access.
  2695. this.map = Object.create(null);
  2696. this.xref = xref;
  2697. this.objId = null;
  2698. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2699. }
  2700. Dict.prototype = {
  2701. assignXref: function Dict_assignXref(newXref) {
  2702. this.xref = newXref;
  2703. },
  2704. // automatically dereferences Ref objects
  2705. get: function Dict_get(key1, key2, key3) {
  2706. var value;
  2707. var xref = this.xref;
  2708. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2709. typeof key2 === 'undefined') {
  2710. return xref ? xref.fetchIfRef(value) : value;
  2711. }
  2712. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2713. typeof key3 === 'undefined') {
  2714. return xref ? xref.fetchIfRef(value) : value;
  2715. }
  2716. value = this.map[key3] || null;
  2717. return xref ? xref.fetchIfRef(value) : value;
  2718. },
  2719. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2720. getAsync: function Dict_getAsync(key1, key2, key3) {
  2721. var value;
  2722. var xref = this.xref;
  2723. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2724. typeof key2 === 'undefined') {
  2725. if (xref) {
  2726. return xref.fetchIfRefAsync(value);
  2727. }
  2728. return Promise.resolve(value);
  2729. }
  2730. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2731. typeof key3 === 'undefined') {
  2732. if (xref) {
  2733. return xref.fetchIfRefAsync(value);
  2734. }
  2735. return Promise.resolve(value);
  2736. }
  2737. value = this.map[key3] || null;
  2738. if (xref) {
  2739. return xref.fetchIfRefAsync(value);
  2740. }
  2741. return Promise.resolve(value);
  2742. },
  2743. // no dereferencing
  2744. getRaw: function Dict_getRaw(key) {
  2745. return this.map[key];
  2746. },
  2747. // creates new map and dereferences all Refs
  2748. getAll: function Dict_getAll() {
  2749. var all = Object.create(null);
  2750. var queue = null;
  2751. var key, obj;
  2752. for (key in this.map) {
  2753. obj = this.get(key);
  2754. if (obj instanceof Dict) {
  2755. if (isRecursionAllowedFor(obj)) {
  2756. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2757. } else {
  2758. all[key] = this.getRaw(key);
  2759. }
  2760. } else {
  2761. all[key] = obj;
  2762. }
  2763. }
  2764. if (!queue) {
  2765. return all;
  2766. }
  2767. // trying to take cyclic references into the account
  2768. var processed = Object.create(null);
  2769. while (queue.length > 0) {
  2770. var item = queue.shift();
  2771. var itemObj = item.obj;
  2772. var objId = itemObj.objId;
  2773. if (objId && objId in processed) {
  2774. item.target[item.key] = processed[objId];
  2775. continue;
  2776. }
  2777. var dereferenced = Object.create(null);
  2778. for (key in itemObj.map) {
  2779. obj = itemObj.get(key);
  2780. if (obj instanceof Dict) {
  2781. if (isRecursionAllowedFor(obj)) {
  2782. queue.push({target: dereferenced, key: key, obj: obj});
  2783. } else {
  2784. dereferenced[key] = itemObj.getRaw(key);
  2785. }
  2786. } else {
  2787. dereferenced[key] = obj;
  2788. }
  2789. }
  2790. if (objId) {
  2791. processed[objId] = dereferenced;
  2792. }
  2793. item.target[item.key] = dereferenced;
  2794. }
  2795. return all;
  2796. },
  2797. set: function Dict_set(key, value) {
  2798. this.map[key] = value;
  2799. },
  2800. has: function Dict_has(key) {
  2801. return key in this.map;
  2802. },
  2803. forEach: function Dict_forEach(callback) {
  2804. for (var key in this.map) {
  2805. callback(key, this.get(key));
  2806. }
  2807. }
  2808. };
  2809. Dict.empty = new Dict(null);
  2810. return Dict;
  2811. })();
  2812. var Ref = (function RefClosure() {
  2813. function Ref(num, gen) {
  2814. this.num = num;
  2815. this.gen = gen;
  2816. }
  2817. Ref.prototype = {
  2818. toString: function Ref_toString() {
  2819. // This function is hot, so we make the string as compact as possible.
  2820. // |this.gen| is almost always zero, so we treat that case specially.
  2821. var str = this.num + 'R';
  2822. if (this.gen !== 0) {
  2823. str += this.gen;
  2824. }
  2825. return str;
  2826. }
  2827. };
  2828. return Ref;
  2829. })();
  2830. // The reference is identified by number and generation.
  2831. // This structure stores only one instance of the reference.
  2832. var RefSet = (function RefSetClosure() {
  2833. function RefSet() {
  2834. this.dict = {};
  2835. }
  2836. RefSet.prototype = {
  2837. has: function RefSet_has(ref) {
  2838. return ref.toString() in this.dict;
  2839. },
  2840. put: function RefSet_put(ref) {
  2841. this.dict[ref.toString()] = true;
  2842. },
  2843. remove: function RefSet_remove(ref) {
  2844. delete this.dict[ref.toString()];
  2845. }
  2846. };
  2847. return RefSet;
  2848. })();
  2849. var RefSetCache = (function RefSetCacheClosure() {
  2850. function RefSetCache() {
  2851. this.dict = Object.create(null);
  2852. }
  2853. RefSetCache.prototype = {
  2854. get: function RefSetCache_get(ref) {
  2855. return this.dict[ref.toString()];
  2856. },
  2857. has: function RefSetCache_has(ref) {
  2858. return ref.toString() in this.dict;
  2859. },
  2860. put: function RefSetCache_put(ref, obj) {
  2861. this.dict[ref.toString()] = obj;
  2862. },
  2863. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2864. this.dict[ref.toString()] = this.get(aliasRef);
  2865. },
  2866. forEach: function RefSetCache_forEach(fn, thisArg) {
  2867. for (var i in this.dict) {
  2868. fn.call(thisArg, this.dict[i]);
  2869. }
  2870. },
  2871. clear: function RefSetCache_clear() {
  2872. this.dict = Object.create(null);
  2873. }
  2874. };
  2875. return RefSetCache;
  2876. })();
  2877. var Catalog = (function CatalogClosure() {
  2878. function Catalog(pdfManager, xref) {
  2879. this.pdfManager = pdfManager;
  2880. this.xref = xref;
  2881. this.catDict = xref.getCatalogObj();
  2882. this.fontCache = new RefSetCache();
  2883. assert(isDict(this.catDict),
  2884. 'catalog object is not a dictionary');
  2885. this.pagePromises = [];
  2886. }
  2887. Catalog.prototype = {
  2888. get metadata() {
  2889. var streamRef = this.catDict.getRaw('Metadata');
  2890. if (!isRef(streamRef)) {
  2891. return shadow(this, 'metadata', null);
  2892. }
  2893. var encryptMetadata = (!this.xref.encrypt ? false :
  2894. this.xref.encrypt.encryptMetadata);
  2895. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2896. var metadata;
  2897. if (stream && isDict(stream.dict)) {
  2898. var type = stream.dict.get('Type');
  2899. var subtype = stream.dict.get('Subtype');
  2900. if (isName(type) && isName(subtype) &&
  2901. type.name === 'Metadata' && subtype.name === 'XML') {
  2902. // XXX: This should examine the charset the XML document defines,
  2903. // however since there are currently no real means to decode
  2904. // arbitrary charsets, let's just hope that the author of the PDF
  2905. // was reasonable enough to stick with the XML default charset,
  2906. // which is UTF-8.
  2907. try {
  2908. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2909. } catch (e) {
  2910. info('Skipping invalid metadata.');
  2911. }
  2912. }
  2913. }
  2914. return shadow(this, 'metadata', metadata);
  2915. },
  2916. get toplevelPagesDict() {
  2917. var pagesObj = this.catDict.get('Pages');
  2918. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2919. // shadow the prototype getter
  2920. return shadow(this, 'toplevelPagesDict', pagesObj);
  2921. },
  2922. get documentOutline() {
  2923. var obj = null;
  2924. try {
  2925. obj = this.readDocumentOutline();
  2926. } catch (ex) {
  2927. if (ex instanceof MissingDataException) {
  2928. throw ex;
  2929. }
  2930. warn('Unable to read document outline');
  2931. }
  2932. return shadow(this, 'documentOutline', obj);
  2933. },
  2934. readDocumentOutline: function Catalog_readDocumentOutline() {
  2935. var xref = this.xref;
  2936. var obj = this.catDict.get('Outlines');
  2937. var root = { items: [] };
  2938. if (isDict(obj)) {
  2939. obj = obj.getRaw('First');
  2940. var processed = new RefSet();
  2941. if (isRef(obj)) {
  2942. var queue = [{obj: obj, parent: root}];
  2943. // to avoid recursion keeping track of the items
  2944. // in the processed dictionary
  2945. processed.put(obj);
  2946. while (queue.length > 0) {
  2947. var i = queue.shift();
  2948. var outlineDict = xref.fetchIfRef(i.obj);
  2949. if (outlineDict === null) {
  2950. continue;
  2951. }
  2952. if (!outlineDict.has('Title')) {
  2953. error('Invalid outline item');
  2954. }
  2955. var dest = outlineDict.get('A');
  2956. if (dest) {
  2957. dest = dest.get('D');
  2958. } else if (outlineDict.has('Dest')) {
  2959. dest = outlineDict.getRaw('Dest');
  2960. if (isName(dest)) {
  2961. dest = dest.name;
  2962. }
  2963. }
  2964. var title = outlineDict.get('Title');
  2965. var outlineItem = {
  2966. dest: dest,
  2967. title: stringToPDFString(title),
  2968. color: outlineDict.get('C') || [0, 0, 0],
  2969. count: outlineDict.get('Count'),
  2970. bold: !!(outlineDict.get('F') & 2),
  2971. italic: !!(outlineDict.get('F') & 1),
  2972. items: []
  2973. };
  2974. i.parent.items.push(outlineItem);
  2975. obj = outlineDict.getRaw('First');
  2976. if (isRef(obj) && !processed.has(obj)) {
  2977. queue.push({obj: obj, parent: outlineItem});
  2978. processed.put(obj);
  2979. }
  2980. obj = outlineDict.getRaw('Next');
  2981. if (isRef(obj) && !processed.has(obj)) {
  2982. queue.push({obj: obj, parent: i.parent});
  2983. processed.put(obj);
  2984. }
  2985. }
  2986. }
  2987. }
  2988. return (root.items.length > 0 ? root.items : null);
  2989. },
  2990. get numPages() {
  2991. var obj = this.toplevelPagesDict.get('Count');
  2992. assert(
  2993. isInt(obj),
  2994. 'page count in top level pages object is not an integer'
  2995. );
  2996. // shadow the prototype getter
  2997. return shadow(this, 'num', obj);
  2998. },
  2999. get destinations() {
  3000. function fetchDestination(dest) {
  3001. return isDict(dest) ? dest.get('D') : dest;
  3002. }
  3003. var xref = this.xref;
  3004. var dests = {}, nameTreeRef, nameDictionaryRef;
  3005. var obj = this.catDict.get('Names');
  3006. if (obj && obj.has('Dests')) {
  3007. nameTreeRef = obj.getRaw('Dests');
  3008. } else if (this.catDict.has('Dests')) {
  3009. nameDictionaryRef = this.catDict.get('Dests');
  3010. }
  3011. if (nameDictionaryRef) {
  3012. // reading simple destination dictionary
  3013. obj = nameDictionaryRef;
  3014. obj.forEach(function catalogForEach(key, value) {
  3015. if (!value) {
  3016. return;
  3017. }
  3018. dests[key] = fetchDestination(value);
  3019. });
  3020. }
  3021. if (nameTreeRef) {
  3022. var nameTree = new NameTree(nameTreeRef, xref);
  3023. var names = nameTree.getAll();
  3024. for (var name in names) {
  3025. if (!names.hasOwnProperty(name)) {
  3026. continue;
  3027. }
  3028. dests[name] = fetchDestination(names[name]);
  3029. }
  3030. }
  3031. return shadow(this, 'destinations', dests);
  3032. },
  3033. get attachments() {
  3034. var xref = this.xref;
  3035. var attachments = null, nameTreeRef;
  3036. var obj = this.catDict.get('Names');
  3037. if (obj) {
  3038. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3039. }
  3040. if (nameTreeRef) {
  3041. var nameTree = new NameTree(nameTreeRef, xref);
  3042. var names = nameTree.getAll();
  3043. for (var name in names) {
  3044. if (!names.hasOwnProperty(name)) {
  3045. continue;
  3046. }
  3047. var fs = new FileSpec(names[name], xref);
  3048. if (!attachments) {
  3049. attachments = {};
  3050. }
  3051. attachments[stringToPDFString(name)] = fs.serializable;
  3052. }
  3053. }
  3054. return shadow(this, 'attachments', attachments);
  3055. },
  3056. get javaScript() {
  3057. var xref = this.xref;
  3058. var obj = this.catDict.get('Names');
  3059. var javaScript = [];
  3060. if (obj && obj.has('JavaScript')) {
  3061. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3062. var names = nameTree.getAll();
  3063. for (var name in names) {
  3064. if (!names.hasOwnProperty(name)) {
  3065. continue;
  3066. }
  3067. // We don't really use the JavaScript right now. This code is
  3068. // defensive so we don't cause errors on document load.
  3069. var jsDict = names[name];
  3070. if (!isDict(jsDict)) {
  3071. continue;
  3072. }
  3073. var type = jsDict.get('S');
  3074. if (!isName(type) || type.name !== 'JavaScript') {
  3075. continue;
  3076. }
  3077. var js = jsDict.get('JS');
  3078. if (!isString(js) && !isStream(js)) {
  3079. continue;
  3080. }
  3081. if (isStream(js)) {
  3082. js = bytesToString(js.getBytes());
  3083. }
  3084. javaScript.push(stringToPDFString(js));
  3085. }
  3086. }
  3087. // Append OpenAction actions to javaScript array
  3088. var openactionDict = this.catDict.get('OpenAction');
  3089. if (isDict(openactionDict)) {
  3090. var objType = openactionDict.get('Type');
  3091. var actionType = openactionDict.get('S');
  3092. var action = openactionDict.get('N');
  3093. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3094. isName(actionType) && actionType.name === 'Named' &&
  3095. isName(action) && action.name === 'Print');
  3096. if (isPrintAction) {
  3097. javaScript.push('print(true);');
  3098. }
  3099. }
  3100. return shadow(this, 'javaScript', javaScript);
  3101. },
  3102. cleanup: function Catalog_cleanup() {
  3103. var promises = [];
  3104. this.fontCache.forEach(function (promise) {
  3105. promises.push(promise);
  3106. });
  3107. return Promise.all(promises).then(function (translatedFonts) {
  3108. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3109. var font = translatedFonts[i].dict;
  3110. delete font.translated;
  3111. }
  3112. this.fontCache.clear();
  3113. }.bind(this));
  3114. },
  3115. getPage: function Catalog_getPage(pageIndex) {
  3116. if (!(pageIndex in this.pagePromises)) {
  3117. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3118. function (a) {
  3119. var dict = a[0];
  3120. var ref = a[1];
  3121. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3122. this.fontCache);
  3123. }.bind(this)
  3124. );
  3125. }
  3126. return this.pagePromises[pageIndex];
  3127. },
  3128. getPageDict: function Catalog_getPageDict(pageIndex) {
  3129. var capability = createPromiseCapability();
  3130. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3131. var currentPageIndex = 0;
  3132. var xref = this.xref;
  3133. function next() {
  3134. while (nodesToVisit.length) {
  3135. var currentNode = nodesToVisit.pop();
  3136. if (isRef(currentNode)) {
  3137. xref.fetchAsync(currentNode).then(function (obj) {
  3138. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3139. if (pageIndex === currentPageIndex) {
  3140. capability.resolve([obj, currentNode]);
  3141. } else {
  3142. currentPageIndex++;
  3143. next();
  3144. }
  3145. return;
  3146. }
  3147. nodesToVisit.push(obj);
  3148. next();
  3149. }, capability.reject);
  3150. return;
  3151. }
  3152. // must be a child page dictionary
  3153. assert(
  3154. isDict(currentNode),
  3155. 'page dictionary kid reference points to wrong type of object'
  3156. );
  3157. var count = currentNode.get('Count');
  3158. // Skip nodes where the page can't be.
  3159. if (currentPageIndex + count <= pageIndex) {
  3160. currentPageIndex += count;
  3161. continue;
  3162. }
  3163. var kids = currentNode.get('Kids');
  3164. assert(isArray(kids), 'page dictionary kids object is not an array');
  3165. if (count === kids.length) {
  3166. // Nodes that don't have the page have been skipped and this is the
  3167. // bottom of the tree which means the page requested must be a
  3168. // descendant of this pages node. Ideally we would just resolve the
  3169. // promise with the page ref here, but there is the case where more
  3170. // pages nodes could link to single a page (see issue 3666 pdf). To
  3171. // handle this push it back on the queue so if it is a pages node it
  3172. // will be descended into.
  3173. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3174. currentPageIndex = pageIndex;
  3175. continue;
  3176. } else {
  3177. for (var last = kids.length - 1; last >= 0; last--) {
  3178. nodesToVisit.push(kids[last]);
  3179. }
  3180. }
  3181. }
  3182. capability.reject('Page index ' + pageIndex + ' not found.');
  3183. }
  3184. next();
  3185. return capability.promise;
  3186. },
  3187. getPageIndex: function Catalog_getPageIndex(ref) {
  3188. // The page tree nodes have the count of all the leaves below them. To get
  3189. // how many pages are before we just have to walk up the tree and keep
  3190. // adding the count of siblings to the left of the node.
  3191. var xref = this.xref;
  3192. function pagesBeforeRef(kidRef) {
  3193. var total = 0;
  3194. var parentRef;
  3195. return xref.fetchAsync(kidRef).then(function (node) {
  3196. if (!node) {
  3197. return null;
  3198. }
  3199. parentRef = node.getRaw('Parent');
  3200. return node.getAsync('Parent');
  3201. }).then(function (parent) {
  3202. if (!parent) {
  3203. return null;
  3204. }
  3205. return parent.getAsync('Kids');
  3206. }).then(function (kids) {
  3207. if (!kids) {
  3208. return null;
  3209. }
  3210. var kidPromises = [];
  3211. var found = false;
  3212. for (var i = 0; i < kids.length; i++) {
  3213. var kid = kids[i];
  3214. assert(isRef(kid), 'kids must be a ref');
  3215. if (kid.num === kidRef.num) {
  3216. found = true;
  3217. break;
  3218. }
  3219. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3220. if (kid.has('Count')) {
  3221. var count = kid.get('Count');
  3222. total += count;
  3223. } else { // page leaf node
  3224. total++;
  3225. }
  3226. }));
  3227. }
  3228. if (!found) {
  3229. error('kid ref not found in parents kids');
  3230. }
  3231. return Promise.all(kidPromises).then(function () {
  3232. return [total, parentRef];
  3233. });
  3234. });
  3235. }
  3236. var total = 0;
  3237. function next(ref) {
  3238. return pagesBeforeRef(ref).then(function (args) {
  3239. if (!args) {
  3240. return total;
  3241. }
  3242. var count = args[0];
  3243. var parentRef = args[1];
  3244. total += count;
  3245. return next(parentRef);
  3246. });
  3247. }
  3248. return next(ref);
  3249. }
  3250. };
  3251. return Catalog;
  3252. })();
  3253. var XRef = (function XRefClosure() {
  3254. function XRef(stream, password) {
  3255. this.stream = stream;
  3256. this.entries = [];
  3257. this.xrefstms = {};
  3258. // prepare the XRef cache
  3259. this.cache = [];
  3260. this.password = password;
  3261. this.stats = {
  3262. streamTypes: [],
  3263. fontTypes: []
  3264. };
  3265. }
  3266. XRef.prototype = {
  3267. setStartXRef: function XRef_setStartXRef(startXRef) {
  3268. // Store the starting positions of xref tables as we process them
  3269. // so we can recover from missing data errors
  3270. this.startXRefQueue = [startXRef];
  3271. },
  3272. parse: function XRef_parse(recoveryMode) {
  3273. var trailerDict;
  3274. if (!recoveryMode) {
  3275. trailerDict = this.readXRef();
  3276. } else {
  3277. warn('Indexing all PDF objects');
  3278. trailerDict = this.indexObjects();
  3279. }
  3280. trailerDict.assignXref(this);
  3281. this.trailer = trailerDict;
  3282. var encrypt = trailerDict.get('Encrypt');
  3283. if (encrypt) {
  3284. var ids = trailerDict.get('ID');
  3285. var fileId = (ids && ids.length) ? ids[0] : '';
  3286. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3287. this.password);
  3288. }
  3289. // get the root dictionary (catalog) object
  3290. if (!(this.root = trailerDict.get('Root'))) {
  3291. error('Invalid root reference');
  3292. }
  3293. },
  3294. processXRefTable: function XRef_processXRefTable(parser) {
  3295. if (!('tableState' in this)) {
  3296. // Stores state of the table as we process it so we can resume
  3297. // from middle of table in case of missing data error
  3298. this.tableState = {
  3299. entryNum: 0,
  3300. streamPos: parser.lexer.stream.pos,
  3301. parserBuf1: parser.buf1,
  3302. parserBuf2: parser.buf2
  3303. };
  3304. }
  3305. var obj = this.readXRefTable(parser);
  3306. // Sanity check
  3307. if (!isCmd(obj, 'trailer')) {
  3308. error('Invalid XRef table: could not find trailer dictionary');
  3309. }
  3310. // Read trailer dictionary, e.g.
  3311. // trailer
  3312. // << /Size 22
  3313. // /Root 20R
  3314. // /Info 10R
  3315. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3316. // >>
  3317. // The parser goes through the entire stream << ... >> and provides
  3318. // a getter interface for the key-value table
  3319. var dict = parser.getObj();
  3320. // The pdflib PDF generator can generate a nested trailer dictionary
  3321. if (!isDict(dict) && dict.dict) {
  3322. dict = dict.dict;
  3323. }
  3324. if (!isDict(dict)) {
  3325. error('Invalid XRef table: could not parse trailer dictionary');
  3326. }
  3327. delete this.tableState;
  3328. return dict;
  3329. },
  3330. readXRefTable: function XRef_readXRefTable(parser) {
  3331. // Example of cross-reference table:
  3332. // xref
  3333. // 0 1 <-- subsection header (first obj #, obj count)
  3334. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3335. // 23 2 <-- subsection header ... and so on ...
  3336. // 0000025518 00002 n
  3337. // 0000025635 00000 n
  3338. // trailer
  3339. // ...
  3340. var stream = parser.lexer.stream;
  3341. var tableState = this.tableState;
  3342. stream.pos = tableState.streamPos;
  3343. parser.buf1 = tableState.parserBuf1;
  3344. parser.buf2 = tableState.parserBuf2;
  3345. // Outer loop is over subsection headers
  3346. var obj;
  3347. while (true) {
  3348. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3349. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3350. break;
  3351. }
  3352. tableState.firstEntryNum = obj;
  3353. tableState.entryCount = parser.getObj();
  3354. }
  3355. var first = tableState.firstEntryNum;
  3356. var count = tableState.entryCount;
  3357. if (!isInt(first) || !isInt(count)) {
  3358. error('Invalid XRef table: wrong types in subsection header');
  3359. }
  3360. // Inner loop is over objects themselves
  3361. for (var i = tableState.entryNum; i < count; i++) {
  3362. tableState.streamPos = stream.pos;
  3363. tableState.entryNum = i;
  3364. tableState.parserBuf1 = parser.buf1;
  3365. tableState.parserBuf2 = parser.buf2;
  3366. var entry = {};
  3367. entry.offset = parser.getObj();
  3368. entry.gen = parser.getObj();
  3369. var type = parser.getObj();
  3370. if (isCmd(type, 'f')) {
  3371. entry.free = true;
  3372. } else if (isCmd(type, 'n')) {
  3373. entry.uncompressed = true;
  3374. }
  3375. // Validate entry obj
  3376. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3377. !(entry.free || entry.uncompressed)) {
  3378. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3379. }
  3380. if (!this.entries[i + first]) {
  3381. this.entries[i + first] = entry;
  3382. }
  3383. }
  3384. tableState.entryNum = 0;
  3385. tableState.streamPos = stream.pos;
  3386. tableState.parserBuf1 = parser.buf1;
  3387. tableState.parserBuf2 = parser.buf2;
  3388. delete tableState.firstEntryNum;
  3389. delete tableState.entryCount;
  3390. }
  3391. // Per issue 3248: hp scanners generate bad XRef
  3392. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3393. // shifting the entries
  3394. this.entries.shift();
  3395. }
  3396. // Sanity check: as per spec, first object must be free
  3397. if (this.entries[0] && !this.entries[0].free) {
  3398. error('Invalid XRef table: unexpected first object');
  3399. }
  3400. return obj;
  3401. },
  3402. processXRefStream: function XRef_processXRefStream(stream) {
  3403. if (!('streamState' in this)) {
  3404. // Stores state of the stream as we process it so we can resume
  3405. // from middle of stream in case of missing data error
  3406. var streamParameters = stream.dict;
  3407. var byteWidths = streamParameters.get('W');
  3408. var range = streamParameters.get('Index');
  3409. if (!range) {
  3410. range = [0, streamParameters.get('Size')];
  3411. }
  3412. this.streamState = {
  3413. entryRanges: range,
  3414. byteWidths: byteWidths,
  3415. entryNum: 0,
  3416. streamPos: stream.pos
  3417. };
  3418. }
  3419. this.readXRefStream(stream);
  3420. delete this.streamState;
  3421. return stream.dict;
  3422. },
  3423. readXRefStream: function XRef_readXRefStream(stream) {
  3424. var i, j;
  3425. var streamState = this.streamState;
  3426. stream.pos = streamState.streamPos;
  3427. var byteWidths = streamState.byteWidths;
  3428. var typeFieldWidth = byteWidths[0];
  3429. var offsetFieldWidth = byteWidths[1];
  3430. var generationFieldWidth = byteWidths[2];
  3431. var entryRanges = streamState.entryRanges;
  3432. while (entryRanges.length > 0) {
  3433. var first = entryRanges[0];
  3434. var n = entryRanges[1];
  3435. if (!isInt(first) || !isInt(n)) {
  3436. error('Invalid XRef range fields: ' + first + ', ' + n);
  3437. }
  3438. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3439. !isInt(generationFieldWidth)) {
  3440. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3441. }
  3442. for (i = streamState.entryNum; i < n; ++i) {
  3443. streamState.entryNum = i;
  3444. streamState.streamPos = stream.pos;
  3445. var type = 0, offset = 0, generation = 0;
  3446. for (j = 0; j < typeFieldWidth; ++j) {
  3447. type = (type << 8) | stream.getByte();
  3448. }
  3449. // if type field is absent, its default value is 1
  3450. if (typeFieldWidth === 0) {
  3451. type = 1;
  3452. }
  3453. for (j = 0; j < offsetFieldWidth; ++j) {
  3454. offset = (offset << 8) | stream.getByte();
  3455. }
  3456. for (j = 0; j < generationFieldWidth; ++j) {
  3457. generation = (generation << 8) | stream.getByte();
  3458. }
  3459. var entry = {};
  3460. entry.offset = offset;
  3461. entry.gen = generation;
  3462. switch (type) {
  3463. case 0:
  3464. entry.free = true;
  3465. break;
  3466. case 1:
  3467. entry.uncompressed = true;
  3468. break;
  3469. case 2:
  3470. break;
  3471. default:
  3472. error('Invalid XRef entry type: ' + type);
  3473. }
  3474. if (!this.entries[first + i]) {
  3475. this.entries[first + i] = entry;
  3476. }
  3477. }
  3478. streamState.entryNum = 0;
  3479. streamState.streamPos = stream.pos;
  3480. entryRanges.splice(0, 2);
  3481. }
  3482. },
  3483. indexObjects: function XRef_indexObjects() {
  3484. // Simple scan through the PDF content to find objects,
  3485. // trailers and XRef streams.
  3486. function readToken(data, offset) {
  3487. var token = '', ch = data[offset];
  3488. while (ch !== 13 && ch !== 10) {
  3489. if (++offset >= data.length) {
  3490. break;
  3491. }
  3492. token += String.fromCharCode(ch);
  3493. ch = data[offset];
  3494. }
  3495. return token;
  3496. }
  3497. function skipUntil(data, offset, what) {
  3498. var length = what.length, dataLength = data.length;
  3499. var skipped = 0;
  3500. // finding byte sequence
  3501. while (offset < dataLength) {
  3502. var i = 0;
  3503. while (i < length && data[offset + i] === what[i]) {
  3504. ++i;
  3505. }
  3506. if (i >= length) {
  3507. break; // sequence found
  3508. }
  3509. offset++;
  3510. skipped++;
  3511. }
  3512. return skipped;
  3513. }
  3514. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3515. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3516. 101, 102]);
  3517. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3518. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3519. var stream = this.stream;
  3520. stream.pos = 0;
  3521. var buffer = stream.getBytes();
  3522. var position = stream.start, length = buffer.length;
  3523. var trailers = [], xrefStms = [];
  3524. while (position < length) {
  3525. var ch = buffer[position];
  3526. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3527. ++position;
  3528. continue;
  3529. }
  3530. if (ch === 37) { // %-comment
  3531. do {
  3532. ++position;
  3533. if (position >= length) {
  3534. break;
  3535. }
  3536. ch = buffer[position];
  3537. } while (ch !== 13 && ch !== 10);
  3538. continue;
  3539. }
  3540. var token = readToken(buffer, position);
  3541. var m;
  3542. if (token === 'xref') {
  3543. position += skipUntil(buffer, position, trailerBytes);
  3544. trailers.push(position);
  3545. position += skipUntil(buffer, position, startxrefBytes);
  3546. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3547. this.entries[m[1]] = {
  3548. offset: position,
  3549. gen: m[2] | 0,
  3550. uncompressed: true
  3551. };
  3552. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3553. var content = buffer.subarray(position, position + contentLength);
  3554. // checking XRef stream suspect
  3555. // (it shall have '/XRef' and next char is not a letter)
  3556. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3557. if (xrefTagOffset < contentLength &&
  3558. content[xrefTagOffset + 5] < 64) {
  3559. xrefStms.push(position);
  3560. this.xrefstms[position] = 1; // don't read it recursively
  3561. }
  3562. position += contentLength;
  3563. } else {
  3564. position += token.length + 1;
  3565. }
  3566. }
  3567. // reading XRef streams
  3568. var i, ii;
  3569. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3570. this.startXRefQueue.push(xrefStms[i]);
  3571. this.readXRef(/* recoveryMode */ true);
  3572. }
  3573. // finding main trailer
  3574. var dict;
  3575. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3576. stream.pos = trailers[i];
  3577. var parser = new Parser(new Lexer(stream), true, this);
  3578. var obj = parser.getObj();
  3579. if (!isCmd(obj, 'trailer')) {
  3580. continue;
  3581. }
  3582. // read the trailer dictionary
  3583. if (!isDict(dict = parser.getObj())) {
  3584. continue;
  3585. }
  3586. // taking the first one with 'ID'
  3587. if (dict.has('ID')) {
  3588. return dict;
  3589. }
  3590. }
  3591. // no tailer with 'ID', taking last one (if exists)
  3592. if (dict) {
  3593. return dict;
  3594. }
  3595. // nothing helps
  3596. // calling error() would reject worker with an UnknownErrorException.
  3597. throw new InvalidPDFException('Invalid PDF structure');
  3598. },
  3599. readXRef: function XRef_readXRef(recoveryMode) {
  3600. var stream = this.stream;
  3601. try {
  3602. while (this.startXRefQueue.length) {
  3603. var startXRef = this.startXRefQueue[0];
  3604. stream.pos = startXRef + stream.start;
  3605. var parser = new Parser(new Lexer(stream), true, this);
  3606. var obj = parser.getObj();
  3607. var dict;
  3608. // Get dictionary
  3609. if (isCmd(obj, 'xref')) {
  3610. // Parse end-of-file XRef
  3611. dict = this.processXRefTable(parser);
  3612. if (!this.topDict) {
  3613. this.topDict = dict;
  3614. }
  3615. // Recursively get other XRefs 'XRefStm', if any
  3616. obj = dict.get('XRefStm');
  3617. if (isInt(obj)) {
  3618. var pos = obj;
  3619. // ignore previously loaded xref streams
  3620. // (possible infinite recursion)
  3621. if (!(pos in this.xrefstms)) {
  3622. this.xrefstms[pos] = 1;
  3623. this.startXRefQueue.push(pos);
  3624. }
  3625. }
  3626. } else if (isInt(obj)) {
  3627. // Parse in-stream XRef
  3628. if (!isInt(parser.getObj()) ||
  3629. !isCmd(parser.getObj(), 'obj') ||
  3630. !isStream(obj = parser.getObj())) {
  3631. error('Invalid XRef stream');
  3632. }
  3633. dict = this.processXRefStream(obj);
  3634. if (!this.topDict) {
  3635. this.topDict = dict;
  3636. }
  3637. if (!dict) {
  3638. error('Failed to read XRef stream');
  3639. }
  3640. } else {
  3641. error('Invalid XRef stream header');
  3642. }
  3643. // Recursively get previous dictionary, if any
  3644. obj = dict.get('Prev');
  3645. if (isInt(obj)) {
  3646. this.startXRefQueue.push(obj);
  3647. } else if (isRef(obj)) {
  3648. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3649. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3650. this.startXRefQueue.push(obj.num);
  3651. }
  3652. this.startXRefQueue.shift();
  3653. }
  3654. return this.topDict;
  3655. } catch (e) {
  3656. if (e instanceof MissingDataException) {
  3657. throw e;
  3658. }
  3659. info('(while reading XRef): ' + e);
  3660. }
  3661. if (recoveryMode) {
  3662. return;
  3663. }
  3664. throw new XRefParseException();
  3665. },
  3666. getEntry: function XRef_getEntry(i) {
  3667. var xrefEntry = this.entries[i];
  3668. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3669. return xrefEntry;
  3670. }
  3671. return null;
  3672. },
  3673. fetchIfRef: function XRef_fetchIfRef(obj) {
  3674. if (!isRef(obj)) {
  3675. return obj;
  3676. }
  3677. return this.fetch(obj);
  3678. },
  3679. fetch: function XRef_fetch(ref, suppressEncryption) {
  3680. assert(isRef(ref), 'ref object is not a reference');
  3681. var num = ref.num;
  3682. if (num in this.cache) {
  3683. var cacheEntry = this.cache[num];
  3684. return cacheEntry;
  3685. }
  3686. var xrefEntry = this.getEntry(num);
  3687. // the referenced entry can be free
  3688. if (xrefEntry === null) {
  3689. return (this.cache[num] = null);
  3690. }
  3691. if (xrefEntry.uncompressed) {
  3692. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3693. } else {
  3694. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3695. }
  3696. if (isDict(xrefEntry)){
  3697. xrefEntry.objId = ref.toString();
  3698. } else if (isStream(xrefEntry)) {
  3699. xrefEntry.dict.objId = ref.toString();
  3700. }
  3701. return xrefEntry;
  3702. },
  3703. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3704. suppressEncryption) {
  3705. var gen = ref.gen;
  3706. var num = ref.num;
  3707. if (xrefEntry.gen !== gen) {
  3708. error('inconsistent generation in XRef');
  3709. }
  3710. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3711. this.stream.start);
  3712. var parser = new Parser(new Lexer(stream), true, this);
  3713. var obj1 = parser.getObj();
  3714. var obj2 = parser.getObj();
  3715. var obj3 = parser.getObj();
  3716. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3717. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3718. !isCmd(obj3)) {
  3719. error('bad XRef entry');
  3720. }
  3721. if (!isCmd(obj3, 'obj')) {
  3722. // some bad PDFs use "obj1234" and really mean 1234
  3723. if (obj3.cmd.indexOf('obj') === 0) {
  3724. num = parseInt(obj3.cmd.substring(3), 10);
  3725. if (!isNaN(num)) {
  3726. return num;
  3727. }
  3728. }
  3729. error('bad XRef entry');
  3730. }
  3731. if (this.encrypt && !suppressEncryption) {
  3732. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3733. } else {
  3734. xrefEntry = parser.getObj();
  3735. }
  3736. if (!isStream(xrefEntry)) {
  3737. this.cache[num] = xrefEntry;
  3738. }
  3739. return xrefEntry;
  3740. },
  3741. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3742. suppressEncryption) {
  3743. var tableOffset = xrefEntry.offset;
  3744. var stream = this.fetch(new Ref(tableOffset, 0));
  3745. if (!isStream(stream)) {
  3746. error('bad ObjStm stream');
  3747. }
  3748. var first = stream.dict.get('First');
  3749. var n = stream.dict.get('N');
  3750. if (!isInt(first) || !isInt(n)) {
  3751. error('invalid first and n parameters for ObjStm stream');
  3752. }
  3753. var parser = new Parser(new Lexer(stream), false, this);
  3754. parser.allowStreams = true;
  3755. var i, entries = [], num, nums = [];
  3756. // read the object numbers to populate cache
  3757. for (i = 0; i < n; ++i) {
  3758. num = parser.getObj();
  3759. if (!isInt(num)) {
  3760. error('invalid object number in the ObjStm stream: ' + num);
  3761. }
  3762. nums.push(num);
  3763. var offset = parser.getObj();
  3764. if (!isInt(offset)) {
  3765. error('invalid object offset in the ObjStm stream: ' + offset);
  3766. }
  3767. }
  3768. // read stream objects for cache
  3769. for (i = 0; i < n; ++i) {
  3770. entries.push(parser.getObj());
  3771. num = nums[i];
  3772. var entry = this.entries[num];
  3773. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3774. this.cache[num] = entries[i];
  3775. }
  3776. }
  3777. xrefEntry = entries[xrefEntry.gen];
  3778. if (xrefEntry === undefined) {
  3779. error('bad XRef entry for compressed object');
  3780. }
  3781. return xrefEntry;
  3782. },
  3783. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3784. if (!isRef(obj)) {
  3785. return Promise.resolve(obj);
  3786. }
  3787. return this.fetchAsync(obj);
  3788. },
  3789. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3790. var streamManager = this.stream.manager;
  3791. var xref = this;
  3792. return new Promise(function tryFetch(resolve, reject) {
  3793. try {
  3794. resolve(xref.fetch(ref, suppressEncryption));
  3795. } catch (e) {
  3796. if (e instanceof MissingDataException) {
  3797. streamManager.requestRange(e.begin, e.end, function () {
  3798. tryFetch(resolve, reject);
  3799. });
  3800. return;
  3801. }
  3802. reject(e);
  3803. }
  3804. });
  3805. },
  3806. getCatalogObj: function XRef_getCatalogObj() {
  3807. return this.root;
  3808. }
  3809. };
  3810. return XRef;
  3811. })();
  3812. /**
  3813. * A NameTree is like a Dict but has some advantageous properties, see the
  3814. * spec (7.9.6) for more details.
  3815. * TODO: implement all the Dict functions and make this more efficent.
  3816. */
  3817. var NameTree = (function NameTreeClosure() {
  3818. function NameTree(root, xref) {
  3819. this.root = root;
  3820. this.xref = xref;
  3821. }
  3822. NameTree.prototype = {
  3823. getAll: function NameTree_getAll() {
  3824. var dict = {};
  3825. if (!this.root) {
  3826. return dict;
  3827. }
  3828. var xref = this.xref;
  3829. // reading name tree
  3830. var processed = new RefSet();
  3831. processed.put(this.root);
  3832. var queue = [this.root];
  3833. while (queue.length > 0) {
  3834. var i, n;
  3835. var obj = xref.fetchIfRef(queue.shift());
  3836. if (!isDict(obj)) {
  3837. continue;
  3838. }
  3839. if (obj.has('Kids')) {
  3840. var kids = obj.get('Kids');
  3841. for (i = 0, n = kids.length; i < n; i++) {
  3842. var kid = kids[i];
  3843. if (processed.has(kid)) {
  3844. error('invalid destinations');
  3845. }
  3846. queue.push(kid);
  3847. processed.put(kid);
  3848. }
  3849. continue;
  3850. }
  3851. var names = obj.get('Names');
  3852. if (names) {
  3853. for (i = 0, n = names.length; i < n; i += 2) {
  3854. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3855. }
  3856. }
  3857. }
  3858. return dict;
  3859. }
  3860. };
  3861. return NameTree;
  3862. })();
  3863. /**
  3864. * "A PDF file can refer to the contents of another file by using a File
  3865. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  3866. * NOTE: Only embedded files are supported (as part of the attachments support)
  3867. * TODO: support the 'URL' file system (with caching if !/V), portable
  3868. * collections attributes and related files (/RF)
  3869. */
  3870. var FileSpec = (function FileSpecClosure() {
  3871. function FileSpec(root, xref) {
  3872. if (!root || !isDict(root)) {
  3873. return;
  3874. }
  3875. this.xref = xref;
  3876. this.root = root;
  3877. if (root.has('FS')) {
  3878. this.fs = root.get('FS');
  3879. }
  3880. this.description = root.has('Desc') ?
  3881. stringToPDFString(root.get('Desc')) :
  3882. '';
  3883. if (root.has('RF')) {
  3884. warn('Related file specifications are not supported');
  3885. }
  3886. this.contentAvailable = true;
  3887. if (!root.has('EF')) {
  3888. this.contentAvailable = false;
  3889. warn('Non-embedded file specifications are not supported');
  3890. }
  3891. }
  3892. function pickPlatformItem(dict) {
  3893. // Look for the filename in this order:
  3894. // UF, F, Unix, Mac, DOS
  3895. if (dict.has('UF')) {
  3896. return dict.get('UF');
  3897. } else if (dict.has('F')) {
  3898. return dict.get('F');
  3899. } else if (dict.has('Unix')) {
  3900. return dict.get('Unix');
  3901. } else if (dict.has('Mac')) {
  3902. return dict.get('Mac');
  3903. } else if (dict.has('DOS')) {
  3904. return dict.get('DOS');
  3905. } else {
  3906. return null;
  3907. }
  3908. }
  3909. FileSpec.prototype = {
  3910. get filename() {
  3911. if (!this._filename && this.root) {
  3912. var filename = pickPlatformItem(this.root) || 'unnamed';
  3913. this._filename = stringToPDFString(filename).
  3914. replace(/\\\\/g, '\\').
  3915. replace(/\\\//g, '/').
  3916. replace(/\\/g, '/');
  3917. }
  3918. return this._filename;
  3919. },
  3920. get content() {
  3921. if (!this.contentAvailable) {
  3922. return null;
  3923. }
  3924. if (!this.contentRef && this.root) {
  3925. this.contentRef = pickPlatformItem(this.root.get('EF'));
  3926. }
  3927. var content = null;
  3928. if (this.contentRef) {
  3929. var xref = this.xref;
  3930. var fileObj = xref.fetchIfRef(this.contentRef);
  3931. if (fileObj && isStream(fileObj)) {
  3932. content = fileObj.getBytes();
  3933. } else {
  3934. warn('Embedded file specification points to non-existing/invalid ' +
  3935. 'content');
  3936. }
  3937. } else {
  3938. warn('Embedded file specification does not have a content');
  3939. }
  3940. return content;
  3941. },
  3942. get serializable() {
  3943. return {
  3944. filename: this.filename,
  3945. content: this.content
  3946. };
  3947. }
  3948. };
  3949. return FileSpec;
  3950. })();
  3951. /**
  3952. * A helper for loading missing data in object graphs. It traverses the graph
  3953. * depth first and queues up any objects that have missing data. Once it has
  3954. * has traversed as many objects that are available it attempts to bundle the
  3955. * missing data requests and then resume from the nodes that weren't ready.
  3956. *
  3957. * NOTE: It provides protection from circular references by keeping track of
  3958. * of loaded references. However, you must be careful not to load any graphs
  3959. * that have references to the catalog or other pages since that will cause the
  3960. * entire PDF document object graph to be traversed.
  3961. */
  3962. var ObjectLoader = (function() {
  3963. function mayHaveChildren(value) {
  3964. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  3965. }
  3966. function addChildren(node, nodesToVisit) {
  3967. var value;
  3968. if (isDict(node) || isStream(node)) {
  3969. var map;
  3970. if (isDict(node)) {
  3971. map = node.map;
  3972. } else {
  3973. map = node.dict.map;
  3974. }
  3975. for (var key in map) {
  3976. value = map[key];
  3977. if (mayHaveChildren(value)) {
  3978. nodesToVisit.push(value);
  3979. }
  3980. }
  3981. } else if (isArray(node)) {
  3982. for (var i = 0, ii = node.length; i < ii; i++) {
  3983. value = node[i];
  3984. if (mayHaveChildren(value)) {
  3985. nodesToVisit.push(value);
  3986. }
  3987. }
  3988. }
  3989. }
  3990. function ObjectLoader(obj, keys, xref) {
  3991. this.obj = obj;
  3992. this.keys = keys;
  3993. this.xref = xref;
  3994. this.refSet = null;
  3995. }
  3996. ObjectLoader.prototype = {
  3997. load: function ObjectLoader_load() {
  3998. var keys = this.keys;
  3999. this.capability = createPromiseCapability();
  4000. // Don't walk the graph if all the data is already loaded.
  4001. if (!(this.xref.stream instanceof ChunkedStream) ||
  4002. this.xref.stream.getMissingChunks().length === 0) {
  4003. this.capability.resolve();
  4004. return this.capability.promise;
  4005. }
  4006. this.refSet = new RefSet();
  4007. // Setup the initial nodes to visit.
  4008. var nodesToVisit = [];
  4009. for (var i = 0; i < keys.length; i++) {
  4010. nodesToVisit.push(this.obj[keys[i]]);
  4011. }
  4012. this.walk(nodesToVisit);
  4013. return this.capability.promise;
  4014. },
  4015. walk: function ObjectLoader_walk(nodesToVisit) {
  4016. var nodesToRevisit = [];
  4017. var pendingRequests = [];
  4018. // DFS walk of the object graph.
  4019. while (nodesToVisit.length) {
  4020. var currentNode = nodesToVisit.pop();
  4021. // Only references or chunked streams can cause missing data exceptions.
  4022. if (isRef(currentNode)) {
  4023. // Skip nodes that have already been visited.
  4024. if (this.refSet.has(currentNode)) {
  4025. continue;
  4026. }
  4027. try {
  4028. var ref = currentNode;
  4029. this.refSet.put(ref);
  4030. currentNode = this.xref.fetch(currentNode);
  4031. } catch (e) {
  4032. if (!(e instanceof MissingDataException)) {
  4033. throw e;
  4034. }
  4035. nodesToRevisit.push(currentNode);
  4036. pendingRequests.push({ begin: e.begin, end: e.end });
  4037. }
  4038. }
  4039. if (currentNode && currentNode.getBaseStreams) {
  4040. var baseStreams = currentNode.getBaseStreams();
  4041. var foundMissingData = false;
  4042. for (var i = 0; i < baseStreams.length; i++) {
  4043. var stream = baseStreams[i];
  4044. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4045. foundMissingData = true;
  4046. pendingRequests.push({
  4047. begin: stream.start,
  4048. end: stream.end
  4049. });
  4050. }
  4051. }
  4052. if (foundMissingData) {
  4053. nodesToRevisit.push(currentNode);
  4054. }
  4055. }
  4056. addChildren(currentNode, nodesToVisit);
  4057. }
  4058. if (pendingRequests.length) {
  4059. this.xref.stream.manager.requestRanges(pendingRequests,
  4060. function pendingRequestCallback() {
  4061. nodesToVisit = nodesToRevisit;
  4062. for (var i = 0; i < nodesToRevisit.length; i++) {
  4063. var node = nodesToRevisit[i];
  4064. // Remove any reference nodes from the currrent refset so they
  4065. // aren't skipped when we revist them.
  4066. if (isRef(node)) {
  4067. this.refSet.remove(node);
  4068. }
  4069. }
  4070. this.walk(nodesToVisit);
  4071. }.bind(this));
  4072. return;
  4073. }
  4074. // Everything is loaded.
  4075. this.refSet = null;
  4076. this.capability.resolve();
  4077. }
  4078. };
  4079. return ObjectLoader;
  4080. })();
  4081. var ISOAdobeCharset = [
  4082. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4083. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4084. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4085. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4086. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4087. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4088. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4089. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4090. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4091. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4092. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4093. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4094. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4095. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4096. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4097. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4098. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4099. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4100. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4101. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4102. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4103. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4104. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4105. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4106. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4107. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4108. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4109. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4110. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4111. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4112. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4113. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4114. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4115. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4116. ];
  4117. var ExpertCharset = [
  4118. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4119. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4120. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4121. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4122. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4123. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4124. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4125. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4126. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4127. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4128. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4129. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4130. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4131. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4132. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4133. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4134. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4135. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4136. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4137. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4138. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4139. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4140. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4141. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4142. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4143. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4144. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4145. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4146. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4147. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4148. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4149. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4150. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4151. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4152. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4153. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4154. 'Ydieresissmall'
  4155. ];
  4156. var ExpertSubsetCharset = [
  4157. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4158. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4159. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4160. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4161. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4162. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4163. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4164. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4165. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4166. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4167. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4168. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4169. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4170. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4171. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4172. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4173. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4174. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4175. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4176. 'periodinferior', 'commainferior'
  4177. ];
  4178. var DEFAULT_ICON_SIZE = 22; // px
  4179. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4180. var Annotation = (function AnnotationClosure() {
  4181. // 12.5.5: Algorithm: Appearance streams
  4182. function getTransformMatrix(rect, bbox, matrix) {
  4183. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4184. var minX = bounds[0];
  4185. var minY = bounds[1];
  4186. var maxX = bounds[2];
  4187. var maxY = bounds[3];
  4188. if (minX === maxX || minY === maxY) {
  4189. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4190. // just apply the transform for rect
  4191. return [1, 0, 0, 1, rect[0], rect[1]];
  4192. }
  4193. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4194. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4195. return [
  4196. xRatio,
  4197. 0,
  4198. 0,
  4199. yRatio,
  4200. rect[0] - minX * xRatio,
  4201. rect[1] - minY * yRatio
  4202. ];
  4203. }
  4204. function getDefaultAppearance(dict) {
  4205. var appearanceState = dict.get('AP');
  4206. if (!isDict(appearanceState)) {
  4207. return;
  4208. }
  4209. var appearance;
  4210. var appearances = appearanceState.get('N');
  4211. if (isDict(appearances)) {
  4212. var as = dict.get('AS');
  4213. if (as && appearances.has(as.name)) {
  4214. appearance = appearances.get(as.name);
  4215. }
  4216. } else {
  4217. appearance = appearances;
  4218. }
  4219. return appearance;
  4220. }
  4221. function Annotation(params) {
  4222. var dict = params.dict;
  4223. var data = this.data = {};
  4224. data.subtype = dict.get('Subtype').name;
  4225. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4226. data.rect = Util.normalizeRect(rect);
  4227. data.annotationFlags = dict.get('F');
  4228. var color = dict.get('C');
  4229. if (isArray(color) && color.length === 3) {
  4230. // TODO(mack): currently only supporting rgb; need support different
  4231. // colorspaces
  4232. data.color = color;
  4233. } else {
  4234. data.color = [0, 0, 0];
  4235. }
  4236. // Some types of annotations have border style dict which has more
  4237. // info than the border array
  4238. if (dict.has('BS')) {
  4239. var borderStyle = dict.get('BS');
  4240. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4241. } else {
  4242. var borderArray = dict.get('Border') || [0, 0, 1];
  4243. data.borderWidth = borderArray[2] || 0;
  4244. // TODO: implement proper support for annotations with line dash patterns.
  4245. var dashArray = borderArray[3];
  4246. if (data.borderWidth > 0 && dashArray) {
  4247. if (!isArray(dashArray)) {
  4248. // Ignore the border if dashArray is not actually an array,
  4249. // this is consistent with the behaviour in Adobe Reader.
  4250. data.borderWidth = 0;
  4251. } else {
  4252. var dashArrayLength = dashArray.length;
  4253. if (dashArrayLength > 0) {
  4254. // According to the PDF specification: the elements in a dashArray
  4255. // shall be numbers that are nonnegative and not all equal to zero.
  4256. var isInvalid = false;
  4257. var numPositive = 0;
  4258. for (var i = 0; i < dashArrayLength; i++) {
  4259. var validNumber = (+dashArray[i] >= 0);
  4260. if (!validNumber) {
  4261. isInvalid = true;
  4262. break;
  4263. } else if (dashArray[i] > 0) {
  4264. numPositive++;
  4265. }
  4266. }
  4267. if (isInvalid || numPositive === 0) {
  4268. data.borderWidth = 0;
  4269. }
  4270. }
  4271. }
  4272. }
  4273. }
  4274. this.appearance = getDefaultAppearance(dict);
  4275. data.hasAppearance = !!this.appearance;
  4276. data.id = params.ref.num;
  4277. }
  4278. Annotation.prototype = {
  4279. getData: function Annotation_getData() {
  4280. return this.data;
  4281. },
  4282. isInvisible: function Annotation_isInvisible() {
  4283. var data = this.data;
  4284. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4285. return false;
  4286. } else {
  4287. return !!(data &&
  4288. data.annotationFlags && // Default: not invisible
  4289. data.annotationFlags & 0x1); // Invisible
  4290. }
  4291. },
  4292. isViewable: function Annotation_isViewable() {
  4293. var data = this.data;
  4294. return !!(!this.isInvisible() &&
  4295. data &&
  4296. (!data.annotationFlags ||
  4297. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4298. data.rect); // rectangle is necessary
  4299. },
  4300. isPrintable: function Annotation_isPrintable() {
  4301. var data = this.data;
  4302. return !!(!this.isInvisible() &&
  4303. data &&
  4304. data.annotationFlags && // Default: not printable
  4305. data.annotationFlags & 0x4 && // Print
  4306. !(data.annotationFlags & 0x2) && // Hidden
  4307. data.rect); // rectangle is necessary
  4308. },
  4309. loadResources: function Annotation_loadResources(keys) {
  4310. return new Promise(function (resolve, reject) {
  4311. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4312. if (!resources) {
  4313. resolve();
  4314. return;
  4315. }
  4316. var objectLoader = new ObjectLoader(resources.map,
  4317. keys,
  4318. resources.xref);
  4319. objectLoader.load().then(function() {
  4320. resolve(resources);
  4321. }, reject);
  4322. }, reject);
  4323. }.bind(this));
  4324. },
  4325. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4326. if (!this.appearance) {
  4327. return Promise.resolve(new OperatorList());
  4328. }
  4329. var data = this.data;
  4330. var appearanceDict = this.appearance.dict;
  4331. var resourcesPromise = this.loadResources([
  4332. 'ExtGState',
  4333. 'ColorSpace',
  4334. 'Pattern',
  4335. 'Shading',
  4336. 'XObject',
  4337. 'Font'
  4338. // ProcSet
  4339. // Properties
  4340. ]);
  4341. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4342. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4343. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4344. var self = this;
  4345. return resourcesPromise.then(function(resources) {
  4346. var opList = new OperatorList();
  4347. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4348. return evaluator.getOperatorList(self.appearance, resources, opList).
  4349. then(function () {
  4350. opList.addOp(OPS.endAnnotation, []);
  4351. self.appearance.reset();
  4352. return opList;
  4353. });
  4354. });
  4355. }
  4356. };
  4357. Annotation.getConstructor =
  4358. function Annotation_getConstructor(subtype, fieldType) {
  4359. if (!subtype) {
  4360. return;
  4361. }
  4362. // TODO(mack): Implement FreeText annotations
  4363. if (subtype === 'Link') {
  4364. return LinkAnnotation;
  4365. } else if (subtype === 'Text') {
  4366. return TextAnnotation;
  4367. } else if (subtype === 'Widget') {
  4368. if (!fieldType) {
  4369. return;
  4370. }
  4371. if (fieldType === 'Tx') {
  4372. return TextWidgetAnnotation;
  4373. } else {
  4374. return WidgetAnnotation;
  4375. }
  4376. } else {
  4377. return Annotation;
  4378. }
  4379. };
  4380. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4381. var dict = xref.fetchIfRef(ref);
  4382. if (!isDict(dict)) {
  4383. return;
  4384. }
  4385. var subtype = dict.get('Subtype');
  4386. subtype = isName(subtype) ? subtype.name : '';
  4387. if (!subtype) {
  4388. return;
  4389. }
  4390. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4391. fieldType = isName(fieldType) ? fieldType.name : '';
  4392. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4393. if (!Constructor) {
  4394. return;
  4395. }
  4396. var params = {
  4397. dict: dict,
  4398. ref: ref,
  4399. };
  4400. var annotation = new Constructor(params);
  4401. if (annotation.isViewable() || annotation.isPrintable()) {
  4402. return annotation;
  4403. } else {
  4404. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4405. warn('unimplemented annotation type: ' + subtype);
  4406. }
  4407. }
  4408. };
  4409. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4410. annotations, opList, pdfManager, partialEvaluator, intent) {
  4411. function reject(e) {
  4412. annotationsReadyCapability.reject(e);
  4413. }
  4414. var annotationsReadyCapability = createPromiseCapability();
  4415. var annotationPromises = [];
  4416. for (var i = 0, n = annotations.length; i < n; ++i) {
  4417. if (intent === 'display' && annotations[i].isViewable() ||
  4418. intent === 'print' && annotations[i].isPrintable()) {
  4419. annotationPromises.push(
  4420. annotations[i].getOperatorList(partialEvaluator));
  4421. }
  4422. }
  4423. Promise.all(annotationPromises).then(function(datas) {
  4424. opList.addOp(OPS.beginAnnotations, []);
  4425. for (var i = 0, n = datas.length; i < n; ++i) {
  4426. var annotOpList = datas[i];
  4427. opList.addOpList(annotOpList);
  4428. }
  4429. opList.addOp(OPS.endAnnotations, []);
  4430. annotationsReadyCapability.resolve();
  4431. }, reject);
  4432. return annotationsReadyCapability.promise;
  4433. };
  4434. return Annotation;
  4435. })();
  4436. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4437. function WidgetAnnotation(params) {
  4438. Annotation.call(this, params);
  4439. var dict = params.dict;
  4440. var data = this.data;
  4441. data.fieldValue = stringToPDFString(
  4442. Util.getInheritableProperty(dict, 'V') || '');
  4443. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4444. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4445. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4446. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4447. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4448. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4449. // Building the full field name by collecting the field and
  4450. // its ancestors 'T' data and joining them using '.'.
  4451. var fieldName = [];
  4452. var namedItem = dict;
  4453. var ref = params.ref;
  4454. while (namedItem) {
  4455. var parent = namedItem.get('Parent');
  4456. var parentRef = namedItem.getRaw('Parent');
  4457. var name = namedItem.get('T');
  4458. if (name) {
  4459. fieldName.unshift(stringToPDFString(name));
  4460. } else {
  4461. // The field name is absent, that means more than one field
  4462. // with the same name may exist. Replacing the empty name
  4463. // with the '`' plus index in the parent's 'Kids' array.
  4464. // This is not in the PDF spec but necessary to id the
  4465. // the input controls.
  4466. var kids = parent.get('Kids');
  4467. var j, jj;
  4468. for (j = 0, jj = kids.length; j < jj; j++) {
  4469. var kidRef = kids[j];
  4470. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4471. break;
  4472. }
  4473. }
  4474. fieldName.unshift('`' + j);
  4475. }
  4476. namedItem = parent;
  4477. ref = parentRef;
  4478. }
  4479. data.fullName = fieldName.join('.');
  4480. }
  4481. var parent = Annotation.prototype;
  4482. Util.inherit(WidgetAnnotation, Annotation, {
  4483. isViewable: function WidgetAnnotation_isViewable() {
  4484. if (this.data.fieldType === 'Sig') {
  4485. warn('unimplemented annotation type: Widget signature');
  4486. return false;
  4487. }
  4488. return parent.isViewable.call(this);
  4489. }
  4490. });
  4491. return WidgetAnnotation;
  4492. })();
  4493. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4494. function TextWidgetAnnotation(params) {
  4495. WidgetAnnotation.call(this, params);
  4496. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4497. this.data.annotationType = AnnotationType.WIDGET;
  4498. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4499. }
  4500. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4501. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4502. if (this.appearance) {
  4503. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4504. }
  4505. var opList = new OperatorList();
  4506. var data = this.data;
  4507. // Even if there is an appearance stream, ignore it. This is the
  4508. // behaviour used by Adobe Reader.
  4509. if (!data.defaultAppearance) {
  4510. return Promise.resolve(opList);
  4511. }
  4512. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4513. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4514. then(function () {
  4515. return opList;
  4516. });
  4517. }
  4518. });
  4519. return TextWidgetAnnotation;
  4520. })();
  4521. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4522. function InteractiveAnnotation(params) {
  4523. Annotation.call(this, params);
  4524. this.data.hasHtml = true;
  4525. }
  4526. Util.inherit(InteractiveAnnotation, Annotation, { });
  4527. return InteractiveAnnotation;
  4528. })();
  4529. var TextAnnotation = (function TextAnnotationClosure() {
  4530. function TextAnnotation(params) {
  4531. InteractiveAnnotation.call(this, params);
  4532. var dict = params.dict;
  4533. var data = this.data;
  4534. var content = dict.get('Contents');
  4535. var title = dict.get('T');
  4536. data.annotationType = AnnotationType.TEXT;
  4537. data.content = stringToPDFString(content || '');
  4538. data.title = stringToPDFString(title || '');
  4539. if (data.hasAppearance) {
  4540. data.name = 'NoIcon';
  4541. } else {
  4542. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4543. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4544. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4545. }
  4546. if (dict.has('C')) {
  4547. data.hasBgColor = true;
  4548. }
  4549. }
  4550. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4551. return TextAnnotation;
  4552. })();
  4553. var LinkAnnotation = (function LinkAnnotationClosure() {
  4554. function LinkAnnotation(params) {
  4555. InteractiveAnnotation.call(this, params);
  4556. var dict = params.dict;
  4557. var data = this.data;
  4558. data.annotationType = AnnotationType.LINK;
  4559. var action = dict.get('A');
  4560. if (action) {
  4561. var linkType = action.get('S').name;
  4562. if (linkType === 'URI') {
  4563. var url = action.get('URI');
  4564. if (isName(url)) {
  4565. // Some bad PDFs do not put parentheses around relative URLs.
  4566. url = '/' + url.name;
  4567. } else if (url) {
  4568. url = addDefaultProtocolToUrl(url);
  4569. }
  4570. // TODO: pdf spec mentions urls can be relative to a Base
  4571. // entry in the dictionary.
  4572. if (!isValidUrl(url, false)) {
  4573. url = '';
  4574. }
  4575. data.url = url;
  4576. } else if (linkType === 'GoTo') {
  4577. data.dest = action.get('D');
  4578. } else if (linkType === 'GoToR') {
  4579. var urlDict = action.get('F');
  4580. if (isDict(urlDict)) {
  4581. // We assume that the 'url' is a Filspec dictionary
  4582. // and fetch the url without checking any further
  4583. url = urlDict.get('F') || '';
  4584. }
  4585. // TODO: pdf reference says that GoToR
  4586. // can also have 'NewWindow' attribute
  4587. if (!isValidUrl(url, false)) {
  4588. url = '';
  4589. }
  4590. data.url = url;
  4591. data.dest = action.get('D');
  4592. } else if (linkType === 'Named') {
  4593. data.action = action.get('N').name;
  4594. } else {
  4595. warn('unrecognized link type: ' + linkType);
  4596. }
  4597. } else if (dict.has('Dest')) {
  4598. // simple destination link
  4599. var dest = dict.get('Dest');
  4600. data.dest = isName(dest) ? dest.name : dest;
  4601. }
  4602. }
  4603. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4604. function addDefaultProtocolToUrl(url) {
  4605. if (url && url.indexOf('www.') === 0) {
  4606. return ('http://' + url);
  4607. }
  4608. return url;
  4609. }
  4610. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  4611. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  4612. return false;
  4613. }
  4614. });
  4615. return LinkAnnotation;
  4616. })();
  4617. var PDFFunction = (function PDFFunctionClosure() {
  4618. var CONSTRUCT_SAMPLED = 0;
  4619. var CONSTRUCT_INTERPOLATED = 2;
  4620. var CONSTRUCT_STICHED = 3;
  4621. var CONSTRUCT_POSTSCRIPT = 4;
  4622. return {
  4623. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4624. str) {
  4625. var i, ii;
  4626. var length = 1;
  4627. for (i = 0, ii = size.length; i < ii; i++) {
  4628. length *= size[i];
  4629. }
  4630. length *= outputSize;
  4631. var array = new Array(length);
  4632. var codeSize = 0;
  4633. var codeBuf = 0;
  4634. // 32 is a valid bps so shifting won't work
  4635. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4636. var strBytes = str.getBytes((length * bps + 7) / 8);
  4637. var strIdx = 0;
  4638. for (i = 0; i < length; i++) {
  4639. while (codeSize < bps) {
  4640. codeBuf <<= 8;
  4641. codeBuf |= strBytes[strIdx++];
  4642. codeSize += 8;
  4643. }
  4644. codeSize -= bps;
  4645. array[i] = (codeBuf >> codeSize) * sampleMul;
  4646. codeBuf &= (1 << codeSize) - 1;
  4647. }
  4648. return array;
  4649. },
  4650. getIR: function PDFFunction_getIR(xref, fn) {
  4651. var dict = fn.dict;
  4652. if (!dict) {
  4653. dict = fn;
  4654. }
  4655. var types = [this.constructSampled,
  4656. null,
  4657. this.constructInterpolated,
  4658. this.constructStiched,
  4659. this.constructPostScript];
  4660. var typeNum = dict.get('FunctionType');
  4661. var typeFn = types[typeNum];
  4662. if (!typeFn) {
  4663. error('Unknown type of function');
  4664. }
  4665. return typeFn.call(this, fn, dict, xref);
  4666. },
  4667. fromIR: function PDFFunction_fromIR(IR) {
  4668. var type = IR[0];
  4669. switch (type) {
  4670. case CONSTRUCT_SAMPLED:
  4671. return this.constructSampledFromIR(IR);
  4672. case CONSTRUCT_INTERPOLATED:
  4673. return this.constructInterpolatedFromIR(IR);
  4674. case CONSTRUCT_STICHED:
  4675. return this.constructStichedFromIR(IR);
  4676. //case CONSTRUCT_POSTSCRIPT:
  4677. default:
  4678. return this.constructPostScriptFromIR(IR);
  4679. }
  4680. },
  4681. parse: function PDFFunction_parse(xref, fn) {
  4682. var IR = this.getIR(xref, fn);
  4683. return this.fromIR(IR);
  4684. },
  4685. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4686. if (!isArray(fnObj)) {
  4687. // not an array -- parsing as regular function
  4688. return this.parse(xref, fnObj);
  4689. }
  4690. var fnArray = [];
  4691. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4692. var obj = xref.fetchIfRef(fnObj[j]);
  4693. fnArray.push(PDFFunction.parse(xref, obj));
  4694. }
  4695. return function (src, srcOffset, dest, destOffset) {
  4696. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4697. fnArray[i](src, srcOffset, dest, destOffset + i);
  4698. }
  4699. };
  4700. },
  4701. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4702. function toMultiArray(arr) {
  4703. var inputLength = arr.length;
  4704. var out = [];
  4705. var index = 0;
  4706. for (var i = 0; i < inputLength; i += 2) {
  4707. out[index] = [arr[i], arr[i + 1]];
  4708. ++index;
  4709. }
  4710. return out;
  4711. }
  4712. var domain = dict.get('Domain');
  4713. var range = dict.get('Range');
  4714. if (!domain || !range) {
  4715. error('No domain or range');
  4716. }
  4717. var inputSize = domain.length / 2;
  4718. var outputSize = range.length / 2;
  4719. domain = toMultiArray(domain);
  4720. range = toMultiArray(range);
  4721. var size = dict.get('Size');
  4722. var bps = dict.get('BitsPerSample');
  4723. var order = dict.get('Order') || 1;
  4724. if (order !== 1) {
  4725. // No description how cubic spline interpolation works in PDF32000:2008
  4726. // As in poppler, ignoring order, linear interpolation may work as good
  4727. info('No support for cubic spline interpolation: ' + order);
  4728. }
  4729. var encode = dict.get('Encode');
  4730. if (!encode) {
  4731. encode = [];
  4732. for (var i = 0; i < inputSize; ++i) {
  4733. encode.push(0);
  4734. encode.push(size[i] - 1);
  4735. }
  4736. }
  4737. encode = toMultiArray(encode);
  4738. var decode = dict.get('Decode');
  4739. if (!decode) {
  4740. decode = range;
  4741. } else {
  4742. decode = toMultiArray(decode);
  4743. }
  4744. var samples = this.getSampleArray(size, outputSize, bps, str);
  4745. return [
  4746. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4747. outputSize, Math.pow(2, bps) - 1, range
  4748. ];
  4749. },
  4750. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4751. // See chapter 3, page 109 of the PDF reference
  4752. function interpolate(x, xmin, xmax, ymin, ymax) {
  4753. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4754. }
  4755. return function constructSampledFromIRResult(src, srcOffset,
  4756. dest, destOffset) {
  4757. // See chapter 3, page 110 of the PDF reference.
  4758. var m = IR[1];
  4759. var domain = IR[2];
  4760. var encode = IR[3];
  4761. var decode = IR[4];
  4762. var samples = IR[5];
  4763. var size = IR[6];
  4764. var n = IR[7];
  4765. //var mask = IR[8];
  4766. var range = IR[9];
  4767. // Building the cube vertices: its part and sample index
  4768. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4769. var cubeVertices = 1 << m;
  4770. var cubeN = new Float64Array(cubeVertices);
  4771. var cubeVertex = new Uint32Array(cubeVertices);
  4772. var i, j;
  4773. for (j = 0; j < cubeVertices; j++) {
  4774. cubeN[j] = 1;
  4775. }
  4776. var k = n, pos = 1;
  4777. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4778. for (i = 0; i < m; ++i) {
  4779. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4780. var domain_2i = domain[i][0];
  4781. var domain_2i_1 = domain[i][1];
  4782. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4783. domain_2i_1);
  4784. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4785. // Encode_2i, Encode_2i+1)
  4786. var e = interpolate(xi, domain_2i, domain_2i_1,
  4787. encode[i][0], encode[i][1]);
  4788. // e_i' = min(max(e_i, 0), Size_i - 1)
  4789. var size_i = size[i];
  4790. e = Math.min(Math.max(e, 0), size_i - 1);
  4791. // Adjusting the cube: N and vertex sample index
  4792. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4793. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4794. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4795. var offset0 = e0 * k;
  4796. var offset1 = offset0 + k; // e1 * k
  4797. for (j = 0; j < cubeVertices; j++) {
  4798. if (j & pos) {
  4799. cubeN[j] *= n1;
  4800. cubeVertex[j] += offset1;
  4801. } else {
  4802. cubeN[j] *= n0;
  4803. cubeVertex[j] += offset0;
  4804. }
  4805. }
  4806. k *= size_i;
  4807. pos <<= 1;
  4808. }
  4809. for (j = 0; j < n; ++j) {
  4810. // Sum all cube vertices' samples portions
  4811. var rj = 0;
  4812. for (i = 0; i < cubeVertices; i++) {
  4813. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4814. }
  4815. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4816. // Decode_2j, Decode_2j+1)
  4817. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4818. // y_j = min(max(r_j, range_2j), range_2j+1)
  4819. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  4820. range[j][1]);
  4821. }
  4822. };
  4823. },
  4824. constructInterpolated: function PDFFunction_constructInterpolated(str,
  4825. dict) {
  4826. var c0 = dict.get('C0') || [0];
  4827. var c1 = dict.get('C1') || [1];
  4828. var n = dict.get('N');
  4829. if (!isArray(c0) || !isArray(c1)) {
  4830. error('Illegal dictionary for interpolated function');
  4831. }
  4832. var length = c0.length;
  4833. var diff = [];
  4834. for (var i = 0; i < length; ++i) {
  4835. diff.push(c1[i] - c0[i]);
  4836. }
  4837. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  4838. },
  4839. constructInterpolatedFromIR:
  4840. function PDFFunction_constructInterpolatedFromIR(IR) {
  4841. var c0 = IR[1];
  4842. var diff = IR[2];
  4843. var n = IR[3];
  4844. var length = diff.length;
  4845. return function constructInterpolatedFromIRResult(src, srcOffset,
  4846. dest, destOffset) {
  4847. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  4848. for (var j = 0; j < length; ++j) {
  4849. dest[destOffset + j] = c0[j] + (x * diff[j]);
  4850. }
  4851. };
  4852. },
  4853. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  4854. var domain = dict.get('Domain');
  4855. if (!domain) {
  4856. error('No domain');
  4857. }
  4858. var inputSize = domain.length / 2;
  4859. if (inputSize !== 1) {
  4860. error('Bad domain for stiched function');
  4861. }
  4862. var fnRefs = dict.get('Functions');
  4863. var fns = [];
  4864. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  4865. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  4866. }
  4867. var bounds = dict.get('Bounds');
  4868. var encode = dict.get('Encode');
  4869. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  4870. },
  4871. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  4872. var domain = IR[1];
  4873. var bounds = IR[2];
  4874. var encode = IR[3];
  4875. var fnsIR = IR[4];
  4876. var fns = [];
  4877. var tmpBuf = new Float32Array(1);
  4878. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  4879. fns.push(PDFFunction.fromIR(fnsIR[i]));
  4880. }
  4881. return function constructStichedFromIRResult(src, srcOffset,
  4882. dest, destOffset) {
  4883. var clip = function constructStichedFromIRClip(v, min, max) {
  4884. if (v > max) {
  4885. v = max;
  4886. } else if (v < min) {
  4887. v = min;
  4888. }
  4889. return v;
  4890. };
  4891. // clip to domain
  4892. var v = clip(src[srcOffset], domain[0], domain[1]);
  4893. // calulate which bound the value is in
  4894. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  4895. if (v < bounds[i]) {
  4896. break;
  4897. }
  4898. }
  4899. // encode value into domain of function
  4900. var dmin = domain[0];
  4901. if (i > 0) {
  4902. dmin = bounds[i - 1];
  4903. }
  4904. var dmax = domain[1];
  4905. if (i < bounds.length) {
  4906. dmax = bounds[i];
  4907. }
  4908. var rmin = encode[2 * i];
  4909. var rmax = encode[2 * i + 1];
  4910. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  4911. // call the appropriate function
  4912. fns[i](tmpBuf, 0, dest, destOffset);
  4913. };
  4914. },
  4915. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  4916. xref) {
  4917. var domain = dict.get('Domain');
  4918. var range = dict.get('Range');
  4919. if (!domain) {
  4920. error('No domain.');
  4921. }
  4922. if (!range) {
  4923. error('No range.');
  4924. }
  4925. var lexer = new PostScriptLexer(fn);
  4926. var parser = new PostScriptParser(lexer);
  4927. var code = parser.parse();
  4928. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  4929. },
  4930. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  4931. IR) {
  4932. var domain = IR[1];
  4933. var range = IR[2];
  4934. var code = IR[3];
  4935. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  4936. if (compiled) {
  4937. // Compiled function consists of simple expressions such as addition,
  4938. // subtraction, Math.max, and also contains 'var' and 'return'
  4939. // statements. See the generation in the PostScriptCompiler below.
  4940. /*jshint -W054 */
  4941. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  4942. }
  4943. info('Unable to compile PS function');
  4944. var numOutputs = range.length >> 1;
  4945. var numInputs = domain.length >> 1;
  4946. var evaluator = new PostScriptEvaluator(code);
  4947. // Cache the values for a big speed up, the cache size is limited though
  4948. // since the number of possible values can be huge from a PS function.
  4949. var cache = {};
  4950. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  4951. // seen in our tests.
  4952. var MAX_CACHE_SIZE = 2048 * 4;
  4953. var cache_available = MAX_CACHE_SIZE;
  4954. var tmpBuf = new Float32Array(numInputs);
  4955. return function constructPostScriptFromIRResult(src, srcOffset,
  4956. dest, destOffset) {
  4957. var i, value;
  4958. var key = '';
  4959. var input = tmpBuf;
  4960. for (i = 0; i < numInputs; i++) {
  4961. value = src[srcOffset + i];
  4962. input[i] = value;
  4963. key += value + '_';
  4964. }
  4965. var cachedValue = cache[key];
  4966. if (cachedValue !== undefined) {
  4967. cachedValue.set(dest, destOffset);
  4968. return;
  4969. }
  4970. var output = new Float32Array(numOutputs);
  4971. var stack = evaluator.execute(input);
  4972. var stackIndex = stack.length - numOutputs;
  4973. for (i = 0; i < numOutputs; i++) {
  4974. value = stack[stackIndex + i];
  4975. var bound = range[i * 2];
  4976. if (value < bound) {
  4977. value = bound;
  4978. } else {
  4979. bound = range[i * 2 +1];
  4980. if (value > bound) {
  4981. value = bound;
  4982. }
  4983. }
  4984. output[i] = value;
  4985. }
  4986. if (cache_available > 0) {
  4987. cache_available--;
  4988. cache[key] = output;
  4989. }
  4990. output.set(dest, destOffset);
  4991. };
  4992. }
  4993. };
  4994. })();
  4995. function isPDFFunction(v) {
  4996. var fnDict;
  4997. if (typeof v !== 'object') {
  4998. return false;
  4999. } else if (isDict(v)) {
  5000. fnDict = v;
  5001. } else if (isStream(v)) {
  5002. fnDict = v.dict;
  5003. } else {
  5004. return false;
  5005. }
  5006. return fnDict.has('FunctionType');
  5007. }
  5008. var PostScriptStack = (function PostScriptStackClosure() {
  5009. var MAX_STACK_SIZE = 100;
  5010. function PostScriptStack(initialStack) {
  5011. this.stack = !initialStack ? [] :
  5012. Array.prototype.slice.call(initialStack, 0);
  5013. }
  5014. PostScriptStack.prototype = {
  5015. push: function PostScriptStack_push(value) {
  5016. if (this.stack.length >= MAX_STACK_SIZE) {
  5017. error('PostScript function stack overflow.');
  5018. }
  5019. this.stack.push(value);
  5020. },
  5021. pop: function PostScriptStack_pop() {
  5022. if (this.stack.length <= 0) {
  5023. error('PostScript function stack underflow.');
  5024. }
  5025. return this.stack.pop();
  5026. },
  5027. copy: function PostScriptStack_copy(n) {
  5028. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5029. error('PostScript function stack overflow.');
  5030. }
  5031. var stack = this.stack;
  5032. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5033. stack.push(stack[i]);
  5034. }
  5035. },
  5036. index: function PostScriptStack_index(n) {
  5037. this.push(this.stack[this.stack.length - n - 1]);
  5038. },
  5039. // rotate the last n stack elements p times
  5040. roll: function PostScriptStack_roll(n, p) {
  5041. var stack = this.stack;
  5042. var l = stack.length - n;
  5043. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5044. for (i = l, j = r; i < j; i++, j--) {
  5045. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5046. }
  5047. for (i = l, j = c - 1; i < j; i++, j--) {
  5048. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5049. }
  5050. for (i = c, j = r; i < j; i++, j--) {
  5051. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5052. }
  5053. }
  5054. };
  5055. return PostScriptStack;
  5056. })();
  5057. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5058. function PostScriptEvaluator(operators) {
  5059. this.operators = operators;
  5060. }
  5061. PostScriptEvaluator.prototype = {
  5062. execute: function PostScriptEvaluator_execute(initialStack) {
  5063. var stack = new PostScriptStack(initialStack);
  5064. var counter = 0;
  5065. var operators = this.operators;
  5066. var length = operators.length;
  5067. var operator, a, b;
  5068. while (counter < length) {
  5069. operator = operators[counter++];
  5070. if (typeof operator === 'number') {
  5071. // Operator is really an operand and should be pushed to the stack.
  5072. stack.push(operator);
  5073. continue;
  5074. }
  5075. switch (operator) {
  5076. // non standard ps operators
  5077. case 'jz': // jump if false
  5078. b = stack.pop();
  5079. a = stack.pop();
  5080. if (!a) {
  5081. counter = b;
  5082. }
  5083. break;
  5084. case 'j': // jump
  5085. a = stack.pop();
  5086. counter = a;
  5087. break;
  5088. // all ps operators in alphabetical order (excluding if/ifelse)
  5089. case 'abs':
  5090. a = stack.pop();
  5091. stack.push(Math.abs(a));
  5092. break;
  5093. case 'add':
  5094. b = stack.pop();
  5095. a = stack.pop();
  5096. stack.push(a + b);
  5097. break;
  5098. case 'and':
  5099. b = stack.pop();
  5100. a = stack.pop();
  5101. if (isBool(a) && isBool(b)) {
  5102. stack.push(a && b);
  5103. } else {
  5104. stack.push(a & b);
  5105. }
  5106. break;
  5107. case 'atan':
  5108. a = stack.pop();
  5109. stack.push(Math.atan(a));
  5110. break;
  5111. case 'bitshift':
  5112. b = stack.pop();
  5113. a = stack.pop();
  5114. if (a > 0) {
  5115. stack.push(a << b);
  5116. } else {
  5117. stack.push(a >> b);
  5118. }
  5119. break;
  5120. case 'ceiling':
  5121. a = stack.pop();
  5122. stack.push(Math.ceil(a));
  5123. break;
  5124. case 'copy':
  5125. a = stack.pop();
  5126. stack.copy(a);
  5127. break;
  5128. case 'cos':
  5129. a = stack.pop();
  5130. stack.push(Math.cos(a));
  5131. break;
  5132. case 'cvi':
  5133. a = stack.pop() | 0;
  5134. stack.push(a);
  5135. break;
  5136. case 'cvr':
  5137. // noop
  5138. break;
  5139. case 'div':
  5140. b = stack.pop();
  5141. a = stack.pop();
  5142. stack.push(a / b);
  5143. break;
  5144. case 'dup':
  5145. stack.copy(1);
  5146. break;
  5147. case 'eq':
  5148. b = stack.pop();
  5149. a = stack.pop();
  5150. stack.push(a === b);
  5151. break;
  5152. case 'exch':
  5153. stack.roll(2, 1);
  5154. break;
  5155. case 'exp':
  5156. b = stack.pop();
  5157. a = stack.pop();
  5158. stack.push(Math.pow(a, b));
  5159. break;
  5160. case 'false':
  5161. stack.push(false);
  5162. break;
  5163. case 'floor':
  5164. a = stack.pop();
  5165. stack.push(Math.floor(a));
  5166. break;
  5167. case 'ge':
  5168. b = stack.pop();
  5169. a = stack.pop();
  5170. stack.push(a >= b);
  5171. break;
  5172. case 'gt':
  5173. b = stack.pop();
  5174. a = stack.pop();
  5175. stack.push(a > b);
  5176. break;
  5177. case 'idiv':
  5178. b = stack.pop();
  5179. a = stack.pop();
  5180. stack.push((a / b) | 0);
  5181. break;
  5182. case 'index':
  5183. a = stack.pop();
  5184. stack.index(a);
  5185. break;
  5186. case 'le':
  5187. b = stack.pop();
  5188. a = stack.pop();
  5189. stack.push(a <= b);
  5190. break;
  5191. case 'ln':
  5192. a = stack.pop();
  5193. stack.push(Math.log(a));
  5194. break;
  5195. case 'log':
  5196. a = stack.pop();
  5197. stack.push(Math.log(a) / Math.LN10);
  5198. break;
  5199. case 'lt':
  5200. b = stack.pop();
  5201. a = stack.pop();
  5202. stack.push(a < b);
  5203. break;
  5204. case 'mod':
  5205. b = stack.pop();
  5206. a = stack.pop();
  5207. stack.push(a % b);
  5208. break;
  5209. case 'mul':
  5210. b = stack.pop();
  5211. a = stack.pop();
  5212. stack.push(a * b);
  5213. break;
  5214. case 'ne':
  5215. b = stack.pop();
  5216. a = stack.pop();
  5217. stack.push(a !== b);
  5218. break;
  5219. case 'neg':
  5220. a = stack.pop();
  5221. stack.push(-a);
  5222. break;
  5223. case 'not':
  5224. a = stack.pop();
  5225. if (isBool(a)) {
  5226. stack.push(!a);
  5227. } else {
  5228. stack.push(~a);
  5229. }
  5230. break;
  5231. case 'or':
  5232. b = stack.pop();
  5233. a = stack.pop();
  5234. if (isBool(a) && isBool(b)) {
  5235. stack.push(a || b);
  5236. } else {
  5237. stack.push(a | b);
  5238. }
  5239. break;
  5240. case 'pop':
  5241. stack.pop();
  5242. break;
  5243. case 'roll':
  5244. b = stack.pop();
  5245. a = stack.pop();
  5246. stack.roll(a, b);
  5247. break;
  5248. case 'round':
  5249. a = stack.pop();
  5250. stack.push(Math.round(a));
  5251. break;
  5252. case 'sin':
  5253. a = stack.pop();
  5254. stack.push(Math.sin(a));
  5255. break;
  5256. case 'sqrt':
  5257. a = stack.pop();
  5258. stack.push(Math.sqrt(a));
  5259. break;
  5260. case 'sub':
  5261. b = stack.pop();
  5262. a = stack.pop();
  5263. stack.push(a - b);
  5264. break;
  5265. case 'true':
  5266. stack.push(true);
  5267. break;
  5268. case 'truncate':
  5269. a = stack.pop();
  5270. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5271. stack.push(a);
  5272. break;
  5273. case 'xor':
  5274. b = stack.pop();
  5275. a = stack.pop();
  5276. if (isBool(a) && isBool(b)) {
  5277. stack.push(a !== b);
  5278. } else {
  5279. stack.push(a ^ b);
  5280. }
  5281. break;
  5282. default:
  5283. error('Unknown operator ' + operator);
  5284. break;
  5285. }
  5286. }
  5287. return stack.stack;
  5288. }
  5289. };
  5290. return PostScriptEvaluator;
  5291. })();
  5292. // Most of the PDFs functions consist of simple operations such as:
  5293. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5294. //
  5295. // We can compile most of such programs, and at the same moment, we can
  5296. // optimize some expressions using basic math properties. Keeping track of
  5297. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5298. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5299. function AstNode(type) {
  5300. this.type = type;
  5301. }
  5302. AstNode.prototype.visit = function (visitor) {
  5303. throw new Error('abstract method');
  5304. };
  5305. function AstArgument(index, min, max) {
  5306. AstNode.call(this, 'args');
  5307. this.index = index;
  5308. this.min = min;
  5309. this.max = max;
  5310. }
  5311. AstArgument.prototype = Object.create(AstNode.prototype);
  5312. AstArgument.prototype.visit = function (visitor) {
  5313. visitor.visitArgument(this);
  5314. };
  5315. function AstLiteral(number) {
  5316. AstNode.call(this, 'literal');
  5317. this.number = number;
  5318. this.min = number;
  5319. this.max = number;
  5320. }
  5321. AstLiteral.prototype = Object.create(AstNode.prototype);
  5322. AstLiteral.prototype.visit = function (visitor) {
  5323. visitor.visitLiteral(this);
  5324. };
  5325. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5326. AstNode.call(this, 'binary');
  5327. this.op = op;
  5328. this.arg1 = arg1;
  5329. this.arg2 = arg2;
  5330. this.min = min;
  5331. this.max = max;
  5332. }
  5333. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5334. AstBinaryOperation.prototype.visit = function (visitor) {
  5335. visitor.visitBinaryOperation(this);
  5336. };
  5337. function AstMin(arg, max) {
  5338. AstNode.call(this, 'max');
  5339. this.arg = arg;
  5340. this.min = arg.min;
  5341. this.max = max;
  5342. }
  5343. AstMin.prototype = Object.create(AstNode.prototype);
  5344. AstMin.prototype.visit = function (visitor) {
  5345. visitor.visitMin(this);
  5346. };
  5347. function AstVariable(index, min, max) {
  5348. AstNode.call(this, 'var');
  5349. this.index = index;
  5350. this.min = min;
  5351. this.max = max;
  5352. }
  5353. AstVariable.prototype = Object.create(AstNode.prototype);
  5354. AstVariable.prototype.visit = function (visitor) {
  5355. visitor.visitVariable(this);
  5356. };
  5357. function AstVariableDefinition(variable, arg) {
  5358. AstNode.call(this, 'definition');
  5359. this.variable = variable;
  5360. this.arg = arg;
  5361. }
  5362. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5363. AstVariableDefinition.prototype.visit = function (visitor) {
  5364. visitor.visitVariableDefinition(this);
  5365. };
  5366. function ExpressionBuilderVisitor() {
  5367. this.parts = [];
  5368. }
  5369. ExpressionBuilderVisitor.prototype = {
  5370. visitArgument: function (arg) {
  5371. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5372. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5373. },
  5374. visitVariable: function (variable) {
  5375. this.parts.push('v', variable.index);
  5376. },
  5377. visitLiteral: function (literal) {
  5378. this.parts.push(literal.number);
  5379. },
  5380. visitBinaryOperation: function (operation) {
  5381. this.parts.push('(');
  5382. operation.arg1.visit(this);
  5383. this.parts.push(' ', operation.op, ' ');
  5384. operation.arg2.visit(this);
  5385. this.parts.push(')');
  5386. },
  5387. visitVariableDefinition: function (definition) {
  5388. this.parts.push('var ');
  5389. definition.variable.visit(this);
  5390. this.parts.push(' = ');
  5391. definition.arg.visit(this);
  5392. this.parts.push(';');
  5393. },
  5394. visitMin: function (max) {
  5395. this.parts.push('Math.min(');
  5396. max.arg.visit(this);
  5397. this.parts.push(', ', max.max, ')');
  5398. },
  5399. toString: function () {
  5400. return this.parts.join('');
  5401. }
  5402. };
  5403. function buildAddOperation(num1, num2) {
  5404. if (num2.type === 'literal' && num2.number === 0) {
  5405. // optimization: second operand is 0
  5406. return num1;
  5407. }
  5408. if (num1.type === 'literal' && num1.number === 0) {
  5409. // optimization: first operand is 0
  5410. return num2;
  5411. }
  5412. if (num2.type === 'literal' && num1.type === 'literal') {
  5413. // optimization: operands operand are literals
  5414. return new AstLiteral(num1.number + num2.number);
  5415. }
  5416. return new AstBinaryOperation('+', num1, num2,
  5417. num1.min + num2.min, num1.max + num2.max);
  5418. }
  5419. function buildMulOperation(num1, num2) {
  5420. if (num2.type === 'literal') {
  5421. // optimization: second operands is a literal...
  5422. if (num2.number === 0) {
  5423. return new AstLiteral(0); // and it's 0
  5424. } else if (num2.number === 1) {
  5425. return num1; // and it's 1
  5426. } else if (num1.type === 'literal') {
  5427. // ... and first operands is a literal too
  5428. return new AstLiteral(num1.number * num2.number);
  5429. }
  5430. }
  5431. if (num1.type === 'literal') {
  5432. // optimization: first operands is a literal...
  5433. if (num1.number === 0) {
  5434. return new AstLiteral(0); // and it's 0
  5435. } else if (num1.number === 1) {
  5436. return num2; // and it's 1
  5437. }
  5438. }
  5439. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5440. num1.max * num2.min, num1.max * num2.max);
  5441. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5442. num1.max * num2.min, num1.max * num2.max);
  5443. return new AstBinaryOperation('*', num1, num2, min, max);
  5444. }
  5445. function buildSubOperation(num1, num2) {
  5446. if (num2.type === 'literal') {
  5447. // optimization: second operands is a literal...
  5448. if (num2.number === 0) {
  5449. return num1; // ... and it's 0
  5450. } else if (num1.type === 'literal') {
  5451. // ... and first operands is a literal too
  5452. return new AstLiteral(num1.number - num2.number);
  5453. }
  5454. }
  5455. if (num2.type === 'binary' && num2.op === '-' &&
  5456. num1.type === 'literal' && num1.number === 1 &&
  5457. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5458. // optimization for case: 1 - (1 - x)
  5459. return num2.arg2;
  5460. }
  5461. return new AstBinaryOperation('-', num1, num2,
  5462. num1.min - num2.max, num1.max - num2.min);
  5463. }
  5464. function buildMinOperation(num1, max) {
  5465. if (num1.min >= max) {
  5466. // optimization: num1 min value is not less than required max
  5467. return new AstLiteral(max); // just returning max
  5468. } else if (num1.max <= max) {
  5469. // optimization: num1 max value is not greater than required max
  5470. return num1; // just returning an argument
  5471. }
  5472. return new AstMin(num1, max);
  5473. }
  5474. function PostScriptCompiler() {}
  5475. PostScriptCompiler.prototype = {
  5476. compile: function PostScriptCompiler_compile(code, domain, range) {
  5477. var stack = [];
  5478. var i, ii;
  5479. var instructions = [];
  5480. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5481. var lastRegister = 0;
  5482. var n, j, min, max;
  5483. var num1, num2, ast1, ast2, tmpVar, item;
  5484. for (i = 0; i < inputSize; i++) {
  5485. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5486. }
  5487. for (i = 0, ii = code.length; i < ii; i++) {
  5488. item = code[i];
  5489. if (typeof item === 'number') {
  5490. stack.push(new AstLiteral(item));
  5491. continue;
  5492. }
  5493. switch (item) {
  5494. case 'add':
  5495. if (stack.length < 2) {
  5496. return null;
  5497. }
  5498. num2 = stack.pop();
  5499. num1 = stack.pop();
  5500. stack.push(buildAddOperation(num1, num2));
  5501. break;
  5502. case 'cvr':
  5503. if (stack.length < 1) {
  5504. return null;
  5505. }
  5506. break;
  5507. case 'mul':
  5508. if (stack.length < 2) {
  5509. return null;
  5510. }
  5511. num2 = stack.pop();
  5512. num1 = stack.pop();
  5513. stack.push(buildMulOperation(num1, num2));
  5514. break;
  5515. case 'sub':
  5516. if (stack.length < 2) {
  5517. return null;
  5518. }
  5519. num2 = stack.pop();
  5520. num1 = stack.pop();
  5521. stack.push(buildSubOperation(num1, num2));
  5522. break;
  5523. case 'exch':
  5524. if (stack.length < 2) {
  5525. return null;
  5526. }
  5527. ast1 = stack.pop(); ast2 = stack.pop();
  5528. stack.push(ast1, ast2);
  5529. break;
  5530. case 'pop':
  5531. if (stack.length < 1) {
  5532. return null;
  5533. }
  5534. stack.pop();
  5535. break;
  5536. case 'index':
  5537. if (stack.length < 1) {
  5538. return null;
  5539. }
  5540. num1 = stack.pop();
  5541. if (num1.type !== 'literal') {
  5542. return null;
  5543. }
  5544. n = num1.number;
  5545. if (n < 0 || (n|0) !== n || stack.length < n) {
  5546. return null;
  5547. }
  5548. ast1 = stack[stack.length - n - 1];
  5549. if (ast1.type === 'literal' || ast1.type === 'var') {
  5550. stack.push(ast1);
  5551. break;
  5552. }
  5553. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5554. stack[stack.length - n - 1] = tmpVar;
  5555. stack.push(tmpVar);
  5556. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5557. break;
  5558. case 'dup':
  5559. if (stack.length < 1) {
  5560. return null;
  5561. }
  5562. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5563. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5564. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5565. // special case of the commands sequence for the min operation
  5566. num1 = stack.pop();
  5567. stack.push(buildMinOperation(num1, code[i + 1]));
  5568. i += 6;
  5569. break;
  5570. }
  5571. ast1 = stack[stack.length - 1];
  5572. if (ast1.type === 'literal' || ast1.type === 'var') {
  5573. // we don't have to save into intermediate variable a literal or
  5574. // variable.
  5575. stack.push(ast1);
  5576. break;
  5577. }
  5578. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5579. stack[stack.length - 1] = tmpVar;
  5580. stack.push(tmpVar);
  5581. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5582. break;
  5583. case 'roll':
  5584. if (stack.length < 2) {
  5585. return null;
  5586. }
  5587. num2 = stack.pop();
  5588. num1 = stack.pop();
  5589. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5590. // both roll operands must be numbers
  5591. return null;
  5592. }
  5593. j = num2.number;
  5594. n = num1.number;
  5595. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5596. // ... and integers
  5597. return null;
  5598. }
  5599. j = ((j % n) + n) % n;
  5600. if (j === 0) {
  5601. break; // just skipping -- there are nothing to rotate
  5602. }
  5603. Array.prototype.push.apply(stack,
  5604. stack.splice(stack.length - n, n - j));
  5605. break;
  5606. default:
  5607. return null; // unsupported operator
  5608. }
  5609. }
  5610. if (stack.length !== outputSize) {
  5611. return null;
  5612. }
  5613. var result = [];
  5614. instructions.forEach(function (instruction) {
  5615. var statementBuilder = new ExpressionBuilderVisitor();
  5616. instruction.visit(statementBuilder);
  5617. result.push(statementBuilder.toString());
  5618. });
  5619. stack.forEach(function (expr, i) {
  5620. var statementBuilder = new ExpressionBuilderVisitor();
  5621. expr.visit(statementBuilder);
  5622. var min = range[i * 2], max = range[i * 2 + 1];
  5623. var out = [statementBuilder.toString()];
  5624. if (min > expr.min) {
  5625. out.unshift('Math.max(', min, ', ');
  5626. out.push(')');
  5627. }
  5628. if (max < expr.max) {
  5629. out.unshift('Math.min(', max, ', ');
  5630. out.push(')');
  5631. }
  5632. out.unshift('dest[destOffset + ', i, '] = ');
  5633. out.push(';');
  5634. result.push(out.join(''));
  5635. });
  5636. return result.join('\n');
  5637. }
  5638. };
  5639. return PostScriptCompiler;
  5640. })();
  5641. var ColorSpace = (function ColorSpaceClosure() {
  5642. // Constructor should define this.numComps, this.defaultColor, this.name
  5643. function ColorSpace() {
  5644. error('should not call ColorSpace constructor');
  5645. }
  5646. ColorSpace.prototype = {
  5647. /**
  5648. * Converts the color value to the RGB color. The color components are
  5649. * located in the src array starting from the srcOffset. Returns the array
  5650. * of the rgb components, each value ranging from [0,255].
  5651. */
  5652. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5653. var rgb = new Uint8Array(3);
  5654. this.getRgbItem(src, srcOffset, rgb, 0);
  5655. return rgb;
  5656. },
  5657. /**
  5658. * Converts the color value to the RGB color, similar to the getRgb method.
  5659. * The result placed into the dest array starting from the destOffset.
  5660. */
  5661. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5662. dest, destOffset) {
  5663. error('Should not call ColorSpace.getRgbItem');
  5664. },
  5665. /**
  5666. * Converts the specified number of the color values to the RGB colors.
  5667. * The colors are located in the src array starting from the srcOffset.
  5668. * The result is placed into the dest array starting from the destOffset.
  5669. * The src array items shall be in [0,2^bits) range, the dest array items
  5670. * will be in [0,255] range. alpha01 indicates how many alpha components
  5671. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5672. * array).
  5673. */
  5674. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5675. dest, destOffset, bits,
  5676. alpha01) {
  5677. error('Should not call ColorSpace.getRgbBuffer');
  5678. },
  5679. /**
  5680. * Determines the number of bytes required to store the result of the
  5681. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5682. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5683. */
  5684. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5685. alpha01) {
  5686. error('Should not call ColorSpace.getOutputLength');
  5687. },
  5688. /**
  5689. * Returns true if source data will be equal the result/output data.
  5690. */
  5691. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5692. return false;
  5693. },
  5694. /**
  5695. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5696. * how many alpha components there are in the dest array; it will be either
  5697. * 0 (RGB array) or 1 (RGBA array).
  5698. */
  5699. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5700. originalHeight, width, height,
  5701. actualHeight, bpc, comps, alpha01) {
  5702. var count = originalWidth * originalHeight;
  5703. var rgbBuf = null;
  5704. var numComponentColors = 1 << bpc;
  5705. var needsResizing = originalHeight !== height || originalWidth !== width;
  5706. var i, ii;
  5707. if (this.isPassthrough(bpc)) {
  5708. rgbBuf = comps;
  5709. } else if (this.numComps === 1 && count > numComponentColors &&
  5710. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5711. // Optimization: create a color map when there is just one component and
  5712. // we are converting more colors than the size of the color map. We
  5713. // don't build the map if the colorspace is gray or rgb since those
  5714. // methods are faster than building a map. This mainly offers big speed
  5715. // ups for indexed and alternate colorspaces.
  5716. //
  5717. // TODO it may be worth while to cache the color map. While running
  5718. // testing I never hit a cache so I will leave that out for now (perhaps
  5719. // we are reparsing colorspaces too much?).
  5720. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5721. new Uint16Array(numComponentColors);
  5722. var key;
  5723. for (i = 0; i < numComponentColors; i++) {
  5724. allColors[i] = i;
  5725. }
  5726. var colorMap = new Uint8Array(numComponentColors * 3);
  5727. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5728. /* alpha01 = */ 0);
  5729. var destPos, rgbPos;
  5730. if (!needsResizing) {
  5731. // Fill in the RGB values directly into |dest|.
  5732. destPos = 0;
  5733. for (i = 0; i < count; ++i) {
  5734. key = comps[i] * 3;
  5735. dest[destPos++] = colorMap[key];
  5736. dest[destPos++] = colorMap[key + 1];
  5737. dest[destPos++] = colorMap[key + 2];
  5738. destPos += alpha01;
  5739. }
  5740. } else {
  5741. rgbBuf = new Uint8Array(count * 3);
  5742. rgbPos = 0;
  5743. for (i = 0; i < count; ++i) {
  5744. key = comps[i] * 3;
  5745. rgbBuf[rgbPos++] = colorMap[key];
  5746. rgbBuf[rgbPos++] = colorMap[key + 1];
  5747. rgbBuf[rgbPos++] = colorMap[key + 2];
  5748. }
  5749. }
  5750. } else {
  5751. if (!needsResizing) {
  5752. // Fill in the RGB values directly into |dest|.
  5753. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5754. alpha01);
  5755. } else {
  5756. rgbBuf = new Uint8Array(count * 3);
  5757. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5758. /* alpha01 = */ 0);
  5759. }
  5760. }
  5761. if (rgbBuf) {
  5762. if (needsResizing) {
  5763. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5764. height, dest, alpha01);
  5765. } else {
  5766. rgbPos = 0;
  5767. destPos = 0;
  5768. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5769. dest[destPos++] = rgbBuf[rgbPos++];
  5770. dest[destPos++] = rgbBuf[rgbPos++];
  5771. dest[destPos++] = rgbBuf[rgbPos++];
  5772. destPos += alpha01;
  5773. }
  5774. }
  5775. }
  5776. },
  5777. /**
  5778. * True if the colorspace has components in the default range of [0, 1].
  5779. * This should be true for all colorspaces except for lab color spaces
  5780. * which are [0,100], [-128, 127], [-128, 127].
  5781. */
  5782. usesZeroToOneRange: true
  5783. };
  5784. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5785. var IR = ColorSpace.parseToIR(cs, xref, res);
  5786. if (IR instanceof AlternateCS) {
  5787. return IR;
  5788. }
  5789. return ColorSpace.fromIR(IR);
  5790. };
  5791. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5792. var name = isArray(IR) ? IR[0] : IR;
  5793. var whitePoint, blackPoint, gamma;
  5794. switch (name) {
  5795. case 'DeviceGrayCS':
  5796. return this.singletons.gray;
  5797. case 'DeviceRgbCS':
  5798. return this.singletons.rgb;
  5799. case 'DeviceCmykCS':
  5800. return this.singletons.cmyk;
  5801. case 'CalGrayCS':
  5802. whitePoint = IR[1].WhitePoint;
  5803. blackPoint = IR[1].BlackPoint;
  5804. gamma = IR[1].Gamma;
  5805. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5806. case 'CalRGBCS':
  5807. whitePoint = IR[1].WhitePoint;
  5808. blackPoint = IR[1].BlackPoint;
  5809. gamma = IR[1].Gamma;
  5810. var matrix = IR[1].Matrix;
  5811. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5812. case 'PatternCS':
  5813. var basePatternCS = IR[1];
  5814. if (basePatternCS) {
  5815. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5816. }
  5817. return new PatternCS(basePatternCS);
  5818. case 'IndexedCS':
  5819. var baseIndexedCS = IR[1];
  5820. var hiVal = IR[2];
  5821. var lookup = IR[3];
  5822. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  5823. case 'AlternateCS':
  5824. var numComps = IR[1];
  5825. var alt = IR[2];
  5826. var tintFnIR = IR[3];
  5827. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  5828. PDFFunction.fromIR(tintFnIR));
  5829. case 'LabCS':
  5830. whitePoint = IR[1].WhitePoint;
  5831. blackPoint = IR[1].BlackPoint;
  5832. var range = IR[1].Range;
  5833. return new LabCS(whitePoint, blackPoint, range);
  5834. default:
  5835. error('Unknown name ' + name);
  5836. }
  5837. return null;
  5838. };
  5839. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  5840. if (isName(cs)) {
  5841. var colorSpaces = res.get('ColorSpace');
  5842. if (isDict(colorSpaces)) {
  5843. var refcs = colorSpaces.get(cs.name);
  5844. if (refcs) {
  5845. cs = refcs;
  5846. }
  5847. }
  5848. }
  5849. cs = xref.fetchIfRef(cs);
  5850. var mode;
  5851. if (isName(cs)) {
  5852. mode = cs.name;
  5853. this.mode = mode;
  5854. switch (mode) {
  5855. case 'DeviceGray':
  5856. case 'G':
  5857. return 'DeviceGrayCS';
  5858. case 'DeviceRGB':
  5859. case 'RGB':
  5860. return 'DeviceRgbCS';
  5861. case 'DeviceCMYK':
  5862. case 'CMYK':
  5863. return 'DeviceCmykCS';
  5864. case 'Pattern':
  5865. return ['PatternCS', null];
  5866. default:
  5867. error('unrecognized colorspace ' + mode);
  5868. }
  5869. } else if (isArray(cs)) {
  5870. mode = cs[0].name;
  5871. this.mode = mode;
  5872. var numComps, params;
  5873. switch (mode) {
  5874. case 'DeviceGray':
  5875. case 'G':
  5876. return 'DeviceGrayCS';
  5877. case 'DeviceRGB':
  5878. case 'RGB':
  5879. return 'DeviceRgbCS';
  5880. case 'DeviceCMYK':
  5881. case 'CMYK':
  5882. return 'DeviceCmykCS';
  5883. case 'CalGray':
  5884. params = cs[1].getAll();
  5885. return ['CalGrayCS', params];
  5886. case 'CalRGB':
  5887. params = cs[1].getAll();
  5888. return ['CalRGBCS', params];
  5889. case 'ICCBased':
  5890. var stream = xref.fetchIfRef(cs[1]);
  5891. var dict = stream.dict;
  5892. numComps = dict.get('N');
  5893. if (numComps === 1) {
  5894. return 'DeviceGrayCS';
  5895. } else if (numComps === 3) {
  5896. return 'DeviceRgbCS';
  5897. } else if (numComps === 4) {
  5898. return 'DeviceCmykCS';
  5899. }
  5900. break;
  5901. case 'Pattern':
  5902. var basePatternCS = cs[1];
  5903. if (basePatternCS) {
  5904. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  5905. }
  5906. return ['PatternCS', basePatternCS];
  5907. case 'Indexed':
  5908. case 'I':
  5909. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  5910. var hiVal = cs[2] + 1;
  5911. var lookup = xref.fetchIfRef(cs[3]);
  5912. if (isStream(lookup)) {
  5913. lookup = lookup.getBytes();
  5914. }
  5915. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  5916. case 'Separation':
  5917. case 'DeviceN':
  5918. var name = cs[1];
  5919. numComps = 1;
  5920. if (isName(name)) {
  5921. numComps = 1;
  5922. } else if (isArray(name)) {
  5923. numComps = name.length;
  5924. }
  5925. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  5926. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  5927. return ['AlternateCS', numComps, alt, tintFnIR];
  5928. case 'Lab':
  5929. params = cs[1].getAll();
  5930. return ['LabCS', params];
  5931. default:
  5932. error('unimplemented color space object "' + mode + '"');
  5933. }
  5934. } else {
  5935. error('unrecognized color space object: "' + cs + '"');
  5936. }
  5937. return null;
  5938. };
  5939. /**
  5940. * Checks if a decode map matches the default decode map for a color space.
  5941. * This handles the general decode maps where there are two values per
  5942. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  5943. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  5944. * slightly different.
  5945. * @param {Array} decode Decode map (usually from an image).
  5946. * @param {Number} n Number of components the color space has.
  5947. */
  5948. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  5949. if (!decode) {
  5950. return true;
  5951. }
  5952. if (n * 2 !== decode.length) {
  5953. warn('The decode map is not the correct length');
  5954. return true;
  5955. }
  5956. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  5957. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  5958. return false;
  5959. }
  5960. }
  5961. return true;
  5962. };
  5963. ColorSpace.singletons = {
  5964. get gray() {
  5965. return shadow(this, 'gray', new DeviceGrayCS());
  5966. },
  5967. get rgb() {
  5968. return shadow(this, 'rgb', new DeviceRgbCS());
  5969. },
  5970. get cmyk() {
  5971. return shadow(this, 'cmyk', new DeviceCmykCS());
  5972. }
  5973. };
  5974. return ColorSpace;
  5975. })();
  5976. /**
  5977. * Alternate color space handles both Separation and DeviceN color spaces. A
  5978. * Separation color space is actually just a DeviceN with one color component.
  5979. * Both color spaces use a tinting function to convert colors to a base color
  5980. * space.
  5981. */
  5982. var AlternateCS = (function AlternateCSClosure() {
  5983. function AlternateCS(numComps, base, tintFn) {
  5984. this.name = 'Alternate';
  5985. this.numComps = numComps;
  5986. this.defaultColor = new Float32Array(numComps);
  5987. for (var i = 0; i < numComps; ++i) {
  5988. this.defaultColor[i] = 1;
  5989. }
  5990. this.base = base;
  5991. this.tintFn = tintFn;
  5992. this.tmpBuf = new Float32Array(base.numComps);
  5993. }
  5994. AlternateCS.prototype = {
  5995. getRgb: ColorSpace.prototype.getRgb,
  5996. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  5997. dest, destOffset) {
  5998. var tmpBuf = this.tmpBuf;
  5999. this.tintFn(src, srcOffset, tmpBuf, 0);
  6000. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6001. },
  6002. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6003. dest, destOffset, bits,
  6004. alpha01) {
  6005. var tintFn = this.tintFn;
  6006. var base = this.base;
  6007. var scale = 1 / ((1 << bits) - 1);
  6008. var baseNumComps = base.numComps;
  6009. var usesZeroToOneRange = base.usesZeroToOneRange;
  6010. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6011. alpha01 === 0;
  6012. var pos = isPassthrough ? destOffset : 0;
  6013. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6014. var numComps = this.numComps;
  6015. var scaled = new Float32Array(numComps);
  6016. var tinted = new Float32Array(baseNumComps);
  6017. var i, j;
  6018. if (usesZeroToOneRange) {
  6019. for (i = 0; i < count; i++) {
  6020. for (j = 0; j < numComps; j++) {
  6021. scaled[j] = src[srcOffset++] * scale;
  6022. }
  6023. tintFn(scaled, 0, tinted, 0);
  6024. for (j = 0; j < baseNumComps; j++) {
  6025. baseBuf[pos++] = tinted[j] * 255;
  6026. }
  6027. }
  6028. } else {
  6029. for (i = 0; i < count; i++) {
  6030. for (j = 0; j < numComps; j++) {
  6031. scaled[j] = src[srcOffset++] * scale;
  6032. }
  6033. tintFn(scaled, 0, tinted, 0);
  6034. base.getRgbItem(tinted, 0, baseBuf, pos);
  6035. pos += baseNumComps;
  6036. }
  6037. }
  6038. if (!isPassthrough) {
  6039. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6040. }
  6041. },
  6042. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6043. alpha01) {
  6044. return this.base.getOutputLength(inputLength *
  6045. this.base.numComps / this.numComps,
  6046. alpha01);
  6047. },
  6048. isPassthrough: ColorSpace.prototype.isPassthrough,
  6049. fillRgb: ColorSpace.prototype.fillRgb,
  6050. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6051. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6052. },
  6053. usesZeroToOneRange: true
  6054. };
  6055. return AlternateCS;
  6056. })();
  6057. var PatternCS = (function PatternCSClosure() {
  6058. function PatternCS(baseCS) {
  6059. this.name = 'Pattern';
  6060. this.base = baseCS;
  6061. }
  6062. PatternCS.prototype = {};
  6063. return PatternCS;
  6064. })();
  6065. var IndexedCS = (function IndexedCSClosure() {
  6066. function IndexedCS(base, highVal, lookup) {
  6067. this.name = 'Indexed';
  6068. this.numComps = 1;
  6069. this.defaultColor = new Uint8Array([0]);
  6070. this.base = base;
  6071. this.highVal = highVal;
  6072. var baseNumComps = base.numComps;
  6073. var length = baseNumComps * highVal;
  6074. var lookupArray;
  6075. if (isStream(lookup)) {
  6076. lookupArray = new Uint8Array(length);
  6077. var bytes = lookup.getBytes(length);
  6078. lookupArray.set(bytes);
  6079. } else if (isString(lookup)) {
  6080. lookupArray = new Uint8Array(length);
  6081. for (var i = 0; i < length; ++i) {
  6082. lookupArray[i] = lookup.charCodeAt(i);
  6083. }
  6084. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6085. lookupArray = lookup;
  6086. } else {
  6087. error('Unrecognized lookup table: ' + lookup);
  6088. }
  6089. this.lookup = lookupArray;
  6090. }
  6091. IndexedCS.prototype = {
  6092. getRgb: ColorSpace.prototype.getRgb,
  6093. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6094. dest, destOffset) {
  6095. var numComps = this.base.numComps;
  6096. var start = src[srcOffset] * numComps;
  6097. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6098. },
  6099. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6100. dest, destOffset, bits,
  6101. alpha01) {
  6102. var base = this.base;
  6103. var numComps = base.numComps;
  6104. var outputDelta = base.getOutputLength(numComps, alpha01);
  6105. var lookup = this.lookup;
  6106. for (var i = 0; i < count; ++i) {
  6107. var lookupPos = src[srcOffset++] * numComps;
  6108. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6109. destOffset += outputDelta;
  6110. }
  6111. },
  6112. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6113. return this.base.getOutputLength(inputLength * this.base.numComps,
  6114. alpha01);
  6115. },
  6116. isPassthrough: ColorSpace.prototype.isPassthrough,
  6117. fillRgb: ColorSpace.prototype.fillRgb,
  6118. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6119. // indexed color maps shouldn't be changed
  6120. return true;
  6121. },
  6122. usesZeroToOneRange: true
  6123. };
  6124. return IndexedCS;
  6125. })();
  6126. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6127. function DeviceGrayCS() {
  6128. this.name = 'DeviceGray';
  6129. this.numComps = 1;
  6130. this.defaultColor = new Float32Array([0]);
  6131. }
  6132. DeviceGrayCS.prototype = {
  6133. getRgb: ColorSpace.prototype.getRgb,
  6134. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6135. dest, destOffset) {
  6136. var c = (src[srcOffset] * 255) | 0;
  6137. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6138. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6139. },
  6140. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6141. dest, destOffset, bits,
  6142. alpha01) {
  6143. var scale = 255 / ((1 << bits) - 1);
  6144. var j = srcOffset, q = destOffset;
  6145. for (var i = 0; i < count; ++i) {
  6146. var c = (scale * src[j++]) | 0;
  6147. dest[q++] = c;
  6148. dest[q++] = c;
  6149. dest[q++] = c;
  6150. q += alpha01;
  6151. }
  6152. },
  6153. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6154. alpha01) {
  6155. return inputLength * (3 + alpha01);
  6156. },
  6157. isPassthrough: ColorSpace.prototype.isPassthrough,
  6158. fillRgb: ColorSpace.prototype.fillRgb,
  6159. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6160. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6161. },
  6162. usesZeroToOneRange: true
  6163. };
  6164. return DeviceGrayCS;
  6165. })();
  6166. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6167. function DeviceRgbCS() {
  6168. this.name = 'DeviceRGB';
  6169. this.numComps = 3;
  6170. this.defaultColor = new Float32Array([0, 0, 0]);
  6171. }
  6172. DeviceRgbCS.prototype = {
  6173. getRgb: ColorSpace.prototype.getRgb,
  6174. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6175. dest, destOffset) {
  6176. var r = (src[srcOffset] * 255) | 0;
  6177. var g = (src[srcOffset + 1] * 255) | 0;
  6178. var b = (src[srcOffset + 2] * 255) | 0;
  6179. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6180. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6181. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6182. },
  6183. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6184. dest, destOffset, bits,
  6185. alpha01) {
  6186. if (bits === 8 && alpha01 === 0) {
  6187. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6188. return;
  6189. }
  6190. var scale = 255 / ((1 << bits) - 1);
  6191. var j = srcOffset, q = destOffset;
  6192. for (var i = 0; i < count; ++i) {
  6193. dest[q++] = (scale * src[j++]) | 0;
  6194. dest[q++] = (scale * src[j++]) | 0;
  6195. dest[q++] = (scale * src[j++]) | 0;
  6196. q += alpha01;
  6197. }
  6198. },
  6199. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6200. alpha01) {
  6201. return (inputLength * (3 + alpha01) / 3) | 0;
  6202. },
  6203. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6204. return bits === 8;
  6205. },
  6206. fillRgb: ColorSpace.prototype.fillRgb,
  6207. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6208. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6209. },
  6210. usesZeroToOneRange: true
  6211. };
  6212. return DeviceRgbCS;
  6213. })();
  6214. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6215. // The coefficients below was found using numerical analysis: the method of
  6216. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6217. // where color_value is the tabular value from the table of sampled RGB colors
  6218. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6219. // CMYK color conversion using the estimation below:
  6220. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6221. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6222. var c = src[srcOffset + 0] * srcScale;
  6223. var m = src[srcOffset + 1] * srcScale;
  6224. var y = src[srcOffset + 2] * srcScale;
  6225. var k = src[srcOffset + 3] * srcScale;
  6226. var r =
  6227. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6228. 18.82290502165302 * y + 212.25662451639585 * k +
  6229. -285.2331026137004) +
  6230. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6231. -17.873870861415444 * k - 5.497006427196366) +
  6232. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6233. 17.5119270841813) +
  6234. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6235. var g =
  6236. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6237. 6.871425592049007 * y + 31.159100130055922 * k +
  6238. -79.2970844816548) +
  6239. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6240. 131.35250912493976 * k - 190.9453302588951) +
  6241. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6242. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6243. var b =
  6244. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6245. 30.89978309703729 * y - 0.23883238689178934 * k +
  6246. -14.183576799673286) +
  6247. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6248. 50.606957656360734 * k - 112.23884253719248) +
  6249. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6250. -193.58209356861505) +
  6251. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6252. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6253. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6254. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6255. }
  6256. function DeviceCmykCS() {
  6257. this.name = 'DeviceCMYK';
  6258. this.numComps = 4;
  6259. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6260. }
  6261. DeviceCmykCS.prototype = {
  6262. getRgb: ColorSpace.prototype.getRgb,
  6263. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6264. dest, destOffset) {
  6265. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6266. },
  6267. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6268. dest, destOffset, bits,
  6269. alpha01) {
  6270. var scale = 1 / ((1 << bits) - 1);
  6271. for (var i = 0; i < count; i++) {
  6272. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6273. srcOffset += 4;
  6274. destOffset += 3 + alpha01;
  6275. }
  6276. },
  6277. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6278. alpha01) {
  6279. return (inputLength / 4 * (3 + alpha01)) | 0;
  6280. },
  6281. isPassthrough: ColorSpace.prototype.isPassthrough,
  6282. fillRgb: ColorSpace.prototype.fillRgb,
  6283. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6284. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6285. },
  6286. usesZeroToOneRange: true
  6287. };
  6288. return DeviceCmykCS;
  6289. })();
  6290. //
  6291. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6292. //
  6293. var CalGrayCS = (function CalGrayCSClosure() {
  6294. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6295. this.name = 'CalGray';
  6296. this.numComps = 1;
  6297. this.defaultColor = new Float32Array([0]);
  6298. if (!whitePoint) {
  6299. error('WhitePoint missing - required for color space CalGray');
  6300. }
  6301. blackPoint = blackPoint || [0, 0, 0];
  6302. gamma = gamma || 1;
  6303. // Translate arguments to spec variables.
  6304. this.XW = whitePoint[0];
  6305. this.YW = whitePoint[1];
  6306. this.ZW = whitePoint[2];
  6307. this.XB = blackPoint[0];
  6308. this.YB = blackPoint[1];
  6309. this.ZB = blackPoint[2];
  6310. this.G = gamma;
  6311. // Validate variables as per spec.
  6312. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6313. error('Invalid WhitePoint components for ' + this.name +
  6314. ', no fallback available');
  6315. }
  6316. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6317. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6318. this.XB = this.YB = this.ZB = 0;
  6319. }
  6320. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6321. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6322. ', ZB: ' + this.ZB + ', only default values are supported.');
  6323. }
  6324. if (this.G < 1) {
  6325. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6326. ', falling back to default');
  6327. this.G = 1;
  6328. }
  6329. }
  6330. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6331. // A represents a gray component of a calibrated gray space.
  6332. // A <---> AG in the spec
  6333. var A = src[srcOffset] * scale;
  6334. var AG = Math.pow(A, cs.G);
  6335. // Computes L as per spec. ( = cs.YW * AG )
  6336. // Except if other than default BlackPoint values are used.
  6337. var L = cs.YW * AG;
  6338. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6339. // Convert values to rgb range [0, 255].
  6340. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6341. dest[destOffset] = val;
  6342. dest[destOffset + 1] = val;
  6343. dest[destOffset + 2] = val;
  6344. }
  6345. CalGrayCS.prototype = {
  6346. getRgb: ColorSpace.prototype.getRgb,
  6347. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6348. dest, destOffset) {
  6349. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6350. },
  6351. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6352. dest, destOffset, bits,
  6353. alpha01) {
  6354. var scale = 1 / ((1 << bits) - 1);
  6355. for (var i = 0; i < count; ++i) {
  6356. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6357. srcOffset += 1;
  6358. destOffset += 3 + alpha01;
  6359. }
  6360. },
  6361. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6362. return inputLength * (3 + alpha01);
  6363. },
  6364. isPassthrough: ColorSpace.prototype.isPassthrough,
  6365. fillRgb: ColorSpace.prototype.fillRgb,
  6366. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6367. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6368. },
  6369. usesZeroToOneRange: true
  6370. };
  6371. return CalGrayCS;
  6372. })();
  6373. //
  6374. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6375. //
  6376. var CalRGBCS = (function CalRGBCSClosure() {
  6377. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6378. // matrices.
  6379. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6380. 0.8951, 0.2664, -0.1614,
  6381. -0.7502, 1.7135, 0.0367,
  6382. 0.0389, -0.0685, 1.0296]);
  6383. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6384. 0.9869929, -0.1470543, 0.1599627,
  6385. 0.4323053, 0.5183603, 0.0492912,
  6386. -0.0085287, 0.0400428, 0.9684867]);
  6387. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6388. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6389. 3.2404542, -1.5371385, -0.4985314,
  6390. -0.9692660, 1.8760108, 0.0415560,
  6391. 0.0556434, -0.2040259, 1.0572252]);
  6392. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6393. var tempNormalizeMatrix = new Float32Array(3);
  6394. var tempConvertMatrix1 = new Float32Array(3);
  6395. var tempConvertMatrix2 = new Float32Array(3);
  6396. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6397. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6398. this.name = 'CalRGB';
  6399. this.numComps = 3;
  6400. this.defaultColor = new Float32Array(3);
  6401. if (!whitePoint) {
  6402. error('WhitePoint missing - required for color space CalRGB');
  6403. }
  6404. blackPoint = blackPoint || new Float32Array(3);
  6405. gamma = gamma || new Float32Array([1, 1, 1]);
  6406. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6407. // Translate arguments to spec variables.
  6408. var XW = whitePoint[0];
  6409. var YW = whitePoint[1];
  6410. var ZW = whitePoint[2];
  6411. this.whitePoint = whitePoint;
  6412. var XB = blackPoint[0];
  6413. var YB = blackPoint[1];
  6414. var ZB = blackPoint[2];
  6415. this.blackPoint = blackPoint;
  6416. this.GR = gamma[0];
  6417. this.GG = gamma[1];
  6418. this.GB = gamma[2];
  6419. this.MXA = matrix[0];
  6420. this.MYA = matrix[1];
  6421. this.MZA = matrix[2];
  6422. this.MXB = matrix[3];
  6423. this.MYB = matrix[4];
  6424. this.MZB = matrix[5];
  6425. this.MXC = matrix[6];
  6426. this.MYC = matrix[7];
  6427. this.MZC = matrix[8];
  6428. // Validate variables as per spec.
  6429. if (XW < 0 || ZW < 0 || YW !== 1) {
  6430. error('Invalid WhitePoint components for ' + this.name +
  6431. ', no fallback available');
  6432. }
  6433. if (XB < 0 || YB < 0 || ZB < 0) {
  6434. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6435. ', ' + ZB + '], falling back to default');
  6436. this.blackPoint = new Float32Array(3);
  6437. }
  6438. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6439. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6440. '] for ' + this.name + ', falling back to default');
  6441. this.GR = this.GG = this.GB = 1;
  6442. }
  6443. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6444. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6445. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6446. info('Invalid Matrix for ' + this.name + ' [' +
  6447. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6448. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6449. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6450. '], falling back to default');
  6451. this.MXA = this.MYB = this.MZC = 1;
  6452. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6453. }
  6454. }
  6455. function matrixProduct(a, b, result) {
  6456. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6457. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6458. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6459. }
  6460. function convertToFlat(sourceWhitePoint, LMS, result) {
  6461. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6462. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6463. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6464. }
  6465. function convertToD65(sourceWhitePoint, LMS, result) {
  6466. var D65X = 0.95047;
  6467. var D65Y = 1;
  6468. var D65Z = 1.08883;
  6469. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6470. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6471. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6472. }
  6473. function sRGBTransferFunction(color) {
  6474. // See http://en.wikipedia.org/wiki/SRGB.
  6475. if (color <= 0.0031308){
  6476. return adjustToRange(0, 1, 12.92 * color);
  6477. }
  6478. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6479. }
  6480. function adjustToRange(min, max, value) {
  6481. return Math.max(min, Math.min(max, value));
  6482. }
  6483. function decodeL(L) {
  6484. if (L < 0) {
  6485. return -decodeL(-L);
  6486. }
  6487. if (L > 8.0) {
  6488. return Math.pow(((L + 16) / 116), 3);
  6489. }
  6490. return L * DECODE_L_CONSTANT;
  6491. }
  6492. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6493. // In case the blackPoint is already the default blackPoint then there is
  6494. // no need to do compensation.
  6495. if (sourceBlackPoint[0] === 0 &&
  6496. sourceBlackPoint[1] === 0 &&
  6497. sourceBlackPoint[2] === 0) {
  6498. result[0] = XYZ_Flat[0];
  6499. result[1] = XYZ_Flat[1];
  6500. result[2] = XYZ_Flat[2];
  6501. return;
  6502. }
  6503. // For the blackPoint calculation details, please see
  6504. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6505. // AdobeBPC.pdf.
  6506. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6507. var zeroDecodeL = decodeL(0);
  6508. var X_DST = zeroDecodeL;
  6509. var X_SRC = decodeL(sourceBlackPoint[0]);
  6510. var Y_DST = zeroDecodeL;
  6511. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6512. var Z_DST = zeroDecodeL;
  6513. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6514. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6515. var X_Offset = 1 - X_Scale;
  6516. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6517. var Y_Offset = 1 - Y_Scale;
  6518. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6519. var Z_Offset = 1 - Z_Scale;
  6520. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6521. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6522. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6523. }
  6524. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6525. // In case the whitePoint is already flat then there is no need to do
  6526. // normalization.
  6527. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6528. result[0] = XYZ_In[0];
  6529. result[1] = XYZ_In[1];
  6530. result[2] = XYZ_In[2];
  6531. return;
  6532. }
  6533. var LMS = result;
  6534. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6535. var LMS_Flat = tempNormalizeMatrix;
  6536. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6537. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6538. }
  6539. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6540. var LMS = result;
  6541. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6542. var LMS_D65 = tempNormalizeMatrix;
  6543. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6544. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6545. }
  6546. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6547. // A, B and C represent a red, green and blue components of a calibrated
  6548. // rgb space.
  6549. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6550. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6551. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6552. // A <---> AGR in the spec
  6553. // B <---> BGG in the spec
  6554. // C <---> CGB in the spec
  6555. var AGR = Math.pow(A, cs.GR);
  6556. var BGG = Math.pow(B, cs.GG);
  6557. var CGB = Math.pow(C, cs.GB);
  6558. // Computes intermediate variables L, M, N as per spec.
  6559. // To decode X, Y, Z values map L, M, N directly to them.
  6560. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6561. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6562. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6563. // The following calculations are based on this document:
  6564. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6565. // AdobeBPC.pdf.
  6566. var XYZ = tempConvertMatrix1;
  6567. XYZ[0] = X;
  6568. XYZ[1] = Y;
  6569. XYZ[2] = Z;
  6570. var XYZ_Flat = tempConvertMatrix2;
  6571. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6572. var XYZ_Black = tempConvertMatrix1;
  6573. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6574. var XYZ_D65 = tempConvertMatrix2;
  6575. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6576. var SRGB = tempConvertMatrix1;
  6577. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6578. var sR = sRGBTransferFunction(SRGB[0]);
  6579. var sG = sRGBTransferFunction(SRGB[1]);
  6580. var sB = sRGBTransferFunction(SRGB[2]);
  6581. // Convert the values to rgb range [0, 255].
  6582. dest[destOffset] = Math.round(sR * 255);
  6583. dest[destOffset + 1] = Math.round(sG * 255);
  6584. dest[destOffset + 2] = Math.round(sB * 255);
  6585. }
  6586. CalRGBCS.prototype = {
  6587. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6588. var rgb = new Uint8Array(3);
  6589. this.getRgbItem(src, srcOffset, rgb, 0);
  6590. return rgb;
  6591. },
  6592. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6593. dest, destOffset) {
  6594. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6595. },
  6596. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6597. dest, destOffset, bits) {
  6598. var scale = 1 / ((1 << bits) - 1);
  6599. for (var i = 0; i < count; ++i) {
  6600. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6601. srcOffset += 3;
  6602. destOffset += 3;
  6603. }
  6604. },
  6605. getOutputLength: function CalRGBCS_getOutputLength(inputLength) {
  6606. return inputLength;
  6607. },
  6608. isPassthrough: ColorSpace.prototype.isPassthrough,
  6609. createRgbBuffer: ColorSpace.prototype.createRgbBuffer,
  6610. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6611. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6612. },
  6613. usesZeroToOneRange: true
  6614. };
  6615. return CalRGBCS;
  6616. })();
  6617. //
  6618. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6619. //
  6620. var LabCS = (function LabCSClosure() {
  6621. function LabCS(whitePoint, blackPoint, range) {
  6622. this.name = 'Lab';
  6623. this.numComps = 3;
  6624. this.defaultColor = new Float32Array([0, 0, 0]);
  6625. if (!whitePoint) {
  6626. error('WhitePoint missing - required for color space Lab');
  6627. }
  6628. blackPoint = blackPoint || [0, 0, 0];
  6629. range = range || [-100, 100, -100, 100];
  6630. // Translate args to spec variables
  6631. this.XW = whitePoint[0];
  6632. this.YW = whitePoint[1];
  6633. this.ZW = whitePoint[2];
  6634. this.amin = range[0];
  6635. this.amax = range[1];
  6636. this.bmin = range[2];
  6637. this.bmax = range[3];
  6638. // These are here just for completeness - the spec doesn't offer any
  6639. // formulas that use BlackPoint in Lab
  6640. this.XB = blackPoint[0];
  6641. this.YB = blackPoint[1];
  6642. this.ZB = blackPoint[2];
  6643. // Validate vars as per spec
  6644. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6645. error('Invalid WhitePoint components, no fallback available');
  6646. }
  6647. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6648. info('Invalid BlackPoint, falling back to default');
  6649. this.XB = this.YB = this.ZB = 0;
  6650. }
  6651. if (this.amin > this.amax || this.bmin > this.bmax) {
  6652. info('Invalid Range, falling back to defaults');
  6653. this.amin = -100;
  6654. this.amax = 100;
  6655. this.bmin = -100;
  6656. this.bmax = 100;
  6657. }
  6658. }
  6659. // Function g(x) from spec
  6660. function fn_g(x) {
  6661. if (x >= 6 / 29) {
  6662. return x * x * x;
  6663. } else {
  6664. return (108 / 841) * (x - 4 / 29);
  6665. }
  6666. }
  6667. function decode(value, high1, low2, high2) {
  6668. return low2 + (value) * (high2 - low2) / (high1);
  6669. }
  6670. // If decoding is needed maxVal should be 2^bits per component - 1.
  6671. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6672. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6673. // not the usual [0, 1]. If a command like setFillColor is used the src
  6674. // values will already be within the correct range. However, if we are
  6675. // converting an image we have to map the values to the correct range given
  6676. // above.
  6677. // Ls,as,bs <---> L*,a*,b* in the spec
  6678. var Ls = src[srcOffset];
  6679. var as = src[srcOffset + 1];
  6680. var bs = src[srcOffset + 2];
  6681. if (maxVal !== false) {
  6682. Ls = decode(Ls, maxVal, 0, 100);
  6683. as = decode(as, maxVal, cs.amin, cs.amax);
  6684. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6685. }
  6686. // Adjust limits of 'as' and 'bs'
  6687. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6688. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6689. // Computes intermediate variables X,Y,Z as per spec
  6690. var M = (Ls + 16) / 116;
  6691. var L = M + (as / 500);
  6692. var N = M - (bs / 200);
  6693. var X = cs.XW * fn_g(L);
  6694. var Y = cs.YW * fn_g(M);
  6695. var Z = cs.ZW * fn_g(N);
  6696. var r, g, b;
  6697. // Using different conversions for D50 and D65 white points,
  6698. // per http://www.color.org/srgb.pdf
  6699. if (cs.ZW < 1) {
  6700. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6701. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6702. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6703. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6704. } else {
  6705. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6706. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6707. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6708. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6709. }
  6710. // clamp color values to [0,1] range then convert to [0,255] range.
  6711. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6712. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6713. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6714. }
  6715. LabCS.prototype = {
  6716. getRgb: ColorSpace.prototype.getRgb,
  6717. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6718. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6719. },
  6720. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6721. dest, destOffset, bits,
  6722. alpha01) {
  6723. var maxVal = (1 << bits) - 1;
  6724. for (var i = 0; i < count; i++) {
  6725. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6726. srcOffset += 3;
  6727. destOffset += 3 + alpha01;
  6728. }
  6729. },
  6730. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6731. return (inputLength * (3 + alpha01) / 3) | 0;
  6732. },
  6733. isPassthrough: ColorSpace.prototype.isPassthrough,
  6734. fillRgb: ColorSpace.prototype.fillRgb,
  6735. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6736. // XXX: Decoding is handled with the lab conversion because of the strange
  6737. // ranges that are used.
  6738. return true;
  6739. },
  6740. usesZeroToOneRange: false
  6741. };
  6742. return LabCS;
  6743. })();
  6744. var ARCFourCipher = (function ARCFourCipherClosure() {
  6745. function ARCFourCipher(key) {
  6746. this.a = 0;
  6747. this.b = 0;
  6748. var s = new Uint8Array(256);
  6749. var i, j = 0, tmp, keyLength = key.length;
  6750. for (i = 0; i < 256; ++i) {
  6751. s[i] = i;
  6752. }
  6753. for (i = 0; i < 256; ++i) {
  6754. tmp = s[i];
  6755. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6756. s[i] = s[j];
  6757. s[j] = tmp;
  6758. }
  6759. this.s = s;
  6760. }
  6761. ARCFourCipher.prototype = {
  6762. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6763. var i, n = data.length, tmp, tmp2;
  6764. var a = this.a, b = this.b, s = this.s;
  6765. var output = new Uint8Array(n);
  6766. for (i = 0; i < n; ++i) {
  6767. a = (a + 1) & 0xFF;
  6768. tmp = s[a];
  6769. b = (b + tmp) & 0xFF;
  6770. tmp2 = s[b];
  6771. s[a] = tmp2;
  6772. s[b] = tmp;
  6773. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6774. }
  6775. this.a = a;
  6776. this.b = b;
  6777. return output;
  6778. }
  6779. };
  6780. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6781. return ARCFourCipher;
  6782. })();
  6783. var calculateMD5 = (function calculateMD5Closure() {
  6784. var r = new Uint8Array([
  6785. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6786. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6787. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6788. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6789. var k = new Int32Array([
  6790. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6791. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6792. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6793. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6794. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6795. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6796. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6797. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6798. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6799. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6800. -145523070, -1120210379, 718787259, -343485551]);
  6801. function hash(data, offset, length) {
  6802. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6803. // pre-processing
  6804. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6805. var padded = new Uint8Array(paddedLength);
  6806. var i, j, n;
  6807. for (i = 0; i < length; ++i) {
  6808. padded[i] = data[offset++];
  6809. }
  6810. padded[i++] = 0x80;
  6811. n = paddedLength - 8;
  6812. while (i < n) {
  6813. padded[i++] = 0;
  6814. }
  6815. padded[i++] = (length << 3) & 0xFF;
  6816. padded[i++] = (length >> 5) & 0xFF;
  6817. padded[i++] = (length >> 13) & 0xFF;
  6818. padded[i++] = (length >> 21) & 0xFF;
  6819. padded[i++] = (length >>> 29) & 0xFF;
  6820. padded[i++] = 0;
  6821. padded[i++] = 0;
  6822. padded[i++] = 0;
  6823. var w = new Int32Array(16);
  6824. for (i = 0; i < paddedLength;) {
  6825. for (j = 0; j < 16; ++j, i += 4) {
  6826. w[j] = (padded[i] | (padded[i + 1] << 8) |
  6827. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  6828. }
  6829. var a = h0, b = h1, c = h2, d = h3, f, g;
  6830. for (j = 0; j < 64; ++j) {
  6831. if (j < 16) {
  6832. f = (b & c) | ((~b) & d);
  6833. g = j;
  6834. } else if (j < 32) {
  6835. f = (d & b) | ((~d) & c);
  6836. g = (5 * j + 1) & 15;
  6837. } else if (j < 48) {
  6838. f = b ^ c ^ d;
  6839. g = (3 * j + 5) & 15;
  6840. } else {
  6841. f = c ^ (b | (~d));
  6842. g = (7 * j) & 15;
  6843. }
  6844. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  6845. d = c;
  6846. c = b;
  6847. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  6848. a = tmp;
  6849. }
  6850. h0 = (h0 + a) | 0;
  6851. h1 = (h1 + b) | 0;
  6852. h2 = (h2 + c) | 0;
  6853. h3 = (h3 + d) | 0;
  6854. }
  6855. return new Uint8Array([
  6856. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  6857. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  6858. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  6859. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  6860. ]);
  6861. }
  6862. return hash;
  6863. })();
  6864. var Word64 = (function Word64Closure() {
  6865. function Word64(highInteger, lowInteger) {
  6866. this.high = highInteger | 0;
  6867. this.low = lowInteger | 0;
  6868. }
  6869. Word64.prototype = {
  6870. and: function Word64_and(word) {
  6871. this.high &= word.high;
  6872. this.low &= word.low;
  6873. },
  6874. xor: function Word64_xor(word) {
  6875. this.high ^= word.high;
  6876. this.low ^= word.low;
  6877. },
  6878. or: function Word64_or(word) {
  6879. this.high |= word.high;
  6880. this.low |= word.low;
  6881. },
  6882. shiftRight: function Word64_shiftRight(places) {
  6883. if (places >= 32) {
  6884. this.low = (this.high >>> (places - 32)) | 0;
  6885. this.high = 0;
  6886. } else {
  6887. this.low = (this.low >>> places) | (this.high << (32 - places));
  6888. this.high = (this.high >>> places) | 0;
  6889. }
  6890. },
  6891. shiftLeft: function Word64_shiftLeft(places) {
  6892. if (places >= 32) {
  6893. this.high = this.low << (places - 32);
  6894. this.low = 0;
  6895. } else {
  6896. this.high = (this.high << places) | (this.low >>> (32 - places));
  6897. this.low = this.low << places;
  6898. }
  6899. },
  6900. rotateRight: function Word64_rotateRight(places) {
  6901. var low, high;
  6902. if (places & 32) {
  6903. high = this.low;
  6904. low = this.high;
  6905. } else {
  6906. low = this.low;
  6907. high = this.high;
  6908. }
  6909. places &= 31;
  6910. this.low = (low >>> places) | (high << (32 - places));
  6911. this.high = (high >>> places) | (low << (32 - places));
  6912. },
  6913. not: function Word64_not() {
  6914. this.high = ~this.high;
  6915. this.low = ~this.low;
  6916. },
  6917. add: function Word64_add(word) {
  6918. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  6919. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  6920. if (lowAdd > 0xFFFFFFFF) {
  6921. highAdd += 1;
  6922. }
  6923. this.low = lowAdd | 0;
  6924. this.high = highAdd | 0;
  6925. },
  6926. copyTo: function Word64_copyTo(bytes, offset) {
  6927. bytes[offset] = (this.high >>> 24) & 0xFF;
  6928. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  6929. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  6930. bytes[offset + 3] = this.high & 0xFF;
  6931. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  6932. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  6933. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  6934. bytes[offset + 7] = this.low & 0xFF;
  6935. },
  6936. assign: function Word64_assign(word) {
  6937. this.high = word.high;
  6938. this.low = word.low;
  6939. }
  6940. };
  6941. return Word64;
  6942. })();
  6943. var calculateSHA256 = (function calculateSHA256Closure() {
  6944. function rotr(x, n) {
  6945. return (x >>> n) | (x << 32 - n);
  6946. }
  6947. function ch(x, y, z) {
  6948. return (x & y) ^ (~x & z);
  6949. }
  6950. function maj(x, y, z) {
  6951. return (x & y) ^ (x & z) ^ (y & z);
  6952. }
  6953. function sigma(x) {
  6954. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  6955. }
  6956. function sigmaPrime(x) {
  6957. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  6958. }
  6959. function littleSigma(x) {
  6960. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  6961. }
  6962. function littleSigmaPrime(x) {
  6963. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  6964. }
  6965. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  6966. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  6967. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  6968. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  6969. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  6970. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  6971. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  6972. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  6973. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  6974. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  6975. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  6976. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  6977. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  6978. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  6979. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  6980. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  6981. function hash(data, offset, length) {
  6982. // initial hash values
  6983. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  6984. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  6985. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  6986. // pre-processing
  6987. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  6988. var padded = new Uint8Array(paddedLength);
  6989. var i, j, n;
  6990. for (i = 0; i < length; ++i) {
  6991. padded[i] = data[offset++];
  6992. }
  6993. padded[i++] = 0x80;
  6994. n = paddedLength - 8;
  6995. while (i < n) {
  6996. padded[i++] = 0;
  6997. }
  6998. padded[i++] = 0;
  6999. padded[i++] = 0;
  7000. padded[i++] = 0;
  7001. padded[i++] = (length >>> 29) & 0xFF;
  7002. padded[i++] = (length >> 21) & 0xFF;
  7003. padded[i++] = (length >> 13) & 0xFF;
  7004. padded[i++] = (length >> 5) & 0xFF;
  7005. padded[i++] = (length << 3) & 0xFF;
  7006. var w = new Uint32Array(64);
  7007. // for each 512 bit block
  7008. for (i = 0; i < paddedLength;) {
  7009. for (j = 0; j < 16; ++j) {
  7010. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7011. (padded[i + 2] << 8) | (padded[i + 3]));
  7012. i += 4;
  7013. }
  7014. for (j = 16; j < 64; ++j) {
  7015. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7016. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7017. }
  7018. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7019. f = h5, g = h6, h = h7, t1, t2;
  7020. for (j = 0; j < 64; ++j) {
  7021. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7022. t2 = sigma(a) + maj(a, b, c);
  7023. h = g;
  7024. g = f;
  7025. f = e;
  7026. e = (d + t1) | 0;
  7027. d = c;
  7028. c = b;
  7029. b = a;
  7030. a = (t1 + t2) | 0;
  7031. }
  7032. h0 = (h0 + a) | 0;
  7033. h1 = (h1 + b) | 0;
  7034. h2 = (h2 + c) | 0;
  7035. h3 = (h3 + d) | 0;
  7036. h4 = (h4 + e) | 0;
  7037. h5 = (h5 + f) | 0;
  7038. h6 = (h6 + g) | 0;
  7039. h7 = (h7 + h) | 0;
  7040. }
  7041. return new Uint8Array([
  7042. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7043. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7044. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7045. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7046. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7047. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7048. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7049. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7050. ]);
  7051. }
  7052. return hash;
  7053. })();
  7054. var calculateSHA512 = (function calculateSHA512Closure() {
  7055. function ch(result, x, y, z, tmp) {
  7056. result.assign(x);
  7057. result.and(y);
  7058. tmp.assign(x);
  7059. tmp.not();
  7060. tmp.and(z);
  7061. result.xor(tmp);
  7062. }
  7063. function maj(result, x, y, z, tmp) {
  7064. result.assign(x);
  7065. result.and(y);
  7066. tmp.assign(x);
  7067. tmp.and(z);
  7068. result.xor(tmp);
  7069. tmp.assign(y);
  7070. tmp.and(z);
  7071. result.xor(tmp);
  7072. }
  7073. function sigma(result, x, tmp) {
  7074. result.assign(x);
  7075. result.rotateRight(28);
  7076. tmp.assign(x);
  7077. tmp.rotateRight(34);
  7078. result.xor(tmp);
  7079. tmp.assign(x);
  7080. tmp.rotateRight(39);
  7081. result.xor(tmp);
  7082. }
  7083. function sigmaPrime(result, x, tmp) {
  7084. result.assign(x);
  7085. result.rotateRight(14);
  7086. tmp.assign(x);
  7087. tmp.rotateRight(18);
  7088. result.xor(tmp);
  7089. tmp.assign(x);
  7090. tmp.rotateRight(41);
  7091. result.xor(tmp);
  7092. }
  7093. function littleSigma(result, x, tmp) {
  7094. result.assign(x);
  7095. result.rotateRight(1);
  7096. tmp.assign(x);
  7097. tmp.rotateRight(8);
  7098. result.xor(tmp);
  7099. tmp.assign(x);
  7100. tmp.shiftRight(7);
  7101. result.xor(tmp);
  7102. }
  7103. function littleSigmaPrime(result, x, tmp) {
  7104. result.assign(x);
  7105. result.rotateRight(19);
  7106. tmp.assign(x);
  7107. tmp.rotateRight(61);
  7108. result.xor(tmp);
  7109. tmp.assign(x);
  7110. tmp.shiftRight(6);
  7111. result.xor(tmp);
  7112. }
  7113. var k = [
  7114. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7115. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7116. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7117. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7118. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7119. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7120. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7121. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7122. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7123. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7124. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7125. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7126. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7127. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7128. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7129. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7130. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7131. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7132. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7133. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7134. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7135. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7136. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7137. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7138. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7139. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7140. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7141. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7142. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7143. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7144. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7145. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7146. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7147. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7148. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7149. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7150. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7151. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7152. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7153. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7154. function hash(data, offset, length, mode384) {
  7155. mode384 = !!mode384;
  7156. // initial hash values
  7157. var h0, h1, h2, h3, h4, h5, h6, h7;
  7158. if (!mode384) {
  7159. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7160. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7161. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7162. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7163. h4 = new Word64(0x510e527f, 0xade682d1);
  7164. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7165. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7166. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7167. }
  7168. else {
  7169. // SHA384 is exactly the same
  7170. // except with different starting values and a trimmed result
  7171. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7172. h1 = new Word64(0x629a292a, 0x367cd507);
  7173. h2 = new Word64(0x9159015a, 0x3070dd17);
  7174. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7175. h4 = new Word64(0x67332667, 0xffc00b31);
  7176. h5 = new Word64(0x8eb44a87, 0x68581511);
  7177. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7178. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7179. }
  7180. // pre-processing
  7181. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7182. var padded = new Uint8Array(paddedLength);
  7183. var i, j, n;
  7184. for (i = 0; i < length; ++i) {
  7185. padded[i] = data[offset++];
  7186. }
  7187. padded[i++] = 0x80;
  7188. n = paddedLength - 16;
  7189. while (i < n) {
  7190. padded[i++] = 0;
  7191. }
  7192. padded[i++] = 0;
  7193. padded[i++] = 0;
  7194. padded[i++] = 0;
  7195. padded[i++] = 0;
  7196. padded[i++] = 0;
  7197. padded[i++] = 0;
  7198. padded[i++] = 0;
  7199. padded[i++] = 0;
  7200. padded[i++] = 0;
  7201. padded[i++] = 0;
  7202. padded[i++] = 0;
  7203. padded[i++] = (length >>> 29) & 0xFF;
  7204. padded[i++] = (length >> 21) & 0xFF;
  7205. padded[i++] = (length >> 13) & 0xFF;
  7206. padded[i++] = (length >> 5) & 0xFF;
  7207. padded[i++] = (length << 3) & 0xFF;
  7208. var w = new Array(80);
  7209. for (i = 0; i < 80; i++) {
  7210. w[i] = new Word64(0, 0);
  7211. }
  7212. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7213. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7214. var g = new Word64(0, 0), h = new Word64(0, 0);
  7215. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7216. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7217. // for each 1024 bit block
  7218. for (i = 0; i < paddedLength;) {
  7219. for (j = 0; j < 16; ++j) {
  7220. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7221. (padded[i + 2] << 8) | (padded[i + 3]);
  7222. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7223. (padded[i + 6]) << 8 | (padded[i + 7]);
  7224. i += 8;
  7225. }
  7226. for (j = 16; j < 80; ++j) {
  7227. tmp3 = w[j];
  7228. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7229. tmp3.add(w[j - 7]);
  7230. littleSigma(tmp1, w[j - 15], tmp2);
  7231. tmp3.add(tmp1);
  7232. tmp3.add(w[j - 16]);
  7233. }
  7234. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7235. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7236. for (j = 0; j < 80; ++j) {
  7237. t1.assign(h);
  7238. sigmaPrime(tmp1, e, tmp2);
  7239. t1.add(tmp1);
  7240. ch(tmp1, e, f, g, tmp2);
  7241. t1.add(tmp1);
  7242. t1.add(k[j]);
  7243. t1.add(w[j]);
  7244. sigma(t2, a, tmp2);
  7245. maj(tmp1, a, b, c, tmp2);
  7246. t2.add(tmp1);
  7247. tmp3 = h;
  7248. h = g;
  7249. g = f;
  7250. f = e;
  7251. d.add(t1);
  7252. e = d;
  7253. d = c;
  7254. c = b;
  7255. b = a;
  7256. tmp3.assign(t1);
  7257. tmp3.add(t2);
  7258. a = tmp3;
  7259. }
  7260. h0.add(a);
  7261. h1.add(b);
  7262. h2.add(c);
  7263. h3.add(d);
  7264. h4.add(e);
  7265. h5.add(f);
  7266. h6.add(g);
  7267. h7.add(h);
  7268. }
  7269. var result;
  7270. if (!mode384) {
  7271. result = new Uint8Array(64);
  7272. h0.copyTo(result,0);
  7273. h1.copyTo(result,8);
  7274. h2.copyTo(result,16);
  7275. h3.copyTo(result,24);
  7276. h4.copyTo(result,32);
  7277. h5.copyTo(result,40);
  7278. h6.copyTo(result,48);
  7279. h7.copyTo(result,56);
  7280. }
  7281. else {
  7282. result = new Uint8Array(48);
  7283. h0.copyTo(result,0);
  7284. h1.copyTo(result,8);
  7285. h2.copyTo(result,16);
  7286. h3.copyTo(result,24);
  7287. h4.copyTo(result,32);
  7288. h5.copyTo(result,40);
  7289. }
  7290. return result;
  7291. }
  7292. return hash;
  7293. })();
  7294. var calculateSHA384 = (function calculateSHA384Closure() {
  7295. function hash(data, offset, length) {
  7296. return calculateSHA512(data, offset, length, true);
  7297. }
  7298. return hash;
  7299. })();
  7300. var NullCipher = (function NullCipherClosure() {
  7301. function NullCipher() {
  7302. }
  7303. NullCipher.prototype = {
  7304. decryptBlock: function NullCipher_decryptBlock(data) {
  7305. return data;
  7306. }
  7307. };
  7308. return NullCipher;
  7309. })();
  7310. var AES128Cipher = (function AES128CipherClosure() {
  7311. var rcon = new Uint8Array([
  7312. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7313. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7314. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7315. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7316. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7317. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7318. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7319. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7320. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7321. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7322. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7323. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7324. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7325. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7326. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7327. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7328. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7329. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7330. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7331. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7332. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7333. 0x74, 0xe8, 0xcb, 0x8d]);
  7334. var s = new Uint8Array([
  7335. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7336. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7337. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7338. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7339. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7340. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7341. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7342. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7343. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7344. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7345. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7346. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7347. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7348. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7349. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7350. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7351. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7352. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7353. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7354. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7355. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7356. 0xb0, 0x54, 0xbb, 0x16]);
  7357. var inv_s = new Uint8Array([
  7358. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7359. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7360. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7361. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7362. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7363. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7364. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7365. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7366. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7367. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7368. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7369. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7370. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7371. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7372. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7373. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7374. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7375. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7376. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7377. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7378. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7379. 0x55, 0x21, 0x0c, 0x7d]);
  7380. var mixCol = new Uint8Array(256);
  7381. for (var i = 0; i < 256; i++) {
  7382. if (i < 128) {
  7383. mixCol[i] = i << 1;
  7384. } else {
  7385. mixCol[i] = (i << 1) ^ 0x1b;
  7386. }
  7387. }
  7388. var mix = new Uint32Array([
  7389. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7390. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7391. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7392. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7393. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7394. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7395. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7396. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7397. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7398. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7399. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7400. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7401. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7402. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7403. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7404. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7405. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7406. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7407. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7408. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7409. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7410. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7411. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7412. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7413. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7414. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7415. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7416. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7417. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7418. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7419. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7420. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7421. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7422. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7423. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7424. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7425. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7426. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7427. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7428. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7429. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7430. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7431. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7432. function expandKey128(cipherKey) {
  7433. var b = 176, result = new Uint8Array(b);
  7434. result.set(cipherKey);
  7435. for (var j = 16, i = 1; j < b; ++i) {
  7436. // RotWord
  7437. var t1 = result[j - 3], t2 = result[j - 2],
  7438. t3 = result[j - 1], t4 = result[j - 4];
  7439. // SubWord
  7440. t1 = s[t1];
  7441. t2 = s[t2];
  7442. t3 = s[t3];
  7443. t4 = s[t4];
  7444. // Rcon
  7445. t1 = t1 ^ rcon[i];
  7446. for (var n = 0; n < 4; ++n) {
  7447. result[j] = (t1 ^= result[j - 16]);
  7448. j++;
  7449. result[j] = (t2 ^= result[j - 16]);
  7450. j++;
  7451. result[j] = (t3 ^= result[j - 16]);
  7452. j++;
  7453. result[j] = (t4 ^= result[j - 16]);
  7454. j++;
  7455. }
  7456. }
  7457. return result;
  7458. }
  7459. function decrypt128(input, key) {
  7460. var state = new Uint8Array(16);
  7461. state.set(input);
  7462. var i, j, k;
  7463. var t, u, v;
  7464. // AddRoundKey
  7465. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7466. state[j] ^= key[k];
  7467. }
  7468. for (i = 9; i >= 1; --i) {
  7469. // InvShiftRows
  7470. t = state[13];
  7471. state[13] = state[9];
  7472. state[9] = state[5];
  7473. state[5] = state[1];
  7474. state[1] = t;
  7475. t = state[14];
  7476. u = state[10];
  7477. state[14] = state[6];
  7478. state[10] = state[2];
  7479. state[6] = t;
  7480. state[2] = u;
  7481. t = state[15];
  7482. u = state[11];
  7483. v = state[7];
  7484. state[15] = state[3];
  7485. state[11] = t;
  7486. state[7] = u;
  7487. state[3] = v;
  7488. // InvSubBytes
  7489. for (j = 0; j < 16; ++j) {
  7490. state[j] = inv_s[state[j]];
  7491. }
  7492. // AddRoundKey
  7493. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7494. state[j] ^= key[k];
  7495. }
  7496. // InvMixColumns
  7497. for (j = 0; j < 16; j += 4) {
  7498. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7499. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7500. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7501. (s3 >>> 24) ^ (s3 << 8));
  7502. state[j] = (t >>> 24) & 0xFF;
  7503. state[j + 1] = (t >> 16) & 0xFF;
  7504. state[j + 2] = (t >> 8) & 0xFF;
  7505. state[j + 3] = t & 0xFF;
  7506. }
  7507. }
  7508. // InvShiftRows
  7509. t = state[13];
  7510. state[13] = state[9];
  7511. state[9] = state[5];
  7512. state[5] = state[1];
  7513. state[1] = t;
  7514. t = state[14];
  7515. u = state[10];
  7516. state[14] = state[6];
  7517. state[10] = state[2];
  7518. state[6] = t;
  7519. state[2] = u;
  7520. t = state[15];
  7521. u = state[11];
  7522. v = state[7];
  7523. state[15] = state[3];
  7524. state[11] = t;
  7525. state[7] = u;
  7526. state[3] = v;
  7527. for (j = 0; j < 16; ++j) {
  7528. // InvSubBytes
  7529. state[j] = inv_s[state[j]];
  7530. // AddRoundKey
  7531. state[j] ^= key[j];
  7532. }
  7533. return state;
  7534. }
  7535. function encrypt128(input, key) {
  7536. var t, u, v, k;
  7537. var state = new Uint8Array(16);
  7538. state.set(input);
  7539. for (j = 0; j < 16; ++j) {
  7540. // AddRoundKey
  7541. state[j] ^= key[j];
  7542. }
  7543. for (i = 1; i < 10; i++) {
  7544. //SubBytes
  7545. for (j = 0; j < 16; ++j) {
  7546. state[j] = s[state[j]];
  7547. }
  7548. //ShiftRows
  7549. v = state[1];
  7550. state[1] = state[5];
  7551. state[5] = state[9];
  7552. state[9] = state[13];
  7553. state[13] = v;
  7554. v = state[2];
  7555. u = state[6];
  7556. state[2] = state[10];
  7557. state[6] = state[14];
  7558. state[10] = v;
  7559. state[14] = u;
  7560. v = state[3];
  7561. u = state[7];
  7562. t = state[11];
  7563. state[3] = state[15];
  7564. state[7] = v;
  7565. state[11] = u;
  7566. state[15] = t;
  7567. //MixColumns
  7568. for (var j = 0; j < 16; j += 4) {
  7569. var s0 = state[j + 0], s1 = state[j + 1];
  7570. var s2 = state[j + 2], s3 = state[j + 3];
  7571. t = s0 ^ s1 ^ s2 ^ s3;
  7572. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7573. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7574. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7575. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7576. }
  7577. //AddRoundKey
  7578. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7579. state[j] ^= key[k];
  7580. }
  7581. }
  7582. //SubBytes
  7583. for (j = 0; j < 16; ++j) {
  7584. state[j] = s[state[j]];
  7585. }
  7586. //ShiftRows
  7587. v = state[1];
  7588. state[1] = state[5];
  7589. state[5] = state[9];
  7590. state[9] = state[13];
  7591. state[13] = v;
  7592. v = state[2];
  7593. u = state[6];
  7594. state[2] = state[10];
  7595. state[6] = state[14];
  7596. state[10] = v;
  7597. state[14] = u;
  7598. v = state[3];
  7599. u = state[7];
  7600. t = state[11];
  7601. state[3] = state[15];
  7602. state[7] = v;
  7603. state[11] = u;
  7604. state[15] = t;
  7605. //AddRoundKey
  7606. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7607. state[j] ^= key[k];
  7608. }
  7609. return state;
  7610. }
  7611. function AES128Cipher(key) {
  7612. this.key = expandKey128(key);
  7613. this.buffer = new Uint8Array(16);
  7614. this.bufferPosition = 0;
  7615. }
  7616. function decryptBlock2(data, finalize) {
  7617. var i, j, ii, sourceLength = data.length,
  7618. buffer = this.buffer, bufferLength = this.bufferPosition,
  7619. result = [], iv = this.iv;
  7620. for (i = 0; i < sourceLength; ++i) {
  7621. buffer[bufferLength] = data[i];
  7622. ++bufferLength;
  7623. if (bufferLength < 16) {
  7624. continue;
  7625. }
  7626. // buffer is full, decrypting
  7627. var plain = decrypt128(buffer, this.key);
  7628. // xor-ing the IV vector to get plain text
  7629. for (j = 0; j < 16; ++j) {
  7630. plain[j] ^= iv[j];
  7631. }
  7632. iv = buffer;
  7633. result.push(plain);
  7634. buffer = new Uint8Array(16);
  7635. bufferLength = 0;
  7636. }
  7637. // saving incomplete buffer
  7638. this.buffer = buffer;
  7639. this.bufferLength = bufferLength;
  7640. this.iv = iv;
  7641. if (result.length === 0) {
  7642. return new Uint8Array([]);
  7643. }
  7644. // combining plain text blocks into one
  7645. var outputLength = 16 * result.length;
  7646. if (finalize) {
  7647. // undo a padding that is described in RFC 2898
  7648. var lastBlock = result[result.length - 1];
  7649. var psLen = lastBlock[15];
  7650. if (psLen <= 16) {
  7651. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7652. if (lastBlock[i] !== psLen) {
  7653. // Invalid padding, assume that the block has no padding.
  7654. psLen = 0;
  7655. break;
  7656. }
  7657. }
  7658. outputLength -= psLen;
  7659. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7660. }
  7661. }
  7662. var output = new Uint8Array(outputLength);
  7663. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7664. output.set(result[i], j);
  7665. }
  7666. return output;
  7667. }
  7668. AES128Cipher.prototype = {
  7669. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7670. var i, sourceLength = data.length;
  7671. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7672. // waiting for IV values -- they are at the start of the stream
  7673. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7674. buffer[bufferLength] = data[i];
  7675. }
  7676. if (bufferLength < 16) {
  7677. // need more data
  7678. this.bufferLength = bufferLength;
  7679. return new Uint8Array([]);
  7680. }
  7681. this.iv = buffer;
  7682. this.buffer = new Uint8Array(16);
  7683. this.bufferLength = 0;
  7684. // starting decryption
  7685. this.decryptBlock = decryptBlock2;
  7686. return this.decryptBlock(data.subarray(16), finalize);
  7687. },
  7688. encrypt: function AES128Cipher_encrypt(data, iv) {
  7689. var i, j, ii, sourceLength = data.length,
  7690. buffer = this.buffer, bufferLength = this.bufferPosition,
  7691. result = [];
  7692. if (!iv) {
  7693. iv = new Uint8Array(16);
  7694. }
  7695. for (i = 0; i < sourceLength; ++i) {
  7696. buffer[bufferLength] = data[i];
  7697. ++bufferLength;
  7698. if (bufferLength < 16) {
  7699. continue;
  7700. }
  7701. for (j = 0; j < 16; ++j) {
  7702. buffer[j] ^= iv[j];
  7703. }
  7704. // buffer is full, encrypting
  7705. var cipher = encrypt128(buffer, this.key);
  7706. iv = cipher;
  7707. result.push(cipher);
  7708. buffer = new Uint8Array(16);
  7709. bufferLength = 0;
  7710. }
  7711. // saving incomplete buffer
  7712. this.buffer = buffer;
  7713. this.bufferLength = bufferLength;
  7714. this.iv = iv;
  7715. if (result.length === 0) {
  7716. return new Uint8Array([]);
  7717. }
  7718. // combining plain text blocks into one
  7719. var outputLength = 16 * result.length;
  7720. var output = new Uint8Array(outputLength);
  7721. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7722. output.set(result[i], j);
  7723. }
  7724. return output;
  7725. }
  7726. };
  7727. return AES128Cipher;
  7728. })();
  7729. var AES256Cipher = (function AES256CipherClosure() {
  7730. var rcon = new Uint8Array([
  7731. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7732. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7733. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7734. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7735. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7736. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7737. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7738. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7739. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7740. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7741. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7742. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7743. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7744. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7745. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7746. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7747. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7748. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7749. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7750. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7751. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7752. 0x74, 0xe8, 0xcb, 0x8d]);
  7753. var s = new Uint8Array([
  7754. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7755. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7756. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7757. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7758. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7759. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7760. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7761. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7762. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7763. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7764. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7765. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7766. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7767. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7768. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7769. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7770. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7771. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7772. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7773. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7774. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7775. 0xb0, 0x54, 0xbb, 0x16]);
  7776. var inv_s = new Uint8Array([
  7777. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7778. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7779. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7780. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7781. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7782. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7783. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7784. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7785. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7786. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7787. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7788. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7789. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7790. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7791. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7792. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7793. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7794. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7795. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7796. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7797. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7798. 0x55, 0x21, 0x0c, 0x7d]);
  7799. var mixCol = new Uint8Array(256);
  7800. for (var i = 0; i < 256; i++) {
  7801. if (i < 128) {
  7802. mixCol[i] = i << 1;
  7803. } else {
  7804. mixCol[i] = (i << 1) ^ 0x1b;
  7805. }
  7806. }
  7807. var mix = new Uint32Array([
  7808. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7809. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7810. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7811. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7812. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7813. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7814. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7815. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7816. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7817. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7818. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7819. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7820. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7821. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7822. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7823. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7824. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7825. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7826. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7827. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7828. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7829. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7830. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7831. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7832. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7833. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7834. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7835. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7836. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7837. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7838. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7839. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7840. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7841. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7842. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7843. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7844. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7845. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7846. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7847. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7848. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7849. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7850. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7851. function expandKey256(cipherKey) {
  7852. var b = 240, result = new Uint8Array(b);
  7853. var r = 1;
  7854. result.set(cipherKey);
  7855. for (var j = 32, i = 1; j < b; ++i) {
  7856. if (j % 32 === 16) {
  7857. t1 = s[t1];
  7858. t2 = s[t2];
  7859. t3 = s[t3];
  7860. t4 = s[t4];
  7861. } else if (j % 32 === 0) {
  7862. // RotWord
  7863. var t1 = result[j - 3], t2 = result[j - 2],
  7864. t3 = result[j - 1], t4 = result[j - 4];
  7865. // SubWord
  7866. t1 = s[t1];
  7867. t2 = s[t2];
  7868. t3 = s[t3];
  7869. t4 = s[t4];
  7870. // Rcon
  7871. t1 = t1 ^ r;
  7872. if ((r <<= 1) >= 256) {
  7873. r = (r ^ 0x1b) & 0xFF;
  7874. }
  7875. }
  7876. for (var n = 0; n < 4; ++n) {
  7877. result[j] = (t1 ^= result[j - 32]);
  7878. j++;
  7879. result[j] = (t2 ^= result[j - 32]);
  7880. j++;
  7881. result[j] = (t3 ^= result[j - 32]);
  7882. j++;
  7883. result[j] = (t4 ^= result[j - 32]);
  7884. j++;
  7885. }
  7886. }
  7887. return result;
  7888. }
  7889. function decrypt256(input, key) {
  7890. var state = new Uint8Array(16);
  7891. state.set(input);
  7892. var i, j, k;
  7893. var t, u, v;
  7894. // AddRoundKey
  7895. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7896. state[j] ^= key[k];
  7897. }
  7898. for (i = 13; i >= 1; --i) {
  7899. // InvShiftRows
  7900. t = state[13];
  7901. state[13] = state[9];
  7902. state[9] = state[5];
  7903. state[5] = state[1];
  7904. state[1] = t;
  7905. t = state[14];
  7906. u = state[10];
  7907. state[14] = state[6];
  7908. state[10] = state[2];
  7909. state[6] = t;
  7910. state[2] = u;
  7911. t = state[15];
  7912. u = state[11];
  7913. v = state[7];
  7914. state[15] = state[3];
  7915. state[11] = t;
  7916. state[7] = u;
  7917. state[3] = v;
  7918. // InvSubBytes
  7919. for (j = 0; j < 16; ++j) {
  7920. state[j] = inv_s[state[j]];
  7921. }
  7922. // AddRoundKey
  7923. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7924. state[j] ^= key[k];
  7925. }
  7926. // InvMixColumns
  7927. for (j = 0; j < 16; j += 4) {
  7928. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7929. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7930. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7931. (s3 >>> 24) ^ (s3 << 8));
  7932. state[j] = (t >>> 24) & 0xFF;
  7933. state[j + 1] = (t >> 16) & 0xFF;
  7934. state[j + 2] = (t >> 8) & 0xFF;
  7935. state[j + 3] = t & 0xFF;
  7936. }
  7937. }
  7938. // InvShiftRows
  7939. t = state[13];
  7940. state[13] = state[9];
  7941. state[9] = state[5];
  7942. state[5] = state[1];
  7943. state[1] = t;
  7944. t = state[14];
  7945. u = state[10];
  7946. state[14] = state[6];
  7947. state[10] = state[2];
  7948. state[6] = t;
  7949. state[2] = u;
  7950. t = state[15];
  7951. u = state[11];
  7952. v = state[7];
  7953. state[15] = state[3];
  7954. state[11] = t;
  7955. state[7] = u;
  7956. state[3] = v;
  7957. for (j = 0; j < 16; ++j) {
  7958. // InvSubBytes
  7959. state[j] = inv_s[state[j]];
  7960. // AddRoundKey
  7961. state[j] ^= key[j];
  7962. }
  7963. return state;
  7964. }
  7965. function encrypt256(input, key) {
  7966. var t, u, v, k;
  7967. var state = new Uint8Array(16);
  7968. state.set(input);
  7969. for (j = 0; j < 16; ++j) {
  7970. // AddRoundKey
  7971. state[j] ^= key[j];
  7972. }
  7973. for (i = 1; i < 14; i++) {
  7974. //SubBytes
  7975. for (j = 0; j < 16; ++j) {
  7976. state[j] = s[state[j]];
  7977. }
  7978. //ShiftRows
  7979. v = state[1];
  7980. state[1] = state[5];
  7981. state[5] = state[9];
  7982. state[9] = state[13];
  7983. state[13] = v;
  7984. v = state[2];
  7985. u = state[6];
  7986. state[2] = state[10];
  7987. state[6] = state[14];
  7988. state[10] = v;
  7989. state[14] = u;
  7990. v = state[3];
  7991. u = state[7];
  7992. t = state[11];
  7993. state[3] = state[15];
  7994. state[7] = v;
  7995. state[11] = u;
  7996. state[15] = t;
  7997. //MixColumns
  7998. for (var j = 0; j < 16; j += 4) {
  7999. var s0 = state[j + 0], s1 = state[j + 1];
  8000. var s2 = state[j + 2], s3 = state[j + 3];
  8001. t = s0 ^ s1 ^ s2 ^ s3;
  8002. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8003. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8004. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8005. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8006. }
  8007. //AddRoundKey
  8008. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8009. state[j] ^= key[k];
  8010. }
  8011. }
  8012. //SubBytes
  8013. for (j = 0; j < 16; ++j) {
  8014. state[j] = s[state[j]];
  8015. }
  8016. //ShiftRows
  8017. v = state[1];
  8018. state[1] = state[5];
  8019. state[5] = state[9];
  8020. state[9] = state[13];
  8021. state[13] = v;
  8022. v = state[2];
  8023. u = state[6];
  8024. state[2] = state[10];
  8025. state[6] = state[14];
  8026. state[10] = v;
  8027. state[14] = u;
  8028. v = state[3];
  8029. u = state[7];
  8030. t = state[11];
  8031. state[3] = state[15];
  8032. state[7] = v;
  8033. state[11] = u;
  8034. state[15] = t;
  8035. //AddRoundKey
  8036. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8037. state[j] ^= key[k];
  8038. }
  8039. return state;
  8040. }
  8041. function AES256Cipher(key) {
  8042. this.key = expandKey256(key);
  8043. this.buffer = new Uint8Array(16);
  8044. this.bufferPosition = 0;
  8045. }
  8046. function decryptBlock2(data, finalize) {
  8047. var i, j, ii, sourceLength = data.length,
  8048. buffer = this.buffer, bufferLength = this.bufferPosition,
  8049. result = [], iv = this.iv;
  8050. for (i = 0; i < sourceLength; ++i) {
  8051. buffer[bufferLength] = data[i];
  8052. ++bufferLength;
  8053. if (bufferLength < 16) {
  8054. continue;
  8055. }
  8056. // buffer is full, decrypting
  8057. var plain = decrypt256(buffer, this.key);
  8058. // xor-ing the IV vector to get plain text
  8059. for (j = 0; j < 16; ++j) {
  8060. plain[j] ^= iv[j];
  8061. }
  8062. iv = buffer;
  8063. result.push(plain);
  8064. buffer = new Uint8Array(16);
  8065. bufferLength = 0;
  8066. }
  8067. // saving incomplete buffer
  8068. this.buffer = buffer;
  8069. this.bufferLength = bufferLength;
  8070. this.iv = iv;
  8071. if (result.length === 0) {
  8072. return new Uint8Array([]);
  8073. }
  8074. // combining plain text blocks into one
  8075. var outputLength = 16 * result.length;
  8076. if (finalize) {
  8077. // undo a padding that is described in RFC 2898
  8078. var lastBlock = result[result.length - 1];
  8079. var psLen = lastBlock[15];
  8080. if (psLen <= 16) {
  8081. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8082. if (lastBlock[i] !== psLen) {
  8083. // Invalid padding, assume that the block has no padding.
  8084. psLen = 0;
  8085. break;
  8086. }
  8087. }
  8088. outputLength -= psLen;
  8089. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8090. }
  8091. }
  8092. var output = new Uint8Array(outputLength);
  8093. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8094. output.set(result[i], j);
  8095. }
  8096. return output;
  8097. }
  8098. AES256Cipher.prototype = {
  8099. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8100. var i, sourceLength = data.length;
  8101. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8102. // if not supplied an IV wait for IV values
  8103. // they are at the start of the stream
  8104. if (iv) {
  8105. this.iv = iv;
  8106. } else {
  8107. for (i = 0; bufferLength < 16 &&
  8108. i < sourceLength; ++i, ++bufferLength) {
  8109. buffer[bufferLength] = data[i];
  8110. }
  8111. if (bufferLength < 16) {
  8112. //need more data
  8113. this.bufferLength = bufferLength;
  8114. return new Uint8Array([]);
  8115. }
  8116. this.iv = buffer;
  8117. data = data.subarray(16);
  8118. }
  8119. this.buffer = new Uint8Array(16);
  8120. this.bufferLength = 0;
  8121. // starting decryption
  8122. this.decryptBlock = decryptBlock2;
  8123. return this.decryptBlock(data, finalize);
  8124. },
  8125. encrypt: function AES256Cipher_encrypt(data, iv) {
  8126. var i, j, ii, sourceLength = data.length,
  8127. buffer = this.buffer, bufferLength = this.bufferPosition,
  8128. result = [];
  8129. if (!iv) {
  8130. iv = new Uint8Array(16);
  8131. }
  8132. for (i = 0; i < sourceLength; ++i) {
  8133. buffer[bufferLength] = data[i];
  8134. ++bufferLength;
  8135. if (bufferLength < 16) {
  8136. continue;
  8137. }
  8138. for (j = 0; j < 16; ++j) {
  8139. buffer[j] ^= iv[j];
  8140. }
  8141. // buffer is full, encrypting
  8142. var cipher = encrypt256(buffer, this.key);
  8143. this.iv = cipher;
  8144. result.push(cipher);
  8145. buffer = new Uint8Array(16);
  8146. bufferLength = 0;
  8147. }
  8148. // saving incomplete buffer
  8149. this.buffer = buffer;
  8150. this.bufferLength = bufferLength;
  8151. this.iv = iv;
  8152. if (result.length === 0) {
  8153. return new Uint8Array([]);
  8154. }
  8155. // combining plain text blocks into one
  8156. var outputLength = 16 * result.length;
  8157. var output = new Uint8Array(outputLength);
  8158. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8159. output.set(result[i], j);
  8160. }
  8161. return output;
  8162. }
  8163. };
  8164. return AES256Cipher;
  8165. })();
  8166. var PDF17 = (function PDF17Closure() {
  8167. function compareByteArrays(array1, array2) {
  8168. if (array1.length !== array2.length) {
  8169. return false;
  8170. }
  8171. for (var i = 0; i < array1.length; i++) {
  8172. if (array1[i] !== array2[i]) {
  8173. return false;
  8174. }
  8175. }
  8176. return true;
  8177. }
  8178. function PDF17() {
  8179. }
  8180. PDF17.prototype = {
  8181. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8182. ownerValidationSalt,
  8183. userBytes,
  8184. ownerPassword) {
  8185. var hashData = new Uint8Array(password.length + 56);
  8186. hashData.set(password, 0);
  8187. hashData.set(ownerValidationSalt, password.length);
  8188. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8189. var result = calculateSHA256(hashData, 0, hashData.length);
  8190. return compareByteArrays(result, ownerPassword);
  8191. },
  8192. checkUserPassword: function PDF17_checkUserPassword(password,
  8193. userValidationSalt,
  8194. userPassword) {
  8195. var hashData = new Uint8Array(password.length + 8);
  8196. hashData.set(password, 0);
  8197. hashData.set(userValidationSalt, password.length);
  8198. var result = calculateSHA256(hashData, 0, hashData.length);
  8199. return compareByteArrays(result, userPassword);
  8200. },
  8201. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8202. ownerEncryption) {
  8203. var hashData = new Uint8Array(password.length + 56);
  8204. hashData.set(password, 0);
  8205. hashData.set(ownerKeySalt, password.length);
  8206. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8207. var key = calculateSHA256(hashData, 0, hashData.length);
  8208. var cipher = new AES256Cipher(key);
  8209. return cipher.decryptBlock(ownerEncryption,
  8210. false,
  8211. new Uint8Array(16));
  8212. },
  8213. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8214. userEncryption) {
  8215. var hashData = new Uint8Array(password.length + 8);
  8216. hashData.set(password, 0);
  8217. hashData.set(userKeySalt, password.length);
  8218. //key is the decryption key for the UE string
  8219. var key = calculateSHA256(hashData, 0, hashData.length);
  8220. var cipher = new AES256Cipher(key);
  8221. return cipher.decryptBlock(userEncryption,
  8222. false,
  8223. new Uint8Array(16));
  8224. }
  8225. };
  8226. return PDF17;
  8227. })();
  8228. var PDF20 = (function PDF20Closure() {
  8229. function concatArrays(array1, array2) {
  8230. var t = new Uint8Array(array1.length + array2.length);
  8231. t.set(array1, 0);
  8232. t.set(array2, array1.length);
  8233. return t;
  8234. }
  8235. function calculatePDF20Hash(password, input, userBytes) {
  8236. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8237. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8238. var e = [0];
  8239. var i = 0;
  8240. while (i < 64 || e[e.length - 1] > i - 32) {
  8241. var arrayLength = password.length + k.length + userBytes.length;
  8242. var k1 = new Uint8Array(arrayLength * 64);
  8243. var array = concatArrays(password, k);
  8244. array = concatArrays(array, userBytes);
  8245. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8246. k1.set(array, pos);
  8247. }
  8248. //AES128 CBC NO PADDING with
  8249. //first 16 bytes of k as the key and the second 16 as the iv.
  8250. var cipher = new AES128Cipher(k.subarray(0, 16));
  8251. e = cipher.encrypt(k1, k.subarray(16, 32));
  8252. //Now we have to take the first 16 bytes of an unsigned
  8253. //big endian integer... and compute the remainder
  8254. //modulo 3.... That is a fairly large number and
  8255. //JavaScript isn't going to handle that well...
  8256. //So we're using a trick that allows us to perform
  8257. //modulo math byte by byte
  8258. var remainder = 0;
  8259. for (var z = 0; z < 16; z++) {
  8260. remainder *= (256 % 3);
  8261. remainder %= 3;
  8262. remainder += ((e[z] >>> 0) % 3);
  8263. remainder %= 3;
  8264. }
  8265. if (remainder === 0) {
  8266. k = calculateSHA256(e, 0, e.length);
  8267. }
  8268. else if (remainder === 1) {
  8269. k = calculateSHA384(e, 0, e.length);
  8270. }
  8271. else if (remainder === 2) {
  8272. k = calculateSHA512(e, 0, e.length);
  8273. }
  8274. i++;
  8275. }
  8276. return k.subarray(0, 32);
  8277. }
  8278. function PDF20() {
  8279. }
  8280. function compareByteArrays(array1, array2) {
  8281. if (array1.length !== array2.length) {
  8282. return false;
  8283. }
  8284. for (var i = 0; i < array1.length; i++) {
  8285. if (array1[i] !== array2[i]) {
  8286. return false;
  8287. }
  8288. }
  8289. return true;
  8290. }
  8291. PDF20.prototype = {
  8292. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8293. return calculatePDF20Hash(password, concatBytes, userBytes);
  8294. },
  8295. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8296. ownerValidationSalt,
  8297. userBytes,
  8298. ownerPassword) {
  8299. var hashData = new Uint8Array(password.length + 56);
  8300. hashData.set(password, 0);
  8301. hashData.set(ownerValidationSalt, password.length);
  8302. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8303. var result = calculatePDF20Hash(password, hashData, userBytes);
  8304. return compareByteArrays(result, ownerPassword);
  8305. },
  8306. checkUserPassword: function PDF20_checkUserPassword(password,
  8307. userValidationSalt,
  8308. userPassword) {
  8309. var hashData = new Uint8Array(password.length + 8);
  8310. hashData.set(password, 0);
  8311. hashData.set(userValidationSalt, password.length);
  8312. var result = calculatePDF20Hash(password, hashData, []);
  8313. return compareByteArrays(result, userPassword);
  8314. },
  8315. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8316. ownerEncryption) {
  8317. var hashData = new Uint8Array(password.length + 56);
  8318. hashData.set(password, 0);
  8319. hashData.set(ownerKeySalt, password.length);
  8320. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8321. var key = calculatePDF20Hash(password, hashData, userBytes);
  8322. var cipher = new AES256Cipher(key);
  8323. return cipher.decryptBlock(ownerEncryption,
  8324. false,
  8325. new Uint8Array(16));
  8326. },
  8327. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8328. userEncryption) {
  8329. var hashData = new Uint8Array(password.length + 8);
  8330. hashData.set(password, 0);
  8331. hashData.set(userKeySalt, password.length);
  8332. //key is the decryption key for the UE string
  8333. var key = calculatePDF20Hash(password, hashData, []);
  8334. var cipher = new AES256Cipher(key);
  8335. return cipher.decryptBlock(userEncryption,
  8336. false,
  8337. new Uint8Array(16));
  8338. }
  8339. };
  8340. return PDF20;
  8341. })();
  8342. var CipherTransform = (function CipherTransformClosure() {
  8343. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8344. this.stringCipherConstructor = stringCipherConstructor;
  8345. this.streamCipherConstructor = streamCipherConstructor;
  8346. }
  8347. CipherTransform.prototype = {
  8348. createStream: function CipherTransform_createStream(stream, length) {
  8349. var cipher = new this.streamCipherConstructor();
  8350. return new DecryptStream(stream, length,
  8351. function cipherTransformDecryptStream(data, finalize) {
  8352. return cipher.decryptBlock(data, finalize);
  8353. }
  8354. );
  8355. },
  8356. decryptString: function CipherTransform_decryptString(s) {
  8357. var cipher = new this.stringCipherConstructor();
  8358. var data = stringToBytes(s);
  8359. data = cipher.decryptBlock(data, true);
  8360. return bytesToString(data);
  8361. }
  8362. };
  8363. return CipherTransform;
  8364. })();
  8365. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8366. var defaultPasswordBytes = new Uint8Array([
  8367. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8368. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8369. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8370. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8371. function createEncryptionKey20(revision, password, ownerPassword,
  8372. ownerValidationSalt, ownerKeySalt, uBytes,
  8373. userPassword, userValidationSalt, userKeySalt,
  8374. ownerEncryption, userEncryption, perms) {
  8375. if (password) {
  8376. var passwordLength = Math.min(127, password.length);
  8377. password = password.subarray(0, passwordLength);
  8378. } else {
  8379. password = [];
  8380. }
  8381. var pdfAlgorithm;
  8382. if (revision === 6) {
  8383. pdfAlgorithm = new PDF20();
  8384. } else {
  8385. pdfAlgorithm = new PDF17();
  8386. }
  8387. if (pdfAlgorithm) {
  8388. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8389. userPassword)) {
  8390. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8391. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8392. uBytes,
  8393. ownerPassword)) {
  8394. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8395. ownerEncryption);
  8396. }
  8397. }
  8398. return null;
  8399. }
  8400. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8401. flags, revision, keyLength, encryptMetadata) {
  8402. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8403. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8404. if (password) {
  8405. n = Math.min(32, password.length);
  8406. for (; i < n; ++i) {
  8407. hashData[i] = password[i];
  8408. }
  8409. }
  8410. j = 0;
  8411. while (i < 32) {
  8412. hashData[i++] = defaultPasswordBytes[j++];
  8413. }
  8414. // as now the padded password in the hashData[0..i]
  8415. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8416. hashData[i++] = ownerPassword[j];
  8417. }
  8418. hashData[i++] = flags & 0xFF;
  8419. hashData[i++] = (flags >> 8) & 0xFF;
  8420. hashData[i++] = (flags >> 16) & 0xFF;
  8421. hashData[i++] = (flags >>> 24) & 0xFF;
  8422. for (j = 0, n = fileId.length; j < n; ++j) {
  8423. hashData[i++] = fileId[j];
  8424. }
  8425. if (revision >= 4 && !encryptMetadata) {
  8426. hashData[i++] = 0xFF;
  8427. hashData[i++] = 0xFF;
  8428. hashData[i++] = 0xFF;
  8429. hashData[i++] = 0xFF;
  8430. }
  8431. var hash = calculateMD5(hashData, 0, i);
  8432. var keyLengthInBytes = keyLength >> 3;
  8433. if (revision >= 3) {
  8434. for (j = 0; j < 50; ++j) {
  8435. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8436. }
  8437. }
  8438. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8439. var cipher, checkData;
  8440. if (revision >= 3) {
  8441. for (i = 0; i < 32; ++i) {
  8442. hashData[i] = defaultPasswordBytes[i];
  8443. }
  8444. for (j = 0, n = fileId.length; j < n; ++j) {
  8445. hashData[i++] = fileId[j];
  8446. }
  8447. cipher = new ARCFourCipher(encryptionKey);
  8448. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8449. n = encryptionKey.length;
  8450. var derivedKey = new Uint8Array(n), k;
  8451. for (j = 1; j <= 19; ++j) {
  8452. for (k = 0; k < n; ++k) {
  8453. derivedKey[k] = encryptionKey[k] ^ j;
  8454. }
  8455. cipher = new ARCFourCipher(derivedKey);
  8456. checkData = cipher.encryptBlock(checkData);
  8457. }
  8458. for (j = 0, n = checkData.length; j < n; ++j) {
  8459. if (userPassword[j] !== checkData[j]) {
  8460. return null;
  8461. }
  8462. }
  8463. } else {
  8464. cipher = new ARCFourCipher(encryptionKey);
  8465. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8466. for (j = 0, n = checkData.length; j < n; ++j) {
  8467. if (userPassword[j] !== checkData[j]) {
  8468. return null;
  8469. }
  8470. }
  8471. }
  8472. return encryptionKey;
  8473. }
  8474. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8475. var hashData = new Uint8Array(32), i = 0, j, n;
  8476. n = Math.min(32, password.length);
  8477. for (; i < n; ++i) {
  8478. hashData[i] = password[i];
  8479. }
  8480. j = 0;
  8481. while (i < 32) {
  8482. hashData[i++] = defaultPasswordBytes[j++];
  8483. }
  8484. var hash = calculateMD5(hashData, 0, i);
  8485. var keyLengthInBytes = keyLength >> 3;
  8486. if (revision >= 3) {
  8487. for (j = 0; j < 50; ++j) {
  8488. hash = calculateMD5(hash, 0, hash.length);
  8489. }
  8490. }
  8491. var cipher, userPassword;
  8492. if (revision >= 3) {
  8493. userPassword = ownerPassword;
  8494. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8495. for (j = 19; j >= 0; j--) {
  8496. for (k = 0; k < keyLengthInBytes; ++k) {
  8497. derivedKey[k] = hash[k] ^ j;
  8498. }
  8499. cipher = new ARCFourCipher(derivedKey);
  8500. userPassword = cipher.encryptBlock(userPassword);
  8501. }
  8502. } else {
  8503. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8504. userPassword = cipher.encryptBlock(ownerPassword);
  8505. }
  8506. return userPassword;
  8507. }
  8508. var identityName = Name.get('Identity');
  8509. function CipherTransformFactory(dict, fileId, password) {
  8510. var filter = dict.get('Filter');
  8511. if (!isName(filter) || filter.name !== 'Standard') {
  8512. error('unknown encryption method');
  8513. }
  8514. this.dict = dict;
  8515. var algorithm = dict.get('V');
  8516. if (!isInt(algorithm) ||
  8517. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8518. algorithm !== 5)) {
  8519. error('unsupported encryption algorithm');
  8520. }
  8521. this.algorithm = algorithm;
  8522. var keyLength = dict.get('Length') || 40;
  8523. if (!isInt(keyLength) ||
  8524. keyLength < 40 || (keyLength % 8) !== 0) {
  8525. error('invalid key length');
  8526. }
  8527. // prepare keys
  8528. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8529. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8530. var flags = dict.get('P');
  8531. var revision = dict.get('R');
  8532. // meaningful when V is 4 or 5
  8533. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8534. dict.get('EncryptMetadata') !== false);
  8535. this.encryptMetadata = encryptMetadata;
  8536. var fileIdBytes = stringToBytes(fileId);
  8537. var passwordBytes;
  8538. if (password) {
  8539. passwordBytes = stringToBytes(password);
  8540. }
  8541. var encryptionKey;
  8542. if (algorithm !== 5) {
  8543. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8544. ownerPassword, userPassword, flags,
  8545. revision, keyLength, encryptMetadata);
  8546. }
  8547. else {
  8548. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8549. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8550. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8551. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8552. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8553. var ownerEncryption = stringToBytes(dict.get('OE'));
  8554. var userEncryption = stringToBytes(dict.get('UE'));
  8555. var perms = stringToBytes(dict.get('Perms'));
  8556. encryptionKey =
  8557. createEncryptionKey20(revision, passwordBytes,
  8558. ownerPassword, ownerValidationSalt,
  8559. ownerKeySalt, uBytes,
  8560. userPassword, userValidationSalt,
  8561. userKeySalt, ownerEncryption,
  8562. userEncryption, perms);
  8563. }
  8564. if (!encryptionKey && !password) {
  8565. throw new PasswordException('No password given',
  8566. PasswordResponses.NEED_PASSWORD);
  8567. } else if (!encryptionKey && password) {
  8568. // Attempting use the password as an owner password
  8569. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8570. revision, keyLength);
  8571. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8572. ownerPassword, userPassword, flags,
  8573. revision, keyLength, encryptMetadata);
  8574. }
  8575. if (!encryptionKey) {
  8576. throw new PasswordException('Incorrect Password',
  8577. PasswordResponses.INCORRECT_PASSWORD);
  8578. }
  8579. this.encryptionKey = encryptionKey;
  8580. if (algorithm >= 4) {
  8581. this.cf = dict.get('CF');
  8582. this.stmf = dict.get('StmF') || identityName;
  8583. this.strf = dict.get('StrF') || identityName;
  8584. this.eff = dict.get('EFF') || this.strf;
  8585. }
  8586. }
  8587. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8588. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8589. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8590. key[i] = encryptionKey[i];
  8591. }
  8592. key[i++] = num & 0xFF;
  8593. key[i++] = (num >> 8) & 0xFF;
  8594. key[i++] = (num >> 16) & 0xFF;
  8595. key[i++] = gen & 0xFF;
  8596. key[i++] = (gen >> 8) & 0xFF;
  8597. if (isAes) {
  8598. key[i++] = 0x73;
  8599. key[i++] = 0x41;
  8600. key[i++] = 0x6C;
  8601. key[i++] = 0x54;
  8602. }
  8603. var hash = calculateMD5(key, 0, i);
  8604. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8605. }
  8606. function buildCipherConstructor(cf, name, num, gen, key) {
  8607. var cryptFilter = cf.get(name.name);
  8608. var cfm;
  8609. if (cryptFilter !== null && cryptFilter !== undefined) {
  8610. cfm = cryptFilter.get('CFM');
  8611. }
  8612. if (!cfm || cfm.name === 'None') {
  8613. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8614. return new NullCipher();
  8615. };
  8616. }
  8617. if ('V2' === cfm.name) {
  8618. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8619. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8620. };
  8621. }
  8622. if ('AESV2' === cfm.name) {
  8623. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8624. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8625. };
  8626. }
  8627. if ('AESV3' === cfm.name) {
  8628. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8629. return new AES256Cipher(key);
  8630. };
  8631. }
  8632. error('Unknown crypto method');
  8633. }
  8634. CipherTransformFactory.prototype = {
  8635. createCipherTransform:
  8636. function CipherTransformFactory_createCipherTransform(num, gen) {
  8637. if (this.algorithm === 4 || this.algorithm === 5) {
  8638. return new CipherTransform(
  8639. buildCipherConstructor(this.cf, this.stmf,
  8640. num, gen, this.encryptionKey),
  8641. buildCipherConstructor(this.cf, this.strf,
  8642. num, gen, this.encryptionKey));
  8643. }
  8644. // algorithms 1 and 2
  8645. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8646. var cipherConstructor = function buildCipherCipherConstructor() {
  8647. return new ARCFourCipher(key);
  8648. };
  8649. return new CipherTransform(cipherConstructor, cipherConstructor);
  8650. }
  8651. };
  8652. return CipherTransformFactory;
  8653. })();
  8654. var PatternType = {
  8655. FUNCTION_BASED: 1,
  8656. AXIAL: 2,
  8657. RADIAL: 3,
  8658. FREE_FORM_MESH: 4,
  8659. LATTICE_FORM_MESH: 5,
  8660. COONS_PATCH_MESH: 6,
  8661. TENSOR_PATCH_MESH: 7
  8662. };
  8663. var Pattern = (function PatternClosure() {
  8664. // Constructor should define this.getPattern
  8665. function Pattern() {
  8666. error('should not call Pattern constructor');
  8667. }
  8668. Pattern.prototype = {
  8669. // Input: current Canvas context
  8670. // Output: the appropriate fillStyle or strokeStyle
  8671. getPattern: function Pattern_getPattern(ctx) {
  8672. error('Should not call Pattern.getStyle: ' + ctx);
  8673. }
  8674. };
  8675. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8676. res) {
  8677. var dict = isStream(shading) ? shading.dict : shading;
  8678. var type = dict.get('ShadingType');
  8679. switch (type) {
  8680. case PatternType.AXIAL:
  8681. case PatternType.RADIAL:
  8682. // Both radial and axial shadings are handled by RadialAxial shading.
  8683. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8684. case PatternType.FREE_FORM_MESH:
  8685. case PatternType.LATTICE_FORM_MESH:
  8686. case PatternType.COONS_PATCH_MESH:
  8687. case PatternType.TENSOR_PATCH_MESH:
  8688. return new Shadings.Mesh(shading, matrix, xref, res);
  8689. default:
  8690. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8691. return new Shadings.Dummy();
  8692. }
  8693. };
  8694. return Pattern;
  8695. })();
  8696. var Shadings = {};
  8697. // A small number to offset the first/last color stops so we can insert ones to
  8698. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8699. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8700. // internally so we have to go bigger.
  8701. Shadings.SMALL_NUMBER = 1e-2;
  8702. // Radial and axial shading have very similar implementations
  8703. // If needed, the implementations can be broken into two classes
  8704. Shadings.RadialAxial = (function RadialAxialClosure() {
  8705. function RadialAxial(dict, matrix, xref, res) {
  8706. this.matrix = matrix;
  8707. this.coordsArr = dict.get('Coords');
  8708. this.shadingType = dict.get('ShadingType');
  8709. this.type = 'Pattern';
  8710. var cs = dict.get('ColorSpace', 'CS');
  8711. cs = ColorSpace.parse(cs, xref, res);
  8712. this.cs = cs;
  8713. var t0 = 0.0, t1 = 1.0;
  8714. if (dict.has('Domain')) {
  8715. var domainArr = dict.get('Domain');
  8716. t0 = domainArr[0];
  8717. t1 = domainArr[1];
  8718. }
  8719. var extendStart = false, extendEnd = false;
  8720. if (dict.has('Extend')) {
  8721. var extendArr = dict.get('Extend');
  8722. extendStart = extendArr[0];
  8723. extendEnd = extendArr[1];
  8724. }
  8725. if (this.shadingType === PatternType.RADIAL &&
  8726. (!extendStart || !extendEnd)) {
  8727. // Radial gradient only currently works if either circle is fully within
  8728. // the other circle.
  8729. var x1 = this.coordsArr[0];
  8730. var y1 = this.coordsArr[1];
  8731. var r1 = this.coordsArr[2];
  8732. var x2 = this.coordsArr[3];
  8733. var y2 = this.coordsArr[4];
  8734. var r2 = this.coordsArr[5];
  8735. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8736. if (r1 <= r2 + distance &&
  8737. r2 <= r1 + distance) {
  8738. warn('Unsupported radial gradient.');
  8739. }
  8740. }
  8741. this.extendStart = extendStart;
  8742. this.extendEnd = extendEnd;
  8743. var fnObj = dict.get('Function');
  8744. var fn = PDFFunction.parseArray(xref, fnObj);
  8745. // 10 samples seems good enough for now, but probably won't work
  8746. // if there are sharp color changes. Ideally, we would implement
  8747. // the spec faithfully and add lossless optimizations.
  8748. var diff = t1 - t0;
  8749. var step = diff / 10;
  8750. var colorStops = this.colorStops = [];
  8751. // Protect against bad domains so we don't end up in an infinte loop below.
  8752. if (t0 >= t1 || step <= 0) {
  8753. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8754. // now.
  8755. info('Bad shading domain.');
  8756. return;
  8757. }
  8758. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8759. var rgbColor;
  8760. for (var i = t0; i <= t1; i += step) {
  8761. ratio[0] = i;
  8762. fn(ratio, 0, color, 0);
  8763. rgbColor = cs.getRgb(color, 0);
  8764. var cssColor = Util.makeCssRgb(rgbColor);
  8765. colorStops.push([(i - t0) / diff, cssColor]);
  8766. }
  8767. var background = 'transparent';
  8768. if (dict.has('Background')) {
  8769. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8770. background = Util.makeCssRgb(rgbColor);
  8771. }
  8772. if (!extendStart) {
  8773. // Insert a color stop at the front and offset the first real color stop
  8774. // so it doesn't conflict with the one we insert.
  8775. colorStops.unshift([0, background]);
  8776. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8777. }
  8778. if (!extendEnd) {
  8779. // Same idea as above in extendStart but for the end.
  8780. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8781. colorStops.push([1, background]);
  8782. }
  8783. this.colorStops = colorStops;
  8784. }
  8785. RadialAxial.prototype = {
  8786. getIR: function RadialAxial_getIR() {
  8787. var coordsArr = this.coordsArr;
  8788. var shadingType = this.shadingType;
  8789. var type, p0, p1, r0, r1;
  8790. if (shadingType === PatternType.AXIAL) {
  8791. p0 = [coordsArr[0], coordsArr[1]];
  8792. p1 = [coordsArr[2], coordsArr[3]];
  8793. r0 = null;
  8794. r1 = null;
  8795. type = 'axial';
  8796. } else if (shadingType === PatternType.RADIAL) {
  8797. p0 = [coordsArr[0], coordsArr[1]];
  8798. p1 = [coordsArr[3], coordsArr[4]];
  8799. r0 = coordsArr[2];
  8800. r1 = coordsArr[5];
  8801. type = 'radial';
  8802. } else {
  8803. error('getPattern type unknown: ' + shadingType);
  8804. }
  8805. var matrix = this.matrix;
  8806. if (matrix) {
  8807. p0 = Util.applyTransform(p0, matrix);
  8808. p1 = Util.applyTransform(p1, matrix);
  8809. }
  8810. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8811. }
  8812. };
  8813. return RadialAxial;
  8814. })();
  8815. // All mesh shading. For now, they will be presented as set of the triangles
  8816. // to be drawn on the canvas and rgb color for each vertex.
  8817. Shadings.Mesh = (function MeshClosure() {
  8818. function MeshStreamReader(stream, context) {
  8819. this.stream = stream;
  8820. this.context = context;
  8821. this.buffer = 0;
  8822. this.bufferLength = 0;
  8823. var numComps = context.numComps;
  8824. this.tmpCompsBuf = new Float32Array(numComps);
  8825. var csNumComps = context.colorSpace;
  8826. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  8827. this.tmpCompsBuf;
  8828. }
  8829. MeshStreamReader.prototype = {
  8830. get hasData() {
  8831. if (this.stream.end) {
  8832. return this.stream.pos < this.stream.end;
  8833. }
  8834. if (this.bufferLength > 0) {
  8835. return true;
  8836. }
  8837. var nextByte = this.stream.getByte();
  8838. if (nextByte < 0) {
  8839. return false;
  8840. }
  8841. this.buffer = nextByte;
  8842. this.bufferLength = 8;
  8843. return true;
  8844. },
  8845. readBits: function MeshStreamReader_readBits(n) {
  8846. var buffer = this.buffer;
  8847. var bufferLength = this.bufferLength;
  8848. if (n === 32) {
  8849. if (bufferLength === 0) {
  8850. return ((this.stream.getByte() << 24) |
  8851. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  8852. this.stream.getByte()) >>> 0;
  8853. }
  8854. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  8855. (this.stream.getByte() << 8) | this.stream.getByte();
  8856. var nextByte = this.stream.getByte();
  8857. this.buffer = nextByte & ((1 << bufferLength) - 1);
  8858. return ((buffer << (8 - bufferLength)) |
  8859. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  8860. }
  8861. if (n === 8 && bufferLength === 0) {
  8862. return this.stream.getByte();
  8863. }
  8864. while (bufferLength < n) {
  8865. buffer = (buffer << 8) | this.stream.getByte();
  8866. bufferLength += 8;
  8867. }
  8868. bufferLength -= n;
  8869. this.bufferLength = bufferLength;
  8870. this.buffer = buffer & ((1 << bufferLength) - 1);
  8871. return buffer >> bufferLength;
  8872. },
  8873. align: function MeshStreamReader_align() {
  8874. this.buffer = 0;
  8875. this.bufferLength = 0;
  8876. },
  8877. readFlag: function MeshStreamReader_readFlag() {
  8878. return this.readBits(this.context.bitsPerFlag);
  8879. },
  8880. readCoordinate: function MeshStreamReader_readCoordinate() {
  8881. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  8882. var xi = this.readBits(bitsPerCoordinate);
  8883. var yi = this.readBits(bitsPerCoordinate);
  8884. var decode = this.context.decode;
  8885. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  8886. 2.3283064365386963e-10; // 2 ^ -32
  8887. return [
  8888. xi * scale * (decode[1] - decode[0]) + decode[0],
  8889. yi * scale * (decode[3] - decode[2]) + decode[2]
  8890. ];
  8891. },
  8892. readComponents: function MeshStreamReader_readComponents() {
  8893. var numComps = this.context.numComps;
  8894. var bitsPerComponent = this.context.bitsPerComponent;
  8895. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  8896. 2.3283064365386963e-10; // 2 ^ -32
  8897. var decode = this.context.decode;
  8898. var components = this.tmpCompsBuf;
  8899. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  8900. var ci = this.readBits(bitsPerComponent);
  8901. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  8902. }
  8903. var color = this.tmpCsCompsBuf;
  8904. if (this.context.colorFn) {
  8905. this.context.colorFn(components, 0, color, 0);
  8906. }
  8907. return this.context.colorSpace.getRgb(color, 0);
  8908. }
  8909. };
  8910. function decodeType4Shading(mesh, reader) {
  8911. var coords = mesh.coords;
  8912. var colors = mesh.colors;
  8913. var operators = [];
  8914. var ps = []; // not maintaining cs since that will match ps
  8915. var verticesLeft = 0; // assuming we have all data to start a new triangle
  8916. while (reader.hasData) {
  8917. var f = reader.readFlag();
  8918. var coord = reader.readCoordinate();
  8919. var color = reader.readComponents();
  8920. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  8921. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  8922. switch (f) {
  8923. case 0:
  8924. verticesLeft = 3;
  8925. break;
  8926. case 1:
  8927. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  8928. verticesLeft = 1;
  8929. break;
  8930. case 2:
  8931. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  8932. verticesLeft = 1;
  8933. break;
  8934. }
  8935. operators.push(f);
  8936. }
  8937. ps.push(coords.length);
  8938. coords.push(coord);
  8939. colors.push(color);
  8940. verticesLeft--;
  8941. reader.align();
  8942. }
  8943. var psPacked = new Int32Array(ps);
  8944. mesh.figures.push({
  8945. type: 'triangles',
  8946. coords: psPacked,
  8947. colors: psPacked
  8948. });
  8949. }
  8950. function decodeType5Shading(mesh, reader, verticesPerRow) {
  8951. var coords = mesh.coords;
  8952. var colors = mesh.colors;
  8953. var ps = []; // not maintaining cs since that will match ps
  8954. while (reader.hasData) {
  8955. var coord = reader.readCoordinate();
  8956. var color = reader.readComponents();
  8957. ps.push(coords.length);
  8958. coords.push(coord);
  8959. colors.push(color);
  8960. }
  8961. var psPacked = new Int32Array(ps);
  8962. mesh.figures.push({
  8963. type: 'lattice',
  8964. coords: psPacked,
  8965. colors: psPacked,
  8966. verticesPerRow: verticesPerRow
  8967. });
  8968. }
  8969. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  8970. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  8971. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  8972. var getB = (function getBClosure() {
  8973. function buildB(count) {
  8974. var lut = [];
  8975. for (var i = 0; i <= count; i++) {
  8976. var t = i / count, t_ = 1 - t;
  8977. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  8978. 3 * t * t * t_, t * t * t]));
  8979. }
  8980. return lut;
  8981. }
  8982. var cache = [];
  8983. return function getB(count) {
  8984. if (!cache[count]) {
  8985. cache[count] = buildB(count);
  8986. }
  8987. return cache[count];
  8988. };
  8989. })();
  8990. function buildFigureFromPatch(mesh, index) {
  8991. var figure = mesh.figures[index];
  8992. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  8993. var coords = mesh.coords, colors = mesh.colors;
  8994. var pi = figure.coords;
  8995. var ci = figure.colors;
  8996. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  8997. coords[pi[12]][0], coords[pi[15]][0]);
  8998. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  8999. coords[pi[12]][1], coords[pi[15]][1]);
  9000. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9001. coords[pi[12]][0], coords[pi[15]][0]);
  9002. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9003. coords[pi[12]][1], coords[pi[15]][1]);
  9004. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9005. (mesh.bounds[2] - mesh.bounds[0]));
  9006. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9007. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9008. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9009. (mesh.bounds[3] - mesh.bounds[1]));
  9010. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9011. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9012. var verticesPerRow = splitXBy + 1;
  9013. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9014. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9015. var k = 0;
  9016. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9017. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9018. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9019. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9020. for (var row = 0; row <= splitYBy; row++) {
  9021. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9022. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9023. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9024. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9025. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9026. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9027. for (var col = 0; col <= splitXBy; col++, k++) {
  9028. if ((row === 0 || row === splitYBy) &&
  9029. (col === 0 || col === splitXBy)) {
  9030. continue;
  9031. }
  9032. var x = 0, y = 0;
  9033. var q = 0;
  9034. for (var i = 0; i <= 3; i++) {
  9035. for (var j = 0; j <= 3; j++, q++) {
  9036. var m = bRow[row][i] * bCol[col][j];
  9037. x += coords[pi[q]][0] * m;
  9038. y += coords[pi[q]][1] * m;
  9039. }
  9040. }
  9041. figureCoords[k] = coords.length;
  9042. coords.push([x, y]);
  9043. figureColors[k] = colors.length;
  9044. var newColor = new Uint8Array(3);
  9045. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9046. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9047. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9048. colors.push(newColor);
  9049. }
  9050. }
  9051. figureCoords[0] = pi[0];
  9052. figureColors[0] = ci[0];
  9053. figureCoords[splitXBy] = pi[3];
  9054. figureColors[splitXBy] = ci[1];
  9055. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9056. figureColors[verticesPerRow * splitYBy] = ci[2];
  9057. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9058. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9059. mesh.figures[index] = {
  9060. type: 'lattice',
  9061. coords: figureCoords,
  9062. colors: figureColors,
  9063. verticesPerRow: verticesPerRow
  9064. };
  9065. }
  9066. function decodeType6Shading(mesh, reader) {
  9067. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9068. var coords = mesh.coords;
  9069. var colors = mesh.colors;
  9070. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9071. var cs = new Int32Array(4); // c00, c30, c03, c33
  9072. while (reader.hasData) {
  9073. var f = reader.readFlag();
  9074. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9075. var i, ii;
  9076. var pi = coords.length;
  9077. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9078. coords.push(reader.readCoordinate());
  9079. }
  9080. var ci = colors.length;
  9081. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9082. colors.push(reader.readComponents());
  9083. }
  9084. var tmp1, tmp2, tmp3, tmp4;
  9085. switch (f) {
  9086. case 0:
  9087. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9088. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9089. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9090. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9091. cs[2] = ci + 1; cs[3] = ci + 2;
  9092. cs[0] = ci; cs[1] = ci + 3;
  9093. break;
  9094. case 1:
  9095. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9096. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9097. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9098. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9099. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9100. tmp1 = cs[2]; tmp2 = cs[3];
  9101. cs[2] = ci + 1; cs[3] = ci;
  9102. cs[0] = tmp1; cs[1] = tmp2;
  9103. break;
  9104. case 2:
  9105. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9106. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9107. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9108. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9109. cs[2] = cs[3]; cs[3] = ci + 1;
  9110. cs[0] = cs[1]; cs[1] = ci;
  9111. break;
  9112. case 3:
  9113. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9114. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9115. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9116. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9117. cs[2] = cs[0]; cs[3] = cs[1];
  9118. cs[0] = ci; cs[1] = ci + 1;
  9119. break;
  9120. }
  9121. // set p11, p12, p21, p22
  9122. ps[5] = coords.length;
  9123. coords.push([
  9124. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9125. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9126. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9127. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9128. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9129. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9130. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9131. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9132. ]);
  9133. ps[6] = coords.length;
  9134. coords.push([
  9135. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9136. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9137. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9138. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9139. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9140. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9141. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9142. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9143. ]);
  9144. ps[9] = coords.length;
  9145. coords.push([
  9146. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9147. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9148. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9149. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9150. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9151. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9152. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9153. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9154. ]);
  9155. ps[10] = coords.length;
  9156. coords.push([
  9157. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9158. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9159. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9160. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9161. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9162. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9163. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9164. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9165. ]);
  9166. mesh.figures.push({
  9167. type: 'patch',
  9168. coords: new Int32Array(ps), // making copies of ps and cs
  9169. colors: new Int32Array(cs)
  9170. });
  9171. }
  9172. }
  9173. function decodeType7Shading(mesh, reader) {
  9174. var coords = mesh.coords;
  9175. var colors = mesh.colors;
  9176. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9177. var cs = new Int32Array(4); // c00, c30, c03, c33
  9178. while (reader.hasData) {
  9179. var f = reader.readFlag();
  9180. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9181. var i, ii;
  9182. var pi = coords.length;
  9183. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9184. coords.push(reader.readCoordinate());
  9185. }
  9186. var ci = colors.length;
  9187. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9188. colors.push(reader.readComponents());
  9189. }
  9190. var tmp1, tmp2, tmp3, tmp4;
  9191. switch (f) {
  9192. case 0:
  9193. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9194. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9195. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9196. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9197. cs[2] = ci + 1; cs[3] = ci + 2;
  9198. cs[0] = ci; cs[1] = ci + 3;
  9199. break;
  9200. case 1:
  9201. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9202. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9203. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9204. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9205. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9206. tmp1 = cs[2]; tmp2 = cs[3];
  9207. cs[2] = ci + 1; cs[3] = ci;
  9208. cs[0] = tmp1; cs[1] = tmp2;
  9209. break;
  9210. case 2:
  9211. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9212. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9213. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9214. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9215. cs[2] = cs[3]; cs[3] = ci + 1;
  9216. cs[0] = cs[1]; cs[1] = ci;
  9217. break;
  9218. case 3:
  9219. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9220. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9221. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9222. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9223. cs[2] = cs[0]; cs[3] = cs[1];
  9224. cs[0] = ci; cs[1] = ci + 1;
  9225. break;
  9226. }
  9227. mesh.figures.push({
  9228. type: 'patch',
  9229. coords: new Int32Array(ps), // making copies of ps and cs
  9230. colors: new Int32Array(cs)
  9231. });
  9232. }
  9233. }
  9234. function updateBounds(mesh) {
  9235. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9236. maxX = minX, maxY = minY;
  9237. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9238. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9239. minX = minX > x ? x : minX;
  9240. minY = minY > y ? y : minY;
  9241. maxX = maxX < x ? x : maxX;
  9242. maxY = maxY < y ? y : maxY;
  9243. }
  9244. mesh.bounds = [minX, minY, maxX, maxY];
  9245. }
  9246. function packData(mesh) {
  9247. var i, ii, j, jj;
  9248. var coords = mesh.coords;
  9249. var coordsPacked = new Float32Array(coords.length * 2);
  9250. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9251. var xy = coords[i];
  9252. coordsPacked[j++] = xy[0];
  9253. coordsPacked[j++] = xy[1];
  9254. }
  9255. mesh.coords = coordsPacked;
  9256. var colors = mesh.colors;
  9257. var colorsPacked = new Uint8Array(colors.length * 3);
  9258. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9259. var c = colors[i];
  9260. colorsPacked[j++] = c[0];
  9261. colorsPacked[j++] = c[1];
  9262. colorsPacked[j++] = c[2];
  9263. }
  9264. mesh.colors = colorsPacked;
  9265. var figures = mesh.figures;
  9266. for (i = 0, ii = figures.length; i < ii; i++) {
  9267. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9268. for (j = 0, jj = ps.length; j < jj; j++) {
  9269. ps[j] *= 2;
  9270. cs[j] *= 3;
  9271. }
  9272. }
  9273. }
  9274. function Mesh(stream, matrix, xref, res) {
  9275. assert(isStream(stream), 'Mesh data is not a stream');
  9276. var dict = stream.dict;
  9277. this.matrix = matrix;
  9278. this.shadingType = dict.get('ShadingType');
  9279. this.type = 'Pattern';
  9280. this.bbox = dict.get('BBox');
  9281. var cs = dict.get('ColorSpace', 'CS');
  9282. cs = ColorSpace.parse(cs, xref, res);
  9283. this.cs = cs;
  9284. this.background = dict.has('Background') ?
  9285. cs.getRgb(dict.get('Background'), 0) : null;
  9286. var fnObj = dict.get('Function');
  9287. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9288. this.coords = [];
  9289. this.colors = [];
  9290. this.figures = [];
  9291. var decodeContext = {
  9292. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9293. bitsPerComponent: dict.get('BitsPerComponent'),
  9294. bitsPerFlag: dict.get('BitsPerFlag'),
  9295. decode: dict.get('Decode'),
  9296. colorFn: fn,
  9297. colorSpace: cs,
  9298. numComps: fn ? 1 : cs.numComps
  9299. };
  9300. var reader = new MeshStreamReader(stream, decodeContext);
  9301. var patchMesh = false;
  9302. switch (this.shadingType) {
  9303. case PatternType.FREE_FORM_MESH:
  9304. decodeType4Shading(this, reader);
  9305. break;
  9306. case PatternType.LATTICE_FORM_MESH:
  9307. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9308. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9309. decodeType5Shading(this, reader, verticesPerRow);
  9310. break;
  9311. case PatternType.COONS_PATCH_MESH:
  9312. decodeType6Shading(this, reader);
  9313. patchMesh = true;
  9314. break;
  9315. case PatternType.TENSOR_PATCH_MESH:
  9316. decodeType7Shading(this, reader);
  9317. patchMesh = true;
  9318. break;
  9319. default:
  9320. error('Unsupported mesh type.');
  9321. break;
  9322. }
  9323. if (patchMesh) {
  9324. // dirty bounds calculation for determining, how dense shall be triangles
  9325. updateBounds(this);
  9326. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9327. buildFigureFromPatch(this, i);
  9328. }
  9329. }
  9330. // calculate bounds
  9331. updateBounds(this);
  9332. packData(this);
  9333. }
  9334. Mesh.prototype = {
  9335. getIR: function Mesh_getIR() {
  9336. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9337. this.bounds, this.matrix, this.bbox, this.background];
  9338. }
  9339. };
  9340. return Mesh;
  9341. })();
  9342. Shadings.Dummy = (function DummyClosure() {
  9343. function Dummy() {
  9344. this.type = 'Pattern';
  9345. }
  9346. Dummy.prototype = {
  9347. getIR: function Dummy_getIR() {
  9348. return ['Dummy'];
  9349. }
  9350. };
  9351. return Dummy;
  9352. })();
  9353. function getTilingPatternIR(operatorList, dict, args) {
  9354. var matrix = dict.get('Matrix');
  9355. var bbox = dict.get('BBox');
  9356. var xstep = dict.get('XStep');
  9357. var ystep = dict.get('YStep');
  9358. var paintType = dict.get('PaintType');
  9359. var tilingType = dict.get('TilingType');
  9360. return [
  9361. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9362. paintType, tilingType
  9363. ];
  9364. }
  9365. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9366. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9367. uniquePrefix, idCounters, fontCache) {
  9368. this.pdfManager = pdfManager;
  9369. this.xref = xref;
  9370. this.handler = handler;
  9371. this.pageIndex = pageIndex;
  9372. this.uniquePrefix = uniquePrefix;
  9373. this.idCounters = idCounters;
  9374. this.fontCache = fontCache;
  9375. }
  9376. // Trying to minimize Date.now() usage and check every 100 time
  9377. var TIME_SLOT_DURATION_MS = 20;
  9378. var CHECK_TIME_EVERY = 100;
  9379. function TimeSlotManager() {
  9380. this.reset();
  9381. }
  9382. TimeSlotManager.prototype = {
  9383. check: function TimeSlotManager_check() {
  9384. if (++this.checked < CHECK_TIME_EVERY) {
  9385. return false;
  9386. }
  9387. this.checked = 0;
  9388. return this.endTime <= Date.now();
  9389. },
  9390. reset: function TimeSlotManager_reset() {
  9391. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9392. this.checked = 0;
  9393. }
  9394. };
  9395. var deferred = Promise.resolve();
  9396. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9397. PartialEvaluator.prototype = {
  9398. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9399. if (!isDict(resources)) {
  9400. return false;
  9401. }
  9402. var processed = Object.create(null);
  9403. if (resources.objId) {
  9404. processed[resources.objId] = true;
  9405. }
  9406. var nodes = [resources];
  9407. while (nodes.length) {
  9408. var key;
  9409. var node = nodes.shift();
  9410. // First check the current resources for blend modes.
  9411. var graphicStates = node.get('ExtGState');
  9412. if (isDict(graphicStates)) {
  9413. graphicStates = graphicStates.getAll();
  9414. for (key in graphicStates) {
  9415. var graphicState = graphicStates[key];
  9416. var bm = graphicState['BM'];
  9417. if (isName(bm) && bm.name !== 'Normal') {
  9418. return true;
  9419. }
  9420. }
  9421. }
  9422. // Descend into the XObjects to look for more resources and blend modes.
  9423. var xObjects = node.get('XObject');
  9424. if (!isDict(xObjects)) {
  9425. continue;
  9426. }
  9427. xObjects = xObjects.getAll();
  9428. for (key in xObjects) {
  9429. var xObject = xObjects[key];
  9430. if (!isStream(xObject)) {
  9431. continue;
  9432. }
  9433. if (xObject.dict.objId) {
  9434. if (processed[xObject.dict.objId]) {
  9435. // stream has objId and is processed already
  9436. continue;
  9437. }
  9438. processed[xObject.dict.objId] = true;
  9439. }
  9440. var xResources = xObject.dict.get('Resources');
  9441. // Checking objId to detect an infinite loop.
  9442. if (isDict(xResources) &&
  9443. (!xResources.objId || !processed[xResources.objId])) {
  9444. nodes.push(xResources);
  9445. if (xResources.objId) {
  9446. processed[xResources.objId] = true;
  9447. }
  9448. }
  9449. }
  9450. }
  9451. return false;
  9452. },
  9453. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9454. xobj, smask,
  9455. operatorList,
  9456. initialState) {
  9457. var matrix = xobj.dict.get('Matrix');
  9458. var bbox = xobj.dict.get('BBox');
  9459. var group = xobj.dict.get('Group');
  9460. if (group) {
  9461. var groupOptions = {
  9462. matrix: matrix,
  9463. bbox: bbox,
  9464. smask: smask,
  9465. isolated: false,
  9466. knockout: false
  9467. };
  9468. var groupSubtype = group.get('S');
  9469. var colorSpace;
  9470. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9471. groupOptions.isolated = (group.get('I') || false);
  9472. groupOptions.knockout = (group.get('K') || false);
  9473. colorSpace = (group.has('CS') ?
  9474. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9475. }
  9476. if (smask && smask.backdrop) {
  9477. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9478. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9479. }
  9480. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9481. }
  9482. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9483. return this.getOperatorList(xobj,
  9484. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9485. then(function () {
  9486. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9487. if (group) {
  9488. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9489. }
  9490. });
  9491. },
  9492. buildPaintImageXObject:
  9493. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9494. inline, operatorList,
  9495. cacheKey, cache) {
  9496. var self = this;
  9497. var dict = image.dict;
  9498. var w = dict.get('Width', 'W');
  9499. var h = dict.get('Height', 'H');
  9500. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9501. warn('Image dimensions are missing, or not numbers.');
  9502. return;
  9503. }
  9504. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9505. warn('Image exceeded maximum allowed size and was removed.');
  9506. return;
  9507. }
  9508. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9509. var imgData, args;
  9510. if (imageMask) {
  9511. // This depends on a tmpCanvas being filled with the
  9512. // current fillStyle, such that processing the pixel
  9513. // data can't be done here. Instead of creating a
  9514. // complete PDFImage, only read the information needed
  9515. // for later.
  9516. var width = dict.get('Width', 'W');
  9517. var height = dict.get('Height', 'H');
  9518. var bitStrideLength = (width + 7) >> 3;
  9519. var imgArray = image.getBytes(bitStrideLength * height);
  9520. var decode = dict.get('Decode', 'D');
  9521. var inverseDecode = (!!decode && decode[0] > 0);
  9522. imgData = PDFImage.createMask(imgArray, width, height,
  9523. image instanceof DecodeStream,
  9524. inverseDecode);
  9525. imgData.cached = true;
  9526. args = [imgData];
  9527. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9528. if (cacheKey) {
  9529. cache.key = cacheKey;
  9530. cache.fn = OPS.paintImageMaskXObject;
  9531. cache.args = args;
  9532. }
  9533. return;
  9534. }
  9535. var softMask = (dict.get('SMask', 'SM') || false);
  9536. var mask = (dict.get('Mask') || false);
  9537. var SMALL_IMAGE_DIMENSIONS = 200;
  9538. // Inlining small images into the queue as RGB data
  9539. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9540. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9541. var imageObj = new PDFImage(this.xref, resources, image,
  9542. inline, null, null);
  9543. // We force the use of RGBA_32BPP images here, because we can't handle
  9544. // any other kind.
  9545. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9546. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9547. return;
  9548. }
  9549. // If there is no imageMask, create the PDFImage and a lot
  9550. // of image processing can be done here.
  9551. var uniquePrefix = (this.uniquePrefix || '');
  9552. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9553. operatorList.addDependency(objId);
  9554. args = [objId, w, h];
  9555. if (!softMask && !mask && image instanceof JpegStream &&
  9556. image.isNativelySupported(this.xref, resources)) {
  9557. // These JPEGs don't need any more processing so we can just send it.
  9558. operatorList.addOp(OPS.paintJpegXObject, args);
  9559. this.handler.send('obj',
  9560. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9561. return;
  9562. }
  9563. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9564. then(function(imageObj) {
  9565. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9566. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9567. [imgData.data.buffer]);
  9568. }).then(null, function (reason) {
  9569. warn('Unable to decode image: ' + reason);
  9570. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9571. });
  9572. operatorList.addOp(OPS.paintImageXObject, args);
  9573. if (cacheKey) {
  9574. cache.key = cacheKey;
  9575. cache.fn = OPS.paintImageXObject;
  9576. cache.args = args;
  9577. }
  9578. },
  9579. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9580. operatorList,
  9581. stateManager) {
  9582. var smaskContent = smask.get('G');
  9583. var smaskOptions = {
  9584. subtype: smask.get('S').name,
  9585. backdrop: smask.get('BC')
  9586. };
  9587. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9588. operatorList, stateManager.state.clone());
  9589. },
  9590. handleTilingType:
  9591. function PartialEvaluator_handleTilingType(fn, args, resources,
  9592. pattern, patternDict,
  9593. operatorList) {
  9594. // Create an IR of the pattern code.
  9595. var tilingOpList = new OperatorList();
  9596. return this.getOperatorList(pattern,
  9597. (patternDict.get('Resources') || resources), tilingOpList).
  9598. then(function () {
  9599. // Add the dependencies to the parent operator list so they are
  9600. // resolved before sub operator list is executed synchronously.
  9601. operatorList.addDependencies(tilingOpList.dependencies);
  9602. operatorList.addOp(fn, getTilingPatternIR({
  9603. fnArray: tilingOpList.fnArray,
  9604. argsArray: tilingOpList.argsArray
  9605. }, patternDict, args));
  9606. });
  9607. },
  9608. handleSetFont:
  9609. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9610. operatorList, state) {
  9611. // TODO(mack): Not needed?
  9612. var fontName;
  9613. if (fontArgs) {
  9614. fontArgs = fontArgs.slice();
  9615. fontName = fontArgs[0].name;
  9616. }
  9617. var self = this;
  9618. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9619. function (translated) {
  9620. if (!translated.font.isType3Font) {
  9621. return translated;
  9622. }
  9623. return translated.loadType3Data(self, resources, operatorList).then(
  9624. function () {
  9625. return translated;
  9626. });
  9627. }).then(function (translated) {
  9628. state.font = translated.font;
  9629. translated.send(self.handler);
  9630. return translated.loadedName;
  9631. });
  9632. },
  9633. handleText: function PartialEvaluator_handleText(chars, state) {
  9634. var font = state.font;
  9635. var glyphs = font.charsToGlyphs(chars);
  9636. var isAddToPathSet = !!(state.textRenderingMode &
  9637. TextRenderingMode.ADD_TO_PATH_FLAG);
  9638. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9639. var buildPath = function (fontChar) {
  9640. if (!font.renderer.hasBuiltPath(fontChar)) {
  9641. var path = font.renderer.getPathJs(fontChar);
  9642. this.handler.send('commonobj', [
  9643. font.loadedName + '_path_' + fontChar,
  9644. 'FontPath',
  9645. path
  9646. ]);
  9647. }
  9648. }.bind(this);
  9649. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9650. var glyph = glyphs[i];
  9651. if (glyph === null) {
  9652. continue;
  9653. }
  9654. buildPath(glyph.fontChar);
  9655. // If the glyph has an accent we need to build a path for its
  9656. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9657. var accent = glyph.accent;
  9658. if (accent && accent.fontChar) {
  9659. buildPath(accent.fontChar);
  9660. }
  9661. }
  9662. }
  9663. return glyphs;
  9664. },
  9665. setGState: function PartialEvaluator_setGState(resources, gState,
  9666. operatorList, xref,
  9667. stateManager) {
  9668. // This array holds the converted/processed state data.
  9669. var gStateObj = [];
  9670. var gStateMap = gState.map;
  9671. var self = this;
  9672. var promise = Promise.resolve();
  9673. for (var key in gStateMap) {
  9674. var value = gStateMap[key];
  9675. switch (key) {
  9676. case 'Type':
  9677. break;
  9678. case 'LW':
  9679. case 'LC':
  9680. case 'LJ':
  9681. case 'ML':
  9682. case 'D':
  9683. case 'RI':
  9684. case 'FL':
  9685. case 'CA':
  9686. case 'ca':
  9687. gStateObj.push([key, value]);
  9688. break;
  9689. case 'Font':
  9690. promise = promise.then(function () {
  9691. return self.handleSetFont(resources, null, value[0],
  9692. operatorList, stateManager.state).
  9693. then(function (loadedName) {
  9694. operatorList.addDependency(loadedName);
  9695. gStateObj.push([key, [loadedName, value[1]]]);
  9696. });
  9697. });
  9698. break;
  9699. case 'BM':
  9700. gStateObj.push([key, value]);
  9701. break;
  9702. case 'SMask':
  9703. if (isName(value) && value.name === 'None') {
  9704. gStateObj.push([key, false]);
  9705. break;
  9706. }
  9707. var dict = xref.fetchIfRef(value);
  9708. if (isDict(dict)) {
  9709. promise = promise.then(function () {
  9710. return self.handleSMask(dict, resources, operatorList,
  9711. stateManager);
  9712. });
  9713. gStateObj.push([key, true]);
  9714. } else {
  9715. warn('Unsupported SMask type');
  9716. }
  9717. break;
  9718. // Only generate info log messages for the following since
  9719. // they are unlikely to have a big impact on the rendering.
  9720. case 'OP':
  9721. case 'op':
  9722. case 'OPM':
  9723. case 'BG':
  9724. case 'BG2':
  9725. case 'UCR':
  9726. case 'UCR2':
  9727. case 'TR':
  9728. case 'TR2':
  9729. case 'HT':
  9730. case 'SM':
  9731. case 'SA':
  9732. case 'AIS':
  9733. case 'TK':
  9734. // TODO implement these operators.
  9735. info('graphic state operator ' + key);
  9736. break;
  9737. default:
  9738. info('Unknown graphic state operator ' + key);
  9739. break;
  9740. }
  9741. }
  9742. return promise.then(function () {
  9743. if (gStateObj.length >= 0) {
  9744. operatorList.addOp(OPS.setGState, [gStateObj]);
  9745. }
  9746. });
  9747. },
  9748. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9749. resources) {
  9750. function errorFont() {
  9751. return Promise.resolve(new TranslatedFont('g_font_error',
  9752. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9753. }
  9754. var fontRef;
  9755. if (font) { // Loading by ref.
  9756. assert(isRef(font));
  9757. fontRef = font;
  9758. } else { // Loading by name.
  9759. var fontRes = resources.get('Font');
  9760. if (fontRes) {
  9761. fontRef = fontRes.getRaw(fontName);
  9762. } else {
  9763. warn('fontRes not available');
  9764. return errorFont();
  9765. }
  9766. }
  9767. if (!fontRef) {
  9768. warn('fontRef not available');
  9769. return errorFont();
  9770. }
  9771. if (this.fontCache.has(fontRef)) {
  9772. return this.fontCache.get(fontRef);
  9773. }
  9774. font = xref.fetchIfRef(fontRef);
  9775. if (!isDict(font)) {
  9776. return errorFont();
  9777. }
  9778. // We are holding font.translated references just for fontRef that are not
  9779. // dictionaries (Dict). See explanation below.
  9780. if (font.translated) {
  9781. return font.translated;
  9782. }
  9783. var fontCapability = createPromiseCapability();
  9784. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9785. var descriptor = preEvaluatedFont.descriptor;
  9786. var fontID = fontRef.num + '_' + fontRef.gen;
  9787. if (isDict(descriptor)) {
  9788. if (!descriptor.fontAliases) {
  9789. descriptor.fontAliases = Object.create(null);
  9790. }
  9791. var fontAliases = descriptor.fontAliases;
  9792. var hash = preEvaluatedFont.hash;
  9793. if (fontAliases[hash]) {
  9794. var aliasFontRef = fontAliases[hash].aliasRef;
  9795. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9796. this.fontCache.putAlias(fontRef, aliasFontRef);
  9797. return this.fontCache.get(fontRef);
  9798. }
  9799. }
  9800. if (!fontAliases[hash]) {
  9801. fontAliases[hash] = {
  9802. fontID: Font.getFontID()
  9803. };
  9804. }
  9805. fontAliases[hash].aliasRef = fontRef;
  9806. fontID = fontAliases[hash].fontID;
  9807. }
  9808. // Workaround for bad PDF generators that don't reference fonts
  9809. // properly, i.e. by not using an object identifier.
  9810. // Check if the fontRef is a Dict (as opposed to a standard object),
  9811. // in which case we don't cache the font and instead reference it by
  9812. // fontName in font.loadedName below.
  9813. var fontRefIsDict = isDict(fontRef);
  9814. if (!fontRefIsDict) {
  9815. this.fontCache.put(fontRef, fontCapability.promise);
  9816. }
  9817. // Keep track of each font we translated so the caller can
  9818. // load them asynchronously before calling display on a page.
  9819. font.loadedName = 'g_font_' + (fontRefIsDict ?
  9820. fontName.replace(/\W/g, '') : fontID);
  9821. font.translated = fontCapability.promise;
  9822. // TODO move promises into translate font
  9823. var translatedPromise;
  9824. try {
  9825. translatedPromise = Promise.resolve(
  9826. this.translateFont(preEvaluatedFont, xref));
  9827. } catch (e) {
  9828. translatedPromise = Promise.reject(e);
  9829. }
  9830. translatedPromise.then(function (translatedFont) {
  9831. if (translatedFont.fontType !== undefined) {
  9832. var xrefFontStats = xref.stats.fontTypes;
  9833. xrefFontStats[translatedFont.fontType] = true;
  9834. }
  9835. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9836. translatedFont, font));
  9837. }, function (reason) {
  9838. // TODO fontCapability.reject?
  9839. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  9840. try {
  9841. // error, but it's still nice to have font type reported
  9842. var descriptor = preEvaluatedFont.descriptor;
  9843. var fontFile3 = descriptor && descriptor.get('FontFile3');
  9844. var subtype = fontFile3 && fontFile3.get('Subtype');
  9845. var fontType = getFontType(preEvaluatedFont.type,
  9846. subtype && subtype.name);
  9847. var xrefFontStats = xref.stats.fontTypes;
  9848. xrefFontStats[fontType] = true;
  9849. } catch (ex) { }
  9850. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9851. new ErrorFont(reason instanceof Error ? reason.message : reason),
  9852. font));
  9853. });
  9854. return fontCapability.promise;
  9855. },
  9856. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  9857. var lastIndex = operatorList.length - 1;
  9858. if (!args) {
  9859. args = [];
  9860. }
  9861. if (lastIndex < 0 ||
  9862. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  9863. operatorList.addOp(OPS.constructPath, [[fn], args]);
  9864. } else {
  9865. var opArgs = operatorList.argsArray[lastIndex];
  9866. opArgs[0].push(fn);
  9867. Array.prototype.push.apply(opArgs[1], args);
  9868. }
  9869. },
  9870. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  9871. cs, patterns, resources, xref) {
  9872. // compile tiling patterns
  9873. var patternName = args[args.length - 1];
  9874. // SCN/scn applies patterns along with normal colors
  9875. var pattern;
  9876. if (isName(patternName) &&
  9877. (pattern = patterns.get(patternName.name))) {
  9878. var dict = (isStream(pattern) ? pattern.dict : pattern);
  9879. var typeNum = dict.get('PatternType');
  9880. if (typeNum === TILING_PATTERN) {
  9881. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  9882. return this.handleTilingType(fn, color, resources, pattern,
  9883. dict, operatorList);
  9884. } else if (typeNum === SHADING_PATTERN) {
  9885. var shading = dict.get('Shading');
  9886. var matrix = dict.get('Matrix');
  9887. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  9888. operatorList.addOp(fn, pattern.getIR());
  9889. return Promise.resolve();
  9890. } else {
  9891. return Promise.reject('Unknown PatternType: ' + typeNum);
  9892. }
  9893. }
  9894. // TODO shall we fail here?
  9895. operatorList.addOp(fn, args);
  9896. return Promise.resolve();
  9897. },
  9898. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  9899. resources,
  9900. operatorList,
  9901. initialState) {
  9902. var self = this;
  9903. var xref = this.xref;
  9904. var imageCache = {};
  9905. assert(operatorList);
  9906. resources = (resources || Dict.empty);
  9907. var xobjs = (resources.get('XObject') || Dict.empty);
  9908. var patterns = (resources.get('Pattern') || Dict.empty);
  9909. var stateManager = new StateManager(initialState || new EvalState());
  9910. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9911. var timeSlotManager = new TimeSlotManager();
  9912. return new Promise(function next(resolve, reject) {
  9913. timeSlotManager.reset();
  9914. var stop, operation = {}, i, ii, cs;
  9915. while (!(stop = timeSlotManager.check())) {
  9916. // The arguments parsed by read() are used beyond this loop, so we
  9917. // cannot reuse the same array on each iteration. Therefore we pass
  9918. // in |null| as the initial value (see the comment on
  9919. // EvaluatorPreprocessor_read() for why).
  9920. operation.args = null;
  9921. if (!(preprocessor.read(operation))) {
  9922. break;
  9923. }
  9924. var args = operation.args;
  9925. var fn = operation.fn;
  9926. switch (fn | 0) {
  9927. case OPS.paintXObject:
  9928. if (args[0].code) {
  9929. break;
  9930. }
  9931. // eagerly compile XForm objects
  9932. var name = args[0].name;
  9933. if (imageCache.key === name) {
  9934. operatorList.addOp(imageCache.fn, imageCache.args);
  9935. args = null;
  9936. continue;
  9937. }
  9938. var xobj = xobjs.get(name);
  9939. if (xobj) {
  9940. assert(isStream(xobj), 'XObject should be a stream');
  9941. var type = xobj.dict.get('Subtype');
  9942. assert(isName(type),
  9943. 'XObject should have a Name subtype');
  9944. if (type.name === 'Form') {
  9945. stateManager.save();
  9946. return self.buildFormXObject(resources, xobj, null,
  9947. operatorList,
  9948. stateManager.state.clone()).
  9949. then(function () {
  9950. stateManager.restore();
  9951. next(resolve, reject);
  9952. }, reject);
  9953. } else if (type.name === 'Image') {
  9954. self.buildPaintImageXObject(resources, xobj, false,
  9955. operatorList, name, imageCache);
  9956. args = null;
  9957. continue;
  9958. } else if (type.name === 'PS') {
  9959. // PostScript XObjects are unused when viewing documents.
  9960. // See section 4.7.1 of Adobe's PDF reference.
  9961. info('Ignored XObject subtype PS');
  9962. continue;
  9963. } else {
  9964. error('Unhandled XObject subtype ' + type.name);
  9965. }
  9966. }
  9967. break;
  9968. case OPS.setFont:
  9969. var fontSize = args[1];
  9970. // eagerly collect all fonts
  9971. return self.handleSetFont(resources, args, null,
  9972. operatorList, stateManager.state).
  9973. then(function (loadedName) {
  9974. operatorList.addDependency(loadedName);
  9975. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  9976. next(resolve, reject);
  9977. }, reject);
  9978. case OPS.endInlineImage:
  9979. var cacheKey = args[0].cacheKey;
  9980. if (cacheKey && imageCache.key === cacheKey) {
  9981. operatorList.addOp(imageCache.fn, imageCache.args);
  9982. args = null;
  9983. continue;
  9984. }
  9985. self.buildPaintImageXObject(resources, args[0], true,
  9986. operatorList, cacheKey, imageCache);
  9987. args = null;
  9988. continue;
  9989. case OPS.showText:
  9990. args[0] = self.handleText(args[0], stateManager.state);
  9991. break;
  9992. case OPS.showSpacedText:
  9993. var arr = args[0];
  9994. var combinedGlyphs = [];
  9995. var arrLength = arr.length;
  9996. for (i = 0; i < arrLength; ++i) {
  9997. var arrItem = arr[i];
  9998. if (isString(arrItem)) {
  9999. Array.prototype.push.apply(combinedGlyphs,
  10000. self.handleText(arrItem, stateManager.state));
  10001. } else if (isNum(arrItem)) {
  10002. combinedGlyphs.push(arrItem);
  10003. }
  10004. }
  10005. args[0] = combinedGlyphs;
  10006. fn = OPS.showText;
  10007. break;
  10008. case OPS.nextLineShowText:
  10009. operatorList.addOp(OPS.nextLine);
  10010. args[0] = self.handleText(args[0], stateManager.state);
  10011. fn = OPS.showText;
  10012. break;
  10013. case OPS.nextLineSetSpacingShowText:
  10014. operatorList.addOp(OPS.nextLine);
  10015. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10016. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10017. args[0] = self.handleText(args[0], stateManager.state);
  10018. fn = OPS.showText;
  10019. break;
  10020. case OPS.setTextRenderingMode:
  10021. stateManager.state.textRenderingMode = args[0];
  10022. break;
  10023. case OPS.setFillColorSpace:
  10024. stateManager.state.fillColorSpace =
  10025. ColorSpace.parse(args[0], xref, resources);
  10026. continue;
  10027. case OPS.setStrokeColorSpace:
  10028. stateManager.state.strokeColorSpace =
  10029. ColorSpace.parse(args[0], xref, resources);
  10030. continue;
  10031. case OPS.setFillColor:
  10032. cs = stateManager.state.fillColorSpace;
  10033. args = cs.getRgb(args, 0);
  10034. fn = OPS.setFillRGBColor;
  10035. break;
  10036. case OPS.setStrokeColor:
  10037. cs = stateManager.state.strokeColorSpace;
  10038. args = cs.getRgb(args, 0);
  10039. fn = OPS.setStrokeRGBColor;
  10040. break;
  10041. case OPS.setFillGray:
  10042. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10043. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10044. fn = OPS.setFillRGBColor;
  10045. break;
  10046. case OPS.setStrokeGray:
  10047. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10048. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10049. fn = OPS.setStrokeRGBColor;
  10050. break;
  10051. case OPS.setFillCMYKColor:
  10052. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10053. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10054. fn = OPS.setFillRGBColor;
  10055. break;
  10056. case OPS.setStrokeCMYKColor:
  10057. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10058. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10059. fn = OPS.setStrokeRGBColor;
  10060. break;
  10061. case OPS.setFillRGBColor:
  10062. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10063. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10064. break;
  10065. case OPS.setStrokeRGBColor:
  10066. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10067. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10068. break;
  10069. case OPS.setFillColorN:
  10070. cs = stateManager.state.fillColorSpace;
  10071. if (cs.name === 'Pattern') {
  10072. return self.handleColorN(operatorList, OPS.setFillColorN,
  10073. args, cs, patterns, resources, xref).then(function() {
  10074. next(resolve, reject);
  10075. }, reject);
  10076. }
  10077. args = cs.getRgb(args, 0);
  10078. fn = OPS.setFillRGBColor;
  10079. break;
  10080. case OPS.setStrokeColorN:
  10081. cs = stateManager.state.strokeColorSpace;
  10082. if (cs.name === 'Pattern') {
  10083. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10084. args, cs, patterns, resources, xref).then(function() {
  10085. next(resolve, reject);
  10086. }, reject);
  10087. }
  10088. args = cs.getRgb(args, 0);
  10089. fn = OPS.setStrokeRGBColor;
  10090. break;
  10091. case OPS.shadingFill:
  10092. var shadingRes = resources.get('Shading');
  10093. if (!shadingRes) {
  10094. error('No shading resource found');
  10095. }
  10096. var shading = shadingRes.get(args[0].name);
  10097. if (!shading) {
  10098. error('No shading object found');
  10099. }
  10100. var shadingFill = Pattern.parseShading(shading, null, xref,
  10101. resources);
  10102. var patternIR = shadingFill.getIR();
  10103. args = [patternIR];
  10104. fn = OPS.shadingFill;
  10105. break;
  10106. case OPS.setGState:
  10107. var dictName = args[0];
  10108. var extGState = resources.get('ExtGState');
  10109. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10110. break;
  10111. }
  10112. var gState = extGState.get(dictName.name);
  10113. return self.setGState(resources, gState, operatorList, xref,
  10114. stateManager).then(function() {
  10115. next(resolve, reject);
  10116. }, reject);
  10117. case OPS.moveTo:
  10118. case OPS.lineTo:
  10119. case OPS.curveTo:
  10120. case OPS.curveTo2:
  10121. case OPS.curveTo3:
  10122. case OPS.closePath:
  10123. self.buildPath(operatorList, fn, args);
  10124. continue;
  10125. case OPS.rectangle:
  10126. self.buildPath(operatorList, fn, args);
  10127. continue;
  10128. }
  10129. operatorList.addOp(fn, args);
  10130. }
  10131. if (stop) {
  10132. deferred.then(function () {
  10133. next(resolve, reject);
  10134. });
  10135. return;
  10136. }
  10137. // Some PDFs don't close all restores inside object/form.
  10138. // Closing those for them.
  10139. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10140. operatorList.addOp(OPS.restore, []);
  10141. }
  10142. resolve();
  10143. });
  10144. },
  10145. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10146. stateManager) {
  10147. stateManager = (stateManager || new StateManager(new TextState()));
  10148. var textContent = {
  10149. items: [],
  10150. styles: Object.create(null)
  10151. };
  10152. var bidiTexts = textContent.items;
  10153. var SPACE_FACTOR = 0.35;
  10154. var MULTI_SPACE_FACTOR = 1.5;
  10155. var self = this;
  10156. var xref = this.xref;
  10157. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10158. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10159. var xobjs = null;
  10160. var xobjsCache = {};
  10161. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10162. var textState;
  10163. function newTextChunk() {
  10164. var font = textState.font;
  10165. if (!(font.loadedName in textContent.styles)) {
  10166. textContent.styles[font.loadedName] = {
  10167. fontFamily: font.fallbackName,
  10168. ascent: font.ascent,
  10169. descent: font.descent,
  10170. vertical: font.vertical
  10171. };
  10172. }
  10173. return {
  10174. // |str| is initially an array which we push individual chars to, and
  10175. // then runBidi() overwrites it with the final string.
  10176. str: [],
  10177. dir: null,
  10178. width: 0,
  10179. height: 0,
  10180. transform: null,
  10181. fontName: font.loadedName
  10182. };
  10183. }
  10184. function runBidi(textChunk) {
  10185. var str = textChunk.str.join('');
  10186. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10187. textChunk.str = bidiResult.str;
  10188. textChunk.dir = bidiResult.dir;
  10189. return textChunk;
  10190. }
  10191. function handleSetFont(fontName, fontRef) {
  10192. return self.loadFont(fontName, fontRef, xref, resources).
  10193. then(function (translated) {
  10194. textState.font = translated.font;
  10195. textState.fontMatrix = translated.font.fontMatrix ||
  10196. FONT_IDENTITY_MATRIX;
  10197. });
  10198. }
  10199. function buildTextGeometry(chars, textChunk) {
  10200. var font = textState.font;
  10201. textChunk = textChunk || newTextChunk();
  10202. if (!textChunk.transform) {
  10203. // 9.4.4 Text Space Details
  10204. var tsm = [textState.fontSize * textState.textHScale, 0,
  10205. 0, textState.fontSize,
  10206. 0, textState.textRise];
  10207. var trm = textChunk.transform = Util.transform(textState.ctm,
  10208. Util.transform(textState.textMatrix, tsm));
  10209. if (!font.vertical) {
  10210. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10211. } else {
  10212. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10213. }
  10214. }
  10215. var width = 0;
  10216. var height = 0;
  10217. var glyphs = font.charsToGlyphs(chars);
  10218. var defaultVMetrics = font.defaultVMetrics;
  10219. for (var i = 0; i < glyphs.length; i++) {
  10220. var glyph = glyphs[i];
  10221. if (!glyph) { // Previous glyph was a space.
  10222. width += textState.wordSpacing * textState.textHScale;
  10223. continue;
  10224. }
  10225. var vMetricX = null;
  10226. var vMetricY = null;
  10227. var glyphWidth = null;
  10228. if (font.vertical) {
  10229. if (glyph.vmetric) {
  10230. glyphWidth = glyph.vmetric[0];
  10231. vMetricX = glyph.vmetric[1];
  10232. vMetricY = glyph.vmetric[2];
  10233. } else {
  10234. glyphWidth = glyph.width;
  10235. vMetricX = glyph.width * 0.5;
  10236. vMetricY = defaultVMetrics[2];
  10237. }
  10238. } else {
  10239. glyphWidth = glyph.width;
  10240. }
  10241. var glyphUnicode = glyph.unicode;
  10242. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10243. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10244. }
  10245. glyphUnicode = reverseIfRtl(glyphUnicode);
  10246. // The following will calculate the x and y of the individual glyphs.
  10247. // if (font.vertical) {
  10248. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10249. // textState.fontMatrix[0];
  10250. // tsm[5] -= vMetricY * textState.fontSize *
  10251. // textState.fontMatrix[0];
  10252. // }
  10253. // var trm = Util.transform(textState.textMatrix, tsm);
  10254. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10255. // var x = pt[0];
  10256. // var y = pt[1];
  10257. var tx = 0;
  10258. var ty = 0;
  10259. if (!font.vertical) {
  10260. var w0 = glyphWidth * textState.fontMatrix[0];
  10261. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10262. textState.textHScale;
  10263. width += tx;
  10264. } else {
  10265. var w1 = glyphWidth * textState.fontMatrix[0];
  10266. ty = w1 * textState.fontSize + textState.charSpacing;
  10267. height += ty;
  10268. }
  10269. textState.translateTextMatrix(tx, ty);
  10270. textChunk.str.push(glyphUnicode);
  10271. }
  10272. var a = textState.textLineMatrix[0];
  10273. var b = textState.textLineMatrix[1];
  10274. var scaleLineX = Math.sqrt(a * a + b * b);
  10275. a = textState.ctm[0];
  10276. b = textState.ctm[1];
  10277. var scaleCtmX = Math.sqrt(a * a + b * b);
  10278. if (!font.vertical) {
  10279. textChunk.width += width * scaleCtmX * scaleLineX;
  10280. } else {
  10281. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10282. }
  10283. return textChunk;
  10284. }
  10285. var timeSlotManager = new TimeSlotManager();
  10286. return new Promise(function next(resolve, reject) {
  10287. timeSlotManager.reset();
  10288. var stop, operation = {}, args = [];
  10289. while (!(stop = timeSlotManager.check())) {
  10290. // The arguments parsed by read() are not used beyond this loop, so
  10291. // we can reuse the same array on every iteration, thus avoiding
  10292. // unnecessary allocations.
  10293. args.length = 0;
  10294. operation.args = args;
  10295. if (!(preprocessor.read(operation))) {
  10296. break;
  10297. }
  10298. textState = stateManager.state;
  10299. var fn = operation.fn;
  10300. args = operation.args;
  10301. switch (fn | 0) {
  10302. case OPS.setFont:
  10303. textState.fontSize = args[1];
  10304. return handleSetFont(args[0].name).then(function() {
  10305. next(resolve, reject);
  10306. }, reject);
  10307. case OPS.setTextRise:
  10308. textState.textRise = args[0];
  10309. break;
  10310. case OPS.setHScale:
  10311. textState.textHScale = args[0] / 100;
  10312. break;
  10313. case OPS.setLeading:
  10314. textState.leading = args[0];
  10315. break;
  10316. case OPS.moveText:
  10317. textState.translateTextLineMatrix(args[0], args[1]);
  10318. textState.textMatrix = textState.textLineMatrix.slice();
  10319. break;
  10320. case OPS.setLeadingMoveText:
  10321. textState.leading = -args[1];
  10322. textState.translateTextLineMatrix(args[0], args[1]);
  10323. textState.textMatrix = textState.textLineMatrix.slice();
  10324. break;
  10325. case OPS.nextLine:
  10326. textState.carriageReturn();
  10327. break;
  10328. case OPS.setTextMatrix:
  10329. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10330. args[4], args[5]);
  10331. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10332. args[4], args[5]);
  10333. break;
  10334. case OPS.setCharSpacing:
  10335. textState.charSpacing = args[0];
  10336. break;
  10337. case OPS.setWordSpacing:
  10338. textState.wordSpacing = args[0];
  10339. break;
  10340. case OPS.beginText:
  10341. textState.textMatrix = IDENTITY_MATRIX.slice();
  10342. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10343. break;
  10344. case OPS.showSpacedText:
  10345. var items = args[0];
  10346. var textChunk = newTextChunk();
  10347. var offset;
  10348. for (var j = 0, jj = items.length; j < jj; j++) {
  10349. if (typeof items[j] === 'string') {
  10350. buildTextGeometry(items[j], textChunk);
  10351. } else {
  10352. var val = items[j] / 1000;
  10353. if (!textState.font.vertical) {
  10354. offset = -val * textState.fontSize * textState.textHScale *
  10355. textState.textMatrix[0];
  10356. textState.translateTextMatrix(offset, 0);
  10357. textChunk.width += offset;
  10358. } else {
  10359. offset = -val * textState.fontSize *
  10360. textState.textMatrix[3];
  10361. textState.translateTextMatrix(0, offset);
  10362. textChunk.height += offset;
  10363. }
  10364. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10365. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10366. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10367. fakeSpaces = Math.round(fakeSpaces);
  10368. while (fakeSpaces--) {
  10369. textChunk.str.push(' ');
  10370. }
  10371. } else if (fakeSpaces > SPACE_FACTOR) {
  10372. textChunk.str.push(' ');
  10373. }
  10374. }
  10375. }
  10376. }
  10377. bidiTexts.push(runBidi(textChunk));
  10378. break;
  10379. case OPS.showText:
  10380. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10381. break;
  10382. case OPS.nextLineShowText:
  10383. textState.carriageReturn();
  10384. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10385. break;
  10386. case OPS.nextLineSetSpacingShowText:
  10387. textState.wordSpacing = args[0];
  10388. textState.charSpacing = args[1];
  10389. textState.carriageReturn();
  10390. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10391. break;
  10392. case OPS.paintXObject:
  10393. if (args[0].code) {
  10394. break;
  10395. }
  10396. if (!xobjs) {
  10397. xobjs = (resources.get('XObject') || Dict.empty);
  10398. }
  10399. var name = args[0].name;
  10400. if (xobjsCache.key === name) {
  10401. if (xobjsCache.texts) {
  10402. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10403. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10404. }
  10405. break;
  10406. }
  10407. var xobj = xobjs.get(name);
  10408. if (!xobj) {
  10409. break;
  10410. }
  10411. assert(isStream(xobj), 'XObject should be a stream');
  10412. var type = xobj.dict.get('Subtype');
  10413. assert(isName(type),
  10414. 'XObject should have a Name subtype');
  10415. if ('Form' !== type.name) {
  10416. xobjsCache.key = name;
  10417. xobjsCache.texts = null;
  10418. break;
  10419. }
  10420. stateManager.save();
  10421. var matrix = xobj.dict.get('Matrix');
  10422. if (isArray(matrix) && matrix.length === 6) {
  10423. stateManager.transform(matrix);
  10424. }
  10425. return self.getTextContent(xobj,
  10426. xobj.dict.get('Resources') || resources, stateManager).
  10427. then(function (formTextContent) {
  10428. Util.appendToArray(bidiTexts, formTextContent.items);
  10429. Util.extendObj(textContent.styles, formTextContent.styles);
  10430. stateManager.restore();
  10431. xobjsCache.key = name;
  10432. xobjsCache.texts = formTextContent;
  10433. next(resolve, reject);
  10434. }, reject);
  10435. case OPS.setGState:
  10436. var dictName = args[0];
  10437. var extGState = resources.get('ExtGState');
  10438. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10439. break;
  10440. }
  10441. var gsStateMap = extGState.get(dictName.name);
  10442. var gsStateFont = null;
  10443. for (var key in gsStateMap) {
  10444. if (key === 'Font') {
  10445. assert(!gsStateFont);
  10446. gsStateFont = gsStateMap[key];
  10447. }
  10448. }
  10449. if (gsStateFont) {
  10450. textState.fontSize = gsStateFont[1];
  10451. return handleSetFont(gsStateFont[0]).then(function() {
  10452. next(resolve, reject);
  10453. }, reject);
  10454. }
  10455. break;
  10456. } // switch
  10457. } // while
  10458. if (stop) {
  10459. deferred.then(function () {
  10460. next(resolve, reject);
  10461. });
  10462. return;
  10463. }
  10464. resolve(textContent);
  10465. });
  10466. },
  10467. extractDataStructures: function
  10468. partialEvaluatorExtractDataStructures(dict, baseDict,
  10469. xref, properties) {
  10470. // 9.10.2
  10471. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10472. if (toUnicode) {
  10473. properties.toUnicode = this.readToUnicode(toUnicode);
  10474. }
  10475. if (properties.composite) {
  10476. // CIDSystemInfo helps to match CID to glyphs
  10477. var cidSystemInfo = dict.get('CIDSystemInfo');
  10478. if (isDict(cidSystemInfo)) {
  10479. properties.cidSystemInfo = {
  10480. registry: cidSystemInfo.get('Registry'),
  10481. ordering: cidSystemInfo.get('Ordering'),
  10482. supplement: cidSystemInfo.get('Supplement')
  10483. };
  10484. }
  10485. var cidToGidMap = dict.get('CIDToGIDMap');
  10486. if (isStream(cidToGidMap)) {
  10487. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10488. }
  10489. }
  10490. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10491. // and depends on the font type. The base encoding and differences are
  10492. // read here, but the encoding that is actually used is chosen during
  10493. // glyph mapping in the font.
  10494. // TODO: Loading the built in encoding in the font would allow the
  10495. // differences to be merged in here not require us to hold on to it.
  10496. var differences = [];
  10497. var baseEncodingName = null;
  10498. var encoding;
  10499. if (dict.has('Encoding')) {
  10500. encoding = dict.get('Encoding');
  10501. if (isDict(encoding)) {
  10502. baseEncodingName = encoding.get('BaseEncoding');
  10503. baseEncodingName = (isName(baseEncodingName) ?
  10504. baseEncodingName.name : null);
  10505. // Load the differences between the base and original
  10506. if (encoding.has('Differences')) {
  10507. var diffEncoding = encoding.get('Differences');
  10508. var index = 0;
  10509. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10510. var data = diffEncoding[j];
  10511. if (isNum(data)) {
  10512. index = data;
  10513. } else {
  10514. differences[index++] = data.name;
  10515. }
  10516. }
  10517. }
  10518. } else if (isName(encoding)) {
  10519. baseEncodingName = encoding.name;
  10520. } else {
  10521. error('Encoding is not a Name nor a Dict');
  10522. }
  10523. // According to table 114 if the encoding is a named encoding it must be
  10524. // one of these predefined encodings.
  10525. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10526. baseEncodingName !== 'MacExpertEncoding' &&
  10527. baseEncodingName !== 'WinAnsiEncoding')) {
  10528. baseEncodingName = null;
  10529. }
  10530. }
  10531. if (baseEncodingName) {
  10532. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10533. } else {
  10534. encoding = (properties.type === 'TrueType' ?
  10535. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10536. // The Symbolic attribute can be misused for regular fonts
  10537. // Heuristic: we have to check if the font is a standard one also
  10538. if (!!(properties.flags & FontFlags.Symbolic)) {
  10539. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  10540. Encodings.SymbolSetEncoding :
  10541. Encodings.MacRomanEncoding);
  10542. }
  10543. properties.defaultEncoding = encoding;
  10544. }
  10545. properties.differences = differences;
  10546. properties.baseEncodingName = baseEncodingName;
  10547. properties.dict = dict;
  10548. },
  10549. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10550. var cmap, cmapObj = toUnicode;
  10551. if (isName(cmapObj)) {
  10552. cmap = CMapFactory.create(cmapObj,
  10553. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10554. return new ToUnicodeMap(cmap);
  10555. } else if (isStream(cmapObj)) {
  10556. cmap = CMapFactory.create(cmapObj,
  10557. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10558. // Convert UTF-16BE
  10559. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10560. // to iterate over all keys.
  10561. cmap.forEach(function(token, i) {
  10562. var str = [];
  10563. for (var k = 0; k < token.length; k += 2) {
  10564. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10565. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10566. str.push(w1);
  10567. continue;
  10568. }
  10569. k += 2;
  10570. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10571. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10572. }
  10573. cmap[i] = String.fromCharCode.apply(String, str);
  10574. });
  10575. return new ToUnicodeMap(cmap);
  10576. }
  10577. return null;
  10578. },
  10579. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10580. // Extract the encoding from the CIDToGIDMap
  10581. var glyphsData = cidToGidStream.getBytes();
  10582. // Set encoding 0 to later verify the font has an encoding
  10583. var result = [];
  10584. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10585. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10586. if (glyphID === 0) {
  10587. continue;
  10588. }
  10589. var code = j >> 1;
  10590. result[code] = glyphID;
  10591. }
  10592. return result;
  10593. },
  10594. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10595. descriptor,
  10596. properties) {
  10597. var glyphsWidths = [];
  10598. var defaultWidth = 0;
  10599. var glyphsVMetrics = [];
  10600. var defaultVMetrics;
  10601. var i, ii, j, jj, start, code, widths;
  10602. if (properties.composite) {
  10603. defaultWidth = dict.get('DW') || 1000;
  10604. widths = dict.get('W');
  10605. if (widths) {
  10606. for (i = 0, ii = widths.length; i < ii; i++) {
  10607. start = widths[i++];
  10608. code = xref.fetchIfRef(widths[i]);
  10609. if (isArray(code)) {
  10610. for (j = 0, jj = code.length; j < jj; j++) {
  10611. glyphsWidths[start++] = code[j];
  10612. }
  10613. } else {
  10614. var width = widths[++i];
  10615. for (j = start; j <= code; j++) {
  10616. glyphsWidths[j] = width;
  10617. }
  10618. }
  10619. }
  10620. }
  10621. if (properties.vertical) {
  10622. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10623. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10624. vmetrics = dict.get('W2');
  10625. if (vmetrics) {
  10626. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10627. start = vmetrics[i++];
  10628. code = xref.fetchIfRef(vmetrics[i]);
  10629. if (isArray(code)) {
  10630. for (j = 0, jj = code.length; j < jj; j++) {
  10631. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10632. }
  10633. } else {
  10634. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10635. for (j = start; j <= code; j++) {
  10636. glyphsVMetrics[j] = vmetric;
  10637. }
  10638. }
  10639. }
  10640. }
  10641. }
  10642. } else {
  10643. var firstChar = properties.firstChar;
  10644. widths = dict.get('Widths');
  10645. if (widths) {
  10646. j = firstChar;
  10647. for (i = 0, ii = widths.length; i < ii; i++) {
  10648. glyphsWidths[j++] = widths[i];
  10649. }
  10650. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10651. } else {
  10652. // Trying get the BaseFont metrics (see comment above).
  10653. var baseFontName = dict.get('BaseFont');
  10654. if (isName(baseFontName)) {
  10655. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10656. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10657. properties);
  10658. defaultWidth = metrics.defaultWidth;
  10659. }
  10660. }
  10661. }
  10662. // Heuristic: detection of monospace font by checking all non-zero widths
  10663. var isMonospace = true;
  10664. var firstWidth = defaultWidth;
  10665. for (var glyph in glyphsWidths) {
  10666. var glyphWidth = glyphsWidths[glyph];
  10667. if (!glyphWidth) {
  10668. continue;
  10669. }
  10670. if (!firstWidth) {
  10671. firstWidth = glyphWidth;
  10672. continue;
  10673. }
  10674. if (firstWidth !== glyphWidth) {
  10675. isMonospace = false;
  10676. break;
  10677. }
  10678. }
  10679. if (isMonospace) {
  10680. properties.flags |= FontFlags.FixedPitch;
  10681. }
  10682. properties.defaultWidth = defaultWidth;
  10683. properties.widths = glyphsWidths;
  10684. properties.defaultVMetrics = defaultVMetrics;
  10685. properties.vmetrics = glyphsVMetrics;
  10686. },
  10687. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10688. // Simulating descriptor flags attribute
  10689. var fontNameWoStyle = baseFontName.split('-')[0];
  10690. return (fontNameWoStyle in serifFonts) ||
  10691. (fontNameWoStyle.search(/serif/gi) !== -1);
  10692. },
  10693. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10694. var defaultWidth = 0;
  10695. var widths = [];
  10696. var monospace = false;
  10697. var lookupName = (stdFontMap[name] || name);
  10698. if (!(lookupName in Metrics)) {
  10699. // Use default fonts for looking up font metrics if the passed
  10700. // font is not a base font
  10701. if (this.isSerifFont(name)) {
  10702. lookupName = 'Times-Roman';
  10703. } else {
  10704. lookupName = 'Helvetica';
  10705. }
  10706. }
  10707. var glyphWidths = Metrics[lookupName];
  10708. if (isNum(glyphWidths)) {
  10709. defaultWidth = glyphWidths;
  10710. monospace = true;
  10711. } else {
  10712. widths = glyphWidths;
  10713. }
  10714. return {
  10715. defaultWidth: defaultWidth,
  10716. monospace: monospace,
  10717. widths: widths
  10718. };
  10719. },
  10720. buildCharCodeToWidth:
  10721. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10722. properties) {
  10723. var widths = Object.create(null);
  10724. var differences = properties.differences;
  10725. var encoding = properties.defaultEncoding;
  10726. for (var charCode = 0; charCode < 256; charCode++) {
  10727. if (charCode in differences &&
  10728. widthsByGlyphName[differences[charCode]]) {
  10729. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10730. continue;
  10731. }
  10732. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10733. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10734. continue;
  10735. }
  10736. }
  10737. return widths;
  10738. },
  10739. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10740. var baseDict = dict;
  10741. var type = dict.get('Subtype');
  10742. assert(isName(type), 'invalid font Subtype');
  10743. var composite = false;
  10744. var uint8array;
  10745. if (type.name === 'Type0') {
  10746. // If font is a composite
  10747. // - get the descendant font
  10748. // - set the type according to the descendant font
  10749. // - get the FontDescriptor from the descendant font
  10750. var df = dict.get('DescendantFonts');
  10751. if (!df) {
  10752. error('Descendant fonts are not specified');
  10753. }
  10754. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10755. type = dict.get('Subtype');
  10756. assert(isName(type), 'invalid font Subtype');
  10757. composite = true;
  10758. }
  10759. var descriptor = dict.get('FontDescriptor');
  10760. if (descriptor) {
  10761. var hash = new MurmurHash3_64();
  10762. var encoding = baseDict.getRaw('Encoding');
  10763. if (isName(encoding)) {
  10764. hash.update(encoding.name);
  10765. } else if (isRef(encoding)) {
  10766. hash.update(encoding.num + '_' + encoding.gen);
  10767. }
  10768. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10769. if (isStream(toUnicode)) {
  10770. var stream = toUnicode.str || toUnicode;
  10771. uint8array = stream.buffer ?
  10772. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10773. new Uint8Array(stream.bytes.buffer,
  10774. stream.start, stream.end - stream.start);
  10775. hash.update(uint8array);
  10776. } else if (isName(toUnicode)) {
  10777. hash.update(toUnicode.name);
  10778. }
  10779. var widths = dict.get('Widths') || baseDict.get('Widths');
  10780. if (widths) {
  10781. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10782. hash.update(uint8array);
  10783. }
  10784. }
  10785. return {
  10786. descriptor: descriptor,
  10787. dict: dict,
  10788. baseDict: baseDict,
  10789. composite: composite,
  10790. type: type.name,
  10791. hash: hash ? hash.hexdigest() : ''
  10792. };
  10793. },
  10794. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10795. xref) {
  10796. var baseDict = preEvaluatedFont.baseDict;
  10797. var dict = preEvaluatedFont.dict;
  10798. var composite = preEvaluatedFont.composite;
  10799. var descriptor = preEvaluatedFont.descriptor;
  10800. var type = preEvaluatedFont.type;
  10801. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10802. var properties;
  10803. if (!descriptor) {
  10804. if (type === 'Type3') {
  10805. // FontDescriptor is only required for Type3 fonts when the document
  10806. // is a tagged pdf. Create a barbebones one to get by.
  10807. descriptor = new Dict(null);
  10808. descriptor.set('FontName', Name.get(type));
  10809. } else {
  10810. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  10811. // FontDescriptor was not required.
  10812. // This case is here for compatibility.
  10813. var baseFontName = dict.get('BaseFont');
  10814. if (!isName(baseFontName)) {
  10815. error('Base font is not specified');
  10816. }
  10817. // Using base font name as a font name.
  10818. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  10819. var metrics = this.getBaseFontMetrics(baseFontName);
  10820. // Simulating descriptor flags attribute
  10821. var fontNameWoStyle = baseFontName.split('-')[0];
  10822. var flags =
  10823. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  10824. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  10825. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  10826. FontFlags.Nonsymbolic);
  10827. properties = {
  10828. type: type,
  10829. name: baseFontName,
  10830. widths: metrics.widths,
  10831. defaultWidth: metrics.defaultWidth,
  10832. flags: flags,
  10833. firstChar: 0,
  10834. lastChar: maxCharIndex
  10835. };
  10836. this.extractDataStructures(dict, dict, xref, properties);
  10837. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  10838. properties);
  10839. return new Font(baseFontName, null, properties);
  10840. }
  10841. }
  10842. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  10843. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  10844. // to ignore this rule when a variant of a standart font is used.
  10845. // TODO Fill the width array depending on which of the base font this is
  10846. // a variant.
  10847. var firstChar = (dict.get('FirstChar') || 0);
  10848. var lastChar = (dict.get('LastChar') || maxCharIndex);
  10849. var fontName = descriptor.get('FontName');
  10850. var baseFont = dict.get('BaseFont');
  10851. // Some bad PDFs have a string as the font name.
  10852. if (isString(fontName)) {
  10853. fontName = Name.get(fontName);
  10854. }
  10855. if (isString(baseFont)) {
  10856. baseFont = Name.get(baseFont);
  10857. }
  10858. if (type !== 'Type3') {
  10859. var fontNameStr = fontName && fontName.name;
  10860. var baseFontStr = baseFont && baseFont.name;
  10861. if (fontNameStr !== baseFontStr) {
  10862. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  10863. '" but should be the same as the Font\'s BaseFont "' +
  10864. baseFontStr + '"');
  10865. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  10866. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  10867. if (fontNameStr && baseFontStr &&
  10868. baseFontStr.indexOf(fontNameStr) === 0) {
  10869. fontName = baseFont;
  10870. }
  10871. }
  10872. }
  10873. fontName = (fontName || baseFont);
  10874. assert(isName(fontName), 'invalid font name');
  10875. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  10876. if (fontFile) {
  10877. if (fontFile.dict) {
  10878. var subtype = fontFile.dict.get('Subtype');
  10879. if (subtype) {
  10880. subtype = subtype.name;
  10881. }
  10882. var length1 = fontFile.dict.get('Length1');
  10883. var length2 = fontFile.dict.get('Length2');
  10884. }
  10885. }
  10886. properties = {
  10887. type: type,
  10888. name: fontName.name,
  10889. subtype: subtype,
  10890. file: fontFile,
  10891. length1: length1,
  10892. length2: length2,
  10893. loadedName: baseDict.loadedName,
  10894. composite: composite,
  10895. wideChars: composite,
  10896. fixedPitch: false,
  10897. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  10898. firstChar: firstChar || 0,
  10899. lastChar: (lastChar || maxCharIndex),
  10900. bbox: descriptor.get('FontBBox'),
  10901. ascent: descriptor.get('Ascent'),
  10902. descent: descriptor.get('Descent'),
  10903. xHeight: descriptor.get('XHeight'),
  10904. capHeight: descriptor.get('CapHeight'),
  10905. flags: descriptor.get('Flags'),
  10906. italicAngle: descriptor.get('ItalicAngle'),
  10907. coded: false
  10908. };
  10909. if (composite) {
  10910. var cidEncoding = baseDict.get('Encoding');
  10911. if (isName(cidEncoding)) {
  10912. properties.cidEncoding = cidEncoding.name;
  10913. }
  10914. properties.cMap = CMapFactory.create(cidEncoding,
  10915. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10916. properties.vertical = properties.cMap.vertical;
  10917. }
  10918. this.extractDataStructures(dict, baseDict, xref, properties);
  10919. this.extractWidths(dict, xref, descriptor, properties);
  10920. if (type === 'Type3') {
  10921. properties.isType3Font = true;
  10922. }
  10923. return new Font(fontName.name, fontFile, properties);
  10924. }
  10925. };
  10926. return PartialEvaluator;
  10927. })();
  10928. var TranslatedFont = (function TranslatedFontClosure() {
  10929. function TranslatedFont(loadedName, font, dict) {
  10930. this.loadedName = loadedName;
  10931. this.font = font;
  10932. this.dict = dict;
  10933. this.type3Loaded = null;
  10934. this.sent = false;
  10935. }
  10936. TranslatedFont.prototype = {
  10937. send: function (handler) {
  10938. if (this.sent) {
  10939. return;
  10940. }
  10941. var fontData = this.font.exportData();
  10942. handler.send('commonobj', [
  10943. this.loadedName,
  10944. 'Font',
  10945. fontData
  10946. ]);
  10947. this.sent = true;
  10948. },
  10949. loadType3Data: function (evaluator, resources, parentOperatorList) {
  10950. assert(this.font.isType3Font);
  10951. if (this.type3Loaded) {
  10952. return this.type3Loaded;
  10953. }
  10954. var translatedFont = this.font;
  10955. var loadCharProcsPromise = Promise.resolve();
  10956. var charProcs = this.dict.get('CharProcs').getAll();
  10957. var fontResources = this.dict.get('Resources') || resources;
  10958. var charProcKeys = Object.keys(charProcs);
  10959. var charProcOperatorList = {};
  10960. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  10961. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  10962. var glyphStream = charProcs[key];
  10963. var operatorList = new OperatorList();
  10964. return evaluator.getOperatorList(glyphStream, fontResources,
  10965. operatorList).then(function () {
  10966. charProcOperatorList[key] = operatorList.getIR();
  10967. // Add the dependencies to the parent operator list so they are
  10968. // resolved before sub operator list is executed synchronously.
  10969. parentOperatorList.addDependencies(operatorList.dependencies);
  10970. }, function (reason) {
  10971. warn('Type3 font resource \"' + key + '\" is not available');
  10972. var operatorList = new OperatorList();
  10973. charProcOperatorList[key] = operatorList.getIR();
  10974. });
  10975. }.bind(this, charProcKeys[i]));
  10976. }
  10977. this.type3Loaded = loadCharProcsPromise.then(function () {
  10978. translatedFont.charProcOperatorList = charProcOperatorList;
  10979. });
  10980. return this.type3Loaded;
  10981. }
  10982. };
  10983. return TranslatedFont;
  10984. })();
  10985. var OperatorList = (function OperatorListClosure() {
  10986. var CHUNK_SIZE = 1000;
  10987. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  10988. function getTransfers(queue) {
  10989. var transfers = [];
  10990. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  10991. for (var i = 0, ii = queue.length; i < ii; i++) {
  10992. switch (fnArray[i]) {
  10993. case OPS.paintInlineImageXObject:
  10994. case OPS.paintInlineImageXObjectGroup:
  10995. case OPS.paintImageMaskXObject:
  10996. var arg = argsArray[i][0]; // first param in imgData
  10997. if (!arg.cached) {
  10998. transfers.push(arg.data.buffer);
  10999. }
  11000. break;
  11001. }
  11002. }
  11003. return transfers;
  11004. }
  11005. function OperatorList(intent, messageHandler, pageIndex) {
  11006. this.messageHandler = messageHandler;
  11007. this.fnArray = [];
  11008. this.argsArray = [];
  11009. this.dependencies = {};
  11010. this.pageIndex = pageIndex;
  11011. this.intent = intent;
  11012. }
  11013. OperatorList.prototype = {
  11014. get length() {
  11015. return this.argsArray.length;
  11016. },
  11017. addOp: function(fn, args) {
  11018. this.fnArray.push(fn);
  11019. this.argsArray.push(args);
  11020. if (this.messageHandler) {
  11021. if (this.fnArray.length >= CHUNK_SIZE) {
  11022. this.flush();
  11023. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11024. (fn === OPS.restore || fn === OPS.endText)) {
  11025. // heuristic to flush on boundary of restore or endText
  11026. this.flush();
  11027. }
  11028. }
  11029. },
  11030. addDependency: function(dependency) {
  11031. if (dependency in this.dependencies) {
  11032. return;
  11033. }
  11034. this.dependencies[dependency] = true;
  11035. this.addOp(OPS.dependency, [dependency]);
  11036. },
  11037. addDependencies: function(dependencies) {
  11038. for (var key in dependencies) {
  11039. this.addDependency(key);
  11040. }
  11041. },
  11042. addOpList: function(opList) {
  11043. Util.extendObj(this.dependencies, opList.dependencies);
  11044. for (var i = 0, ii = opList.length; i < ii; i++) {
  11045. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11046. }
  11047. },
  11048. getIR: function() {
  11049. return {
  11050. fnArray: this.fnArray,
  11051. argsArray: this.argsArray,
  11052. length: this.length
  11053. };
  11054. },
  11055. flush: function(lastChunk) {
  11056. if (this.intent !== 'oplist') {
  11057. new QueueOptimizer().optimize(this);
  11058. }
  11059. var transfers = getTransfers(this);
  11060. this.messageHandler.send('RenderPageChunk', {
  11061. operatorList: {
  11062. fnArray: this.fnArray,
  11063. argsArray: this.argsArray,
  11064. lastChunk: lastChunk,
  11065. length: this.length
  11066. },
  11067. pageIndex: this.pageIndex,
  11068. intent: this.intent
  11069. }, transfers);
  11070. this.dependencies = {};
  11071. this.fnArray.length = 0;
  11072. this.argsArray.length = 0;
  11073. }
  11074. };
  11075. return OperatorList;
  11076. })();
  11077. var StateManager = (function StateManagerClosure() {
  11078. function StateManager(initialState) {
  11079. this.state = initialState;
  11080. this.stateStack = [];
  11081. }
  11082. StateManager.prototype = {
  11083. save: function () {
  11084. var old = this.state;
  11085. this.stateStack.push(this.state);
  11086. this.state = old.clone();
  11087. },
  11088. restore: function () {
  11089. var prev = this.stateStack.pop();
  11090. if (prev) {
  11091. this.state = prev;
  11092. }
  11093. },
  11094. transform: function (args) {
  11095. this.state.ctm = Util.transform(this.state.ctm, args);
  11096. }
  11097. };
  11098. return StateManager;
  11099. })();
  11100. var TextState = (function TextStateClosure() {
  11101. function TextState() {
  11102. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11103. this.fontSize = 0;
  11104. this.font = null;
  11105. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11106. this.textMatrix = IDENTITY_MATRIX.slice();
  11107. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11108. this.charSpacing = 0;
  11109. this.wordSpacing = 0;
  11110. this.leading = 0;
  11111. this.textHScale = 1;
  11112. this.textRise = 0;
  11113. }
  11114. TextState.prototype = {
  11115. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11116. var m = this.textMatrix;
  11117. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11118. },
  11119. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11120. var m = this.textLineMatrix;
  11121. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11122. },
  11123. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11124. var m = this.textMatrix;
  11125. m[4] = m[0] * x + m[2] * y + m[4];
  11126. m[5] = m[1] * x + m[3] * y + m[5];
  11127. },
  11128. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11129. var m = this.textLineMatrix;
  11130. m[4] = m[0] * x + m[2] * y + m[4];
  11131. m[5] = m[1] * x + m[3] * y + m[5];
  11132. },
  11133. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11134. // 9.4.4 Text Space Details
  11135. var tsm = [this.fontSize * this.textHScale, 0,
  11136. 0, this.fontSize,
  11137. 0, this.textRise];
  11138. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11139. },
  11140. carriageReturn: function TextState_carriageReturn() {
  11141. this.translateTextLineMatrix(0, -this.leading);
  11142. this.textMatrix = this.textLineMatrix.slice();
  11143. },
  11144. clone: function TextState_clone() {
  11145. var clone = Object.create(this);
  11146. clone.textMatrix = this.textMatrix.slice();
  11147. clone.textLineMatrix = this.textLineMatrix.slice();
  11148. clone.fontMatrix = this.fontMatrix.slice();
  11149. return clone;
  11150. }
  11151. };
  11152. return TextState;
  11153. })();
  11154. var EvalState = (function EvalStateClosure() {
  11155. function EvalState() {
  11156. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11157. this.font = null;
  11158. this.textRenderingMode = TextRenderingMode.FILL;
  11159. this.fillColorSpace = ColorSpace.singletons.gray;
  11160. this.strokeColorSpace = ColorSpace.singletons.gray;
  11161. }
  11162. EvalState.prototype = {
  11163. clone: function CanvasExtraState_clone() {
  11164. return Object.create(this);
  11165. },
  11166. };
  11167. return EvalState;
  11168. })();
  11169. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11170. // Specifies properties for each command
  11171. //
  11172. // If variableArgs === true: [0, `numArgs`] expected
  11173. // If variableArgs === false: exactly `numArgs` expected
  11174. var OP_MAP = {
  11175. // Graphic state
  11176. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11177. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11178. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11179. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11180. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11181. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11182. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11183. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11184. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11185. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11186. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11187. // Path
  11188. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11189. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11190. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11191. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11192. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11193. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11194. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11195. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11196. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11197. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11198. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11199. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11200. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11201. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11202. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11203. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11204. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11205. // Clipping
  11206. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11207. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11208. // Text
  11209. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11210. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11211. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11212. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11213. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11214. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11215. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11216. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11217. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11218. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11219. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11220. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11221. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11222. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11223. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11224. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11225. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11226. variableArgs: false },
  11227. // Type3 fonts
  11228. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11229. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11230. // Color
  11231. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11232. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11233. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11234. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11235. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11236. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11237. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11238. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11239. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11240. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11241. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11242. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11243. // Shading
  11244. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11245. // Images
  11246. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11247. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11248. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11249. // XObjects
  11250. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11251. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11252. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11253. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11254. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11255. variableArgs: false },
  11256. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11257. // Compatibility
  11258. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11259. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11260. // (reserved partial commands for the lexer)
  11261. BM: null,
  11262. BD: null,
  11263. 'true': null,
  11264. fa: null,
  11265. fal: null,
  11266. fals: null,
  11267. 'false': null,
  11268. nu: null,
  11269. nul: null,
  11270. 'null': null
  11271. };
  11272. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11273. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11274. // dictionary
  11275. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11276. this.stateManager = stateManager;
  11277. this.nonProcessedArgs = [];
  11278. }
  11279. EvaluatorPreprocessor.prototype = {
  11280. get savedStatesDepth() {
  11281. return this.stateManager.stateStack.length;
  11282. },
  11283. // |operation| is an object with two fields:
  11284. //
  11285. // - |fn| is an out param.
  11286. //
  11287. // - |args| is an inout param. On entry, it should have one of two values.
  11288. //
  11289. // - An empty array. This indicates that the caller is providing the
  11290. // array in which the args will be stored in. The caller should use
  11291. // this value if it can reuse a single array for each call to read().
  11292. //
  11293. // - |null|. This indicates that the caller needs this function to create
  11294. // the array in which any args are stored in. If there are zero args,
  11295. // this function will leave |operation.args| as |null| (thus avoiding
  11296. // allocations that would occur if we used an empty array to represent
  11297. // zero arguments). Otherwise, it will replace |null| with a new array
  11298. // containing the arguments. The caller should use this value if it
  11299. // cannot reuse an array for each call to read().
  11300. //
  11301. // These two modes are present because this function is very hot and so
  11302. // avoiding allocations where possible is worthwhile.
  11303. //
  11304. read: function EvaluatorPreprocessor_read(operation) {
  11305. var args = operation.args;
  11306. while (true) {
  11307. var obj = this.parser.getObj();
  11308. if (isCmd(obj)) {
  11309. var cmd = obj.cmd;
  11310. // Check that the command is valid
  11311. var opSpec = OP_MAP[cmd];
  11312. if (!opSpec) {
  11313. warn('Unknown command "' + cmd + '"');
  11314. continue;
  11315. }
  11316. var fn = opSpec.id;
  11317. var numArgs = opSpec.numArgs;
  11318. var argsLength = args !== null ? args.length : 0;
  11319. if (!opSpec.variableArgs) {
  11320. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11321. if (argsLength !== numArgs) {
  11322. var nonProcessedArgs = this.nonProcessedArgs;
  11323. while (argsLength > numArgs) {
  11324. nonProcessedArgs.push(args.shift());
  11325. argsLength--;
  11326. }
  11327. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11328. if (!args) {
  11329. args = [];
  11330. }
  11331. args.unshift(nonProcessedArgs.pop());
  11332. argsLength++;
  11333. }
  11334. }
  11335. if (argsLength < numArgs) {
  11336. // If we receive too few args, it's not possible to possible
  11337. // to execute the command, so skip the command
  11338. info('Command ' + fn + ': because expected ' +
  11339. numArgs + ' args, but received ' + argsLength +
  11340. ' args; skipping');
  11341. args = null;
  11342. continue;
  11343. }
  11344. } else if (argsLength > numArgs) {
  11345. info('Command ' + fn + ': expected [0,' + numArgs +
  11346. '] args, but received ' + argsLength + ' args');
  11347. }
  11348. // TODO figure out how to type-check vararg functions
  11349. this.preprocessCommand(fn, args);
  11350. operation.fn = fn;
  11351. operation.args = args;
  11352. return true;
  11353. } else {
  11354. if (isEOF(obj)) {
  11355. return false; // no more commands
  11356. }
  11357. // argument
  11358. if (obj !== null) {
  11359. if (!args) {
  11360. args = [];
  11361. }
  11362. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11363. assert(args.length <= 33, 'Too many arguments');
  11364. }
  11365. }
  11366. }
  11367. },
  11368. preprocessCommand:
  11369. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11370. switch (fn | 0) {
  11371. case OPS.save:
  11372. this.stateManager.save();
  11373. break;
  11374. case OPS.restore:
  11375. this.stateManager.restore();
  11376. break;
  11377. case OPS.transform:
  11378. this.stateManager.transform(args);
  11379. break;
  11380. }
  11381. }
  11382. };
  11383. return EvaluatorPreprocessor;
  11384. })();
  11385. var QueueOptimizer = (function QueueOptimizerClosure() {
  11386. function addState(parentState, pattern, fn) {
  11387. var state = parentState;
  11388. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11389. var item = pattern[i];
  11390. state = (state[item] || (state[item] = []));
  11391. }
  11392. state[pattern[pattern.length - 1]] = fn;
  11393. }
  11394. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11395. argsArray) {
  11396. // Handles special case of mainly LaTeX documents which use image masks to
  11397. // draw lines with the current fill style.
  11398. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11399. // have been found at iFirstSave.
  11400. var iFirstPIMXO = iFirstSave + 2;
  11401. for (var i = 0; i < count; i++) {
  11402. var arg = argsArray[iFirstPIMXO + 4 * i];
  11403. var imageMask = arg.length === 1 && arg[0];
  11404. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11405. (!imageMask.data.length ||
  11406. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11407. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11408. continue;
  11409. }
  11410. break;
  11411. }
  11412. return count - i;
  11413. }
  11414. var InitialState = [];
  11415. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11416. // sequences with one |paintInlineImageXObjectGroup| operation.
  11417. addState(InitialState,
  11418. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11419. function foundInlineImageGroup(context) {
  11420. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11421. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11422. var MAX_WIDTH = 1000;
  11423. var IMAGE_PADDING = 1;
  11424. var fnArray = context.fnArray, argsArray = context.argsArray;
  11425. var curr = context.iCurr;
  11426. var iFirstSave = curr - 3;
  11427. var iFirstTransform = curr - 2;
  11428. var iFirstPIIXO = curr - 1;
  11429. // Look for the quartets.
  11430. var i = iFirstSave + 4;
  11431. var ii = fnArray.length;
  11432. while (i + 3 < ii) {
  11433. if (fnArray[i] !== OPS.save ||
  11434. fnArray[i + 1] !== OPS.transform ||
  11435. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11436. fnArray[i + 3] !== OPS.restore) {
  11437. break; // ops don't match
  11438. }
  11439. i += 4;
  11440. }
  11441. // At this point, i is the index of the first op past the last valid
  11442. // quartet.
  11443. var count = Math.min((i - iFirstSave) / 4,
  11444. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11445. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11446. return i;
  11447. }
  11448. // assuming that heights of those image is too small (~1 pixel)
  11449. // packing as much as possible by lines
  11450. var maxX = 0;
  11451. var map = [], maxLineHeight = 0;
  11452. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11453. var q;
  11454. for (q = 0; q < count; q++) {
  11455. var transform = argsArray[iFirstTransform + (q << 2)];
  11456. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11457. if (currentX + img.width > MAX_WIDTH) {
  11458. // starting new line
  11459. maxX = Math.max(maxX, currentX);
  11460. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11461. currentX = 0;
  11462. maxLineHeight = 0;
  11463. }
  11464. map.push({
  11465. transform: transform,
  11466. x: currentX, y: currentY,
  11467. w: img.width, h: img.height
  11468. });
  11469. currentX += img.width + 2 * IMAGE_PADDING;
  11470. maxLineHeight = Math.max(maxLineHeight, img.height);
  11471. }
  11472. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11473. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11474. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11475. var imgRowSize = imgWidth << 2;
  11476. for (q = 0; q < count; q++) {
  11477. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11478. // Copy image by lines and extends pixels into padding.
  11479. var rowSize = map[q].w << 2;
  11480. var dataOffset = 0;
  11481. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11482. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11483. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11484. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11485. dataOffset += rowSize;
  11486. offset += imgRowSize;
  11487. }
  11488. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11489. while (offset >= 0) {
  11490. data[offset - 4] = data[offset];
  11491. data[offset - 3] = data[offset + 1];
  11492. data[offset - 2] = data[offset + 2];
  11493. data[offset - 1] = data[offset + 3];
  11494. data[offset + rowSize] = data[offset + rowSize - 4];
  11495. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11496. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11497. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11498. offset -= imgRowSize;
  11499. }
  11500. }
  11501. // Replace queue items.
  11502. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11503. argsArray.splice(iFirstSave, count * 4,
  11504. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11505. data: imgData }, map]);
  11506. return iFirstSave + 1;
  11507. });
  11508. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11509. // sequences with one |paintImageMaskXObjectGroup| or one
  11510. // |paintImageMaskXObjectRepeat| operation.
  11511. addState(InitialState,
  11512. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11513. function foundImageMaskGroup(context) {
  11514. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11515. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11516. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11517. var fnArray = context.fnArray, argsArray = context.argsArray;
  11518. var curr = context.iCurr;
  11519. var iFirstSave = curr - 3;
  11520. var iFirstTransform = curr - 2;
  11521. var iFirstPIMXO = curr - 1;
  11522. // Look for the quartets.
  11523. var i = iFirstSave + 4;
  11524. var ii = fnArray.length;
  11525. while (i + 3 < ii) {
  11526. if (fnArray[i] !== OPS.save ||
  11527. fnArray[i + 1] !== OPS.transform ||
  11528. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11529. fnArray[i + 3] !== OPS.restore) {
  11530. break; // ops don't match
  11531. }
  11532. i += 4;
  11533. }
  11534. // At this point, i is the index of the first op past the last valid
  11535. // quartet.
  11536. var count = (i - iFirstSave) / 4;
  11537. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11538. argsArray);
  11539. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11540. return i;
  11541. }
  11542. var q;
  11543. var isSameImage = false;
  11544. var iTransform, transformArgs;
  11545. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11546. if (argsArray[iFirstTransform][1] === 0 &&
  11547. argsArray[iFirstTransform][2] === 0) {
  11548. isSameImage = true;
  11549. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11550. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11551. iTransform = iFirstTransform + 4;
  11552. var iPIMXO = iFirstPIMXO + 4;
  11553. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11554. transformArgs = argsArray[iTransform];
  11555. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11556. transformArgs[0] !== firstTransformArg0 ||
  11557. transformArgs[1] !== 0 ||
  11558. transformArgs[2] !== 0 ||
  11559. transformArgs[3] !== firstTransformArg3) {
  11560. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11561. isSameImage = false;
  11562. } else {
  11563. count = q;
  11564. }
  11565. break; // different image or transform
  11566. }
  11567. }
  11568. }
  11569. if (isSameImage) {
  11570. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11571. var positions = new Float32Array(count * 2);
  11572. iTransform = iFirstTransform;
  11573. for (q = 0; q < count; q++, iTransform += 4) {
  11574. transformArgs = argsArray[iTransform];
  11575. positions[(q << 1)] = transformArgs[4];
  11576. positions[(q << 1) + 1] = transformArgs[5];
  11577. }
  11578. // Replace queue items.
  11579. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11580. argsArray.splice(iFirstSave, count * 4,
  11581. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11582. } else {
  11583. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11584. var images = [];
  11585. for (q = 0; q < count; q++) {
  11586. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11587. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11588. images.push({ data: maskParams.data, width: maskParams.width,
  11589. height: maskParams.height,
  11590. transform: transformArgs });
  11591. }
  11592. // Replace queue items.
  11593. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11594. argsArray.splice(iFirstSave, count * 4, [images]);
  11595. }
  11596. return iFirstSave + 1;
  11597. });
  11598. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11599. // with one paintImageXObjectRepeat operation, if the |transform| and
  11600. // |paintImageXObjectRepeat| ops are appropriate.
  11601. addState(InitialState,
  11602. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11603. function (context) {
  11604. var MIN_IMAGES_IN_BLOCK = 3;
  11605. var MAX_IMAGES_IN_BLOCK = 1000;
  11606. var fnArray = context.fnArray, argsArray = context.argsArray;
  11607. var curr = context.iCurr;
  11608. var iFirstSave = curr - 3;
  11609. var iFirstTransform = curr - 2;
  11610. var iFirstPIXO = curr - 1;
  11611. var iFirstRestore = curr;
  11612. if (argsArray[iFirstTransform][1] !== 0 ||
  11613. argsArray[iFirstTransform][2] !== 0) {
  11614. return iFirstRestore + 1; // transform has the wrong form
  11615. }
  11616. // Look for the quartets.
  11617. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11618. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11619. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11620. var i = iFirstSave + 4;
  11621. var ii = fnArray.length;
  11622. while (i + 3 < ii) {
  11623. if (fnArray[i] !== OPS.save ||
  11624. fnArray[i + 1] !== OPS.transform ||
  11625. fnArray[i + 2] !== OPS.paintImageXObject ||
  11626. fnArray[i + 3] !== OPS.restore) {
  11627. break; // ops don't match
  11628. }
  11629. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11630. argsArray[i + 1][1] !== 0 ||
  11631. argsArray[i + 1][2] !== 0 ||
  11632. argsArray[i + 1][3] !== firstTransformArg3) {
  11633. break; // transforms don't match
  11634. }
  11635. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11636. break; // images don't match
  11637. }
  11638. i += 4;
  11639. }
  11640. // At this point, i is the index of the first op past the last valid
  11641. // quartet.
  11642. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11643. if (count < MIN_IMAGES_IN_BLOCK) {
  11644. return i;
  11645. }
  11646. // Extract the (x,y) positions from all of the matching transforms.
  11647. var positions = new Float32Array(count * 2);
  11648. var iTransform = iFirstTransform;
  11649. for (var q = 0; q < count; q++, iTransform += 4) {
  11650. var transformArgs = argsArray[iTransform];
  11651. positions[(q << 1)] = transformArgs[4];
  11652. positions[(q << 1) + 1] = transformArgs[5];
  11653. }
  11654. // Replace queue items.
  11655. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11656. positions];
  11657. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11658. argsArray.splice(iFirstSave, count * 4, args);
  11659. return iFirstSave + 1;
  11660. });
  11661. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11662. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11663. // sequences, if the font for each one is the same.
  11664. addState(InitialState,
  11665. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11666. function (context) {
  11667. var MIN_CHARS_IN_BLOCK = 3;
  11668. var MAX_CHARS_IN_BLOCK = 1000;
  11669. var fnArray = context.fnArray, argsArray = context.argsArray;
  11670. var curr = context.iCurr;
  11671. var iFirstBeginText = curr - 4;
  11672. var iFirstSetFont = curr - 3;
  11673. var iFirstSetTextMatrix = curr - 2;
  11674. var iFirstShowText = curr - 1;
  11675. var iFirstEndText = curr;
  11676. // Look for the quintets.
  11677. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11678. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11679. var i = iFirstBeginText + 5;
  11680. var ii = fnArray.length;
  11681. while (i + 4 < ii) {
  11682. if (fnArray[i] !== OPS.beginText ||
  11683. fnArray[i + 1] !== OPS.setFont ||
  11684. fnArray[i + 2] !== OPS.setTextMatrix ||
  11685. fnArray[i + 3] !== OPS.showText ||
  11686. fnArray[i + 4] !== OPS.endText) {
  11687. break; // ops don't match
  11688. }
  11689. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11690. argsArray[i + 1][1] !== firstSetFontArg1) {
  11691. break; // fonts don't match
  11692. }
  11693. i += 5;
  11694. }
  11695. // At this point, i is the index of the first op past the last valid
  11696. // quintet.
  11697. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11698. if (count < MIN_CHARS_IN_BLOCK) {
  11699. return i;
  11700. }
  11701. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11702. // showText, endText), include that as well. (E.g. <something> might be
  11703. // |dependency|.)
  11704. var iFirst = iFirstBeginText;
  11705. if (iFirstBeginText >= 4 &&
  11706. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11707. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11708. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11709. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11710. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11711. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11712. count++;
  11713. iFirst -= 5;
  11714. }
  11715. // Remove (endText, beginText, setFont) trios.
  11716. var iEndText = iFirst + 4;
  11717. for (var q = 1; q < count; q++) {
  11718. fnArray.splice(iEndText, 3);
  11719. argsArray.splice(iEndText, 3);
  11720. iEndText += 2;
  11721. }
  11722. return iEndText + 1;
  11723. });
  11724. function QueueOptimizer() {}
  11725. QueueOptimizer.prototype = {
  11726. optimize: function QueueOptimizer_optimize(queue) {
  11727. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11728. var context = {
  11729. iCurr: 0,
  11730. fnArray: fnArray,
  11731. argsArray: argsArray
  11732. };
  11733. var state;
  11734. var i = 0, ii = fnArray.length;
  11735. while (i < ii) {
  11736. state = (state || InitialState)[fnArray[i]];
  11737. if (typeof state === 'function') { // we found some handler
  11738. context.iCurr = i;
  11739. // state() returns the index of the first non-matching op (if we
  11740. // didn't match) or the first op past the modified ops (if we did
  11741. // match and replace).
  11742. i = state(context);
  11743. state = undefined; // reset the state machine
  11744. ii = context.fnArray.length;
  11745. } else {
  11746. i++;
  11747. }
  11748. }
  11749. }
  11750. };
  11751. return QueueOptimizer;
  11752. })();
  11753. var BUILT_IN_CMAPS = [
  11754. // << Start unicode maps.
  11755. 'Adobe-GB1-UCS2',
  11756. 'Adobe-CNS1-UCS2',
  11757. 'Adobe-Japan1-UCS2',
  11758. 'Adobe-Korea1-UCS2',
  11759. // >> End unicode maps.
  11760. '78-EUC-H',
  11761. '78-EUC-V',
  11762. '78-H',
  11763. '78-RKSJ-H',
  11764. '78-RKSJ-V',
  11765. '78-V',
  11766. '78ms-RKSJ-H',
  11767. '78ms-RKSJ-V',
  11768. '83pv-RKSJ-H',
  11769. '90ms-RKSJ-H',
  11770. '90ms-RKSJ-V',
  11771. '90msp-RKSJ-H',
  11772. '90msp-RKSJ-V',
  11773. '90pv-RKSJ-H',
  11774. '90pv-RKSJ-V',
  11775. 'Add-H',
  11776. 'Add-RKSJ-H',
  11777. 'Add-RKSJ-V',
  11778. 'Add-V',
  11779. 'Adobe-CNS1-0',
  11780. 'Adobe-CNS1-1',
  11781. 'Adobe-CNS1-2',
  11782. 'Adobe-CNS1-3',
  11783. 'Adobe-CNS1-4',
  11784. 'Adobe-CNS1-5',
  11785. 'Adobe-CNS1-6',
  11786. 'Adobe-GB1-0',
  11787. 'Adobe-GB1-1',
  11788. 'Adobe-GB1-2',
  11789. 'Adobe-GB1-3',
  11790. 'Adobe-GB1-4',
  11791. 'Adobe-GB1-5',
  11792. 'Adobe-Japan1-0',
  11793. 'Adobe-Japan1-1',
  11794. 'Adobe-Japan1-2',
  11795. 'Adobe-Japan1-3',
  11796. 'Adobe-Japan1-4',
  11797. 'Adobe-Japan1-5',
  11798. 'Adobe-Japan1-6',
  11799. 'Adobe-Korea1-0',
  11800. 'Adobe-Korea1-1',
  11801. 'Adobe-Korea1-2',
  11802. 'B5-H',
  11803. 'B5-V',
  11804. 'B5pc-H',
  11805. 'B5pc-V',
  11806. 'CNS-EUC-H',
  11807. 'CNS-EUC-V',
  11808. 'CNS1-H',
  11809. 'CNS1-V',
  11810. 'CNS2-H',
  11811. 'CNS2-V',
  11812. 'ETHK-B5-H',
  11813. 'ETHK-B5-V',
  11814. 'ETen-B5-H',
  11815. 'ETen-B5-V',
  11816. 'ETenms-B5-H',
  11817. 'ETenms-B5-V',
  11818. 'EUC-H',
  11819. 'EUC-V',
  11820. 'Ext-H',
  11821. 'Ext-RKSJ-H',
  11822. 'Ext-RKSJ-V',
  11823. 'Ext-V',
  11824. 'GB-EUC-H',
  11825. 'GB-EUC-V',
  11826. 'GB-H',
  11827. 'GB-V',
  11828. 'GBK-EUC-H',
  11829. 'GBK-EUC-V',
  11830. 'GBK2K-H',
  11831. 'GBK2K-V',
  11832. 'GBKp-EUC-H',
  11833. 'GBKp-EUC-V',
  11834. 'GBT-EUC-H',
  11835. 'GBT-EUC-V',
  11836. 'GBT-H',
  11837. 'GBT-V',
  11838. 'GBTpc-EUC-H',
  11839. 'GBTpc-EUC-V',
  11840. 'GBpc-EUC-H',
  11841. 'GBpc-EUC-V',
  11842. 'H',
  11843. 'HKdla-B5-H',
  11844. 'HKdla-B5-V',
  11845. 'HKdlb-B5-H',
  11846. 'HKdlb-B5-V',
  11847. 'HKgccs-B5-H',
  11848. 'HKgccs-B5-V',
  11849. 'HKm314-B5-H',
  11850. 'HKm314-B5-V',
  11851. 'HKm471-B5-H',
  11852. 'HKm471-B5-V',
  11853. 'HKscs-B5-H',
  11854. 'HKscs-B5-V',
  11855. 'Hankaku',
  11856. 'Hiragana',
  11857. 'KSC-EUC-H',
  11858. 'KSC-EUC-V',
  11859. 'KSC-H',
  11860. 'KSC-Johab-H',
  11861. 'KSC-Johab-V',
  11862. 'KSC-V',
  11863. 'KSCms-UHC-H',
  11864. 'KSCms-UHC-HW-H',
  11865. 'KSCms-UHC-HW-V',
  11866. 'KSCms-UHC-V',
  11867. 'KSCpc-EUC-H',
  11868. 'KSCpc-EUC-V',
  11869. 'Katakana',
  11870. 'NWP-H',
  11871. 'NWP-V',
  11872. 'RKSJ-H',
  11873. 'RKSJ-V',
  11874. 'Roman',
  11875. 'UniCNS-UCS2-H',
  11876. 'UniCNS-UCS2-V',
  11877. 'UniCNS-UTF16-H',
  11878. 'UniCNS-UTF16-V',
  11879. 'UniCNS-UTF32-H',
  11880. 'UniCNS-UTF32-V',
  11881. 'UniCNS-UTF8-H',
  11882. 'UniCNS-UTF8-V',
  11883. 'UniGB-UCS2-H',
  11884. 'UniGB-UCS2-V',
  11885. 'UniGB-UTF16-H',
  11886. 'UniGB-UTF16-V',
  11887. 'UniGB-UTF32-H',
  11888. 'UniGB-UTF32-V',
  11889. 'UniGB-UTF8-H',
  11890. 'UniGB-UTF8-V',
  11891. 'UniJIS-UCS2-H',
  11892. 'UniJIS-UCS2-HW-H',
  11893. 'UniJIS-UCS2-HW-V',
  11894. 'UniJIS-UCS2-V',
  11895. 'UniJIS-UTF16-H',
  11896. 'UniJIS-UTF16-V',
  11897. 'UniJIS-UTF32-H',
  11898. 'UniJIS-UTF32-V',
  11899. 'UniJIS-UTF8-H',
  11900. 'UniJIS-UTF8-V',
  11901. 'UniJIS2004-UTF16-H',
  11902. 'UniJIS2004-UTF16-V',
  11903. 'UniJIS2004-UTF32-H',
  11904. 'UniJIS2004-UTF32-V',
  11905. 'UniJIS2004-UTF8-H',
  11906. 'UniJIS2004-UTF8-V',
  11907. 'UniJISPro-UCS2-HW-V',
  11908. 'UniJISPro-UCS2-V',
  11909. 'UniJISPro-UTF8-V',
  11910. 'UniJISX0213-UTF32-H',
  11911. 'UniJISX0213-UTF32-V',
  11912. 'UniJISX02132004-UTF32-H',
  11913. 'UniJISX02132004-UTF32-V',
  11914. 'UniKS-UCS2-H',
  11915. 'UniKS-UCS2-V',
  11916. 'UniKS-UTF16-H',
  11917. 'UniKS-UTF16-V',
  11918. 'UniKS-UTF32-H',
  11919. 'UniKS-UTF32-V',
  11920. 'UniKS-UTF8-H',
  11921. 'UniKS-UTF8-V',
  11922. 'V',
  11923. 'WP-Symbol'];
  11924. // CMap, not to be confused with TrueType's cmap.
  11925. var CMap = (function CMapClosure() {
  11926. function CMap(builtInCMap) {
  11927. // Codespace ranges are stored as follows:
  11928. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  11929. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  11930. this.codespaceRanges = [[], [], [], []];
  11931. this.numCodespaceRanges = 0;
  11932. // Map entries have one of two forms.
  11933. // - cid chars are 16-bit unsigned integers, stored as integers.
  11934. // - bf chars are variable-length byte sequences, stored as strings, with
  11935. // one byte per character.
  11936. this._map = [];
  11937. this.vertical = false;
  11938. this.useCMap = null;
  11939. this.builtInCMap = builtInCMap;
  11940. }
  11941. CMap.prototype = {
  11942. addCodespaceRange: function(n, low, high) {
  11943. this.codespaceRanges[n - 1].push(low, high);
  11944. this.numCodespaceRanges++;
  11945. },
  11946. mapCidRange: function(low, high, dstLow) {
  11947. while (low <= high) {
  11948. this._map[low++] = dstLow++;
  11949. }
  11950. },
  11951. mapBfRange: function(low, high, dstLow) {
  11952. var lastByte = dstLow.length - 1;
  11953. while (low <= high) {
  11954. this._map[low++] = dstLow;
  11955. // Only the last byte has to be incremented.
  11956. dstLow = dstLow.substr(0, lastByte) +
  11957. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  11958. }
  11959. },
  11960. mapBfRangeToArray: function(low, high, array) {
  11961. var i = 0, ii = array.length;
  11962. while (low <= high && i < ii) {
  11963. this._map[low] = array[i++];
  11964. ++low;
  11965. }
  11966. },
  11967. // This is used for both bf and cid chars.
  11968. mapOne: function(src, dst) {
  11969. this._map[src] = dst;
  11970. },
  11971. lookup: function(code) {
  11972. return this._map[code];
  11973. },
  11974. contains: function(code) {
  11975. return this._map[code] !== undefined;
  11976. },
  11977. forEach: function(callback) {
  11978. // Most maps have fewer than 65536 entries, and for those we use normal
  11979. // array iteration. But really sparse tables are possible -- e.g. with
  11980. // indices in the *billions*. For such tables we use for..in, which isn't
  11981. // ideal because it stringifies the indices for all present elements, but
  11982. // it does avoid iterating over every undefined entry.
  11983. var map = this._map;
  11984. var length = map.length;
  11985. var i;
  11986. if (length <= 0x10000) {
  11987. for (i = 0; i < length; i++) {
  11988. if (map[i] !== undefined) {
  11989. callback(i, map[i]);
  11990. }
  11991. }
  11992. } else {
  11993. for (i in this._map) {
  11994. callback(i, map[i]);
  11995. }
  11996. }
  11997. },
  11998. charCodeOf: function(value) {
  11999. return this._map.indexOf(value);
  12000. },
  12001. getMap: function() {
  12002. return this._map;
  12003. },
  12004. readCharCode: function(str, offset, out) {
  12005. var c = 0;
  12006. var codespaceRanges = this.codespaceRanges;
  12007. var codespaceRangesLen = this.codespaceRanges.length;
  12008. // 9.7.6.2 CMap Mapping
  12009. // The code length is at most 4.
  12010. for (var n = 0; n < codespaceRangesLen; n++) {
  12011. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12012. // Check each codespace range to see if it falls within.
  12013. var codespaceRange = codespaceRanges[n];
  12014. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12015. var low = codespaceRange[k++];
  12016. var high = codespaceRange[k++];
  12017. if (c >= low && c <= high) {
  12018. out.charcode = c;
  12019. out.length = n + 1;
  12020. return;
  12021. }
  12022. }
  12023. }
  12024. out.charcode = 0;
  12025. out.length = 1;
  12026. }
  12027. };
  12028. return CMap;
  12029. })();
  12030. // A special case of CMap, where the _map array implicitly has a length of
  12031. // 65535 and each element is equal to its index.
  12032. var IdentityCMap = (function IdentityCMapClosure() {
  12033. function IdentityCMap(vertical, n) {
  12034. CMap.call(this);
  12035. this.vertical = vertical;
  12036. this.addCodespaceRange(n, 0, 0xffff);
  12037. }
  12038. Util.inherit(IdentityCMap, CMap, {});
  12039. IdentityCMap.prototype = {
  12040. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12041. mapCidRange: function(low, high, dstLow) {
  12042. error('should not call mapCidRange');
  12043. },
  12044. mapBfRange: function(low, high, dstLow) {
  12045. error('should not call mapBfRange');
  12046. },
  12047. mapBfRangeToArray: function(low, high, array) {
  12048. error('should not call mapBfRangeToArray');
  12049. },
  12050. mapOne: function(src, dst) {
  12051. error('should not call mapCidOne');
  12052. },
  12053. lookup: function(code) {
  12054. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12055. },
  12056. contains: function(code) {
  12057. return isInt(code) && code <= 0xffff;
  12058. },
  12059. forEach: function(callback) {
  12060. for (var i = 0; i <= 0xffff; i++) {
  12061. callback(i, i);
  12062. }
  12063. },
  12064. charCodeOf: function(value) {
  12065. return (isInt(value) && value <= 0xffff) ? value : -1;
  12066. },
  12067. getMap: function() {
  12068. // Sometimes identity maps must be instantiated, but it's rare.
  12069. var map = new Array(0x10000);
  12070. for (var i = 0; i <= 0xffff; i++) {
  12071. map[i] = i;
  12072. }
  12073. return map;
  12074. },
  12075. readCharCode: CMap.prototype.readCharCode
  12076. };
  12077. return IdentityCMap;
  12078. })();
  12079. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12080. function fetchBinaryData(url) {
  12081. var nonBinaryRequest = PDFJS.disableWorker;
  12082. var request = new XMLHttpRequest();
  12083. request.open('GET', url, false);
  12084. if (!nonBinaryRequest) {
  12085. try {
  12086. request.responseType = 'arraybuffer';
  12087. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12088. } catch (e) {
  12089. nonBinaryRequest = true;
  12090. }
  12091. }
  12092. if (nonBinaryRequest && request.overrideMimeType) {
  12093. request.overrideMimeType('text/plain; charset=x-user-defined');
  12094. }
  12095. request.send(null);
  12096. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12097. error('Unable to get binary cMap at: ' + url);
  12098. }
  12099. if (nonBinaryRequest) {
  12100. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12101. return ch.charCodeAt(0) & 255;
  12102. });
  12103. return new Uint8Array(data);
  12104. }
  12105. return new Uint8Array(request.response);
  12106. }
  12107. function hexToInt(a, size) {
  12108. var n = 0;
  12109. for (var i = 0; i <= size; i++) {
  12110. n = (n << 8) | a[i];
  12111. }
  12112. return n >>> 0;
  12113. }
  12114. function hexToStr(a, size) {
  12115. // This code is hot. Special-case some common values to avoid creating an
  12116. // object with subarray().
  12117. if (size === 1) {
  12118. return String.fromCharCode(a[0], a[1]);
  12119. }
  12120. if (size === 3) {
  12121. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12122. }
  12123. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12124. }
  12125. function addHex(a, b, size) {
  12126. var c = 0;
  12127. for (var i = size; i >= 0; i--) {
  12128. c += a[i] + b[i];
  12129. a[i] = c & 255;
  12130. c >>= 8;
  12131. }
  12132. }
  12133. function incHex(a, size) {
  12134. var c = 1;
  12135. for (var i = size; i >= 0 && c > 0; i--) {
  12136. c += a[i];
  12137. a[i] = c & 255;
  12138. c >>= 8;
  12139. }
  12140. }
  12141. var MAX_NUM_SIZE = 16;
  12142. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12143. function BinaryCMapStream(data) {
  12144. this.buffer = data;
  12145. this.pos = 0;
  12146. this.end = data.length;
  12147. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12148. }
  12149. BinaryCMapStream.prototype = {
  12150. readByte: function () {
  12151. if (this.pos >= this.end) {
  12152. return -1;
  12153. }
  12154. return this.buffer[this.pos++];
  12155. },
  12156. readNumber: function () {
  12157. var n = 0;
  12158. var last;
  12159. do {
  12160. var b = this.readByte();
  12161. if (b < 0) {
  12162. error('unexpected EOF in bcmap');
  12163. }
  12164. last = !(b & 0x80);
  12165. n = (n << 7) | (b & 0x7F);
  12166. } while (!last);
  12167. return n;
  12168. },
  12169. readSigned: function () {
  12170. var n = this.readNumber();
  12171. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12172. },
  12173. readHex: function (num, size) {
  12174. num.set(this.buffer.subarray(this.pos,
  12175. this.pos + size + 1));
  12176. this.pos += size + 1;
  12177. },
  12178. readHexNumber: function (num, size) {
  12179. var last;
  12180. var stack = this.tmpBuf, sp = 0;
  12181. do {
  12182. var b = this.readByte();
  12183. if (b < 0) {
  12184. error('unexpected EOF in bcmap');
  12185. }
  12186. last = !(b & 0x80);
  12187. stack[sp++] = b & 0x7F;
  12188. } while (!last);
  12189. var i = size, buffer = 0, bufferSize = 0;
  12190. while (i >= 0) {
  12191. while (bufferSize < 8 && stack.length > 0) {
  12192. buffer = (stack[--sp] << bufferSize) | buffer;
  12193. bufferSize += 7;
  12194. }
  12195. num[i] = buffer & 255;
  12196. i--;
  12197. buffer >>= 8;
  12198. bufferSize -= 8;
  12199. }
  12200. },
  12201. readHexSigned: function (num, size) {
  12202. this.readHexNumber(num, size);
  12203. var sign = num[size] & 1 ? 255 : 0;
  12204. var c = 0;
  12205. for (var i = 0; i <= size; i++) {
  12206. c = ((c & 1) << 8) | num[i];
  12207. num[i] = (c >> 1) ^ sign;
  12208. }
  12209. },
  12210. readString: function () {
  12211. var len = this.readNumber();
  12212. var s = '';
  12213. for (var i = 0; i < len; i++) {
  12214. s += String.fromCharCode(this.readNumber());
  12215. }
  12216. return s;
  12217. }
  12218. };
  12219. function processBinaryCMap(url, cMap, extend) {
  12220. var data = fetchBinaryData(url);
  12221. var stream = new BinaryCMapStream(data);
  12222. var header = stream.readByte();
  12223. cMap.vertical = !!(header & 1);
  12224. var useCMap = null;
  12225. var start = new Uint8Array(MAX_NUM_SIZE);
  12226. var end = new Uint8Array(MAX_NUM_SIZE);
  12227. var char = new Uint8Array(MAX_NUM_SIZE);
  12228. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12229. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12230. var code;
  12231. var b;
  12232. while ((b = stream.readByte()) >= 0) {
  12233. var type = b >> 5;
  12234. if (type === 7) { // metadata, e.g. comment or usecmap
  12235. switch (b & 0x1F) {
  12236. case 0:
  12237. stream.readString(); // skipping comment
  12238. break;
  12239. case 1:
  12240. useCMap = stream.readString();
  12241. break;
  12242. }
  12243. continue;
  12244. }
  12245. var sequence = !!(b & 0x10);
  12246. var dataSize = b & 15;
  12247. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12248. var ucs2DataSize = 1;
  12249. var subitemsCount = stream.readNumber();
  12250. var i;
  12251. switch (type) {
  12252. case 0: // codespacerange
  12253. stream.readHex(start, dataSize);
  12254. stream.readHexNumber(end, dataSize);
  12255. addHex(end, start, dataSize);
  12256. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12257. hexToInt(end, dataSize));
  12258. for (i = 1; i < subitemsCount; i++) {
  12259. incHex(end, dataSize);
  12260. stream.readHexNumber(start, dataSize);
  12261. addHex(start, end, dataSize);
  12262. stream.readHexNumber(end, dataSize);
  12263. addHex(end, start, dataSize);
  12264. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12265. hexToInt(end, dataSize));
  12266. }
  12267. break;
  12268. case 1: // notdefrange
  12269. stream.readHex(start, dataSize);
  12270. stream.readHexNumber(end, dataSize);
  12271. addHex(end, start, dataSize);
  12272. code = stream.readNumber();
  12273. // undefined range, skipping
  12274. for (i = 1; i < subitemsCount; i++) {
  12275. incHex(end, dataSize);
  12276. stream.readHexNumber(start, dataSize);
  12277. addHex(start, end, dataSize);
  12278. stream.readHexNumber(end, dataSize);
  12279. addHex(end, start, dataSize);
  12280. code = stream.readNumber();
  12281. // nop
  12282. }
  12283. break;
  12284. case 2: // cidchar
  12285. stream.readHex(char, dataSize);
  12286. code = stream.readNumber();
  12287. cMap.mapOne(hexToInt(char, dataSize), code);
  12288. for (i = 1; i < subitemsCount; i++) {
  12289. incHex(char, dataSize);
  12290. if (!sequence) {
  12291. stream.readHexNumber(tmp, dataSize);
  12292. addHex(char, tmp, dataSize);
  12293. }
  12294. code = stream.readSigned() + (code + 1);
  12295. cMap.mapOne(hexToInt(char, dataSize), code);
  12296. }
  12297. break;
  12298. case 3: // cidrange
  12299. stream.readHex(start, dataSize);
  12300. stream.readHexNumber(end, dataSize);
  12301. addHex(end, start, dataSize);
  12302. code = stream.readNumber();
  12303. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12304. code);
  12305. for (i = 1; i < subitemsCount; i++) {
  12306. incHex(end, dataSize);
  12307. if (!sequence) {
  12308. stream.readHexNumber(start, dataSize);
  12309. addHex(start, end, dataSize);
  12310. } else {
  12311. start.set(end);
  12312. }
  12313. stream.readHexNumber(end, dataSize);
  12314. addHex(end, start, dataSize);
  12315. code = stream.readNumber();
  12316. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12317. code);
  12318. }
  12319. break;
  12320. case 4: // bfchar
  12321. stream.readHex(char, ucs2DataSize);
  12322. stream.readHex(charCode, dataSize);
  12323. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12324. hexToStr(charCode, dataSize));
  12325. for (i = 1; i < subitemsCount; i++) {
  12326. incHex(char, ucs2DataSize);
  12327. if (!sequence) {
  12328. stream.readHexNumber(tmp, ucs2DataSize);
  12329. addHex(char, tmp, ucs2DataSize);
  12330. }
  12331. incHex(charCode, dataSize);
  12332. stream.readHexSigned(tmp, dataSize);
  12333. addHex(charCode, tmp, dataSize);
  12334. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12335. hexToStr(charCode, dataSize));
  12336. }
  12337. break;
  12338. case 5: // bfrange
  12339. stream.readHex(start, ucs2DataSize);
  12340. stream.readHexNumber(end, ucs2DataSize);
  12341. addHex(end, start, ucs2DataSize);
  12342. stream.readHex(charCode, dataSize);
  12343. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12344. hexToInt(end, ucs2DataSize),
  12345. hexToStr(charCode, dataSize));
  12346. for (i = 1; i < subitemsCount; i++) {
  12347. incHex(end, ucs2DataSize);
  12348. if (!sequence) {
  12349. stream.readHexNumber(start, ucs2DataSize);
  12350. addHex(start, end, ucs2DataSize);
  12351. } else {
  12352. start.set(end);
  12353. }
  12354. stream.readHexNumber(end, ucs2DataSize);
  12355. addHex(end, start, ucs2DataSize);
  12356. stream.readHex(charCode, dataSize);
  12357. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12358. hexToInt(end, ucs2DataSize),
  12359. hexToStr(charCode, dataSize));
  12360. }
  12361. break;
  12362. default:
  12363. error('Unknown type: ' + type);
  12364. break;
  12365. }
  12366. }
  12367. if (useCMap) {
  12368. extend(useCMap);
  12369. }
  12370. return cMap;
  12371. }
  12372. function BinaryCMapReader() {}
  12373. BinaryCMapReader.prototype = {
  12374. read: processBinaryCMap
  12375. };
  12376. return BinaryCMapReader;
  12377. })();
  12378. var CMapFactory = (function CMapFactoryClosure() {
  12379. function strToInt(str) {
  12380. var a = 0;
  12381. for (var i = 0; i < str.length; i++) {
  12382. a = (a << 8) | str.charCodeAt(i);
  12383. }
  12384. return a >>> 0;
  12385. }
  12386. function expectString(obj) {
  12387. if (!isString(obj)) {
  12388. error('Malformed CMap: expected string.');
  12389. }
  12390. }
  12391. function expectInt(obj) {
  12392. if (!isInt(obj)) {
  12393. error('Malformed CMap: expected int.');
  12394. }
  12395. }
  12396. function parseBfChar(cMap, lexer) {
  12397. while (true) {
  12398. var obj = lexer.getObj();
  12399. if (isEOF(obj)) {
  12400. break;
  12401. }
  12402. if (isCmd(obj, 'endbfchar')) {
  12403. return;
  12404. }
  12405. expectString(obj);
  12406. var src = strToInt(obj);
  12407. obj = lexer.getObj();
  12408. // TODO are /dstName used?
  12409. expectString(obj);
  12410. var dst = obj;
  12411. cMap.mapOne(src, dst);
  12412. }
  12413. }
  12414. function parseBfRange(cMap, lexer) {
  12415. while (true) {
  12416. var obj = lexer.getObj();
  12417. if (isEOF(obj)) {
  12418. break;
  12419. }
  12420. if (isCmd(obj, 'endbfrange')) {
  12421. return;
  12422. }
  12423. expectString(obj);
  12424. var low = strToInt(obj);
  12425. obj = lexer.getObj();
  12426. expectString(obj);
  12427. var high = strToInt(obj);
  12428. obj = lexer.getObj();
  12429. if (isInt(obj) || isString(obj)) {
  12430. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12431. cMap.mapBfRange(low, high, dstLow);
  12432. } else if (isCmd(obj, '[')) {
  12433. obj = lexer.getObj();
  12434. var array = [];
  12435. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12436. array.push(obj);
  12437. obj = lexer.getObj();
  12438. }
  12439. cMap.mapBfRangeToArray(low, high, array);
  12440. } else {
  12441. break;
  12442. }
  12443. }
  12444. error('Invalid bf range.');
  12445. }
  12446. function parseCidChar(cMap, lexer) {
  12447. while (true) {
  12448. var obj = lexer.getObj();
  12449. if (isEOF(obj)) {
  12450. break;
  12451. }
  12452. if (isCmd(obj, 'endcidchar')) {
  12453. return;
  12454. }
  12455. expectString(obj);
  12456. var src = strToInt(obj);
  12457. obj = lexer.getObj();
  12458. expectInt(obj);
  12459. var dst = obj;
  12460. cMap.mapOne(src, dst);
  12461. }
  12462. }
  12463. function parseCidRange(cMap, lexer) {
  12464. while (true) {
  12465. var obj = lexer.getObj();
  12466. if (isEOF(obj)) {
  12467. break;
  12468. }
  12469. if (isCmd(obj, 'endcidrange')) {
  12470. return;
  12471. }
  12472. expectString(obj);
  12473. var low = strToInt(obj);
  12474. obj = lexer.getObj();
  12475. expectString(obj);
  12476. var high = strToInt(obj);
  12477. obj = lexer.getObj();
  12478. expectInt(obj);
  12479. var dstLow = obj;
  12480. cMap.mapCidRange(low, high, dstLow);
  12481. }
  12482. }
  12483. function parseCodespaceRange(cMap, lexer) {
  12484. while (true) {
  12485. var obj = lexer.getObj();
  12486. if (isEOF(obj)) {
  12487. break;
  12488. }
  12489. if (isCmd(obj, 'endcodespacerange')) {
  12490. return;
  12491. }
  12492. if (!isString(obj)) {
  12493. break;
  12494. }
  12495. var low = strToInt(obj);
  12496. obj = lexer.getObj();
  12497. if (!isString(obj)) {
  12498. break;
  12499. }
  12500. var high = strToInt(obj);
  12501. cMap.addCodespaceRange(obj.length, low, high);
  12502. }
  12503. error('Invalid codespace range.');
  12504. }
  12505. function parseWMode(cMap, lexer) {
  12506. var obj = lexer.getObj();
  12507. if (isInt(obj)) {
  12508. cMap.vertical = !!obj;
  12509. }
  12510. }
  12511. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12512. var previous;
  12513. var embededUseCMap;
  12514. objLoop: while (true) {
  12515. var obj = lexer.getObj();
  12516. if (isEOF(obj)) {
  12517. break;
  12518. } else if (isName(obj)) {
  12519. if (obj.name === 'WMode') {
  12520. parseWMode(cMap, lexer);
  12521. }
  12522. previous = obj;
  12523. } else if (isCmd(obj)) {
  12524. switch (obj.cmd) {
  12525. case 'endcmap':
  12526. break objLoop;
  12527. case 'usecmap':
  12528. if (isName(previous)) {
  12529. embededUseCMap = previous.name;
  12530. }
  12531. break;
  12532. case 'begincodespacerange':
  12533. parseCodespaceRange(cMap, lexer);
  12534. break;
  12535. case 'beginbfchar':
  12536. parseBfChar(cMap, lexer);
  12537. break;
  12538. case 'begincidchar':
  12539. parseCidChar(cMap, lexer);
  12540. break;
  12541. case 'beginbfrange':
  12542. parseBfRange(cMap, lexer);
  12543. break;
  12544. case 'begincidrange':
  12545. parseCidRange(cMap, lexer);
  12546. break;
  12547. }
  12548. }
  12549. }
  12550. if (!useCMap && embededUseCMap) {
  12551. // Load the usecmap definition from the file only if there wasn't one
  12552. // specified.
  12553. useCMap = embededUseCMap;
  12554. }
  12555. if (useCMap) {
  12556. extendCMap(cMap, builtInCMapParams, useCMap);
  12557. }
  12558. }
  12559. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12560. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12561. // If there aren't any code space ranges defined clone all the parent ones
  12562. // into this cMap.
  12563. if (cMap.numCodespaceRanges === 0) {
  12564. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12565. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12566. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12567. }
  12568. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12569. }
  12570. // Merge the map into the current one, making sure not to override
  12571. // any previously defined entries.
  12572. cMap.useCMap.forEach(function(key, value) {
  12573. if (!cMap.contains(key)) {
  12574. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12575. }
  12576. });
  12577. }
  12578. function parseBinaryCMap(name, builtInCMapParams) {
  12579. var url = builtInCMapParams.url + name + '.bcmap';
  12580. var cMap = new CMap(true);
  12581. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12582. extendCMap(cMap, builtInCMapParams, useCMap);
  12583. });
  12584. return cMap;
  12585. }
  12586. function createBuiltInCMap(name, builtInCMapParams) {
  12587. if (name === 'Identity-H') {
  12588. return new IdentityCMap(false, 2);
  12589. } else if (name === 'Identity-V') {
  12590. return new IdentityCMap(true, 2);
  12591. }
  12592. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12593. error('Unknown cMap name: ' + name);
  12594. }
  12595. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12596. if (builtInCMapParams.packed) {
  12597. return parseBinaryCMap(name, builtInCMapParams);
  12598. }
  12599. var request = new XMLHttpRequest();
  12600. var url = builtInCMapParams.url + name;
  12601. request.open('GET', url, false);
  12602. request.send(null);
  12603. if (!request.responseText) {
  12604. error('Unable to get cMap at: ' + url);
  12605. }
  12606. var cMap = new CMap(true);
  12607. var lexer = new Lexer(new StringStream(request.responseText));
  12608. parseCMap(cMap, lexer, builtInCMapParams, null);
  12609. return cMap;
  12610. }
  12611. return {
  12612. create: function (encoding, builtInCMapParams, useCMap) {
  12613. if (isName(encoding)) {
  12614. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12615. } else if (isStream(encoding)) {
  12616. var cMap = new CMap();
  12617. var lexer = new Lexer(encoding);
  12618. try {
  12619. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12620. } catch (e) {
  12621. warn('Invalid CMap data. ' + e);
  12622. }
  12623. return cMap;
  12624. }
  12625. error('Encoding required.');
  12626. }
  12627. };
  12628. })();
  12629. // Unicode Private Use Area
  12630. var PRIVATE_USE_OFFSET_START = 0xE000;
  12631. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12632. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12633. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12634. // except for Type 3 fonts
  12635. var PDF_GLYPH_SPACE_UNITS = 1000;
  12636. // Hinting is currently disabled due to unknown problems on windows
  12637. // in tracemonkey and various other pdfs with type1 fonts.
  12638. var HINTING_ENABLED = false;
  12639. // Accented charactars are not displayed properly on windows, using this flag
  12640. // to control analysis of seac charstrings.
  12641. var SEAC_ANALYSIS_ENABLED = false;
  12642. var FontFlags = {
  12643. FixedPitch: 1,
  12644. Serif: 2,
  12645. Symbolic: 4,
  12646. Script: 8,
  12647. Nonsymbolic: 32,
  12648. Italic: 64,
  12649. AllCap: 65536,
  12650. SmallCap: 131072,
  12651. ForceBold: 262144
  12652. };
  12653. var Encodings = {
  12654. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12655. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12656. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12657. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12658. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12659. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12660. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12661. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12662. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12663. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12664. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12665. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12666. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12667. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12668. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12669. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12670. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12671. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12672. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12673. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12674. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12675. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12676. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12677. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12678. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12679. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12680. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12681. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12682. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12683. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12684. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12685. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12686. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12687. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12688. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12689. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12690. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12691. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12692. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12693. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12694. 'Ydieresissmall'],
  12695. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12696. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12697. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12698. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12699. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12700. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12701. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12702. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12703. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12704. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12705. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12706. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12707. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12708. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12709. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12710. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12711. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12712. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12713. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12714. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12715. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12716. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12717. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12718. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12719. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12720. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12721. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12722. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12723. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12724. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12725. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12726. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12727. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12728. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12729. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12730. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12731. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12732. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12733. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12734. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12735. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12736. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12737. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12738. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12739. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12740. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12741. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12742. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12743. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12744. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12745. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12746. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12747. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12748. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12749. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12750. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12751. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12752. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12753. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12754. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12755. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12756. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12757. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12758. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12759. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12760. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12761. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12762. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12763. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12764. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12765. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12766. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12767. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12768. 'ogonek', 'caron'],
  12769. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12770. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12771. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12772. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12773. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12774. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12775. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12776. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12777. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12778. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12779. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12780. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12781. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12782. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12783. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12784. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12785. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12786. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12787. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12788. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12789. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12790. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12791. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12792. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12793. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12794. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12795. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12796. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12797. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12798. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12799. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12800. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12801. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12802. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12803. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12804. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12805. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12806. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  12807. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  12808. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  12809. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  12810. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  12811. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  12812. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  12813. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  12814. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  12815. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  12816. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  12817. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  12818. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  12819. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  12820. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  12821. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  12822. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  12823. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  12824. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  12825. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  12826. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  12827. 'ydieresis'],
  12828. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12829. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12830. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  12831. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  12832. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  12833. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  12834. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  12835. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  12836. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  12837. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  12838. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  12839. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  12840. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  12841. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  12842. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  12843. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12844. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  12845. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  12846. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  12847. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  12848. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  12849. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  12850. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  12851. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  12852. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  12853. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  12854. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  12855. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  12856. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  12857. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  12858. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  12859. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  12860. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  12861. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  12862. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  12863. 'bracerightbt'],
  12864. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12865. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12866. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  12867. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  12868. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  12869. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  12870. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  12871. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  12872. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  12873. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  12874. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  12875. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12877. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  12878. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  12879. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  12880. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  12881. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  12882. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  12883. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  12884. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  12885. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  12886. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  12887. 'a188', 'a189', 'a190', 'a191']
  12888. };
  12889. /**
  12890. * Hold a map of decoded fonts and of the standard fourteen Type1
  12891. * fonts and their acronyms.
  12892. */
  12893. var stdFontMap = {
  12894. 'ArialNarrow': 'Helvetica',
  12895. 'ArialNarrow-Bold': 'Helvetica-Bold',
  12896. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  12897. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  12898. 'ArialBlack': 'Helvetica',
  12899. 'ArialBlack-Bold': 'Helvetica-Bold',
  12900. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  12901. 'ArialBlack-Italic': 'Helvetica-Oblique',
  12902. 'Arial': 'Helvetica',
  12903. 'Arial-Bold': 'Helvetica-Bold',
  12904. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  12905. 'Arial-Italic': 'Helvetica-Oblique',
  12906. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  12907. 'Arial-BoldMT': 'Helvetica-Bold',
  12908. 'Arial-ItalicMT': 'Helvetica-Oblique',
  12909. 'ArialMT': 'Helvetica',
  12910. 'Courier-Bold': 'Courier-Bold',
  12911. 'Courier-BoldItalic': 'Courier-BoldOblique',
  12912. 'Courier-Italic': 'Courier-Oblique',
  12913. 'CourierNew': 'Courier',
  12914. 'CourierNew-Bold': 'Courier-Bold',
  12915. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  12916. 'CourierNew-Italic': 'Courier-Oblique',
  12917. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  12918. 'CourierNewPS-BoldMT': 'Courier-Bold',
  12919. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  12920. 'CourierNewPSMT': 'Courier',
  12921. 'Helvetica-Bold': 'Helvetica-Bold',
  12922. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  12923. 'Helvetica-Italic': 'Helvetica-Oblique',
  12924. 'Symbol-Bold': 'Symbol',
  12925. 'Symbol-BoldItalic': 'Symbol',
  12926. 'Symbol-Italic': 'Symbol',
  12927. 'TimesNewRoman': 'Times-Roman',
  12928. 'TimesNewRoman-Bold': 'Times-Bold',
  12929. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  12930. 'TimesNewRoman-Italic': 'Times-Italic',
  12931. 'TimesNewRomanPS': 'Times-Roman',
  12932. 'TimesNewRomanPS-Bold': 'Times-Bold',
  12933. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  12934. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  12935. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  12936. 'TimesNewRomanPS-Italic': 'Times-Italic',
  12937. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  12938. 'TimesNewRomanPSMT': 'Times-Roman',
  12939. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  12940. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  12941. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  12942. };
  12943. /**
  12944. * Holds the map of the non-standard fonts that might be included as a standard
  12945. * fonts without glyph data.
  12946. */
  12947. var nonStdFontMap = {
  12948. 'ComicSansMS': 'Comic Sans MS',
  12949. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  12950. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  12951. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  12952. 'LucidaConsole': 'Courier',
  12953. 'LucidaConsole-Bold': 'Courier-Bold',
  12954. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  12955. 'LucidaConsole-Italic': 'Courier-Oblique',
  12956. 'MS-Gothic': 'MS Gothic',
  12957. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  12958. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  12959. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  12960. 'MS-Mincho': 'MS Mincho',
  12961. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  12962. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  12963. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  12964. 'MS-PGothic': 'MS PGothic',
  12965. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  12966. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  12967. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  12968. 'MS-PMincho': 'MS PMincho',
  12969. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  12970. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  12971. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  12972. };
  12973. var serifFonts = {
  12974. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  12975. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  12976. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  12977. 'Arno': true, 'Aster': true, 'Aurora': true,
  12978. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  12979. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  12980. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  12981. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  12982. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  12983. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  12984. 'Cartier': true, 'Caslon': true, 'Catull': true,
  12985. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  12986. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  12987. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  12988. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  12989. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  12990. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  12991. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  12992. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  12993. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  12994. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  12995. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  12996. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  12997. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  12998. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  12999. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13000. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13001. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13002. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13003. 'Miller': true, 'Minion': true, 'Modern': true,
  13004. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13005. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13006. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13007. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13008. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13009. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13010. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13011. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13012. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13013. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13014. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13015. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13016. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13017. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13018. };
  13019. var symbolsFonts = {
  13020. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13021. };
  13022. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13023. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13024. // glyphs, but common for some set of the standard fonts.
  13025. var GlyphMapForStandardFonts = {
  13026. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13027. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13028. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13029. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13030. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13031. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13032. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13033. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13034. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13035. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13036. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13037. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13038. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13039. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13040. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13041. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13042. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13043. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13044. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13045. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13046. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13047. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13048. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13049. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13050. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13051. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13052. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  13053. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  13054. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13055. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13056. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13057. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13058. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13059. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13060. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13061. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13062. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13063. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13064. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13065. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13066. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13067. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13068. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13069. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13070. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13071. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13072. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13073. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13074. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13075. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13076. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13077. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13078. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13079. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13080. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13081. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13082. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13083. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13084. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13085. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13086. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13087. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13088. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13089. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13090. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13091. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13092. };
  13093. // Some characters, e.g. copyrightserif, mapped to the private use area and
  13094. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13095. // to the similar equivalents in the normal characters range.
  13096. function mapSpecialUnicodeValues(code) {
  13097. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13098. return 0;
  13099. }
  13100. switch (code) {
  13101. case 0xF8E9: // copyrightsans
  13102. case 0xF6D9: // copyrightserif
  13103. return 0x00A9; // copyright
  13104. case 0xF8E8: // registersans
  13105. case 0xF6DA: // registerserif
  13106. return 0x00AE; // registered
  13107. case 0xF8EA: // trademarksans
  13108. case 0xF6DB: // trademarkserif
  13109. return 0x2122; // trademark
  13110. default:
  13111. return code;
  13112. }
  13113. }
  13114. var UnicodeRanges = [
  13115. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13116. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13117. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13118. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13119. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13120. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13121. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13122. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13123. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13124. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13125. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13126. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13127. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13128. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13129. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13130. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13131. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13132. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13133. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13134. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13135. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13136. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13137. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13138. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13139. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13140. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13141. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13142. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13143. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13144. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13145. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13146. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13147. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13148. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13149. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13150. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13151. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13152. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13153. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13154. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13155. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13156. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13157. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13158. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13159. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13160. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13161. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13162. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13163. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13164. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13165. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13166. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13167. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13168. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13169. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13170. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13171. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13172. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13173. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13174. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13175. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13176. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13177. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13178. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13179. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13180. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13181. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13182. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13183. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13184. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13185. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13186. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13187. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13188. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13189. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13190. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13191. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13192. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13193. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13194. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13195. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13196. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13197. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13198. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13199. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13200. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13201. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13202. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13203. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13204. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13205. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13206. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13207. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13208. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13209. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13210. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13211. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13212. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13213. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13214. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13215. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13216. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13217. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13218. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13219. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13220. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13221. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13222. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13223. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13224. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13225. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13226. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13227. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13228. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13229. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13230. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13231. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13232. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13233. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13234. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13235. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13236. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13237. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13238. ];
  13239. var MacStandardGlyphOrdering = [
  13240. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13241. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13242. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13243. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13244. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13245. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13246. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13247. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13248. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13249. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13250. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13251. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13252. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13253. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13254. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13255. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13256. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13257. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13258. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13259. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13260. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13261. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13262. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13263. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13264. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13265. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13266. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13267. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13268. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13269. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13270. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13271. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13272. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13273. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13274. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13275. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13276. function getUnicodeRangeFor(value) {
  13277. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13278. var range = UnicodeRanges[i];
  13279. if (value >= range.begin && value < range.end) {
  13280. return i;
  13281. }
  13282. }
  13283. return -1;
  13284. }
  13285. function isRTLRangeFor(value) {
  13286. var range = UnicodeRanges[13];
  13287. if (value >= range.begin && value < range.end) {
  13288. return true;
  13289. }
  13290. range = UnicodeRanges[11];
  13291. if (value >= range.begin && value < range.end) {
  13292. return true;
  13293. }
  13294. return false;
  13295. }
  13296. // The normalization table is obtained by filtering the Unicode characters
  13297. // database with <compat> entries.
  13298. var NormalizedUnicodes = {
  13299. '\u00A8': '\u0020\u0308',
  13300. '\u00AF': '\u0020\u0304',
  13301. '\u00B4': '\u0020\u0301',
  13302. '\u00B5': '\u03BC',
  13303. '\u00B8': '\u0020\u0327',
  13304. '\u0132': '\u0049\u004A',
  13305. '\u0133': '\u0069\u006A',
  13306. '\u013F': '\u004C\u00B7',
  13307. '\u0140': '\u006C\u00B7',
  13308. '\u0149': '\u02BC\u006E',
  13309. '\u017F': '\u0073',
  13310. '\u01C4': '\u0044\u017D',
  13311. '\u01C5': '\u0044\u017E',
  13312. '\u01C6': '\u0064\u017E',
  13313. '\u01C7': '\u004C\u004A',
  13314. '\u01C8': '\u004C\u006A',
  13315. '\u01C9': '\u006C\u006A',
  13316. '\u01CA': '\u004E\u004A',
  13317. '\u01CB': '\u004E\u006A',
  13318. '\u01CC': '\u006E\u006A',
  13319. '\u01F1': '\u0044\u005A',
  13320. '\u01F2': '\u0044\u007A',
  13321. '\u01F3': '\u0064\u007A',
  13322. '\u02D8': '\u0020\u0306',
  13323. '\u02D9': '\u0020\u0307',
  13324. '\u02DA': '\u0020\u030A',
  13325. '\u02DB': '\u0020\u0328',
  13326. '\u02DC': '\u0020\u0303',
  13327. '\u02DD': '\u0020\u030B',
  13328. '\u037A': '\u0020\u0345',
  13329. '\u0384': '\u0020\u0301',
  13330. '\u03D0': '\u03B2',
  13331. '\u03D1': '\u03B8',
  13332. '\u03D2': '\u03A5',
  13333. '\u03D5': '\u03C6',
  13334. '\u03D6': '\u03C0',
  13335. '\u03F0': '\u03BA',
  13336. '\u03F1': '\u03C1',
  13337. '\u03F2': '\u03C2',
  13338. '\u03F4': '\u0398',
  13339. '\u03F5': '\u03B5',
  13340. '\u03F9': '\u03A3',
  13341. '\u0587': '\u0565\u0582',
  13342. '\u0675': '\u0627\u0674',
  13343. '\u0676': '\u0648\u0674',
  13344. '\u0677': '\u06C7\u0674',
  13345. '\u0678': '\u064A\u0674',
  13346. '\u0E33': '\u0E4D\u0E32',
  13347. '\u0EB3': '\u0ECD\u0EB2',
  13348. '\u0EDC': '\u0EAB\u0E99',
  13349. '\u0EDD': '\u0EAB\u0EA1',
  13350. '\u0F77': '\u0FB2\u0F81',
  13351. '\u0F79': '\u0FB3\u0F81',
  13352. '\u1E9A': '\u0061\u02BE',
  13353. '\u1FBD': '\u0020\u0313',
  13354. '\u1FBF': '\u0020\u0313',
  13355. '\u1FC0': '\u0020\u0342',
  13356. '\u1FFE': '\u0020\u0314',
  13357. '\u2002': '\u0020',
  13358. '\u2003': '\u0020',
  13359. '\u2004': '\u0020',
  13360. '\u2005': '\u0020',
  13361. '\u2006': '\u0020',
  13362. '\u2008': '\u0020',
  13363. '\u2009': '\u0020',
  13364. '\u200A': '\u0020',
  13365. '\u2017': '\u0020\u0333',
  13366. '\u2024': '\u002E',
  13367. '\u2025': '\u002E\u002E',
  13368. '\u2026': '\u002E\u002E\u002E',
  13369. '\u2033': '\u2032\u2032',
  13370. '\u2034': '\u2032\u2032\u2032',
  13371. '\u2036': '\u2035\u2035',
  13372. '\u2037': '\u2035\u2035\u2035',
  13373. '\u203C': '\u0021\u0021',
  13374. '\u203E': '\u0020\u0305',
  13375. '\u2047': '\u003F\u003F',
  13376. '\u2048': '\u003F\u0021',
  13377. '\u2049': '\u0021\u003F',
  13378. '\u2057': '\u2032\u2032\u2032\u2032',
  13379. '\u205F': '\u0020',
  13380. '\u20A8': '\u0052\u0073',
  13381. '\u2100': '\u0061\u002F\u0063',
  13382. '\u2101': '\u0061\u002F\u0073',
  13383. '\u2103': '\u00B0\u0043',
  13384. '\u2105': '\u0063\u002F\u006F',
  13385. '\u2106': '\u0063\u002F\u0075',
  13386. '\u2107': '\u0190',
  13387. '\u2109': '\u00B0\u0046',
  13388. '\u2116': '\u004E\u006F',
  13389. '\u2121': '\u0054\u0045\u004C',
  13390. '\u2135': '\u05D0',
  13391. '\u2136': '\u05D1',
  13392. '\u2137': '\u05D2',
  13393. '\u2138': '\u05D3',
  13394. '\u213B': '\u0046\u0041\u0058',
  13395. '\u2160': '\u0049',
  13396. '\u2161': '\u0049\u0049',
  13397. '\u2162': '\u0049\u0049\u0049',
  13398. '\u2163': '\u0049\u0056',
  13399. '\u2164': '\u0056',
  13400. '\u2165': '\u0056\u0049',
  13401. '\u2166': '\u0056\u0049\u0049',
  13402. '\u2167': '\u0056\u0049\u0049\u0049',
  13403. '\u2168': '\u0049\u0058',
  13404. '\u2169': '\u0058',
  13405. '\u216A': '\u0058\u0049',
  13406. '\u216B': '\u0058\u0049\u0049',
  13407. '\u216C': '\u004C',
  13408. '\u216D': '\u0043',
  13409. '\u216E': '\u0044',
  13410. '\u216F': '\u004D',
  13411. '\u2170': '\u0069',
  13412. '\u2171': '\u0069\u0069',
  13413. '\u2172': '\u0069\u0069\u0069',
  13414. '\u2173': '\u0069\u0076',
  13415. '\u2174': '\u0076',
  13416. '\u2175': '\u0076\u0069',
  13417. '\u2176': '\u0076\u0069\u0069',
  13418. '\u2177': '\u0076\u0069\u0069\u0069',
  13419. '\u2178': '\u0069\u0078',
  13420. '\u2179': '\u0078',
  13421. '\u217A': '\u0078\u0069',
  13422. '\u217B': '\u0078\u0069\u0069',
  13423. '\u217C': '\u006C',
  13424. '\u217D': '\u0063',
  13425. '\u217E': '\u0064',
  13426. '\u217F': '\u006D',
  13427. '\u222C': '\u222B\u222B',
  13428. '\u222D': '\u222B\u222B\u222B',
  13429. '\u222F': '\u222E\u222E',
  13430. '\u2230': '\u222E\u222E\u222E',
  13431. '\u2474': '\u0028\u0031\u0029',
  13432. '\u2475': '\u0028\u0032\u0029',
  13433. '\u2476': '\u0028\u0033\u0029',
  13434. '\u2477': '\u0028\u0034\u0029',
  13435. '\u2478': '\u0028\u0035\u0029',
  13436. '\u2479': '\u0028\u0036\u0029',
  13437. '\u247A': '\u0028\u0037\u0029',
  13438. '\u247B': '\u0028\u0038\u0029',
  13439. '\u247C': '\u0028\u0039\u0029',
  13440. '\u247D': '\u0028\u0031\u0030\u0029',
  13441. '\u247E': '\u0028\u0031\u0031\u0029',
  13442. '\u247F': '\u0028\u0031\u0032\u0029',
  13443. '\u2480': '\u0028\u0031\u0033\u0029',
  13444. '\u2481': '\u0028\u0031\u0034\u0029',
  13445. '\u2482': '\u0028\u0031\u0035\u0029',
  13446. '\u2483': '\u0028\u0031\u0036\u0029',
  13447. '\u2484': '\u0028\u0031\u0037\u0029',
  13448. '\u2485': '\u0028\u0031\u0038\u0029',
  13449. '\u2486': '\u0028\u0031\u0039\u0029',
  13450. '\u2487': '\u0028\u0032\u0030\u0029',
  13451. '\u2488': '\u0031\u002E',
  13452. '\u2489': '\u0032\u002E',
  13453. '\u248A': '\u0033\u002E',
  13454. '\u248B': '\u0034\u002E',
  13455. '\u248C': '\u0035\u002E',
  13456. '\u248D': '\u0036\u002E',
  13457. '\u248E': '\u0037\u002E',
  13458. '\u248F': '\u0038\u002E',
  13459. '\u2490': '\u0039\u002E',
  13460. '\u2491': '\u0031\u0030\u002E',
  13461. '\u2492': '\u0031\u0031\u002E',
  13462. '\u2493': '\u0031\u0032\u002E',
  13463. '\u2494': '\u0031\u0033\u002E',
  13464. '\u2495': '\u0031\u0034\u002E',
  13465. '\u2496': '\u0031\u0035\u002E',
  13466. '\u2497': '\u0031\u0036\u002E',
  13467. '\u2498': '\u0031\u0037\u002E',
  13468. '\u2499': '\u0031\u0038\u002E',
  13469. '\u249A': '\u0031\u0039\u002E',
  13470. '\u249B': '\u0032\u0030\u002E',
  13471. '\u249C': '\u0028\u0061\u0029',
  13472. '\u249D': '\u0028\u0062\u0029',
  13473. '\u249E': '\u0028\u0063\u0029',
  13474. '\u249F': '\u0028\u0064\u0029',
  13475. '\u24A0': '\u0028\u0065\u0029',
  13476. '\u24A1': '\u0028\u0066\u0029',
  13477. '\u24A2': '\u0028\u0067\u0029',
  13478. '\u24A3': '\u0028\u0068\u0029',
  13479. '\u24A4': '\u0028\u0069\u0029',
  13480. '\u24A5': '\u0028\u006A\u0029',
  13481. '\u24A6': '\u0028\u006B\u0029',
  13482. '\u24A7': '\u0028\u006C\u0029',
  13483. '\u24A8': '\u0028\u006D\u0029',
  13484. '\u24A9': '\u0028\u006E\u0029',
  13485. '\u24AA': '\u0028\u006F\u0029',
  13486. '\u24AB': '\u0028\u0070\u0029',
  13487. '\u24AC': '\u0028\u0071\u0029',
  13488. '\u24AD': '\u0028\u0072\u0029',
  13489. '\u24AE': '\u0028\u0073\u0029',
  13490. '\u24AF': '\u0028\u0074\u0029',
  13491. '\u24B0': '\u0028\u0075\u0029',
  13492. '\u24B1': '\u0028\u0076\u0029',
  13493. '\u24B2': '\u0028\u0077\u0029',
  13494. '\u24B3': '\u0028\u0078\u0029',
  13495. '\u24B4': '\u0028\u0079\u0029',
  13496. '\u24B5': '\u0028\u007A\u0029',
  13497. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13498. '\u2A74': '\u003A\u003A\u003D',
  13499. '\u2A75': '\u003D\u003D',
  13500. '\u2A76': '\u003D\u003D\u003D',
  13501. '\u2E9F': '\u6BCD',
  13502. '\u2EF3': '\u9F9F',
  13503. '\u2F00': '\u4E00',
  13504. '\u2F01': '\u4E28',
  13505. '\u2F02': '\u4E36',
  13506. '\u2F03': '\u4E3F',
  13507. '\u2F04': '\u4E59',
  13508. '\u2F05': '\u4E85',
  13509. '\u2F06': '\u4E8C',
  13510. '\u2F07': '\u4EA0',
  13511. '\u2F08': '\u4EBA',
  13512. '\u2F09': '\u513F',
  13513. '\u2F0A': '\u5165',
  13514. '\u2F0B': '\u516B',
  13515. '\u2F0C': '\u5182',
  13516. '\u2F0D': '\u5196',
  13517. '\u2F0E': '\u51AB',
  13518. '\u2F0F': '\u51E0',
  13519. '\u2F10': '\u51F5',
  13520. '\u2F11': '\u5200',
  13521. '\u2F12': '\u529B',
  13522. '\u2F13': '\u52F9',
  13523. '\u2F14': '\u5315',
  13524. '\u2F15': '\u531A',
  13525. '\u2F16': '\u5338',
  13526. '\u2F17': '\u5341',
  13527. '\u2F18': '\u535C',
  13528. '\u2F19': '\u5369',
  13529. '\u2F1A': '\u5382',
  13530. '\u2F1B': '\u53B6',
  13531. '\u2F1C': '\u53C8',
  13532. '\u2F1D': '\u53E3',
  13533. '\u2F1E': '\u56D7',
  13534. '\u2F1F': '\u571F',
  13535. '\u2F20': '\u58EB',
  13536. '\u2F21': '\u5902',
  13537. '\u2F22': '\u590A',
  13538. '\u2F23': '\u5915',
  13539. '\u2F24': '\u5927',
  13540. '\u2F25': '\u5973',
  13541. '\u2F26': '\u5B50',
  13542. '\u2F27': '\u5B80',
  13543. '\u2F28': '\u5BF8',
  13544. '\u2F29': '\u5C0F',
  13545. '\u2F2A': '\u5C22',
  13546. '\u2F2B': '\u5C38',
  13547. '\u2F2C': '\u5C6E',
  13548. '\u2F2D': '\u5C71',
  13549. '\u2F2E': '\u5DDB',
  13550. '\u2F2F': '\u5DE5',
  13551. '\u2F30': '\u5DF1',
  13552. '\u2F31': '\u5DFE',
  13553. '\u2F32': '\u5E72',
  13554. '\u2F33': '\u5E7A',
  13555. '\u2F34': '\u5E7F',
  13556. '\u2F35': '\u5EF4',
  13557. '\u2F36': '\u5EFE',
  13558. '\u2F37': '\u5F0B',
  13559. '\u2F38': '\u5F13',
  13560. '\u2F39': '\u5F50',
  13561. '\u2F3A': '\u5F61',
  13562. '\u2F3B': '\u5F73',
  13563. '\u2F3C': '\u5FC3',
  13564. '\u2F3D': '\u6208',
  13565. '\u2F3E': '\u6236',
  13566. '\u2F3F': '\u624B',
  13567. '\u2F40': '\u652F',
  13568. '\u2F41': '\u6534',
  13569. '\u2F42': '\u6587',
  13570. '\u2F43': '\u6597',
  13571. '\u2F44': '\u65A4',
  13572. '\u2F45': '\u65B9',
  13573. '\u2F46': '\u65E0',
  13574. '\u2F47': '\u65E5',
  13575. '\u2F48': '\u66F0',
  13576. '\u2F49': '\u6708',
  13577. '\u2F4A': '\u6728',
  13578. '\u2F4B': '\u6B20',
  13579. '\u2F4C': '\u6B62',
  13580. '\u2F4D': '\u6B79',
  13581. '\u2F4E': '\u6BB3',
  13582. '\u2F4F': '\u6BCB',
  13583. '\u2F50': '\u6BD4',
  13584. '\u2F51': '\u6BDB',
  13585. '\u2F52': '\u6C0F',
  13586. '\u2F53': '\u6C14',
  13587. '\u2F54': '\u6C34',
  13588. '\u2F55': '\u706B',
  13589. '\u2F56': '\u722A',
  13590. '\u2F57': '\u7236',
  13591. '\u2F58': '\u723B',
  13592. '\u2F59': '\u723F',
  13593. '\u2F5A': '\u7247',
  13594. '\u2F5B': '\u7259',
  13595. '\u2F5C': '\u725B',
  13596. '\u2F5D': '\u72AC',
  13597. '\u2F5E': '\u7384',
  13598. '\u2F5F': '\u7389',
  13599. '\u2F60': '\u74DC',
  13600. '\u2F61': '\u74E6',
  13601. '\u2F62': '\u7518',
  13602. '\u2F63': '\u751F',
  13603. '\u2F64': '\u7528',
  13604. '\u2F65': '\u7530',
  13605. '\u2F66': '\u758B',
  13606. '\u2F67': '\u7592',
  13607. '\u2F68': '\u7676',
  13608. '\u2F69': '\u767D',
  13609. '\u2F6A': '\u76AE',
  13610. '\u2F6B': '\u76BF',
  13611. '\u2F6C': '\u76EE',
  13612. '\u2F6D': '\u77DB',
  13613. '\u2F6E': '\u77E2',
  13614. '\u2F6F': '\u77F3',
  13615. '\u2F70': '\u793A',
  13616. '\u2F71': '\u79B8',
  13617. '\u2F72': '\u79BE',
  13618. '\u2F73': '\u7A74',
  13619. '\u2F74': '\u7ACB',
  13620. '\u2F75': '\u7AF9',
  13621. '\u2F76': '\u7C73',
  13622. '\u2F77': '\u7CF8',
  13623. '\u2F78': '\u7F36',
  13624. '\u2F79': '\u7F51',
  13625. '\u2F7A': '\u7F8A',
  13626. '\u2F7B': '\u7FBD',
  13627. '\u2F7C': '\u8001',
  13628. '\u2F7D': '\u800C',
  13629. '\u2F7E': '\u8012',
  13630. '\u2F7F': '\u8033',
  13631. '\u2F80': '\u807F',
  13632. '\u2F81': '\u8089',
  13633. '\u2F82': '\u81E3',
  13634. '\u2F83': '\u81EA',
  13635. '\u2F84': '\u81F3',
  13636. '\u2F85': '\u81FC',
  13637. '\u2F86': '\u820C',
  13638. '\u2F87': '\u821B',
  13639. '\u2F88': '\u821F',
  13640. '\u2F89': '\u826E',
  13641. '\u2F8A': '\u8272',
  13642. '\u2F8B': '\u8278',
  13643. '\u2F8C': '\u864D',
  13644. '\u2F8D': '\u866B',
  13645. '\u2F8E': '\u8840',
  13646. '\u2F8F': '\u884C',
  13647. '\u2F90': '\u8863',
  13648. '\u2F91': '\u897E',
  13649. '\u2F92': '\u898B',
  13650. '\u2F93': '\u89D2',
  13651. '\u2F94': '\u8A00',
  13652. '\u2F95': '\u8C37',
  13653. '\u2F96': '\u8C46',
  13654. '\u2F97': '\u8C55',
  13655. '\u2F98': '\u8C78',
  13656. '\u2F99': '\u8C9D',
  13657. '\u2F9A': '\u8D64',
  13658. '\u2F9B': '\u8D70',
  13659. '\u2F9C': '\u8DB3',
  13660. '\u2F9D': '\u8EAB',
  13661. '\u2F9E': '\u8ECA',
  13662. '\u2F9F': '\u8F9B',
  13663. '\u2FA0': '\u8FB0',
  13664. '\u2FA1': '\u8FB5',
  13665. '\u2FA2': '\u9091',
  13666. '\u2FA3': '\u9149',
  13667. '\u2FA4': '\u91C6',
  13668. '\u2FA5': '\u91CC',
  13669. '\u2FA6': '\u91D1',
  13670. '\u2FA7': '\u9577',
  13671. '\u2FA8': '\u9580',
  13672. '\u2FA9': '\u961C',
  13673. '\u2FAA': '\u96B6',
  13674. '\u2FAB': '\u96B9',
  13675. '\u2FAC': '\u96E8',
  13676. '\u2FAD': '\u9751',
  13677. '\u2FAE': '\u975E',
  13678. '\u2FAF': '\u9762',
  13679. '\u2FB0': '\u9769',
  13680. '\u2FB1': '\u97CB',
  13681. '\u2FB2': '\u97ED',
  13682. '\u2FB3': '\u97F3',
  13683. '\u2FB4': '\u9801',
  13684. '\u2FB5': '\u98A8',
  13685. '\u2FB6': '\u98DB',
  13686. '\u2FB7': '\u98DF',
  13687. '\u2FB8': '\u9996',
  13688. '\u2FB9': '\u9999',
  13689. '\u2FBA': '\u99AC',
  13690. '\u2FBB': '\u9AA8',
  13691. '\u2FBC': '\u9AD8',
  13692. '\u2FBD': '\u9ADF',
  13693. '\u2FBE': '\u9B25',
  13694. '\u2FBF': '\u9B2F',
  13695. '\u2FC0': '\u9B32',
  13696. '\u2FC1': '\u9B3C',
  13697. '\u2FC2': '\u9B5A',
  13698. '\u2FC3': '\u9CE5',
  13699. '\u2FC4': '\u9E75',
  13700. '\u2FC5': '\u9E7F',
  13701. '\u2FC6': '\u9EA5',
  13702. '\u2FC7': '\u9EBB',
  13703. '\u2FC8': '\u9EC3',
  13704. '\u2FC9': '\u9ECD',
  13705. '\u2FCA': '\u9ED1',
  13706. '\u2FCB': '\u9EF9',
  13707. '\u2FCC': '\u9EFD',
  13708. '\u2FCD': '\u9F0E',
  13709. '\u2FCE': '\u9F13',
  13710. '\u2FCF': '\u9F20',
  13711. '\u2FD0': '\u9F3B',
  13712. '\u2FD1': '\u9F4A',
  13713. '\u2FD2': '\u9F52',
  13714. '\u2FD3': '\u9F8D',
  13715. '\u2FD4': '\u9F9C',
  13716. '\u2FD5': '\u9FA0',
  13717. '\u3036': '\u3012',
  13718. '\u3038': '\u5341',
  13719. '\u3039': '\u5344',
  13720. '\u303A': '\u5345',
  13721. '\u309B': '\u0020\u3099',
  13722. '\u309C': '\u0020\u309A',
  13723. '\u3131': '\u1100',
  13724. '\u3132': '\u1101',
  13725. '\u3133': '\u11AA',
  13726. '\u3134': '\u1102',
  13727. '\u3135': '\u11AC',
  13728. '\u3136': '\u11AD',
  13729. '\u3137': '\u1103',
  13730. '\u3138': '\u1104',
  13731. '\u3139': '\u1105',
  13732. '\u313A': '\u11B0',
  13733. '\u313B': '\u11B1',
  13734. '\u313C': '\u11B2',
  13735. '\u313D': '\u11B3',
  13736. '\u313E': '\u11B4',
  13737. '\u313F': '\u11B5',
  13738. '\u3140': '\u111A',
  13739. '\u3141': '\u1106',
  13740. '\u3142': '\u1107',
  13741. '\u3143': '\u1108',
  13742. '\u3144': '\u1121',
  13743. '\u3145': '\u1109',
  13744. '\u3146': '\u110A',
  13745. '\u3147': '\u110B',
  13746. '\u3148': '\u110C',
  13747. '\u3149': '\u110D',
  13748. '\u314A': '\u110E',
  13749. '\u314B': '\u110F',
  13750. '\u314C': '\u1110',
  13751. '\u314D': '\u1111',
  13752. '\u314E': '\u1112',
  13753. '\u314F': '\u1161',
  13754. '\u3150': '\u1162',
  13755. '\u3151': '\u1163',
  13756. '\u3152': '\u1164',
  13757. '\u3153': '\u1165',
  13758. '\u3154': '\u1166',
  13759. '\u3155': '\u1167',
  13760. '\u3156': '\u1168',
  13761. '\u3157': '\u1169',
  13762. '\u3158': '\u116A',
  13763. '\u3159': '\u116B',
  13764. '\u315A': '\u116C',
  13765. '\u315B': '\u116D',
  13766. '\u315C': '\u116E',
  13767. '\u315D': '\u116F',
  13768. '\u315E': '\u1170',
  13769. '\u315F': '\u1171',
  13770. '\u3160': '\u1172',
  13771. '\u3161': '\u1173',
  13772. '\u3162': '\u1174',
  13773. '\u3163': '\u1175',
  13774. '\u3164': '\u1160',
  13775. '\u3165': '\u1114',
  13776. '\u3166': '\u1115',
  13777. '\u3167': '\u11C7',
  13778. '\u3168': '\u11C8',
  13779. '\u3169': '\u11CC',
  13780. '\u316A': '\u11CE',
  13781. '\u316B': '\u11D3',
  13782. '\u316C': '\u11D7',
  13783. '\u316D': '\u11D9',
  13784. '\u316E': '\u111C',
  13785. '\u316F': '\u11DD',
  13786. '\u3170': '\u11DF',
  13787. '\u3171': '\u111D',
  13788. '\u3172': '\u111E',
  13789. '\u3173': '\u1120',
  13790. '\u3174': '\u1122',
  13791. '\u3175': '\u1123',
  13792. '\u3176': '\u1127',
  13793. '\u3177': '\u1129',
  13794. '\u3178': '\u112B',
  13795. '\u3179': '\u112C',
  13796. '\u317A': '\u112D',
  13797. '\u317B': '\u112E',
  13798. '\u317C': '\u112F',
  13799. '\u317D': '\u1132',
  13800. '\u317E': '\u1136',
  13801. '\u317F': '\u1140',
  13802. '\u3180': '\u1147',
  13803. '\u3181': '\u114C',
  13804. '\u3182': '\u11F1',
  13805. '\u3183': '\u11F2',
  13806. '\u3184': '\u1157',
  13807. '\u3185': '\u1158',
  13808. '\u3186': '\u1159',
  13809. '\u3187': '\u1184',
  13810. '\u3188': '\u1185',
  13811. '\u3189': '\u1188',
  13812. '\u318A': '\u1191',
  13813. '\u318B': '\u1192',
  13814. '\u318C': '\u1194',
  13815. '\u318D': '\u119E',
  13816. '\u318E': '\u11A1',
  13817. '\u3200': '\u0028\u1100\u0029',
  13818. '\u3201': '\u0028\u1102\u0029',
  13819. '\u3202': '\u0028\u1103\u0029',
  13820. '\u3203': '\u0028\u1105\u0029',
  13821. '\u3204': '\u0028\u1106\u0029',
  13822. '\u3205': '\u0028\u1107\u0029',
  13823. '\u3206': '\u0028\u1109\u0029',
  13824. '\u3207': '\u0028\u110B\u0029',
  13825. '\u3208': '\u0028\u110C\u0029',
  13826. '\u3209': '\u0028\u110E\u0029',
  13827. '\u320A': '\u0028\u110F\u0029',
  13828. '\u320B': '\u0028\u1110\u0029',
  13829. '\u320C': '\u0028\u1111\u0029',
  13830. '\u320D': '\u0028\u1112\u0029',
  13831. '\u320E': '\u0028\u1100\u1161\u0029',
  13832. '\u320F': '\u0028\u1102\u1161\u0029',
  13833. '\u3210': '\u0028\u1103\u1161\u0029',
  13834. '\u3211': '\u0028\u1105\u1161\u0029',
  13835. '\u3212': '\u0028\u1106\u1161\u0029',
  13836. '\u3213': '\u0028\u1107\u1161\u0029',
  13837. '\u3214': '\u0028\u1109\u1161\u0029',
  13838. '\u3215': '\u0028\u110B\u1161\u0029',
  13839. '\u3216': '\u0028\u110C\u1161\u0029',
  13840. '\u3217': '\u0028\u110E\u1161\u0029',
  13841. '\u3218': '\u0028\u110F\u1161\u0029',
  13842. '\u3219': '\u0028\u1110\u1161\u0029',
  13843. '\u321A': '\u0028\u1111\u1161\u0029',
  13844. '\u321B': '\u0028\u1112\u1161\u0029',
  13845. '\u321C': '\u0028\u110C\u116E\u0029',
  13846. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  13847. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  13848. '\u3220': '\u0028\u4E00\u0029',
  13849. '\u3221': '\u0028\u4E8C\u0029',
  13850. '\u3222': '\u0028\u4E09\u0029',
  13851. '\u3223': '\u0028\u56DB\u0029',
  13852. '\u3224': '\u0028\u4E94\u0029',
  13853. '\u3225': '\u0028\u516D\u0029',
  13854. '\u3226': '\u0028\u4E03\u0029',
  13855. '\u3227': '\u0028\u516B\u0029',
  13856. '\u3228': '\u0028\u4E5D\u0029',
  13857. '\u3229': '\u0028\u5341\u0029',
  13858. '\u322A': '\u0028\u6708\u0029',
  13859. '\u322B': '\u0028\u706B\u0029',
  13860. '\u322C': '\u0028\u6C34\u0029',
  13861. '\u322D': '\u0028\u6728\u0029',
  13862. '\u322E': '\u0028\u91D1\u0029',
  13863. '\u322F': '\u0028\u571F\u0029',
  13864. '\u3230': '\u0028\u65E5\u0029',
  13865. '\u3231': '\u0028\u682A\u0029',
  13866. '\u3232': '\u0028\u6709\u0029',
  13867. '\u3233': '\u0028\u793E\u0029',
  13868. '\u3234': '\u0028\u540D\u0029',
  13869. '\u3235': '\u0028\u7279\u0029',
  13870. '\u3236': '\u0028\u8CA1\u0029',
  13871. '\u3237': '\u0028\u795D\u0029',
  13872. '\u3238': '\u0028\u52B4\u0029',
  13873. '\u3239': '\u0028\u4EE3\u0029',
  13874. '\u323A': '\u0028\u547C\u0029',
  13875. '\u323B': '\u0028\u5B66\u0029',
  13876. '\u323C': '\u0028\u76E3\u0029',
  13877. '\u323D': '\u0028\u4F01\u0029',
  13878. '\u323E': '\u0028\u8CC7\u0029',
  13879. '\u323F': '\u0028\u5354\u0029',
  13880. '\u3240': '\u0028\u796D\u0029',
  13881. '\u3241': '\u0028\u4F11\u0029',
  13882. '\u3242': '\u0028\u81EA\u0029',
  13883. '\u3243': '\u0028\u81F3\u0029',
  13884. '\u32C0': '\u0031\u6708',
  13885. '\u32C1': '\u0032\u6708',
  13886. '\u32C2': '\u0033\u6708',
  13887. '\u32C3': '\u0034\u6708',
  13888. '\u32C4': '\u0035\u6708',
  13889. '\u32C5': '\u0036\u6708',
  13890. '\u32C6': '\u0037\u6708',
  13891. '\u32C7': '\u0038\u6708',
  13892. '\u32C8': '\u0039\u6708',
  13893. '\u32C9': '\u0031\u0030\u6708',
  13894. '\u32CA': '\u0031\u0031\u6708',
  13895. '\u32CB': '\u0031\u0032\u6708',
  13896. '\u3358': '\u0030\u70B9',
  13897. '\u3359': '\u0031\u70B9',
  13898. '\u335A': '\u0032\u70B9',
  13899. '\u335B': '\u0033\u70B9',
  13900. '\u335C': '\u0034\u70B9',
  13901. '\u335D': '\u0035\u70B9',
  13902. '\u335E': '\u0036\u70B9',
  13903. '\u335F': '\u0037\u70B9',
  13904. '\u3360': '\u0038\u70B9',
  13905. '\u3361': '\u0039\u70B9',
  13906. '\u3362': '\u0031\u0030\u70B9',
  13907. '\u3363': '\u0031\u0031\u70B9',
  13908. '\u3364': '\u0031\u0032\u70B9',
  13909. '\u3365': '\u0031\u0033\u70B9',
  13910. '\u3366': '\u0031\u0034\u70B9',
  13911. '\u3367': '\u0031\u0035\u70B9',
  13912. '\u3368': '\u0031\u0036\u70B9',
  13913. '\u3369': '\u0031\u0037\u70B9',
  13914. '\u336A': '\u0031\u0038\u70B9',
  13915. '\u336B': '\u0031\u0039\u70B9',
  13916. '\u336C': '\u0032\u0030\u70B9',
  13917. '\u336D': '\u0032\u0031\u70B9',
  13918. '\u336E': '\u0032\u0032\u70B9',
  13919. '\u336F': '\u0032\u0033\u70B9',
  13920. '\u3370': '\u0032\u0034\u70B9',
  13921. '\u33E0': '\u0031\u65E5',
  13922. '\u33E1': '\u0032\u65E5',
  13923. '\u33E2': '\u0033\u65E5',
  13924. '\u33E3': '\u0034\u65E5',
  13925. '\u33E4': '\u0035\u65E5',
  13926. '\u33E5': '\u0036\u65E5',
  13927. '\u33E6': '\u0037\u65E5',
  13928. '\u33E7': '\u0038\u65E5',
  13929. '\u33E8': '\u0039\u65E5',
  13930. '\u33E9': '\u0031\u0030\u65E5',
  13931. '\u33EA': '\u0031\u0031\u65E5',
  13932. '\u33EB': '\u0031\u0032\u65E5',
  13933. '\u33EC': '\u0031\u0033\u65E5',
  13934. '\u33ED': '\u0031\u0034\u65E5',
  13935. '\u33EE': '\u0031\u0035\u65E5',
  13936. '\u33EF': '\u0031\u0036\u65E5',
  13937. '\u33F0': '\u0031\u0037\u65E5',
  13938. '\u33F1': '\u0031\u0038\u65E5',
  13939. '\u33F2': '\u0031\u0039\u65E5',
  13940. '\u33F3': '\u0032\u0030\u65E5',
  13941. '\u33F4': '\u0032\u0031\u65E5',
  13942. '\u33F5': '\u0032\u0032\u65E5',
  13943. '\u33F6': '\u0032\u0033\u65E5',
  13944. '\u33F7': '\u0032\u0034\u65E5',
  13945. '\u33F8': '\u0032\u0035\u65E5',
  13946. '\u33F9': '\u0032\u0036\u65E5',
  13947. '\u33FA': '\u0032\u0037\u65E5',
  13948. '\u33FB': '\u0032\u0038\u65E5',
  13949. '\u33FC': '\u0032\u0039\u65E5',
  13950. '\u33FD': '\u0033\u0030\u65E5',
  13951. '\u33FE': '\u0033\u0031\u65E5',
  13952. '\uFB00': '\u0066\u0066',
  13953. '\uFB01': '\u0066\u0069',
  13954. '\uFB02': '\u0066\u006C',
  13955. '\uFB03': '\u0066\u0066\u0069',
  13956. '\uFB04': '\u0066\u0066\u006C',
  13957. '\uFB05': '\u017F\u0074',
  13958. '\uFB06': '\u0073\u0074',
  13959. '\uFB13': '\u0574\u0576',
  13960. '\uFB14': '\u0574\u0565',
  13961. '\uFB15': '\u0574\u056B',
  13962. '\uFB16': '\u057E\u0576',
  13963. '\uFB17': '\u0574\u056D',
  13964. '\uFB4F': '\u05D0\u05DC',
  13965. '\uFB50': '\u0671',
  13966. '\uFB51': '\u0671',
  13967. '\uFB52': '\u067B',
  13968. '\uFB53': '\u067B',
  13969. '\uFB54': '\u067B',
  13970. '\uFB55': '\u067B',
  13971. '\uFB56': '\u067E',
  13972. '\uFB57': '\u067E',
  13973. '\uFB58': '\u067E',
  13974. '\uFB59': '\u067E',
  13975. '\uFB5A': '\u0680',
  13976. '\uFB5B': '\u0680',
  13977. '\uFB5C': '\u0680',
  13978. '\uFB5D': '\u0680',
  13979. '\uFB5E': '\u067A',
  13980. '\uFB5F': '\u067A',
  13981. '\uFB60': '\u067A',
  13982. '\uFB61': '\u067A',
  13983. '\uFB62': '\u067F',
  13984. '\uFB63': '\u067F',
  13985. '\uFB64': '\u067F',
  13986. '\uFB65': '\u067F',
  13987. '\uFB66': '\u0679',
  13988. '\uFB67': '\u0679',
  13989. '\uFB68': '\u0679',
  13990. '\uFB69': '\u0679',
  13991. '\uFB6A': '\u06A4',
  13992. '\uFB6B': '\u06A4',
  13993. '\uFB6C': '\u06A4',
  13994. '\uFB6D': '\u06A4',
  13995. '\uFB6E': '\u06A6',
  13996. '\uFB6F': '\u06A6',
  13997. '\uFB70': '\u06A6',
  13998. '\uFB71': '\u06A6',
  13999. '\uFB72': '\u0684',
  14000. '\uFB73': '\u0684',
  14001. '\uFB74': '\u0684',
  14002. '\uFB75': '\u0684',
  14003. '\uFB76': '\u0683',
  14004. '\uFB77': '\u0683',
  14005. '\uFB78': '\u0683',
  14006. '\uFB79': '\u0683',
  14007. '\uFB7A': '\u0686',
  14008. '\uFB7B': '\u0686',
  14009. '\uFB7C': '\u0686',
  14010. '\uFB7D': '\u0686',
  14011. '\uFB7E': '\u0687',
  14012. '\uFB7F': '\u0687',
  14013. '\uFB80': '\u0687',
  14014. '\uFB81': '\u0687',
  14015. '\uFB82': '\u068D',
  14016. '\uFB83': '\u068D',
  14017. '\uFB84': '\u068C',
  14018. '\uFB85': '\u068C',
  14019. '\uFB86': '\u068E',
  14020. '\uFB87': '\u068E',
  14021. '\uFB88': '\u0688',
  14022. '\uFB89': '\u0688',
  14023. '\uFB8A': '\u0698',
  14024. '\uFB8B': '\u0698',
  14025. '\uFB8C': '\u0691',
  14026. '\uFB8D': '\u0691',
  14027. '\uFB8E': '\u06A9',
  14028. '\uFB8F': '\u06A9',
  14029. '\uFB90': '\u06A9',
  14030. '\uFB91': '\u06A9',
  14031. '\uFB92': '\u06AF',
  14032. '\uFB93': '\u06AF',
  14033. '\uFB94': '\u06AF',
  14034. '\uFB95': '\u06AF',
  14035. '\uFB96': '\u06B3',
  14036. '\uFB97': '\u06B3',
  14037. '\uFB98': '\u06B3',
  14038. '\uFB99': '\u06B3',
  14039. '\uFB9A': '\u06B1',
  14040. '\uFB9B': '\u06B1',
  14041. '\uFB9C': '\u06B1',
  14042. '\uFB9D': '\u06B1',
  14043. '\uFB9E': '\u06BA',
  14044. '\uFB9F': '\u06BA',
  14045. '\uFBA0': '\u06BB',
  14046. '\uFBA1': '\u06BB',
  14047. '\uFBA2': '\u06BB',
  14048. '\uFBA3': '\u06BB',
  14049. '\uFBA4': '\u06C0',
  14050. '\uFBA5': '\u06C0',
  14051. '\uFBA6': '\u06C1',
  14052. '\uFBA7': '\u06C1',
  14053. '\uFBA8': '\u06C1',
  14054. '\uFBA9': '\u06C1',
  14055. '\uFBAA': '\u06BE',
  14056. '\uFBAB': '\u06BE',
  14057. '\uFBAC': '\u06BE',
  14058. '\uFBAD': '\u06BE',
  14059. '\uFBAE': '\u06D2',
  14060. '\uFBAF': '\u06D2',
  14061. '\uFBB0': '\u06D3',
  14062. '\uFBB1': '\u06D3',
  14063. '\uFBD3': '\u06AD',
  14064. '\uFBD4': '\u06AD',
  14065. '\uFBD5': '\u06AD',
  14066. '\uFBD6': '\u06AD',
  14067. '\uFBD7': '\u06C7',
  14068. '\uFBD8': '\u06C7',
  14069. '\uFBD9': '\u06C6',
  14070. '\uFBDA': '\u06C6',
  14071. '\uFBDB': '\u06C8',
  14072. '\uFBDC': '\u06C8',
  14073. '\uFBDD': '\u0677',
  14074. '\uFBDE': '\u06CB',
  14075. '\uFBDF': '\u06CB',
  14076. '\uFBE0': '\u06C5',
  14077. '\uFBE1': '\u06C5',
  14078. '\uFBE2': '\u06C9',
  14079. '\uFBE3': '\u06C9',
  14080. '\uFBE4': '\u06D0',
  14081. '\uFBE5': '\u06D0',
  14082. '\uFBE6': '\u06D0',
  14083. '\uFBE7': '\u06D0',
  14084. '\uFBE8': '\u0649',
  14085. '\uFBE9': '\u0649',
  14086. '\uFBEA': '\u0626\u0627',
  14087. '\uFBEB': '\u0626\u0627',
  14088. '\uFBEC': '\u0626\u06D5',
  14089. '\uFBED': '\u0626\u06D5',
  14090. '\uFBEE': '\u0626\u0648',
  14091. '\uFBEF': '\u0626\u0648',
  14092. '\uFBF0': '\u0626\u06C7',
  14093. '\uFBF1': '\u0626\u06C7',
  14094. '\uFBF2': '\u0626\u06C6',
  14095. '\uFBF3': '\u0626\u06C6',
  14096. '\uFBF4': '\u0626\u06C8',
  14097. '\uFBF5': '\u0626\u06C8',
  14098. '\uFBF6': '\u0626\u06D0',
  14099. '\uFBF7': '\u0626\u06D0',
  14100. '\uFBF8': '\u0626\u06D0',
  14101. '\uFBF9': '\u0626\u0649',
  14102. '\uFBFA': '\u0626\u0649',
  14103. '\uFBFB': '\u0626\u0649',
  14104. '\uFBFC': '\u06CC',
  14105. '\uFBFD': '\u06CC',
  14106. '\uFBFE': '\u06CC',
  14107. '\uFBFF': '\u06CC',
  14108. '\uFC00': '\u0626\u062C',
  14109. '\uFC01': '\u0626\u062D',
  14110. '\uFC02': '\u0626\u0645',
  14111. '\uFC03': '\u0626\u0649',
  14112. '\uFC04': '\u0626\u064A',
  14113. '\uFC05': '\u0628\u062C',
  14114. '\uFC06': '\u0628\u062D',
  14115. '\uFC07': '\u0628\u062E',
  14116. '\uFC08': '\u0628\u0645',
  14117. '\uFC09': '\u0628\u0649',
  14118. '\uFC0A': '\u0628\u064A',
  14119. '\uFC0B': '\u062A\u062C',
  14120. '\uFC0C': '\u062A\u062D',
  14121. '\uFC0D': '\u062A\u062E',
  14122. '\uFC0E': '\u062A\u0645',
  14123. '\uFC0F': '\u062A\u0649',
  14124. '\uFC10': '\u062A\u064A',
  14125. '\uFC11': '\u062B\u062C',
  14126. '\uFC12': '\u062B\u0645',
  14127. '\uFC13': '\u062B\u0649',
  14128. '\uFC14': '\u062B\u064A',
  14129. '\uFC15': '\u062C\u062D',
  14130. '\uFC16': '\u062C\u0645',
  14131. '\uFC17': '\u062D\u062C',
  14132. '\uFC18': '\u062D\u0645',
  14133. '\uFC19': '\u062E\u062C',
  14134. '\uFC1A': '\u062E\u062D',
  14135. '\uFC1B': '\u062E\u0645',
  14136. '\uFC1C': '\u0633\u062C',
  14137. '\uFC1D': '\u0633\u062D',
  14138. '\uFC1E': '\u0633\u062E',
  14139. '\uFC1F': '\u0633\u0645',
  14140. '\uFC20': '\u0635\u062D',
  14141. '\uFC21': '\u0635\u0645',
  14142. '\uFC22': '\u0636\u062C',
  14143. '\uFC23': '\u0636\u062D',
  14144. '\uFC24': '\u0636\u062E',
  14145. '\uFC25': '\u0636\u0645',
  14146. '\uFC26': '\u0637\u062D',
  14147. '\uFC27': '\u0637\u0645',
  14148. '\uFC28': '\u0638\u0645',
  14149. '\uFC29': '\u0639\u062C',
  14150. '\uFC2A': '\u0639\u0645',
  14151. '\uFC2B': '\u063A\u062C',
  14152. '\uFC2C': '\u063A\u0645',
  14153. '\uFC2D': '\u0641\u062C',
  14154. '\uFC2E': '\u0641\u062D',
  14155. '\uFC2F': '\u0641\u062E',
  14156. '\uFC30': '\u0641\u0645',
  14157. '\uFC31': '\u0641\u0649',
  14158. '\uFC32': '\u0641\u064A',
  14159. '\uFC33': '\u0642\u062D',
  14160. '\uFC34': '\u0642\u0645',
  14161. '\uFC35': '\u0642\u0649',
  14162. '\uFC36': '\u0642\u064A',
  14163. '\uFC37': '\u0643\u0627',
  14164. '\uFC38': '\u0643\u062C',
  14165. '\uFC39': '\u0643\u062D',
  14166. '\uFC3A': '\u0643\u062E',
  14167. '\uFC3B': '\u0643\u0644',
  14168. '\uFC3C': '\u0643\u0645',
  14169. '\uFC3D': '\u0643\u0649',
  14170. '\uFC3E': '\u0643\u064A',
  14171. '\uFC3F': '\u0644\u062C',
  14172. '\uFC40': '\u0644\u062D',
  14173. '\uFC41': '\u0644\u062E',
  14174. '\uFC42': '\u0644\u0645',
  14175. '\uFC43': '\u0644\u0649',
  14176. '\uFC44': '\u0644\u064A',
  14177. '\uFC45': '\u0645\u062C',
  14178. '\uFC46': '\u0645\u062D',
  14179. '\uFC47': '\u0645\u062E',
  14180. '\uFC48': '\u0645\u0645',
  14181. '\uFC49': '\u0645\u0649',
  14182. '\uFC4A': '\u0645\u064A',
  14183. '\uFC4B': '\u0646\u062C',
  14184. '\uFC4C': '\u0646\u062D',
  14185. '\uFC4D': '\u0646\u062E',
  14186. '\uFC4E': '\u0646\u0645',
  14187. '\uFC4F': '\u0646\u0649',
  14188. '\uFC50': '\u0646\u064A',
  14189. '\uFC51': '\u0647\u062C',
  14190. '\uFC52': '\u0647\u0645',
  14191. '\uFC53': '\u0647\u0649',
  14192. '\uFC54': '\u0647\u064A',
  14193. '\uFC55': '\u064A\u062C',
  14194. '\uFC56': '\u064A\u062D',
  14195. '\uFC57': '\u064A\u062E',
  14196. '\uFC58': '\u064A\u0645',
  14197. '\uFC59': '\u064A\u0649',
  14198. '\uFC5A': '\u064A\u064A',
  14199. '\uFC5B': '\u0630\u0670',
  14200. '\uFC5C': '\u0631\u0670',
  14201. '\uFC5D': '\u0649\u0670',
  14202. '\uFC5E': '\u0020\u064C\u0651',
  14203. '\uFC5F': '\u0020\u064D\u0651',
  14204. '\uFC60': '\u0020\u064E\u0651',
  14205. '\uFC61': '\u0020\u064F\u0651',
  14206. '\uFC62': '\u0020\u0650\u0651',
  14207. '\uFC63': '\u0020\u0651\u0670',
  14208. '\uFC64': '\u0626\u0631',
  14209. '\uFC65': '\u0626\u0632',
  14210. '\uFC66': '\u0626\u0645',
  14211. '\uFC67': '\u0626\u0646',
  14212. '\uFC68': '\u0626\u0649',
  14213. '\uFC69': '\u0626\u064A',
  14214. '\uFC6A': '\u0628\u0631',
  14215. '\uFC6B': '\u0628\u0632',
  14216. '\uFC6C': '\u0628\u0645',
  14217. '\uFC6D': '\u0628\u0646',
  14218. '\uFC6E': '\u0628\u0649',
  14219. '\uFC6F': '\u0628\u064A',
  14220. '\uFC70': '\u062A\u0631',
  14221. '\uFC71': '\u062A\u0632',
  14222. '\uFC72': '\u062A\u0645',
  14223. '\uFC73': '\u062A\u0646',
  14224. '\uFC74': '\u062A\u0649',
  14225. '\uFC75': '\u062A\u064A',
  14226. '\uFC76': '\u062B\u0631',
  14227. '\uFC77': '\u062B\u0632',
  14228. '\uFC78': '\u062B\u0645',
  14229. '\uFC79': '\u062B\u0646',
  14230. '\uFC7A': '\u062B\u0649',
  14231. '\uFC7B': '\u062B\u064A',
  14232. '\uFC7C': '\u0641\u0649',
  14233. '\uFC7D': '\u0641\u064A',
  14234. '\uFC7E': '\u0642\u0649',
  14235. '\uFC7F': '\u0642\u064A',
  14236. '\uFC80': '\u0643\u0627',
  14237. '\uFC81': '\u0643\u0644',
  14238. '\uFC82': '\u0643\u0645',
  14239. '\uFC83': '\u0643\u0649',
  14240. '\uFC84': '\u0643\u064A',
  14241. '\uFC85': '\u0644\u0645',
  14242. '\uFC86': '\u0644\u0649',
  14243. '\uFC87': '\u0644\u064A',
  14244. '\uFC88': '\u0645\u0627',
  14245. '\uFC89': '\u0645\u0645',
  14246. '\uFC8A': '\u0646\u0631',
  14247. '\uFC8B': '\u0646\u0632',
  14248. '\uFC8C': '\u0646\u0645',
  14249. '\uFC8D': '\u0646\u0646',
  14250. '\uFC8E': '\u0646\u0649',
  14251. '\uFC8F': '\u0646\u064A',
  14252. '\uFC90': '\u0649\u0670',
  14253. '\uFC91': '\u064A\u0631',
  14254. '\uFC92': '\u064A\u0632',
  14255. '\uFC93': '\u064A\u0645',
  14256. '\uFC94': '\u064A\u0646',
  14257. '\uFC95': '\u064A\u0649',
  14258. '\uFC96': '\u064A\u064A',
  14259. '\uFC97': '\u0626\u062C',
  14260. '\uFC98': '\u0626\u062D',
  14261. '\uFC99': '\u0626\u062E',
  14262. '\uFC9A': '\u0626\u0645',
  14263. '\uFC9B': '\u0626\u0647',
  14264. '\uFC9C': '\u0628\u062C',
  14265. '\uFC9D': '\u0628\u062D',
  14266. '\uFC9E': '\u0628\u062E',
  14267. '\uFC9F': '\u0628\u0645',
  14268. '\uFCA0': '\u0628\u0647',
  14269. '\uFCA1': '\u062A\u062C',
  14270. '\uFCA2': '\u062A\u062D',
  14271. '\uFCA3': '\u062A\u062E',
  14272. '\uFCA4': '\u062A\u0645',
  14273. '\uFCA5': '\u062A\u0647',
  14274. '\uFCA6': '\u062B\u0645',
  14275. '\uFCA7': '\u062C\u062D',
  14276. '\uFCA8': '\u062C\u0645',
  14277. '\uFCA9': '\u062D\u062C',
  14278. '\uFCAA': '\u062D\u0645',
  14279. '\uFCAB': '\u062E\u062C',
  14280. '\uFCAC': '\u062E\u0645',
  14281. '\uFCAD': '\u0633\u062C',
  14282. '\uFCAE': '\u0633\u062D',
  14283. '\uFCAF': '\u0633\u062E',
  14284. '\uFCB0': '\u0633\u0645',
  14285. '\uFCB1': '\u0635\u062D',
  14286. '\uFCB2': '\u0635\u062E',
  14287. '\uFCB3': '\u0635\u0645',
  14288. '\uFCB4': '\u0636\u062C',
  14289. '\uFCB5': '\u0636\u062D',
  14290. '\uFCB6': '\u0636\u062E',
  14291. '\uFCB7': '\u0636\u0645',
  14292. '\uFCB8': '\u0637\u062D',
  14293. '\uFCB9': '\u0638\u0645',
  14294. '\uFCBA': '\u0639\u062C',
  14295. '\uFCBB': '\u0639\u0645',
  14296. '\uFCBC': '\u063A\u062C',
  14297. '\uFCBD': '\u063A\u0645',
  14298. '\uFCBE': '\u0641\u062C',
  14299. '\uFCBF': '\u0641\u062D',
  14300. '\uFCC0': '\u0641\u062E',
  14301. '\uFCC1': '\u0641\u0645',
  14302. '\uFCC2': '\u0642\u062D',
  14303. '\uFCC3': '\u0642\u0645',
  14304. '\uFCC4': '\u0643\u062C',
  14305. '\uFCC5': '\u0643\u062D',
  14306. '\uFCC6': '\u0643\u062E',
  14307. '\uFCC7': '\u0643\u0644',
  14308. '\uFCC8': '\u0643\u0645',
  14309. '\uFCC9': '\u0644\u062C',
  14310. '\uFCCA': '\u0644\u062D',
  14311. '\uFCCB': '\u0644\u062E',
  14312. '\uFCCC': '\u0644\u0645',
  14313. '\uFCCD': '\u0644\u0647',
  14314. '\uFCCE': '\u0645\u062C',
  14315. '\uFCCF': '\u0645\u062D',
  14316. '\uFCD0': '\u0645\u062E',
  14317. '\uFCD1': '\u0645\u0645',
  14318. '\uFCD2': '\u0646\u062C',
  14319. '\uFCD3': '\u0646\u062D',
  14320. '\uFCD4': '\u0646\u062E',
  14321. '\uFCD5': '\u0646\u0645',
  14322. '\uFCD6': '\u0646\u0647',
  14323. '\uFCD7': '\u0647\u062C',
  14324. '\uFCD8': '\u0647\u0645',
  14325. '\uFCD9': '\u0647\u0670',
  14326. '\uFCDA': '\u064A\u062C',
  14327. '\uFCDB': '\u064A\u062D',
  14328. '\uFCDC': '\u064A\u062E',
  14329. '\uFCDD': '\u064A\u0645',
  14330. '\uFCDE': '\u064A\u0647',
  14331. '\uFCDF': '\u0626\u0645',
  14332. '\uFCE0': '\u0626\u0647',
  14333. '\uFCE1': '\u0628\u0645',
  14334. '\uFCE2': '\u0628\u0647',
  14335. '\uFCE3': '\u062A\u0645',
  14336. '\uFCE4': '\u062A\u0647',
  14337. '\uFCE5': '\u062B\u0645',
  14338. '\uFCE6': '\u062B\u0647',
  14339. '\uFCE7': '\u0633\u0645',
  14340. '\uFCE8': '\u0633\u0647',
  14341. '\uFCE9': '\u0634\u0645',
  14342. '\uFCEA': '\u0634\u0647',
  14343. '\uFCEB': '\u0643\u0644',
  14344. '\uFCEC': '\u0643\u0645',
  14345. '\uFCED': '\u0644\u0645',
  14346. '\uFCEE': '\u0646\u0645',
  14347. '\uFCEF': '\u0646\u0647',
  14348. '\uFCF0': '\u064A\u0645',
  14349. '\uFCF1': '\u064A\u0647',
  14350. '\uFCF2': '\u0640\u064E\u0651',
  14351. '\uFCF3': '\u0640\u064F\u0651',
  14352. '\uFCF4': '\u0640\u0650\u0651',
  14353. '\uFCF5': '\u0637\u0649',
  14354. '\uFCF6': '\u0637\u064A',
  14355. '\uFCF7': '\u0639\u0649',
  14356. '\uFCF8': '\u0639\u064A',
  14357. '\uFCF9': '\u063A\u0649',
  14358. '\uFCFA': '\u063A\u064A',
  14359. '\uFCFB': '\u0633\u0649',
  14360. '\uFCFC': '\u0633\u064A',
  14361. '\uFCFD': '\u0634\u0649',
  14362. '\uFCFE': '\u0634\u064A',
  14363. '\uFCFF': '\u062D\u0649',
  14364. '\uFD00': '\u062D\u064A',
  14365. '\uFD01': '\u062C\u0649',
  14366. '\uFD02': '\u062C\u064A',
  14367. '\uFD03': '\u062E\u0649',
  14368. '\uFD04': '\u062E\u064A',
  14369. '\uFD05': '\u0635\u0649',
  14370. '\uFD06': '\u0635\u064A',
  14371. '\uFD07': '\u0636\u0649',
  14372. '\uFD08': '\u0636\u064A',
  14373. '\uFD09': '\u0634\u062C',
  14374. '\uFD0A': '\u0634\u062D',
  14375. '\uFD0B': '\u0634\u062E',
  14376. '\uFD0C': '\u0634\u0645',
  14377. '\uFD0D': '\u0634\u0631',
  14378. '\uFD0E': '\u0633\u0631',
  14379. '\uFD0F': '\u0635\u0631',
  14380. '\uFD10': '\u0636\u0631',
  14381. '\uFD11': '\u0637\u0649',
  14382. '\uFD12': '\u0637\u064A',
  14383. '\uFD13': '\u0639\u0649',
  14384. '\uFD14': '\u0639\u064A',
  14385. '\uFD15': '\u063A\u0649',
  14386. '\uFD16': '\u063A\u064A',
  14387. '\uFD17': '\u0633\u0649',
  14388. '\uFD18': '\u0633\u064A',
  14389. '\uFD19': '\u0634\u0649',
  14390. '\uFD1A': '\u0634\u064A',
  14391. '\uFD1B': '\u062D\u0649',
  14392. '\uFD1C': '\u062D\u064A',
  14393. '\uFD1D': '\u062C\u0649',
  14394. '\uFD1E': '\u062C\u064A',
  14395. '\uFD1F': '\u062E\u0649',
  14396. '\uFD20': '\u062E\u064A',
  14397. '\uFD21': '\u0635\u0649',
  14398. '\uFD22': '\u0635\u064A',
  14399. '\uFD23': '\u0636\u0649',
  14400. '\uFD24': '\u0636\u064A',
  14401. '\uFD25': '\u0634\u062C',
  14402. '\uFD26': '\u0634\u062D',
  14403. '\uFD27': '\u0634\u062E',
  14404. '\uFD28': '\u0634\u0645',
  14405. '\uFD29': '\u0634\u0631',
  14406. '\uFD2A': '\u0633\u0631',
  14407. '\uFD2B': '\u0635\u0631',
  14408. '\uFD2C': '\u0636\u0631',
  14409. '\uFD2D': '\u0634\u062C',
  14410. '\uFD2E': '\u0634\u062D',
  14411. '\uFD2F': '\u0634\u062E',
  14412. '\uFD30': '\u0634\u0645',
  14413. '\uFD31': '\u0633\u0647',
  14414. '\uFD32': '\u0634\u0647',
  14415. '\uFD33': '\u0637\u0645',
  14416. '\uFD34': '\u0633\u062C',
  14417. '\uFD35': '\u0633\u062D',
  14418. '\uFD36': '\u0633\u062E',
  14419. '\uFD37': '\u0634\u062C',
  14420. '\uFD38': '\u0634\u062D',
  14421. '\uFD39': '\u0634\u062E',
  14422. '\uFD3A': '\u0637\u0645',
  14423. '\uFD3B': '\u0638\u0645',
  14424. '\uFD3C': '\u0627\u064B',
  14425. '\uFD3D': '\u0627\u064B',
  14426. '\uFD50': '\u062A\u062C\u0645',
  14427. '\uFD51': '\u062A\u062D\u062C',
  14428. '\uFD52': '\u062A\u062D\u062C',
  14429. '\uFD53': '\u062A\u062D\u0645',
  14430. '\uFD54': '\u062A\u062E\u0645',
  14431. '\uFD55': '\u062A\u0645\u062C',
  14432. '\uFD56': '\u062A\u0645\u062D',
  14433. '\uFD57': '\u062A\u0645\u062E',
  14434. '\uFD58': '\u062C\u0645\u062D',
  14435. '\uFD59': '\u062C\u0645\u062D',
  14436. '\uFD5A': '\u062D\u0645\u064A',
  14437. '\uFD5B': '\u062D\u0645\u0649',
  14438. '\uFD5C': '\u0633\u062D\u062C',
  14439. '\uFD5D': '\u0633\u062C\u062D',
  14440. '\uFD5E': '\u0633\u062C\u0649',
  14441. '\uFD5F': '\u0633\u0645\u062D',
  14442. '\uFD60': '\u0633\u0645\u062D',
  14443. '\uFD61': '\u0633\u0645\u062C',
  14444. '\uFD62': '\u0633\u0645\u0645',
  14445. '\uFD63': '\u0633\u0645\u0645',
  14446. '\uFD64': '\u0635\u062D\u062D',
  14447. '\uFD65': '\u0635\u062D\u062D',
  14448. '\uFD66': '\u0635\u0645\u0645',
  14449. '\uFD67': '\u0634\u062D\u0645',
  14450. '\uFD68': '\u0634\u062D\u0645',
  14451. '\uFD69': '\u0634\u062C\u064A',
  14452. '\uFD6A': '\u0634\u0645\u062E',
  14453. '\uFD6B': '\u0634\u0645\u062E',
  14454. '\uFD6C': '\u0634\u0645\u0645',
  14455. '\uFD6D': '\u0634\u0645\u0645',
  14456. '\uFD6E': '\u0636\u062D\u0649',
  14457. '\uFD6F': '\u0636\u062E\u0645',
  14458. '\uFD70': '\u0636\u062E\u0645',
  14459. '\uFD71': '\u0637\u0645\u062D',
  14460. '\uFD72': '\u0637\u0645\u062D',
  14461. '\uFD73': '\u0637\u0645\u0645',
  14462. '\uFD74': '\u0637\u0645\u064A',
  14463. '\uFD75': '\u0639\u062C\u0645',
  14464. '\uFD76': '\u0639\u0645\u0645',
  14465. '\uFD77': '\u0639\u0645\u0645',
  14466. '\uFD78': '\u0639\u0645\u0649',
  14467. '\uFD79': '\u063A\u0645\u0645',
  14468. '\uFD7A': '\u063A\u0645\u064A',
  14469. '\uFD7B': '\u063A\u0645\u0649',
  14470. '\uFD7C': '\u0641\u062E\u0645',
  14471. '\uFD7D': '\u0641\u062E\u0645',
  14472. '\uFD7E': '\u0642\u0645\u062D',
  14473. '\uFD7F': '\u0642\u0645\u0645',
  14474. '\uFD80': '\u0644\u062D\u0645',
  14475. '\uFD81': '\u0644\u062D\u064A',
  14476. '\uFD82': '\u0644\u062D\u0649',
  14477. '\uFD83': '\u0644\u062C\u062C',
  14478. '\uFD84': '\u0644\u062C\u062C',
  14479. '\uFD85': '\u0644\u062E\u0645',
  14480. '\uFD86': '\u0644\u062E\u0645',
  14481. '\uFD87': '\u0644\u0645\u062D',
  14482. '\uFD88': '\u0644\u0645\u062D',
  14483. '\uFD89': '\u0645\u062D\u062C',
  14484. '\uFD8A': '\u0645\u062D\u0645',
  14485. '\uFD8B': '\u0645\u062D\u064A',
  14486. '\uFD8C': '\u0645\u062C\u062D',
  14487. '\uFD8D': '\u0645\u062C\u0645',
  14488. '\uFD8E': '\u0645\u062E\u062C',
  14489. '\uFD8F': '\u0645\u062E\u0645',
  14490. '\uFD92': '\u0645\u062C\u062E',
  14491. '\uFD93': '\u0647\u0645\u062C',
  14492. '\uFD94': '\u0647\u0645\u0645',
  14493. '\uFD95': '\u0646\u062D\u0645',
  14494. '\uFD96': '\u0646\u062D\u0649',
  14495. '\uFD97': '\u0646\u062C\u0645',
  14496. '\uFD98': '\u0646\u062C\u0645',
  14497. '\uFD99': '\u0646\u062C\u0649',
  14498. '\uFD9A': '\u0646\u0645\u064A',
  14499. '\uFD9B': '\u0646\u0645\u0649',
  14500. '\uFD9C': '\u064A\u0645\u0645',
  14501. '\uFD9D': '\u064A\u0645\u0645',
  14502. '\uFD9E': '\u0628\u062E\u064A',
  14503. '\uFD9F': '\u062A\u062C\u064A',
  14504. '\uFDA0': '\u062A\u062C\u0649',
  14505. '\uFDA1': '\u062A\u062E\u064A',
  14506. '\uFDA2': '\u062A\u062E\u0649',
  14507. '\uFDA3': '\u062A\u0645\u064A',
  14508. '\uFDA4': '\u062A\u0645\u0649',
  14509. '\uFDA5': '\u062C\u0645\u064A',
  14510. '\uFDA6': '\u062C\u062D\u0649',
  14511. '\uFDA7': '\u062C\u0645\u0649',
  14512. '\uFDA8': '\u0633\u062E\u0649',
  14513. '\uFDA9': '\u0635\u062D\u064A',
  14514. '\uFDAA': '\u0634\u062D\u064A',
  14515. '\uFDAB': '\u0636\u062D\u064A',
  14516. '\uFDAC': '\u0644\u062C\u064A',
  14517. '\uFDAD': '\u0644\u0645\u064A',
  14518. '\uFDAE': '\u064A\u062D\u064A',
  14519. '\uFDAF': '\u064A\u062C\u064A',
  14520. '\uFDB0': '\u064A\u0645\u064A',
  14521. '\uFDB1': '\u0645\u0645\u064A',
  14522. '\uFDB2': '\u0642\u0645\u064A',
  14523. '\uFDB3': '\u0646\u062D\u064A',
  14524. '\uFDB4': '\u0642\u0645\u062D',
  14525. '\uFDB5': '\u0644\u062D\u0645',
  14526. '\uFDB6': '\u0639\u0645\u064A',
  14527. '\uFDB7': '\u0643\u0645\u064A',
  14528. '\uFDB8': '\u0646\u062C\u062D',
  14529. '\uFDB9': '\u0645\u062E\u064A',
  14530. '\uFDBA': '\u0644\u062C\u0645',
  14531. '\uFDBB': '\u0643\u0645\u0645',
  14532. '\uFDBC': '\u0644\u062C\u0645',
  14533. '\uFDBD': '\u0646\u062C\u062D',
  14534. '\uFDBE': '\u062C\u062D\u064A',
  14535. '\uFDBF': '\u062D\u062C\u064A',
  14536. '\uFDC0': '\u0645\u062C\u064A',
  14537. '\uFDC1': '\u0641\u0645\u064A',
  14538. '\uFDC2': '\u0628\u062D\u064A',
  14539. '\uFDC3': '\u0643\u0645\u0645',
  14540. '\uFDC4': '\u0639\u062C\u0645',
  14541. '\uFDC5': '\u0635\u0645\u0645',
  14542. '\uFDC6': '\u0633\u062E\u064A',
  14543. '\uFDC7': '\u0646\u062C\u064A',
  14544. '\uFE49': '\u203E',
  14545. '\uFE4A': '\u203E',
  14546. '\uFE4B': '\u203E',
  14547. '\uFE4C': '\u203E',
  14548. '\uFE4D': '\u005F',
  14549. '\uFE4E': '\u005F',
  14550. '\uFE4F': '\u005F',
  14551. '\uFE80': '\u0621',
  14552. '\uFE81': '\u0622',
  14553. '\uFE82': '\u0622',
  14554. '\uFE83': '\u0623',
  14555. '\uFE84': '\u0623',
  14556. '\uFE85': '\u0624',
  14557. '\uFE86': '\u0624',
  14558. '\uFE87': '\u0625',
  14559. '\uFE88': '\u0625',
  14560. '\uFE89': '\u0626',
  14561. '\uFE8A': '\u0626',
  14562. '\uFE8B': '\u0626',
  14563. '\uFE8C': '\u0626',
  14564. '\uFE8D': '\u0627',
  14565. '\uFE8E': '\u0627',
  14566. '\uFE8F': '\u0628',
  14567. '\uFE90': '\u0628',
  14568. '\uFE91': '\u0628',
  14569. '\uFE92': '\u0628',
  14570. '\uFE93': '\u0629',
  14571. '\uFE94': '\u0629',
  14572. '\uFE95': '\u062A',
  14573. '\uFE96': '\u062A',
  14574. '\uFE97': '\u062A',
  14575. '\uFE98': '\u062A',
  14576. '\uFE99': '\u062B',
  14577. '\uFE9A': '\u062B',
  14578. '\uFE9B': '\u062B',
  14579. '\uFE9C': '\u062B',
  14580. '\uFE9D': '\u062C',
  14581. '\uFE9E': '\u062C',
  14582. '\uFE9F': '\u062C',
  14583. '\uFEA0': '\u062C',
  14584. '\uFEA1': '\u062D',
  14585. '\uFEA2': '\u062D',
  14586. '\uFEA3': '\u062D',
  14587. '\uFEA4': '\u062D',
  14588. '\uFEA5': '\u062E',
  14589. '\uFEA6': '\u062E',
  14590. '\uFEA7': '\u062E',
  14591. '\uFEA8': '\u062E',
  14592. '\uFEA9': '\u062F',
  14593. '\uFEAA': '\u062F',
  14594. '\uFEAB': '\u0630',
  14595. '\uFEAC': '\u0630',
  14596. '\uFEAD': '\u0631',
  14597. '\uFEAE': '\u0631',
  14598. '\uFEAF': '\u0632',
  14599. '\uFEB0': '\u0632',
  14600. '\uFEB1': '\u0633',
  14601. '\uFEB2': '\u0633',
  14602. '\uFEB3': '\u0633',
  14603. '\uFEB4': '\u0633',
  14604. '\uFEB5': '\u0634',
  14605. '\uFEB6': '\u0634',
  14606. '\uFEB7': '\u0634',
  14607. '\uFEB8': '\u0634',
  14608. '\uFEB9': '\u0635',
  14609. '\uFEBA': '\u0635',
  14610. '\uFEBB': '\u0635',
  14611. '\uFEBC': '\u0635',
  14612. '\uFEBD': '\u0636',
  14613. '\uFEBE': '\u0636',
  14614. '\uFEBF': '\u0636',
  14615. '\uFEC0': '\u0636',
  14616. '\uFEC1': '\u0637',
  14617. '\uFEC2': '\u0637',
  14618. '\uFEC3': '\u0637',
  14619. '\uFEC4': '\u0637',
  14620. '\uFEC5': '\u0638',
  14621. '\uFEC6': '\u0638',
  14622. '\uFEC7': '\u0638',
  14623. '\uFEC8': '\u0638',
  14624. '\uFEC9': '\u0639',
  14625. '\uFECA': '\u0639',
  14626. '\uFECB': '\u0639',
  14627. '\uFECC': '\u0639',
  14628. '\uFECD': '\u063A',
  14629. '\uFECE': '\u063A',
  14630. '\uFECF': '\u063A',
  14631. '\uFED0': '\u063A',
  14632. '\uFED1': '\u0641',
  14633. '\uFED2': '\u0641',
  14634. '\uFED3': '\u0641',
  14635. '\uFED4': '\u0641',
  14636. '\uFED5': '\u0642',
  14637. '\uFED6': '\u0642',
  14638. '\uFED7': '\u0642',
  14639. '\uFED8': '\u0642',
  14640. '\uFED9': '\u0643',
  14641. '\uFEDA': '\u0643',
  14642. '\uFEDB': '\u0643',
  14643. '\uFEDC': '\u0643',
  14644. '\uFEDD': '\u0644',
  14645. '\uFEDE': '\u0644',
  14646. '\uFEDF': '\u0644',
  14647. '\uFEE0': '\u0644',
  14648. '\uFEE1': '\u0645',
  14649. '\uFEE2': '\u0645',
  14650. '\uFEE3': '\u0645',
  14651. '\uFEE4': '\u0645',
  14652. '\uFEE5': '\u0646',
  14653. '\uFEE6': '\u0646',
  14654. '\uFEE7': '\u0646',
  14655. '\uFEE8': '\u0646',
  14656. '\uFEE9': '\u0647',
  14657. '\uFEEA': '\u0647',
  14658. '\uFEEB': '\u0647',
  14659. '\uFEEC': '\u0647',
  14660. '\uFEED': '\u0648',
  14661. '\uFEEE': '\u0648',
  14662. '\uFEEF': '\u0649',
  14663. '\uFEF0': '\u0649',
  14664. '\uFEF1': '\u064A',
  14665. '\uFEF2': '\u064A',
  14666. '\uFEF3': '\u064A',
  14667. '\uFEF4': '\u064A',
  14668. '\uFEF5': '\u0644\u0622',
  14669. '\uFEF6': '\u0644\u0622',
  14670. '\uFEF7': '\u0644\u0623',
  14671. '\uFEF8': '\u0644\u0623',
  14672. '\uFEF9': '\u0644\u0625',
  14673. '\uFEFA': '\u0644\u0625',
  14674. '\uFEFB': '\u0644\u0627',
  14675. '\uFEFC': '\u0644\u0627'
  14676. };
  14677. function reverseIfRtl(chars) {
  14678. var charsLength = chars.length;
  14679. //reverse an arabic ligature
  14680. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14681. return chars;
  14682. }
  14683. var s = '';
  14684. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14685. s += chars[ii];
  14686. }
  14687. return s;
  14688. }
  14689. function adjustWidths(properties) {
  14690. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14691. return;
  14692. }
  14693. // adjusting width to fontMatrix scale
  14694. var scale = 0.001 / properties.fontMatrix[0];
  14695. var glyphsWidths = properties.widths;
  14696. for (var glyph in glyphsWidths) {
  14697. glyphsWidths[glyph] *= scale;
  14698. }
  14699. properties.defaultWidth *= scale;
  14700. }
  14701. function getFontType(type, subtype) {
  14702. switch (type) {
  14703. case 'Type1':
  14704. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14705. case 'CIDFontType0':
  14706. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14707. FontType.CIDFONTTYPE0;
  14708. case 'OpenType':
  14709. return FontType.OPENTYPE;
  14710. case 'TrueType':
  14711. return FontType.TRUETYPE;
  14712. case 'CIDFontType2':
  14713. return FontType.CIDFONTTYPE2;
  14714. case 'MMType1':
  14715. return FontType.MMTYPE1;
  14716. case 'Type0':
  14717. return FontType.TYPE0;
  14718. default:
  14719. return FontType.UNKNOWN;
  14720. }
  14721. }
  14722. var Glyph = (function GlyphClosure() {
  14723. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14724. this.fontChar = fontChar;
  14725. this.unicode = unicode;
  14726. this.accent = accent;
  14727. this.width = width;
  14728. this.vmetric = vmetric;
  14729. this.operatorListId = operatorListId;
  14730. }
  14731. Glyph.prototype.matchesForCache =
  14732. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14733. return this.fontChar === fontChar &&
  14734. this.unicode === unicode &&
  14735. this.accent === accent &&
  14736. this.width === width &&
  14737. this.vmetric === vmetric &&
  14738. this.operatorListId === operatorListId;
  14739. };
  14740. return Glyph;
  14741. })();
  14742. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14743. function ToUnicodeMap(cmap) {
  14744. // The elements of this._map can be integers or strings, depending on how
  14745. // |cmap| was created.
  14746. this._map = cmap;
  14747. }
  14748. ToUnicodeMap.prototype = {
  14749. get length() {
  14750. return this._map.length;
  14751. },
  14752. forEach: function(callback) {
  14753. for (var charCode in this._map) {
  14754. callback(charCode, this._map[charCode].charCodeAt(0));
  14755. }
  14756. },
  14757. get: function(i) {
  14758. return this._map[i];
  14759. },
  14760. charCodeOf: function(v) {
  14761. return this._map.indexOf(v);
  14762. }
  14763. };
  14764. return ToUnicodeMap;
  14765. })();
  14766. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14767. function IdentityToUnicodeMap(firstChar, lastChar) {
  14768. this.firstChar = firstChar;
  14769. this.lastChar = lastChar;
  14770. }
  14771. IdentityToUnicodeMap.prototype = {
  14772. get length() {
  14773. error('should not access .length');
  14774. },
  14775. forEach: function (callback) {
  14776. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  14777. callback(i, i);
  14778. }
  14779. },
  14780. get: function (i) {
  14781. if (this.firstChar <= i && i <= this.lastChar) {
  14782. return String.fromCharCode(i);
  14783. }
  14784. return undefined;
  14785. },
  14786. charCodeOf: function (v) {
  14787. error('should not call .charCodeOf');
  14788. }
  14789. };
  14790. return IdentityToUnicodeMap;
  14791. })();
  14792. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  14793. function writeInt16(dest, offset, num) {
  14794. dest[offset] = (num >> 8) & 0xFF;
  14795. dest[offset + 1] = num & 0xFF;
  14796. }
  14797. function writeInt32(dest, offset, num) {
  14798. dest[offset] = (num >> 24) & 0xFF;
  14799. dest[offset + 1] = (num >> 16) & 0xFF;
  14800. dest[offset + 2] = (num >> 8) & 0xFF;
  14801. dest[offset + 3] = num & 0xFF;
  14802. }
  14803. function writeData(dest, offset, data) {
  14804. var i, ii;
  14805. if (data instanceof Uint8Array) {
  14806. dest.set(data, offset);
  14807. } else if (typeof data === 'string') {
  14808. for (i = 0, ii = data.length; i < ii; i++) {
  14809. dest[offset++] = data.charCodeAt(i) & 0xFF;
  14810. }
  14811. } else {
  14812. // treating everything else as array
  14813. for (i = 0, ii = data.length; i < ii; i++) {
  14814. dest[offset++] = data[i] & 0xFF;
  14815. }
  14816. }
  14817. }
  14818. function OpenTypeFileBuilder(sfnt) {
  14819. this.sfnt = sfnt;
  14820. this.tables = Object.create(null);
  14821. }
  14822. OpenTypeFileBuilder.getSearchParams =
  14823. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  14824. var maxPower2 = 1, log2 = 0;
  14825. while ((maxPower2 ^ entriesCount) > maxPower2) {
  14826. maxPower2 <<= 1;
  14827. log2++;
  14828. }
  14829. var searchRange = maxPower2 * entrySize;
  14830. return {
  14831. range: searchRange,
  14832. entry: log2,
  14833. rangeShift: entrySize * entriesCount - searchRange
  14834. };
  14835. };
  14836. var OTF_HEADER_SIZE = 12;
  14837. var OTF_TABLE_ENTRY_SIZE = 16;
  14838. OpenTypeFileBuilder.prototype = {
  14839. toArray: function OpenTypeFileBuilder_toArray() {
  14840. var sfnt = this.sfnt;
  14841. // Tables needs to be written by ascendant alphabetic order
  14842. var tables = this.tables;
  14843. var tablesNames = Object.keys(tables);
  14844. tablesNames.sort();
  14845. var numTables = tablesNames.length;
  14846. var i, j, jj, table, tableName;
  14847. // layout the tables data
  14848. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  14849. var tableOffsets = [offset];
  14850. for (i = 0; i < numTables; i++) {
  14851. table = tables[tablesNames[i]];
  14852. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  14853. offset += paddedLength;
  14854. tableOffsets.push(offset);
  14855. }
  14856. var file = new Uint8Array(offset);
  14857. // write the table data first (mostly for checksum)
  14858. for (i = 0; i < numTables; i++) {
  14859. table = tables[tablesNames[i]];
  14860. writeData(file, tableOffsets[i], table);
  14861. }
  14862. // sfnt version (4 bytes)
  14863. if (sfnt === 'true') {
  14864. // Windows hates the Mac TrueType sfnt version number
  14865. sfnt = string32(0x00010000);
  14866. }
  14867. file[0] = sfnt.charCodeAt(0) & 0xFF;
  14868. file[1] = sfnt.charCodeAt(1) & 0xFF;
  14869. file[2] = sfnt.charCodeAt(2) & 0xFF;
  14870. file[3] = sfnt.charCodeAt(3) & 0xFF;
  14871. // numTables (2 bytes)
  14872. writeInt16(file, 4, numTables);
  14873. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  14874. // searchRange (2 bytes)
  14875. writeInt16(file, 6, searchParams.range);
  14876. // entrySelector (2 bytes)
  14877. writeInt16(file, 8, searchParams.entry);
  14878. // rangeShift (2 bytes)
  14879. writeInt16(file, 10, searchParams.rangeShift);
  14880. offset = OTF_HEADER_SIZE;
  14881. // writing table entries
  14882. for (i = 0; i < numTables; i++) {
  14883. tableName = tablesNames[i];
  14884. file[offset] = tableName.charCodeAt(0) & 0xFF;
  14885. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  14886. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  14887. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  14888. // checksum
  14889. var checksum = 0;
  14890. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  14891. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  14892. (file[j + 2] << 8) + file[j + 3];
  14893. checksum = (checksum + quad) | 0;
  14894. }
  14895. writeInt32(file, offset + 4, checksum);
  14896. // offset
  14897. writeInt32(file, offset + 8, tableOffsets[i]);
  14898. // length
  14899. writeInt32(file, offset + 12, tables[tableName].length);
  14900. offset += OTF_TABLE_ENTRY_SIZE;
  14901. }
  14902. return file;
  14903. },
  14904. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  14905. if (tag in this.tables) {
  14906. throw new Error('Table ' + tag + ' already exists');
  14907. }
  14908. this.tables[tag] = data;
  14909. }
  14910. };
  14911. return OpenTypeFileBuilder;
  14912. })();
  14913. /**
  14914. * 'Font' is the class the outside world should use, it encapsulate all the font
  14915. * decoding logics whatever type it is (assuming the font type is supported).
  14916. *
  14917. * For example to read a Type1 font and to attach it to the document:
  14918. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  14919. * type1Font.bind();
  14920. */
  14921. var Font = (function FontClosure() {
  14922. function Font(name, file, properties) {
  14923. var charCode, glyphName;
  14924. this.name = name;
  14925. this.loadedName = properties.loadedName;
  14926. this.isType3Font = properties.isType3Font;
  14927. this.sizes = [];
  14928. this.glyphCache = {};
  14929. var names = name.split('+');
  14930. names = names.length > 1 ? names[1] : names[0];
  14931. names = names.split(/[-,_]/g)[0];
  14932. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  14933. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  14934. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  14935. var type = properties.type;
  14936. var subtype = properties.subtype;
  14937. this.type = type;
  14938. this.fallbackName = (this.isMonospace ? 'monospace' :
  14939. (this.isSerifFont ? 'serif' : 'sans-serif'));
  14940. this.differences = properties.differences;
  14941. this.widths = properties.widths;
  14942. this.defaultWidth = properties.defaultWidth;
  14943. this.composite = properties.composite;
  14944. this.wideChars = properties.wideChars;
  14945. this.cMap = properties.cMap;
  14946. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  14947. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  14948. this.fontMatrix = properties.fontMatrix;
  14949. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  14950. this.toFontChar = [];
  14951. if (properties.type === 'Type3') {
  14952. for (charCode = 0; charCode < 256; charCode++) {
  14953. this.toFontChar[charCode] = (this.differences[charCode] ||
  14954. properties.defaultEncoding[charCode]);
  14955. }
  14956. this.fontType = FontType.TYPE3;
  14957. return;
  14958. }
  14959. this.cidEncoding = properties.cidEncoding;
  14960. this.vertical = properties.vertical;
  14961. if (this.vertical) {
  14962. this.vmetrics = properties.vmetrics;
  14963. this.defaultVMetrics = properties.defaultVMetrics;
  14964. }
  14965. if (!file || file.isEmpty) {
  14966. if (file) {
  14967. // Some bad PDF generators will include empty font files,
  14968. // attempting to recover by assuming that no file exists.
  14969. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  14970. }
  14971. this.missingFile = true;
  14972. // The file data is not specified. Trying to fix the font name
  14973. // to be used with the canvas.font.
  14974. var fontName = name.replace(/[,_]/g, '-');
  14975. var isStandardFont = fontName in stdFontMap;
  14976. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  14977. this.bold = (fontName.search(/bold/gi) !== -1);
  14978. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  14979. (fontName.search(/italic/gi) !== -1));
  14980. // Use 'name' instead of 'fontName' here because the original
  14981. // name ArialBlack for example will be replaced by Helvetica.
  14982. this.black = (name.search(/Black/g) !== -1);
  14983. // if at least one width is present, remeasure all chars when exists
  14984. this.remeasure = Object.keys(this.widths).length > 0;
  14985. if (isStandardFont && type === 'CIDFontType2' &&
  14986. properties.cidEncoding.indexOf('Identity-') === 0) {
  14987. // Standard fonts might be embedded as CID font without glyph mapping.
  14988. // Building one based on GlyphMapForStandardFonts.
  14989. var map = [];
  14990. for (var code in GlyphMapForStandardFonts) {
  14991. map[+code] = GlyphMapForStandardFonts[code];
  14992. }
  14993. this.toFontChar = map;
  14994. this.toUnicode = new ToUnicodeMap(map);
  14995. } else if (/Symbol/i.test(fontName)) {
  14996. var symbols = Encodings.SymbolSetEncoding;
  14997. for (charCode in symbols) {
  14998. var fontChar = GlyphsUnicode[symbols[charCode]];
  14999. if (!fontChar) {
  15000. continue;
  15001. }
  15002. this.toFontChar[charCode] = fontChar;
  15003. }
  15004. } else if (isStandardFont) {
  15005. this.toFontChar = [];
  15006. for (charCode in properties.defaultEncoding) {
  15007. glyphName = (properties.differences[charCode] ||
  15008. properties.defaultEncoding[charCode]);
  15009. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15010. }
  15011. } else {
  15012. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15013. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15014. if (notCidFont) {
  15015. glyphName = (properties.differences[charCode] ||
  15016. properties.defaultEncoding[charCode]);
  15017. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15018. }
  15019. this.toFontChar[charCode] = unicodeCharCode;
  15020. }.bind(this));
  15021. }
  15022. this.loadedName = fontName.split('-')[0];
  15023. this.loading = false;
  15024. this.fontType = getFontType(type, subtype);
  15025. return;
  15026. }
  15027. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15028. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15029. // Some TrueType fonts by mistake claim Type1C
  15030. if (isTrueTypeFile(file)) {
  15031. subtype = 'TrueType';
  15032. } else {
  15033. type = 'Type1';
  15034. }
  15035. }
  15036. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15037. type = 'CIDFontType0';
  15038. }
  15039. // XXX: Temporarily change the type for open type so we trigger a warning.
  15040. // This should be removed when we add support for open type.
  15041. if (subtype === 'OpenType') {
  15042. type = 'OpenType';
  15043. }
  15044. var data;
  15045. switch (type) {
  15046. case 'Type1':
  15047. case 'CIDFontType0':
  15048. this.mimetype = 'font/opentype';
  15049. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15050. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15051. adjustWidths(properties);
  15052. // Wrap the CFF data inside an OTF font file
  15053. data = this.convert(name, cff, properties);
  15054. break;
  15055. case 'OpenType':
  15056. case 'TrueType':
  15057. case 'CIDFontType2':
  15058. this.mimetype = 'font/opentype';
  15059. // Repair the TrueType file. It is can be damaged in the point of
  15060. // view of the sanitizer
  15061. data = this.checkAndRepair(name, file, properties);
  15062. if (this.isOpenType) {
  15063. type = 'OpenType';
  15064. }
  15065. break;
  15066. default:
  15067. error('Font ' + type + ' is not supported');
  15068. break;
  15069. }
  15070. this.data = data;
  15071. this.fontType = getFontType(type, subtype);
  15072. // Transfer some properties again that could change during font conversion
  15073. this.fontMatrix = properties.fontMatrix;
  15074. this.widths = properties.widths;
  15075. this.defaultWidth = properties.defaultWidth;
  15076. this.encoding = properties.baseEncoding;
  15077. this.seacMap = properties.seacMap;
  15078. this.loading = true;
  15079. }
  15080. Font.getFontID = (function () {
  15081. var ID = 1;
  15082. return function Font_getFontID() {
  15083. return String(ID++);
  15084. };
  15085. })();
  15086. function int16(b0, b1) {
  15087. return (b0 << 8) + b1;
  15088. }
  15089. function int32(b0, b1, b2, b3) {
  15090. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15091. }
  15092. function string16(value) {
  15093. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15094. }
  15095. function safeString16(value) {
  15096. // clamp value to the 16-bit int range
  15097. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15098. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15099. }
  15100. function isTrueTypeFile(file) {
  15101. var header = file.peekBytes(4);
  15102. return readUint32(header, 0) === 0x00010000;
  15103. }
  15104. /**
  15105. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15106. * with their unicode value. It also moves char codes that are in known
  15107. * problematic locations.
  15108. * @return {Object} Two properties:
  15109. * 'toFontChar' - maps original char codes(the value that will be read
  15110. * from commands such as show text) to the char codes that will be used in the
  15111. * font that we build
  15112. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15113. */
  15114. function adjustMapping(charCodeToGlyphId, properties) {
  15115. var toUnicode = properties.toUnicode;
  15116. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15117. var isIdentityUnicode =
  15118. properties.toUnicode instanceof IdentityToUnicodeMap;
  15119. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15120. var newMap = Object.create(null);
  15121. var toFontChar = [];
  15122. var usedFontCharCodes = [];
  15123. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15124. for (var originalCharCode in charCodeToGlyphId) {
  15125. originalCharCode |= 0;
  15126. var glyphId = charCodeToGlyphId[originalCharCode];
  15127. var fontCharCode = originalCharCode;
  15128. // First try to map the value to a unicode position if a non identity map
  15129. // was created.
  15130. if (!isIdentityUnicode) {
  15131. if (toUnicode.get(originalCharCode) !== undefined) {
  15132. var unicode = toUnicode.get(fontCharCode);
  15133. // TODO: Try to map ligatures to the correct spot.
  15134. if (unicode.length === 1) {
  15135. fontCharCode = unicode.charCodeAt(0);
  15136. }
  15137. } else if (isCidFontType2) {
  15138. // For CIDFontType2, move characters not present in toUnicode
  15139. // to the private use area (fixes bug 1028735 and issue 4881).
  15140. fontCharCode = nextAvailableFontCharCode;
  15141. }
  15142. }
  15143. // Try to move control characters, special characters and already mapped
  15144. // characters to the private use area since they will not be drawn by
  15145. // canvas if left in their current position. Also, move characters if the
  15146. // font was symbolic and there is only an identity unicode map since the
  15147. // characters probably aren't in the correct position (fixes an issue
  15148. // with firefox and thuluthfont).
  15149. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15150. fontCharCode <= 0x1f || // Control chars
  15151. fontCharCode === 0x7F || // Control char
  15152. fontCharCode === 0xAD || // Soft hyphen
  15153. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15154. // Prevent drawing characters in the specials unicode block.
  15155. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15156. (isSymbolic && isIdentityUnicode)) &&
  15157. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15158. // Loop to try and find a free spot in the private use area.
  15159. do {
  15160. fontCharCode = nextAvailableFontCharCode++;
  15161. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15162. fontCharCode = 0xF020;
  15163. nextAvailableFontCharCode = fontCharCode + 1;
  15164. }
  15165. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15166. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15167. }
  15168. newMap[fontCharCode] = glyphId;
  15169. toFontChar[originalCharCode] = fontCharCode;
  15170. usedFontCharCodes[fontCharCode] = true;
  15171. }
  15172. return {
  15173. toFontChar: toFontChar,
  15174. charCodeToGlyphId: newMap,
  15175. nextAvailableFontCharCode: nextAvailableFontCharCode
  15176. };
  15177. }
  15178. function getRanges(glyphs) {
  15179. // Array.sort() sorts by characters, not numerically, so convert to an
  15180. // array of characters.
  15181. var codes = [];
  15182. for (var charCode in glyphs) {
  15183. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15184. }
  15185. codes.sort(function fontGetRangesSort(a, b) {
  15186. return a.fontCharCode - b.fontCharCode;
  15187. });
  15188. // Split the sorted codes into ranges.
  15189. var ranges = [];
  15190. var length = codes.length;
  15191. for (var n = 0; n < length; ) {
  15192. var start = codes[n].fontCharCode;
  15193. var codeIndices = [codes[n].glyphId];
  15194. ++n;
  15195. var end = start;
  15196. while (n < length && end + 1 === codes[n].fontCharCode) {
  15197. codeIndices.push(codes[n].glyphId);
  15198. ++end;
  15199. ++n;
  15200. if (end === 0xFFFF) {
  15201. break;
  15202. }
  15203. }
  15204. ranges.push([start, end, codeIndices]);
  15205. }
  15206. return ranges;
  15207. }
  15208. function createCmapTable(glyphs) {
  15209. var ranges = getRanges(glyphs);
  15210. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15211. var cmap = '\x00\x00' + // version
  15212. string16(numTables) + // numTables
  15213. '\x00\x03' + // platformID
  15214. '\x00\x01' + // encodingID
  15215. string32(4 + numTables * 8); // start of the table record
  15216. var i, ii, j, jj;
  15217. for (i = ranges.length - 1; i >= 0; --i) {
  15218. if (ranges[i][0] <= 0xFFFF) { break; }
  15219. }
  15220. var bmpLength = i + 1;
  15221. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15222. ranges[i][1] = 0xFFFE;
  15223. }
  15224. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15225. var segCount = bmpLength + trailingRangesCount;
  15226. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15227. // Fill up the 4 parallel arrays describing the segments.
  15228. var startCount = '';
  15229. var endCount = '';
  15230. var idDeltas = '';
  15231. var idRangeOffsets = '';
  15232. var glyphsIds = '';
  15233. var bias = 0;
  15234. var range, start, end, codes;
  15235. for (i = 0, ii = bmpLength; i < ii; i++) {
  15236. range = ranges[i];
  15237. start = range[0];
  15238. end = range[1];
  15239. startCount += string16(start);
  15240. endCount += string16(end);
  15241. codes = range[2];
  15242. var contiguous = true;
  15243. for (j = 1, jj = codes.length; j < jj; ++j) {
  15244. if (codes[j] !== codes[j - 1] + 1) {
  15245. contiguous = false;
  15246. break;
  15247. }
  15248. }
  15249. if (!contiguous) {
  15250. var offset = (segCount - i) * 2 + bias * 2;
  15251. bias += (end - start + 1);
  15252. idDeltas += string16(0);
  15253. idRangeOffsets += string16(offset);
  15254. for (j = 0, jj = codes.length; j < jj; ++j) {
  15255. glyphsIds += string16(codes[j]);
  15256. }
  15257. } else {
  15258. var startCode = codes[0];
  15259. idDeltas += string16((startCode - start) & 0xFFFF);
  15260. idRangeOffsets += string16(0);
  15261. }
  15262. }
  15263. if (trailingRangesCount > 0) {
  15264. endCount += '\xFF\xFF';
  15265. startCount += '\xFF\xFF';
  15266. idDeltas += '\x00\x01';
  15267. idRangeOffsets += '\x00\x00';
  15268. }
  15269. var format314 = '\x00\x00' + // language
  15270. string16(2 * segCount) +
  15271. string16(searchParams.range) +
  15272. string16(searchParams.entry) +
  15273. string16(searchParams.rangeShift) +
  15274. endCount + '\x00\x00' + startCount +
  15275. idDeltas + idRangeOffsets + glyphsIds;
  15276. var format31012 = '';
  15277. var header31012 = '';
  15278. if (numTables > 1) {
  15279. cmap += '\x00\x03' + // platformID
  15280. '\x00\x0A' + // encodingID
  15281. string32(4 + numTables * 8 +
  15282. 4 + format314.length); // start of the table record
  15283. format31012 = '';
  15284. for (i = 0, ii = ranges.length; i < ii; i++) {
  15285. range = ranges[i];
  15286. start = range[0];
  15287. codes = range[2];
  15288. var code = codes[0];
  15289. for (j = 1, jj = codes.length; j < jj; ++j) {
  15290. if (codes[j] !== codes[j - 1] + 1) {
  15291. end = range[0] + j - 1;
  15292. format31012 += string32(start) + // startCharCode
  15293. string32(end) + // endCharCode
  15294. string32(code); // startGlyphID
  15295. start = end + 1;
  15296. code = codes[j];
  15297. }
  15298. }
  15299. format31012 += string32(start) + // startCharCode
  15300. string32(range[1]) + // endCharCode
  15301. string32(code); // startGlyphID
  15302. }
  15303. header31012 = '\x00\x0C' + // format
  15304. '\x00\x00' + // reserved
  15305. string32(format31012.length + 16) + // length
  15306. '\x00\x00\x00\x00' + // language
  15307. string32(format31012.length / 12); // nGroups
  15308. }
  15309. return cmap + '\x00\x04' + // format
  15310. string16(format314.length + 4) + // length
  15311. format314 + header31012 + format31012;
  15312. }
  15313. function validateOS2Table(os2) {
  15314. var stream = new Stream(os2.data);
  15315. var version = stream.getUint16();
  15316. // TODO verify all OS/2 tables fields, but currently we validate only those
  15317. // that give us issues
  15318. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15319. var selection = stream.getUint16();
  15320. if (version < 4 && (selection & 0x0300)) {
  15321. return false;
  15322. }
  15323. var firstChar = stream.getUint16();
  15324. var lastChar = stream.getUint16();
  15325. if (firstChar > lastChar) {
  15326. return false;
  15327. }
  15328. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15329. var usWinAscent = stream.getUint16();
  15330. if (usWinAscent === 0) { // makes font unreadable by windows
  15331. return false;
  15332. }
  15333. // OS/2 appears to be valid, resetting some fields
  15334. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15335. return true;
  15336. }
  15337. function createOS2Table(properties, charstrings, override) {
  15338. override = override || {
  15339. unitsPerEm: 0,
  15340. yMax: 0,
  15341. yMin: 0,
  15342. ascent: 0,
  15343. descent: 0
  15344. };
  15345. var ulUnicodeRange1 = 0;
  15346. var ulUnicodeRange2 = 0;
  15347. var ulUnicodeRange3 = 0;
  15348. var ulUnicodeRange4 = 0;
  15349. var firstCharIndex = null;
  15350. var lastCharIndex = 0;
  15351. if (charstrings) {
  15352. for (var code in charstrings) {
  15353. code |= 0;
  15354. if (firstCharIndex > code || !firstCharIndex) {
  15355. firstCharIndex = code;
  15356. }
  15357. if (lastCharIndex < code) {
  15358. lastCharIndex = code;
  15359. }
  15360. var position = getUnicodeRangeFor(code);
  15361. if (position < 32) {
  15362. ulUnicodeRange1 |= 1 << position;
  15363. } else if (position < 64) {
  15364. ulUnicodeRange2 |= 1 << position - 32;
  15365. } else if (position < 96) {
  15366. ulUnicodeRange3 |= 1 << position - 64;
  15367. } else if (position < 123) {
  15368. ulUnicodeRange4 |= 1 << position - 96;
  15369. } else {
  15370. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15371. }
  15372. }
  15373. } else {
  15374. // TODO
  15375. firstCharIndex = 0;
  15376. lastCharIndex = 255;
  15377. }
  15378. var bbox = properties.bbox || [0, 0, 0, 0];
  15379. var unitsPerEm = (override.unitsPerEm ||
  15380. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15381. // if the font units differ to the PDF glyph space units
  15382. // then scale up the values
  15383. var scale = (properties.ascentScaled ? 1.0 :
  15384. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15385. var typoAscent = (override.ascent ||
  15386. Math.round(scale * (properties.ascent || bbox[3])));
  15387. var typoDescent = (override.descent ||
  15388. Math.round(scale * (properties.descent || bbox[1])));
  15389. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15390. typoDescent = -typoDescent; // fixing incorrect descent
  15391. }
  15392. var winAscent = override.yMax || typoAscent;
  15393. var winDescent = -override.yMin || -typoDescent;
  15394. return '\x00\x03' + // version
  15395. '\x02\x24' + // xAvgCharWidth
  15396. '\x01\xF4' + // usWeightClass
  15397. '\x00\x05' + // usWidthClass
  15398. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15399. '\x02\x8A' + // ySubscriptXSize
  15400. '\x02\xBB' + // ySubscriptYSize
  15401. '\x00\x00' + // ySubscriptXOffset
  15402. '\x00\x8C' + // ySubscriptYOffset
  15403. '\x02\x8A' + // ySuperScriptXSize
  15404. '\x02\xBB' + // ySuperScriptYSize
  15405. '\x00\x00' + // ySuperScriptXOffset
  15406. '\x01\xDF' + // ySuperScriptYOffset
  15407. '\x00\x31' + // yStrikeOutSize
  15408. '\x01\x02' + // yStrikeOutPosition
  15409. '\x00\x00' + // sFamilyClass
  15410. '\x00\x00\x06' +
  15411. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15412. '\x00\x00\x00\x00\x00\x00' + // Panose
  15413. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15414. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15415. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15416. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15417. '\x2A\x32\x31\x2A' + // achVendID
  15418. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15419. string16(firstCharIndex ||
  15420. properties.firstChar) + // usFirstCharIndex
  15421. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15422. string16(typoAscent) + // sTypoAscender
  15423. string16(typoDescent) + // sTypoDescender
  15424. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15425. string16(winAscent) + // usWinAscent
  15426. string16(winDescent) + // usWinDescent
  15427. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15428. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15429. string16(properties.xHeight) + // sxHeight
  15430. string16(properties.capHeight) + // sCapHeight
  15431. string16(0) + // usDefaultChar
  15432. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15433. '\x00\x03'; // usMaxContext
  15434. }
  15435. function createPostTable(properties) {
  15436. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15437. return ('\x00\x03\x00\x00' + // Version number
  15438. string32(angle) + // italicAngle
  15439. '\x00\x00' + // underlinePosition
  15440. '\x00\x00' + // underlineThickness
  15441. string32(properties.fixedPitch) + // isFixedPitch
  15442. '\x00\x00\x00\x00' + // minMemType42
  15443. '\x00\x00\x00\x00' + // maxMemType42
  15444. '\x00\x00\x00\x00' + // minMemType1
  15445. '\x00\x00\x00\x00'); // maxMemType1
  15446. }
  15447. function createNameTable(name, proto) {
  15448. if (!proto) {
  15449. proto = [[], []]; // no strings and unicode strings
  15450. }
  15451. var strings = [
  15452. proto[0][0] || 'Original licence', // 0.Copyright
  15453. proto[0][1] || name, // 1.Font family
  15454. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15455. proto[0][3] || 'uniqueID', // 3.Unique ID
  15456. proto[0][4] || name, // 4.Full font name
  15457. proto[0][5] || 'Version 0.11', // 5.Version
  15458. proto[0][6] || '', // 6.Postscript name
  15459. proto[0][7] || 'Unknown', // 7.Trademark
  15460. proto[0][8] || 'Unknown', // 8.Manufacturer
  15461. proto[0][9] || 'Unknown' // 9.Designer
  15462. ];
  15463. // Mac want 1-byte per character strings while Windows want
  15464. // 2-bytes per character, so duplicate the names table
  15465. var stringsUnicode = [];
  15466. var i, ii, j, jj, str;
  15467. for (i = 0, ii = strings.length; i < ii; i++) {
  15468. str = proto[1][i] || strings[i];
  15469. var strBufUnicode = [];
  15470. for (j = 0, jj = str.length; j < jj; j++) {
  15471. strBufUnicode.push(string16(str.charCodeAt(j)));
  15472. }
  15473. stringsUnicode.push(strBufUnicode.join(''));
  15474. }
  15475. var names = [strings, stringsUnicode];
  15476. var platforms = ['\x00\x01', '\x00\x03'];
  15477. var encodings = ['\x00\x00', '\x00\x01'];
  15478. var languages = ['\x00\x00', '\x04\x09'];
  15479. var namesRecordCount = strings.length * platforms.length;
  15480. var nameTable =
  15481. '\x00\x00' + // format
  15482. string16(namesRecordCount) + // Number of names Record
  15483. string16(namesRecordCount * 12 + 6); // Storage
  15484. // Build the name records field
  15485. var strOffset = 0;
  15486. for (i = 0, ii = platforms.length; i < ii; i++) {
  15487. var strs = names[i];
  15488. for (j = 0, jj = strs.length; j < jj; j++) {
  15489. str = strs[j];
  15490. var nameRecord =
  15491. platforms[i] + // platform ID
  15492. encodings[i] + // encoding ID
  15493. languages[i] + // language ID
  15494. string16(j) + // name ID
  15495. string16(str.length) +
  15496. string16(strOffset);
  15497. nameTable += nameRecord;
  15498. strOffset += str.length;
  15499. }
  15500. }
  15501. nameTable += strings.join('') + stringsUnicode.join('');
  15502. return nameTable;
  15503. }
  15504. Font.prototype = {
  15505. name: null,
  15506. font: null,
  15507. mimetype: null,
  15508. encoding: null,
  15509. get renderer() {
  15510. var renderer = FontRendererFactory.create(this);
  15511. return shadow(this, 'renderer', renderer);
  15512. },
  15513. exportData: function Font_exportData() {
  15514. var data = {};
  15515. for (var i in this) {
  15516. if (this.hasOwnProperty(i)) {
  15517. data[i] = this[i];
  15518. }
  15519. }
  15520. return data;
  15521. },
  15522. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15523. function readTableEntry(file) {
  15524. var tag = bytesToString(file.getBytes(4));
  15525. var checksum = file.getInt32();
  15526. var offset = file.getInt32() >>> 0;
  15527. var length = file.getInt32() >>> 0;
  15528. // Read the table associated data
  15529. var previousPosition = file.pos;
  15530. file.pos = file.start ? file.start : 0;
  15531. file.skip(offset);
  15532. var data = file.getBytes(length);
  15533. file.pos = previousPosition;
  15534. if (tag === 'head') {
  15535. // clearing checksum adjustment
  15536. data[8] = data[9] = data[10] = data[11] = 0;
  15537. data[17] |= 0x20; //Set font optimized for cleartype flag
  15538. }
  15539. return {
  15540. tag: tag,
  15541. checksum: checksum,
  15542. length: length,
  15543. offset: offset,
  15544. data: data
  15545. };
  15546. }
  15547. function readOpenTypeHeader(ttf) {
  15548. return {
  15549. version: bytesToString(ttf.getBytes(4)),
  15550. numTables: ttf.getUint16(),
  15551. searchRange: ttf.getUint16(),
  15552. entrySelector: ttf.getUint16(),
  15553. rangeShift: ttf.getUint16()
  15554. };
  15555. }
  15556. /**
  15557. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15558. * PDF spec
  15559. */
  15560. function readCmapTable(cmap, font, isSymbolicFont) {
  15561. var segment;
  15562. var start = (font.start ? font.start : 0) + cmap.offset;
  15563. font.pos = start;
  15564. var version = font.getUint16();
  15565. var numTables = font.getUint16();
  15566. var potentialTable;
  15567. var canBreak = false;
  15568. // There's an order of preference in terms of which cmap subtable to
  15569. // use:
  15570. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15571. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15572. // The following takes advantage of the fact that the tables are sorted
  15573. // to work.
  15574. for (var i = 0; i < numTables; i++) {
  15575. var platformId = font.getUint16();
  15576. var encodingId = font.getUint16();
  15577. var offset = font.getInt32() >>> 0;
  15578. var useTable = false;
  15579. if (platformId === 1 && encodingId === 0) {
  15580. useTable = true;
  15581. // Continue the loop since there still may be a higher priority
  15582. // table.
  15583. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15584. useTable = true;
  15585. canBreak = true;
  15586. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15587. useTable = true;
  15588. canBreak = true;
  15589. }
  15590. if (useTable) {
  15591. potentialTable = {
  15592. platformId: platformId,
  15593. encodingId: encodingId,
  15594. offset: offset
  15595. };
  15596. }
  15597. if (canBreak) {
  15598. break;
  15599. }
  15600. }
  15601. if (!potentialTable) {
  15602. warn('Could not find a preferred cmap table.');
  15603. return {
  15604. platformId: -1,
  15605. encodingId: -1,
  15606. mappings: [],
  15607. hasShortCmap: false
  15608. };
  15609. }
  15610. font.pos = start + potentialTable.offset;
  15611. var format = font.getUint16();
  15612. var length = font.getUint16();
  15613. var language = font.getUint16();
  15614. var hasShortCmap = false;
  15615. var mappings = [];
  15616. var j, glyphId;
  15617. // TODO(mack): refactor this cmap subtable reading logic out
  15618. if (format === 0) {
  15619. for (j = 0; j < 256; j++) {
  15620. var index = font.getByte();
  15621. if (!index) {
  15622. continue;
  15623. }
  15624. mappings.push({
  15625. charCode: j,
  15626. glyphId: index
  15627. });
  15628. }
  15629. hasShortCmap = true;
  15630. } else if (format === 4) {
  15631. // re-creating the table in format 4 since the encoding
  15632. // might be changed
  15633. var segCount = (font.getUint16() >> 1);
  15634. font.getBytes(6); // skipping range fields
  15635. var segIndex, segments = [];
  15636. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15637. segments.push({ end: font.getUint16() });
  15638. }
  15639. font.getUint16();
  15640. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15641. segments[segIndex].start = font.getUint16();
  15642. }
  15643. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15644. segments[segIndex].delta = font.getUint16();
  15645. }
  15646. var offsetsCount = 0;
  15647. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15648. segment = segments[segIndex];
  15649. var rangeOffset = font.getUint16();
  15650. if (!rangeOffset) {
  15651. segment.offsetIndex = -1;
  15652. continue;
  15653. }
  15654. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15655. segment.offsetIndex = offsetIndex;
  15656. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15657. segment.end - segment.start + 1);
  15658. }
  15659. var offsets = [];
  15660. for (j = 0; j < offsetsCount; j++) {
  15661. offsets.push(font.getUint16());
  15662. }
  15663. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15664. segment = segments[segIndex];
  15665. start = segment.start;
  15666. var end = segment.end;
  15667. var delta = segment.delta;
  15668. offsetIndex = segment.offsetIndex;
  15669. for (j = start; j <= end; j++) {
  15670. if (j === 0xFFFF) {
  15671. continue;
  15672. }
  15673. glyphId = (offsetIndex < 0 ?
  15674. j : offsets[offsetIndex + j - start]);
  15675. glyphId = (glyphId + delta) & 0xFFFF;
  15676. if (glyphId === 0) {
  15677. continue;
  15678. }
  15679. mappings.push({
  15680. charCode: j,
  15681. glyphId: glyphId
  15682. });
  15683. }
  15684. }
  15685. } else if (format === 6) {
  15686. // Format 6 is a 2-bytes dense mapping, which means the font data
  15687. // lives glue together even if they are pretty far in the unicode
  15688. // table. (This looks weird, so I can have missed something), this
  15689. // works on Linux but seems to fails on Mac so let's rewrite the
  15690. // cmap table to a 3-1-4 style
  15691. var firstCode = font.getUint16();
  15692. var entryCount = font.getUint16();
  15693. for (j = 0; j < entryCount; j++) {
  15694. glyphId = font.getUint16();
  15695. var charCode = firstCode + j;
  15696. mappings.push({
  15697. charCode: charCode,
  15698. glyphId: glyphId
  15699. });
  15700. }
  15701. } else {
  15702. error('cmap table has unsupported format: ' + format);
  15703. }
  15704. // removing duplicate entries
  15705. mappings.sort(function (a, b) {
  15706. return a.charCode - b.charCode;
  15707. });
  15708. for (i = 1; i < mappings.length; i++) {
  15709. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15710. mappings.splice(i, 1);
  15711. i--;
  15712. }
  15713. }
  15714. return {
  15715. platformId: potentialTable.platformId,
  15716. encodingId: potentialTable.encodingId,
  15717. mappings: mappings,
  15718. hasShortCmap: hasShortCmap
  15719. };
  15720. }
  15721. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15722. if (!header) {
  15723. if (metrics) {
  15724. metrics.data = null;
  15725. }
  15726. return;
  15727. }
  15728. font.pos = (font.start ? font.start : 0) + header.offset;
  15729. font.pos += header.length - 2;
  15730. var numOfMetrics = font.getUint16();
  15731. if (numOfMetrics > numGlyphs) {
  15732. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  15733. 'greater than the numGlyphs (' + numGlyphs + ')');
  15734. // Reduce numOfMetrics if it is greater than numGlyphs
  15735. numOfMetrics = numGlyphs;
  15736. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  15737. header.data[35] = numOfMetrics & 0x00ff;
  15738. }
  15739. var numOfSidebearings = numGlyphs - numOfMetrics;
  15740. var numMissing = numOfSidebearings -
  15741. ((metrics.length - numOfMetrics * 4) >> 1);
  15742. var i, ii;
  15743. if (numMissing > 0) {
  15744. font.pos = (font.start ? font.start : 0) + metrics.offset;
  15745. var entries = '';
  15746. for (i = 0, ii = metrics.length; i < ii; i++) {
  15747. entries += String.fromCharCode(font.getByte());
  15748. }
  15749. for (i = 0; i < numMissing; i++) {
  15750. entries += '\x00\x00';
  15751. }
  15752. metrics.data = entries;
  15753. }
  15754. }
  15755. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  15756. hintsValid) {
  15757. if (sourceEnd - sourceStart <= 12) {
  15758. // glyph with data less than 12 is invalid one
  15759. return 0;
  15760. }
  15761. var glyf = source.subarray(sourceStart, sourceEnd);
  15762. var contoursCount = (glyf[0] << 8) | glyf[1];
  15763. if (contoursCount & 0x8000) {
  15764. // complex glyph, writing as is
  15765. dest.set(glyf, destStart);
  15766. return glyf.length;
  15767. }
  15768. var i, j = 10, flagsCount = 0;
  15769. for (i = 0; i < contoursCount; i++) {
  15770. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  15771. flagsCount = endPoint + 1;
  15772. j += 2;
  15773. }
  15774. // skipping instructions
  15775. var instructionsStart = j;
  15776. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  15777. j += 2 + instructionsLength;
  15778. var instructionsEnd = j;
  15779. // validating flags
  15780. var coordinatesLength = 0;
  15781. for (i = 0; i < flagsCount; i++) {
  15782. var flag = glyf[j++];
  15783. if (flag & 0xC0) {
  15784. // reserved flags must be zero, cleaning up
  15785. glyf[j - 1] = flag & 0x3F;
  15786. }
  15787. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  15788. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  15789. coordinatesLength += xyLength;
  15790. if (flag & 8) {
  15791. var repeat = glyf[j++];
  15792. i += repeat;
  15793. coordinatesLength += repeat * xyLength;
  15794. }
  15795. }
  15796. // glyph without coordinates will be rejected
  15797. if (coordinatesLength === 0) {
  15798. return 0;
  15799. }
  15800. var glyphDataLength = j + coordinatesLength;
  15801. if (glyphDataLength > glyf.length) {
  15802. // not enough data for coordinates
  15803. return 0;
  15804. }
  15805. if (!hintsValid && instructionsLength > 0) {
  15806. dest.set(glyf.subarray(0, instructionsStart), destStart);
  15807. dest.set([0, 0], destStart + instructionsStart);
  15808. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  15809. destStart + instructionsStart + 2);
  15810. glyphDataLength -= instructionsLength;
  15811. if (glyf.length - glyphDataLength > 3) {
  15812. glyphDataLength = (glyphDataLength + 3) & ~3;
  15813. }
  15814. return glyphDataLength;
  15815. }
  15816. if (glyf.length - glyphDataLength > 3) {
  15817. // truncating and aligning to 4 bytes the long glyph data
  15818. glyphDataLength = (glyphDataLength + 3) & ~3;
  15819. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  15820. return glyphDataLength;
  15821. }
  15822. // glyph data is fine
  15823. dest.set(glyf, destStart);
  15824. return glyf.length;
  15825. }
  15826. function sanitizeHead(head, numGlyphs, locaLength) {
  15827. var data = head.data;
  15828. // Validate version:
  15829. // Should always be 0x00010000
  15830. var version = int32(data[0], data[1], data[2], data[3]);
  15831. if (version >> 16 !== 1) {
  15832. info('Attempting to fix invalid version in head table: ' + version);
  15833. data[0] = 0;
  15834. data[1] = 1;
  15835. data[2] = 0;
  15836. data[3] = 0;
  15837. }
  15838. var indexToLocFormat = int16(data[50], data[51]);
  15839. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  15840. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  15841. indexToLocFormat);
  15842. // The value of indexToLocFormat should be 0 if the loca table
  15843. // consists of short offsets, and should be 1 if the loca table
  15844. // consists of long offsets.
  15845. //
  15846. // The number of entries in the loca table should be numGlyphs + 1.
  15847. //
  15848. // Using this information, we can work backwards to deduce if the
  15849. // size of each offset in the loca table, and thus figure out the
  15850. // appropriate value for indexToLocFormat.
  15851. var numGlyphsPlusOne = numGlyphs + 1;
  15852. if (locaLength === numGlyphsPlusOne << 1) {
  15853. // 0x0000 indicates the loca table consists of short offsets
  15854. data[50] = 0;
  15855. data[51] = 0;
  15856. } else if (locaLength === numGlyphsPlusOne << 2) {
  15857. // 0x0001 indicates the loca table consists of long offsets
  15858. data[50] = 0;
  15859. data[51] = 1;
  15860. } else {
  15861. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  15862. }
  15863. }
  15864. }
  15865. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  15866. isGlyphLocationsLong, hintsValid,
  15867. dupFirstEntry) {
  15868. var itemSize, itemDecode, itemEncode;
  15869. if (isGlyphLocationsLong) {
  15870. itemSize = 4;
  15871. itemDecode = function fontItemDecodeLong(data, offset) {
  15872. return (data[offset] << 24) | (data[offset + 1] << 16) |
  15873. (data[offset + 2] << 8) | data[offset + 3];
  15874. };
  15875. itemEncode = function fontItemEncodeLong(data, offset, value) {
  15876. data[offset] = (value >>> 24) & 0xFF;
  15877. data[offset + 1] = (value >> 16) & 0xFF;
  15878. data[offset + 2] = (value >> 8) & 0xFF;
  15879. data[offset + 3] = value & 0xFF;
  15880. };
  15881. } else {
  15882. itemSize = 2;
  15883. itemDecode = function fontItemDecode(data, offset) {
  15884. return (data[offset] << 9) | (data[offset + 1] << 1);
  15885. };
  15886. itemEncode = function fontItemEncode(data, offset, value) {
  15887. data[offset] = (value >> 9) & 0xFF;
  15888. data[offset + 1] = (value >> 1) & 0xFF;
  15889. };
  15890. }
  15891. var locaData = loca.data;
  15892. var locaDataSize = itemSize * (1 + numGlyphs);
  15893. // is loca.data too short or long?
  15894. if (locaData.length !== locaDataSize) {
  15895. locaData = new Uint8Array(locaDataSize);
  15896. locaData.set(loca.data.subarray(0, locaDataSize));
  15897. loca.data = locaData;
  15898. }
  15899. // removing the invalid glyphs
  15900. var oldGlyfData = glyf.data;
  15901. var oldGlyfDataLength = oldGlyfData.length;
  15902. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  15903. var startOffset = itemDecode(locaData, 0);
  15904. var writeOffset = 0;
  15905. itemEncode(locaData, 0, writeOffset);
  15906. var i, j;
  15907. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15908. var endOffset = itemDecode(locaData, j);
  15909. if (endOffset > oldGlyfDataLength &&
  15910. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  15911. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  15912. // the glyf table size, which makes last glyph out of range.
  15913. endOffset = oldGlyfDataLength;
  15914. }
  15915. if (endOffset > oldGlyfDataLength) {
  15916. // glyph end offset points outside glyf data, rejecting the glyph
  15917. itemEncode(locaData, j, writeOffset);
  15918. startOffset = endOffset;
  15919. continue;
  15920. }
  15921. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  15922. newGlyfData, writeOffset, hintsValid);
  15923. writeOffset += newLength;
  15924. itemEncode(locaData, j, writeOffset);
  15925. startOffset = endOffset;
  15926. }
  15927. if (writeOffset === 0) {
  15928. // glyf table cannot be empty -- redoing the glyf and loca tables
  15929. // to have single glyph with one point
  15930. var simpleGlyph = new Uint8Array(
  15931. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  15932. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15933. itemEncode(locaData, j, simpleGlyph.length);
  15934. }
  15935. glyf.data = simpleGlyph;
  15936. return;
  15937. }
  15938. if (dupFirstEntry) {
  15939. var firstEntryLength = itemDecode(locaData, itemSize);
  15940. if (newGlyfData.length > firstEntryLength + writeOffset) {
  15941. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  15942. } else {
  15943. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  15944. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  15945. }
  15946. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  15947. itemEncode(loca.data, locaData.length - itemSize,
  15948. writeOffset + firstEntryLength);
  15949. } else {
  15950. glyf.data = newGlyfData.subarray(0, writeOffset);
  15951. }
  15952. }
  15953. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  15954. var start = (font.start ? font.start : 0) + post.offset;
  15955. font.pos = start;
  15956. var length = post.length, end = start + length;
  15957. var version = font.getInt32();
  15958. // skip rest to the tables
  15959. font.getBytes(28);
  15960. var glyphNames;
  15961. var valid = true;
  15962. var i;
  15963. switch (version) {
  15964. case 0x00010000:
  15965. glyphNames = MacStandardGlyphOrdering;
  15966. break;
  15967. case 0x00020000:
  15968. var numGlyphs = font.getUint16();
  15969. if (numGlyphs !== maxpNumGlyphs) {
  15970. valid = false;
  15971. break;
  15972. }
  15973. var glyphNameIndexes = [];
  15974. for (i = 0; i < numGlyphs; ++i) {
  15975. var index = font.getUint16();
  15976. if (index >= 32768) {
  15977. valid = false;
  15978. break;
  15979. }
  15980. glyphNameIndexes.push(index);
  15981. }
  15982. if (!valid) {
  15983. break;
  15984. }
  15985. var customNames = [];
  15986. var strBuf = [];
  15987. while (font.pos < end) {
  15988. var stringLength = font.getByte();
  15989. strBuf.length = stringLength;
  15990. for (i = 0; i < stringLength; ++i) {
  15991. strBuf[i] = String.fromCharCode(font.getByte());
  15992. }
  15993. customNames.push(strBuf.join(''));
  15994. }
  15995. glyphNames = [];
  15996. for (i = 0; i < numGlyphs; ++i) {
  15997. var j = glyphNameIndexes[i];
  15998. if (j < 258) {
  15999. glyphNames.push(MacStandardGlyphOrdering[j]);
  16000. continue;
  16001. }
  16002. glyphNames.push(customNames[j - 258]);
  16003. }
  16004. break;
  16005. case 0x00030000:
  16006. break;
  16007. default:
  16008. warn('Unknown/unsupported post table version ' + version);
  16009. valid = false;
  16010. break;
  16011. }
  16012. properties.glyphNames = glyphNames;
  16013. return valid;
  16014. }
  16015. function readNameTable(nameTable) {
  16016. var start = (font.start ? font.start : 0) + nameTable.offset;
  16017. font.pos = start;
  16018. var names = [[], []];
  16019. var length = nameTable.length, end = start + length;
  16020. var format = font.getUint16();
  16021. var FORMAT_0_HEADER_LENGTH = 6;
  16022. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16023. // unsupported name table format or table "too" small
  16024. return names;
  16025. }
  16026. var numRecords = font.getUint16();
  16027. var stringsStart = font.getUint16();
  16028. var records = [];
  16029. var NAME_RECORD_LENGTH = 12;
  16030. var i, ii;
  16031. for (i = 0; i < numRecords &&
  16032. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16033. var r = {
  16034. platform: font.getUint16(),
  16035. encoding: font.getUint16(),
  16036. language: font.getUint16(),
  16037. name: font.getUint16(),
  16038. length: font.getUint16(),
  16039. offset: font.getUint16()
  16040. };
  16041. // using only Macintosh and Windows platform/encoding names
  16042. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16043. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16044. records.push(r);
  16045. }
  16046. }
  16047. for (i = 0, ii = records.length; i < ii; i++) {
  16048. var record = records[i];
  16049. var pos = start + stringsStart + record.offset;
  16050. if (pos + record.length > end) {
  16051. continue; // outside of name table, ignoring
  16052. }
  16053. font.pos = pos;
  16054. var nameIndex = record.name;
  16055. if (record.encoding) {
  16056. // unicode
  16057. var str = '';
  16058. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16059. str += String.fromCharCode(font.getUint16());
  16060. }
  16061. names[1][nameIndex] = str;
  16062. } else {
  16063. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16064. }
  16065. }
  16066. return names;
  16067. }
  16068. var TTOpsStackDeltas = [
  16069. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16070. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16071. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16072. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16073. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16074. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16075. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16076. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16077. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16078. // 0xC0-DF == -1 and 0xE0-FF == -2
  16079. function sanitizeTTProgram(table, ttContext) {
  16080. var data = table.data;
  16081. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16082. var stack = [];
  16083. var callstack = [];
  16084. var functionsCalled = [];
  16085. var tooComplexToFollowFunctions =
  16086. ttContext.tooComplexToFollowFunctions;
  16087. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16088. for (var ii = data.length; i < ii;) {
  16089. var op = data[i++];
  16090. // The TrueType instruction set docs can be found at
  16091. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16092. if (op === 0x40) { // NPUSHB - pushes n bytes
  16093. n = data[i++];
  16094. if (inFDEF || inELSE) {
  16095. i += n;
  16096. } else {
  16097. for (j = 0; j < n; j++) {
  16098. stack.push(data[i++]);
  16099. }
  16100. }
  16101. } else if (op === 0x41) { // NPUSHW - pushes n words
  16102. n = data[i++];
  16103. if (inFDEF || inELSE) {
  16104. i += n * 2;
  16105. } else {
  16106. for (j = 0; j < n; j++) {
  16107. b = data[i++];
  16108. stack.push((b << 8) | data[i++]);
  16109. }
  16110. }
  16111. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16112. n = op - 0xB0 + 1;
  16113. if (inFDEF || inELSE) {
  16114. i += n;
  16115. } else {
  16116. for (j = 0; j < n; j++) {
  16117. stack.push(data[i++]);
  16118. }
  16119. }
  16120. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16121. n = op - 0xB8 + 1;
  16122. if (inFDEF || inELSE) {
  16123. i += n * 2;
  16124. } else {
  16125. for (j = 0; j < n; j++) {
  16126. b = data[i++];
  16127. stack.push((b << 8) | data[i++]);
  16128. }
  16129. }
  16130. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16131. if (!inFDEF && !inELSE) {
  16132. // collecting inforamtion about which functions are used
  16133. funcId = stack[stack.length - 1];
  16134. ttContext.functionsUsed[funcId] = true;
  16135. if (funcId in ttContext.functionsStackDeltas) {
  16136. stack.length += ttContext.functionsStackDeltas[funcId];
  16137. } else if (funcId in ttContext.functionsDefined &&
  16138. functionsCalled.indexOf(funcId) < 0) {
  16139. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16140. functionsCalled.push(funcId);
  16141. pc = ttContext.functionsDefined[funcId];
  16142. if (!pc) {
  16143. warn('TT: CALL non-existent function');
  16144. ttContext.hintsValid = false;
  16145. return;
  16146. }
  16147. data = pc.data;
  16148. i = pc.i;
  16149. }
  16150. }
  16151. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16152. if (inFDEF || inELSE) {
  16153. warn('TT: nested FDEFs not allowed');
  16154. tooComplexToFollowFunctions = true;
  16155. }
  16156. inFDEF = true;
  16157. // collecting inforamtion about which functions are defined
  16158. lastDeff = i;
  16159. funcId = stack.pop();
  16160. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16161. } else if (op === 0x2D) { // ENDF - end of function
  16162. if (inFDEF) {
  16163. inFDEF = false;
  16164. lastEndf = i;
  16165. } else {
  16166. pc = callstack.pop();
  16167. if (!pc) {
  16168. warn('TT: ENDF bad stack');
  16169. ttContext.hintsValid = false;
  16170. return;
  16171. }
  16172. funcId = functionsCalled.pop();
  16173. data = pc.data;
  16174. i = pc.i;
  16175. ttContext.functionsStackDeltas[funcId] =
  16176. stack.length - pc.stackTop;
  16177. }
  16178. } else if (op === 0x89) { // IDEF - instruction definition
  16179. if (inFDEF || inELSE) {
  16180. warn('TT: nested IDEFs not allowed');
  16181. tooComplexToFollowFunctions = true;
  16182. }
  16183. inFDEF = true;
  16184. // recording it as a function to track ENDF
  16185. lastDeff = i;
  16186. } else if (op === 0x58) { // IF
  16187. ++ifLevel;
  16188. } else if (op === 0x1B) { // ELSE
  16189. inELSE = ifLevel;
  16190. } else if (op === 0x59) { // EIF
  16191. if (inELSE === ifLevel) {
  16192. inELSE = 0;
  16193. }
  16194. --ifLevel;
  16195. } else if (op === 0x1C) { // JMPR
  16196. if (!inFDEF && !inELSE) {
  16197. var offset = stack[stack.length - 1];
  16198. // only jumping forward to prevent infinite loop
  16199. if (offset > 0) {
  16200. i += offset - 1;
  16201. }
  16202. }
  16203. }
  16204. // Adjusting stack not extactly, but just enough to get function id
  16205. if (!inFDEF && !inELSE) {
  16206. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16207. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16208. if (op >= 0x71 && op <= 0x75) {
  16209. n = stack.pop();
  16210. if (n === n) {
  16211. stackDelta = -n * 2;
  16212. }
  16213. }
  16214. while (stackDelta < 0 && stack.length > 0) {
  16215. stack.pop();
  16216. stackDelta++;
  16217. }
  16218. while (stackDelta > 0) {
  16219. stack.push(NaN); // pushing any number into stack
  16220. stackDelta--;
  16221. }
  16222. }
  16223. }
  16224. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16225. var content = [data];
  16226. if (i > data.length) {
  16227. content.push(new Uint8Array(i - data.length));
  16228. }
  16229. if (lastDeff > lastEndf) {
  16230. warn('TT: complementing a missing function tail');
  16231. // new function definition started, but not finished
  16232. // complete function by [CLEAR, ENDF]
  16233. content.push(new Uint8Array([0x22, 0x2D]));
  16234. }
  16235. foldTTTable(table, content);
  16236. }
  16237. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16238. if (ttContext.tooComplexToFollowFunctions) {
  16239. return;
  16240. }
  16241. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16242. warn('TT: more functions defined than expected');
  16243. ttContext.hintsValid = false;
  16244. return;
  16245. }
  16246. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16247. if (j > maxFunctionDefs) {
  16248. warn('TT: invalid function id: ' + j);
  16249. ttContext.hintsValid = false;
  16250. return;
  16251. }
  16252. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16253. warn('TT: undefined function: ' + j);
  16254. ttContext.hintsValid = false;
  16255. return;
  16256. }
  16257. }
  16258. }
  16259. function foldTTTable(table, content) {
  16260. if (content.length > 1) {
  16261. // concatenating the content items
  16262. var newLength = 0;
  16263. var j, jj;
  16264. for (j = 0, jj = content.length; j < jj; j++) {
  16265. newLength += content[j].length;
  16266. }
  16267. newLength = (newLength + 3) & ~3;
  16268. var result = new Uint8Array(newLength);
  16269. var pos = 0;
  16270. for (j = 0, jj = content.length; j < jj; j++) {
  16271. result.set(content[j], pos);
  16272. pos += content[j].length;
  16273. }
  16274. table.data = result;
  16275. table.length = newLength;
  16276. }
  16277. }
  16278. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16279. var ttContext = {
  16280. functionsDefined: [],
  16281. functionsUsed: [],
  16282. functionsStackDeltas: [],
  16283. tooComplexToFollowFunctions: false,
  16284. hintsValid: true
  16285. };
  16286. if (fpgm) {
  16287. sanitizeTTProgram(fpgm, ttContext);
  16288. }
  16289. if (prep) {
  16290. sanitizeTTProgram(prep, ttContext);
  16291. }
  16292. if (fpgm) {
  16293. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16294. }
  16295. if (cvt && (cvt.length & 1)) {
  16296. var cvtData = new Uint8Array(cvt.length + 1);
  16297. cvtData.set(cvt.data);
  16298. cvt.data = cvtData;
  16299. }
  16300. return ttContext.hintsValid;
  16301. }
  16302. // The following steps modify the original font data, making copy
  16303. font = new Stream(new Uint8Array(font.getBytes()));
  16304. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16305. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16306. var header = readOpenTypeHeader(font);
  16307. var numTables = header.numTables;
  16308. var cff, cffFile;
  16309. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16310. hmtx: null, maxp: null, name: null, post: null };
  16311. var table;
  16312. for (var i = 0; i < numTables; i++) {
  16313. table = readTableEntry(font);
  16314. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16315. continue; // skipping table if it's not a required or optional table
  16316. }
  16317. if (table.length === 0) {
  16318. continue; // skipping empty tables
  16319. }
  16320. tables[table.tag] = table;
  16321. }
  16322. var isTrueType = !tables['CFF '];
  16323. if (!isTrueType) {
  16324. // OpenType font
  16325. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16326. // no major tables: throwing everything at CFFFont
  16327. cffFile = new Stream(tables['CFF '].data);
  16328. cff = new CFFFont(cffFile, properties);
  16329. return this.convert(name, cff, properties);
  16330. }
  16331. delete tables.glyf;
  16332. delete tables.loca;
  16333. delete tables.fpgm;
  16334. delete tables.prep;
  16335. delete tables['cvt '];
  16336. this.isOpenType = true;
  16337. } else {
  16338. if (!tables.glyf || !tables.loca) {
  16339. error('Required "glyf" or "loca" tables are not found');
  16340. }
  16341. this.isOpenType = false;
  16342. }
  16343. if (!tables.maxp) {
  16344. error('Required "maxp" table is not found');
  16345. }
  16346. font.pos = (font.start || 0) + tables.maxp.offset;
  16347. var version = font.getInt32();
  16348. var numGlyphs = font.getUint16();
  16349. var maxFunctionDefs = 0;
  16350. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16351. // maxZones can be invalid
  16352. font.pos += 8;
  16353. var maxZones = font.getUint16();
  16354. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16355. tables.maxp.data[14] = 0;
  16356. tables.maxp.data[15] = 2;
  16357. }
  16358. font.pos += 4;
  16359. maxFunctionDefs = font.getUint16();
  16360. }
  16361. var dupFirstEntry = false;
  16362. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16363. properties.toUnicode.get(0) > '\u0000') {
  16364. // oracle's defect (see 3427), duplicating first entry
  16365. dupFirstEntry = true;
  16366. numGlyphs++;
  16367. tables.maxp.data[4] = numGlyphs >> 8;
  16368. tables.maxp.data[5] = numGlyphs & 255;
  16369. }
  16370. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16371. tables['cvt '], maxFunctionDefs);
  16372. if (!hintsValid) {
  16373. delete tables.fpgm;
  16374. delete tables.prep;
  16375. delete tables['cvt '];
  16376. }
  16377. // Ensure the hmtx table contains the advance width and
  16378. // sidebearings information for numGlyphs in the maxp table
  16379. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16380. if (!tables.head) {
  16381. error('Required "head" table is not found');
  16382. }
  16383. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16384. if (isTrueType) {
  16385. var isGlyphLocationsLong = int16(tables.head.data[50],
  16386. tables.head.data[51]);
  16387. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16388. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16389. }
  16390. if (!tables.hhea) {
  16391. error('Required "hhea" table is not found');
  16392. }
  16393. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16394. // Sometimes it's 0. That needs to be fixed
  16395. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16396. tables.hhea.data[10] = 0xFF;
  16397. tables.hhea.data[11] = 0xFF;
  16398. }
  16399. // The 'post' table has glyphs names.
  16400. if (tables.post) {
  16401. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16402. if (!valid) {
  16403. tables.post = null;
  16404. }
  16405. }
  16406. var charCodeToGlyphId = [], charCode;
  16407. if (properties.type === 'CIDFontType2') {
  16408. var cidToGidMap = properties.cidToGidMap || [];
  16409. var cidToGidMapLength = cidToGidMap.length;
  16410. properties.cMap.forEach(function(charCode, cid) {
  16411. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16412. var glyphId = -1;
  16413. if (cidToGidMapLength === 0) {
  16414. glyphId = charCode;
  16415. } else if (cidToGidMap[cid] !== undefined) {
  16416. glyphId = cidToGidMap[cid];
  16417. }
  16418. if (glyphId >= 0 && glyphId < numGlyphs) {
  16419. charCodeToGlyphId[charCode] = glyphId;
  16420. }
  16421. });
  16422. if (dupFirstEntry) {
  16423. charCodeToGlyphId[0] = numGlyphs - 1;
  16424. }
  16425. } else {
  16426. // Most of the following logic in this code branch is based on the
  16427. // 9.6.6.4 of the PDF spec.
  16428. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16429. var cmapPlatformId = cmapTable.platformId;
  16430. var cmapEncodingId = cmapTable.encodingId;
  16431. var cmapMappings = cmapTable.mappings;
  16432. var cmapMappingsLength = cmapMappings.length;
  16433. var hasEncoding = properties.differences.length ||
  16434. !!properties.baseEncodingName;
  16435. // The spec seems to imply that if the font is symbolic the encoding
  16436. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16437. // where the the font is symbolic and it has an encoding.
  16438. if (hasEncoding &&
  16439. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16440. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  16441. var baseEncoding = [];
  16442. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16443. properties.baseEncodingName === 'WinAnsiEncoding') {
  16444. baseEncoding = Encodings[properties.baseEncodingName];
  16445. }
  16446. for (charCode = 0; charCode < 256; charCode++) {
  16447. var glyphName;
  16448. if (this.differences && charCode in this.differences) {
  16449. glyphName = this.differences[charCode];
  16450. } else if (charCode in baseEncoding &&
  16451. baseEncoding[charCode] !== '') {
  16452. glyphName = baseEncoding[charCode];
  16453. } else {
  16454. glyphName = Encodings.StandardEncoding[charCode];
  16455. }
  16456. if (!glyphName) {
  16457. continue;
  16458. }
  16459. var unicodeOrCharCode;
  16460. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16461. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16462. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16463. // TODO: the encoding needs to be updated with mac os table.
  16464. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16465. }
  16466. var found = false;
  16467. for (i = 0; i < cmapMappingsLength; ++i) {
  16468. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16469. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16470. found = true;
  16471. break;
  16472. }
  16473. }
  16474. if (!found && properties.glyphNames) {
  16475. // Try to map using the post table. There are currently no known
  16476. // pdfs that this fixes.
  16477. var glyphId = properties.glyphNames.indexOf(glyphName);
  16478. if (glyphId > 0) {
  16479. charCodeToGlyphId[charCode] = glyphId;
  16480. }
  16481. }
  16482. }
  16483. } else {
  16484. // For (3, 0) cmap tables:
  16485. // The charcode key being stored in charCodeToGlyphId is the lower
  16486. // byte of the two-byte charcodes of the cmap table since according to
  16487. // the spec: 'each byte from the string shall be prepended with the
  16488. // high byte of the range [of charcodes in the cmap table], to form
  16489. // a two-byte character, which shall be used to select the
  16490. // associated glyph description from the subtable'.
  16491. //
  16492. // For (1, 0) cmap tables:
  16493. // 'single bytes from the string shall be used to look up the
  16494. // associated glyph descriptions from the subtable'. This means
  16495. // charcodes in the cmap will be single bytes, so no-op since
  16496. // glyph.charCode & 0xFF === glyph.charCode
  16497. for (i = 0; i < cmapMappingsLength; ++i) {
  16498. charCode = cmapMappings[i].charCode & 0xFF;
  16499. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16500. }
  16501. }
  16502. }
  16503. if (charCodeToGlyphId.length === 0) {
  16504. // defines at least one glyph
  16505. charCodeToGlyphId[0] = 0;
  16506. }
  16507. // Converting glyphs and ids into font's cmap table
  16508. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16509. this.toFontChar = newMapping.toFontChar;
  16510. tables.cmap = {
  16511. tag: 'cmap',
  16512. data: createCmapTable(newMapping.charCodeToGlyphId)
  16513. };
  16514. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16515. // extract some more font properties from the OpenType head and
  16516. // hhea tables; yMin and descent value are always negative
  16517. var override = {
  16518. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16519. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16520. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16521. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16522. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16523. };
  16524. tables['OS/2'] = {
  16525. tag: 'OS/2',
  16526. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16527. override)
  16528. };
  16529. }
  16530. // Rewrite the 'post' table if needed
  16531. if (!tables.post) {
  16532. tables.post = {
  16533. tag: 'post',
  16534. data: createPostTable(properties)
  16535. };
  16536. }
  16537. if (!isTrueType) {
  16538. try {
  16539. // Trying to repair CFF file
  16540. cffFile = new Stream(tables['CFF '].data);
  16541. var parser = new CFFParser(cffFile, properties);
  16542. cff = parser.parse();
  16543. var compiler = new CFFCompiler(cff);
  16544. tables['CFF '].data = compiler.compile();
  16545. } catch (e) {
  16546. warn('Failed to compile font ' + properties.loadedName);
  16547. }
  16548. }
  16549. // Re-creating 'name' table
  16550. if (!tables.name) {
  16551. tables.name = {
  16552. tag: 'name',
  16553. data: createNameTable(this.name)
  16554. };
  16555. } else {
  16556. // ... using existing 'name' table as prototype
  16557. var namePrototype = readNameTable(tables.name);
  16558. tables.name.data = createNameTable(name, namePrototype);
  16559. }
  16560. var builder = new OpenTypeFileBuilder(header.version);
  16561. for (var tableTag in tables) {
  16562. builder.addTable(tableTag, tables[tableTag].data);
  16563. }
  16564. return builder.toArray();
  16565. },
  16566. convert: function Font_convert(fontName, font, properties) {
  16567. // TODO: Check the charstring widths to determine this.
  16568. properties.fixedPitch = false;
  16569. var mapping = font.getGlyphMapping(properties);
  16570. var newMapping = adjustMapping(mapping, properties);
  16571. this.toFontChar = newMapping.toFontChar;
  16572. var numGlyphs = font.numGlyphs;
  16573. function getCharCodes(charCodeToGlyphId, glyphId) {
  16574. var charCodes = null;
  16575. for (var charCode in charCodeToGlyphId) {
  16576. if (glyphId === charCodeToGlyphId[charCode]) {
  16577. if (!charCodes) {
  16578. charCodes = [];
  16579. }
  16580. charCodes.push(charCode | 0);
  16581. }
  16582. }
  16583. return charCodes;
  16584. }
  16585. function createCharCode(charCodeToGlyphId, glyphId) {
  16586. for (var charCode in charCodeToGlyphId) {
  16587. if (glyphId === charCodeToGlyphId[charCode]) {
  16588. return charCode | 0;
  16589. }
  16590. }
  16591. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16592. glyphId;
  16593. return newMapping.nextAvailableFontCharCode++;
  16594. }
  16595. var seacs = font.seacs;
  16596. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16597. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16598. var charset = font.getCharset();
  16599. var seacMap = Object.create(null);
  16600. for (var glyphId in seacs) {
  16601. glyphId |= 0;
  16602. var seac = seacs[glyphId];
  16603. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16604. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16605. var baseGlyphId = charset.indexOf(baseGlyphName);
  16606. var accentGlyphId = charset.indexOf(accentGlyphName);
  16607. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16608. continue;
  16609. }
  16610. var accentOffset = {
  16611. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16612. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16613. };
  16614. var charCodes = getCharCodes(mapping, glyphId);
  16615. if (!charCodes) {
  16616. // There's no point in mapping it if the char code was never mapped
  16617. // to begin with.
  16618. continue;
  16619. }
  16620. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16621. var charCode = charCodes[i];
  16622. // Find a fontCharCode that maps to the base and accent glyphs.
  16623. // If one doesn't exists, create it.
  16624. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16625. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16626. baseGlyphId);
  16627. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16628. accentGlyphId);
  16629. seacMap[charCode] = {
  16630. baseFontCharCode: baseFontCharCode,
  16631. accentFontCharCode: accentFontCharCode,
  16632. accentOffset: accentOffset
  16633. };
  16634. }
  16635. }
  16636. properties.seacMap = seacMap;
  16637. }
  16638. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16639. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16640. // PostScript Font Program
  16641. builder.addTable('CFF ', font.data);
  16642. // OS/2 and Windows Specific metrics
  16643. builder.addTable('OS/2', createOS2Table(properties,
  16644. newMapping.charCodeToGlyphId));
  16645. // Character to glyphs mapping
  16646. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16647. // Font header
  16648. builder.addTable('head',
  16649. '\x00\x01\x00\x00' + // Version number
  16650. '\x00\x00\x10\x00' + // fontRevision
  16651. '\x00\x00\x00\x00' + // checksumAdjustement
  16652. '\x5F\x0F\x3C\xF5' + // magicNumber
  16653. '\x00\x00' + // Flags
  16654. safeString16(unitsPerEm) + // unitsPerEM
  16655. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16656. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16657. '\x00\x00' + // xMin
  16658. safeString16(properties.descent) + // yMin
  16659. '\x0F\xFF' + // xMax
  16660. safeString16(properties.ascent) + // yMax
  16661. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16662. '\x00\x11' + // lowestRecPPEM
  16663. '\x00\x00' + // fontDirectionHint
  16664. '\x00\x00' + // indexToLocFormat
  16665. '\x00\x00'); // glyphDataFormat
  16666. // Horizontal header
  16667. builder.addTable('hhea',
  16668. '\x00\x01\x00\x00' + // Version number
  16669. safeString16(properties.ascent) + // Typographic Ascent
  16670. safeString16(properties.descent) + // Typographic Descent
  16671. '\x00\x00' + // Line Gap
  16672. '\xFF\xFF' + // advanceWidthMax
  16673. '\x00\x00' + // minLeftSidebearing
  16674. '\x00\x00' + // minRightSidebearing
  16675. '\x00\x00' + // xMaxExtent
  16676. safeString16(properties.capHeight) + // caretSlopeRise
  16677. safeString16(Math.tan(properties.italicAngle) *
  16678. properties.xHeight) + // caretSlopeRun
  16679. '\x00\x00' + // caretOffset
  16680. '\x00\x00' + // -reserved-
  16681. '\x00\x00' + // -reserved-
  16682. '\x00\x00' + // -reserved-
  16683. '\x00\x00' + // -reserved-
  16684. '\x00\x00' + // metricDataFormat
  16685. string16(numGlyphs)); // Number of HMetrics
  16686. // Horizontal metrics
  16687. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16688. var charstrings = font.charstrings;
  16689. var cffWidths = font.cff ? font.cff.widths : null;
  16690. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16691. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16692. var width = 0;
  16693. if (charstrings) {
  16694. var charstring = charstrings[i - 1];
  16695. width = 'width' in charstring ? charstring.width : 0;
  16696. } else if (cffWidths) {
  16697. width = Math.ceil(cffWidths[i] || 0);
  16698. }
  16699. hmtx += string16(width) + string16(0);
  16700. }
  16701. return hmtx;
  16702. })());
  16703. // Maximum profile
  16704. builder.addTable('maxp',
  16705. '\x00\x00\x50\x00' + // Version number
  16706. string16(numGlyphs)); // Num of glyphs
  16707. // Naming tables
  16708. builder.addTable('name', createNameTable(fontName));
  16709. // PostScript informations
  16710. builder.addTable('post', createPostTable(properties));
  16711. return builder.toArray();
  16712. },
  16713. /**
  16714. * Builds a char code to unicode map based on section 9.10 of the spec.
  16715. * @param {Object} properties Font properties object.
  16716. * @return {Object} A ToUnicodeMap object.
  16717. */
  16718. buildToUnicode: function Font_buildToUnicode(properties) {
  16719. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16720. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16721. return properties.toUnicode;
  16722. }
  16723. // According to the spec if the font is a simple font we should only map
  16724. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16725. // the differences array only contains adobe standard or symbol set names,
  16726. // in pratice it seems better to always try to create a toUnicode
  16727. // map based of the default encoding.
  16728. var toUnicode, charcode;
  16729. if (!properties.composite /* is simple font */) {
  16730. toUnicode = [];
  16731. var encoding = properties.defaultEncoding.slice();
  16732. var baseEncodingName = properties.baseEncodingName;
  16733. // Merge in the differences array.
  16734. var differences = properties.differences;
  16735. for (charcode in differences) {
  16736. encoding[charcode] = differences[charcode];
  16737. }
  16738. for (charcode in encoding) {
  16739. // a) Map the character code to a character name.
  16740. var glyphName = encoding[charcode];
  16741. // b) Look up the character name in the Adobe Glyph List (see the
  16742. // Bibliography) to obtain the corresponding Unicode value.
  16743. if (glyphName === '') {
  16744. continue;
  16745. } else if (GlyphsUnicode[glyphName] === undefined) {
  16746. // (undocumented) c) Few heuristics to recognize unknown glyphs
  16747. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  16748. var code = 0;
  16749. switch (glyphName[0]) {
  16750. case 'G': // Gxx glyph
  16751. if (glyphName.length === 3) {
  16752. code = parseInt(glyphName.substr(1), 16);
  16753. }
  16754. break;
  16755. case 'g': // g00xx glyph
  16756. if (glyphName.length === 5) {
  16757. code = parseInt(glyphName.substr(1), 16);
  16758. }
  16759. break;
  16760. case 'C': // Cddd glyph
  16761. case 'c': // cddd glyph
  16762. if (glyphName.length >= 3) {
  16763. code = +glyphName.substr(1);
  16764. }
  16765. break;
  16766. }
  16767. if (code) {
  16768. // If |baseEncodingName| is one the predefined encodings,
  16769. // and |code| equals |charcode|, using the glyph defined in the
  16770. // baseEncoding seems to yield a better |toUnicode| mapping
  16771. // (fixes issue 5070).
  16772. if (baseEncodingName && code === +charcode) {
  16773. var baseEncoding = Encodings[baseEncodingName];
  16774. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  16775. toUnicode[charcode] =
  16776. String.fromCharCode(GlyphsUnicode[glyphName]);
  16777. continue;
  16778. }
  16779. }
  16780. toUnicode[charcode] = String.fromCharCode(code);
  16781. }
  16782. continue;
  16783. }
  16784. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  16785. }
  16786. return new ToUnicodeMap(toUnicode);
  16787. }
  16788. // If the font is a composite font that uses one of the predefined CMaps
  16789. // listed in Table 118 (except Identity–H and Identity–V) or whose
  16790. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  16791. // Adobe-Korea1 character collection:
  16792. if (properties.composite && (
  16793. (properties.cMap.builtInCMap &&
  16794. !(properties.cMap instanceof IdentityCMap)) ||
  16795. (properties.cidSystemInfo.registry === 'Adobe' &&
  16796. (properties.cidSystemInfo.ordering === 'GB1' ||
  16797. properties.cidSystemInfo.ordering === 'CNS1' ||
  16798. properties.cidSystemInfo.ordering === 'Japan1' ||
  16799. properties.cidSystemInfo.ordering === 'Korea1')))) {
  16800. // Then:
  16801. // a) Map the character code to a character identifier (CID) according
  16802. // to the font’s CMap.
  16803. // b) Obtain the registry and ordering of the character collection used
  16804. // by the font’s CMap (for example, Adobe and Japan1) from its
  16805. // CIDSystemInfo dictionary.
  16806. var registry = properties.cidSystemInfo.registry;
  16807. var ordering = properties.cidSystemInfo.ordering;
  16808. // c) Construct a second CMap name by concatenating the registry and
  16809. // ordering obtained in step (b) in the format registry–ordering–UCS2
  16810. // (for example, Adobe–Japan1–UCS2).
  16811. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  16812. // d) Obtain the CMap with the name constructed in step (c) (available
  16813. // from the ASN Web site; see the Bibliography).
  16814. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  16815. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  16816. var cMap = properties.cMap;
  16817. toUnicode = [];
  16818. cMap.forEach(function(charcode, cid) {
  16819. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16820. // e) Map the CID obtained in step (a) according to the CMap obtained
  16821. // in step (d), producing a Unicode value.
  16822. var ucs2 = ucs2CMap.lookup(cid);
  16823. if (ucs2) {
  16824. toUnicode[charcode] =
  16825. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  16826. ucs2.charCodeAt(1));
  16827. }
  16828. });
  16829. return new ToUnicodeMap(toUnicode);
  16830. }
  16831. // The viewer's choice, just use an identity map.
  16832. return new IdentityToUnicodeMap(properties.firstChar,
  16833. properties.lastChar);
  16834. },
  16835. get spaceWidth() {
  16836. if ('_shadowWidth' in this) {
  16837. return this._shadowWidth;
  16838. }
  16839. // trying to estimate space character width
  16840. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  16841. var width;
  16842. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  16843. var glyphName = possibleSpaceReplacements[i];
  16844. // if possible, getting width by glyph name
  16845. if (glyphName in this.widths) {
  16846. width = this.widths[glyphName];
  16847. break;
  16848. }
  16849. var glyphUnicode = GlyphsUnicode[glyphName];
  16850. // finding the charcode via unicodeToCID map
  16851. var charcode = 0;
  16852. if (this.composite) {
  16853. if (this.cMap.contains(glyphUnicode)) {
  16854. charcode = this.cMap.lookup(glyphUnicode);
  16855. }
  16856. }
  16857. // ... via toUnicode map
  16858. if (!charcode && 'toUnicode' in this) {
  16859. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  16860. }
  16861. // setting it to unicode if negative or undefined
  16862. if (charcode <= 0) {
  16863. charcode = glyphUnicode;
  16864. }
  16865. // trying to get width via charcode
  16866. width = this.widths[charcode];
  16867. if (width) {
  16868. break; // the non-zero width found
  16869. }
  16870. }
  16871. width = width || this.defaultWidth;
  16872. // Do not shadow the property here. See discussion:
  16873. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  16874. this._shadowWidth = width;
  16875. return width;
  16876. },
  16877. charToGlyph: function Font_charToGlyph(charcode) {
  16878. var fontCharCode, width, operatorListId;
  16879. var widthCode = charcode;
  16880. if (this.cMap && this.cMap.contains(charcode)) {
  16881. widthCode = this.cMap.lookup(charcode);
  16882. }
  16883. width = this.widths[widthCode];
  16884. width = isNum(width) ? width : this.defaultWidth;
  16885. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  16886. var unicode = this.toUnicode.get(charcode) || charcode;
  16887. if (typeof unicode === 'number') {
  16888. unicode = String.fromCharCode(unicode);
  16889. }
  16890. // First try the toFontChar map, if it's not there then try falling
  16891. // back to the char code.
  16892. fontCharCode = this.toFontChar[charcode] || charcode;
  16893. if (this.missingFile) {
  16894. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  16895. }
  16896. if (this.isType3Font) {
  16897. // Font char code in this case is actually a glyph name.
  16898. operatorListId = fontCharCode;
  16899. }
  16900. var accent = null;
  16901. if (this.seacMap && this.seacMap[charcode]) {
  16902. var seac = this.seacMap[charcode];
  16903. fontCharCode = seac.baseFontCharCode;
  16904. accent = {
  16905. fontChar: String.fromCharCode(seac.accentFontCharCode),
  16906. offset: seac.accentOffset
  16907. };
  16908. }
  16909. var fontChar = String.fromCharCode(fontCharCode);
  16910. var glyph = this.glyphCache[charcode];
  16911. if (!glyph ||
  16912. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  16913. operatorListId)) {
  16914. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  16915. operatorListId);
  16916. this.glyphCache[charcode] = glyph;
  16917. }
  16918. return glyph;
  16919. },
  16920. charsToGlyphs: function Font_charsToGlyphs(chars) {
  16921. var charsCache = this.charsCache;
  16922. var glyphs, glyph, charcode;
  16923. // if we translated this string before, just grab it from the cache
  16924. if (charsCache) {
  16925. glyphs = charsCache[chars];
  16926. if (glyphs) {
  16927. return glyphs;
  16928. }
  16929. }
  16930. // lazily create the translation cache
  16931. if (!charsCache) {
  16932. charsCache = this.charsCache = Object.create(null);
  16933. }
  16934. glyphs = [];
  16935. var charsCacheKey = chars;
  16936. var i = 0, ii;
  16937. if (this.cMap) {
  16938. // composite fonts have multi-byte strings convert the string from
  16939. // single-byte to multi-byte
  16940. var c = {};
  16941. while (i < chars.length) {
  16942. this.cMap.readCharCode(chars, i, c);
  16943. charcode = c.charcode;
  16944. var length = c.length;
  16945. i += length;
  16946. glyph = this.charToGlyph(charcode);
  16947. glyphs.push(glyph);
  16948. // placing null after each word break charcode (ASCII SPACE)
  16949. // Ignore occurences of 0x20 in multiple-byte codes.
  16950. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  16951. glyphs.push(null);
  16952. }
  16953. }
  16954. } else {
  16955. for (i = 0, ii = chars.length; i < ii; ++i) {
  16956. charcode = chars.charCodeAt(i);
  16957. glyph = this.charToGlyph(charcode);
  16958. glyphs.push(glyph);
  16959. if (charcode === 0x20) {
  16960. glyphs.push(null);
  16961. }
  16962. }
  16963. }
  16964. // Enter the translated string into the cache
  16965. return (charsCache[charsCacheKey] = glyphs);
  16966. }
  16967. };
  16968. return Font;
  16969. })();
  16970. var ErrorFont = (function ErrorFontClosure() {
  16971. function ErrorFont(error) {
  16972. this.error = error;
  16973. this.loadedName = 'g_font_error';
  16974. this.loading = false;
  16975. }
  16976. ErrorFont.prototype = {
  16977. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  16978. return [];
  16979. },
  16980. exportData: function ErrorFont_exportData() {
  16981. return {error: this.error};
  16982. }
  16983. };
  16984. return ErrorFont;
  16985. })();
  16986. /**
  16987. * Shared logic for building a char code to glyph id mapping for Type1 and
  16988. * simple CFF fonts. See section 9.6.6.2 of the spec.
  16989. * @param {Object} properties Font properties object.
  16990. * @param {Object} builtInEncoding The encoding contained within the actual font
  16991. * data.
  16992. * @param {Array} Array of glyph names where the index is the glyph ID.
  16993. * @returns {Object} A char code to glyph ID map.
  16994. */
  16995. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  16996. var charCodeToGlyphId = Object.create(null);
  16997. var glyphId, charCode, baseEncoding;
  16998. if (properties.baseEncodingName) {
  16999. // If a valid base encoding name was used, the mapping is initialized with
  17000. // that.
  17001. baseEncoding = Encodings[properties.baseEncodingName];
  17002. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17003. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17004. if (glyphId >= 0) {
  17005. charCodeToGlyphId[charCode] = glyphId;
  17006. }
  17007. }
  17008. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17009. // For a symbolic font the encoding should be the fonts built-in
  17010. // encoding.
  17011. for (charCode in builtInEncoding) {
  17012. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17013. }
  17014. } else {
  17015. // For non-symbolic fonts that don't have a base encoding the standard
  17016. // encoding should be used.
  17017. baseEncoding = Encodings.StandardEncoding;
  17018. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17019. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17020. if (glyphId >= 0) {
  17021. charCodeToGlyphId[charCode] = glyphId;
  17022. }
  17023. }
  17024. }
  17025. // Lastly, merge in the differences.
  17026. var differences = properties.differences;
  17027. if (differences) {
  17028. for (charCode in differences) {
  17029. var glyphName = differences[charCode];
  17030. glyphId = glyphNames.indexOf(glyphName);
  17031. if (glyphId >= 0) {
  17032. charCodeToGlyphId[charCode] = glyphId;
  17033. }
  17034. }
  17035. }
  17036. return charCodeToGlyphId;
  17037. }
  17038. /*
  17039. * CharStrings are encoded following the the CharString Encoding sequence
  17040. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17041. * The value in a byte indicates a command, a number, or subsequent bytes
  17042. * that are to be interpreted in a special way.
  17043. *
  17044. * CharString Number Encoding:
  17045. * A CharString byte containing the values from 32 through 255 inclusive
  17046. * indicate an integer. These values are decoded in four ranges.
  17047. *
  17048. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17049. * indicate the integer v - 139. Thus, the integer values from -107 through
  17050. * 107 inclusive may be encoded in single byte.
  17051. *
  17052. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17053. * indicates an integer involving the next byte, w, according to the formula:
  17054. * [(v - 247) x 256] + w + 108
  17055. *
  17056. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17057. * indicates an integer involving the next byte, w, according to the formula:
  17058. * -[(v - 251) * 256] - w - 108
  17059. *
  17060. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17061. * are a two complement signed integer. The first of these bytes contains the
  17062. * highest order bits, the second byte contains the next higher order bits
  17063. * and the fourth byte contain the lowest order bits.
  17064. *
  17065. *
  17066. * CharString Command Encoding:
  17067. * CharStrings commands are encoded in 1 or 2 bytes.
  17068. *
  17069. * Single byte commands are encoded in 1 byte that contains a value between
  17070. * 0 and 31 inclusive.
  17071. * If a command byte contains the value 12, then the value in the next byte
  17072. * indicates a command. This "escape" mechanism allows many extra commands
  17073. * to be encoded and this encoding technique helps to minimize the length of
  17074. * the charStrings.
  17075. */
  17076. var Type1CharString = (function Type1CharStringClosure() {
  17077. var COMMAND_MAP = {
  17078. 'hstem': [1],
  17079. 'vstem': [3],
  17080. 'vmoveto': [4],
  17081. 'rlineto': [5],
  17082. 'hlineto': [6],
  17083. 'vlineto': [7],
  17084. 'rrcurveto': [8],
  17085. 'callsubr': [10],
  17086. 'flex': [12, 35],
  17087. 'drop' : [12, 18],
  17088. 'endchar': [14],
  17089. 'rmoveto': [21],
  17090. 'hmoveto': [22],
  17091. 'vhcurveto': [30],
  17092. 'hvcurveto': [31]
  17093. };
  17094. function Type1CharString() {
  17095. this.width = 0;
  17096. this.lsb = 0;
  17097. this.flexing = false;
  17098. this.output = [];
  17099. this.stack = [];
  17100. }
  17101. Type1CharString.prototype = {
  17102. convert: function Type1CharString_convert(encoded, subrs) {
  17103. var count = encoded.length;
  17104. var error = false;
  17105. var wx, sbx, subrNumber;
  17106. for (var i = 0; i < count; i++) {
  17107. var value = encoded[i];
  17108. if (value < 32) {
  17109. if (value === 12) {
  17110. value = (value << 8) + encoded[++i];
  17111. }
  17112. switch (value) {
  17113. case 1: // hstem
  17114. if (!HINTING_ENABLED) {
  17115. this.stack = [];
  17116. break;
  17117. }
  17118. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17119. break;
  17120. case 3: // vstem
  17121. if (!HINTING_ENABLED) {
  17122. this.stack = [];
  17123. break;
  17124. }
  17125. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17126. break;
  17127. case 4: // vmoveto
  17128. if (this.flexing) {
  17129. if (this.stack.length < 1) {
  17130. error = true;
  17131. break;
  17132. }
  17133. // Add the dx for flex and but also swap the values so they are
  17134. // the right order.
  17135. var dy = this.stack.pop();
  17136. this.stack.push(0, dy);
  17137. break;
  17138. }
  17139. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17140. break;
  17141. case 5: // rlineto
  17142. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17143. break;
  17144. case 6: // hlineto
  17145. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17146. break;
  17147. case 7: // vlineto
  17148. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17149. break;
  17150. case 8: // rrcurveto
  17151. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17152. break;
  17153. case 9: // closepath
  17154. // closepath is a Type1 command that does not take argument and is
  17155. // useless in Type2 and it can simply be ignored.
  17156. this.stack = [];
  17157. break;
  17158. case 10: // callsubr
  17159. if (this.stack.length < 1) {
  17160. error = true;
  17161. break;
  17162. }
  17163. subrNumber = this.stack.pop();
  17164. error = this.convert(subrs[subrNumber], subrs);
  17165. break;
  17166. case 11: // return
  17167. return error;
  17168. case 13: // hsbw
  17169. if (this.stack.length < 2) {
  17170. error = true;
  17171. break;
  17172. }
  17173. // To convert to type2 we have to move the width value to the
  17174. // first part of the charstring and then use hmoveto with lsb.
  17175. wx = this.stack.pop();
  17176. sbx = this.stack.pop();
  17177. this.lsb = sbx;
  17178. this.width = wx;
  17179. this.stack.push(wx, sbx);
  17180. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17181. break;
  17182. case 14: // endchar
  17183. this.output.push(COMMAND_MAP.endchar[0]);
  17184. break;
  17185. case 21: // rmoveto
  17186. if (this.flexing) {
  17187. break;
  17188. }
  17189. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17190. break;
  17191. case 22: // hmoveto
  17192. if (this.flexing) {
  17193. // Add the dy for flex.
  17194. this.stack.push(0);
  17195. break;
  17196. }
  17197. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17198. break;
  17199. case 30: // vhcurveto
  17200. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17201. break;
  17202. case 31: // hvcurveto
  17203. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17204. break;
  17205. case (12 << 8) + 0: // dotsection
  17206. // dotsection is a Type1 command to specify some hinting feature
  17207. // for dots that do not take a parameter and it can safely be
  17208. // ignored for Type2.
  17209. this.stack = [];
  17210. break;
  17211. case (12 << 8) + 1: // vstem3
  17212. if (!HINTING_ENABLED) {
  17213. this.stack = [];
  17214. break;
  17215. }
  17216. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17217. // multiple parameters, so instead of returning [vh]stem3 take a
  17218. // shortcut and return [vhstem] instead.
  17219. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17220. break;
  17221. case (12 << 8) + 2: // hstem3
  17222. if (!HINTING_ENABLED) {
  17223. this.stack = [];
  17224. break;
  17225. }
  17226. // See vstem3.
  17227. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17228. break;
  17229. case (12 << 8) + 6: // seac
  17230. // seac is like type 2's special endchar but it doesn't use the
  17231. // first argument asb, so remove it.
  17232. if (SEAC_ANALYSIS_ENABLED) {
  17233. this.seac = this.stack.splice(-4, 4);
  17234. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17235. } else {
  17236. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17237. }
  17238. break;
  17239. case (12 << 8) + 7: // sbw
  17240. if (this.stack.length < 4) {
  17241. error = true;
  17242. break;
  17243. }
  17244. // To convert to type2 we have to move the width value to the
  17245. // first part of the charstring and then use rmoveto with
  17246. // (dx, dy). The height argument will not be used for vmtx and
  17247. // vhea tables reconstruction -- ignoring it.
  17248. var wy = this.stack.pop();
  17249. wx = this.stack.pop();
  17250. var sby = this.stack.pop();
  17251. sbx = this.stack.pop();
  17252. this.lsb = sbx;
  17253. this.width = wx;
  17254. this.stack.push(wx, sbx, sby);
  17255. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17256. break;
  17257. case (12 << 8) + 12: // div
  17258. if (this.stack.length < 2) {
  17259. error = true;
  17260. break;
  17261. }
  17262. var num2 = this.stack.pop();
  17263. var num1 = this.stack.pop();
  17264. this.stack.push(num1 / num2);
  17265. break;
  17266. case (12 << 8) + 16: // callothersubr
  17267. if (this.stack.length < 2) {
  17268. error = true;
  17269. break;
  17270. }
  17271. subrNumber = this.stack.pop();
  17272. var numArgs = this.stack.pop();
  17273. if (subrNumber === 0 && numArgs === 3) {
  17274. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17275. this.stack.push(
  17276. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17277. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17278. flexArgs[4], // bcp2x
  17279. flexArgs[5], // bcp2y
  17280. flexArgs[6], // p2x
  17281. flexArgs[7], // p2y
  17282. flexArgs[8], // bcp3x
  17283. flexArgs[9], // bcp3y
  17284. flexArgs[10], // bcp4x
  17285. flexArgs[11], // bcp4y
  17286. flexArgs[12], // p3x
  17287. flexArgs[13], // p3y
  17288. flexArgs[14] // flexDepth
  17289. // 15 = finalx unused by flex
  17290. // 16 = finaly unused by flex
  17291. );
  17292. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17293. this.flexing = false;
  17294. this.stack.push(flexArgs[15], flexArgs[16]);
  17295. } else if (subrNumber === 1 && numArgs === 0) {
  17296. this.flexing = true;
  17297. }
  17298. break;
  17299. case (12 << 8) + 17: // pop
  17300. // Ignore this since it is only used with othersubr.
  17301. break;
  17302. case (12 << 8) + 33: // setcurrentpoint
  17303. // Ignore for now.
  17304. this.stack = [];
  17305. break;
  17306. default:
  17307. warn('Unknown type 1 charstring command of "' + value + '"');
  17308. break;
  17309. }
  17310. if (error) {
  17311. break;
  17312. }
  17313. continue;
  17314. } else if (value <= 246) {
  17315. value = value - 139;
  17316. } else if (value <= 250) {
  17317. value = ((value - 247) * 256) + encoded[++i] + 108;
  17318. } else if (value <= 254) {
  17319. value = -((value - 251) * 256) - encoded[++i] - 108;
  17320. } else {
  17321. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17322. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17323. }
  17324. this.stack.push(value);
  17325. }
  17326. return error;
  17327. },
  17328. executeCommand: function(howManyArgs, command, keepStack) {
  17329. var stackLength = this.stack.length;
  17330. if (howManyArgs > stackLength) {
  17331. return true;
  17332. }
  17333. var start = stackLength - howManyArgs;
  17334. for (var i = start; i < stackLength; i++) {
  17335. var value = this.stack[i];
  17336. if (value === (value | 0)) { // int
  17337. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17338. } else { // fixed point
  17339. value = (65536 * value) | 0;
  17340. this.output.push(255,
  17341. (value >> 24) & 0xFF,
  17342. (value >> 16) & 0xFF,
  17343. (value >> 8) & 0xFF,
  17344. value & 0xFF);
  17345. }
  17346. }
  17347. this.output.push.apply(this.output, command);
  17348. if (keepStack) {
  17349. this.stack.splice(start, howManyArgs);
  17350. } else {
  17351. this.stack.length = 0;
  17352. }
  17353. return false;
  17354. }
  17355. };
  17356. return Type1CharString;
  17357. })();
  17358. /*
  17359. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17360. * program. Some of its logic depends on the Type2 charstrings
  17361. * structure.
  17362. * Note: this doesn't really parse the font since that would require evaluation
  17363. * of PostScript, but it is possible in most cases to extract what we need
  17364. * without a full parse.
  17365. */
  17366. var Type1Parser = (function Type1ParserClosure() {
  17367. /*
  17368. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17369. * of Plaintext Bytes. The function took a key as a parameter which can be
  17370. * for decrypting the eexec block of for decoding charStrings.
  17371. */
  17372. var EEXEC_ENCRYPT_KEY = 55665;
  17373. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17374. function isHexDigit(code) {
  17375. return code >= 48 && code <= 57 || // '0'-'9'
  17376. code >= 65 && code <= 70 || // 'A'-'F'
  17377. code >= 97 && code <= 102; // 'a'-'f'
  17378. }
  17379. function decrypt(data, key, discardNumber) {
  17380. var r = key | 0, c1 = 52845, c2 = 22719;
  17381. var count = data.length;
  17382. var decrypted = new Uint8Array(count);
  17383. for (var i = 0; i < count; i++) {
  17384. var value = data[i];
  17385. decrypted[i] = value ^ (r >> 8);
  17386. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17387. }
  17388. return Array.prototype.slice.call(decrypted, discardNumber);
  17389. }
  17390. function decryptAscii(data, key, discardNumber) {
  17391. var r = key | 0, c1 = 52845, c2 = 22719;
  17392. var count = data.length, maybeLength = count >>> 1;
  17393. var decrypted = new Uint8Array(maybeLength);
  17394. var i, j;
  17395. for (i = 0, j = 0; i < count; i++) {
  17396. var digit1 = data[i];
  17397. if (!isHexDigit(digit1)) {
  17398. continue;
  17399. }
  17400. i++;
  17401. var digit2;
  17402. while (i < count && !isHexDigit(digit2 = data[i])) {
  17403. i++;
  17404. }
  17405. if (i < count) {
  17406. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17407. decrypted[j++] = value ^ (r >> 8);
  17408. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17409. }
  17410. }
  17411. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17412. }
  17413. function isSpecial(c) {
  17414. return c === 0x2F || // '/'
  17415. c === 0x5B || c === 0x5D || // '[', ']'
  17416. c === 0x7B || c === 0x7D || // '{', '}'
  17417. c === 0x28 || c === 0x29; // '(', ')'
  17418. }
  17419. function Type1Parser(stream, encrypted) {
  17420. if (encrypted) {
  17421. var data = stream.getBytes();
  17422. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17423. isHexDigit(data[2]) && isHexDigit(data[3]));
  17424. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17425. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17426. }
  17427. this.stream = stream;
  17428. this.nextChar();
  17429. }
  17430. Type1Parser.prototype = {
  17431. readNumberArray: function Type1Parser_readNumberArray() {
  17432. this.getToken(); // read '[' or '{' (arrays can start with either)
  17433. var array = [];
  17434. while (true) {
  17435. var token = this.getToken();
  17436. if (token === null || token === ']' || token === '}') {
  17437. break;
  17438. }
  17439. array.push(parseFloat(token || 0));
  17440. }
  17441. return array;
  17442. },
  17443. readNumber: function Type1Parser_readNumber() {
  17444. var token = this.getToken();
  17445. return parseFloat(token || 0);
  17446. },
  17447. readInt: function Type1Parser_readInt() {
  17448. // Use '| 0' to prevent setting a double into length such as the double
  17449. // does not flow into the loop variable.
  17450. var token = this.getToken();
  17451. return parseInt(token || 0, 10) | 0;
  17452. },
  17453. readBoolean: function Type1Parser_readBoolean() {
  17454. var token = this.getToken();
  17455. // Use 1 and 0 since that's what type2 charstrings use.
  17456. return token === 'true' ? 1 : 0;
  17457. },
  17458. nextChar : function Type1_nextChar() {
  17459. return (this.currentChar = this.stream.getByte());
  17460. },
  17461. getToken: function Type1Parser_getToken() {
  17462. // Eat whitespace and comments.
  17463. var comment = false;
  17464. var ch = this.currentChar;
  17465. while (true) {
  17466. if (ch === -1) {
  17467. return null;
  17468. }
  17469. if (comment) {
  17470. if (ch === 0x0A || ch === 0x0D) {
  17471. comment = false;
  17472. }
  17473. } else if (ch === 0x25) { // '%'
  17474. comment = true;
  17475. } else if (!Lexer.isSpace(ch)) {
  17476. break;
  17477. }
  17478. ch = this.nextChar();
  17479. }
  17480. if (isSpecial(ch)) {
  17481. this.nextChar();
  17482. return String.fromCharCode(ch);
  17483. }
  17484. var token = '';
  17485. do {
  17486. token += String.fromCharCode(ch);
  17487. ch = this.nextChar();
  17488. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17489. return token;
  17490. },
  17491. /*
  17492. * Returns an object containing a Subrs array and a CharStrings
  17493. * array extracted from and eexec encrypted block of data
  17494. */
  17495. extractFontProgram: function Type1Parser_extractFontProgram() {
  17496. var stream = this.stream;
  17497. var subrs = [], charstrings = [];
  17498. var program = {
  17499. subrs: [],
  17500. charstrings: [],
  17501. properties: {
  17502. 'privateData': {
  17503. 'lenIV': 4
  17504. }
  17505. }
  17506. };
  17507. var token, length, data, lenIV, encoded;
  17508. while ((token = this.getToken()) !== null) {
  17509. if (token !== '/') {
  17510. continue;
  17511. }
  17512. token = this.getToken();
  17513. switch (token) {
  17514. case 'CharStrings':
  17515. // The number immediately following CharStrings must be greater or
  17516. // equal to the number of CharStrings.
  17517. this.getToken();
  17518. this.getToken(); // read in 'dict'
  17519. this.getToken(); // read in 'dup'
  17520. this.getToken(); // read in 'begin'
  17521. while(true) {
  17522. token = this.getToken();
  17523. if (token === null || token === 'end') {
  17524. break;
  17525. }
  17526. if (token !== '/') {
  17527. continue;
  17528. }
  17529. var glyph = this.getToken();
  17530. length = this.readInt();
  17531. this.getToken(); // read in 'RD' or '-|'
  17532. data = stream.makeSubStream(stream.pos, length);
  17533. lenIV = program.properties.privateData['lenIV'];
  17534. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17535. // Skip past the required space and binary data.
  17536. stream.skip(length);
  17537. this.nextChar();
  17538. token = this.getToken(); // read in 'ND' or '|-'
  17539. if (token === 'noaccess') {
  17540. this.getToken(); // read in 'def'
  17541. }
  17542. charstrings.push({
  17543. glyph: glyph,
  17544. encoded: encoded
  17545. });
  17546. }
  17547. break;
  17548. case 'Subrs':
  17549. var num = this.readInt();
  17550. this.getToken(); // read in 'array'
  17551. while ((token = this.getToken()) === 'dup') {
  17552. var index = this.readInt();
  17553. length = this.readInt();
  17554. this.getToken(); // read in 'RD' or '-|'
  17555. data = stream.makeSubStream(stream.pos, length);
  17556. lenIV = program.properties.privateData['lenIV'];
  17557. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17558. // Skip past the required space and binary data.
  17559. stream.skip(length);
  17560. this.nextChar();
  17561. token = this.getToken(); // read in 'NP' or '|'
  17562. if (token === 'noaccess') {
  17563. this.getToken(); // read in 'put'
  17564. }
  17565. subrs[index] = encoded;
  17566. }
  17567. break;
  17568. case 'BlueValues':
  17569. case 'OtherBlues':
  17570. case 'FamilyBlues':
  17571. case 'FamilyOtherBlues':
  17572. var blueArray = this.readNumberArray();
  17573. // *Blue* values may contain invalid data: disables reading of
  17574. // those values when hinting is disabled.
  17575. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17576. HINTING_ENABLED) {
  17577. program.properties.privateData[token] = blueArray;
  17578. }
  17579. break;
  17580. case 'StemSnapH':
  17581. case 'StemSnapV':
  17582. program.properties.privateData[token] = this.readNumberArray();
  17583. break;
  17584. case 'StdHW':
  17585. case 'StdVW':
  17586. program.properties.privateData[token] =
  17587. this.readNumberArray()[0];
  17588. break;
  17589. case 'BlueShift':
  17590. case 'lenIV':
  17591. case 'BlueFuzz':
  17592. case 'BlueScale':
  17593. case 'LanguageGroup':
  17594. case 'ExpansionFactor':
  17595. program.properties.privateData[token] = this.readNumber();
  17596. break;
  17597. case 'ForceBold':
  17598. program.properties.privateData[token] = this.readBoolean();
  17599. break;
  17600. }
  17601. }
  17602. for (var i = 0; i < charstrings.length; i++) {
  17603. glyph = charstrings[i].glyph;
  17604. encoded = charstrings[i].encoded;
  17605. var charString = new Type1CharString();
  17606. var error = charString.convert(encoded, subrs);
  17607. var output = charString.output;
  17608. if (error) {
  17609. // It seems when FreeType encounters an error while evaluating a glyph
  17610. // that it completely ignores the glyph so we'll mimic that behaviour
  17611. // here and put an endchar to make the validator happy.
  17612. output = [14];
  17613. }
  17614. program.charstrings.push({
  17615. glyphName: glyph,
  17616. charstring: output,
  17617. width: charString.width,
  17618. lsb: charString.lsb,
  17619. seac: charString.seac
  17620. });
  17621. }
  17622. return program;
  17623. },
  17624. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17625. var token;
  17626. while ((token = this.getToken()) !== null) {
  17627. if (token !== '/') {
  17628. continue;
  17629. }
  17630. token = this.getToken();
  17631. switch (token) {
  17632. case 'FontMatrix':
  17633. var matrix = this.readNumberArray();
  17634. properties.fontMatrix = matrix;
  17635. break;
  17636. case 'Encoding':
  17637. var encodingArg = this.getToken();
  17638. var encoding;
  17639. if (!/^\d+$/.test(encodingArg)) {
  17640. // encoding name is specified
  17641. encoding = Encodings[encodingArg];
  17642. } else {
  17643. encoding = [];
  17644. var size = parseInt(encodingArg, 10) | 0;
  17645. this.getToken(); // read in 'array'
  17646. for (var j = 0; j < size; j++) {
  17647. token = this.getToken();
  17648. // skipping till first dup or def (e.g. ignoring for statement)
  17649. while (token !== 'dup' && token !== 'def') {
  17650. token = this.getToken();
  17651. if (token === null) {
  17652. return; // invalid header
  17653. }
  17654. }
  17655. if (token === 'def') {
  17656. break; // read all array data
  17657. }
  17658. var index = this.readInt();
  17659. this.getToken(); // read in '/'
  17660. var glyph = this.getToken();
  17661. encoding[index] = glyph;
  17662. this.getToken(); // read the in 'put'
  17663. }
  17664. }
  17665. properties.builtInEncoding = encoding;
  17666. break;
  17667. case 'FontBBox':
  17668. var fontBBox = this.readNumberArray();
  17669. // adjusting ascent/descent
  17670. properties.ascent = fontBBox[3];
  17671. properties.descent = fontBBox[1];
  17672. properties.ascentScaled = true;
  17673. break;
  17674. }
  17675. }
  17676. }
  17677. };
  17678. return Type1Parser;
  17679. })();
  17680. /**
  17681. * The CFF class takes a Type1 file and wrap it into a
  17682. * 'Compact Font Format' which itself embed Type2 charstrings.
  17683. */
  17684. var CFFStandardStrings = [
  17685. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17686. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17687. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17688. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17689. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17690. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17691. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17692. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17693. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17694. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17695. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17696. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17697. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17698. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17699. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17700. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17701. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17702. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17703. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17704. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17705. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17706. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17707. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17708. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17709. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17710. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17711. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17712. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17713. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17714. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17715. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17716. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17717. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17718. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17719. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17720. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  17721. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  17722. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  17723. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  17724. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  17725. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  17726. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  17727. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  17728. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  17729. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  17730. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  17731. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  17732. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  17733. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  17734. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  17735. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  17736. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  17737. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  17738. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  17739. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  17740. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  17741. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  17742. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  17743. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  17744. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  17745. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  17746. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  17747. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  17748. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  17749. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  17750. ];
  17751. // Type1Font is also a CIDFontType0.
  17752. var Type1Font = function Type1Font(name, file, properties) {
  17753. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  17754. // Also, length1 and length2 might be off by 6 bytes as well.
  17755. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  17756. var PFB_HEADER_SIZE = 6;
  17757. var headerBlockLength = properties.length1;
  17758. var eexecBlockLength = properties.length2;
  17759. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  17760. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  17761. if (pfbHeaderPresent) {
  17762. file.skip(PFB_HEADER_SIZE);
  17763. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17764. (pfbHeader[3] << 8) | pfbHeader[2];
  17765. }
  17766. // Get the data block containing glyphs and subrs informations
  17767. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  17768. var headerBlockParser = new Type1Parser(headerBlock);
  17769. headerBlockParser.extractFontHeader(properties);
  17770. if (pfbHeaderPresent) {
  17771. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  17772. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  17773. (pfbHeader[3] << 8) | pfbHeader[2];
  17774. }
  17775. // Decrypt the data blocks and retrieve it's content
  17776. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  17777. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  17778. var data = eexecBlockParser.extractFontProgram();
  17779. for (var info in data.properties) {
  17780. properties[info] = data.properties[info];
  17781. }
  17782. var charstrings = data.charstrings;
  17783. var type2Charstrings = this.getType2Charstrings(charstrings);
  17784. var subrs = this.getType2Subrs(data.subrs);
  17785. this.charstrings = charstrings;
  17786. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  17787. subrs, properties);
  17788. this.seacs = this.getSeacs(data.charstrings);
  17789. };
  17790. Type1Font.prototype = {
  17791. get numGlyphs() {
  17792. return this.charstrings.length + 1;
  17793. },
  17794. getCharset: function Type1Font_getCharset() {
  17795. var charset = ['.notdef'];
  17796. var charstrings = this.charstrings;
  17797. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17798. charset.push(charstrings[glyphId].glyphName);
  17799. }
  17800. return charset;
  17801. },
  17802. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  17803. var charstrings = this.charstrings;
  17804. var glyphNames = ['.notdef'], glyphId;
  17805. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  17806. glyphNames.push(charstrings[glyphId].glyphName);
  17807. }
  17808. var encoding = properties.builtInEncoding;
  17809. if (encoding) {
  17810. var builtInEncoding = {};
  17811. for (var charCode in encoding) {
  17812. glyphId = glyphNames.indexOf(encoding[charCode]);
  17813. if (glyphId >= 0) {
  17814. builtInEncoding[charCode] = glyphId;
  17815. }
  17816. }
  17817. }
  17818. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  17819. },
  17820. getSeacs: function Type1Font_getSeacs(charstrings) {
  17821. var i, ii;
  17822. var seacMap = [];
  17823. for (i = 0, ii = charstrings.length; i < ii; i++) {
  17824. var charstring = charstrings[i];
  17825. if (charstring.seac) {
  17826. // Offset by 1 for .notdef
  17827. seacMap[i + 1] = charstring.seac;
  17828. }
  17829. }
  17830. return seacMap;
  17831. },
  17832. getType2Charstrings: function Type1Font_getType2Charstrings(
  17833. type1Charstrings) {
  17834. var type2Charstrings = [];
  17835. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  17836. type2Charstrings.push(type1Charstrings[i].charstring);
  17837. }
  17838. return type2Charstrings;
  17839. },
  17840. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  17841. var bias = 0;
  17842. var count = type1Subrs.length;
  17843. if (count < 1133) {
  17844. bias = 107;
  17845. } else if (count < 33769) {
  17846. bias = 1131;
  17847. } else {
  17848. bias = 32768;
  17849. }
  17850. // Add a bunch of empty subrs to deal with the Type2 bias
  17851. var type2Subrs = [];
  17852. var i;
  17853. for (i = 0; i < bias; i++) {
  17854. type2Subrs.push([0x0B]);
  17855. }
  17856. for (i = 0; i < count; i++) {
  17857. type2Subrs.push(type1Subrs[i]);
  17858. }
  17859. return type2Subrs;
  17860. },
  17861. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  17862. var cff = new CFF();
  17863. cff.header = new CFFHeader(1, 0, 4, 4);
  17864. cff.names = [name];
  17865. var topDict = new CFFTopDict();
  17866. // CFF strings IDs 0...390 are predefined names, so refering
  17867. // to entries in our own String INDEX starts at SID 391.
  17868. topDict.setByName('version', 391);
  17869. topDict.setByName('Notice', 392);
  17870. topDict.setByName('FullName', 393);
  17871. topDict.setByName('FamilyName', 394);
  17872. topDict.setByName('Weight', 395);
  17873. topDict.setByName('Encoding', null); // placeholder
  17874. topDict.setByName('FontMatrix', properties.fontMatrix);
  17875. topDict.setByName('FontBBox', properties.bbox);
  17876. topDict.setByName('charset', null); // placeholder
  17877. topDict.setByName('CharStrings', null); // placeholder
  17878. topDict.setByName('Private', null); // placeholder
  17879. cff.topDict = topDict;
  17880. var strings = new CFFStrings();
  17881. strings.add('Version 0.11'); // Version
  17882. strings.add('See original notice'); // Notice
  17883. strings.add(name); // FullName
  17884. strings.add(name); // FamilyName
  17885. strings.add('Medium'); // Weight
  17886. cff.strings = strings;
  17887. cff.globalSubrIndex = new CFFIndex();
  17888. var count = glyphs.length;
  17889. var charsetArray = [0];
  17890. var i, ii;
  17891. for (i = 0; i < count; i++) {
  17892. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  17893. // TODO: Insert the string and correctly map it. Previously it was
  17894. // thought mapping names that aren't in the standard strings to .notdef
  17895. // was fine, however in issue818 when mapping them all to .notdef the
  17896. // adieresis glyph no longer worked.
  17897. if (index === -1) {
  17898. index = 0;
  17899. }
  17900. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  17901. }
  17902. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  17903. var charStringsIndex = new CFFIndex();
  17904. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  17905. for (i = 0; i < count; i++) {
  17906. charStringsIndex.add(glyphs[i]);
  17907. }
  17908. cff.charStrings = charStringsIndex;
  17909. var privateDict = new CFFPrivateDict();
  17910. privateDict.setByName('Subrs', null); // placeholder
  17911. var fields = [
  17912. 'BlueValues',
  17913. 'OtherBlues',
  17914. 'FamilyBlues',
  17915. 'FamilyOtherBlues',
  17916. 'StemSnapH',
  17917. 'StemSnapV',
  17918. 'BlueShift',
  17919. 'BlueFuzz',
  17920. 'BlueScale',
  17921. 'LanguageGroup',
  17922. 'ExpansionFactor',
  17923. 'ForceBold',
  17924. 'StdHW',
  17925. 'StdVW'
  17926. ];
  17927. for (i = 0, ii = fields.length; i < ii; i++) {
  17928. var field = fields[i];
  17929. if (!properties.privateData.hasOwnProperty(field)) {
  17930. continue;
  17931. }
  17932. var value = properties.privateData[field];
  17933. if (isArray(value)) {
  17934. // All of the private dictionary array data in CFF must be stored as
  17935. // "delta-encoded" numbers.
  17936. for (var j = value.length - 1; j > 0; j--) {
  17937. value[j] -= value[j - 1]; // ... difference from previous value
  17938. }
  17939. }
  17940. privateDict.setByName(field, value);
  17941. }
  17942. cff.topDict.privateDict = privateDict;
  17943. var subrIndex = new CFFIndex();
  17944. for (i = 0, ii = subrs.length; i < ii; i++) {
  17945. subrIndex.add(subrs[i]);
  17946. }
  17947. privateDict.subrsIndex = subrIndex;
  17948. var compiler = new CFFCompiler(cff);
  17949. return compiler.compile();
  17950. }
  17951. };
  17952. var CFFFont = (function CFFFontClosure() {
  17953. function CFFFont(file, properties) {
  17954. this.properties = properties;
  17955. var parser = new CFFParser(file, properties);
  17956. this.cff = parser.parse();
  17957. var compiler = new CFFCompiler(this.cff);
  17958. this.seacs = this.cff.seacs;
  17959. try {
  17960. this.data = compiler.compile();
  17961. } catch (e) {
  17962. warn('Failed to compile font ' + properties.loadedName);
  17963. // There may have just been an issue with the compiler, set the data
  17964. // anyway and hope the font loaded.
  17965. this.data = file;
  17966. }
  17967. }
  17968. CFFFont.prototype = {
  17969. get numGlyphs() {
  17970. return this.cff.charStrings.count;
  17971. },
  17972. getCharset: function CFFFont_getCharset() {
  17973. return this.cff.charset.charset;
  17974. },
  17975. getGlyphMapping: function CFFFont_getGlyphMapping() {
  17976. var cff = this.cff;
  17977. var properties = this.properties;
  17978. var charsets = cff.charset.charset;
  17979. var charCodeToGlyphId;
  17980. var glyphId;
  17981. if (properties.composite) {
  17982. charCodeToGlyphId = Object.create(null);
  17983. if (cff.isCIDFont) {
  17984. // If the font is actually a CID font then we should use the charset
  17985. // to map CIDs to GIDs.
  17986. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  17987. var cid = charsets[glyphId];
  17988. var charCode = properties.cMap.charCodeOf(cid);
  17989. charCodeToGlyphId[charCode] = glyphId;
  17990. }
  17991. } else {
  17992. // If it is NOT actually a CID font then CIDs should be mapped
  17993. // directly to GIDs.
  17994. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  17995. charCodeToGlyphId[glyphId] = glyphId;
  17996. }
  17997. }
  17998. return charCodeToGlyphId;
  17999. }
  18000. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18001. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18002. return charCodeToGlyphId;
  18003. }
  18004. };
  18005. return CFFFont;
  18006. })();
  18007. var CFFParser = (function CFFParserClosure() {
  18008. var CharstringValidationData = [
  18009. null,
  18010. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18011. null,
  18012. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18013. { id: 'vmoveto', min: 1, stackClearing: true },
  18014. { id: 'rlineto', min: 2, resetStack: true },
  18015. { id: 'hlineto', min: 1, resetStack: true },
  18016. { id: 'vlineto', min: 1, resetStack: true },
  18017. { id: 'rrcurveto', min: 6, resetStack: true },
  18018. null,
  18019. { id: 'callsubr', min: 1, undefStack: true },
  18020. { id: 'return', min: 0, undefStack: true },
  18021. null, // 12
  18022. null,
  18023. { id: 'endchar', min: 0, stackClearing: true },
  18024. null,
  18025. null,
  18026. null,
  18027. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18028. { id: 'hintmask', min: 0, stackClearing: true },
  18029. { id: 'cntrmask', min: 0, stackClearing: true },
  18030. { id: 'rmoveto', min: 2, stackClearing: true },
  18031. { id: 'hmoveto', min: 1, stackClearing: true },
  18032. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18033. { id: 'rcurveline', min: 8, resetStack: true },
  18034. { id: 'rlinecurve', min: 8, resetStack: true },
  18035. { id: 'vvcurveto', min: 4, resetStack: true },
  18036. { id: 'hhcurveto', min: 4, resetStack: true },
  18037. null, // shortint
  18038. { id: 'callgsubr', min: 1, undefStack: true },
  18039. { id: 'vhcurveto', min: 4, resetStack: true },
  18040. { id: 'hvcurveto', min: 4, resetStack: true }
  18041. ];
  18042. var CharstringValidationData12 = [
  18043. null,
  18044. null,
  18045. null,
  18046. { id: 'and', min: 2, stackDelta: -1 },
  18047. { id: 'or', min: 2, stackDelta: -1 },
  18048. { id: 'not', min: 1, stackDelta: 0 },
  18049. null,
  18050. null,
  18051. null,
  18052. { id: 'abs', min: 1, stackDelta: 0 },
  18053. { id: 'add', min: 2, stackDelta: -1,
  18054. stackFn: function stack_div(stack, index) {
  18055. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18056. }
  18057. },
  18058. { id: 'sub', min: 2, stackDelta: -1,
  18059. stackFn: function stack_div(stack, index) {
  18060. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18061. }
  18062. },
  18063. { id: 'div', min: 2, stackDelta: -1,
  18064. stackFn: function stack_div(stack, index) {
  18065. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18066. }
  18067. },
  18068. null,
  18069. { id: 'neg', min: 1, stackDelta: 0,
  18070. stackFn: function stack_div(stack, index) {
  18071. stack[index - 1] = -stack[index - 1];
  18072. }
  18073. },
  18074. { id: 'eq', min: 2, stackDelta: -1 },
  18075. null,
  18076. null,
  18077. { id: 'drop', min: 1, stackDelta: -1 },
  18078. null,
  18079. { id: 'put', min: 2, stackDelta: -2 },
  18080. { id: 'get', min: 1, stackDelta: 0 },
  18081. { id: 'ifelse', min: 4, stackDelta: -3 },
  18082. { id: 'random', min: 0, stackDelta: 1 },
  18083. { id: 'mul', min: 2, stackDelta: -1,
  18084. stackFn: function stack_div(stack, index) {
  18085. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18086. }
  18087. },
  18088. null,
  18089. { id: 'sqrt', min: 1, stackDelta: 0 },
  18090. { id: 'dup', min: 1, stackDelta: 1 },
  18091. { id: 'exch', min: 2, stackDelta: 0 },
  18092. { id: 'index', min: 2, stackDelta: 0 },
  18093. { id: 'roll', min: 3, stackDelta: -2 },
  18094. null,
  18095. null,
  18096. null,
  18097. { id: 'hflex', min: 7, resetStack: true },
  18098. { id: 'flex', min: 13, resetStack: true },
  18099. { id: 'hflex1', min: 9, resetStack: true },
  18100. { id: 'flex1', min: 11, resetStack: true }
  18101. ];
  18102. function CFFParser(file, properties) {
  18103. this.bytes = file.getBytes();
  18104. this.properties = properties;
  18105. }
  18106. CFFParser.prototype = {
  18107. parse: function CFFParser_parse() {
  18108. var properties = this.properties;
  18109. var cff = new CFF();
  18110. this.cff = cff;
  18111. // The first five sections must be in order, all the others are reached
  18112. // via offsets contained in one of the below.
  18113. var header = this.parseHeader();
  18114. var nameIndex = this.parseIndex(header.endPos);
  18115. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18116. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18117. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18118. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18119. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18120. cff.header = header.obj;
  18121. cff.names = this.parseNameIndex(nameIndex.obj);
  18122. cff.strings = this.parseStringIndex(stringIndex.obj);
  18123. cff.topDict = topDict;
  18124. cff.globalSubrIndex = globalSubrIndex.obj;
  18125. this.parsePrivateDict(cff.topDict);
  18126. cff.isCIDFont = topDict.hasName('ROS');
  18127. var charStringOffset = topDict.getByName('CharStrings');
  18128. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18129. cff.charStrings = charStringsAndSeacs.charStrings;
  18130. cff.seacs = charStringsAndSeacs.seacs;
  18131. cff.widths = charStringsAndSeacs.widths;
  18132. var fontMatrix = topDict.getByName('FontMatrix');
  18133. if (fontMatrix) {
  18134. properties.fontMatrix = fontMatrix;
  18135. }
  18136. var fontBBox = topDict.getByName('FontBBox');
  18137. if (fontBBox) {
  18138. // adjusting ascent/descent
  18139. properties.ascent = fontBBox[3];
  18140. properties.descent = fontBBox[1];
  18141. properties.ascentScaled = true;
  18142. }
  18143. var charset, encoding;
  18144. if (cff.isCIDFont) {
  18145. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18146. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18147. var dictRaw = fdArrayIndex.get(i);
  18148. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18149. cff.strings);
  18150. this.parsePrivateDict(fontDict);
  18151. cff.fdArray.push(fontDict);
  18152. }
  18153. // cid fonts don't have an encoding
  18154. encoding = null;
  18155. charset = this.parseCharsets(topDict.getByName('charset'),
  18156. cff.charStrings.count, cff.strings, true);
  18157. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18158. cff.charStrings.count);
  18159. } else {
  18160. charset = this.parseCharsets(topDict.getByName('charset'),
  18161. cff.charStrings.count, cff.strings, false);
  18162. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18163. properties,
  18164. cff.strings, charset.charset);
  18165. }
  18166. cff.charset = charset;
  18167. cff.encoding = encoding;
  18168. return cff;
  18169. },
  18170. parseHeader: function CFFParser_parseHeader() {
  18171. var bytes = this.bytes;
  18172. var bytesLength = bytes.length;
  18173. var offset = 0;
  18174. // Prevent an infinite loop, by checking that the offset is within the
  18175. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18176. while (offset < bytesLength && bytes[offset] !== 1) {
  18177. ++offset;
  18178. }
  18179. if (offset >= bytesLength) {
  18180. error('Invalid CFF header');
  18181. } else if (offset !== 0) {
  18182. info('cff data is shifted');
  18183. bytes = bytes.subarray(offset);
  18184. this.bytes = bytes;
  18185. }
  18186. var major = bytes[0];
  18187. var minor = bytes[1];
  18188. var hdrSize = bytes[2];
  18189. var offSize = bytes[3];
  18190. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18191. return { obj: header, endPos: hdrSize };
  18192. },
  18193. parseDict: function CFFParser_parseDict(dict) {
  18194. var pos = 0;
  18195. function parseOperand() {
  18196. var value = dict[pos++];
  18197. if (value === 30) {
  18198. return parseFloatOperand(pos);
  18199. } else if (value === 28) {
  18200. value = dict[pos++];
  18201. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18202. return value;
  18203. } else if (value === 29) {
  18204. value = dict[pos++];
  18205. value = (value << 8) | dict[pos++];
  18206. value = (value << 8) | dict[pos++];
  18207. value = (value << 8) | dict[pos++];
  18208. return value;
  18209. } else if (value >= 32 && value <= 246) {
  18210. return value - 139;
  18211. } else if (value >= 247 && value <= 250) {
  18212. return ((value - 247) * 256) + dict[pos++] + 108;
  18213. } else if (value >= 251 && value <= 254) {
  18214. return -((value - 251) * 256) - dict[pos++] - 108;
  18215. } else {
  18216. error('255 is not a valid DICT command');
  18217. }
  18218. return -1;
  18219. }
  18220. function parseFloatOperand() {
  18221. var str = '';
  18222. var eof = 15;
  18223. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18224. '9', '.', 'E', 'E-', null, '-'];
  18225. var length = dict.length;
  18226. while (pos < length) {
  18227. var b = dict[pos++];
  18228. var b1 = b >> 4;
  18229. var b2 = b & 15;
  18230. if (b1 === eof) {
  18231. break;
  18232. }
  18233. str += lookup[b1];
  18234. if (b2 === eof) {
  18235. break;
  18236. }
  18237. str += lookup[b2];
  18238. }
  18239. return parseFloat(str);
  18240. }
  18241. var operands = [];
  18242. var entries = [];
  18243. pos = 0;
  18244. var end = dict.length;
  18245. while (pos < end) {
  18246. var b = dict[pos];
  18247. if (b <= 21) {
  18248. if (b === 12) {
  18249. b = (b << 8) | dict[++pos];
  18250. }
  18251. entries.push([b, operands]);
  18252. operands = [];
  18253. ++pos;
  18254. } else {
  18255. operands.push(parseOperand());
  18256. }
  18257. }
  18258. return entries;
  18259. },
  18260. parseIndex: function CFFParser_parseIndex(pos) {
  18261. var cffIndex = new CFFIndex();
  18262. var bytes = this.bytes;
  18263. var count = (bytes[pos++] << 8) | bytes[pos++];
  18264. var offsets = [];
  18265. var end = pos;
  18266. var i, ii;
  18267. if (count !== 0) {
  18268. var offsetSize = bytes[pos++];
  18269. // add 1 for offset to determine size of last object
  18270. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18271. for (i = 0, ii = count + 1; i < ii; ++i) {
  18272. var offset = 0;
  18273. for (var j = 0; j < offsetSize; ++j) {
  18274. offset <<= 8;
  18275. offset += bytes[pos++];
  18276. }
  18277. offsets.push(startPos + offset);
  18278. }
  18279. end = offsets[count];
  18280. }
  18281. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18282. var offsetStart = offsets[i];
  18283. var offsetEnd = offsets[i + 1];
  18284. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18285. }
  18286. return {obj: cffIndex, endPos: end};
  18287. },
  18288. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18289. var names = [];
  18290. for (var i = 0, ii = index.count; i < ii; ++i) {
  18291. var name = index.get(i);
  18292. // OTS doesn't allow names to be over 127 characters.
  18293. var length = Math.min(name.length, 127);
  18294. var data = [];
  18295. // OTS also only permits certain characters in the name.
  18296. for (var j = 0; j < length; ++j) {
  18297. var c = name[j];
  18298. if (j === 0 && c === 0) {
  18299. data[j] = c;
  18300. continue;
  18301. }
  18302. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18303. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18304. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18305. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18306. data[j] = 95;
  18307. continue;
  18308. }
  18309. data[j] = c;
  18310. }
  18311. names.push(bytesToString(data));
  18312. }
  18313. return names;
  18314. },
  18315. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18316. var strings = new CFFStrings();
  18317. for (var i = 0, ii = index.count; i < ii; ++i) {
  18318. var data = index.get(i);
  18319. strings.add(bytesToString(data));
  18320. }
  18321. return strings;
  18322. },
  18323. createDict: function CFFParser_createDict(Type, dict, strings) {
  18324. var cffDict = new Type(strings);
  18325. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18326. var pair = dict[i];
  18327. var key = pair[0];
  18328. var value = pair[1];
  18329. cffDict.setByKey(key, value);
  18330. }
  18331. return cffDict;
  18332. },
  18333. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18334. var charStrings = this.parseIndex(charStringOffset).obj;
  18335. var seacs = [];
  18336. var widths = [];
  18337. var count = charStrings.count;
  18338. for (var i = 0; i < count; i++) {
  18339. var charstring = charStrings.get(i);
  18340. var stackSize = 0;
  18341. var stack = [];
  18342. var undefStack = true;
  18343. var hints = 0;
  18344. var valid = true;
  18345. var data = charstring;
  18346. var length = data.length;
  18347. var firstStackClearing = true;
  18348. for (var j = 0; j < length;) {
  18349. var value = data[j++];
  18350. var validationCommand = null;
  18351. if (value === 12) {
  18352. var q = data[j++];
  18353. if (q === 0) {
  18354. // The CFF specification state that the 'dotsection' command
  18355. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18356. // charstrings processors should support them. Unfortunately
  18357. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18358. // is replaced by a useless (0, hmoveto).
  18359. data[j - 2] = 139;
  18360. data[j - 1] = 22;
  18361. stackSize = 0;
  18362. } else {
  18363. validationCommand = CharstringValidationData12[q];
  18364. }
  18365. } else if (value === 28) { // number (16 bit)
  18366. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18367. j += 2;
  18368. stackSize++;
  18369. } else if (value === 14) {
  18370. if (stackSize >= 4) {
  18371. stackSize -= 4;
  18372. if (SEAC_ANALYSIS_ENABLED) {
  18373. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18374. valid = false;
  18375. }
  18376. }
  18377. validationCommand = CharstringValidationData[value];
  18378. } else if (value >= 32 && value <= 246) { // number
  18379. stack[stackSize] = value - 139;
  18380. stackSize++;
  18381. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18382. stack[stackSize] = (value < 251 ?
  18383. ((value - 247) << 8) + data[j] + 108 :
  18384. -((value - 251) << 8) - data[j] - 108);
  18385. j++;
  18386. stackSize++;
  18387. } else if (value === 255) { // number (32 bit)
  18388. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18389. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18390. j += 4;
  18391. stackSize++;
  18392. } else if (value === 19 || value === 20) {
  18393. hints += stackSize >> 1;
  18394. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18395. stackSize %= 2;
  18396. validationCommand = CharstringValidationData[value];
  18397. } else {
  18398. validationCommand = CharstringValidationData[value];
  18399. }
  18400. if (validationCommand) {
  18401. if (validationCommand.stem) {
  18402. hints += stackSize >> 1;
  18403. }
  18404. if ('min' in validationCommand) {
  18405. if (!undefStack && stackSize < validationCommand.min) {
  18406. warn('Not enough parameters for ' + validationCommand.id +
  18407. '; actual: ' + stackSize +
  18408. ', expected: ' + validationCommand.min);
  18409. valid = false;
  18410. break;
  18411. }
  18412. }
  18413. if (firstStackClearing && validationCommand.stackClearing) {
  18414. firstStackClearing = false;
  18415. // the optional character width can be found before the first
  18416. // stack-clearing command arguments
  18417. stackSize -= validationCommand.min;
  18418. if (stackSize >= 2 && validationCommand.stem) {
  18419. // there are even amount of arguments for stem commands
  18420. stackSize %= 2;
  18421. } else if (stackSize > 1) {
  18422. warn('Found too many parameters for stack-clearing command');
  18423. }
  18424. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18425. widths[i] = stack[stackSize - 1];
  18426. }
  18427. }
  18428. if ('stackDelta' in validationCommand) {
  18429. if ('stackFn' in validationCommand) {
  18430. validationCommand.stackFn(stack, stackSize);
  18431. }
  18432. stackSize += validationCommand.stackDelta;
  18433. } else if (validationCommand.stackClearing) {
  18434. stackSize = 0;
  18435. } else if (validationCommand.resetStack) {
  18436. stackSize = 0;
  18437. undefStack = false;
  18438. } else if (validationCommand.undefStack) {
  18439. stackSize = 0;
  18440. undefStack = true;
  18441. firstStackClearing = false;
  18442. }
  18443. }
  18444. }
  18445. if (!valid) {
  18446. // resetting invalid charstring to single 'endchar'
  18447. charStrings.set(i, new Uint8Array([14]));
  18448. }
  18449. }
  18450. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18451. },
  18452. emptyPrivateDictionary:
  18453. function CFFParser_emptyPrivateDictionary(parentDict) {
  18454. var privateDict = this.createDict(CFFPrivateDict, [],
  18455. parentDict.strings);
  18456. parentDict.setByKey(18, [0, 0]);
  18457. parentDict.privateDict = privateDict;
  18458. },
  18459. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18460. // no private dict, do nothing
  18461. if (!parentDict.hasName('Private')) {
  18462. this.emptyPrivateDictionary(parentDict);
  18463. return;
  18464. }
  18465. var privateOffset = parentDict.getByName('Private');
  18466. // make sure the params are formatted correctly
  18467. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18468. parentDict.removeByName('Private');
  18469. return;
  18470. }
  18471. var size = privateOffset[0];
  18472. var offset = privateOffset[1];
  18473. // remove empty dicts or ones that refer to invalid location
  18474. if (size === 0 || offset >= this.bytes.length) {
  18475. this.emptyPrivateDictionary(parentDict);
  18476. return;
  18477. }
  18478. var privateDictEnd = offset + size;
  18479. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18480. var dict = this.parseDict(dictData);
  18481. var privateDict = this.createDict(CFFPrivateDict, dict,
  18482. parentDict.strings);
  18483. parentDict.privateDict = privateDict;
  18484. // Parse the Subrs index also since it's relative to the private dict.
  18485. if (!privateDict.getByName('Subrs')) {
  18486. return;
  18487. }
  18488. var subrsOffset = privateDict.getByName('Subrs');
  18489. var relativeOffset = offset + subrsOffset;
  18490. // Validate the offset.
  18491. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18492. this.emptyPrivateDictionary(parentDict);
  18493. return;
  18494. }
  18495. var subrsIndex = this.parseIndex(relativeOffset);
  18496. privateDict.subrsIndex = subrsIndex.obj;
  18497. },
  18498. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18499. if (pos === 0) {
  18500. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18501. ISOAdobeCharset);
  18502. } else if (pos === 1) {
  18503. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18504. ExpertCharset);
  18505. } else if (pos === 2) {
  18506. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18507. ExpertSubsetCharset);
  18508. }
  18509. var bytes = this.bytes;
  18510. var start = pos;
  18511. var format = bytes[pos++];
  18512. var charset = ['.notdef'];
  18513. var id, count, i;
  18514. // subtract 1 for the .notdef glyph
  18515. length -= 1;
  18516. switch (format) {
  18517. case 0:
  18518. for (i = 0; i < length; i++) {
  18519. id = (bytes[pos++] << 8) | bytes[pos++];
  18520. charset.push(cid ? id : strings.get(id));
  18521. }
  18522. break;
  18523. case 1:
  18524. while (charset.length <= length) {
  18525. id = (bytes[pos++] << 8) | bytes[pos++];
  18526. count = bytes[pos++];
  18527. for (i = 0; i <= count; i++) {
  18528. charset.push(cid ? id++ : strings.get(id++));
  18529. }
  18530. }
  18531. break;
  18532. case 2:
  18533. while (charset.length <= length) {
  18534. id = (bytes[pos++] << 8) | bytes[pos++];
  18535. count = (bytes[pos++] << 8) | bytes[pos++];
  18536. for (i = 0; i <= count; i++) {
  18537. charset.push(cid ? id++ : strings.get(id++));
  18538. }
  18539. }
  18540. break;
  18541. default:
  18542. error('Unknown charset format');
  18543. }
  18544. // Raw won't be needed if we actually compile the charset.
  18545. var end = pos;
  18546. var raw = bytes.subarray(start, end);
  18547. return new CFFCharset(false, format, charset, raw);
  18548. },
  18549. parseEncoding: function CFFParser_parseEncoding(pos,
  18550. properties,
  18551. strings,
  18552. charset) {
  18553. var encoding = {};
  18554. var bytes = this.bytes;
  18555. var predefined = false;
  18556. var hasSupplement = false;
  18557. var format, i, ii;
  18558. var raw = null;
  18559. function readSupplement() {
  18560. var supplementsCount = bytes[pos++];
  18561. for (i = 0; i < supplementsCount; i++) {
  18562. var code = bytes[pos++];
  18563. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18564. encoding[code] = charset.indexOf(strings.get(sid));
  18565. }
  18566. }
  18567. if (pos === 0 || pos === 1) {
  18568. predefined = true;
  18569. format = pos;
  18570. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18571. Encodings.StandardEncoding;
  18572. for (i = 0, ii = charset.length; i < ii; i++) {
  18573. var index = baseEncoding.indexOf(charset[i]);
  18574. if (index !== -1) {
  18575. encoding[index] = i;
  18576. }
  18577. }
  18578. } else {
  18579. var dataStart = pos;
  18580. format = bytes[pos++];
  18581. switch (format & 0x7f) {
  18582. case 0:
  18583. var glyphsCount = bytes[pos++];
  18584. for (i = 1; i <= glyphsCount; i++) {
  18585. encoding[bytes[pos++]] = i;
  18586. }
  18587. break;
  18588. case 1:
  18589. var rangesCount = bytes[pos++];
  18590. var gid = 1;
  18591. for (i = 0; i < rangesCount; i++) {
  18592. var start = bytes[pos++];
  18593. var left = bytes[pos++];
  18594. for (var j = start; j <= start + left; j++) {
  18595. encoding[j] = gid++;
  18596. }
  18597. }
  18598. break;
  18599. default:
  18600. error('Unknow encoding format: ' + format + ' in CFF');
  18601. break;
  18602. }
  18603. var dataEnd = pos;
  18604. if (format & 0x80) {
  18605. // The font sanitizer does not support CFF encoding with a
  18606. // supplement, since the encoding is not really used to map
  18607. // between gid to glyph, let's overwrite what is declared in
  18608. // the top dictionary to let the sanitizer think the font use
  18609. // StandardEncoding, that's a lie but that's ok.
  18610. bytes[dataStart] &= 0x7f;
  18611. readSupplement();
  18612. hasSupplement = true;
  18613. }
  18614. raw = bytes.subarray(dataStart, dataEnd);
  18615. }
  18616. format = format & 0x7f;
  18617. return new CFFEncoding(predefined, format, encoding, raw);
  18618. },
  18619. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18620. var start = pos;
  18621. var bytes = this.bytes;
  18622. var format = bytes[pos++];
  18623. var fdSelect = [];
  18624. var i;
  18625. switch (format) {
  18626. case 0:
  18627. for (i = 0; i < length; ++i) {
  18628. var id = bytes[pos++];
  18629. fdSelect.push(id);
  18630. }
  18631. break;
  18632. case 3:
  18633. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18634. for (i = 0; i < rangesCount; ++i) {
  18635. var first = (bytes[pos++] << 8) | bytes[pos++];
  18636. var fdIndex = bytes[pos++];
  18637. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18638. for (var j = first; j < next; ++j) {
  18639. fdSelect.push(fdIndex);
  18640. }
  18641. }
  18642. // Advance past the sentinel(next).
  18643. pos += 2;
  18644. break;
  18645. default:
  18646. error('Unknown fdselect format ' + format);
  18647. break;
  18648. }
  18649. var end = pos;
  18650. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18651. }
  18652. };
  18653. return CFFParser;
  18654. })();
  18655. // Compact Font Format
  18656. var CFF = (function CFFClosure() {
  18657. function CFF() {
  18658. this.header = null;
  18659. this.names = [];
  18660. this.topDict = null;
  18661. this.strings = new CFFStrings();
  18662. this.globalSubrIndex = null;
  18663. // The following could really be per font, but since we only have one font
  18664. // store them here.
  18665. this.encoding = null;
  18666. this.charset = null;
  18667. this.charStrings = null;
  18668. this.fdArray = [];
  18669. this.fdSelect = null;
  18670. this.isCIDFont = false;
  18671. }
  18672. return CFF;
  18673. })();
  18674. var CFFHeader = (function CFFHeaderClosure() {
  18675. function CFFHeader(major, minor, hdrSize, offSize) {
  18676. this.major = major;
  18677. this.minor = minor;
  18678. this.hdrSize = hdrSize;
  18679. this.offSize = offSize;
  18680. }
  18681. return CFFHeader;
  18682. })();
  18683. var CFFStrings = (function CFFStringsClosure() {
  18684. function CFFStrings() {
  18685. this.strings = [];
  18686. }
  18687. CFFStrings.prototype = {
  18688. get: function CFFStrings_get(index) {
  18689. if (index >= 0 && index <= 390) {
  18690. return CFFStandardStrings[index];
  18691. }
  18692. if (index - 391 <= this.strings.length) {
  18693. return this.strings[index - 391];
  18694. }
  18695. return CFFStandardStrings[0];
  18696. },
  18697. add: function CFFStrings_add(value) {
  18698. this.strings.push(value);
  18699. },
  18700. get count() {
  18701. return this.strings.length;
  18702. }
  18703. };
  18704. return CFFStrings;
  18705. })();
  18706. var CFFIndex = (function CFFIndexClosure() {
  18707. function CFFIndex() {
  18708. this.objects = [];
  18709. this.length = 0;
  18710. }
  18711. CFFIndex.prototype = {
  18712. add: function CFFIndex_add(data) {
  18713. this.length += data.length;
  18714. this.objects.push(data);
  18715. },
  18716. set: function CFFIndex_set(index, data) {
  18717. this.length += data.length - this.objects[index].length;
  18718. this.objects[index] = data;
  18719. },
  18720. get: function CFFIndex_get(index) {
  18721. return this.objects[index];
  18722. },
  18723. get count() {
  18724. return this.objects.length;
  18725. }
  18726. };
  18727. return CFFIndex;
  18728. })();
  18729. var CFFDict = (function CFFDictClosure() {
  18730. function CFFDict(tables, strings) {
  18731. this.keyToNameMap = tables.keyToNameMap;
  18732. this.nameToKeyMap = tables.nameToKeyMap;
  18733. this.defaults = tables.defaults;
  18734. this.types = tables.types;
  18735. this.opcodes = tables.opcodes;
  18736. this.order = tables.order;
  18737. this.strings = strings;
  18738. this.values = {};
  18739. }
  18740. CFFDict.prototype = {
  18741. // value should always be an array
  18742. setByKey: function CFFDict_setByKey(key, value) {
  18743. if (!(key in this.keyToNameMap)) {
  18744. return false;
  18745. }
  18746. // ignore empty values
  18747. if (value.length === 0) {
  18748. return true;
  18749. }
  18750. var type = this.types[key];
  18751. // remove the array wrapping these types of values
  18752. if (type === 'num' || type === 'sid' || type === 'offset') {
  18753. value = value[0];
  18754. }
  18755. this.values[key] = value;
  18756. return true;
  18757. },
  18758. setByName: function CFFDict_setByName(name, value) {
  18759. if (!(name in this.nameToKeyMap)) {
  18760. error('Invalid dictionary name "' + name + '"');
  18761. }
  18762. this.values[this.nameToKeyMap[name]] = value;
  18763. },
  18764. hasName: function CFFDict_hasName(name) {
  18765. return this.nameToKeyMap[name] in this.values;
  18766. },
  18767. getByName: function CFFDict_getByName(name) {
  18768. if (!(name in this.nameToKeyMap)) {
  18769. error('Invalid dictionary name "' + name + '"');
  18770. }
  18771. var key = this.nameToKeyMap[name];
  18772. if (!(key in this.values)) {
  18773. return this.defaults[key];
  18774. }
  18775. return this.values[key];
  18776. },
  18777. removeByName: function CFFDict_removeByName(name) {
  18778. delete this.values[this.nameToKeyMap[name]];
  18779. }
  18780. };
  18781. CFFDict.createTables = function CFFDict_createTables(layout) {
  18782. var tables = {
  18783. keyToNameMap: {},
  18784. nameToKeyMap: {},
  18785. defaults: {},
  18786. types: {},
  18787. opcodes: {},
  18788. order: []
  18789. };
  18790. for (var i = 0, ii = layout.length; i < ii; ++i) {
  18791. var entry = layout[i];
  18792. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  18793. tables.keyToNameMap[key] = entry[1];
  18794. tables.nameToKeyMap[entry[1]] = key;
  18795. tables.types[key] = entry[2];
  18796. tables.defaults[key] = entry[3];
  18797. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  18798. tables.order.push(key);
  18799. }
  18800. return tables;
  18801. };
  18802. return CFFDict;
  18803. })();
  18804. var CFFTopDict = (function CFFTopDictClosure() {
  18805. var layout = [
  18806. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  18807. [[12, 20], 'SyntheticBase', 'num', null],
  18808. [0, 'version', 'sid', null],
  18809. [1, 'Notice', 'sid', null],
  18810. [[12, 0], 'Copyright', 'sid', null],
  18811. [2, 'FullName', 'sid', null],
  18812. [3, 'FamilyName', 'sid', null],
  18813. [4, 'Weight', 'sid', null],
  18814. [[12, 1], 'isFixedPitch', 'num', 0],
  18815. [[12, 2], 'ItalicAngle', 'num', 0],
  18816. [[12, 3], 'UnderlinePosition', 'num', -100],
  18817. [[12, 4], 'UnderlineThickness', 'num', 50],
  18818. [[12, 5], 'PaintType', 'num', 0],
  18819. [[12, 6], 'CharstringType', 'num', 2],
  18820. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  18821. [0.001, 0, 0, 0.001, 0, 0]],
  18822. [13, 'UniqueID', 'num', null],
  18823. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  18824. [[12, 8], 'StrokeWidth', 'num', 0],
  18825. [14, 'XUID', 'array', null],
  18826. [15, 'charset', 'offset', 0],
  18827. [16, 'Encoding', 'offset', 0],
  18828. [17, 'CharStrings', 'offset', 0],
  18829. [18, 'Private', ['offset', 'offset'], null],
  18830. [[12, 21], 'PostScript', 'sid', null],
  18831. [[12, 22], 'BaseFontName', 'sid', null],
  18832. [[12, 23], 'BaseFontBlend', 'delta', null],
  18833. [[12, 31], 'CIDFontVersion', 'num', 0],
  18834. [[12, 32], 'CIDFontRevision', 'num', 0],
  18835. [[12, 33], 'CIDFontType', 'num', 0],
  18836. [[12, 34], 'CIDCount', 'num', 8720],
  18837. [[12, 35], 'UIDBase', 'num', null],
  18838. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  18839. // before FDArray.
  18840. [[12, 37], 'FDSelect', 'offset', null],
  18841. [[12, 36], 'FDArray', 'offset', null],
  18842. [[12, 38], 'FontName', 'sid', null]
  18843. ];
  18844. var tables = null;
  18845. function CFFTopDict(strings) {
  18846. if (tables === null) {
  18847. tables = CFFDict.createTables(layout);
  18848. }
  18849. CFFDict.call(this, tables, strings);
  18850. this.privateDict = null;
  18851. }
  18852. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  18853. return CFFTopDict;
  18854. })();
  18855. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  18856. var layout = [
  18857. [6, 'BlueValues', 'delta', null],
  18858. [7, 'OtherBlues', 'delta', null],
  18859. [8, 'FamilyBlues', 'delta', null],
  18860. [9, 'FamilyOtherBlues', 'delta', null],
  18861. [[12, 9], 'BlueScale', 'num', 0.039625],
  18862. [[12, 10], 'BlueShift', 'num', 7],
  18863. [[12, 11], 'BlueFuzz', 'num', 1],
  18864. [10, 'StdHW', 'num', null],
  18865. [11, 'StdVW', 'num', null],
  18866. [[12, 12], 'StemSnapH', 'delta', null],
  18867. [[12, 13], 'StemSnapV', 'delta', null],
  18868. [[12, 14], 'ForceBold', 'num', 0],
  18869. [[12, 17], 'LanguageGroup', 'num', 0],
  18870. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  18871. [[12, 19], 'initialRandomSeed', 'num', 0],
  18872. [20, 'defaultWidthX', 'num', 0],
  18873. [21, 'nominalWidthX', 'num', 0],
  18874. [19, 'Subrs', 'offset', null]
  18875. ];
  18876. var tables = null;
  18877. function CFFPrivateDict(strings) {
  18878. if (tables === null) {
  18879. tables = CFFDict.createTables(layout);
  18880. }
  18881. CFFDict.call(this, tables, strings);
  18882. this.subrsIndex = null;
  18883. }
  18884. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  18885. return CFFPrivateDict;
  18886. })();
  18887. var CFFCharsetPredefinedTypes = {
  18888. ISO_ADOBE: 0,
  18889. EXPERT: 1,
  18890. EXPERT_SUBSET: 2
  18891. };
  18892. var CFFCharset = (function CFFCharsetClosure() {
  18893. function CFFCharset(predefined, format, charset, raw) {
  18894. this.predefined = predefined;
  18895. this.format = format;
  18896. this.charset = charset;
  18897. this.raw = raw;
  18898. }
  18899. return CFFCharset;
  18900. })();
  18901. var CFFEncoding = (function CFFEncodingClosure() {
  18902. function CFFEncoding(predefined, format, encoding, raw) {
  18903. this.predefined = predefined;
  18904. this.format = format;
  18905. this.encoding = encoding;
  18906. this.raw = raw;
  18907. }
  18908. return CFFEncoding;
  18909. })();
  18910. var CFFFDSelect = (function CFFFDSelectClosure() {
  18911. function CFFFDSelect(fdSelect, raw) {
  18912. this.fdSelect = fdSelect;
  18913. this.raw = raw;
  18914. }
  18915. return CFFFDSelect;
  18916. })();
  18917. // Helper class to keep track of where an offset is within the data and helps
  18918. // filling in that offset once it's known.
  18919. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  18920. function CFFOffsetTracker() {
  18921. this.offsets = {};
  18922. }
  18923. CFFOffsetTracker.prototype = {
  18924. isTracking: function CFFOffsetTracker_isTracking(key) {
  18925. return key in this.offsets;
  18926. },
  18927. track: function CFFOffsetTracker_track(key, location) {
  18928. if (key in this.offsets) {
  18929. error('Already tracking location of ' + key);
  18930. }
  18931. this.offsets[key] = location;
  18932. },
  18933. offset: function CFFOffsetTracker_offset(value) {
  18934. for (var key in this.offsets) {
  18935. this.offsets[key] += value;
  18936. }
  18937. },
  18938. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  18939. values,
  18940. output) {
  18941. if (!(key in this.offsets)) {
  18942. error('Not tracking location of ' + key);
  18943. }
  18944. var data = output.data;
  18945. var dataOffset = this.offsets[key];
  18946. var size = 5;
  18947. for (var i = 0, ii = values.length; i < ii; ++i) {
  18948. var offset0 = i * size + dataOffset;
  18949. var offset1 = offset0 + 1;
  18950. var offset2 = offset0 + 2;
  18951. var offset3 = offset0 + 3;
  18952. var offset4 = offset0 + 4;
  18953. // It's easy to screw up offsets so perform this sanity check.
  18954. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  18955. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  18956. error('writing to an offset that is not empty');
  18957. }
  18958. var value = values[i];
  18959. data[offset0] = 0x1d;
  18960. data[offset1] = (value >> 24) & 0xFF;
  18961. data[offset2] = (value >> 16) & 0xFF;
  18962. data[offset3] = (value >> 8) & 0xFF;
  18963. data[offset4] = value & 0xFF;
  18964. }
  18965. }
  18966. };
  18967. return CFFOffsetTracker;
  18968. })();
  18969. // Takes a CFF and converts it to the binary representation.
  18970. var CFFCompiler = (function CFFCompilerClosure() {
  18971. function CFFCompiler(cff) {
  18972. this.cff = cff;
  18973. }
  18974. CFFCompiler.prototype = {
  18975. compile: function CFFCompiler_compile() {
  18976. var cff = this.cff;
  18977. var output = {
  18978. data: [],
  18979. length: 0,
  18980. add: function CFFCompiler_add(data) {
  18981. this.data = this.data.concat(data);
  18982. this.length = this.data.length;
  18983. }
  18984. };
  18985. // Compile the five entries that must be in order.
  18986. var header = this.compileHeader(cff.header);
  18987. output.add(header);
  18988. var nameIndex = this.compileNameIndex(cff.names);
  18989. output.add(nameIndex);
  18990. if (cff.isCIDFont) {
  18991. // The spec is unclear on how font matrices should relate to each other
  18992. // when there is one in the main top dict and the sub top dicts.
  18993. // Windows handles this differently than linux and osx so we have to
  18994. // normalize to work on all.
  18995. // Rules based off of some mailing list discussions:
  18996. // - If main font has a matrix and subfont doesn't, use the main matrix.
  18997. // - If no main font matrix and there is a subfont matrix, use the
  18998. // subfont matrix.
  18999. // - If both have matrices, concat together.
  19000. // - If neither have matrices, use default.
  19001. // To make this work on all platforms we move the top matrix into each
  19002. // sub top dict and concat if necessary.
  19003. if (cff.topDict.hasName('FontMatrix')) {
  19004. var base = cff.topDict.getByName('FontMatrix');
  19005. cff.topDict.removeByName('FontMatrix');
  19006. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19007. var subDict = cff.fdArray[i];
  19008. var matrix = base.slice(0);
  19009. if (subDict.hasName('FontMatrix')) {
  19010. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19011. }
  19012. subDict.setByName('FontMatrix', matrix);
  19013. }
  19014. }
  19015. }
  19016. var compiled = this.compileTopDicts([cff.topDict],
  19017. output.length,
  19018. cff.isCIDFont);
  19019. output.add(compiled.output);
  19020. var topDictTracker = compiled.trackers[0];
  19021. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19022. output.add(stringIndex);
  19023. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19024. output.add(globalSubrIndex);
  19025. // Now start on the other entries that have no specfic order.
  19026. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19027. if (cff.encoding.predefined) {
  19028. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19029. output);
  19030. } else {
  19031. var encoding = this.compileEncoding(cff.encoding);
  19032. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19033. output.add(encoding);
  19034. }
  19035. }
  19036. if (cff.charset && cff.topDict.hasName('charset')) {
  19037. if (cff.charset.predefined) {
  19038. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19039. output);
  19040. } else {
  19041. var charset = this.compileCharset(cff.charset);
  19042. topDictTracker.setEntryLocation('charset', [output.length], output);
  19043. output.add(charset);
  19044. }
  19045. }
  19046. var charStrings = this.compileCharStrings(cff.charStrings);
  19047. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19048. output.add(charStrings);
  19049. if (cff.isCIDFont) {
  19050. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19051. // and linux don't seem to care.
  19052. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19053. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19054. output.add(fdSelect);
  19055. // It is unclear if the sub font dictionary can have CID related
  19056. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19057. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19058. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19059. output.add(compiled.output);
  19060. var fontDictTrackers = compiled.trackers;
  19061. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19062. }
  19063. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19064. // If the font data ends with INDEX whose object data is zero-length,
  19065. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19066. output.add([0]);
  19067. return output.data;
  19068. },
  19069. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19070. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19071. return this.encodeInteger(value);
  19072. } else {
  19073. return this.encodeFloat(value);
  19074. }
  19075. },
  19076. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19077. var value = num.toString();
  19078. // rounding inaccurate doubles
  19079. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19080. if (m) {
  19081. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19082. value = (Math.round(num * epsilon) / epsilon).toString();
  19083. }
  19084. var nibbles = '';
  19085. var i, ii;
  19086. for (i = 0, ii = value.length; i < ii; ++i) {
  19087. var a = value[i];
  19088. if (a === 'e') {
  19089. nibbles += value[++i] === '-' ? 'c' : 'b';
  19090. } else if (a === '.') {
  19091. nibbles += 'a';
  19092. } else if (a === '-') {
  19093. nibbles += 'e';
  19094. } else {
  19095. nibbles += a;
  19096. }
  19097. }
  19098. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19099. var out = [30];
  19100. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19101. out.push(parseInt(nibbles.substr(i, 2), 16));
  19102. }
  19103. return out;
  19104. },
  19105. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19106. var code;
  19107. if (value >= -107 && value <= 107) {
  19108. code = [value + 139];
  19109. } else if (value >= 108 && value <= 1131) {
  19110. value = [value - 108];
  19111. code = [(value >> 8) + 247, value & 0xFF];
  19112. } else if (value >= -1131 && value <= -108) {
  19113. value = -value - 108;
  19114. code = [(value >> 8) + 251, value & 0xFF];
  19115. } else if (value >= -32768 && value <= 32767) {
  19116. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19117. } else {
  19118. code = [0x1d,
  19119. (value >> 24) & 0xFF,
  19120. (value >> 16) & 0xFF,
  19121. (value >> 8) & 0xFF,
  19122. value & 0xFF];
  19123. }
  19124. return code;
  19125. },
  19126. compileHeader: function CFFCompiler_compileHeader(header) {
  19127. return [
  19128. header.major,
  19129. header.minor,
  19130. header.hdrSize,
  19131. header.offSize
  19132. ];
  19133. },
  19134. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19135. var nameIndex = new CFFIndex();
  19136. for (var i = 0, ii = names.length; i < ii; ++i) {
  19137. nameIndex.add(stringToBytes(names[i]));
  19138. }
  19139. return this.compileIndex(nameIndex);
  19140. },
  19141. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19142. length,
  19143. removeCidKeys) {
  19144. var fontDictTrackers = [];
  19145. var fdArrayIndex = new CFFIndex();
  19146. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19147. var fontDict = dicts[i];
  19148. if (removeCidKeys) {
  19149. fontDict.removeByName('CIDFontVersion');
  19150. fontDict.removeByName('CIDFontRevision');
  19151. fontDict.removeByName('CIDFontType');
  19152. fontDict.removeByName('CIDCount');
  19153. fontDict.removeByName('UIDBase');
  19154. }
  19155. var fontDictTracker = new CFFOffsetTracker();
  19156. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19157. fontDictTrackers.push(fontDictTracker);
  19158. fdArrayIndex.add(fontDictData);
  19159. fontDictTracker.offset(length);
  19160. }
  19161. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19162. return {
  19163. trackers: fontDictTrackers,
  19164. output: fdArrayIndex
  19165. };
  19166. },
  19167. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19168. trackers,
  19169. output) {
  19170. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19171. var fontDict = dicts[i];
  19172. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19173. 'There must be an private dictionary.');
  19174. var privateDict = fontDict.privateDict;
  19175. var privateDictTracker = new CFFOffsetTracker();
  19176. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19177. var outputLength = output.length;
  19178. privateDictTracker.offset(outputLength);
  19179. if (!privateDictData.length) {
  19180. // The private dictionary was empty, set the output length to zero to
  19181. // ensure the offset length isn't out of bounds in the eyes of the
  19182. // sanitizer.
  19183. outputLength = 0;
  19184. }
  19185. trackers[i].setEntryLocation('Private',
  19186. [privateDictData.length, outputLength],
  19187. output);
  19188. output.add(privateDictData);
  19189. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19190. var subrs = this.compileIndex(privateDict.subrsIndex);
  19191. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19192. output);
  19193. output.add(subrs);
  19194. }
  19195. }
  19196. },
  19197. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19198. var out = [];
  19199. // The dictionary keys must be in a certain order.
  19200. var order = dict.order;
  19201. for (var i = 0; i < order.length; ++i) {
  19202. var key = order[i];
  19203. if (!(key in dict.values)) {
  19204. continue;
  19205. }
  19206. var values = dict.values[key];
  19207. var types = dict.types[key];
  19208. if (!isArray(types)) {
  19209. types = [types];
  19210. }
  19211. if (!isArray(values)) {
  19212. values = [values];
  19213. }
  19214. // Remove any empty dict values.
  19215. if (values.length === 0) {
  19216. continue;
  19217. }
  19218. for (var j = 0, jj = types.length; j < jj; ++j) {
  19219. var type = types[j];
  19220. var value = values[j];
  19221. switch (type) {
  19222. case 'num':
  19223. case 'sid':
  19224. out = out.concat(this.encodeNumber(value));
  19225. break;
  19226. case 'offset':
  19227. // For offsets we just insert a 32bit integer so we don't have to
  19228. // deal with figuring out the length of the offset when it gets
  19229. // replaced later on by the compiler.
  19230. var name = dict.keyToNameMap[key];
  19231. // Some offsets have the offset and the length, so just record the
  19232. // position of the first one.
  19233. if (!offsetTracker.isTracking(name)) {
  19234. offsetTracker.track(name, out.length);
  19235. }
  19236. out = out.concat([0x1d, 0, 0, 0, 0]);
  19237. break;
  19238. case 'array':
  19239. case 'delta':
  19240. out = out.concat(this.encodeNumber(value));
  19241. for (var k = 1, kk = values.length; k < kk; ++k) {
  19242. out = out.concat(this.encodeNumber(values[k]));
  19243. }
  19244. break;
  19245. default:
  19246. error('Unknown data type of ' + type);
  19247. break;
  19248. }
  19249. }
  19250. out = out.concat(dict.opcodes[key]);
  19251. }
  19252. return out;
  19253. },
  19254. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19255. var stringIndex = new CFFIndex();
  19256. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19257. stringIndex.add(stringToBytes(strings[i]));
  19258. }
  19259. return this.compileIndex(stringIndex);
  19260. },
  19261. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19262. var globalSubrIndex = this.cff.globalSubrIndex;
  19263. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19264. },
  19265. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19266. return this.compileIndex(charStrings);
  19267. },
  19268. compileCharset: function CFFCompiler_compileCharset(charset) {
  19269. return this.compileTypedArray(charset.raw);
  19270. },
  19271. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19272. return this.compileTypedArray(encoding.raw);
  19273. },
  19274. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19275. return this.compileTypedArray(fdSelect);
  19276. },
  19277. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19278. var out = [];
  19279. for (var i = 0, ii = data.length; i < ii; ++i) {
  19280. out[i] = data[i];
  19281. }
  19282. return out;
  19283. },
  19284. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19285. trackers = trackers || [];
  19286. var objects = index.objects;
  19287. // First 2 bytes contains the number of objects contained into this index
  19288. var count = objects.length;
  19289. // If there is no object, just create an index. This technically
  19290. // should just be [0, 0] but OTS has an issue with that.
  19291. if (count === 0) {
  19292. return [0, 0, 0];
  19293. }
  19294. var data = [(count >> 8) & 0xFF, count & 0xff];
  19295. var lastOffset = 1, i;
  19296. for (i = 0; i < count; ++i) {
  19297. lastOffset += objects[i].length;
  19298. }
  19299. var offsetSize;
  19300. if (lastOffset < 0x100) {
  19301. offsetSize = 1;
  19302. } else if (lastOffset < 0x10000) {
  19303. offsetSize = 2;
  19304. } else if (lastOffset < 0x1000000) {
  19305. offsetSize = 3;
  19306. } else {
  19307. offsetSize = 4;
  19308. }
  19309. // Next byte contains the offset size use to reference object in the file
  19310. data.push(offsetSize);
  19311. // Add another offset after this one because we need a new offset
  19312. var relativeOffset = 1;
  19313. for (i = 0; i < count + 1; i++) {
  19314. if (offsetSize === 1) {
  19315. data.push(relativeOffset & 0xFF);
  19316. } else if (offsetSize === 2) {
  19317. data.push((relativeOffset >> 8) & 0xFF,
  19318. relativeOffset & 0xFF);
  19319. } else if (offsetSize === 3) {
  19320. data.push((relativeOffset >> 16) & 0xFF,
  19321. (relativeOffset >> 8) & 0xFF,
  19322. relativeOffset & 0xFF);
  19323. } else {
  19324. data.push((relativeOffset >>> 24) & 0xFF,
  19325. (relativeOffset >> 16) & 0xFF,
  19326. (relativeOffset >> 8) & 0xFF,
  19327. relativeOffset & 0xFF);
  19328. }
  19329. if (objects[i]) {
  19330. relativeOffset += objects[i].length;
  19331. }
  19332. }
  19333. for (i = 0; i < count; i++) {
  19334. // Notify the tracker where the object will be offset in the data.
  19335. if (trackers[i]) {
  19336. trackers[i].offset(data.length);
  19337. }
  19338. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19339. data.push(objects[i][j]);
  19340. }
  19341. }
  19342. return data;
  19343. }
  19344. };
  19345. return CFFCompiler;
  19346. })();
  19347. // Workaround for seac on Windows.
  19348. (function checkSeacSupport() {
  19349. if (/Windows/.test(navigator.userAgent)) {
  19350. SEAC_ANALYSIS_ENABLED = true;
  19351. }
  19352. })();
  19353. // Workaround for Private Use Area characters in Chrome on Windows
  19354. // http://code.google.com/p/chromium/issues/detail?id=122465
  19355. // https://github.com/mozilla/pdf.js/issues/1689
  19356. (function checkChromeWindows() {
  19357. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19358. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19359. }
  19360. })();
  19361. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19362. function getLong(data, offset) {
  19363. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19364. (data[offset + 2] << 8) | data[offset + 3];
  19365. }
  19366. function getUshort(data, offset) {
  19367. return (data[offset] << 8) | data[offset + 1];
  19368. }
  19369. function parseCmap(data, start, end) {
  19370. var offset = (getUshort(data, start + 2) === 1 ?
  19371. getLong(data, start + 8) : getLong(data, start + 16));
  19372. var format = getUshort(data, start + offset);
  19373. var length, ranges, p, i;
  19374. if (format === 4) {
  19375. length = getUshort(data, start + offset + 2);
  19376. var segCount = getUshort(data, start + offset + 6) >> 1;
  19377. p = start + offset + 14;
  19378. ranges = [];
  19379. for (i = 0; i < segCount; i++, p += 2) {
  19380. ranges[i] = {end: getUshort(data, p)};
  19381. }
  19382. p += 2;
  19383. for (i = 0; i < segCount; i++, p += 2) {
  19384. ranges[i].start = getUshort(data, p);
  19385. }
  19386. for (i = 0; i < segCount; i++, p += 2) {
  19387. ranges[i].idDelta = getUshort(data, p);
  19388. }
  19389. for (i = 0; i < segCount; i++, p += 2) {
  19390. var idOffset = getUshort(data, p);
  19391. if (idOffset === 0) {
  19392. continue;
  19393. }
  19394. ranges[i].ids = [];
  19395. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19396. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19397. idOffset += 2;
  19398. }
  19399. }
  19400. return ranges;
  19401. } else if (format === 12) {
  19402. length = getLong(data, start + offset + 4);
  19403. var groups = getLong(data, start + offset + 12);
  19404. p = start + offset + 16;
  19405. ranges = [];
  19406. for (i = 0; i < groups; i++) {
  19407. ranges.push({
  19408. start: getLong(data, p),
  19409. end: getLong(data, p + 4),
  19410. idDelta: getLong(data, p + 8) - getLong(data, p)
  19411. });
  19412. p += 12;
  19413. }
  19414. return ranges;
  19415. }
  19416. error('not supported cmap: ' + format);
  19417. }
  19418. function parseCff(data, start, end) {
  19419. var properties = {};
  19420. var parser = new CFFParser(new Stream(data, start, end - start),
  19421. properties);
  19422. var cff = parser.parse();
  19423. return {
  19424. glyphs: cff.charStrings.objects,
  19425. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19426. cff.topDict.privateDict.subrsIndex.objects),
  19427. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19428. };
  19429. }
  19430. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19431. var itemSize, itemDecode;
  19432. if (isGlyphLocationsLong) {
  19433. itemSize = 4;
  19434. itemDecode = function fontItemDecodeLong(data, offset) {
  19435. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19436. (data[offset + 2] << 8) | data[offset + 3];
  19437. };
  19438. } else {
  19439. itemSize = 2;
  19440. itemDecode = function fontItemDecode(data, offset) {
  19441. return (data[offset] << 9) | (data[offset + 1] << 1);
  19442. };
  19443. }
  19444. var glyphs = [];
  19445. var startOffset = itemDecode(loca, 0);
  19446. for (var j = itemSize; j < loca.length; j += itemSize) {
  19447. var endOffset = itemDecode(loca, j);
  19448. glyphs.push(glyf.subarray(startOffset, endOffset));
  19449. startOffset = endOffset;
  19450. }
  19451. return glyphs;
  19452. }
  19453. function lookupCmap(ranges, unicode) {
  19454. var code = unicode.charCodeAt(0);
  19455. var l = 0, r = ranges.length - 1;
  19456. while (l < r) {
  19457. var c = (l + r + 1) >> 1;
  19458. if (code < ranges[c].start) {
  19459. r = c - 1;
  19460. } else {
  19461. l = c;
  19462. }
  19463. }
  19464. if (ranges[l].start <= code && code <= ranges[l].end) {
  19465. return (ranges[l].idDelta + (ranges[l].ids ?
  19466. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19467. }
  19468. return 0;
  19469. }
  19470. function compileGlyf(code, js, font) {
  19471. function moveTo(x, y) {
  19472. js.push('c.moveTo(' + x + ',' + y + ');');
  19473. }
  19474. function lineTo(x, y) {
  19475. js.push('c.lineTo(' + x + ',' + y + ');');
  19476. }
  19477. function quadraticCurveTo(xa, ya, x, y) {
  19478. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19479. x + ',' + y + ');');
  19480. }
  19481. var i = 0;
  19482. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19483. var flags;
  19484. var x = 0, y = 0;
  19485. i += 10;
  19486. if (numberOfContours < 0) {
  19487. // composite glyph
  19488. do {
  19489. flags = (code[i] << 8) | code[i + 1];
  19490. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19491. i += 4;
  19492. var arg1, arg2;
  19493. if ((flags & 0x01)) {
  19494. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19495. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19496. i += 4;
  19497. } else {
  19498. arg1 = code[i++]; arg2 = code[i++];
  19499. }
  19500. if ((flags & 0x02)) {
  19501. x = arg1;
  19502. y = arg2;
  19503. } else {
  19504. x = 0; y = 0; // TODO "they are points" ?
  19505. }
  19506. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19507. if ((flags & 0x08)) {
  19508. scaleX =
  19509. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19510. i += 2;
  19511. } else if ((flags & 0x40)) {
  19512. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19513. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19514. i += 4;
  19515. } else if ((flags & 0x80)) {
  19516. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19517. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19518. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19519. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19520. i += 8;
  19521. }
  19522. var subglyph = font.glyphs[glyphIndex];
  19523. if (subglyph) {
  19524. js.push('c.save();');
  19525. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19526. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19527. compileGlyf(subglyph, js, font);
  19528. js.push('c.restore();');
  19529. }
  19530. } while ((flags & 0x20));
  19531. } else {
  19532. // simple glyph
  19533. var endPtsOfContours = [];
  19534. var j, jj;
  19535. for (j = 0; j < numberOfContours; j++) {
  19536. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19537. i += 2;
  19538. }
  19539. var instructionLength = (code[i] << 8) | code[i + 1];
  19540. i += 2 + instructionLength; // skipping the instructions
  19541. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19542. var points = [];
  19543. while (points.length < numberOfPoints) {
  19544. flags = code[i++];
  19545. var repeat = 1;
  19546. if ((flags & 0x08)) {
  19547. repeat += code[i++];
  19548. }
  19549. while (repeat-- > 0) {
  19550. points.push({flags: flags});
  19551. }
  19552. }
  19553. for (j = 0; j < numberOfPoints; j++) {
  19554. switch (points[j].flags & 0x12) {
  19555. case 0x00:
  19556. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19557. i += 2;
  19558. break;
  19559. case 0x02:
  19560. x -= code[i++];
  19561. break;
  19562. case 0x12:
  19563. x += code[i++];
  19564. break;
  19565. }
  19566. points[j].x = x;
  19567. }
  19568. for (j = 0; j < numberOfPoints; j++) {
  19569. switch (points[j].flags & 0x24) {
  19570. case 0x00:
  19571. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19572. i += 2;
  19573. break;
  19574. case 0x04:
  19575. y -= code[i++];
  19576. break;
  19577. case 0x24:
  19578. y += code[i++];
  19579. break;
  19580. }
  19581. points[j].y = y;
  19582. }
  19583. var startPoint = 0;
  19584. for (i = 0; i < numberOfContours; i++) {
  19585. var endPoint = endPtsOfContours[i];
  19586. // contours might have implicit points, which is located in the middle
  19587. // between two neighboring off-curve points
  19588. var contour = points.slice(startPoint, endPoint + 1);
  19589. if ((contour[0].flags & 1)) {
  19590. contour.push(contour[0]); // using start point at the contour end
  19591. } else if ((contour[contour.length - 1].flags & 1)) {
  19592. // first is off-curve point, trying to use one from the end
  19593. contour.unshift(contour[contour.length - 1]);
  19594. } else {
  19595. // start and end are off-curve points, creating implicit one
  19596. var p = {
  19597. flags: 1,
  19598. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19599. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19600. };
  19601. contour.unshift(p);
  19602. contour.push(p);
  19603. }
  19604. moveTo(contour[0].x, contour[0].y);
  19605. for (j = 1, jj = contour.length; j < jj; j++) {
  19606. if ((contour[j].flags & 1)) {
  19607. lineTo(contour[j].x, contour[j].y);
  19608. } else if ((contour[j + 1].flags & 1)){
  19609. quadraticCurveTo(contour[j].x, contour[j].y,
  19610. contour[j + 1].x, contour[j + 1].y);
  19611. j++;
  19612. } else {
  19613. quadraticCurveTo(contour[j].x, contour[j].y,
  19614. (contour[j].x + contour[j + 1].x) / 2,
  19615. (contour[j].y + contour[j + 1].y) / 2);
  19616. }
  19617. }
  19618. startPoint = endPoint + 1;
  19619. }
  19620. }
  19621. }
  19622. function compileCharString(code, js, font) {
  19623. var stack = [];
  19624. var x = 0, y = 0;
  19625. var stems = 0;
  19626. function moveTo(x, y) {
  19627. js.push('c.moveTo(' + x + ',' + y + ');');
  19628. }
  19629. function lineTo(x, y) {
  19630. js.push('c.lineTo(' + x + ',' + y + ');');
  19631. }
  19632. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19633. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19634. x + ',' + y + ');');
  19635. }
  19636. function parse(code) {
  19637. var i = 0;
  19638. while (i < code.length) {
  19639. var stackClean = false;
  19640. var v = code[i++];
  19641. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19642. switch (v) {
  19643. case 1: // hstem
  19644. stems += stack.length >> 1;
  19645. stackClean = true;
  19646. break;
  19647. case 3: // vstem
  19648. stems += stack.length >> 1;
  19649. stackClean = true;
  19650. break;
  19651. case 4: // vmoveto
  19652. y += stack.pop();
  19653. moveTo(x, y);
  19654. stackClean = true;
  19655. break;
  19656. case 5: // rlineto
  19657. while (stack.length > 0) {
  19658. x += stack.shift();
  19659. y += stack.shift();
  19660. lineTo(x, y);
  19661. }
  19662. break;
  19663. case 6: // hlineto
  19664. while (stack.length > 0) {
  19665. x += stack.shift();
  19666. lineTo(x, y);
  19667. if (stack.length === 0) {
  19668. break;
  19669. }
  19670. y += stack.shift();
  19671. lineTo(x, y);
  19672. }
  19673. break;
  19674. case 7: // vlineto
  19675. while (stack.length > 0) {
  19676. y += stack.shift();
  19677. lineTo(x, y);
  19678. if (stack.length === 0) {
  19679. break;
  19680. }
  19681. x += stack.shift();
  19682. lineTo(x, y);
  19683. }
  19684. break;
  19685. case 8: // rrcurveto
  19686. while (stack.length > 0) {
  19687. xa = x + stack.shift(); ya = y + stack.shift();
  19688. xb = xa + stack.shift(); yb = ya + stack.shift();
  19689. x = xb + stack.shift(); y = yb + stack.shift();
  19690. bezierCurveTo(xa, ya, xb, yb, x, y);
  19691. }
  19692. break;
  19693. case 10: // callsubr
  19694. n = stack.pop() + font.subrsBias;
  19695. subrCode = font.subrs[n];
  19696. if (subrCode) {
  19697. parse(subrCode);
  19698. }
  19699. break;
  19700. case 11: // return
  19701. return;
  19702. case 12:
  19703. v = code[i++];
  19704. switch (v) {
  19705. case 34: // flex
  19706. xa = x + stack.shift();
  19707. xb = xa + stack.shift(); y1 = y + stack.shift();
  19708. x = xb + stack.shift();
  19709. bezierCurveTo(xa, y, xb, y1, x, y1);
  19710. xa = x + stack.shift();
  19711. xb = xa + stack.shift();
  19712. x = xb + stack.shift();
  19713. bezierCurveTo(xa, y1, xb, y, x, y);
  19714. break;
  19715. case 35: // flex
  19716. xa = x + stack.shift(); ya = y + stack.shift();
  19717. xb = xa + stack.shift(); yb = ya + stack.shift();
  19718. x = xb + stack.shift(); y = yb + stack.shift();
  19719. bezierCurveTo(xa, ya, xb, yb, x, y);
  19720. xa = x + stack.shift(); ya = y + stack.shift();
  19721. xb = xa + stack.shift(); yb = ya + stack.shift();
  19722. x = xb + stack.shift(); y = yb + stack.shift();
  19723. bezierCurveTo(xa, ya, xb, yb, x, y);
  19724. stack.pop(); // fd
  19725. break;
  19726. case 36: // hflex1
  19727. xa = x + stack.shift(); y1 = y + stack.shift();
  19728. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19729. x = xb + stack.shift();
  19730. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19731. xa = x + stack.shift();
  19732. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19733. x = xb + stack.shift();
  19734. bezierCurveTo(xa, y2, xb, y3, x, y);
  19735. break;
  19736. case 37: // flex1
  19737. var x0 = x, y0 = y;
  19738. xa = x + stack.shift(); ya = y + stack.shift();
  19739. xb = xa + stack.shift(); yb = ya + stack.shift();
  19740. x = xb + stack.shift(); y = yb + stack.shift();
  19741. bezierCurveTo(xa, ya, xb, yb, x, y);
  19742. xa = x + stack.shift(); ya = y + stack.shift();
  19743. xb = xa + stack.shift(); yb = ya + stack.shift();
  19744. x = xb; y = yb;
  19745. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19746. x += stack.shift();
  19747. } else {
  19748. y += stack.shift();
  19749. }
  19750. bezierCurveTo(xa, ya, xb, yb, x, y);
  19751. break;
  19752. default:
  19753. error('unknown operator: 12 ' + v);
  19754. }
  19755. break;
  19756. case 14: // endchar
  19757. if (stack.length >= 4) {
  19758. var achar = stack.pop();
  19759. var bchar = stack.pop();
  19760. y = stack.pop();
  19761. x = stack.pop();
  19762. js.push('c.save();');
  19763. js.push('c.translate('+ x + ',' + y + ');');
  19764. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19765. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19766. compileCharString(font.glyphs[gid], js, font);
  19767. js.push('c.restore();');
  19768. gid = lookupCmap(font.cmap, String.fromCharCode(
  19769. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19770. compileCharString(font.glyphs[gid], js, font);
  19771. }
  19772. return;
  19773. case 18: // hstemhm
  19774. stems += stack.length >> 1;
  19775. stackClean = true;
  19776. break;
  19777. case 19: // hintmask
  19778. stems += stack.length >> 1;
  19779. i += (stems + 7) >> 3;
  19780. stackClean = true;
  19781. break;
  19782. case 20: // cntrmask
  19783. stems += stack.length >> 1;
  19784. i += (stems + 7) >> 3;
  19785. stackClean = true;
  19786. break;
  19787. case 21: // rmoveto
  19788. y += stack.pop();
  19789. x += stack.pop();
  19790. moveTo(x, y);
  19791. stackClean = true;
  19792. break;
  19793. case 22: // hmoveto
  19794. x += stack.pop();
  19795. moveTo(x, y);
  19796. stackClean = true;
  19797. break;
  19798. case 23: // vstemhm
  19799. stems += stack.length >> 1;
  19800. stackClean = true;
  19801. break;
  19802. case 24: // rcurveline
  19803. while (stack.length > 2) {
  19804. xa = x + stack.shift(); ya = y + stack.shift();
  19805. xb = xa + stack.shift(); yb = ya + stack.shift();
  19806. x = xb + stack.shift(); y = yb + stack.shift();
  19807. bezierCurveTo(xa, ya, xb, yb, x, y);
  19808. }
  19809. x += stack.shift();
  19810. y += stack.shift();
  19811. lineTo(x, y);
  19812. break;
  19813. case 25: // rlinecurve
  19814. while (stack.length > 6) {
  19815. x += stack.shift();
  19816. y += stack.shift();
  19817. lineTo(x, y);
  19818. }
  19819. xa = x + stack.shift(); ya = y + stack.shift();
  19820. xb = xa + stack.shift(); yb = ya + stack.shift();
  19821. x = xb + stack.shift(); y = yb + stack.shift();
  19822. bezierCurveTo(xa, ya, xb, yb, x, y);
  19823. break;
  19824. case 26: // vvcurveto
  19825. if (stack.length % 2) {
  19826. x += stack.shift();
  19827. }
  19828. while (stack.length > 0) {
  19829. xa = x; ya = y + stack.shift();
  19830. xb = xa + stack.shift(); yb = ya + stack.shift();
  19831. x = xb; y = yb + stack.shift();
  19832. bezierCurveTo(xa, ya, xb, yb, x, y);
  19833. }
  19834. break;
  19835. case 27: // hhcurveto
  19836. if (stack.length % 2) {
  19837. y += stack.shift();
  19838. }
  19839. while (stack.length > 0) {
  19840. xa = x + stack.shift(); ya = y;
  19841. xb = xa + stack.shift(); yb = ya + stack.shift();
  19842. x = xb + stack.shift(); y = yb;
  19843. bezierCurveTo(xa, ya, xb, yb, x, y);
  19844. }
  19845. break;
  19846. case 28:
  19847. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19848. i += 2;
  19849. break;
  19850. case 29: // callgsubr
  19851. n = stack.pop() + font.gsubrsBias;
  19852. subrCode = font.gsubrs[n];
  19853. if (subrCode) {
  19854. parse(subrCode);
  19855. }
  19856. break;
  19857. case 30: // vhcurveto
  19858. while (stack.length > 0) {
  19859. xa = x; ya = y + stack.shift();
  19860. xb = xa + stack.shift(); yb = ya + stack.shift();
  19861. x = xb + stack.shift();
  19862. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19863. bezierCurveTo(xa, ya, xb, yb, x, y);
  19864. if (stack.length === 0) {
  19865. break;
  19866. }
  19867. xa = x + stack.shift(); ya = y;
  19868. xb = xa + stack.shift(); yb = ya + stack.shift();
  19869. y = yb + stack.shift();
  19870. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19871. bezierCurveTo(xa, ya, xb, yb, x, y);
  19872. }
  19873. break;
  19874. case 31: // hvcurveto
  19875. while (stack.length > 0) {
  19876. xa = x + stack.shift(); ya = y;
  19877. xb = xa + stack.shift(); yb = ya + stack.shift();
  19878. y = yb + stack.shift();
  19879. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19880. bezierCurveTo(xa, ya, xb, yb, x, y);
  19881. if (stack.length === 0) {
  19882. break;
  19883. }
  19884. xa = x; ya = y + stack.shift();
  19885. xb = xa + stack.shift(); yb = ya + stack.shift();
  19886. x = xb + stack.shift();
  19887. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19888. bezierCurveTo(xa, ya, xb, yb, x, y);
  19889. }
  19890. break;
  19891. default:
  19892. if (v < 32) {
  19893. error('unknown operator: ' + v);
  19894. }
  19895. if (v < 247) {
  19896. stack.push(v - 139);
  19897. } else if (v < 251) {
  19898. stack.push((v - 247) * 256 + code[i++] + 108);
  19899. } else if (v < 255) {
  19900. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19901. } else {
  19902. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19903. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19904. i += 4;
  19905. }
  19906. break;
  19907. }
  19908. if (stackClean) {
  19909. stack.length = 0;
  19910. }
  19911. }
  19912. }
  19913. parse(code);
  19914. }
  19915. var noop = '';
  19916. function CompiledFont(fontMatrix) {
  19917. this.compiledGlyphs = {};
  19918. this.fontMatrix = fontMatrix;
  19919. }
  19920. CompiledFont.prototype = {
  19921. getPathJs: function (unicode) {
  19922. var gid = lookupCmap(this.cmap, unicode);
  19923. var fn = this.compiledGlyphs[gid];
  19924. if (!fn) {
  19925. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19926. }
  19927. return fn;
  19928. },
  19929. compileGlyph: function (code) {
  19930. if (!code || code.length === 0 || code[0] === 14) {
  19931. return noop;
  19932. }
  19933. var js = [];
  19934. js.push('c.save();');
  19935. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  19936. js.push('c.scale(size, -size);');
  19937. this.compileGlyphImpl(code, js);
  19938. js.push('c.restore();');
  19939. return js.join('\n');
  19940. },
  19941. compileGlyphImpl: function () {
  19942. error('Children classes should implement this.');
  19943. },
  19944. hasBuiltPath: function (unicode) {
  19945. var gid = lookupCmap(this.cmap, unicode);
  19946. return gid in this.compiledGlyphs;
  19947. }
  19948. };
  19949. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19950. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19951. CompiledFont.call(this, fontMatrix);
  19952. this.glyphs = glyphs;
  19953. this.cmap = cmap;
  19954. this.compiledGlyphs = [];
  19955. }
  19956. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19957. compileGlyphImpl: function (code, js) {
  19958. compileGlyf(code, js, this);
  19959. }
  19960. });
  19961. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19962. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19963. CompiledFont.call(this, fontMatrix);
  19964. this.glyphs = cffInfo.glyphs;
  19965. this.gsubrs = cffInfo.gsubrs || [];
  19966. this.subrs = cffInfo.subrs || [];
  19967. this.cmap = cmap;
  19968. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19969. this.compiledGlyphs = [];
  19970. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19971. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19972. this.subrsBias = (this.subrs.length < 1240 ?
  19973. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19974. }
  19975. Util.inherit(Type2Compiled, CompiledFont, {
  19976. compileGlyphImpl: function (code, js) {
  19977. compileCharString(code, js, this);
  19978. }
  19979. });
  19980. return {
  19981. create: function FontRendererFactory_create(font) {
  19982. var data = new Uint8Array(font.data);
  19983. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19984. var numTables = getUshort(data, 4);
  19985. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19986. var tag = bytesToString(data.subarray(p, p + 4));
  19987. var offset = getLong(data, p + 8);
  19988. var length = getLong(data, p + 12);
  19989. switch (tag) {
  19990. case 'cmap':
  19991. cmap = parseCmap(data, offset, offset + length);
  19992. break;
  19993. case 'glyf':
  19994. glyf = data.subarray(offset, offset + length);
  19995. break;
  19996. case 'loca':
  19997. loca = data.subarray(offset, offset + length);
  19998. break;
  19999. case 'head':
  20000. unitsPerEm = getUshort(data, offset + 18);
  20001. indexToLocFormat = getUshort(data, offset + 50);
  20002. break;
  20003. case 'CFF ':
  20004. cff = parseCff(data, offset, offset + length);
  20005. break;
  20006. }
  20007. }
  20008. if (glyf) {
  20009. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20010. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20011. return new TrueTypeCompiled(
  20012. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20013. } else {
  20014. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20015. }
  20016. }
  20017. };
  20018. })();
  20019. var GlyphsUnicode = {
  20020. A: 0x0041,
  20021. AE: 0x00C6,
  20022. AEacute: 0x01FC,
  20023. AEmacron: 0x01E2,
  20024. AEsmall: 0xF7E6,
  20025. Aacute: 0x00C1,
  20026. Aacutesmall: 0xF7E1,
  20027. Abreve: 0x0102,
  20028. Abreveacute: 0x1EAE,
  20029. Abrevecyrillic: 0x04D0,
  20030. Abrevedotbelow: 0x1EB6,
  20031. Abrevegrave: 0x1EB0,
  20032. Abrevehookabove: 0x1EB2,
  20033. Abrevetilde: 0x1EB4,
  20034. Acaron: 0x01CD,
  20035. Acircle: 0x24B6,
  20036. Acircumflex: 0x00C2,
  20037. Acircumflexacute: 0x1EA4,
  20038. Acircumflexdotbelow: 0x1EAC,
  20039. Acircumflexgrave: 0x1EA6,
  20040. Acircumflexhookabove: 0x1EA8,
  20041. Acircumflexsmall: 0xF7E2,
  20042. Acircumflextilde: 0x1EAA,
  20043. Acute: 0xF6C9,
  20044. Acutesmall: 0xF7B4,
  20045. Acyrillic: 0x0410,
  20046. Adblgrave: 0x0200,
  20047. Adieresis: 0x00C4,
  20048. Adieresiscyrillic: 0x04D2,
  20049. Adieresismacron: 0x01DE,
  20050. Adieresissmall: 0xF7E4,
  20051. Adotbelow: 0x1EA0,
  20052. Adotmacron: 0x01E0,
  20053. Agrave: 0x00C0,
  20054. Agravesmall: 0xF7E0,
  20055. Ahookabove: 0x1EA2,
  20056. Aiecyrillic: 0x04D4,
  20057. Ainvertedbreve: 0x0202,
  20058. Alpha: 0x0391,
  20059. Alphatonos: 0x0386,
  20060. Amacron: 0x0100,
  20061. Amonospace: 0xFF21,
  20062. Aogonek: 0x0104,
  20063. Aring: 0x00C5,
  20064. Aringacute: 0x01FA,
  20065. Aringbelow: 0x1E00,
  20066. Aringsmall: 0xF7E5,
  20067. Asmall: 0xF761,
  20068. Atilde: 0x00C3,
  20069. Atildesmall: 0xF7E3,
  20070. Aybarmenian: 0x0531,
  20071. B: 0x0042,
  20072. Bcircle: 0x24B7,
  20073. Bdotaccent: 0x1E02,
  20074. Bdotbelow: 0x1E04,
  20075. Becyrillic: 0x0411,
  20076. Benarmenian: 0x0532,
  20077. Beta: 0x0392,
  20078. Bhook: 0x0181,
  20079. Blinebelow: 0x1E06,
  20080. Bmonospace: 0xFF22,
  20081. Brevesmall: 0xF6F4,
  20082. Bsmall: 0xF762,
  20083. Btopbar: 0x0182,
  20084. C: 0x0043,
  20085. Caarmenian: 0x053E,
  20086. Cacute: 0x0106,
  20087. Caron: 0xF6CA,
  20088. Caronsmall: 0xF6F5,
  20089. Ccaron: 0x010C,
  20090. Ccedilla: 0x00C7,
  20091. Ccedillaacute: 0x1E08,
  20092. Ccedillasmall: 0xF7E7,
  20093. Ccircle: 0x24B8,
  20094. Ccircumflex: 0x0108,
  20095. Cdot: 0x010A,
  20096. Cdotaccent: 0x010A,
  20097. Cedillasmall: 0xF7B8,
  20098. Chaarmenian: 0x0549,
  20099. Cheabkhasiancyrillic: 0x04BC,
  20100. Checyrillic: 0x0427,
  20101. Chedescenderabkhasiancyrillic: 0x04BE,
  20102. Chedescendercyrillic: 0x04B6,
  20103. Chedieresiscyrillic: 0x04F4,
  20104. Cheharmenian: 0x0543,
  20105. Chekhakassiancyrillic: 0x04CB,
  20106. Cheverticalstrokecyrillic: 0x04B8,
  20107. Chi: 0x03A7,
  20108. Chook: 0x0187,
  20109. Circumflexsmall: 0xF6F6,
  20110. Cmonospace: 0xFF23,
  20111. Coarmenian: 0x0551,
  20112. Csmall: 0xF763,
  20113. D: 0x0044,
  20114. DZ: 0x01F1,
  20115. DZcaron: 0x01C4,
  20116. Daarmenian: 0x0534,
  20117. Dafrican: 0x0189,
  20118. Dcaron: 0x010E,
  20119. Dcedilla: 0x1E10,
  20120. Dcircle: 0x24B9,
  20121. Dcircumflexbelow: 0x1E12,
  20122. Dcroat: 0x0110,
  20123. Ddotaccent: 0x1E0A,
  20124. Ddotbelow: 0x1E0C,
  20125. Decyrillic: 0x0414,
  20126. Deicoptic: 0x03EE,
  20127. Delta: 0x2206,
  20128. Deltagreek: 0x0394,
  20129. Dhook: 0x018A,
  20130. Dieresis: 0xF6CB,
  20131. DieresisAcute: 0xF6CC,
  20132. DieresisGrave: 0xF6CD,
  20133. Dieresissmall: 0xF7A8,
  20134. Digammagreek: 0x03DC,
  20135. Djecyrillic: 0x0402,
  20136. Dlinebelow: 0x1E0E,
  20137. Dmonospace: 0xFF24,
  20138. Dotaccentsmall: 0xF6F7,
  20139. Dslash: 0x0110,
  20140. Dsmall: 0xF764,
  20141. Dtopbar: 0x018B,
  20142. Dz: 0x01F2,
  20143. Dzcaron: 0x01C5,
  20144. Dzeabkhasiancyrillic: 0x04E0,
  20145. Dzecyrillic: 0x0405,
  20146. Dzhecyrillic: 0x040F,
  20147. E: 0x0045,
  20148. Eacute: 0x00C9,
  20149. Eacutesmall: 0xF7E9,
  20150. Ebreve: 0x0114,
  20151. Ecaron: 0x011A,
  20152. Ecedillabreve: 0x1E1C,
  20153. Echarmenian: 0x0535,
  20154. Ecircle: 0x24BA,
  20155. Ecircumflex: 0x00CA,
  20156. Ecircumflexacute: 0x1EBE,
  20157. Ecircumflexbelow: 0x1E18,
  20158. Ecircumflexdotbelow: 0x1EC6,
  20159. Ecircumflexgrave: 0x1EC0,
  20160. Ecircumflexhookabove: 0x1EC2,
  20161. Ecircumflexsmall: 0xF7EA,
  20162. Ecircumflextilde: 0x1EC4,
  20163. Ecyrillic: 0x0404,
  20164. Edblgrave: 0x0204,
  20165. Edieresis: 0x00CB,
  20166. Edieresissmall: 0xF7EB,
  20167. Edot: 0x0116,
  20168. Edotaccent: 0x0116,
  20169. Edotbelow: 0x1EB8,
  20170. Efcyrillic: 0x0424,
  20171. Egrave: 0x00C8,
  20172. Egravesmall: 0xF7E8,
  20173. Eharmenian: 0x0537,
  20174. Ehookabove: 0x1EBA,
  20175. Eightroman: 0x2167,
  20176. Einvertedbreve: 0x0206,
  20177. Eiotifiedcyrillic: 0x0464,
  20178. Elcyrillic: 0x041B,
  20179. Elevenroman: 0x216A,
  20180. Emacron: 0x0112,
  20181. Emacronacute: 0x1E16,
  20182. Emacrongrave: 0x1E14,
  20183. Emcyrillic: 0x041C,
  20184. Emonospace: 0xFF25,
  20185. Encyrillic: 0x041D,
  20186. Endescendercyrillic: 0x04A2,
  20187. Eng: 0x014A,
  20188. Enghecyrillic: 0x04A4,
  20189. Enhookcyrillic: 0x04C7,
  20190. Eogonek: 0x0118,
  20191. Eopen: 0x0190,
  20192. Epsilon: 0x0395,
  20193. Epsilontonos: 0x0388,
  20194. Ercyrillic: 0x0420,
  20195. Ereversed: 0x018E,
  20196. Ereversedcyrillic: 0x042D,
  20197. Escyrillic: 0x0421,
  20198. Esdescendercyrillic: 0x04AA,
  20199. Esh: 0x01A9,
  20200. Esmall: 0xF765,
  20201. Eta: 0x0397,
  20202. Etarmenian: 0x0538,
  20203. Etatonos: 0x0389,
  20204. Eth: 0x00D0,
  20205. Ethsmall: 0xF7F0,
  20206. Etilde: 0x1EBC,
  20207. Etildebelow: 0x1E1A,
  20208. Euro: 0x20AC,
  20209. Ezh: 0x01B7,
  20210. Ezhcaron: 0x01EE,
  20211. Ezhreversed: 0x01B8,
  20212. F: 0x0046,
  20213. Fcircle: 0x24BB,
  20214. Fdotaccent: 0x1E1E,
  20215. Feharmenian: 0x0556,
  20216. Feicoptic: 0x03E4,
  20217. Fhook: 0x0191,
  20218. Fitacyrillic: 0x0472,
  20219. Fiveroman: 0x2164,
  20220. Fmonospace: 0xFF26,
  20221. Fourroman: 0x2163,
  20222. Fsmall: 0xF766,
  20223. G: 0x0047,
  20224. GBsquare: 0x3387,
  20225. Gacute: 0x01F4,
  20226. Gamma: 0x0393,
  20227. Gammaafrican: 0x0194,
  20228. Gangiacoptic: 0x03EA,
  20229. Gbreve: 0x011E,
  20230. Gcaron: 0x01E6,
  20231. Gcedilla: 0x0122,
  20232. Gcircle: 0x24BC,
  20233. Gcircumflex: 0x011C,
  20234. Gcommaaccent: 0x0122,
  20235. Gdot: 0x0120,
  20236. Gdotaccent: 0x0120,
  20237. Gecyrillic: 0x0413,
  20238. Ghadarmenian: 0x0542,
  20239. Ghemiddlehookcyrillic: 0x0494,
  20240. Ghestrokecyrillic: 0x0492,
  20241. Gheupturncyrillic: 0x0490,
  20242. Ghook: 0x0193,
  20243. Gimarmenian: 0x0533,
  20244. Gjecyrillic: 0x0403,
  20245. Gmacron: 0x1E20,
  20246. Gmonospace: 0xFF27,
  20247. Grave: 0xF6CE,
  20248. Gravesmall: 0xF760,
  20249. Gsmall: 0xF767,
  20250. Gsmallhook: 0x029B,
  20251. Gstroke: 0x01E4,
  20252. H: 0x0048,
  20253. H18533: 0x25CF,
  20254. H18543: 0x25AA,
  20255. H18551: 0x25AB,
  20256. H22073: 0x25A1,
  20257. HPsquare: 0x33CB,
  20258. Haabkhasiancyrillic: 0x04A8,
  20259. Hadescendercyrillic: 0x04B2,
  20260. Hardsigncyrillic: 0x042A,
  20261. Hbar: 0x0126,
  20262. Hbrevebelow: 0x1E2A,
  20263. Hcedilla: 0x1E28,
  20264. Hcircle: 0x24BD,
  20265. Hcircumflex: 0x0124,
  20266. Hdieresis: 0x1E26,
  20267. Hdotaccent: 0x1E22,
  20268. Hdotbelow: 0x1E24,
  20269. Hmonospace: 0xFF28,
  20270. Hoarmenian: 0x0540,
  20271. Horicoptic: 0x03E8,
  20272. Hsmall: 0xF768,
  20273. Hungarumlaut: 0xF6CF,
  20274. Hungarumlautsmall: 0xF6F8,
  20275. Hzsquare: 0x3390,
  20276. I: 0x0049,
  20277. IAcyrillic: 0x042F,
  20278. IJ: 0x0132,
  20279. IUcyrillic: 0x042E,
  20280. Iacute: 0x00CD,
  20281. Iacutesmall: 0xF7ED,
  20282. Ibreve: 0x012C,
  20283. Icaron: 0x01CF,
  20284. Icircle: 0x24BE,
  20285. Icircumflex: 0x00CE,
  20286. Icircumflexsmall: 0xF7EE,
  20287. Icyrillic: 0x0406,
  20288. Idblgrave: 0x0208,
  20289. Idieresis: 0x00CF,
  20290. Idieresisacute: 0x1E2E,
  20291. Idieresiscyrillic: 0x04E4,
  20292. Idieresissmall: 0xF7EF,
  20293. Idot: 0x0130,
  20294. Idotaccent: 0x0130,
  20295. Idotbelow: 0x1ECA,
  20296. Iebrevecyrillic: 0x04D6,
  20297. Iecyrillic: 0x0415,
  20298. Ifraktur: 0x2111,
  20299. Igrave: 0x00CC,
  20300. Igravesmall: 0xF7EC,
  20301. Ihookabove: 0x1EC8,
  20302. Iicyrillic: 0x0418,
  20303. Iinvertedbreve: 0x020A,
  20304. Iishortcyrillic: 0x0419,
  20305. Imacron: 0x012A,
  20306. Imacroncyrillic: 0x04E2,
  20307. Imonospace: 0xFF29,
  20308. Iniarmenian: 0x053B,
  20309. Iocyrillic: 0x0401,
  20310. Iogonek: 0x012E,
  20311. Iota: 0x0399,
  20312. Iotaafrican: 0x0196,
  20313. Iotadieresis: 0x03AA,
  20314. Iotatonos: 0x038A,
  20315. Ismall: 0xF769,
  20316. Istroke: 0x0197,
  20317. Itilde: 0x0128,
  20318. Itildebelow: 0x1E2C,
  20319. Izhitsacyrillic: 0x0474,
  20320. Izhitsadblgravecyrillic: 0x0476,
  20321. J: 0x004A,
  20322. Jaarmenian: 0x0541,
  20323. Jcircle: 0x24BF,
  20324. Jcircumflex: 0x0134,
  20325. Jecyrillic: 0x0408,
  20326. Jheharmenian: 0x054B,
  20327. Jmonospace: 0xFF2A,
  20328. Jsmall: 0xF76A,
  20329. K: 0x004B,
  20330. KBsquare: 0x3385,
  20331. KKsquare: 0x33CD,
  20332. Kabashkircyrillic: 0x04A0,
  20333. Kacute: 0x1E30,
  20334. Kacyrillic: 0x041A,
  20335. Kadescendercyrillic: 0x049A,
  20336. Kahookcyrillic: 0x04C3,
  20337. Kappa: 0x039A,
  20338. Kastrokecyrillic: 0x049E,
  20339. Kaverticalstrokecyrillic: 0x049C,
  20340. Kcaron: 0x01E8,
  20341. Kcedilla: 0x0136,
  20342. Kcircle: 0x24C0,
  20343. Kcommaaccent: 0x0136,
  20344. Kdotbelow: 0x1E32,
  20345. Keharmenian: 0x0554,
  20346. Kenarmenian: 0x053F,
  20347. Khacyrillic: 0x0425,
  20348. Kheicoptic: 0x03E6,
  20349. Khook: 0x0198,
  20350. Kjecyrillic: 0x040C,
  20351. Klinebelow: 0x1E34,
  20352. Kmonospace: 0xFF2B,
  20353. Koppacyrillic: 0x0480,
  20354. Koppagreek: 0x03DE,
  20355. Ksicyrillic: 0x046E,
  20356. Ksmall: 0xF76B,
  20357. L: 0x004C,
  20358. LJ: 0x01C7,
  20359. LL: 0xF6BF,
  20360. Lacute: 0x0139,
  20361. Lambda: 0x039B,
  20362. Lcaron: 0x013D,
  20363. Lcedilla: 0x013B,
  20364. Lcircle: 0x24C1,
  20365. Lcircumflexbelow: 0x1E3C,
  20366. Lcommaaccent: 0x013B,
  20367. Ldot: 0x013F,
  20368. Ldotaccent: 0x013F,
  20369. Ldotbelow: 0x1E36,
  20370. Ldotbelowmacron: 0x1E38,
  20371. Liwnarmenian: 0x053C,
  20372. Lj: 0x01C8,
  20373. Ljecyrillic: 0x0409,
  20374. Llinebelow: 0x1E3A,
  20375. Lmonospace: 0xFF2C,
  20376. Lslash: 0x0141,
  20377. Lslashsmall: 0xF6F9,
  20378. Lsmall: 0xF76C,
  20379. M: 0x004D,
  20380. MBsquare: 0x3386,
  20381. Macron: 0xF6D0,
  20382. Macronsmall: 0xF7AF,
  20383. Macute: 0x1E3E,
  20384. Mcircle: 0x24C2,
  20385. Mdotaccent: 0x1E40,
  20386. Mdotbelow: 0x1E42,
  20387. Menarmenian: 0x0544,
  20388. Mmonospace: 0xFF2D,
  20389. Msmall: 0xF76D,
  20390. Mturned: 0x019C,
  20391. Mu: 0x039C,
  20392. N: 0x004E,
  20393. NJ: 0x01CA,
  20394. Nacute: 0x0143,
  20395. Ncaron: 0x0147,
  20396. Ncedilla: 0x0145,
  20397. Ncircle: 0x24C3,
  20398. Ncircumflexbelow: 0x1E4A,
  20399. Ncommaaccent: 0x0145,
  20400. Ndotaccent: 0x1E44,
  20401. Ndotbelow: 0x1E46,
  20402. Nhookleft: 0x019D,
  20403. Nineroman: 0x2168,
  20404. Nj: 0x01CB,
  20405. Njecyrillic: 0x040A,
  20406. Nlinebelow: 0x1E48,
  20407. Nmonospace: 0xFF2E,
  20408. Nowarmenian: 0x0546,
  20409. Nsmall: 0xF76E,
  20410. Ntilde: 0x00D1,
  20411. Ntildesmall: 0xF7F1,
  20412. Nu: 0x039D,
  20413. O: 0x004F,
  20414. OE: 0x0152,
  20415. OEsmall: 0xF6FA,
  20416. Oacute: 0x00D3,
  20417. Oacutesmall: 0xF7F3,
  20418. Obarredcyrillic: 0x04E8,
  20419. Obarreddieresiscyrillic: 0x04EA,
  20420. Obreve: 0x014E,
  20421. Ocaron: 0x01D1,
  20422. Ocenteredtilde: 0x019F,
  20423. Ocircle: 0x24C4,
  20424. Ocircumflex: 0x00D4,
  20425. Ocircumflexacute: 0x1ED0,
  20426. Ocircumflexdotbelow: 0x1ED8,
  20427. Ocircumflexgrave: 0x1ED2,
  20428. Ocircumflexhookabove: 0x1ED4,
  20429. Ocircumflexsmall: 0xF7F4,
  20430. Ocircumflextilde: 0x1ED6,
  20431. Ocyrillic: 0x041E,
  20432. Odblacute: 0x0150,
  20433. Odblgrave: 0x020C,
  20434. Odieresis: 0x00D6,
  20435. Odieresiscyrillic: 0x04E6,
  20436. Odieresissmall: 0xF7F6,
  20437. Odotbelow: 0x1ECC,
  20438. Ogoneksmall: 0xF6FB,
  20439. Ograve: 0x00D2,
  20440. Ogravesmall: 0xF7F2,
  20441. Oharmenian: 0x0555,
  20442. Ohm: 0x2126,
  20443. Ohookabove: 0x1ECE,
  20444. Ohorn: 0x01A0,
  20445. Ohornacute: 0x1EDA,
  20446. Ohorndotbelow: 0x1EE2,
  20447. Ohorngrave: 0x1EDC,
  20448. Ohornhookabove: 0x1EDE,
  20449. Ohorntilde: 0x1EE0,
  20450. Ohungarumlaut: 0x0150,
  20451. Oi: 0x01A2,
  20452. Oinvertedbreve: 0x020E,
  20453. Omacron: 0x014C,
  20454. Omacronacute: 0x1E52,
  20455. Omacrongrave: 0x1E50,
  20456. Omega: 0x2126,
  20457. Omegacyrillic: 0x0460,
  20458. Omegagreek: 0x03A9,
  20459. Omegaroundcyrillic: 0x047A,
  20460. Omegatitlocyrillic: 0x047C,
  20461. Omegatonos: 0x038F,
  20462. Omicron: 0x039F,
  20463. Omicrontonos: 0x038C,
  20464. Omonospace: 0xFF2F,
  20465. Oneroman: 0x2160,
  20466. Oogonek: 0x01EA,
  20467. Oogonekmacron: 0x01EC,
  20468. Oopen: 0x0186,
  20469. Oslash: 0x00D8,
  20470. Oslashacute: 0x01FE,
  20471. Oslashsmall: 0xF7F8,
  20472. Osmall: 0xF76F,
  20473. Ostrokeacute: 0x01FE,
  20474. Otcyrillic: 0x047E,
  20475. Otilde: 0x00D5,
  20476. Otildeacute: 0x1E4C,
  20477. Otildedieresis: 0x1E4E,
  20478. Otildesmall: 0xF7F5,
  20479. P: 0x0050,
  20480. Pacute: 0x1E54,
  20481. Pcircle: 0x24C5,
  20482. Pdotaccent: 0x1E56,
  20483. Pecyrillic: 0x041F,
  20484. Peharmenian: 0x054A,
  20485. Pemiddlehookcyrillic: 0x04A6,
  20486. Phi: 0x03A6,
  20487. Phook: 0x01A4,
  20488. Pi: 0x03A0,
  20489. Piwrarmenian: 0x0553,
  20490. Pmonospace: 0xFF30,
  20491. Psi: 0x03A8,
  20492. Psicyrillic: 0x0470,
  20493. Psmall: 0xF770,
  20494. Q: 0x0051,
  20495. Qcircle: 0x24C6,
  20496. Qmonospace: 0xFF31,
  20497. Qsmall: 0xF771,
  20498. R: 0x0052,
  20499. Raarmenian: 0x054C,
  20500. Racute: 0x0154,
  20501. Rcaron: 0x0158,
  20502. Rcedilla: 0x0156,
  20503. Rcircle: 0x24C7,
  20504. Rcommaaccent: 0x0156,
  20505. Rdblgrave: 0x0210,
  20506. Rdotaccent: 0x1E58,
  20507. Rdotbelow: 0x1E5A,
  20508. Rdotbelowmacron: 0x1E5C,
  20509. Reharmenian: 0x0550,
  20510. Rfraktur: 0x211C,
  20511. Rho: 0x03A1,
  20512. Ringsmall: 0xF6FC,
  20513. Rinvertedbreve: 0x0212,
  20514. Rlinebelow: 0x1E5E,
  20515. Rmonospace: 0xFF32,
  20516. Rsmall: 0xF772,
  20517. Rsmallinverted: 0x0281,
  20518. Rsmallinvertedsuperior: 0x02B6,
  20519. S: 0x0053,
  20520. SF010000: 0x250C,
  20521. SF020000: 0x2514,
  20522. SF030000: 0x2510,
  20523. SF040000: 0x2518,
  20524. SF050000: 0x253C,
  20525. SF060000: 0x252C,
  20526. SF070000: 0x2534,
  20527. SF080000: 0x251C,
  20528. SF090000: 0x2524,
  20529. SF100000: 0x2500,
  20530. SF110000: 0x2502,
  20531. SF190000: 0x2561,
  20532. SF200000: 0x2562,
  20533. SF210000: 0x2556,
  20534. SF220000: 0x2555,
  20535. SF230000: 0x2563,
  20536. SF240000: 0x2551,
  20537. SF250000: 0x2557,
  20538. SF260000: 0x255D,
  20539. SF270000: 0x255C,
  20540. SF280000: 0x255B,
  20541. SF360000: 0x255E,
  20542. SF370000: 0x255F,
  20543. SF380000: 0x255A,
  20544. SF390000: 0x2554,
  20545. SF400000: 0x2569,
  20546. SF410000: 0x2566,
  20547. SF420000: 0x2560,
  20548. SF430000: 0x2550,
  20549. SF440000: 0x256C,
  20550. SF450000: 0x2567,
  20551. SF460000: 0x2568,
  20552. SF470000: 0x2564,
  20553. SF480000: 0x2565,
  20554. SF490000: 0x2559,
  20555. SF500000: 0x2558,
  20556. SF510000: 0x2552,
  20557. SF520000: 0x2553,
  20558. SF530000: 0x256B,
  20559. SF540000: 0x256A,
  20560. Sacute: 0x015A,
  20561. Sacutedotaccent: 0x1E64,
  20562. Sampigreek: 0x03E0,
  20563. Scaron: 0x0160,
  20564. Scarondotaccent: 0x1E66,
  20565. Scaronsmall: 0xF6FD,
  20566. Scedilla: 0x015E,
  20567. Schwa: 0x018F,
  20568. Schwacyrillic: 0x04D8,
  20569. Schwadieresiscyrillic: 0x04DA,
  20570. Scircle: 0x24C8,
  20571. Scircumflex: 0x015C,
  20572. Scommaaccent: 0x0218,
  20573. Sdotaccent: 0x1E60,
  20574. Sdotbelow: 0x1E62,
  20575. Sdotbelowdotaccent: 0x1E68,
  20576. Seharmenian: 0x054D,
  20577. Sevenroman: 0x2166,
  20578. Shaarmenian: 0x0547,
  20579. Shacyrillic: 0x0428,
  20580. Shchacyrillic: 0x0429,
  20581. Sheicoptic: 0x03E2,
  20582. Shhacyrillic: 0x04BA,
  20583. Shimacoptic: 0x03EC,
  20584. Sigma: 0x03A3,
  20585. Sixroman: 0x2165,
  20586. Smonospace: 0xFF33,
  20587. Softsigncyrillic: 0x042C,
  20588. Ssmall: 0xF773,
  20589. Stigmagreek: 0x03DA,
  20590. T: 0x0054,
  20591. Tau: 0x03A4,
  20592. Tbar: 0x0166,
  20593. Tcaron: 0x0164,
  20594. Tcedilla: 0x0162,
  20595. Tcircle: 0x24C9,
  20596. Tcircumflexbelow: 0x1E70,
  20597. Tcommaaccent: 0x0162,
  20598. Tdotaccent: 0x1E6A,
  20599. Tdotbelow: 0x1E6C,
  20600. Tecyrillic: 0x0422,
  20601. Tedescendercyrillic: 0x04AC,
  20602. Tenroman: 0x2169,
  20603. Tetsecyrillic: 0x04B4,
  20604. Theta: 0x0398,
  20605. Thook: 0x01AC,
  20606. Thorn: 0x00DE,
  20607. Thornsmall: 0xF7FE,
  20608. Threeroman: 0x2162,
  20609. Tildesmall: 0xF6FE,
  20610. Tiwnarmenian: 0x054F,
  20611. Tlinebelow: 0x1E6E,
  20612. Tmonospace: 0xFF34,
  20613. Toarmenian: 0x0539,
  20614. Tonefive: 0x01BC,
  20615. Tonesix: 0x0184,
  20616. Tonetwo: 0x01A7,
  20617. Tretroflexhook: 0x01AE,
  20618. Tsecyrillic: 0x0426,
  20619. Tshecyrillic: 0x040B,
  20620. Tsmall: 0xF774,
  20621. Twelveroman: 0x216B,
  20622. Tworoman: 0x2161,
  20623. U: 0x0055,
  20624. Uacute: 0x00DA,
  20625. Uacutesmall: 0xF7FA,
  20626. Ubreve: 0x016C,
  20627. Ucaron: 0x01D3,
  20628. Ucircle: 0x24CA,
  20629. Ucircumflex: 0x00DB,
  20630. Ucircumflexbelow: 0x1E76,
  20631. Ucircumflexsmall: 0xF7FB,
  20632. Ucyrillic: 0x0423,
  20633. Udblacute: 0x0170,
  20634. Udblgrave: 0x0214,
  20635. Udieresis: 0x00DC,
  20636. Udieresisacute: 0x01D7,
  20637. Udieresisbelow: 0x1E72,
  20638. Udieresiscaron: 0x01D9,
  20639. Udieresiscyrillic: 0x04F0,
  20640. Udieresisgrave: 0x01DB,
  20641. Udieresismacron: 0x01D5,
  20642. Udieresissmall: 0xF7FC,
  20643. Udotbelow: 0x1EE4,
  20644. Ugrave: 0x00D9,
  20645. Ugravesmall: 0xF7F9,
  20646. Uhookabove: 0x1EE6,
  20647. Uhorn: 0x01AF,
  20648. Uhornacute: 0x1EE8,
  20649. Uhorndotbelow: 0x1EF0,
  20650. Uhorngrave: 0x1EEA,
  20651. Uhornhookabove: 0x1EEC,
  20652. Uhorntilde: 0x1EEE,
  20653. Uhungarumlaut: 0x0170,
  20654. Uhungarumlautcyrillic: 0x04F2,
  20655. Uinvertedbreve: 0x0216,
  20656. Ukcyrillic: 0x0478,
  20657. Umacron: 0x016A,
  20658. Umacroncyrillic: 0x04EE,
  20659. Umacrondieresis: 0x1E7A,
  20660. Umonospace: 0xFF35,
  20661. Uogonek: 0x0172,
  20662. Upsilon: 0x03A5,
  20663. Upsilon1: 0x03D2,
  20664. Upsilonacutehooksymbolgreek: 0x03D3,
  20665. Upsilonafrican: 0x01B1,
  20666. Upsilondieresis: 0x03AB,
  20667. Upsilondieresishooksymbolgreek: 0x03D4,
  20668. Upsilonhooksymbol: 0x03D2,
  20669. Upsilontonos: 0x038E,
  20670. Uring: 0x016E,
  20671. Ushortcyrillic: 0x040E,
  20672. Usmall: 0xF775,
  20673. Ustraightcyrillic: 0x04AE,
  20674. Ustraightstrokecyrillic: 0x04B0,
  20675. Utilde: 0x0168,
  20676. Utildeacute: 0x1E78,
  20677. Utildebelow: 0x1E74,
  20678. V: 0x0056,
  20679. Vcircle: 0x24CB,
  20680. Vdotbelow: 0x1E7E,
  20681. Vecyrillic: 0x0412,
  20682. Vewarmenian: 0x054E,
  20683. Vhook: 0x01B2,
  20684. Vmonospace: 0xFF36,
  20685. Voarmenian: 0x0548,
  20686. Vsmall: 0xF776,
  20687. Vtilde: 0x1E7C,
  20688. W: 0x0057,
  20689. Wacute: 0x1E82,
  20690. Wcircle: 0x24CC,
  20691. Wcircumflex: 0x0174,
  20692. Wdieresis: 0x1E84,
  20693. Wdotaccent: 0x1E86,
  20694. Wdotbelow: 0x1E88,
  20695. Wgrave: 0x1E80,
  20696. Wmonospace: 0xFF37,
  20697. Wsmall: 0xF777,
  20698. X: 0x0058,
  20699. Xcircle: 0x24CD,
  20700. Xdieresis: 0x1E8C,
  20701. Xdotaccent: 0x1E8A,
  20702. Xeharmenian: 0x053D,
  20703. Xi: 0x039E,
  20704. Xmonospace: 0xFF38,
  20705. Xsmall: 0xF778,
  20706. Y: 0x0059,
  20707. Yacute: 0x00DD,
  20708. Yacutesmall: 0xF7FD,
  20709. Yatcyrillic: 0x0462,
  20710. Ycircle: 0x24CE,
  20711. Ycircumflex: 0x0176,
  20712. Ydieresis: 0x0178,
  20713. Ydieresissmall: 0xF7FF,
  20714. Ydotaccent: 0x1E8E,
  20715. Ydotbelow: 0x1EF4,
  20716. Yericyrillic: 0x042B,
  20717. Yerudieresiscyrillic: 0x04F8,
  20718. Ygrave: 0x1EF2,
  20719. Yhook: 0x01B3,
  20720. Yhookabove: 0x1EF6,
  20721. Yiarmenian: 0x0545,
  20722. Yicyrillic: 0x0407,
  20723. Yiwnarmenian: 0x0552,
  20724. Ymonospace: 0xFF39,
  20725. Ysmall: 0xF779,
  20726. Ytilde: 0x1EF8,
  20727. Yusbigcyrillic: 0x046A,
  20728. Yusbigiotifiedcyrillic: 0x046C,
  20729. Yuslittlecyrillic: 0x0466,
  20730. Yuslittleiotifiedcyrillic: 0x0468,
  20731. Z: 0x005A,
  20732. Zaarmenian: 0x0536,
  20733. Zacute: 0x0179,
  20734. Zcaron: 0x017D,
  20735. Zcaronsmall: 0xF6FF,
  20736. Zcircle: 0x24CF,
  20737. Zcircumflex: 0x1E90,
  20738. Zdot: 0x017B,
  20739. Zdotaccent: 0x017B,
  20740. Zdotbelow: 0x1E92,
  20741. Zecyrillic: 0x0417,
  20742. Zedescendercyrillic: 0x0498,
  20743. Zedieresiscyrillic: 0x04DE,
  20744. Zeta: 0x0396,
  20745. Zhearmenian: 0x053A,
  20746. Zhebrevecyrillic: 0x04C1,
  20747. Zhecyrillic: 0x0416,
  20748. Zhedescendercyrillic: 0x0496,
  20749. Zhedieresiscyrillic: 0x04DC,
  20750. Zlinebelow: 0x1E94,
  20751. Zmonospace: 0xFF3A,
  20752. Zsmall: 0xF77A,
  20753. Zstroke: 0x01B5,
  20754. a: 0x0061,
  20755. aabengali: 0x0986,
  20756. aacute: 0x00E1,
  20757. aadeva: 0x0906,
  20758. aagujarati: 0x0A86,
  20759. aagurmukhi: 0x0A06,
  20760. aamatragurmukhi: 0x0A3E,
  20761. aarusquare: 0x3303,
  20762. aavowelsignbengali: 0x09BE,
  20763. aavowelsigndeva: 0x093E,
  20764. aavowelsigngujarati: 0x0ABE,
  20765. abbreviationmarkarmenian: 0x055F,
  20766. abbreviationsigndeva: 0x0970,
  20767. abengali: 0x0985,
  20768. abopomofo: 0x311A,
  20769. abreve: 0x0103,
  20770. abreveacute: 0x1EAF,
  20771. abrevecyrillic: 0x04D1,
  20772. abrevedotbelow: 0x1EB7,
  20773. abrevegrave: 0x1EB1,
  20774. abrevehookabove: 0x1EB3,
  20775. abrevetilde: 0x1EB5,
  20776. acaron: 0x01CE,
  20777. acircle: 0x24D0,
  20778. acircumflex: 0x00E2,
  20779. acircumflexacute: 0x1EA5,
  20780. acircumflexdotbelow: 0x1EAD,
  20781. acircumflexgrave: 0x1EA7,
  20782. acircumflexhookabove: 0x1EA9,
  20783. acircumflextilde: 0x1EAB,
  20784. acute: 0x00B4,
  20785. acutebelowcmb: 0x0317,
  20786. acutecmb: 0x0301,
  20787. acutecomb: 0x0301,
  20788. acutedeva: 0x0954,
  20789. acutelowmod: 0x02CF,
  20790. acutetonecmb: 0x0341,
  20791. acyrillic: 0x0430,
  20792. adblgrave: 0x0201,
  20793. addakgurmukhi: 0x0A71,
  20794. adeva: 0x0905,
  20795. adieresis: 0x00E4,
  20796. adieresiscyrillic: 0x04D3,
  20797. adieresismacron: 0x01DF,
  20798. adotbelow: 0x1EA1,
  20799. adotmacron: 0x01E1,
  20800. ae: 0x00E6,
  20801. aeacute: 0x01FD,
  20802. aekorean: 0x3150,
  20803. aemacron: 0x01E3,
  20804. afii00208: 0x2015,
  20805. afii08941: 0x20A4,
  20806. afii10017: 0x0410,
  20807. afii10018: 0x0411,
  20808. afii10019: 0x0412,
  20809. afii10020: 0x0413,
  20810. afii10021: 0x0414,
  20811. afii10022: 0x0415,
  20812. afii10023: 0x0401,
  20813. afii10024: 0x0416,
  20814. afii10025: 0x0417,
  20815. afii10026: 0x0418,
  20816. afii10027: 0x0419,
  20817. afii10028: 0x041A,
  20818. afii10029: 0x041B,
  20819. afii10030: 0x041C,
  20820. afii10031: 0x041D,
  20821. afii10032: 0x041E,
  20822. afii10033: 0x041F,
  20823. afii10034: 0x0420,
  20824. afii10035: 0x0421,
  20825. afii10036: 0x0422,
  20826. afii10037: 0x0423,
  20827. afii10038: 0x0424,
  20828. afii10039: 0x0425,
  20829. afii10040: 0x0426,
  20830. afii10041: 0x0427,
  20831. afii10042: 0x0428,
  20832. afii10043: 0x0429,
  20833. afii10044: 0x042A,
  20834. afii10045: 0x042B,
  20835. afii10046: 0x042C,
  20836. afii10047: 0x042D,
  20837. afii10048: 0x042E,
  20838. afii10049: 0x042F,
  20839. afii10050: 0x0490,
  20840. afii10051: 0x0402,
  20841. afii10052: 0x0403,
  20842. afii10053: 0x0404,
  20843. afii10054: 0x0405,
  20844. afii10055: 0x0406,
  20845. afii10056: 0x0407,
  20846. afii10057: 0x0408,
  20847. afii10058: 0x0409,
  20848. afii10059: 0x040A,
  20849. afii10060: 0x040B,
  20850. afii10061: 0x040C,
  20851. afii10062: 0x040E,
  20852. afii10063: 0xF6C4,
  20853. afii10064: 0xF6C5,
  20854. afii10065: 0x0430,
  20855. afii10066: 0x0431,
  20856. afii10067: 0x0432,
  20857. afii10068: 0x0433,
  20858. afii10069: 0x0434,
  20859. afii10070: 0x0435,
  20860. afii10071: 0x0451,
  20861. afii10072: 0x0436,
  20862. afii10073: 0x0437,
  20863. afii10074: 0x0438,
  20864. afii10075: 0x0439,
  20865. afii10076: 0x043A,
  20866. afii10077: 0x043B,
  20867. afii10078: 0x043C,
  20868. afii10079: 0x043D,
  20869. afii10080: 0x043E,
  20870. afii10081: 0x043F,
  20871. afii10082: 0x0440,
  20872. afii10083: 0x0441,
  20873. afii10084: 0x0442,
  20874. afii10085: 0x0443,
  20875. afii10086: 0x0444,
  20876. afii10087: 0x0445,
  20877. afii10088: 0x0446,
  20878. afii10089: 0x0447,
  20879. afii10090: 0x0448,
  20880. afii10091: 0x0449,
  20881. afii10092: 0x044A,
  20882. afii10093: 0x044B,
  20883. afii10094: 0x044C,
  20884. afii10095: 0x044D,
  20885. afii10096: 0x044E,
  20886. afii10097: 0x044F,
  20887. afii10098: 0x0491,
  20888. afii10099: 0x0452,
  20889. afii10100: 0x0453,
  20890. afii10101: 0x0454,
  20891. afii10102: 0x0455,
  20892. afii10103: 0x0456,
  20893. afii10104: 0x0457,
  20894. afii10105: 0x0458,
  20895. afii10106: 0x0459,
  20896. afii10107: 0x045A,
  20897. afii10108: 0x045B,
  20898. afii10109: 0x045C,
  20899. afii10110: 0x045E,
  20900. afii10145: 0x040F,
  20901. afii10146: 0x0462,
  20902. afii10147: 0x0472,
  20903. afii10148: 0x0474,
  20904. afii10192: 0xF6C6,
  20905. afii10193: 0x045F,
  20906. afii10194: 0x0463,
  20907. afii10195: 0x0473,
  20908. afii10196: 0x0475,
  20909. afii10831: 0xF6C7,
  20910. afii10832: 0xF6C8,
  20911. afii10846: 0x04D9,
  20912. afii299: 0x200E,
  20913. afii300: 0x200F,
  20914. afii301: 0x200D,
  20915. afii57381: 0x066A,
  20916. afii57388: 0x060C,
  20917. afii57392: 0x0660,
  20918. afii57393: 0x0661,
  20919. afii57394: 0x0662,
  20920. afii57395: 0x0663,
  20921. afii57396: 0x0664,
  20922. afii57397: 0x0665,
  20923. afii57398: 0x0666,
  20924. afii57399: 0x0667,
  20925. afii57400: 0x0668,
  20926. afii57401: 0x0669,
  20927. afii57403: 0x061B,
  20928. afii57407: 0x061F,
  20929. afii57409: 0x0621,
  20930. afii57410: 0x0622,
  20931. afii57411: 0x0623,
  20932. afii57412: 0x0624,
  20933. afii57413: 0x0625,
  20934. afii57414: 0x0626,
  20935. afii57415: 0x0627,
  20936. afii57416: 0x0628,
  20937. afii57417: 0x0629,
  20938. afii57418: 0x062A,
  20939. afii57419: 0x062B,
  20940. afii57420: 0x062C,
  20941. afii57421: 0x062D,
  20942. afii57422: 0x062E,
  20943. afii57423: 0x062F,
  20944. afii57424: 0x0630,
  20945. afii57425: 0x0631,
  20946. afii57426: 0x0632,
  20947. afii57427: 0x0633,
  20948. afii57428: 0x0634,
  20949. afii57429: 0x0635,
  20950. afii57430: 0x0636,
  20951. afii57431: 0x0637,
  20952. afii57432: 0x0638,
  20953. afii57433: 0x0639,
  20954. afii57434: 0x063A,
  20955. afii57440: 0x0640,
  20956. afii57441: 0x0641,
  20957. afii57442: 0x0642,
  20958. afii57443: 0x0643,
  20959. afii57444: 0x0644,
  20960. afii57445: 0x0645,
  20961. afii57446: 0x0646,
  20962. afii57448: 0x0648,
  20963. afii57449: 0x0649,
  20964. afii57450: 0x064A,
  20965. afii57451: 0x064B,
  20966. afii57452: 0x064C,
  20967. afii57453: 0x064D,
  20968. afii57454: 0x064E,
  20969. afii57455: 0x064F,
  20970. afii57456: 0x0650,
  20971. afii57457: 0x0651,
  20972. afii57458: 0x0652,
  20973. afii57470: 0x0647,
  20974. afii57505: 0x06A4,
  20975. afii57506: 0x067E,
  20976. afii57507: 0x0686,
  20977. afii57508: 0x0698,
  20978. afii57509: 0x06AF,
  20979. afii57511: 0x0679,
  20980. afii57512: 0x0688,
  20981. afii57513: 0x0691,
  20982. afii57514: 0x06BA,
  20983. afii57519: 0x06D2,
  20984. afii57534: 0x06D5,
  20985. afii57636: 0x20AA,
  20986. afii57645: 0x05BE,
  20987. afii57658: 0x05C3,
  20988. afii57664: 0x05D0,
  20989. afii57665: 0x05D1,
  20990. afii57666: 0x05D2,
  20991. afii57667: 0x05D3,
  20992. afii57668: 0x05D4,
  20993. afii57669: 0x05D5,
  20994. afii57670: 0x05D6,
  20995. afii57671: 0x05D7,
  20996. afii57672: 0x05D8,
  20997. afii57673: 0x05D9,
  20998. afii57674: 0x05DA,
  20999. afii57675: 0x05DB,
  21000. afii57676: 0x05DC,
  21001. afii57677: 0x05DD,
  21002. afii57678: 0x05DE,
  21003. afii57679: 0x05DF,
  21004. afii57680: 0x05E0,
  21005. afii57681: 0x05E1,
  21006. afii57682: 0x05E2,
  21007. afii57683: 0x05E3,
  21008. afii57684: 0x05E4,
  21009. afii57685: 0x05E5,
  21010. afii57686: 0x05E6,
  21011. afii57687: 0x05E7,
  21012. afii57688: 0x05E8,
  21013. afii57689: 0x05E9,
  21014. afii57690: 0x05EA,
  21015. afii57694: 0xFB2A,
  21016. afii57695: 0xFB2B,
  21017. afii57700: 0xFB4B,
  21018. afii57705: 0xFB1F,
  21019. afii57716: 0x05F0,
  21020. afii57717: 0x05F1,
  21021. afii57718: 0x05F2,
  21022. afii57723: 0xFB35,
  21023. afii57793: 0x05B4,
  21024. afii57794: 0x05B5,
  21025. afii57795: 0x05B6,
  21026. afii57796: 0x05BB,
  21027. afii57797: 0x05B8,
  21028. afii57798: 0x05B7,
  21029. afii57799: 0x05B0,
  21030. afii57800: 0x05B2,
  21031. afii57801: 0x05B1,
  21032. afii57802: 0x05B3,
  21033. afii57803: 0x05C2,
  21034. afii57804: 0x05C1,
  21035. afii57806: 0x05B9,
  21036. afii57807: 0x05BC,
  21037. afii57839: 0x05BD,
  21038. afii57841: 0x05BF,
  21039. afii57842: 0x05C0,
  21040. afii57929: 0x02BC,
  21041. afii61248: 0x2105,
  21042. afii61289: 0x2113,
  21043. afii61352: 0x2116,
  21044. afii61573: 0x202C,
  21045. afii61574: 0x202D,
  21046. afii61575: 0x202E,
  21047. afii61664: 0x200C,
  21048. afii63167: 0x066D,
  21049. afii64937: 0x02BD,
  21050. agrave: 0x00E0,
  21051. agujarati: 0x0A85,
  21052. agurmukhi: 0x0A05,
  21053. ahiragana: 0x3042,
  21054. ahookabove: 0x1EA3,
  21055. aibengali: 0x0990,
  21056. aibopomofo: 0x311E,
  21057. aideva: 0x0910,
  21058. aiecyrillic: 0x04D5,
  21059. aigujarati: 0x0A90,
  21060. aigurmukhi: 0x0A10,
  21061. aimatragurmukhi: 0x0A48,
  21062. ainarabic: 0x0639,
  21063. ainfinalarabic: 0xFECA,
  21064. aininitialarabic: 0xFECB,
  21065. ainmedialarabic: 0xFECC,
  21066. ainvertedbreve: 0x0203,
  21067. aivowelsignbengali: 0x09C8,
  21068. aivowelsigndeva: 0x0948,
  21069. aivowelsigngujarati: 0x0AC8,
  21070. akatakana: 0x30A2,
  21071. akatakanahalfwidth: 0xFF71,
  21072. akorean: 0x314F,
  21073. alef: 0x05D0,
  21074. alefarabic: 0x0627,
  21075. alefdageshhebrew: 0xFB30,
  21076. aleffinalarabic: 0xFE8E,
  21077. alefhamzaabovearabic: 0x0623,
  21078. alefhamzaabovefinalarabic: 0xFE84,
  21079. alefhamzabelowarabic: 0x0625,
  21080. alefhamzabelowfinalarabic: 0xFE88,
  21081. alefhebrew: 0x05D0,
  21082. aleflamedhebrew: 0xFB4F,
  21083. alefmaddaabovearabic: 0x0622,
  21084. alefmaddaabovefinalarabic: 0xFE82,
  21085. alefmaksuraarabic: 0x0649,
  21086. alefmaksurafinalarabic: 0xFEF0,
  21087. alefmaksurainitialarabic: 0xFEF3,
  21088. alefmaksuramedialarabic: 0xFEF4,
  21089. alefpatahhebrew: 0xFB2E,
  21090. alefqamatshebrew: 0xFB2F,
  21091. aleph: 0x2135,
  21092. allequal: 0x224C,
  21093. alpha: 0x03B1,
  21094. alphatonos: 0x03AC,
  21095. amacron: 0x0101,
  21096. amonospace: 0xFF41,
  21097. ampersand: 0x0026,
  21098. ampersandmonospace: 0xFF06,
  21099. ampersandsmall: 0xF726,
  21100. amsquare: 0x33C2,
  21101. anbopomofo: 0x3122,
  21102. angbopomofo: 0x3124,
  21103. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21104. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21105. angkhankhuthai: 0x0E5A,
  21106. angle: 0x2220,
  21107. anglebracketleft: 0x3008,
  21108. anglebracketleftvertical: 0xFE3F,
  21109. anglebracketright: 0x3009,
  21110. anglebracketrightvertical: 0xFE40,
  21111. angleleft: 0x2329,
  21112. angleright: 0x232A,
  21113. angstrom: 0x212B,
  21114. anoteleia: 0x0387,
  21115. anudattadeva: 0x0952,
  21116. anusvarabengali: 0x0982,
  21117. anusvaradeva: 0x0902,
  21118. anusvaragujarati: 0x0A82,
  21119. aogonek: 0x0105,
  21120. apaatosquare: 0x3300,
  21121. aparen: 0x249C,
  21122. apostrophearmenian: 0x055A,
  21123. apostrophemod: 0x02BC,
  21124. apple: 0xF8FF,
  21125. approaches: 0x2250,
  21126. approxequal: 0x2248,
  21127. approxequalorimage: 0x2252,
  21128. approximatelyequal: 0x2245,
  21129. araeaekorean: 0x318E,
  21130. araeakorean: 0x318D,
  21131. arc: 0x2312,
  21132. arighthalfring: 0x1E9A,
  21133. aring: 0x00E5,
  21134. aringacute: 0x01FB,
  21135. aringbelow: 0x1E01,
  21136. arrowboth: 0x2194,
  21137. arrowdashdown: 0x21E3,
  21138. arrowdashleft: 0x21E0,
  21139. arrowdashright: 0x21E2,
  21140. arrowdashup: 0x21E1,
  21141. arrowdblboth: 0x21D4,
  21142. arrowdbldown: 0x21D3,
  21143. arrowdblleft: 0x21D0,
  21144. arrowdblright: 0x21D2,
  21145. arrowdblup: 0x21D1,
  21146. arrowdown: 0x2193,
  21147. arrowdownleft: 0x2199,
  21148. arrowdownright: 0x2198,
  21149. arrowdownwhite: 0x21E9,
  21150. arrowheaddownmod: 0x02C5,
  21151. arrowheadleftmod: 0x02C2,
  21152. arrowheadrightmod: 0x02C3,
  21153. arrowheadupmod: 0x02C4,
  21154. arrowhorizex: 0xF8E7,
  21155. arrowleft: 0x2190,
  21156. arrowleftdbl: 0x21D0,
  21157. arrowleftdblstroke: 0x21CD,
  21158. arrowleftoverright: 0x21C6,
  21159. arrowleftwhite: 0x21E6,
  21160. arrowright: 0x2192,
  21161. arrowrightdblstroke: 0x21CF,
  21162. arrowrightheavy: 0x279E,
  21163. arrowrightoverleft: 0x21C4,
  21164. arrowrightwhite: 0x21E8,
  21165. arrowtableft: 0x21E4,
  21166. arrowtabright: 0x21E5,
  21167. arrowup: 0x2191,
  21168. arrowupdn: 0x2195,
  21169. arrowupdnbse: 0x21A8,
  21170. arrowupdownbase: 0x21A8,
  21171. arrowupleft: 0x2196,
  21172. arrowupleftofdown: 0x21C5,
  21173. arrowupright: 0x2197,
  21174. arrowupwhite: 0x21E7,
  21175. arrowvertex: 0xF8E6,
  21176. asciicircum: 0x005E,
  21177. asciicircummonospace: 0xFF3E,
  21178. asciitilde: 0x007E,
  21179. asciitildemonospace: 0xFF5E,
  21180. ascript: 0x0251,
  21181. ascriptturned: 0x0252,
  21182. asmallhiragana: 0x3041,
  21183. asmallkatakana: 0x30A1,
  21184. asmallkatakanahalfwidth: 0xFF67,
  21185. asterisk: 0x002A,
  21186. asteriskaltonearabic: 0x066D,
  21187. asteriskarabic: 0x066D,
  21188. asteriskmath: 0x2217,
  21189. asteriskmonospace: 0xFF0A,
  21190. asterisksmall: 0xFE61,
  21191. asterism: 0x2042,
  21192. asuperior: 0xF6E9,
  21193. asymptoticallyequal: 0x2243,
  21194. at: 0x0040,
  21195. atilde: 0x00E3,
  21196. atmonospace: 0xFF20,
  21197. atsmall: 0xFE6B,
  21198. aturned: 0x0250,
  21199. aubengali: 0x0994,
  21200. aubopomofo: 0x3120,
  21201. audeva: 0x0914,
  21202. augujarati: 0x0A94,
  21203. augurmukhi: 0x0A14,
  21204. aulengthmarkbengali: 0x09D7,
  21205. aumatragurmukhi: 0x0A4C,
  21206. auvowelsignbengali: 0x09CC,
  21207. auvowelsigndeva: 0x094C,
  21208. auvowelsigngujarati: 0x0ACC,
  21209. avagrahadeva: 0x093D,
  21210. aybarmenian: 0x0561,
  21211. ayin: 0x05E2,
  21212. ayinaltonehebrew: 0xFB20,
  21213. ayinhebrew: 0x05E2,
  21214. b: 0x0062,
  21215. babengali: 0x09AC,
  21216. backslash: 0x005C,
  21217. backslashmonospace: 0xFF3C,
  21218. badeva: 0x092C,
  21219. bagujarati: 0x0AAC,
  21220. bagurmukhi: 0x0A2C,
  21221. bahiragana: 0x3070,
  21222. bahtthai: 0x0E3F,
  21223. bakatakana: 0x30D0,
  21224. bar: 0x007C,
  21225. barmonospace: 0xFF5C,
  21226. bbopomofo: 0x3105,
  21227. bcircle: 0x24D1,
  21228. bdotaccent: 0x1E03,
  21229. bdotbelow: 0x1E05,
  21230. beamedsixteenthnotes: 0x266C,
  21231. because: 0x2235,
  21232. becyrillic: 0x0431,
  21233. beharabic: 0x0628,
  21234. behfinalarabic: 0xFE90,
  21235. behinitialarabic: 0xFE91,
  21236. behiragana: 0x3079,
  21237. behmedialarabic: 0xFE92,
  21238. behmeeminitialarabic: 0xFC9F,
  21239. behmeemisolatedarabic: 0xFC08,
  21240. behnoonfinalarabic: 0xFC6D,
  21241. bekatakana: 0x30D9,
  21242. benarmenian: 0x0562,
  21243. bet: 0x05D1,
  21244. beta: 0x03B2,
  21245. betasymbolgreek: 0x03D0,
  21246. betdagesh: 0xFB31,
  21247. betdageshhebrew: 0xFB31,
  21248. bethebrew: 0x05D1,
  21249. betrafehebrew: 0xFB4C,
  21250. bhabengali: 0x09AD,
  21251. bhadeva: 0x092D,
  21252. bhagujarati: 0x0AAD,
  21253. bhagurmukhi: 0x0A2D,
  21254. bhook: 0x0253,
  21255. bihiragana: 0x3073,
  21256. bikatakana: 0x30D3,
  21257. bilabialclick: 0x0298,
  21258. bindigurmukhi: 0x0A02,
  21259. birusquare: 0x3331,
  21260. blackcircle: 0x25CF,
  21261. blackdiamond: 0x25C6,
  21262. blackdownpointingtriangle: 0x25BC,
  21263. blackleftpointingpointer: 0x25C4,
  21264. blackleftpointingtriangle: 0x25C0,
  21265. blacklenticularbracketleft: 0x3010,
  21266. blacklenticularbracketleftvertical: 0xFE3B,
  21267. blacklenticularbracketright: 0x3011,
  21268. blacklenticularbracketrightvertical: 0xFE3C,
  21269. blacklowerlefttriangle: 0x25E3,
  21270. blacklowerrighttriangle: 0x25E2,
  21271. blackrectangle: 0x25AC,
  21272. blackrightpointingpointer: 0x25BA,
  21273. blackrightpointingtriangle: 0x25B6,
  21274. blacksmallsquare: 0x25AA,
  21275. blacksmilingface: 0x263B,
  21276. blacksquare: 0x25A0,
  21277. blackstar: 0x2605,
  21278. blackupperlefttriangle: 0x25E4,
  21279. blackupperrighttriangle: 0x25E5,
  21280. blackuppointingsmalltriangle: 0x25B4,
  21281. blackuppointingtriangle: 0x25B2,
  21282. blank: 0x2423,
  21283. blinebelow: 0x1E07,
  21284. block: 0x2588,
  21285. bmonospace: 0xFF42,
  21286. bobaimaithai: 0x0E1A,
  21287. bohiragana: 0x307C,
  21288. bokatakana: 0x30DC,
  21289. bparen: 0x249D,
  21290. bqsquare: 0x33C3,
  21291. braceex: 0xF8F4,
  21292. braceleft: 0x007B,
  21293. braceleftbt: 0xF8F3,
  21294. braceleftmid: 0xF8F2,
  21295. braceleftmonospace: 0xFF5B,
  21296. braceleftsmall: 0xFE5B,
  21297. bracelefttp: 0xF8F1,
  21298. braceleftvertical: 0xFE37,
  21299. braceright: 0x007D,
  21300. bracerightbt: 0xF8FE,
  21301. bracerightmid: 0xF8FD,
  21302. bracerightmonospace: 0xFF5D,
  21303. bracerightsmall: 0xFE5C,
  21304. bracerighttp: 0xF8FC,
  21305. bracerightvertical: 0xFE38,
  21306. bracketleft: 0x005B,
  21307. bracketleftbt: 0xF8F0,
  21308. bracketleftex: 0xF8EF,
  21309. bracketleftmonospace: 0xFF3B,
  21310. bracketlefttp: 0xF8EE,
  21311. bracketright: 0x005D,
  21312. bracketrightbt: 0xF8FB,
  21313. bracketrightex: 0xF8FA,
  21314. bracketrightmonospace: 0xFF3D,
  21315. bracketrighttp: 0xF8F9,
  21316. breve: 0x02D8,
  21317. brevebelowcmb: 0x032E,
  21318. brevecmb: 0x0306,
  21319. breveinvertedbelowcmb: 0x032F,
  21320. breveinvertedcmb: 0x0311,
  21321. breveinverteddoublecmb: 0x0361,
  21322. bridgebelowcmb: 0x032A,
  21323. bridgeinvertedbelowcmb: 0x033A,
  21324. brokenbar: 0x00A6,
  21325. bstroke: 0x0180,
  21326. bsuperior: 0xF6EA,
  21327. btopbar: 0x0183,
  21328. buhiragana: 0x3076,
  21329. bukatakana: 0x30D6,
  21330. bullet: 0x2022,
  21331. bulletinverse: 0x25D8,
  21332. bulletoperator: 0x2219,
  21333. bullseye: 0x25CE,
  21334. c: 0x0063,
  21335. caarmenian: 0x056E,
  21336. cabengali: 0x099A,
  21337. cacute: 0x0107,
  21338. cadeva: 0x091A,
  21339. cagujarati: 0x0A9A,
  21340. cagurmukhi: 0x0A1A,
  21341. calsquare: 0x3388,
  21342. candrabindubengali: 0x0981,
  21343. candrabinducmb: 0x0310,
  21344. candrabindudeva: 0x0901,
  21345. candrabindugujarati: 0x0A81,
  21346. capslock: 0x21EA,
  21347. careof: 0x2105,
  21348. caron: 0x02C7,
  21349. caronbelowcmb: 0x032C,
  21350. caroncmb: 0x030C,
  21351. carriagereturn: 0x21B5,
  21352. cbopomofo: 0x3118,
  21353. ccaron: 0x010D,
  21354. ccedilla: 0x00E7,
  21355. ccedillaacute: 0x1E09,
  21356. ccircle: 0x24D2,
  21357. ccircumflex: 0x0109,
  21358. ccurl: 0x0255,
  21359. cdot: 0x010B,
  21360. cdotaccent: 0x010B,
  21361. cdsquare: 0x33C5,
  21362. cedilla: 0x00B8,
  21363. cedillacmb: 0x0327,
  21364. cent: 0x00A2,
  21365. centigrade: 0x2103,
  21366. centinferior: 0xF6DF,
  21367. centmonospace: 0xFFE0,
  21368. centoldstyle: 0xF7A2,
  21369. centsuperior: 0xF6E0,
  21370. chaarmenian: 0x0579,
  21371. chabengali: 0x099B,
  21372. chadeva: 0x091B,
  21373. chagujarati: 0x0A9B,
  21374. chagurmukhi: 0x0A1B,
  21375. chbopomofo: 0x3114,
  21376. cheabkhasiancyrillic: 0x04BD,
  21377. checkmark: 0x2713,
  21378. checyrillic: 0x0447,
  21379. chedescenderabkhasiancyrillic: 0x04BF,
  21380. chedescendercyrillic: 0x04B7,
  21381. chedieresiscyrillic: 0x04F5,
  21382. cheharmenian: 0x0573,
  21383. chekhakassiancyrillic: 0x04CC,
  21384. cheverticalstrokecyrillic: 0x04B9,
  21385. chi: 0x03C7,
  21386. chieuchacirclekorean: 0x3277,
  21387. chieuchaparenkorean: 0x3217,
  21388. chieuchcirclekorean: 0x3269,
  21389. chieuchkorean: 0x314A,
  21390. chieuchparenkorean: 0x3209,
  21391. chochangthai: 0x0E0A,
  21392. chochanthai: 0x0E08,
  21393. chochingthai: 0x0E09,
  21394. chochoethai: 0x0E0C,
  21395. chook: 0x0188,
  21396. cieucacirclekorean: 0x3276,
  21397. cieucaparenkorean: 0x3216,
  21398. cieuccirclekorean: 0x3268,
  21399. cieuckorean: 0x3148,
  21400. cieucparenkorean: 0x3208,
  21401. cieucuparenkorean: 0x321C,
  21402. circle: 0x25CB,
  21403. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21404. circlemultiply: 0x2297,
  21405. circleot: 0x2299,
  21406. circleplus: 0x2295,
  21407. circlepostalmark: 0x3036,
  21408. circlewithlefthalfblack: 0x25D0,
  21409. circlewithrighthalfblack: 0x25D1,
  21410. circumflex: 0x02C6,
  21411. circumflexbelowcmb: 0x032D,
  21412. circumflexcmb: 0x0302,
  21413. clear: 0x2327,
  21414. clickalveolar: 0x01C2,
  21415. clickdental: 0x01C0,
  21416. clicklateral: 0x01C1,
  21417. clickretroflex: 0x01C3,
  21418. club: 0x2663,
  21419. clubsuitblack: 0x2663,
  21420. clubsuitwhite: 0x2667,
  21421. cmcubedsquare: 0x33A4,
  21422. cmonospace: 0xFF43,
  21423. cmsquaredsquare: 0x33A0,
  21424. coarmenian: 0x0581,
  21425. colon: 0x003A,
  21426. colonmonetary: 0x20A1,
  21427. colonmonospace: 0xFF1A,
  21428. colonsign: 0x20A1,
  21429. colonsmall: 0xFE55,
  21430. colontriangularhalfmod: 0x02D1,
  21431. colontriangularmod: 0x02D0,
  21432. comma: 0x002C,
  21433. commaabovecmb: 0x0313,
  21434. commaaboverightcmb: 0x0315,
  21435. commaaccent: 0xF6C3,
  21436. commaarabic: 0x060C,
  21437. commaarmenian: 0x055D,
  21438. commainferior: 0xF6E1,
  21439. commamonospace: 0xFF0C,
  21440. commareversedabovecmb: 0x0314,
  21441. commareversedmod: 0x02BD,
  21442. commasmall: 0xFE50,
  21443. commasuperior: 0xF6E2,
  21444. commaturnedabovecmb: 0x0312,
  21445. commaturnedmod: 0x02BB,
  21446. compass: 0x263C,
  21447. congruent: 0x2245,
  21448. contourintegral: 0x222E,
  21449. control: 0x2303,
  21450. controlACK: 0x0006,
  21451. controlBEL: 0x0007,
  21452. controlBS: 0x0008,
  21453. controlCAN: 0x0018,
  21454. controlCR: 0x000D,
  21455. controlDC1: 0x0011,
  21456. controlDC2: 0x0012,
  21457. controlDC3: 0x0013,
  21458. controlDC4: 0x0014,
  21459. controlDEL: 0x007F,
  21460. controlDLE: 0x0010,
  21461. controlEM: 0x0019,
  21462. controlENQ: 0x0005,
  21463. controlEOT: 0x0004,
  21464. controlESC: 0x001B,
  21465. controlETB: 0x0017,
  21466. controlETX: 0x0003,
  21467. controlFF: 0x000C,
  21468. controlFS: 0x001C,
  21469. controlGS: 0x001D,
  21470. controlHT: 0x0009,
  21471. controlLF: 0x000A,
  21472. controlNAK: 0x0015,
  21473. controlRS: 0x001E,
  21474. controlSI: 0x000F,
  21475. controlSO: 0x000E,
  21476. controlSOT: 0x0002,
  21477. controlSTX: 0x0001,
  21478. controlSUB: 0x001A,
  21479. controlSYN: 0x0016,
  21480. controlUS: 0x001F,
  21481. controlVT: 0x000B,
  21482. copyright: 0x00A9,
  21483. copyrightsans: 0xF8E9,
  21484. copyrightserif: 0xF6D9,
  21485. cornerbracketleft: 0x300C,
  21486. cornerbracketlefthalfwidth: 0xFF62,
  21487. cornerbracketleftvertical: 0xFE41,
  21488. cornerbracketright: 0x300D,
  21489. cornerbracketrighthalfwidth: 0xFF63,
  21490. cornerbracketrightvertical: 0xFE42,
  21491. corporationsquare: 0x337F,
  21492. cosquare: 0x33C7,
  21493. coverkgsquare: 0x33C6,
  21494. cparen: 0x249E,
  21495. cruzeiro: 0x20A2,
  21496. cstretched: 0x0297,
  21497. curlyand: 0x22CF,
  21498. curlyor: 0x22CE,
  21499. currency: 0x00A4,
  21500. cyrBreve: 0xF6D1,
  21501. cyrFlex: 0xF6D2,
  21502. cyrbreve: 0xF6D4,
  21503. cyrflex: 0xF6D5,
  21504. d: 0x0064,
  21505. daarmenian: 0x0564,
  21506. dabengali: 0x09A6,
  21507. dadarabic: 0x0636,
  21508. dadeva: 0x0926,
  21509. dadfinalarabic: 0xFEBE,
  21510. dadinitialarabic: 0xFEBF,
  21511. dadmedialarabic: 0xFEC0,
  21512. dagesh: 0x05BC,
  21513. dageshhebrew: 0x05BC,
  21514. dagger: 0x2020,
  21515. daggerdbl: 0x2021,
  21516. dagujarati: 0x0AA6,
  21517. dagurmukhi: 0x0A26,
  21518. dahiragana: 0x3060,
  21519. dakatakana: 0x30C0,
  21520. dalarabic: 0x062F,
  21521. dalet: 0x05D3,
  21522. daletdagesh: 0xFB33,
  21523. daletdageshhebrew: 0xFB33,
  21524. dalethebrew: 0x05D3,
  21525. dalfinalarabic: 0xFEAA,
  21526. dammaarabic: 0x064F,
  21527. dammalowarabic: 0x064F,
  21528. dammatanaltonearabic: 0x064C,
  21529. dammatanarabic: 0x064C,
  21530. danda: 0x0964,
  21531. dargahebrew: 0x05A7,
  21532. dargalefthebrew: 0x05A7,
  21533. dasiapneumatacyrilliccmb: 0x0485,
  21534. dblGrave: 0xF6D3,
  21535. dblanglebracketleft: 0x300A,
  21536. dblanglebracketleftvertical: 0xFE3D,
  21537. dblanglebracketright: 0x300B,
  21538. dblanglebracketrightvertical: 0xFE3E,
  21539. dblarchinvertedbelowcmb: 0x032B,
  21540. dblarrowleft: 0x21D4,
  21541. dblarrowright: 0x21D2,
  21542. dbldanda: 0x0965,
  21543. dblgrave: 0xF6D6,
  21544. dblgravecmb: 0x030F,
  21545. dblintegral: 0x222C,
  21546. dbllowline: 0x2017,
  21547. dbllowlinecmb: 0x0333,
  21548. dbloverlinecmb: 0x033F,
  21549. dblprimemod: 0x02BA,
  21550. dblverticalbar: 0x2016,
  21551. dblverticallineabovecmb: 0x030E,
  21552. dbopomofo: 0x3109,
  21553. dbsquare: 0x33C8,
  21554. dcaron: 0x010F,
  21555. dcedilla: 0x1E11,
  21556. dcircle: 0x24D3,
  21557. dcircumflexbelow: 0x1E13,
  21558. dcroat: 0x0111,
  21559. ddabengali: 0x09A1,
  21560. ddadeva: 0x0921,
  21561. ddagujarati: 0x0AA1,
  21562. ddagurmukhi: 0x0A21,
  21563. ddalarabic: 0x0688,
  21564. ddalfinalarabic: 0xFB89,
  21565. dddhadeva: 0x095C,
  21566. ddhabengali: 0x09A2,
  21567. ddhadeva: 0x0922,
  21568. ddhagujarati: 0x0AA2,
  21569. ddhagurmukhi: 0x0A22,
  21570. ddotaccent: 0x1E0B,
  21571. ddotbelow: 0x1E0D,
  21572. decimalseparatorarabic: 0x066B,
  21573. decimalseparatorpersian: 0x066B,
  21574. decyrillic: 0x0434,
  21575. degree: 0x00B0,
  21576. dehihebrew: 0x05AD,
  21577. dehiragana: 0x3067,
  21578. deicoptic: 0x03EF,
  21579. dekatakana: 0x30C7,
  21580. deleteleft: 0x232B,
  21581. deleteright: 0x2326,
  21582. delta: 0x03B4,
  21583. deltaturned: 0x018D,
  21584. denominatorminusonenumeratorbengali: 0x09F8,
  21585. dezh: 0x02A4,
  21586. dhabengali: 0x09A7,
  21587. dhadeva: 0x0927,
  21588. dhagujarati: 0x0AA7,
  21589. dhagurmukhi: 0x0A27,
  21590. dhook: 0x0257,
  21591. dialytikatonos: 0x0385,
  21592. dialytikatonoscmb: 0x0344,
  21593. diamond: 0x2666,
  21594. diamondsuitwhite: 0x2662,
  21595. dieresis: 0x00A8,
  21596. dieresisacute: 0xF6D7,
  21597. dieresisbelowcmb: 0x0324,
  21598. dieresiscmb: 0x0308,
  21599. dieresisgrave: 0xF6D8,
  21600. dieresistonos: 0x0385,
  21601. dihiragana: 0x3062,
  21602. dikatakana: 0x30C2,
  21603. dittomark: 0x3003,
  21604. divide: 0x00F7,
  21605. divides: 0x2223,
  21606. divisionslash: 0x2215,
  21607. djecyrillic: 0x0452,
  21608. dkshade: 0x2593,
  21609. dlinebelow: 0x1E0F,
  21610. dlsquare: 0x3397,
  21611. dmacron: 0x0111,
  21612. dmonospace: 0xFF44,
  21613. dnblock: 0x2584,
  21614. dochadathai: 0x0E0E,
  21615. dodekthai: 0x0E14,
  21616. dohiragana: 0x3069,
  21617. dokatakana: 0x30C9,
  21618. dollar: 0x0024,
  21619. dollarinferior: 0xF6E3,
  21620. dollarmonospace: 0xFF04,
  21621. dollaroldstyle: 0xF724,
  21622. dollarsmall: 0xFE69,
  21623. dollarsuperior: 0xF6E4,
  21624. dong: 0x20AB,
  21625. dorusquare: 0x3326,
  21626. dotaccent: 0x02D9,
  21627. dotaccentcmb: 0x0307,
  21628. dotbelowcmb: 0x0323,
  21629. dotbelowcomb: 0x0323,
  21630. dotkatakana: 0x30FB,
  21631. dotlessi: 0x0131,
  21632. dotlessj: 0xF6BE,
  21633. dotlessjstrokehook: 0x0284,
  21634. dotmath: 0x22C5,
  21635. dottedcircle: 0x25CC,
  21636. doubleyodpatah: 0xFB1F,
  21637. doubleyodpatahhebrew: 0xFB1F,
  21638. downtackbelowcmb: 0x031E,
  21639. downtackmod: 0x02D5,
  21640. dparen: 0x249F,
  21641. dsuperior: 0xF6EB,
  21642. dtail: 0x0256,
  21643. dtopbar: 0x018C,
  21644. duhiragana: 0x3065,
  21645. dukatakana: 0x30C5,
  21646. dz: 0x01F3,
  21647. dzaltone: 0x02A3,
  21648. dzcaron: 0x01C6,
  21649. dzcurl: 0x02A5,
  21650. dzeabkhasiancyrillic: 0x04E1,
  21651. dzecyrillic: 0x0455,
  21652. dzhecyrillic: 0x045F,
  21653. e: 0x0065,
  21654. eacute: 0x00E9,
  21655. earth: 0x2641,
  21656. ebengali: 0x098F,
  21657. ebopomofo: 0x311C,
  21658. ebreve: 0x0115,
  21659. ecandradeva: 0x090D,
  21660. ecandragujarati: 0x0A8D,
  21661. ecandravowelsigndeva: 0x0945,
  21662. ecandravowelsigngujarati: 0x0AC5,
  21663. ecaron: 0x011B,
  21664. ecedillabreve: 0x1E1D,
  21665. echarmenian: 0x0565,
  21666. echyiwnarmenian: 0x0587,
  21667. ecircle: 0x24D4,
  21668. ecircumflex: 0x00EA,
  21669. ecircumflexacute: 0x1EBF,
  21670. ecircumflexbelow: 0x1E19,
  21671. ecircumflexdotbelow: 0x1EC7,
  21672. ecircumflexgrave: 0x1EC1,
  21673. ecircumflexhookabove: 0x1EC3,
  21674. ecircumflextilde: 0x1EC5,
  21675. ecyrillic: 0x0454,
  21676. edblgrave: 0x0205,
  21677. edeva: 0x090F,
  21678. edieresis: 0x00EB,
  21679. edot: 0x0117,
  21680. edotaccent: 0x0117,
  21681. edotbelow: 0x1EB9,
  21682. eegurmukhi: 0x0A0F,
  21683. eematragurmukhi: 0x0A47,
  21684. efcyrillic: 0x0444,
  21685. egrave: 0x00E8,
  21686. egujarati: 0x0A8F,
  21687. eharmenian: 0x0567,
  21688. ehbopomofo: 0x311D,
  21689. ehiragana: 0x3048,
  21690. ehookabove: 0x1EBB,
  21691. eibopomofo: 0x311F,
  21692. eight: 0x0038,
  21693. eightarabic: 0x0668,
  21694. eightbengali: 0x09EE,
  21695. eightcircle: 0x2467,
  21696. eightcircleinversesansserif: 0x2791,
  21697. eightdeva: 0x096E,
  21698. eighteencircle: 0x2471,
  21699. eighteenparen: 0x2485,
  21700. eighteenperiod: 0x2499,
  21701. eightgujarati: 0x0AEE,
  21702. eightgurmukhi: 0x0A6E,
  21703. eighthackarabic: 0x0668,
  21704. eighthangzhou: 0x3028,
  21705. eighthnotebeamed: 0x266B,
  21706. eightideographicparen: 0x3227,
  21707. eightinferior: 0x2088,
  21708. eightmonospace: 0xFF18,
  21709. eightoldstyle: 0xF738,
  21710. eightparen: 0x247B,
  21711. eightperiod: 0x248F,
  21712. eightpersian: 0x06F8,
  21713. eightroman: 0x2177,
  21714. eightsuperior: 0x2078,
  21715. eightthai: 0x0E58,
  21716. einvertedbreve: 0x0207,
  21717. eiotifiedcyrillic: 0x0465,
  21718. ekatakana: 0x30A8,
  21719. ekatakanahalfwidth: 0xFF74,
  21720. ekonkargurmukhi: 0x0A74,
  21721. ekorean: 0x3154,
  21722. elcyrillic: 0x043B,
  21723. element: 0x2208,
  21724. elevencircle: 0x246A,
  21725. elevenparen: 0x247E,
  21726. elevenperiod: 0x2492,
  21727. elevenroman: 0x217A,
  21728. ellipsis: 0x2026,
  21729. ellipsisvertical: 0x22EE,
  21730. emacron: 0x0113,
  21731. emacronacute: 0x1E17,
  21732. emacrongrave: 0x1E15,
  21733. emcyrillic: 0x043C,
  21734. emdash: 0x2014,
  21735. emdashvertical: 0xFE31,
  21736. emonospace: 0xFF45,
  21737. emphasismarkarmenian: 0x055B,
  21738. emptyset: 0x2205,
  21739. enbopomofo: 0x3123,
  21740. encyrillic: 0x043D,
  21741. endash: 0x2013,
  21742. endashvertical: 0xFE32,
  21743. endescendercyrillic: 0x04A3,
  21744. eng: 0x014B,
  21745. engbopomofo: 0x3125,
  21746. enghecyrillic: 0x04A5,
  21747. enhookcyrillic: 0x04C8,
  21748. enspace: 0x2002,
  21749. eogonek: 0x0119,
  21750. eokorean: 0x3153,
  21751. eopen: 0x025B,
  21752. eopenclosed: 0x029A,
  21753. eopenreversed: 0x025C,
  21754. eopenreversedclosed: 0x025E,
  21755. eopenreversedhook: 0x025D,
  21756. eparen: 0x24A0,
  21757. epsilon: 0x03B5,
  21758. epsilontonos: 0x03AD,
  21759. equal: 0x003D,
  21760. equalmonospace: 0xFF1D,
  21761. equalsmall: 0xFE66,
  21762. equalsuperior: 0x207C,
  21763. equivalence: 0x2261,
  21764. erbopomofo: 0x3126,
  21765. ercyrillic: 0x0440,
  21766. ereversed: 0x0258,
  21767. ereversedcyrillic: 0x044D,
  21768. escyrillic: 0x0441,
  21769. esdescendercyrillic: 0x04AB,
  21770. esh: 0x0283,
  21771. eshcurl: 0x0286,
  21772. eshortdeva: 0x090E,
  21773. eshortvowelsigndeva: 0x0946,
  21774. eshreversedloop: 0x01AA,
  21775. eshsquatreversed: 0x0285,
  21776. esmallhiragana: 0x3047,
  21777. esmallkatakana: 0x30A7,
  21778. esmallkatakanahalfwidth: 0xFF6A,
  21779. estimated: 0x212E,
  21780. esuperior: 0xF6EC,
  21781. eta: 0x03B7,
  21782. etarmenian: 0x0568,
  21783. etatonos: 0x03AE,
  21784. eth: 0x00F0,
  21785. etilde: 0x1EBD,
  21786. etildebelow: 0x1E1B,
  21787. etnahtafoukhhebrew: 0x0591,
  21788. etnahtafoukhlefthebrew: 0x0591,
  21789. etnahtahebrew: 0x0591,
  21790. etnahtalefthebrew: 0x0591,
  21791. eturned: 0x01DD,
  21792. eukorean: 0x3161,
  21793. euro: 0x20AC,
  21794. evowelsignbengali: 0x09C7,
  21795. evowelsigndeva: 0x0947,
  21796. evowelsigngujarati: 0x0AC7,
  21797. exclam: 0x0021,
  21798. exclamarmenian: 0x055C,
  21799. exclamdbl: 0x203C,
  21800. exclamdown: 0x00A1,
  21801. exclamdownsmall: 0xF7A1,
  21802. exclammonospace: 0xFF01,
  21803. exclamsmall: 0xF721,
  21804. existential: 0x2203,
  21805. ezh: 0x0292,
  21806. ezhcaron: 0x01EF,
  21807. ezhcurl: 0x0293,
  21808. ezhreversed: 0x01B9,
  21809. ezhtail: 0x01BA,
  21810. f: 0x0066,
  21811. fadeva: 0x095E,
  21812. fagurmukhi: 0x0A5E,
  21813. fahrenheit: 0x2109,
  21814. fathaarabic: 0x064E,
  21815. fathalowarabic: 0x064E,
  21816. fathatanarabic: 0x064B,
  21817. fbopomofo: 0x3108,
  21818. fcircle: 0x24D5,
  21819. fdotaccent: 0x1E1F,
  21820. feharabic: 0x0641,
  21821. feharmenian: 0x0586,
  21822. fehfinalarabic: 0xFED2,
  21823. fehinitialarabic: 0xFED3,
  21824. fehmedialarabic: 0xFED4,
  21825. feicoptic: 0x03E5,
  21826. female: 0x2640,
  21827. ff: 0xFB00,
  21828. ffi: 0xFB03,
  21829. ffl: 0xFB04,
  21830. fi: 0xFB01,
  21831. fifteencircle: 0x246E,
  21832. fifteenparen: 0x2482,
  21833. fifteenperiod: 0x2496,
  21834. figuredash: 0x2012,
  21835. filledbox: 0x25A0,
  21836. filledrect: 0x25AC,
  21837. finalkaf: 0x05DA,
  21838. finalkafdagesh: 0xFB3A,
  21839. finalkafdageshhebrew: 0xFB3A,
  21840. finalkafhebrew: 0x05DA,
  21841. finalmem: 0x05DD,
  21842. finalmemhebrew: 0x05DD,
  21843. finalnun: 0x05DF,
  21844. finalnunhebrew: 0x05DF,
  21845. finalpe: 0x05E3,
  21846. finalpehebrew: 0x05E3,
  21847. finaltsadi: 0x05E5,
  21848. finaltsadihebrew: 0x05E5,
  21849. firsttonechinese: 0x02C9,
  21850. fisheye: 0x25C9,
  21851. fitacyrillic: 0x0473,
  21852. five: 0x0035,
  21853. fivearabic: 0x0665,
  21854. fivebengali: 0x09EB,
  21855. fivecircle: 0x2464,
  21856. fivecircleinversesansserif: 0x278E,
  21857. fivedeva: 0x096B,
  21858. fiveeighths: 0x215D,
  21859. fivegujarati: 0x0AEB,
  21860. fivegurmukhi: 0x0A6B,
  21861. fivehackarabic: 0x0665,
  21862. fivehangzhou: 0x3025,
  21863. fiveideographicparen: 0x3224,
  21864. fiveinferior: 0x2085,
  21865. fivemonospace: 0xFF15,
  21866. fiveoldstyle: 0xF735,
  21867. fiveparen: 0x2478,
  21868. fiveperiod: 0x248C,
  21869. fivepersian: 0x06F5,
  21870. fiveroman: 0x2174,
  21871. fivesuperior: 0x2075,
  21872. fivethai: 0x0E55,
  21873. fl: 0xFB02,
  21874. florin: 0x0192,
  21875. fmonospace: 0xFF46,
  21876. fmsquare: 0x3399,
  21877. fofanthai: 0x0E1F,
  21878. fofathai: 0x0E1D,
  21879. fongmanthai: 0x0E4F,
  21880. forall: 0x2200,
  21881. four: 0x0034,
  21882. fourarabic: 0x0664,
  21883. fourbengali: 0x09EA,
  21884. fourcircle: 0x2463,
  21885. fourcircleinversesansserif: 0x278D,
  21886. fourdeva: 0x096A,
  21887. fourgujarati: 0x0AEA,
  21888. fourgurmukhi: 0x0A6A,
  21889. fourhackarabic: 0x0664,
  21890. fourhangzhou: 0x3024,
  21891. fourideographicparen: 0x3223,
  21892. fourinferior: 0x2084,
  21893. fourmonospace: 0xFF14,
  21894. fournumeratorbengali: 0x09F7,
  21895. fouroldstyle: 0xF734,
  21896. fourparen: 0x2477,
  21897. fourperiod: 0x248B,
  21898. fourpersian: 0x06F4,
  21899. fourroman: 0x2173,
  21900. foursuperior: 0x2074,
  21901. fourteencircle: 0x246D,
  21902. fourteenparen: 0x2481,
  21903. fourteenperiod: 0x2495,
  21904. fourthai: 0x0E54,
  21905. fourthtonechinese: 0x02CB,
  21906. fparen: 0x24A1,
  21907. fraction: 0x2044,
  21908. franc: 0x20A3,
  21909. g: 0x0067,
  21910. gabengali: 0x0997,
  21911. gacute: 0x01F5,
  21912. gadeva: 0x0917,
  21913. gafarabic: 0x06AF,
  21914. gaffinalarabic: 0xFB93,
  21915. gafinitialarabic: 0xFB94,
  21916. gafmedialarabic: 0xFB95,
  21917. gagujarati: 0x0A97,
  21918. gagurmukhi: 0x0A17,
  21919. gahiragana: 0x304C,
  21920. gakatakana: 0x30AC,
  21921. gamma: 0x03B3,
  21922. gammalatinsmall: 0x0263,
  21923. gammasuperior: 0x02E0,
  21924. gangiacoptic: 0x03EB,
  21925. gbopomofo: 0x310D,
  21926. gbreve: 0x011F,
  21927. gcaron: 0x01E7,
  21928. gcedilla: 0x0123,
  21929. gcircle: 0x24D6,
  21930. gcircumflex: 0x011D,
  21931. gcommaaccent: 0x0123,
  21932. gdot: 0x0121,
  21933. gdotaccent: 0x0121,
  21934. gecyrillic: 0x0433,
  21935. gehiragana: 0x3052,
  21936. gekatakana: 0x30B2,
  21937. geometricallyequal: 0x2251,
  21938. gereshaccenthebrew: 0x059C,
  21939. gereshhebrew: 0x05F3,
  21940. gereshmuqdamhebrew: 0x059D,
  21941. germandbls: 0x00DF,
  21942. gershayimaccenthebrew: 0x059E,
  21943. gershayimhebrew: 0x05F4,
  21944. getamark: 0x3013,
  21945. ghabengali: 0x0998,
  21946. ghadarmenian: 0x0572,
  21947. ghadeva: 0x0918,
  21948. ghagujarati: 0x0A98,
  21949. ghagurmukhi: 0x0A18,
  21950. ghainarabic: 0x063A,
  21951. ghainfinalarabic: 0xFECE,
  21952. ghaininitialarabic: 0xFECF,
  21953. ghainmedialarabic: 0xFED0,
  21954. ghemiddlehookcyrillic: 0x0495,
  21955. ghestrokecyrillic: 0x0493,
  21956. gheupturncyrillic: 0x0491,
  21957. ghhadeva: 0x095A,
  21958. ghhagurmukhi: 0x0A5A,
  21959. ghook: 0x0260,
  21960. ghzsquare: 0x3393,
  21961. gihiragana: 0x304E,
  21962. gikatakana: 0x30AE,
  21963. gimarmenian: 0x0563,
  21964. gimel: 0x05D2,
  21965. gimeldagesh: 0xFB32,
  21966. gimeldageshhebrew: 0xFB32,
  21967. gimelhebrew: 0x05D2,
  21968. gjecyrillic: 0x0453,
  21969. glottalinvertedstroke: 0x01BE,
  21970. glottalstop: 0x0294,
  21971. glottalstopinverted: 0x0296,
  21972. glottalstopmod: 0x02C0,
  21973. glottalstopreversed: 0x0295,
  21974. glottalstopreversedmod: 0x02C1,
  21975. glottalstopreversedsuperior: 0x02E4,
  21976. glottalstopstroke: 0x02A1,
  21977. glottalstopstrokereversed: 0x02A2,
  21978. gmacron: 0x1E21,
  21979. gmonospace: 0xFF47,
  21980. gohiragana: 0x3054,
  21981. gokatakana: 0x30B4,
  21982. gparen: 0x24A2,
  21983. gpasquare: 0x33AC,
  21984. gradient: 0x2207,
  21985. grave: 0x0060,
  21986. gravebelowcmb: 0x0316,
  21987. gravecmb: 0x0300,
  21988. gravecomb: 0x0300,
  21989. gravedeva: 0x0953,
  21990. gravelowmod: 0x02CE,
  21991. gravemonospace: 0xFF40,
  21992. gravetonecmb: 0x0340,
  21993. greater: 0x003E,
  21994. greaterequal: 0x2265,
  21995. greaterequalorless: 0x22DB,
  21996. greatermonospace: 0xFF1E,
  21997. greaterorequivalent: 0x2273,
  21998. greaterorless: 0x2277,
  21999. greateroverequal: 0x2267,
  22000. greatersmall: 0xFE65,
  22001. gscript: 0x0261,
  22002. gstroke: 0x01E5,
  22003. guhiragana: 0x3050,
  22004. guillemotleft: 0x00AB,
  22005. guillemotright: 0x00BB,
  22006. guilsinglleft: 0x2039,
  22007. guilsinglright: 0x203A,
  22008. gukatakana: 0x30B0,
  22009. guramusquare: 0x3318,
  22010. gysquare: 0x33C9,
  22011. h: 0x0068,
  22012. haabkhasiancyrillic: 0x04A9,
  22013. haaltonearabic: 0x06C1,
  22014. habengali: 0x09B9,
  22015. hadescendercyrillic: 0x04B3,
  22016. hadeva: 0x0939,
  22017. hagujarati: 0x0AB9,
  22018. hagurmukhi: 0x0A39,
  22019. haharabic: 0x062D,
  22020. hahfinalarabic: 0xFEA2,
  22021. hahinitialarabic: 0xFEA3,
  22022. hahiragana: 0x306F,
  22023. hahmedialarabic: 0xFEA4,
  22024. haitusquare: 0x332A,
  22025. hakatakana: 0x30CF,
  22026. hakatakanahalfwidth: 0xFF8A,
  22027. halantgurmukhi: 0x0A4D,
  22028. hamzaarabic: 0x0621,
  22029. hamzalowarabic: 0x0621,
  22030. hangulfiller: 0x3164,
  22031. hardsigncyrillic: 0x044A,
  22032. harpoonleftbarbup: 0x21BC,
  22033. harpoonrightbarbup: 0x21C0,
  22034. hasquare: 0x33CA,
  22035. hatafpatah: 0x05B2,
  22036. hatafpatah16: 0x05B2,
  22037. hatafpatah23: 0x05B2,
  22038. hatafpatah2f: 0x05B2,
  22039. hatafpatahhebrew: 0x05B2,
  22040. hatafpatahnarrowhebrew: 0x05B2,
  22041. hatafpatahquarterhebrew: 0x05B2,
  22042. hatafpatahwidehebrew: 0x05B2,
  22043. hatafqamats: 0x05B3,
  22044. hatafqamats1b: 0x05B3,
  22045. hatafqamats28: 0x05B3,
  22046. hatafqamats34: 0x05B3,
  22047. hatafqamatshebrew: 0x05B3,
  22048. hatafqamatsnarrowhebrew: 0x05B3,
  22049. hatafqamatsquarterhebrew: 0x05B3,
  22050. hatafqamatswidehebrew: 0x05B3,
  22051. hatafsegol: 0x05B1,
  22052. hatafsegol17: 0x05B1,
  22053. hatafsegol24: 0x05B1,
  22054. hatafsegol30: 0x05B1,
  22055. hatafsegolhebrew: 0x05B1,
  22056. hatafsegolnarrowhebrew: 0x05B1,
  22057. hatafsegolquarterhebrew: 0x05B1,
  22058. hatafsegolwidehebrew: 0x05B1,
  22059. hbar: 0x0127,
  22060. hbopomofo: 0x310F,
  22061. hbrevebelow: 0x1E2B,
  22062. hcedilla: 0x1E29,
  22063. hcircle: 0x24D7,
  22064. hcircumflex: 0x0125,
  22065. hdieresis: 0x1E27,
  22066. hdotaccent: 0x1E23,
  22067. hdotbelow: 0x1E25,
  22068. he: 0x05D4,
  22069. heart: 0x2665,
  22070. heartsuitblack: 0x2665,
  22071. heartsuitwhite: 0x2661,
  22072. hedagesh: 0xFB34,
  22073. hedageshhebrew: 0xFB34,
  22074. hehaltonearabic: 0x06C1,
  22075. heharabic: 0x0647,
  22076. hehebrew: 0x05D4,
  22077. hehfinalaltonearabic: 0xFBA7,
  22078. hehfinalalttwoarabic: 0xFEEA,
  22079. hehfinalarabic: 0xFEEA,
  22080. hehhamzaabovefinalarabic: 0xFBA5,
  22081. hehhamzaaboveisolatedarabic: 0xFBA4,
  22082. hehinitialaltonearabic: 0xFBA8,
  22083. hehinitialarabic: 0xFEEB,
  22084. hehiragana: 0x3078,
  22085. hehmedialaltonearabic: 0xFBA9,
  22086. hehmedialarabic: 0xFEEC,
  22087. heiseierasquare: 0x337B,
  22088. hekatakana: 0x30D8,
  22089. hekatakanahalfwidth: 0xFF8D,
  22090. hekutaarusquare: 0x3336,
  22091. henghook: 0x0267,
  22092. herutusquare: 0x3339,
  22093. het: 0x05D7,
  22094. hethebrew: 0x05D7,
  22095. hhook: 0x0266,
  22096. hhooksuperior: 0x02B1,
  22097. hieuhacirclekorean: 0x327B,
  22098. hieuhaparenkorean: 0x321B,
  22099. hieuhcirclekorean: 0x326D,
  22100. hieuhkorean: 0x314E,
  22101. hieuhparenkorean: 0x320D,
  22102. hihiragana: 0x3072,
  22103. hikatakana: 0x30D2,
  22104. hikatakanahalfwidth: 0xFF8B,
  22105. hiriq: 0x05B4,
  22106. hiriq14: 0x05B4,
  22107. hiriq21: 0x05B4,
  22108. hiriq2d: 0x05B4,
  22109. hiriqhebrew: 0x05B4,
  22110. hiriqnarrowhebrew: 0x05B4,
  22111. hiriqquarterhebrew: 0x05B4,
  22112. hiriqwidehebrew: 0x05B4,
  22113. hlinebelow: 0x1E96,
  22114. hmonospace: 0xFF48,
  22115. hoarmenian: 0x0570,
  22116. hohipthai: 0x0E2B,
  22117. hohiragana: 0x307B,
  22118. hokatakana: 0x30DB,
  22119. hokatakanahalfwidth: 0xFF8E,
  22120. holam: 0x05B9,
  22121. holam19: 0x05B9,
  22122. holam26: 0x05B9,
  22123. holam32: 0x05B9,
  22124. holamhebrew: 0x05B9,
  22125. holamnarrowhebrew: 0x05B9,
  22126. holamquarterhebrew: 0x05B9,
  22127. holamwidehebrew: 0x05B9,
  22128. honokhukthai: 0x0E2E,
  22129. hookabovecomb: 0x0309,
  22130. hookcmb: 0x0309,
  22131. hookpalatalizedbelowcmb: 0x0321,
  22132. hookretroflexbelowcmb: 0x0322,
  22133. hoonsquare: 0x3342,
  22134. horicoptic: 0x03E9,
  22135. horizontalbar: 0x2015,
  22136. horncmb: 0x031B,
  22137. hotsprings: 0x2668,
  22138. house: 0x2302,
  22139. hparen: 0x24A3,
  22140. hsuperior: 0x02B0,
  22141. hturned: 0x0265,
  22142. huhiragana: 0x3075,
  22143. huiitosquare: 0x3333,
  22144. hukatakana: 0x30D5,
  22145. hukatakanahalfwidth: 0xFF8C,
  22146. hungarumlaut: 0x02DD,
  22147. hungarumlautcmb: 0x030B,
  22148. hv: 0x0195,
  22149. hyphen: 0x002D,
  22150. hypheninferior: 0xF6E5,
  22151. hyphenmonospace: 0xFF0D,
  22152. hyphensmall: 0xFE63,
  22153. hyphensuperior: 0xF6E6,
  22154. hyphentwo: 0x2010,
  22155. i: 0x0069,
  22156. iacute: 0x00ED,
  22157. iacyrillic: 0x044F,
  22158. ibengali: 0x0987,
  22159. ibopomofo: 0x3127,
  22160. ibreve: 0x012D,
  22161. icaron: 0x01D0,
  22162. icircle: 0x24D8,
  22163. icircumflex: 0x00EE,
  22164. icyrillic: 0x0456,
  22165. idblgrave: 0x0209,
  22166. ideographearthcircle: 0x328F,
  22167. ideographfirecircle: 0x328B,
  22168. ideographicallianceparen: 0x323F,
  22169. ideographiccallparen: 0x323A,
  22170. ideographiccentrecircle: 0x32A5,
  22171. ideographicclose: 0x3006,
  22172. ideographiccomma: 0x3001,
  22173. ideographiccommaleft: 0xFF64,
  22174. ideographiccongratulationparen: 0x3237,
  22175. ideographiccorrectcircle: 0x32A3,
  22176. ideographicearthparen: 0x322F,
  22177. ideographicenterpriseparen: 0x323D,
  22178. ideographicexcellentcircle: 0x329D,
  22179. ideographicfestivalparen: 0x3240,
  22180. ideographicfinancialcircle: 0x3296,
  22181. ideographicfinancialparen: 0x3236,
  22182. ideographicfireparen: 0x322B,
  22183. ideographichaveparen: 0x3232,
  22184. ideographichighcircle: 0x32A4,
  22185. ideographiciterationmark: 0x3005,
  22186. ideographiclaborcircle: 0x3298,
  22187. ideographiclaborparen: 0x3238,
  22188. ideographicleftcircle: 0x32A7,
  22189. ideographiclowcircle: 0x32A6,
  22190. ideographicmedicinecircle: 0x32A9,
  22191. ideographicmetalparen: 0x322E,
  22192. ideographicmoonparen: 0x322A,
  22193. ideographicnameparen: 0x3234,
  22194. ideographicperiod: 0x3002,
  22195. ideographicprintcircle: 0x329E,
  22196. ideographicreachparen: 0x3243,
  22197. ideographicrepresentparen: 0x3239,
  22198. ideographicresourceparen: 0x323E,
  22199. ideographicrightcircle: 0x32A8,
  22200. ideographicsecretcircle: 0x3299,
  22201. ideographicselfparen: 0x3242,
  22202. ideographicsocietyparen: 0x3233,
  22203. ideographicspace: 0x3000,
  22204. ideographicspecialparen: 0x3235,
  22205. ideographicstockparen: 0x3231,
  22206. ideographicstudyparen: 0x323B,
  22207. ideographicsunparen: 0x3230,
  22208. ideographicsuperviseparen: 0x323C,
  22209. ideographicwaterparen: 0x322C,
  22210. ideographicwoodparen: 0x322D,
  22211. ideographiczero: 0x3007,
  22212. ideographmetalcircle: 0x328E,
  22213. ideographmooncircle: 0x328A,
  22214. ideographnamecircle: 0x3294,
  22215. ideographsuncircle: 0x3290,
  22216. ideographwatercircle: 0x328C,
  22217. ideographwoodcircle: 0x328D,
  22218. ideva: 0x0907,
  22219. idieresis: 0x00EF,
  22220. idieresisacute: 0x1E2F,
  22221. idieresiscyrillic: 0x04E5,
  22222. idotbelow: 0x1ECB,
  22223. iebrevecyrillic: 0x04D7,
  22224. iecyrillic: 0x0435,
  22225. ieungacirclekorean: 0x3275,
  22226. ieungaparenkorean: 0x3215,
  22227. ieungcirclekorean: 0x3267,
  22228. ieungkorean: 0x3147,
  22229. ieungparenkorean: 0x3207,
  22230. igrave: 0x00EC,
  22231. igujarati: 0x0A87,
  22232. igurmukhi: 0x0A07,
  22233. ihiragana: 0x3044,
  22234. ihookabove: 0x1EC9,
  22235. iibengali: 0x0988,
  22236. iicyrillic: 0x0438,
  22237. iideva: 0x0908,
  22238. iigujarati: 0x0A88,
  22239. iigurmukhi: 0x0A08,
  22240. iimatragurmukhi: 0x0A40,
  22241. iinvertedbreve: 0x020B,
  22242. iishortcyrillic: 0x0439,
  22243. iivowelsignbengali: 0x09C0,
  22244. iivowelsigndeva: 0x0940,
  22245. iivowelsigngujarati: 0x0AC0,
  22246. ij: 0x0133,
  22247. ikatakana: 0x30A4,
  22248. ikatakanahalfwidth: 0xFF72,
  22249. ikorean: 0x3163,
  22250. ilde: 0x02DC,
  22251. iluyhebrew: 0x05AC,
  22252. imacron: 0x012B,
  22253. imacroncyrillic: 0x04E3,
  22254. imageorapproximatelyequal: 0x2253,
  22255. imatragurmukhi: 0x0A3F,
  22256. imonospace: 0xFF49,
  22257. increment: 0x2206,
  22258. infinity: 0x221E,
  22259. iniarmenian: 0x056B,
  22260. integral: 0x222B,
  22261. integralbottom: 0x2321,
  22262. integralbt: 0x2321,
  22263. integralex: 0xF8F5,
  22264. integraltop: 0x2320,
  22265. integraltp: 0x2320,
  22266. intersection: 0x2229,
  22267. intisquare: 0x3305,
  22268. invbullet: 0x25D8,
  22269. invcircle: 0x25D9,
  22270. invsmileface: 0x263B,
  22271. iocyrillic: 0x0451,
  22272. iogonek: 0x012F,
  22273. iota: 0x03B9,
  22274. iotadieresis: 0x03CA,
  22275. iotadieresistonos: 0x0390,
  22276. iotalatin: 0x0269,
  22277. iotatonos: 0x03AF,
  22278. iparen: 0x24A4,
  22279. irigurmukhi: 0x0A72,
  22280. ismallhiragana: 0x3043,
  22281. ismallkatakana: 0x30A3,
  22282. ismallkatakanahalfwidth: 0xFF68,
  22283. issharbengali: 0x09FA,
  22284. istroke: 0x0268,
  22285. isuperior: 0xF6ED,
  22286. iterationhiragana: 0x309D,
  22287. iterationkatakana: 0x30FD,
  22288. itilde: 0x0129,
  22289. itildebelow: 0x1E2D,
  22290. iubopomofo: 0x3129,
  22291. iucyrillic: 0x044E,
  22292. ivowelsignbengali: 0x09BF,
  22293. ivowelsigndeva: 0x093F,
  22294. ivowelsigngujarati: 0x0ABF,
  22295. izhitsacyrillic: 0x0475,
  22296. izhitsadblgravecyrillic: 0x0477,
  22297. j: 0x006A,
  22298. jaarmenian: 0x0571,
  22299. jabengali: 0x099C,
  22300. jadeva: 0x091C,
  22301. jagujarati: 0x0A9C,
  22302. jagurmukhi: 0x0A1C,
  22303. jbopomofo: 0x3110,
  22304. jcaron: 0x01F0,
  22305. jcircle: 0x24D9,
  22306. jcircumflex: 0x0135,
  22307. jcrossedtail: 0x029D,
  22308. jdotlessstroke: 0x025F,
  22309. jecyrillic: 0x0458,
  22310. jeemarabic: 0x062C,
  22311. jeemfinalarabic: 0xFE9E,
  22312. jeeminitialarabic: 0xFE9F,
  22313. jeemmedialarabic: 0xFEA0,
  22314. jeharabic: 0x0698,
  22315. jehfinalarabic: 0xFB8B,
  22316. jhabengali: 0x099D,
  22317. jhadeva: 0x091D,
  22318. jhagujarati: 0x0A9D,
  22319. jhagurmukhi: 0x0A1D,
  22320. jheharmenian: 0x057B,
  22321. jis: 0x3004,
  22322. jmonospace: 0xFF4A,
  22323. jparen: 0x24A5,
  22324. jsuperior: 0x02B2,
  22325. k: 0x006B,
  22326. kabashkircyrillic: 0x04A1,
  22327. kabengali: 0x0995,
  22328. kacute: 0x1E31,
  22329. kacyrillic: 0x043A,
  22330. kadescendercyrillic: 0x049B,
  22331. kadeva: 0x0915,
  22332. kaf: 0x05DB,
  22333. kafarabic: 0x0643,
  22334. kafdagesh: 0xFB3B,
  22335. kafdageshhebrew: 0xFB3B,
  22336. kaffinalarabic: 0xFEDA,
  22337. kafhebrew: 0x05DB,
  22338. kafinitialarabic: 0xFEDB,
  22339. kafmedialarabic: 0xFEDC,
  22340. kafrafehebrew: 0xFB4D,
  22341. kagujarati: 0x0A95,
  22342. kagurmukhi: 0x0A15,
  22343. kahiragana: 0x304B,
  22344. kahookcyrillic: 0x04C4,
  22345. kakatakana: 0x30AB,
  22346. kakatakanahalfwidth: 0xFF76,
  22347. kappa: 0x03BA,
  22348. kappasymbolgreek: 0x03F0,
  22349. kapyeounmieumkorean: 0x3171,
  22350. kapyeounphieuphkorean: 0x3184,
  22351. kapyeounpieupkorean: 0x3178,
  22352. kapyeounssangpieupkorean: 0x3179,
  22353. karoriisquare: 0x330D,
  22354. kashidaautoarabic: 0x0640,
  22355. kashidaautonosidebearingarabic: 0x0640,
  22356. kasmallkatakana: 0x30F5,
  22357. kasquare: 0x3384,
  22358. kasraarabic: 0x0650,
  22359. kasratanarabic: 0x064D,
  22360. kastrokecyrillic: 0x049F,
  22361. katahiraprolongmarkhalfwidth: 0xFF70,
  22362. kaverticalstrokecyrillic: 0x049D,
  22363. kbopomofo: 0x310E,
  22364. kcalsquare: 0x3389,
  22365. kcaron: 0x01E9,
  22366. kcedilla: 0x0137,
  22367. kcircle: 0x24DA,
  22368. kcommaaccent: 0x0137,
  22369. kdotbelow: 0x1E33,
  22370. keharmenian: 0x0584,
  22371. kehiragana: 0x3051,
  22372. kekatakana: 0x30B1,
  22373. kekatakanahalfwidth: 0xFF79,
  22374. kenarmenian: 0x056F,
  22375. kesmallkatakana: 0x30F6,
  22376. kgreenlandic: 0x0138,
  22377. khabengali: 0x0996,
  22378. khacyrillic: 0x0445,
  22379. khadeva: 0x0916,
  22380. khagujarati: 0x0A96,
  22381. khagurmukhi: 0x0A16,
  22382. khaharabic: 0x062E,
  22383. khahfinalarabic: 0xFEA6,
  22384. khahinitialarabic: 0xFEA7,
  22385. khahmedialarabic: 0xFEA8,
  22386. kheicoptic: 0x03E7,
  22387. khhadeva: 0x0959,
  22388. khhagurmukhi: 0x0A59,
  22389. khieukhacirclekorean: 0x3278,
  22390. khieukhaparenkorean: 0x3218,
  22391. khieukhcirclekorean: 0x326A,
  22392. khieukhkorean: 0x314B,
  22393. khieukhparenkorean: 0x320A,
  22394. khokhaithai: 0x0E02,
  22395. khokhonthai: 0x0E05,
  22396. khokhuatthai: 0x0E03,
  22397. khokhwaithai: 0x0E04,
  22398. khomutthai: 0x0E5B,
  22399. khook: 0x0199,
  22400. khorakhangthai: 0x0E06,
  22401. khzsquare: 0x3391,
  22402. kihiragana: 0x304D,
  22403. kikatakana: 0x30AD,
  22404. kikatakanahalfwidth: 0xFF77,
  22405. kiroguramusquare: 0x3315,
  22406. kiromeetorusquare: 0x3316,
  22407. kirosquare: 0x3314,
  22408. kiyeokacirclekorean: 0x326E,
  22409. kiyeokaparenkorean: 0x320E,
  22410. kiyeokcirclekorean: 0x3260,
  22411. kiyeokkorean: 0x3131,
  22412. kiyeokparenkorean: 0x3200,
  22413. kiyeoksioskorean: 0x3133,
  22414. kjecyrillic: 0x045C,
  22415. klinebelow: 0x1E35,
  22416. klsquare: 0x3398,
  22417. kmcubedsquare: 0x33A6,
  22418. kmonospace: 0xFF4B,
  22419. kmsquaredsquare: 0x33A2,
  22420. kohiragana: 0x3053,
  22421. kohmsquare: 0x33C0,
  22422. kokaithai: 0x0E01,
  22423. kokatakana: 0x30B3,
  22424. kokatakanahalfwidth: 0xFF7A,
  22425. kooposquare: 0x331E,
  22426. koppacyrillic: 0x0481,
  22427. koreanstandardsymbol: 0x327F,
  22428. koroniscmb: 0x0343,
  22429. kparen: 0x24A6,
  22430. kpasquare: 0x33AA,
  22431. ksicyrillic: 0x046F,
  22432. ktsquare: 0x33CF,
  22433. kturned: 0x029E,
  22434. kuhiragana: 0x304F,
  22435. kukatakana: 0x30AF,
  22436. kukatakanahalfwidth: 0xFF78,
  22437. kvsquare: 0x33B8,
  22438. kwsquare: 0x33BE,
  22439. l: 0x006C,
  22440. labengali: 0x09B2,
  22441. lacute: 0x013A,
  22442. ladeva: 0x0932,
  22443. lagujarati: 0x0AB2,
  22444. lagurmukhi: 0x0A32,
  22445. lakkhangyaothai: 0x0E45,
  22446. lamaleffinalarabic: 0xFEFC,
  22447. lamalefhamzaabovefinalarabic: 0xFEF8,
  22448. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22449. lamalefhamzabelowfinalarabic: 0xFEFA,
  22450. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22451. lamalefisolatedarabic: 0xFEFB,
  22452. lamalefmaddaabovefinalarabic: 0xFEF6,
  22453. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22454. lamarabic: 0x0644,
  22455. lambda: 0x03BB,
  22456. lambdastroke: 0x019B,
  22457. lamed: 0x05DC,
  22458. lameddagesh: 0xFB3C,
  22459. lameddageshhebrew: 0xFB3C,
  22460. lamedhebrew: 0x05DC,
  22461. lamfinalarabic: 0xFEDE,
  22462. lamhahinitialarabic: 0xFCCA,
  22463. laminitialarabic: 0xFEDF,
  22464. lamjeeminitialarabic: 0xFCC9,
  22465. lamkhahinitialarabic: 0xFCCB,
  22466. lamlamhehisolatedarabic: 0xFDF2,
  22467. lammedialarabic: 0xFEE0,
  22468. lammeemhahinitialarabic: 0xFD88,
  22469. lammeeminitialarabic: 0xFCCC,
  22470. largecircle: 0x25EF,
  22471. lbar: 0x019A,
  22472. lbelt: 0x026C,
  22473. lbopomofo: 0x310C,
  22474. lcaron: 0x013E,
  22475. lcedilla: 0x013C,
  22476. lcircle: 0x24DB,
  22477. lcircumflexbelow: 0x1E3D,
  22478. lcommaaccent: 0x013C,
  22479. ldot: 0x0140,
  22480. ldotaccent: 0x0140,
  22481. ldotbelow: 0x1E37,
  22482. ldotbelowmacron: 0x1E39,
  22483. leftangleabovecmb: 0x031A,
  22484. lefttackbelowcmb: 0x0318,
  22485. less: 0x003C,
  22486. lessequal: 0x2264,
  22487. lessequalorgreater: 0x22DA,
  22488. lessmonospace: 0xFF1C,
  22489. lessorequivalent: 0x2272,
  22490. lessorgreater: 0x2276,
  22491. lessoverequal: 0x2266,
  22492. lesssmall: 0xFE64,
  22493. lezh: 0x026E,
  22494. lfblock: 0x258C,
  22495. lhookretroflex: 0x026D,
  22496. lira: 0x20A4,
  22497. liwnarmenian: 0x056C,
  22498. lj: 0x01C9,
  22499. ljecyrillic: 0x0459,
  22500. ll: 0xF6C0,
  22501. lladeva: 0x0933,
  22502. llagujarati: 0x0AB3,
  22503. llinebelow: 0x1E3B,
  22504. llladeva: 0x0934,
  22505. llvocalicbengali: 0x09E1,
  22506. llvocalicdeva: 0x0961,
  22507. llvocalicvowelsignbengali: 0x09E3,
  22508. llvocalicvowelsigndeva: 0x0963,
  22509. lmiddletilde: 0x026B,
  22510. lmonospace: 0xFF4C,
  22511. lmsquare: 0x33D0,
  22512. lochulathai: 0x0E2C,
  22513. logicaland: 0x2227,
  22514. logicalnot: 0x00AC,
  22515. logicalnotreversed: 0x2310,
  22516. logicalor: 0x2228,
  22517. lolingthai: 0x0E25,
  22518. longs: 0x017F,
  22519. lowlinecenterline: 0xFE4E,
  22520. lowlinecmb: 0x0332,
  22521. lowlinedashed: 0xFE4D,
  22522. lozenge: 0x25CA,
  22523. lparen: 0x24A7,
  22524. lslash: 0x0142,
  22525. lsquare: 0x2113,
  22526. lsuperior: 0xF6EE,
  22527. ltshade: 0x2591,
  22528. luthai: 0x0E26,
  22529. lvocalicbengali: 0x098C,
  22530. lvocalicdeva: 0x090C,
  22531. lvocalicvowelsignbengali: 0x09E2,
  22532. lvocalicvowelsigndeva: 0x0962,
  22533. lxsquare: 0x33D3,
  22534. m: 0x006D,
  22535. mabengali: 0x09AE,
  22536. macron: 0x00AF,
  22537. macronbelowcmb: 0x0331,
  22538. macroncmb: 0x0304,
  22539. macronlowmod: 0x02CD,
  22540. macronmonospace: 0xFFE3,
  22541. macute: 0x1E3F,
  22542. madeva: 0x092E,
  22543. magujarati: 0x0AAE,
  22544. magurmukhi: 0x0A2E,
  22545. mahapakhhebrew: 0x05A4,
  22546. mahapakhlefthebrew: 0x05A4,
  22547. mahiragana: 0x307E,
  22548. maichattawalowleftthai: 0xF895,
  22549. maichattawalowrightthai: 0xF894,
  22550. maichattawathai: 0x0E4B,
  22551. maichattawaupperleftthai: 0xF893,
  22552. maieklowleftthai: 0xF88C,
  22553. maieklowrightthai: 0xF88B,
  22554. maiekthai: 0x0E48,
  22555. maiekupperleftthai: 0xF88A,
  22556. maihanakatleftthai: 0xF884,
  22557. maihanakatthai: 0x0E31,
  22558. maitaikhuleftthai: 0xF889,
  22559. maitaikhuthai: 0x0E47,
  22560. maitholowleftthai: 0xF88F,
  22561. maitholowrightthai: 0xF88E,
  22562. maithothai: 0x0E49,
  22563. maithoupperleftthai: 0xF88D,
  22564. maitrilowleftthai: 0xF892,
  22565. maitrilowrightthai: 0xF891,
  22566. maitrithai: 0x0E4A,
  22567. maitriupperleftthai: 0xF890,
  22568. maiyamokthai: 0x0E46,
  22569. makatakana: 0x30DE,
  22570. makatakanahalfwidth: 0xFF8F,
  22571. male: 0x2642,
  22572. mansyonsquare: 0x3347,
  22573. maqafhebrew: 0x05BE,
  22574. mars: 0x2642,
  22575. masoracirclehebrew: 0x05AF,
  22576. masquare: 0x3383,
  22577. mbopomofo: 0x3107,
  22578. mbsquare: 0x33D4,
  22579. mcircle: 0x24DC,
  22580. mcubedsquare: 0x33A5,
  22581. mdotaccent: 0x1E41,
  22582. mdotbelow: 0x1E43,
  22583. meemarabic: 0x0645,
  22584. meemfinalarabic: 0xFEE2,
  22585. meeminitialarabic: 0xFEE3,
  22586. meemmedialarabic: 0xFEE4,
  22587. meemmeeminitialarabic: 0xFCD1,
  22588. meemmeemisolatedarabic: 0xFC48,
  22589. meetorusquare: 0x334D,
  22590. mehiragana: 0x3081,
  22591. meizierasquare: 0x337E,
  22592. mekatakana: 0x30E1,
  22593. mekatakanahalfwidth: 0xFF92,
  22594. mem: 0x05DE,
  22595. memdagesh: 0xFB3E,
  22596. memdageshhebrew: 0xFB3E,
  22597. memhebrew: 0x05DE,
  22598. menarmenian: 0x0574,
  22599. merkhahebrew: 0x05A5,
  22600. merkhakefulahebrew: 0x05A6,
  22601. merkhakefulalefthebrew: 0x05A6,
  22602. merkhalefthebrew: 0x05A5,
  22603. mhook: 0x0271,
  22604. mhzsquare: 0x3392,
  22605. middledotkatakanahalfwidth: 0xFF65,
  22606. middot: 0x00B7,
  22607. mieumacirclekorean: 0x3272,
  22608. mieumaparenkorean: 0x3212,
  22609. mieumcirclekorean: 0x3264,
  22610. mieumkorean: 0x3141,
  22611. mieumpansioskorean: 0x3170,
  22612. mieumparenkorean: 0x3204,
  22613. mieumpieupkorean: 0x316E,
  22614. mieumsioskorean: 0x316F,
  22615. mihiragana: 0x307F,
  22616. mikatakana: 0x30DF,
  22617. mikatakanahalfwidth: 0xFF90,
  22618. minus: 0x2212,
  22619. minusbelowcmb: 0x0320,
  22620. minuscircle: 0x2296,
  22621. minusmod: 0x02D7,
  22622. minusplus: 0x2213,
  22623. minute: 0x2032,
  22624. miribaarusquare: 0x334A,
  22625. mirisquare: 0x3349,
  22626. mlonglegturned: 0x0270,
  22627. mlsquare: 0x3396,
  22628. mmcubedsquare: 0x33A3,
  22629. mmonospace: 0xFF4D,
  22630. mmsquaredsquare: 0x339F,
  22631. mohiragana: 0x3082,
  22632. mohmsquare: 0x33C1,
  22633. mokatakana: 0x30E2,
  22634. mokatakanahalfwidth: 0xFF93,
  22635. molsquare: 0x33D6,
  22636. momathai: 0x0E21,
  22637. moverssquare: 0x33A7,
  22638. moverssquaredsquare: 0x33A8,
  22639. mparen: 0x24A8,
  22640. mpasquare: 0x33AB,
  22641. mssquare: 0x33B3,
  22642. msuperior: 0xF6EF,
  22643. mturned: 0x026F,
  22644. mu: 0x00B5,
  22645. mu1: 0x00B5,
  22646. muasquare: 0x3382,
  22647. muchgreater: 0x226B,
  22648. muchless: 0x226A,
  22649. mufsquare: 0x338C,
  22650. mugreek: 0x03BC,
  22651. mugsquare: 0x338D,
  22652. muhiragana: 0x3080,
  22653. mukatakana: 0x30E0,
  22654. mukatakanahalfwidth: 0xFF91,
  22655. mulsquare: 0x3395,
  22656. multiply: 0x00D7,
  22657. mumsquare: 0x339B,
  22658. munahhebrew: 0x05A3,
  22659. munahlefthebrew: 0x05A3,
  22660. musicalnote: 0x266A,
  22661. musicalnotedbl: 0x266B,
  22662. musicflatsign: 0x266D,
  22663. musicsharpsign: 0x266F,
  22664. mussquare: 0x33B2,
  22665. muvsquare: 0x33B6,
  22666. muwsquare: 0x33BC,
  22667. mvmegasquare: 0x33B9,
  22668. mvsquare: 0x33B7,
  22669. mwmegasquare: 0x33BF,
  22670. mwsquare: 0x33BD,
  22671. n: 0x006E,
  22672. nabengali: 0x09A8,
  22673. nabla: 0x2207,
  22674. nacute: 0x0144,
  22675. nadeva: 0x0928,
  22676. nagujarati: 0x0AA8,
  22677. nagurmukhi: 0x0A28,
  22678. nahiragana: 0x306A,
  22679. nakatakana: 0x30CA,
  22680. nakatakanahalfwidth: 0xFF85,
  22681. napostrophe: 0x0149,
  22682. nasquare: 0x3381,
  22683. nbopomofo: 0x310B,
  22684. nbspace: 0x00A0,
  22685. ncaron: 0x0148,
  22686. ncedilla: 0x0146,
  22687. ncircle: 0x24DD,
  22688. ncircumflexbelow: 0x1E4B,
  22689. ncommaaccent: 0x0146,
  22690. ndotaccent: 0x1E45,
  22691. ndotbelow: 0x1E47,
  22692. nehiragana: 0x306D,
  22693. nekatakana: 0x30CD,
  22694. nekatakanahalfwidth: 0xFF88,
  22695. newsheqelsign: 0x20AA,
  22696. nfsquare: 0x338B,
  22697. ngabengali: 0x0999,
  22698. ngadeva: 0x0919,
  22699. ngagujarati: 0x0A99,
  22700. ngagurmukhi: 0x0A19,
  22701. ngonguthai: 0x0E07,
  22702. nhiragana: 0x3093,
  22703. nhookleft: 0x0272,
  22704. nhookretroflex: 0x0273,
  22705. nieunacirclekorean: 0x326F,
  22706. nieunaparenkorean: 0x320F,
  22707. nieuncieuckorean: 0x3135,
  22708. nieuncirclekorean: 0x3261,
  22709. nieunhieuhkorean: 0x3136,
  22710. nieunkorean: 0x3134,
  22711. nieunpansioskorean: 0x3168,
  22712. nieunparenkorean: 0x3201,
  22713. nieunsioskorean: 0x3167,
  22714. nieuntikeutkorean: 0x3166,
  22715. nihiragana: 0x306B,
  22716. nikatakana: 0x30CB,
  22717. nikatakanahalfwidth: 0xFF86,
  22718. nikhahitleftthai: 0xF899,
  22719. nikhahitthai: 0x0E4D,
  22720. nine: 0x0039,
  22721. ninearabic: 0x0669,
  22722. ninebengali: 0x09EF,
  22723. ninecircle: 0x2468,
  22724. ninecircleinversesansserif: 0x2792,
  22725. ninedeva: 0x096F,
  22726. ninegujarati: 0x0AEF,
  22727. ninegurmukhi: 0x0A6F,
  22728. ninehackarabic: 0x0669,
  22729. ninehangzhou: 0x3029,
  22730. nineideographicparen: 0x3228,
  22731. nineinferior: 0x2089,
  22732. ninemonospace: 0xFF19,
  22733. nineoldstyle: 0xF739,
  22734. nineparen: 0x247C,
  22735. nineperiod: 0x2490,
  22736. ninepersian: 0x06F9,
  22737. nineroman: 0x2178,
  22738. ninesuperior: 0x2079,
  22739. nineteencircle: 0x2472,
  22740. nineteenparen: 0x2486,
  22741. nineteenperiod: 0x249A,
  22742. ninethai: 0x0E59,
  22743. nj: 0x01CC,
  22744. njecyrillic: 0x045A,
  22745. nkatakana: 0x30F3,
  22746. nkatakanahalfwidth: 0xFF9D,
  22747. nlegrightlong: 0x019E,
  22748. nlinebelow: 0x1E49,
  22749. nmonospace: 0xFF4E,
  22750. nmsquare: 0x339A,
  22751. nnabengali: 0x09A3,
  22752. nnadeva: 0x0923,
  22753. nnagujarati: 0x0AA3,
  22754. nnagurmukhi: 0x0A23,
  22755. nnnadeva: 0x0929,
  22756. nohiragana: 0x306E,
  22757. nokatakana: 0x30CE,
  22758. nokatakanahalfwidth: 0xFF89,
  22759. nonbreakingspace: 0x00A0,
  22760. nonenthai: 0x0E13,
  22761. nonuthai: 0x0E19,
  22762. noonarabic: 0x0646,
  22763. noonfinalarabic: 0xFEE6,
  22764. noonghunnaarabic: 0x06BA,
  22765. noonghunnafinalarabic: 0xFB9F,
  22766. nooninitialarabic: 0xFEE7,
  22767. noonjeeminitialarabic: 0xFCD2,
  22768. noonjeemisolatedarabic: 0xFC4B,
  22769. noonmedialarabic: 0xFEE8,
  22770. noonmeeminitialarabic: 0xFCD5,
  22771. noonmeemisolatedarabic: 0xFC4E,
  22772. noonnoonfinalarabic: 0xFC8D,
  22773. notcontains: 0x220C,
  22774. notelement: 0x2209,
  22775. notelementof: 0x2209,
  22776. notequal: 0x2260,
  22777. notgreater: 0x226F,
  22778. notgreaternorequal: 0x2271,
  22779. notgreaternorless: 0x2279,
  22780. notidentical: 0x2262,
  22781. notless: 0x226E,
  22782. notlessnorequal: 0x2270,
  22783. notparallel: 0x2226,
  22784. notprecedes: 0x2280,
  22785. notsubset: 0x2284,
  22786. notsucceeds: 0x2281,
  22787. notsuperset: 0x2285,
  22788. nowarmenian: 0x0576,
  22789. nparen: 0x24A9,
  22790. nssquare: 0x33B1,
  22791. nsuperior: 0x207F,
  22792. ntilde: 0x00F1,
  22793. nu: 0x03BD,
  22794. nuhiragana: 0x306C,
  22795. nukatakana: 0x30CC,
  22796. nukatakanahalfwidth: 0xFF87,
  22797. nuktabengali: 0x09BC,
  22798. nuktadeva: 0x093C,
  22799. nuktagujarati: 0x0ABC,
  22800. nuktagurmukhi: 0x0A3C,
  22801. numbersign: 0x0023,
  22802. numbersignmonospace: 0xFF03,
  22803. numbersignsmall: 0xFE5F,
  22804. numeralsigngreek: 0x0374,
  22805. numeralsignlowergreek: 0x0375,
  22806. numero: 0x2116,
  22807. nun: 0x05E0,
  22808. nundagesh: 0xFB40,
  22809. nundageshhebrew: 0xFB40,
  22810. nunhebrew: 0x05E0,
  22811. nvsquare: 0x33B5,
  22812. nwsquare: 0x33BB,
  22813. nyabengali: 0x099E,
  22814. nyadeva: 0x091E,
  22815. nyagujarati: 0x0A9E,
  22816. nyagurmukhi: 0x0A1E,
  22817. o: 0x006F,
  22818. oacute: 0x00F3,
  22819. oangthai: 0x0E2D,
  22820. obarred: 0x0275,
  22821. obarredcyrillic: 0x04E9,
  22822. obarreddieresiscyrillic: 0x04EB,
  22823. obengali: 0x0993,
  22824. obopomofo: 0x311B,
  22825. obreve: 0x014F,
  22826. ocandradeva: 0x0911,
  22827. ocandragujarati: 0x0A91,
  22828. ocandravowelsigndeva: 0x0949,
  22829. ocandravowelsigngujarati: 0x0AC9,
  22830. ocaron: 0x01D2,
  22831. ocircle: 0x24DE,
  22832. ocircumflex: 0x00F4,
  22833. ocircumflexacute: 0x1ED1,
  22834. ocircumflexdotbelow: 0x1ED9,
  22835. ocircumflexgrave: 0x1ED3,
  22836. ocircumflexhookabove: 0x1ED5,
  22837. ocircumflextilde: 0x1ED7,
  22838. ocyrillic: 0x043E,
  22839. odblacute: 0x0151,
  22840. odblgrave: 0x020D,
  22841. odeva: 0x0913,
  22842. odieresis: 0x00F6,
  22843. odieresiscyrillic: 0x04E7,
  22844. odotbelow: 0x1ECD,
  22845. oe: 0x0153,
  22846. oekorean: 0x315A,
  22847. ogonek: 0x02DB,
  22848. ogonekcmb: 0x0328,
  22849. ograve: 0x00F2,
  22850. ogujarati: 0x0A93,
  22851. oharmenian: 0x0585,
  22852. ohiragana: 0x304A,
  22853. ohookabove: 0x1ECF,
  22854. ohorn: 0x01A1,
  22855. ohornacute: 0x1EDB,
  22856. ohorndotbelow: 0x1EE3,
  22857. ohorngrave: 0x1EDD,
  22858. ohornhookabove: 0x1EDF,
  22859. ohorntilde: 0x1EE1,
  22860. ohungarumlaut: 0x0151,
  22861. oi: 0x01A3,
  22862. oinvertedbreve: 0x020F,
  22863. okatakana: 0x30AA,
  22864. okatakanahalfwidth: 0xFF75,
  22865. okorean: 0x3157,
  22866. olehebrew: 0x05AB,
  22867. omacron: 0x014D,
  22868. omacronacute: 0x1E53,
  22869. omacrongrave: 0x1E51,
  22870. omdeva: 0x0950,
  22871. omega: 0x03C9,
  22872. omega1: 0x03D6,
  22873. omegacyrillic: 0x0461,
  22874. omegalatinclosed: 0x0277,
  22875. omegaroundcyrillic: 0x047B,
  22876. omegatitlocyrillic: 0x047D,
  22877. omegatonos: 0x03CE,
  22878. omgujarati: 0x0AD0,
  22879. omicron: 0x03BF,
  22880. omicrontonos: 0x03CC,
  22881. omonospace: 0xFF4F,
  22882. one: 0x0031,
  22883. onearabic: 0x0661,
  22884. onebengali: 0x09E7,
  22885. onecircle: 0x2460,
  22886. onecircleinversesansserif: 0x278A,
  22887. onedeva: 0x0967,
  22888. onedotenleader: 0x2024,
  22889. oneeighth: 0x215B,
  22890. onefitted: 0xF6DC,
  22891. onegujarati: 0x0AE7,
  22892. onegurmukhi: 0x0A67,
  22893. onehackarabic: 0x0661,
  22894. onehalf: 0x00BD,
  22895. onehangzhou: 0x3021,
  22896. oneideographicparen: 0x3220,
  22897. oneinferior: 0x2081,
  22898. onemonospace: 0xFF11,
  22899. onenumeratorbengali: 0x09F4,
  22900. oneoldstyle: 0xF731,
  22901. oneparen: 0x2474,
  22902. oneperiod: 0x2488,
  22903. onepersian: 0x06F1,
  22904. onequarter: 0x00BC,
  22905. oneroman: 0x2170,
  22906. onesuperior: 0x00B9,
  22907. onethai: 0x0E51,
  22908. onethird: 0x2153,
  22909. oogonek: 0x01EB,
  22910. oogonekmacron: 0x01ED,
  22911. oogurmukhi: 0x0A13,
  22912. oomatragurmukhi: 0x0A4B,
  22913. oopen: 0x0254,
  22914. oparen: 0x24AA,
  22915. openbullet: 0x25E6,
  22916. option: 0x2325,
  22917. ordfeminine: 0x00AA,
  22918. ordmasculine: 0x00BA,
  22919. orthogonal: 0x221F,
  22920. oshortdeva: 0x0912,
  22921. oshortvowelsigndeva: 0x094A,
  22922. oslash: 0x00F8,
  22923. oslashacute: 0x01FF,
  22924. osmallhiragana: 0x3049,
  22925. osmallkatakana: 0x30A9,
  22926. osmallkatakanahalfwidth: 0xFF6B,
  22927. ostrokeacute: 0x01FF,
  22928. osuperior: 0xF6F0,
  22929. otcyrillic: 0x047F,
  22930. otilde: 0x00F5,
  22931. otildeacute: 0x1E4D,
  22932. otildedieresis: 0x1E4F,
  22933. oubopomofo: 0x3121,
  22934. overline: 0x203E,
  22935. overlinecenterline: 0xFE4A,
  22936. overlinecmb: 0x0305,
  22937. overlinedashed: 0xFE49,
  22938. overlinedblwavy: 0xFE4C,
  22939. overlinewavy: 0xFE4B,
  22940. overscore: 0x00AF,
  22941. ovowelsignbengali: 0x09CB,
  22942. ovowelsigndeva: 0x094B,
  22943. ovowelsigngujarati: 0x0ACB,
  22944. p: 0x0070,
  22945. paampssquare: 0x3380,
  22946. paasentosquare: 0x332B,
  22947. pabengali: 0x09AA,
  22948. pacute: 0x1E55,
  22949. padeva: 0x092A,
  22950. pagedown: 0x21DF,
  22951. pageup: 0x21DE,
  22952. pagujarati: 0x0AAA,
  22953. pagurmukhi: 0x0A2A,
  22954. pahiragana: 0x3071,
  22955. paiyannoithai: 0x0E2F,
  22956. pakatakana: 0x30D1,
  22957. palatalizationcyrilliccmb: 0x0484,
  22958. palochkacyrillic: 0x04C0,
  22959. pansioskorean: 0x317F,
  22960. paragraph: 0x00B6,
  22961. parallel: 0x2225,
  22962. parenleft: 0x0028,
  22963. parenleftaltonearabic: 0xFD3E,
  22964. parenleftbt: 0xF8ED,
  22965. parenleftex: 0xF8EC,
  22966. parenleftinferior: 0x208D,
  22967. parenleftmonospace: 0xFF08,
  22968. parenleftsmall: 0xFE59,
  22969. parenleftsuperior: 0x207D,
  22970. parenlefttp: 0xF8EB,
  22971. parenleftvertical: 0xFE35,
  22972. parenright: 0x0029,
  22973. parenrightaltonearabic: 0xFD3F,
  22974. parenrightbt: 0xF8F8,
  22975. parenrightex: 0xF8F7,
  22976. parenrightinferior: 0x208E,
  22977. parenrightmonospace: 0xFF09,
  22978. parenrightsmall: 0xFE5A,
  22979. parenrightsuperior: 0x207E,
  22980. parenrighttp: 0xF8F6,
  22981. parenrightvertical: 0xFE36,
  22982. partialdiff: 0x2202,
  22983. paseqhebrew: 0x05C0,
  22984. pashtahebrew: 0x0599,
  22985. pasquare: 0x33A9,
  22986. patah: 0x05B7,
  22987. patah11: 0x05B7,
  22988. patah1d: 0x05B7,
  22989. patah2a: 0x05B7,
  22990. patahhebrew: 0x05B7,
  22991. patahnarrowhebrew: 0x05B7,
  22992. patahquarterhebrew: 0x05B7,
  22993. patahwidehebrew: 0x05B7,
  22994. pazerhebrew: 0x05A1,
  22995. pbopomofo: 0x3106,
  22996. pcircle: 0x24DF,
  22997. pdotaccent: 0x1E57,
  22998. pe: 0x05E4,
  22999. pecyrillic: 0x043F,
  23000. pedagesh: 0xFB44,
  23001. pedageshhebrew: 0xFB44,
  23002. peezisquare: 0x333B,
  23003. pefinaldageshhebrew: 0xFB43,
  23004. peharabic: 0x067E,
  23005. peharmenian: 0x057A,
  23006. pehebrew: 0x05E4,
  23007. pehfinalarabic: 0xFB57,
  23008. pehinitialarabic: 0xFB58,
  23009. pehiragana: 0x307A,
  23010. pehmedialarabic: 0xFB59,
  23011. pekatakana: 0x30DA,
  23012. pemiddlehookcyrillic: 0x04A7,
  23013. perafehebrew: 0xFB4E,
  23014. percent: 0x0025,
  23015. percentarabic: 0x066A,
  23016. percentmonospace: 0xFF05,
  23017. percentsmall: 0xFE6A,
  23018. period: 0x002E,
  23019. periodarmenian: 0x0589,
  23020. periodcentered: 0x00B7,
  23021. periodhalfwidth: 0xFF61,
  23022. periodinferior: 0xF6E7,
  23023. periodmonospace: 0xFF0E,
  23024. periodsmall: 0xFE52,
  23025. periodsuperior: 0xF6E8,
  23026. perispomenigreekcmb: 0x0342,
  23027. perpendicular: 0x22A5,
  23028. perthousand: 0x2030,
  23029. peseta: 0x20A7,
  23030. pfsquare: 0x338A,
  23031. phabengali: 0x09AB,
  23032. phadeva: 0x092B,
  23033. phagujarati: 0x0AAB,
  23034. phagurmukhi: 0x0A2B,
  23035. phi: 0x03C6,
  23036. phi1: 0x03D5,
  23037. phieuphacirclekorean: 0x327A,
  23038. phieuphaparenkorean: 0x321A,
  23039. phieuphcirclekorean: 0x326C,
  23040. phieuphkorean: 0x314D,
  23041. phieuphparenkorean: 0x320C,
  23042. philatin: 0x0278,
  23043. phinthuthai: 0x0E3A,
  23044. phisymbolgreek: 0x03D5,
  23045. phook: 0x01A5,
  23046. phophanthai: 0x0E1E,
  23047. phophungthai: 0x0E1C,
  23048. phosamphaothai: 0x0E20,
  23049. pi: 0x03C0,
  23050. pieupacirclekorean: 0x3273,
  23051. pieupaparenkorean: 0x3213,
  23052. pieupcieuckorean: 0x3176,
  23053. pieupcirclekorean: 0x3265,
  23054. pieupkiyeokkorean: 0x3172,
  23055. pieupkorean: 0x3142,
  23056. pieupparenkorean: 0x3205,
  23057. pieupsioskiyeokkorean: 0x3174,
  23058. pieupsioskorean: 0x3144,
  23059. pieupsiostikeutkorean: 0x3175,
  23060. pieupthieuthkorean: 0x3177,
  23061. pieuptikeutkorean: 0x3173,
  23062. pihiragana: 0x3074,
  23063. pikatakana: 0x30D4,
  23064. pisymbolgreek: 0x03D6,
  23065. piwrarmenian: 0x0583,
  23066. plus: 0x002B,
  23067. plusbelowcmb: 0x031F,
  23068. pluscircle: 0x2295,
  23069. plusminus: 0x00B1,
  23070. plusmod: 0x02D6,
  23071. plusmonospace: 0xFF0B,
  23072. plussmall: 0xFE62,
  23073. plussuperior: 0x207A,
  23074. pmonospace: 0xFF50,
  23075. pmsquare: 0x33D8,
  23076. pohiragana: 0x307D,
  23077. pointingindexdownwhite: 0x261F,
  23078. pointingindexleftwhite: 0x261C,
  23079. pointingindexrightwhite: 0x261E,
  23080. pointingindexupwhite: 0x261D,
  23081. pokatakana: 0x30DD,
  23082. poplathai: 0x0E1B,
  23083. postalmark: 0x3012,
  23084. postalmarkface: 0x3020,
  23085. pparen: 0x24AB,
  23086. precedes: 0x227A,
  23087. prescription: 0x211E,
  23088. primemod: 0x02B9,
  23089. primereversed: 0x2035,
  23090. product: 0x220F,
  23091. projective: 0x2305,
  23092. prolongedkana: 0x30FC,
  23093. propellor: 0x2318,
  23094. propersubset: 0x2282,
  23095. propersuperset: 0x2283,
  23096. proportion: 0x2237,
  23097. proportional: 0x221D,
  23098. psi: 0x03C8,
  23099. psicyrillic: 0x0471,
  23100. psilipneumatacyrilliccmb: 0x0486,
  23101. pssquare: 0x33B0,
  23102. puhiragana: 0x3077,
  23103. pukatakana: 0x30D7,
  23104. pvsquare: 0x33B4,
  23105. pwsquare: 0x33BA,
  23106. q: 0x0071,
  23107. qadeva: 0x0958,
  23108. qadmahebrew: 0x05A8,
  23109. qafarabic: 0x0642,
  23110. qaffinalarabic: 0xFED6,
  23111. qafinitialarabic: 0xFED7,
  23112. qafmedialarabic: 0xFED8,
  23113. qamats: 0x05B8,
  23114. qamats10: 0x05B8,
  23115. qamats1a: 0x05B8,
  23116. qamats1c: 0x05B8,
  23117. qamats27: 0x05B8,
  23118. qamats29: 0x05B8,
  23119. qamats33: 0x05B8,
  23120. qamatsde: 0x05B8,
  23121. qamatshebrew: 0x05B8,
  23122. qamatsnarrowhebrew: 0x05B8,
  23123. qamatsqatanhebrew: 0x05B8,
  23124. qamatsqatannarrowhebrew: 0x05B8,
  23125. qamatsqatanquarterhebrew: 0x05B8,
  23126. qamatsqatanwidehebrew: 0x05B8,
  23127. qamatsquarterhebrew: 0x05B8,
  23128. qamatswidehebrew: 0x05B8,
  23129. qarneyparahebrew: 0x059F,
  23130. qbopomofo: 0x3111,
  23131. qcircle: 0x24E0,
  23132. qhook: 0x02A0,
  23133. qmonospace: 0xFF51,
  23134. qof: 0x05E7,
  23135. qofdagesh: 0xFB47,
  23136. qofdageshhebrew: 0xFB47,
  23137. qofhebrew: 0x05E7,
  23138. qparen: 0x24AC,
  23139. quarternote: 0x2669,
  23140. qubuts: 0x05BB,
  23141. qubuts18: 0x05BB,
  23142. qubuts25: 0x05BB,
  23143. qubuts31: 0x05BB,
  23144. qubutshebrew: 0x05BB,
  23145. qubutsnarrowhebrew: 0x05BB,
  23146. qubutsquarterhebrew: 0x05BB,
  23147. qubutswidehebrew: 0x05BB,
  23148. question: 0x003F,
  23149. questionarabic: 0x061F,
  23150. questionarmenian: 0x055E,
  23151. questiondown: 0x00BF,
  23152. questiondownsmall: 0xF7BF,
  23153. questiongreek: 0x037E,
  23154. questionmonospace: 0xFF1F,
  23155. questionsmall: 0xF73F,
  23156. quotedbl: 0x0022,
  23157. quotedblbase: 0x201E,
  23158. quotedblleft: 0x201C,
  23159. quotedblmonospace: 0xFF02,
  23160. quotedblprime: 0x301E,
  23161. quotedblprimereversed: 0x301D,
  23162. quotedblright: 0x201D,
  23163. quoteleft: 0x2018,
  23164. quoteleftreversed: 0x201B,
  23165. quotereversed: 0x201B,
  23166. quoteright: 0x2019,
  23167. quoterightn: 0x0149,
  23168. quotesinglbase: 0x201A,
  23169. quotesingle: 0x0027,
  23170. quotesinglemonospace: 0xFF07,
  23171. r: 0x0072,
  23172. raarmenian: 0x057C,
  23173. rabengali: 0x09B0,
  23174. racute: 0x0155,
  23175. radeva: 0x0930,
  23176. radical: 0x221A,
  23177. radicalex: 0xF8E5,
  23178. radoverssquare: 0x33AE,
  23179. radoverssquaredsquare: 0x33AF,
  23180. radsquare: 0x33AD,
  23181. rafe: 0x05BF,
  23182. rafehebrew: 0x05BF,
  23183. ragujarati: 0x0AB0,
  23184. ragurmukhi: 0x0A30,
  23185. rahiragana: 0x3089,
  23186. rakatakana: 0x30E9,
  23187. rakatakanahalfwidth: 0xFF97,
  23188. ralowerdiagonalbengali: 0x09F1,
  23189. ramiddlediagonalbengali: 0x09F0,
  23190. ramshorn: 0x0264,
  23191. ratio: 0x2236,
  23192. rbopomofo: 0x3116,
  23193. rcaron: 0x0159,
  23194. rcedilla: 0x0157,
  23195. rcircle: 0x24E1,
  23196. rcommaaccent: 0x0157,
  23197. rdblgrave: 0x0211,
  23198. rdotaccent: 0x1E59,
  23199. rdotbelow: 0x1E5B,
  23200. rdotbelowmacron: 0x1E5D,
  23201. referencemark: 0x203B,
  23202. reflexsubset: 0x2286,
  23203. reflexsuperset: 0x2287,
  23204. registered: 0x00AE,
  23205. registersans: 0xF8E8,
  23206. registerserif: 0xF6DA,
  23207. reharabic: 0x0631,
  23208. reharmenian: 0x0580,
  23209. rehfinalarabic: 0xFEAE,
  23210. rehiragana: 0x308C,
  23211. rekatakana: 0x30EC,
  23212. rekatakanahalfwidth: 0xFF9A,
  23213. resh: 0x05E8,
  23214. reshdageshhebrew: 0xFB48,
  23215. reshhebrew: 0x05E8,
  23216. reversedtilde: 0x223D,
  23217. reviahebrew: 0x0597,
  23218. reviamugrashhebrew: 0x0597,
  23219. revlogicalnot: 0x2310,
  23220. rfishhook: 0x027E,
  23221. rfishhookreversed: 0x027F,
  23222. rhabengali: 0x09DD,
  23223. rhadeva: 0x095D,
  23224. rho: 0x03C1,
  23225. rhook: 0x027D,
  23226. rhookturned: 0x027B,
  23227. rhookturnedsuperior: 0x02B5,
  23228. rhosymbolgreek: 0x03F1,
  23229. rhotichookmod: 0x02DE,
  23230. rieulacirclekorean: 0x3271,
  23231. rieulaparenkorean: 0x3211,
  23232. rieulcirclekorean: 0x3263,
  23233. rieulhieuhkorean: 0x3140,
  23234. rieulkiyeokkorean: 0x313A,
  23235. rieulkiyeoksioskorean: 0x3169,
  23236. rieulkorean: 0x3139,
  23237. rieulmieumkorean: 0x313B,
  23238. rieulpansioskorean: 0x316C,
  23239. rieulparenkorean: 0x3203,
  23240. rieulphieuphkorean: 0x313F,
  23241. rieulpieupkorean: 0x313C,
  23242. rieulpieupsioskorean: 0x316B,
  23243. rieulsioskorean: 0x313D,
  23244. rieulthieuthkorean: 0x313E,
  23245. rieultikeutkorean: 0x316A,
  23246. rieulyeorinhieuhkorean: 0x316D,
  23247. rightangle: 0x221F,
  23248. righttackbelowcmb: 0x0319,
  23249. righttriangle: 0x22BF,
  23250. rihiragana: 0x308A,
  23251. rikatakana: 0x30EA,
  23252. rikatakanahalfwidth: 0xFF98,
  23253. ring: 0x02DA,
  23254. ringbelowcmb: 0x0325,
  23255. ringcmb: 0x030A,
  23256. ringhalfleft: 0x02BF,
  23257. ringhalfleftarmenian: 0x0559,
  23258. ringhalfleftbelowcmb: 0x031C,
  23259. ringhalfleftcentered: 0x02D3,
  23260. ringhalfright: 0x02BE,
  23261. ringhalfrightbelowcmb: 0x0339,
  23262. ringhalfrightcentered: 0x02D2,
  23263. rinvertedbreve: 0x0213,
  23264. rittorusquare: 0x3351,
  23265. rlinebelow: 0x1E5F,
  23266. rlongleg: 0x027C,
  23267. rlonglegturned: 0x027A,
  23268. rmonospace: 0xFF52,
  23269. rohiragana: 0x308D,
  23270. rokatakana: 0x30ED,
  23271. rokatakanahalfwidth: 0xFF9B,
  23272. roruathai: 0x0E23,
  23273. rparen: 0x24AD,
  23274. rrabengali: 0x09DC,
  23275. rradeva: 0x0931,
  23276. rragurmukhi: 0x0A5C,
  23277. rreharabic: 0x0691,
  23278. rrehfinalarabic: 0xFB8D,
  23279. rrvocalicbengali: 0x09E0,
  23280. rrvocalicdeva: 0x0960,
  23281. rrvocalicgujarati: 0x0AE0,
  23282. rrvocalicvowelsignbengali: 0x09C4,
  23283. rrvocalicvowelsigndeva: 0x0944,
  23284. rrvocalicvowelsigngujarati: 0x0AC4,
  23285. rsuperior: 0xF6F1,
  23286. rtblock: 0x2590,
  23287. rturned: 0x0279,
  23288. rturnedsuperior: 0x02B4,
  23289. ruhiragana: 0x308B,
  23290. rukatakana: 0x30EB,
  23291. rukatakanahalfwidth: 0xFF99,
  23292. rupeemarkbengali: 0x09F2,
  23293. rupeesignbengali: 0x09F3,
  23294. rupiah: 0xF6DD,
  23295. ruthai: 0x0E24,
  23296. rvocalicbengali: 0x098B,
  23297. rvocalicdeva: 0x090B,
  23298. rvocalicgujarati: 0x0A8B,
  23299. rvocalicvowelsignbengali: 0x09C3,
  23300. rvocalicvowelsigndeva: 0x0943,
  23301. rvocalicvowelsigngujarati: 0x0AC3,
  23302. s: 0x0073,
  23303. sabengali: 0x09B8,
  23304. sacute: 0x015B,
  23305. sacutedotaccent: 0x1E65,
  23306. sadarabic: 0x0635,
  23307. sadeva: 0x0938,
  23308. sadfinalarabic: 0xFEBA,
  23309. sadinitialarabic: 0xFEBB,
  23310. sadmedialarabic: 0xFEBC,
  23311. sagujarati: 0x0AB8,
  23312. sagurmukhi: 0x0A38,
  23313. sahiragana: 0x3055,
  23314. sakatakana: 0x30B5,
  23315. sakatakanahalfwidth: 0xFF7B,
  23316. sallallahoualayhewasallamarabic: 0xFDFA,
  23317. samekh: 0x05E1,
  23318. samekhdagesh: 0xFB41,
  23319. samekhdageshhebrew: 0xFB41,
  23320. samekhhebrew: 0x05E1,
  23321. saraaathai: 0x0E32,
  23322. saraaethai: 0x0E41,
  23323. saraaimaimalaithai: 0x0E44,
  23324. saraaimaimuanthai: 0x0E43,
  23325. saraamthai: 0x0E33,
  23326. saraathai: 0x0E30,
  23327. saraethai: 0x0E40,
  23328. saraiileftthai: 0xF886,
  23329. saraiithai: 0x0E35,
  23330. saraileftthai: 0xF885,
  23331. saraithai: 0x0E34,
  23332. saraothai: 0x0E42,
  23333. saraueeleftthai: 0xF888,
  23334. saraueethai: 0x0E37,
  23335. saraueleftthai: 0xF887,
  23336. sarauethai: 0x0E36,
  23337. sarauthai: 0x0E38,
  23338. sarauuthai: 0x0E39,
  23339. sbopomofo: 0x3119,
  23340. scaron: 0x0161,
  23341. scarondotaccent: 0x1E67,
  23342. scedilla: 0x015F,
  23343. schwa: 0x0259,
  23344. schwacyrillic: 0x04D9,
  23345. schwadieresiscyrillic: 0x04DB,
  23346. schwahook: 0x025A,
  23347. scircle: 0x24E2,
  23348. scircumflex: 0x015D,
  23349. scommaaccent: 0x0219,
  23350. sdotaccent: 0x1E61,
  23351. sdotbelow: 0x1E63,
  23352. sdotbelowdotaccent: 0x1E69,
  23353. seagullbelowcmb: 0x033C,
  23354. second: 0x2033,
  23355. secondtonechinese: 0x02CA,
  23356. section: 0x00A7,
  23357. seenarabic: 0x0633,
  23358. seenfinalarabic: 0xFEB2,
  23359. seeninitialarabic: 0xFEB3,
  23360. seenmedialarabic: 0xFEB4,
  23361. segol: 0x05B6,
  23362. segol13: 0x05B6,
  23363. segol1f: 0x05B6,
  23364. segol2c: 0x05B6,
  23365. segolhebrew: 0x05B6,
  23366. segolnarrowhebrew: 0x05B6,
  23367. segolquarterhebrew: 0x05B6,
  23368. segoltahebrew: 0x0592,
  23369. segolwidehebrew: 0x05B6,
  23370. seharmenian: 0x057D,
  23371. sehiragana: 0x305B,
  23372. sekatakana: 0x30BB,
  23373. sekatakanahalfwidth: 0xFF7E,
  23374. semicolon: 0x003B,
  23375. semicolonarabic: 0x061B,
  23376. semicolonmonospace: 0xFF1B,
  23377. semicolonsmall: 0xFE54,
  23378. semivoicedmarkkana: 0x309C,
  23379. semivoicedmarkkanahalfwidth: 0xFF9F,
  23380. sentisquare: 0x3322,
  23381. sentosquare: 0x3323,
  23382. seven: 0x0037,
  23383. sevenarabic: 0x0667,
  23384. sevenbengali: 0x09ED,
  23385. sevencircle: 0x2466,
  23386. sevencircleinversesansserif: 0x2790,
  23387. sevendeva: 0x096D,
  23388. seveneighths: 0x215E,
  23389. sevengujarati: 0x0AED,
  23390. sevengurmukhi: 0x0A6D,
  23391. sevenhackarabic: 0x0667,
  23392. sevenhangzhou: 0x3027,
  23393. sevenideographicparen: 0x3226,
  23394. seveninferior: 0x2087,
  23395. sevenmonospace: 0xFF17,
  23396. sevenoldstyle: 0xF737,
  23397. sevenparen: 0x247A,
  23398. sevenperiod: 0x248E,
  23399. sevenpersian: 0x06F7,
  23400. sevenroman: 0x2176,
  23401. sevensuperior: 0x2077,
  23402. seventeencircle: 0x2470,
  23403. seventeenparen: 0x2484,
  23404. seventeenperiod: 0x2498,
  23405. seventhai: 0x0E57,
  23406. sfthyphen: 0x00AD,
  23407. shaarmenian: 0x0577,
  23408. shabengali: 0x09B6,
  23409. shacyrillic: 0x0448,
  23410. shaddaarabic: 0x0651,
  23411. shaddadammaarabic: 0xFC61,
  23412. shaddadammatanarabic: 0xFC5E,
  23413. shaddafathaarabic: 0xFC60,
  23414. shaddakasraarabic: 0xFC62,
  23415. shaddakasratanarabic: 0xFC5F,
  23416. shade: 0x2592,
  23417. shadedark: 0x2593,
  23418. shadelight: 0x2591,
  23419. shademedium: 0x2592,
  23420. shadeva: 0x0936,
  23421. shagujarati: 0x0AB6,
  23422. shagurmukhi: 0x0A36,
  23423. shalshelethebrew: 0x0593,
  23424. shbopomofo: 0x3115,
  23425. shchacyrillic: 0x0449,
  23426. sheenarabic: 0x0634,
  23427. sheenfinalarabic: 0xFEB6,
  23428. sheeninitialarabic: 0xFEB7,
  23429. sheenmedialarabic: 0xFEB8,
  23430. sheicoptic: 0x03E3,
  23431. sheqel: 0x20AA,
  23432. sheqelhebrew: 0x20AA,
  23433. sheva: 0x05B0,
  23434. sheva115: 0x05B0,
  23435. sheva15: 0x05B0,
  23436. sheva22: 0x05B0,
  23437. sheva2e: 0x05B0,
  23438. shevahebrew: 0x05B0,
  23439. shevanarrowhebrew: 0x05B0,
  23440. shevaquarterhebrew: 0x05B0,
  23441. shevawidehebrew: 0x05B0,
  23442. shhacyrillic: 0x04BB,
  23443. shimacoptic: 0x03ED,
  23444. shin: 0x05E9,
  23445. shindagesh: 0xFB49,
  23446. shindageshhebrew: 0xFB49,
  23447. shindageshshindot: 0xFB2C,
  23448. shindageshshindothebrew: 0xFB2C,
  23449. shindageshsindot: 0xFB2D,
  23450. shindageshsindothebrew: 0xFB2D,
  23451. shindothebrew: 0x05C1,
  23452. shinhebrew: 0x05E9,
  23453. shinshindot: 0xFB2A,
  23454. shinshindothebrew: 0xFB2A,
  23455. shinsindot: 0xFB2B,
  23456. shinsindothebrew: 0xFB2B,
  23457. shook: 0x0282,
  23458. sigma: 0x03C3,
  23459. sigma1: 0x03C2,
  23460. sigmafinal: 0x03C2,
  23461. sigmalunatesymbolgreek: 0x03F2,
  23462. sihiragana: 0x3057,
  23463. sikatakana: 0x30B7,
  23464. sikatakanahalfwidth: 0xFF7C,
  23465. siluqhebrew: 0x05BD,
  23466. siluqlefthebrew: 0x05BD,
  23467. similar: 0x223C,
  23468. sindothebrew: 0x05C2,
  23469. siosacirclekorean: 0x3274,
  23470. siosaparenkorean: 0x3214,
  23471. sioscieuckorean: 0x317E,
  23472. sioscirclekorean: 0x3266,
  23473. sioskiyeokkorean: 0x317A,
  23474. sioskorean: 0x3145,
  23475. siosnieunkorean: 0x317B,
  23476. siosparenkorean: 0x3206,
  23477. siospieupkorean: 0x317D,
  23478. siostikeutkorean: 0x317C,
  23479. six: 0x0036,
  23480. sixarabic: 0x0666,
  23481. sixbengali: 0x09EC,
  23482. sixcircle: 0x2465,
  23483. sixcircleinversesansserif: 0x278F,
  23484. sixdeva: 0x096C,
  23485. sixgujarati: 0x0AEC,
  23486. sixgurmukhi: 0x0A6C,
  23487. sixhackarabic: 0x0666,
  23488. sixhangzhou: 0x3026,
  23489. sixideographicparen: 0x3225,
  23490. sixinferior: 0x2086,
  23491. sixmonospace: 0xFF16,
  23492. sixoldstyle: 0xF736,
  23493. sixparen: 0x2479,
  23494. sixperiod: 0x248D,
  23495. sixpersian: 0x06F6,
  23496. sixroman: 0x2175,
  23497. sixsuperior: 0x2076,
  23498. sixteencircle: 0x246F,
  23499. sixteencurrencydenominatorbengali: 0x09F9,
  23500. sixteenparen: 0x2483,
  23501. sixteenperiod: 0x2497,
  23502. sixthai: 0x0E56,
  23503. slash: 0x002F,
  23504. slashmonospace: 0xFF0F,
  23505. slong: 0x017F,
  23506. slongdotaccent: 0x1E9B,
  23507. smileface: 0x263A,
  23508. smonospace: 0xFF53,
  23509. sofpasuqhebrew: 0x05C3,
  23510. softhyphen: 0x00AD,
  23511. softsigncyrillic: 0x044C,
  23512. sohiragana: 0x305D,
  23513. sokatakana: 0x30BD,
  23514. sokatakanahalfwidth: 0xFF7F,
  23515. soliduslongoverlaycmb: 0x0338,
  23516. solidusshortoverlaycmb: 0x0337,
  23517. sorusithai: 0x0E29,
  23518. sosalathai: 0x0E28,
  23519. sosothai: 0x0E0B,
  23520. sosuathai: 0x0E2A,
  23521. space: 0x0020,
  23522. spacehackarabic: 0x0020,
  23523. spade: 0x2660,
  23524. spadesuitblack: 0x2660,
  23525. spadesuitwhite: 0x2664,
  23526. sparen: 0x24AE,
  23527. squarebelowcmb: 0x033B,
  23528. squarecc: 0x33C4,
  23529. squarecm: 0x339D,
  23530. squarediagonalcrosshatchfill: 0x25A9,
  23531. squarehorizontalfill: 0x25A4,
  23532. squarekg: 0x338F,
  23533. squarekm: 0x339E,
  23534. squarekmcapital: 0x33CE,
  23535. squareln: 0x33D1,
  23536. squarelog: 0x33D2,
  23537. squaremg: 0x338E,
  23538. squaremil: 0x33D5,
  23539. squaremm: 0x339C,
  23540. squaremsquared: 0x33A1,
  23541. squareorthogonalcrosshatchfill: 0x25A6,
  23542. squareupperlefttolowerrightfill: 0x25A7,
  23543. squareupperrighttolowerleftfill: 0x25A8,
  23544. squareverticalfill: 0x25A5,
  23545. squarewhitewithsmallblack: 0x25A3,
  23546. srsquare: 0x33DB,
  23547. ssabengali: 0x09B7,
  23548. ssadeva: 0x0937,
  23549. ssagujarati: 0x0AB7,
  23550. ssangcieuckorean: 0x3149,
  23551. ssanghieuhkorean: 0x3185,
  23552. ssangieungkorean: 0x3180,
  23553. ssangkiyeokkorean: 0x3132,
  23554. ssangnieunkorean: 0x3165,
  23555. ssangpieupkorean: 0x3143,
  23556. ssangsioskorean: 0x3146,
  23557. ssangtikeutkorean: 0x3138,
  23558. ssuperior: 0xF6F2,
  23559. sterling: 0x00A3,
  23560. sterlingmonospace: 0xFFE1,
  23561. strokelongoverlaycmb: 0x0336,
  23562. strokeshortoverlaycmb: 0x0335,
  23563. subset: 0x2282,
  23564. subsetnotequal: 0x228A,
  23565. subsetorequal: 0x2286,
  23566. succeeds: 0x227B,
  23567. suchthat: 0x220B,
  23568. suhiragana: 0x3059,
  23569. sukatakana: 0x30B9,
  23570. sukatakanahalfwidth: 0xFF7D,
  23571. sukunarabic: 0x0652,
  23572. summation: 0x2211,
  23573. sun: 0x263C,
  23574. superset: 0x2283,
  23575. supersetnotequal: 0x228B,
  23576. supersetorequal: 0x2287,
  23577. svsquare: 0x33DC,
  23578. syouwaerasquare: 0x337C,
  23579. t: 0x0074,
  23580. tabengali: 0x09A4,
  23581. tackdown: 0x22A4,
  23582. tackleft: 0x22A3,
  23583. tadeva: 0x0924,
  23584. tagujarati: 0x0AA4,
  23585. tagurmukhi: 0x0A24,
  23586. taharabic: 0x0637,
  23587. tahfinalarabic: 0xFEC2,
  23588. tahinitialarabic: 0xFEC3,
  23589. tahiragana: 0x305F,
  23590. tahmedialarabic: 0xFEC4,
  23591. taisyouerasquare: 0x337D,
  23592. takatakana: 0x30BF,
  23593. takatakanahalfwidth: 0xFF80,
  23594. tatweelarabic: 0x0640,
  23595. tau: 0x03C4,
  23596. tav: 0x05EA,
  23597. tavdages: 0xFB4A,
  23598. tavdagesh: 0xFB4A,
  23599. tavdageshhebrew: 0xFB4A,
  23600. tavhebrew: 0x05EA,
  23601. tbar: 0x0167,
  23602. tbopomofo: 0x310A,
  23603. tcaron: 0x0165,
  23604. tccurl: 0x02A8,
  23605. tcedilla: 0x0163,
  23606. tcheharabic: 0x0686,
  23607. tchehfinalarabic: 0xFB7B,
  23608. tchehinitialarabic: 0xFB7C,
  23609. tchehmedialarabic: 0xFB7D,
  23610. tcircle: 0x24E3,
  23611. tcircumflexbelow: 0x1E71,
  23612. tcommaaccent: 0x0163,
  23613. tdieresis: 0x1E97,
  23614. tdotaccent: 0x1E6B,
  23615. tdotbelow: 0x1E6D,
  23616. tecyrillic: 0x0442,
  23617. tedescendercyrillic: 0x04AD,
  23618. teharabic: 0x062A,
  23619. tehfinalarabic: 0xFE96,
  23620. tehhahinitialarabic: 0xFCA2,
  23621. tehhahisolatedarabic: 0xFC0C,
  23622. tehinitialarabic: 0xFE97,
  23623. tehiragana: 0x3066,
  23624. tehjeeminitialarabic: 0xFCA1,
  23625. tehjeemisolatedarabic: 0xFC0B,
  23626. tehmarbutaarabic: 0x0629,
  23627. tehmarbutafinalarabic: 0xFE94,
  23628. tehmedialarabic: 0xFE98,
  23629. tehmeeminitialarabic: 0xFCA4,
  23630. tehmeemisolatedarabic: 0xFC0E,
  23631. tehnoonfinalarabic: 0xFC73,
  23632. tekatakana: 0x30C6,
  23633. tekatakanahalfwidth: 0xFF83,
  23634. telephone: 0x2121,
  23635. telephoneblack: 0x260E,
  23636. telishagedolahebrew: 0x05A0,
  23637. telishaqetanahebrew: 0x05A9,
  23638. tencircle: 0x2469,
  23639. tenideographicparen: 0x3229,
  23640. tenparen: 0x247D,
  23641. tenperiod: 0x2491,
  23642. tenroman: 0x2179,
  23643. tesh: 0x02A7,
  23644. tet: 0x05D8,
  23645. tetdagesh: 0xFB38,
  23646. tetdageshhebrew: 0xFB38,
  23647. tethebrew: 0x05D8,
  23648. tetsecyrillic: 0x04B5,
  23649. tevirhebrew: 0x059B,
  23650. tevirlefthebrew: 0x059B,
  23651. thabengali: 0x09A5,
  23652. thadeva: 0x0925,
  23653. thagujarati: 0x0AA5,
  23654. thagurmukhi: 0x0A25,
  23655. thalarabic: 0x0630,
  23656. thalfinalarabic: 0xFEAC,
  23657. thanthakhatlowleftthai: 0xF898,
  23658. thanthakhatlowrightthai: 0xF897,
  23659. thanthakhatthai: 0x0E4C,
  23660. thanthakhatupperleftthai: 0xF896,
  23661. theharabic: 0x062B,
  23662. thehfinalarabic: 0xFE9A,
  23663. thehinitialarabic: 0xFE9B,
  23664. thehmedialarabic: 0xFE9C,
  23665. thereexists: 0x2203,
  23666. therefore: 0x2234,
  23667. theta: 0x03B8,
  23668. theta1: 0x03D1,
  23669. thetasymbolgreek: 0x03D1,
  23670. thieuthacirclekorean: 0x3279,
  23671. thieuthaparenkorean: 0x3219,
  23672. thieuthcirclekorean: 0x326B,
  23673. thieuthkorean: 0x314C,
  23674. thieuthparenkorean: 0x320B,
  23675. thirteencircle: 0x246C,
  23676. thirteenparen: 0x2480,
  23677. thirteenperiod: 0x2494,
  23678. thonangmonthothai: 0x0E11,
  23679. thook: 0x01AD,
  23680. thophuthaothai: 0x0E12,
  23681. thorn: 0x00FE,
  23682. thothahanthai: 0x0E17,
  23683. thothanthai: 0x0E10,
  23684. thothongthai: 0x0E18,
  23685. thothungthai: 0x0E16,
  23686. thousandcyrillic: 0x0482,
  23687. thousandsseparatorarabic: 0x066C,
  23688. thousandsseparatorpersian: 0x066C,
  23689. three: 0x0033,
  23690. threearabic: 0x0663,
  23691. threebengali: 0x09E9,
  23692. threecircle: 0x2462,
  23693. threecircleinversesansserif: 0x278C,
  23694. threedeva: 0x0969,
  23695. threeeighths: 0x215C,
  23696. threegujarati: 0x0AE9,
  23697. threegurmukhi: 0x0A69,
  23698. threehackarabic: 0x0663,
  23699. threehangzhou: 0x3023,
  23700. threeideographicparen: 0x3222,
  23701. threeinferior: 0x2083,
  23702. threemonospace: 0xFF13,
  23703. threenumeratorbengali: 0x09F6,
  23704. threeoldstyle: 0xF733,
  23705. threeparen: 0x2476,
  23706. threeperiod: 0x248A,
  23707. threepersian: 0x06F3,
  23708. threequarters: 0x00BE,
  23709. threequartersemdash: 0xF6DE,
  23710. threeroman: 0x2172,
  23711. threesuperior: 0x00B3,
  23712. threethai: 0x0E53,
  23713. thzsquare: 0x3394,
  23714. tihiragana: 0x3061,
  23715. tikatakana: 0x30C1,
  23716. tikatakanahalfwidth: 0xFF81,
  23717. tikeutacirclekorean: 0x3270,
  23718. tikeutaparenkorean: 0x3210,
  23719. tikeutcirclekorean: 0x3262,
  23720. tikeutkorean: 0x3137,
  23721. tikeutparenkorean: 0x3202,
  23722. tilde: 0x02DC,
  23723. tildebelowcmb: 0x0330,
  23724. tildecmb: 0x0303,
  23725. tildecomb: 0x0303,
  23726. tildedoublecmb: 0x0360,
  23727. tildeoperator: 0x223C,
  23728. tildeoverlaycmb: 0x0334,
  23729. tildeverticalcmb: 0x033E,
  23730. timescircle: 0x2297,
  23731. tipehahebrew: 0x0596,
  23732. tipehalefthebrew: 0x0596,
  23733. tippigurmukhi: 0x0A70,
  23734. titlocyrilliccmb: 0x0483,
  23735. tiwnarmenian: 0x057F,
  23736. tlinebelow: 0x1E6F,
  23737. tmonospace: 0xFF54,
  23738. toarmenian: 0x0569,
  23739. tohiragana: 0x3068,
  23740. tokatakana: 0x30C8,
  23741. tokatakanahalfwidth: 0xFF84,
  23742. tonebarextrahighmod: 0x02E5,
  23743. tonebarextralowmod: 0x02E9,
  23744. tonebarhighmod: 0x02E6,
  23745. tonebarlowmod: 0x02E8,
  23746. tonebarmidmod: 0x02E7,
  23747. tonefive: 0x01BD,
  23748. tonesix: 0x0185,
  23749. tonetwo: 0x01A8,
  23750. tonos: 0x0384,
  23751. tonsquare: 0x3327,
  23752. topatakthai: 0x0E0F,
  23753. tortoiseshellbracketleft: 0x3014,
  23754. tortoiseshellbracketleftsmall: 0xFE5D,
  23755. tortoiseshellbracketleftvertical: 0xFE39,
  23756. tortoiseshellbracketright: 0x3015,
  23757. tortoiseshellbracketrightsmall: 0xFE5E,
  23758. tortoiseshellbracketrightvertical: 0xFE3A,
  23759. totaothai: 0x0E15,
  23760. tpalatalhook: 0x01AB,
  23761. tparen: 0x24AF,
  23762. trademark: 0x2122,
  23763. trademarksans: 0xF8EA,
  23764. trademarkserif: 0xF6DB,
  23765. tretroflexhook: 0x0288,
  23766. triagdn: 0x25BC,
  23767. triaglf: 0x25C4,
  23768. triagrt: 0x25BA,
  23769. triagup: 0x25B2,
  23770. ts: 0x02A6,
  23771. tsadi: 0x05E6,
  23772. tsadidagesh: 0xFB46,
  23773. tsadidageshhebrew: 0xFB46,
  23774. tsadihebrew: 0x05E6,
  23775. tsecyrillic: 0x0446,
  23776. tsere: 0x05B5,
  23777. tsere12: 0x05B5,
  23778. tsere1e: 0x05B5,
  23779. tsere2b: 0x05B5,
  23780. tserehebrew: 0x05B5,
  23781. tserenarrowhebrew: 0x05B5,
  23782. tserequarterhebrew: 0x05B5,
  23783. tserewidehebrew: 0x05B5,
  23784. tshecyrillic: 0x045B,
  23785. tsuperior: 0xF6F3,
  23786. ttabengali: 0x099F,
  23787. ttadeva: 0x091F,
  23788. ttagujarati: 0x0A9F,
  23789. ttagurmukhi: 0x0A1F,
  23790. tteharabic: 0x0679,
  23791. ttehfinalarabic: 0xFB67,
  23792. ttehinitialarabic: 0xFB68,
  23793. ttehmedialarabic: 0xFB69,
  23794. tthabengali: 0x09A0,
  23795. tthadeva: 0x0920,
  23796. tthagujarati: 0x0AA0,
  23797. tthagurmukhi: 0x0A20,
  23798. tturned: 0x0287,
  23799. tuhiragana: 0x3064,
  23800. tukatakana: 0x30C4,
  23801. tukatakanahalfwidth: 0xFF82,
  23802. tusmallhiragana: 0x3063,
  23803. tusmallkatakana: 0x30C3,
  23804. tusmallkatakanahalfwidth: 0xFF6F,
  23805. twelvecircle: 0x246B,
  23806. twelveparen: 0x247F,
  23807. twelveperiod: 0x2493,
  23808. twelveroman: 0x217B,
  23809. twentycircle: 0x2473,
  23810. twentyhangzhou: 0x5344,
  23811. twentyparen: 0x2487,
  23812. twentyperiod: 0x249B,
  23813. two: 0x0032,
  23814. twoarabic: 0x0662,
  23815. twobengali: 0x09E8,
  23816. twocircle: 0x2461,
  23817. twocircleinversesansserif: 0x278B,
  23818. twodeva: 0x0968,
  23819. twodotenleader: 0x2025,
  23820. twodotleader: 0x2025,
  23821. twodotleadervertical: 0xFE30,
  23822. twogujarati: 0x0AE8,
  23823. twogurmukhi: 0x0A68,
  23824. twohackarabic: 0x0662,
  23825. twohangzhou: 0x3022,
  23826. twoideographicparen: 0x3221,
  23827. twoinferior: 0x2082,
  23828. twomonospace: 0xFF12,
  23829. twonumeratorbengali: 0x09F5,
  23830. twooldstyle: 0xF732,
  23831. twoparen: 0x2475,
  23832. twoperiod: 0x2489,
  23833. twopersian: 0x06F2,
  23834. tworoman: 0x2171,
  23835. twostroke: 0x01BB,
  23836. twosuperior: 0x00B2,
  23837. twothai: 0x0E52,
  23838. twothirds: 0x2154,
  23839. u: 0x0075,
  23840. uacute: 0x00FA,
  23841. ubar: 0x0289,
  23842. ubengali: 0x0989,
  23843. ubopomofo: 0x3128,
  23844. ubreve: 0x016D,
  23845. ucaron: 0x01D4,
  23846. ucircle: 0x24E4,
  23847. ucircumflex: 0x00FB,
  23848. ucircumflexbelow: 0x1E77,
  23849. ucyrillic: 0x0443,
  23850. udattadeva: 0x0951,
  23851. udblacute: 0x0171,
  23852. udblgrave: 0x0215,
  23853. udeva: 0x0909,
  23854. udieresis: 0x00FC,
  23855. udieresisacute: 0x01D8,
  23856. udieresisbelow: 0x1E73,
  23857. udieresiscaron: 0x01DA,
  23858. udieresiscyrillic: 0x04F1,
  23859. udieresisgrave: 0x01DC,
  23860. udieresismacron: 0x01D6,
  23861. udotbelow: 0x1EE5,
  23862. ugrave: 0x00F9,
  23863. ugujarati: 0x0A89,
  23864. ugurmukhi: 0x0A09,
  23865. uhiragana: 0x3046,
  23866. uhookabove: 0x1EE7,
  23867. uhorn: 0x01B0,
  23868. uhornacute: 0x1EE9,
  23869. uhorndotbelow: 0x1EF1,
  23870. uhorngrave: 0x1EEB,
  23871. uhornhookabove: 0x1EED,
  23872. uhorntilde: 0x1EEF,
  23873. uhungarumlaut: 0x0171,
  23874. uhungarumlautcyrillic: 0x04F3,
  23875. uinvertedbreve: 0x0217,
  23876. ukatakana: 0x30A6,
  23877. ukatakanahalfwidth: 0xFF73,
  23878. ukcyrillic: 0x0479,
  23879. ukorean: 0x315C,
  23880. umacron: 0x016B,
  23881. umacroncyrillic: 0x04EF,
  23882. umacrondieresis: 0x1E7B,
  23883. umatragurmukhi: 0x0A41,
  23884. umonospace: 0xFF55,
  23885. underscore: 0x005F,
  23886. underscoredbl: 0x2017,
  23887. underscoremonospace: 0xFF3F,
  23888. underscorevertical: 0xFE33,
  23889. underscorewavy: 0xFE4F,
  23890. union: 0x222A,
  23891. universal: 0x2200,
  23892. uogonek: 0x0173,
  23893. uparen: 0x24B0,
  23894. upblock: 0x2580,
  23895. upperdothebrew: 0x05C4,
  23896. upsilon: 0x03C5,
  23897. upsilondieresis: 0x03CB,
  23898. upsilondieresistonos: 0x03B0,
  23899. upsilonlatin: 0x028A,
  23900. upsilontonos: 0x03CD,
  23901. uptackbelowcmb: 0x031D,
  23902. uptackmod: 0x02D4,
  23903. uragurmukhi: 0x0A73,
  23904. uring: 0x016F,
  23905. ushortcyrillic: 0x045E,
  23906. usmallhiragana: 0x3045,
  23907. usmallkatakana: 0x30A5,
  23908. usmallkatakanahalfwidth: 0xFF69,
  23909. ustraightcyrillic: 0x04AF,
  23910. ustraightstrokecyrillic: 0x04B1,
  23911. utilde: 0x0169,
  23912. utildeacute: 0x1E79,
  23913. utildebelow: 0x1E75,
  23914. uubengali: 0x098A,
  23915. uudeva: 0x090A,
  23916. uugujarati: 0x0A8A,
  23917. uugurmukhi: 0x0A0A,
  23918. uumatragurmukhi: 0x0A42,
  23919. uuvowelsignbengali: 0x09C2,
  23920. uuvowelsigndeva: 0x0942,
  23921. uuvowelsigngujarati: 0x0AC2,
  23922. uvowelsignbengali: 0x09C1,
  23923. uvowelsigndeva: 0x0941,
  23924. uvowelsigngujarati: 0x0AC1,
  23925. v: 0x0076,
  23926. vadeva: 0x0935,
  23927. vagujarati: 0x0AB5,
  23928. vagurmukhi: 0x0A35,
  23929. vakatakana: 0x30F7,
  23930. vav: 0x05D5,
  23931. vavdagesh: 0xFB35,
  23932. vavdagesh65: 0xFB35,
  23933. vavdageshhebrew: 0xFB35,
  23934. vavhebrew: 0x05D5,
  23935. vavholam: 0xFB4B,
  23936. vavholamhebrew: 0xFB4B,
  23937. vavvavhebrew: 0x05F0,
  23938. vavyodhebrew: 0x05F1,
  23939. vcircle: 0x24E5,
  23940. vdotbelow: 0x1E7F,
  23941. vecyrillic: 0x0432,
  23942. veharabic: 0x06A4,
  23943. vehfinalarabic: 0xFB6B,
  23944. vehinitialarabic: 0xFB6C,
  23945. vehmedialarabic: 0xFB6D,
  23946. vekatakana: 0x30F9,
  23947. venus: 0x2640,
  23948. verticalbar: 0x007C,
  23949. verticallineabovecmb: 0x030D,
  23950. verticallinebelowcmb: 0x0329,
  23951. verticallinelowmod: 0x02CC,
  23952. verticallinemod: 0x02C8,
  23953. vewarmenian: 0x057E,
  23954. vhook: 0x028B,
  23955. vikatakana: 0x30F8,
  23956. viramabengali: 0x09CD,
  23957. viramadeva: 0x094D,
  23958. viramagujarati: 0x0ACD,
  23959. visargabengali: 0x0983,
  23960. visargadeva: 0x0903,
  23961. visargagujarati: 0x0A83,
  23962. vmonospace: 0xFF56,
  23963. voarmenian: 0x0578,
  23964. voicediterationhiragana: 0x309E,
  23965. voicediterationkatakana: 0x30FE,
  23966. voicedmarkkana: 0x309B,
  23967. voicedmarkkanahalfwidth: 0xFF9E,
  23968. vokatakana: 0x30FA,
  23969. vparen: 0x24B1,
  23970. vtilde: 0x1E7D,
  23971. vturned: 0x028C,
  23972. vuhiragana: 0x3094,
  23973. vukatakana: 0x30F4,
  23974. w: 0x0077,
  23975. wacute: 0x1E83,
  23976. waekorean: 0x3159,
  23977. wahiragana: 0x308F,
  23978. wakatakana: 0x30EF,
  23979. wakatakanahalfwidth: 0xFF9C,
  23980. wakorean: 0x3158,
  23981. wasmallhiragana: 0x308E,
  23982. wasmallkatakana: 0x30EE,
  23983. wattosquare: 0x3357,
  23984. wavedash: 0x301C,
  23985. wavyunderscorevertical: 0xFE34,
  23986. wawarabic: 0x0648,
  23987. wawfinalarabic: 0xFEEE,
  23988. wawhamzaabovearabic: 0x0624,
  23989. wawhamzaabovefinalarabic: 0xFE86,
  23990. wbsquare: 0x33DD,
  23991. wcircle: 0x24E6,
  23992. wcircumflex: 0x0175,
  23993. wdieresis: 0x1E85,
  23994. wdotaccent: 0x1E87,
  23995. wdotbelow: 0x1E89,
  23996. wehiragana: 0x3091,
  23997. weierstrass: 0x2118,
  23998. wekatakana: 0x30F1,
  23999. wekorean: 0x315E,
  24000. weokorean: 0x315D,
  24001. wgrave: 0x1E81,
  24002. whitebullet: 0x25E6,
  24003. whitecircle: 0x25CB,
  24004. whitecircleinverse: 0x25D9,
  24005. whitecornerbracketleft: 0x300E,
  24006. whitecornerbracketleftvertical: 0xFE43,
  24007. whitecornerbracketright: 0x300F,
  24008. whitecornerbracketrightvertical: 0xFE44,
  24009. whitediamond: 0x25C7,
  24010. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24011. whitedownpointingsmalltriangle: 0x25BF,
  24012. whitedownpointingtriangle: 0x25BD,
  24013. whiteleftpointingsmalltriangle: 0x25C3,
  24014. whiteleftpointingtriangle: 0x25C1,
  24015. whitelenticularbracketleft: 0x3016,
  24016. whitelenticularbracketright: 0x3017,
  24017. whiterightpointingsmalltriangle: 0x25B9,
  24018. whiterightpointingtriangle: 0x25B7,
  24019. whitesmallsquare: 0x25AB,
  24020. whitesmilingface: 0x263A,
  24021. whitesquare: 0x25A1,
  24022. whitestar: 0x2606,
  24023. whitetelephone: 0x260F,
  24024. whitetortoiseshellbracketleft: 0x3018,
  24025. whitetortoiseshellbracketright: 0x3019,
  24026. whiteuppointingsmalltriangle: 0x25B5,
  24027. whiteuppointingtriangle: 0x25B3,
  24028. wihiragana: 0x3090,
  24029. wikatakana: 0x30F0,
  24030. wikorean: 0x315F,
  24031. wmonospace: 0xFF57,
  24032. wohiragana: 0x3092,
  24033. wokatakana: 0x30F2,
  24034. wokatakanahalfwidth: 0xFF66,
  24035. won: 0x20A9,
  24036. wonmonospace: 0xFFE6,
  24037. wowaenthai: 0x0E27,
  24038. wparen: 0x24B2,
  24039. wring: 0x1E98,
  24040. wsuperior: 0x02B7,
  24041. wturned: 0x028D,
  24042. wynn: 0x01BF,
  24043. x: 0x0078,
  24044. xabovecmb: 0x033D,
  24045. xbopomofo: 0x3112,
  24046. xcircle: 0x24E7,
  24047. xdieresis: 0x1E8D,
  24048. xdotaccent: 0x1E8B,
  24049. xeharmenian: 0x056D,
  24050. xi: 0x03BE,
  24051. xmonospace: 0xFF58,
  24052. xparen: 0x24B3,
  24053. xsuperior: 0x02E3,
  24054. y: 0x0079,
  24055. yaadosquare: 0x334E,
  24056. yabengali: 0x09AF,
  24057. yacute: 0x00FD,
  24058. yadeva: 0x092F,
  24059. yaekorean: 0x3152,
  24060. yagujarati: 0x0AAF,
  24061. yagurmukhi: 0x0A2F,
  24062. yahiragana: 0x3084,
  24063. yakatakana: 0x30E4,
  24064. yakatakanahalfwidth: 0xFF94,
  24065. yakorean: 0x3151,
  24066. yamakkanthai: 0x0E4E,
  24067. yasmallhiragana: 0x3083,
  24068. yasmallkatakana: 0x30E3,
  24069. yasmallkatakanahalfwidth: 0xFF6C,
  24070. yatcyrillic: 0x0463,
  24071. ycircle: 0x24E8,
  24072. ycircumflex: 0x0177,
  24073. ydieresis: 0x00FF,
  24074. ydotaccent: 0x1E8F,
  24075. ydotbelow: 0x1EF5,
  24076. yeharabic: 0x064A,
  24077. yehbarreearabic: 0x06D2,
  24078. yehbarreefinalarabic: 0xFBAF,
  24079. yehfinalarabic: 0xFEF2,
  24080. yehhamzaabovearabic: 0x0626,
  24081. yehhamzaabovefinalarabic: 0xFE8A,
  24082. yehhamzaaboveinitialarabic: 0xFE8B,
  24083. yehhamzaabovemedialarabic: 0xFE8C,
  24084. yehinitialarabic: 0xFEF3,
  24085. yehmedialarabic: 0xFEF4,
  24086. yehmeeminitialarabic: 0xFCDD,
  24087. yehmeemisolatedarabic: 0xFC58,
  24088. yehnoonfinalarabic: 0xFC94,
  24089. yehthreedotsbelowarabic: 0x06D1,
  24090. yekorean: 0x3156,
  24091. yen: 0x00A5,
  24092. yenmonospace: 0xFFE5,
  24093. yeokorean: 0x3155,
  24094. yeorinhieuhkorean: 0x3186,
  24095. yerahbenyomohebrew: 0x05AA,
  24096. yerahbenyomolefthebrew: 0x05AA,
  24097. yericyrillic: 0x044B,
  24098. yerudieresiscyrillic: 0x04F9,
  24099. yesieungkorean: 0x3181,
  24100. yesieungpansioskorean: 0x3183,
  24101. yesieungsioskorean: 0x3182,
  24102. yetivhebrew: 0x059A,
  24103. ygrave: 0x1EF3,
  24104. yhook: 0x01B4,
  24105. yhookabove: 0x1EF7,
  24106. yiarmenian: 0x0575,
  24107. yicyrillic: 0x0457,
  24108. yikorean: 0x3162,
  24109. yinyang: 0x262F,
  24110. yiwnarmenian: 0x0582,
  24111. ymonospace: 0xFF59,
  24112. yod: 0x05D9,
  24113. yoddagesh: 0xFB39,
  24114. yoddageshhebrew: 0xFB39,
  24115. yodhebrew: 0x05D9,
  24116. yodyodhebrew: 0x05F2,
  24117. yodyodpatahhebrew: 0xFB1F,
  24118. yohiragana: 0x3088,
  24119. yoikorean: 0x3189,
  24120. yokatakana: 0x30E8,
  24121. yokatakanahalfwidth: 0xFF96,
  24122. yokorean: 0x315B,
  24123. yosmallhiragana: 0x3087,
  24124. yosmallkatakana: 0x30E7,
  24125. yosmallkatakanahalfwidth: 0xFF6E,
  24126. yotgreek: 0x03F3,
  24127. yoyaekorean: 0x3188,
  24128. yoyakorean: 0x3187,
  24129. yoyakthai: 0x0E22,
  24130. yoyingthai: 0x0E0D,
  24131. yparen: 0x24B4,
  24132. ypogegrammeni: 0x037A,
  24133. ypogegrammenigreekcmb: 0x0345,
  24134. yr: 0x01A6,
  24135. yring: 0x1E99,
  24136. ysuperior: 0x02B8,
  24137. ytilde: 0x1EF9,
  24138. yturned: 0x028E,
  24139. yuhiragana: 0x3086,
  24140. yuikorean: 0x318C,
  24141. yukatakana: 0x30E6,
  24142. yukatakanahalfwidth: 0xFF95,
  24143. yukorean: 0x3160,
  24144. yusbigcyrillic: 0x046B,
  24145. yusbigiotifiedcyrillic: 0x046D,
  24146. yuslittlecyrillic: 0x0467,
  24147. yuslittleiotifiedcyrillic: 0x0469,
  24148. yusmallhiragana: 0x3085,
  24149. yusmallkatakana: 0x30E5,
  24150. yusmallkatakanahalfwidth: 0xFF6D,
  24151. yuyekorean: 0x318B,
  24152. yuyeokorean: 0x318A,
  24153. yyabengali: 0x09DF,
  24154. yyadeva: 0x095F,
  24155. z: 0x007A,
  24156. zaarmenian: 0x0566,
  24157. zacute: 0x017A,
  24158. zadeva: 0x095B,
  24159. zagurmukhi: 0x0A5B,
  24160. zaharabic: 0x0638,
  24161. zahfinalarabic: 0xFEC6,
  24162. zahinitialarabic: 0xFEC7,
  24163. zahiragana: 0x3056,
  24164. zahmedialarabic: 0xFEC8,
  24165. zainarabic: 0x0632,
  24166. zainfinalarabic: 0xFEB0,
  24167. zakatakana: 0x30B6,
  24168. zaqefgadolhebrew: 0x0595,
  24169. zaqefqatanhebrew: 0x0594,
  24170. zarqahebrew: 0x0598,
  24171. zayin: 0x05D6,
  24172. zayindagesh: 0xFB36,
  24173. zayindageshhebrew: 0xFB36,
  24174. zayinhebrew: 0x05D6,
  24175. zbopomofo: 0x3117,
  24176. zcaron: 0x017E,
  24177. zcircle: 0x24E9,
  24178. zcircumflex: 0x1E91,
  24179. zcurl: 0x0291,
  24180. zdot: 0x017C,
  24181. zdotaccent: 0x017C,
  24182. zdotbelow: 0x1E93,
  24183. zecyrillic: 0x0437,
  24184. zedescendercyrillic: 0x0499,
  24185. zedieresiscyrillic: 0x04DF,
  24186. zehiragana: 0x305C,
  24187. zekatakana: 0x30BC,
  24188. zero: 0x0030,
  24189. zeroarabic: 0x0660,
  24190. zerobengali: 0x09E6,
  24191. zerodeva: 0x0966,
  24192. zerogujarati: 0x0AE6,
  24193. zerogurmukhi: 0x0A66,
  24194. zerohackarabic: 0x0660,
  24195. zeroinferior: 0x2080,
  24196. zeromonospace: 0xFF10,
  24197. zerooldstyle: 0xF730,
  24198. zeropersian: 0x06F0,
  24199. zerosuperior: 0x2070,
  24200. zerothai: 0x0E50,
  24201. zerowidthjoiner: 0xFEFF,
  24202. zerowidthnonjoiner: 0x200C,
  24203. zerowidthspace: 0x200B,
  24204. zeta: 0x03B6,
  24205. zhbopomofo: 0x3113,
  24206. zhearmenian: 0x056A,
  24207. zhebrevecyrillic: 0x04C2,
  24208. zhecyrillic: 0x0436,
  24209. zhedescendercyrillic: 0x0497,
  24210. zhedieresiscyrillic: 0x04DD,
  24211. zihiragana: 0x3058,
  24212. zikatakana: 0x30B8,
  24213. zinorhebrew: 0x05AE,
  24214. zlinebelow: 0x1E95,
  24215. zmonospace: 0xFF5A,
  24216. zohiragana: 0x305E,
  24217. zokatakana: 0x30BE,
  24218. zparen: 0x24B5,
  24219. zretroflexhook: 0x0290,
  24220. zstroke: 0x01B6,
  24221. zuhiragana: 0x305A,
  24222. zukatakana: 0x30BA,
  24223. '.notdef': 0x0000
  24224. };
  24225. var PDFImage = (function PDFImageClosure() {
  24226. /**
  24227. * Decode the image in the main thread if it supported. Resovles the promise
  24228. * when the image data is ready.
  24229. */
  24230. function handleImageData(handler, xref, res, image) {
  24231. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24232. // For natively supported jpegs send them to the main thread for decoding.
  24233. var dict = image.dict;
  24234. var colorSpace = dict.get('ColorSpace', 'CS');
  24235. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24236. var numComps = colorSpace.numComps;
  24237. var decodePromise = handler.sendWithPromise('JpegDecode',
  24238. [image.getIR(), numComps]);
  24239. return decodePromise.then(function (message) {
  24240. var data = message.data;
  24241. return new Stream(data, 0, data.length, image.dict);
  24242. });
  24243. } else {
  24244. return Promise.resolve(image);
  24245. }
  24246. }
  24247. /**
  24248. * Decode and clamp a value. The formula is different from the spec because we
  24249. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24250. */
  24251. function decodeAndClamp(value, addend, coefficient, max) {
  24252. value = addend + value * coefficient;
  24253. // Clamp the value to the range
  24254. return (value < 0 ? 0 : (value > max ? max : value));
  24255. }
  24256. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24257. this.image = image;
  24258. var dict = image.dict;
  24259. if (dict.has('Filter')) {
  24260. var filter = dict.get('Filter').name;
  24261. if (filter === 'JPXDecode') {
  24262. var jpxImage = new JpxImage();
  24263. jpxImage.parseImageProperties(image.stream);
  24264. image.stream.reset();
  24265. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24266. image.numComps = jpxImage.componentsCount;
  24267. } else if (filter === 'JBIG2Decode') {
  24268. image.bitsPerComponent = 1;
  24269. image.numComps = 1;
  24270. }
  24271. }
  24272. // TODO cache rendered images?
  24273. this.width = dict.get('Width', 'W');
  24274. this.height = dict.get('Height', 'H');
  24275. if (this.width < 1 || this.height < 1) {
  24276. error('Invalid image width: ' + this.width + ' or height: ' +
  24277. this.height);
  24278. }
  24279. this.interpolate = dict.get('Interpolate', 'I') || false;
  24280. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24281. this.matte = dict.get('Matte') || false;
  24282. var bitsPerComponent = image.bitsPerComponent;
  24283. if (!bitsPerComponent) {
  24284. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24285. if (!bitsPerComponent) {
  24286. if (this.imageMask) {
  24287. bitsPerComponent = 1;
  24288. } else {
  24289. error('Bits per component missing in image: ' + this.imageMask);
  24290. }
  24291. }
  24292. }
  24293. this.bpc = bitsPerComponent;
  24294. if (!this.imageMask) {
  24295. var colorSpace = dict.get('ColorSpace', 'CS');
  24296. if (!colorSpace) {
  24297. info('JPX images (which do not require color spaces)');
  24298. switch (image.numComps) {
  24299. case 1:
  24300. colorSpace = Name.get('DeviceGray');
  24301. break;
  24302. case 3:
  24303. colorSpace = Name.get('DeviceRGB');
  24304. break;
  24305. case 4:
  24306. colorSpace = Name.get('DeviceCMYK');
  24307. break;
  24308. default:
  24309. error('JPX images with ' + this.numComps +
  24310. ' color components not supported.');
  24311. }
  24312. }
  24313. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24314. this.numComps = this.colorSpace.numComps;
  24315. }
  24316. this.decode = dict.get('Decode', 'D');
  24317. this.needsDecode = false;
  24318. if (this.decode &&
  24319. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24320. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24321. this.needsDecode = true;
  24322. // Do some preprocessing to avoid more math.
  24323. var max = (1 << bitsPerComponent) - 1;
  24324. this.decodeCoefficients = [];
  24325. this.decodeAddends = [];
  24326. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24327. var dmin = this.decode[i];
  24328. var dmax = this.decode[i + 1];
  24329. this.decodeCoefficients[j] = dmax - dmin;
  24330. this.decodeAddends[j] = max * dmin;
  24331. }
  24332. }
  24333. if (smask) {
  24334. this.smask = new PDFImage(xref, res, smask, false);
  24335. } else if (mask) {
  24336. if (isStream(mask)) {
  24337. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24338. } else {
  24339. // Color key mask (just an array).
  24340. this.mask = mask;
  24341. }
  24342. }
  24343. }
  24344. /**
  24345. * Handles processing of image data and returns the Promise that is resolved
  24346. * with a PDFImage when the image is ready to be used.
  24347. */
  24348. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24349. res, image, inline) {
  24350. var imagePromise = handleImageData(handler, xref, res, image);
  24351. var smaskPromise;
  24352. var maskPromise;
  24353. var smask = image.dict.get('SMask');
  24354. var mask = image.dict.get('Mask');
  24355. if (smask) {
  24356. smaskPromise = handleImageData(handler, xref, res, smask);
  24357. maskPromise = Promise.resolve(null);
  24358. } else {
  24359. smaskPromise = Promise.resolve(null);
  24360. if (mask) {
  24361. if (isStream(mask)) {
  24362. maskPromise = handleImageData(handler, xref, res, mask);
  24363. } else if (isArray(mask)) {
  24364. maskPromise = Promise.resolve(mask);
  24365. } else {
  24366. warn('Unsupported mask format.');
  24367. maskPromise = Promise.resolve(null);
  24368. }
  24369. } else {
  24370. maskPromise = Promise.resolve(null);
  24371. }
  24372. }
  24373. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24374. function(results) {
  24375. var imageData = results[0];
  24376. var smaskData = results[1];
  24377. var maskData = results[2];
  24378. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24379. });
  24380. };
  24381. /**
  24382. * Resize an image using the nearest neighbor algorithm. Currently only
  24383. * supports one and three component images.
  24384. * @param {TypedArray} pixels The original image with one component.
  24385. * @param {Number} bpc Number of bits per component.
  24386. * @param {Number} components Number of color components, 1 or 3 is supported.
  24387. * @param {Number} w1 Original width.
  24388. * @param {Number} h1 Original height.
  24389. * @param {Number} w2 New width.
  24390. * @param {Number} h2 New height.
  24391. * @param {TypedArray} dest (Optional) The destination buffer.
  24392. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24393. * @return {TypedArray} Resized image data.
  24394. */
  24395. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24396. w1, h1, w2, h2, dest, alpha01) {
  24397. if (components !== 1 && components !== 3) {
  24398. error('Unsupported component count for resizing.');
  24399. }
  24400. var length = w2 * h2 * components;
  24401. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24402. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24403. var xRatio = w1 / w2;
  24404. var yRatio = h1 / h2;
  24405. var i, j, py, newIndex = 0, oldIndex;
  24406. var xScaled = new Uint16Array(w2);
  24407. var w1Scanline = w1 * components;
  24408. if (alpha01 !== 1) {
  24409. alpha01 = 0;
  24410. }
  24411. for (j = 0; j < w2; j++) {
  24412. xScaled[j] = Math.floor(j * xRatio) * components;
  24413. }
  24414. if (components === 1) {
  24415. for (i = 0; i < h2; i++) {
  24416. py = Math.floor(i * yRatio) * w1Scanline;
  24417. for (j = 0; j < w2; j++) {
  24418. oldIndex = py + xScaled[j];
  24419. temp[newIndex++] = pixels[oldIndex];
  24420. }
  24421. }
  24422. } else if (components === 3) {
  24423. for (i = 0; i < h2; i++) {
  24424. py = Math.floor(i * yRatio) * w1Scanline;
  24425. for (j = 0; j < w2; j++) {
  24426. oldIndex = py + xScaled[j];
  24427. temp[newIndex++] = pixels[oldIndex++];
  24428. temp[newIndex++] = pixels[oldIndex++];
  24429. temp[newIndex++] = pixels[oldIndex++];
  24430. newIndex += alpha01;
  24431. }
  24432. }
  24433. }
  24434. return temp;
  24435. };
  24436. PDFImage.createMask =
  24437. function PDFImage_createMask(imgArray, width, height,
  24438. imageIsFromDecodeStream, inverseDecode) {
  24439. // |imgArray| might not contain full data for every pixel of the mask, so
  24440. // we need to distinguish between |computedLength| and |actualLength|.
  24441. // In particular, if inverseDecode is true, then the array we return must
  24442. // have a length of |computedLength|.
  24443. var computedLength = ((width + 7) >> 3) * height;
  24444. var actualLength = imgArray.byteLength;
  24445. var haveFullData = computedLength === actualLength;
  24446. var data, i;
  24447. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24448. // imgArray came from a DecodeStream and its data is in an appropriate
  24449. // form, so we can just transfer it.
  24450. data = imgArray;
  24451. } else if (!inverseDecode) {
  24452. data = new Uint8Array(actualLength);
  24453. data.set(imgArray);
  24454. } else {
  24455. data = new Uint8Array(computedLength);
  24456. data.set(imgArray);
  24457. for (i = actualLength; i < computedLength; i++) {
  24458. data[i] = 0xff;
  24459. }
  24460. }
  24461. // If necessary, invert the original mask data (but not any extra we might
  24462. // have added above). It's safe to modify the array -- whether it's the
  24463. // original or a copy, we're about to transfer it anyway, so nothing else
  24464. // in this thread can be relying on its contents.
  24465. if (inverseDecode) {
  24466. for (i = 0; i < actualLength; i++) {
  24467. data[i] = ~data[i];
  24468. }
  24469. }
  24470. return {data: data, width: width, height: height};
  24471. };
  24472. PDFImage.prototype = {
  24473. get drawWidth() {
  24474. return Math.max(this.width,
  24475. this.smask && this.smask.width || 0,
  24476. this.mask && this.mask.width || 0);
  24477. },
  24478. get drawHeight() {
  24479. return Math.max(this.height,
  24480. this.smask && this.smask.height || 0,
  24481. this.mask && this.mask.height || 0);
  24482. },
  24483. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24484. var bpc = this.bpc;
  24485. var numComps = this.numComps;
  24486. var decodeAddends = this.decodeAddends;
  24487. var decodeCoefficients = this.decodeCoefficients;
  24488. var max = (1 << bpc) - 1;
  24489. var i, ii;
  24490. if (bpc === 1) {
  24491. // If the buffer needed decode that means it just needs to be inverted.
  24492. for (i = 0, ii = buffer.length; i < ii; i++) {
  24493. buffer[i] = +!(buffer[i]);
  24494. }
  24495. return;
  24496. }
  24497. var index = 0;
  24498. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24499. for (var j = 0; j < numComps; j++) {
  24500. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24501. decodeCoefficients[j], max);
  24502. index++;
  24503. }
  24504. }
  24505. },
  24506. getComponents: function PDFImage_getComponents(buffer) {
  24507. var bpc = this.bpc;
  24508. // This image doesn't require any extra work.
  24509. if (bpc === 8) {
  24510. return buffer;
  24511. }
  24512. var width = this.width;
  24513. var height = this.height;
  24514. var numComps = this.numComps;
  24515. var length = width * height * numComps;
  24516. var bufferPos = 0;
  24517. var output = (bpc <= 8 ? new Uint8Array(length) :
  24518. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24519. var rowComps = width * numComps;
  24520. var max = (1 << bpc) - 1;
  24521. var i = 0, ii, buf;
  24522. if (bpc === 1) {
  24523. // Optimization for reading 1 bpc images.
  24524. var mask, loop1End, loop2End;
  24525. for (var j = 0; j < height; j++) {
  24526. loop1End = i + (rowComps & ~7);
  24527. loop2End = i + rowComps;
  24528. // unroll loop for all full bytes
  24529. while (i < loop1End) {
  24530. buf = buffer[bufferPos++];
  24531. output[i] = (buf >> 7) & 1;
  24532. output[i + 1] = (buf >> 6) & 1;
  24533. output[i + 2] = (buf >> 5) & 1;
  24534. output[i + 3] = (buf >> 4) & 1;
  24535. output[i + 4] = (buf >> 3) & 1;
  24536. output[i + 5] = (buf >> 2) & 1;
  24537. output[i + 6] = (buf >> 1) & 1;
  24538. output[i + 7] = buf & 1;
  24539. i += 8;
  24540. }
  24541. // handle remaing bits
  24542. if (i < loop2End) {
  24543. buf = buffer[bufferPos++];
  24544. mask = 128;
  24545. while (i < loop2End) {
  24546. output[i++] = +!!(buf & mask);
  24547. mask >>= 1;
  24548. }
  24549. }
  24550. }
  24551. } else {
  24552. // The general case that handles all other bpc values.
  24553. var bits = 0;
  24554. buf = 0;
  24555. for (i = 0, ii = length; i < ii; ++i) {
  24556. if (i % rowComps === 0) {
  24557. buf = 0;
  24558. bits = 0;
  24559. }
  24560. while (bits < bpc) {
  24561. buf = (buf << 8) | buffer[bufferPos++];
  24562. bits += 8;
  24563. }
  24564. var remainingBits = bits - bpc;
  24565. var value = buf >> remainingBits;
  24566. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  24567. buf = buf & ((1 << remainingBits) - 1);
  24568. bits = remainingBits;
  24569. }
  24570. }
  24571. return output;
  24572. },
  24573. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  24574. actualHeight, image) {
  24575. var smask = this.smask;
  24576. var mask = this.mask;
  24577. var alphaBuf, sw, sh, i, ii, j;
  24578. if (smask) {
  24579. sw = smask.width;
  24580. sh = smask.height;
  24581. alphaBuf = new Uint8Array(sw * sh);
  24582. smask.fillGrayBuffer(alphaBuf);
  24583. if (sw !== width || sh !== height) {
  24584. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  24585. height);
  24586. }
  24587. } else if (mask) {
  24588. if (mask instanceof PDFImage) {
  24589. sw = mask.width;
  24590. sh = mask.height;
  24591. alphaBuf = new Uint8Array(sw * sh);
  24592. mask.numComps = 1;
  24593. mask.fillGrayBuffer(alphaBuf);
  24594. // Need to invert values in rgbaBuf
  24595. for (i = 0, ii = sw * sh; i < ii; ++i) {
  24596. alphaBuf[i] = 255 - alphaBuf[i];
  24597. }
  24598. if (sw !== width || sh !== height) {
  24599. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  24600. height);
  24601. }
  24602. } else if (isArray(mask)) {
  24603. // Color key mask: if any of the compontents are outside the range
  24604. // then they should be painted.
  24605. alphaBuf = new Uint8Array(width * height);
  24606. var numComps = this.numComps;
  24607. for (i = 0, ii = width * height; i < ii; ++i) {
  24608. var opacity = 0;
  24609. var imageOffset = i * numComps;
  24610. for (j = 0; j < numComps; ++j) {
  24611. var color = image[imageOffset + j];
  24612. var maskOffset = j * 2;
  24613. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  24614. opacity = 255;
  24615. break;
  24616. }
  24617. }
  24618. alphaBuf[i] = opacity;
  24619. }
  24620. } else {
  24621. error('Unknown mask format.');
  24622. }
  24623. }
  24624. if (alphaBuf) {
  24625. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24626. rgbaBuf[j] = alphaBuf[i];
  24627. }
  24628. } else {
  24629. // No mask.
  24630. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  24631. rgbaBuf[j] = 255;
  24632. }
  24633. }
  24634. },
  24635. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  24636. var matte = this.smask && this.smask.matte;
  24637. if (!matte) {
  24638. return;
  24639. }
  24640. var matteRgb = this.colorSpace.getRgb(matte, 0);
  24641. var matteR = matteRgb[0];
  24642. var matteG = matteRgb[1];
  24643. var matteB = matteRgb[2];
  24644. var length = width * height * 4;
  24645. var r, g, b;
  24646. for (var i = 0; i < length; i += 4) {
  24647. var alpha = buffer[i + 3];
  24648. if (alpha === 0) {
  24649. // according formula we have to get Infinity in all components
  24650. // making it white (typical paper color) should be okay
  24651. buffer[i] = 255;
  24652. buffer[i + 1] = 255;
  24653. buffer[i + 2] = 255;
  24654. continue;
  24655. }
  24656. var k = 255 / alpha;
  24657. r = (buffer[i] - matteR) * k + matteR;
  24658. g = (buffer[i + 1] - matteG) * k + matteG;
  24659. b = (buffer[i + 2] - matteB) * k + matteB;
  24660. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  24661. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  24662. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  24663. }
  24664. },
  24665. createImageData: function PDFImage_createImageData(forceRGBA) {
  24666. var drawWidth = this.drawWidth;
  24667. var drawHeight = this.drawHeight;
  24668. var imgData = { // other fields are filled in below
  24669. width: drawWidth,
  24670. height: drawHeight
  24671. };
  24672. var numComps = this.numComps;
  24673. var originalWidth = this.width;
  24674. var originalHeight = this.height;
  24675. var bpc = this.bpc;
  24676. // Rows start at byte boundary.
  24677. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  24678. var imgArray;
  24679. if (!forceRGBA) {
  24680. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  24681. // without any complications, we pass a same-sized copy to the main
  24682. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  24683. // of memory for many scanned documents. It's also much faster.
  24684. //
  24685. // Similarly, if it is a 24-bit-per pixel RGB image without any
  24686. // complications, we avoid expanding by 1.333x to RGBA form.
  24687. var kind;
  24688. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  24689. kind = ImageKind.GRAYSCALE_1BPP;
  24690. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  24691. kind = ImageKind.RGB_24BPP;
  24692. }
  24693. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  24694. drawWidth === originalWidth && drawHeight === originalHeight) {
  24695. imgData.kind = kind;
  24696. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24697. // If imgArray came from a DecodeStream, we're safe to transfer it
  24698. // (and thus neuter it) because it will constitute the entire
  24699. // DecodeStream's data. But if it came from a Stream, we need to
  24700. // copy it because it'll only be a portion of the Stream's data, and
  24701. // the rest will be read later on.
  24702. if (this.image instanceof DecodeStream) {
  24703. imgData.data = imgArray;
  24704. } else {
  24705. var newArray = new Uint8Array(imgArray.length);
  24706. newArray.set(imgArray);
  24707. imgData.data = newArray;
  24708. }
  24709. return imgData;
  24710. }
  24711. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  24712. imgData.kind = ImageKind.RGB_24BPP;
  24713. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  24714. drawWidth, drawHeight, true);
  24715. return imgData;
  24716. }
  24717. }
  24718. imgArray = this.getImageBytes(originalHeight * rowBytes);
  24719. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  24720. var actualHeight = 0 | (imgArray.length / rowBytes *
  24721. drawHeight / originalHeight);
  24722. var comps = this.getComponents(imgArray);
  24723. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  24724. // more compact RGB_24BPP form if allowable.
  24725. var alpha01, maybeUndoPreblend;
  24726. if (!forceRGBA && !this.smask && !this.mask) {
  24727. imgData.kind = ImageKind.RGB_24BPP;
  24728. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  24729. alpha01 = 0;
  24730. maybeUndoPreblend = false;
  24731. } else {
  24732. imgData.kind = ImageKind.RGBA_32BPP;
  24733. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  24734. alpha01 = 1;
  24735. maybeUndoPreblend = true;
  24736. // Color key masking (opacity) must be performed before decoding.
  24737. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  24738. comps);
  24739. }
  24740. if (this.needsDecode) {
  24741. this.decodeBuffer(comps);
  24742. }
  24743. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  24744. drawWidth, drawHeight, actualHeight, bpc, comps,
  24745. alpha01);
  24746. if (maybeUndoPreblend) {
  24747. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  24748. }
  24749. return imgData;
  24750. },
  24751. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  24752. var numComps = this.numComps;
  24753. if (numComps !== 1) {
  24754. error('Reading gray scale from a color image: ' + numComps);
  24755. }
  24756. var width = this.width;
  24757. var height = this.height;
  24758. var bpc = this.bpc;
  24759. // rows start at byte boundary
  24760. var rowBytes = (width * numComps * bpc + 7) >> 3;
  24761. var imgArray = this.getImageBytes(height * rowBytes);
  24762. var comps = this.getComponents(imgArray);
  24763. var i, length;
  24764. if (bpc === 1) {
  24765. // inline decoding (= inversion) for 1 bpc images
  24766. length = width * height;
  24767. if (this.needsDecode) {
  24768. // invert and scale to {0, 255}
  24769. for (i = 0; i < length; ++i) {
  24770. buffer[i] = (comps[i] - 1) & 255;
  24771. }
  24772. } else {
  24773. // scale to {0, 255}
  24774. for (i = 0; i < length; ++i) {
  24775. buffer[i] = (-comps[i]) & 255;
  24776. }
  24777. }
  24778. return;
  24779. }
  24780. if (this.needsDecode) {
  24781. this.decodeBuffer(comps);
  24782. }
  24783. length = width * height;
  24784. // we aren't using a colorspace so we need to scale the value
  24785. var scale = 255 / ((1 << bpc) - 1);
  24786. for (i = 0; i < length; ++i) {
  24787. buffer[i] = (scale * comps[i]) | 0;
  24788. }
  24789. },
  24790. getImageBytes: function PDFImage_getImageBytes(length,
  24791. drawWidth, drawHeight,
  24792. forceRGB) {
  24793. this.image.reset();
  24794. this.image.drawWidth = drawWidth || this.width;
  24795. this.image.drawHeight = drawHeight || this.height;
  24796. this.image.forceRGB = !!forceRGB;
  24797. return this.image.getBytes(length);
  24798. }
  24799. };
  24800. return PDFImage;
  24801. })();
  24802. // The Metrics object contains glyph widths (in glyph space units).
  24803. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  24804. // space unit corresponds to 1/1000th of text space unit.
  24805. var Metrics = {
  24806. 'Courier': 600,
  24807. 'Courier-Bold': 600,
  24808. 'Courier-BoldOblique': 600,
  24809. 'Courier-Oblique': 600,
  24810. 'Helvetica' : {
  24811. 'space': 278,
  24812. 'exclam': 278,
  24813. 'quotedbl': 355,
  24814. 'numbersign': 556,
  24815. 'dollar': 556,
  24816. 'percent': 889,
  24817. 'ampersand': 667,
  24818. 'quoteright': 222,
  24819. 'parenleft': 333,
  24820. 'parenright': 333,
  24821. 'asterisk': 389,
  24822. 'plus': 584,
  24823. 'comma': 278,
  24824. 'hyphen': 333,
  24825. 'period': 278,
  24826. 'slash': 278,
  24827. 'zero': 556,
  24828. 'one': 556,
  24829. 'two': 556,
  24830. 'three': 556,
  24831. 'four': 556,
  24832. 'five': 556,
  24833. 'six': 556,
  24834. 'seven': 556,
  24835. 'eight': 556,
  24836. 'nine': 556,
  24837. 'colon': 278,
  24838. 'semicolon': 278,
  24839. 'less': 584,
  24840. 'equal': 584,
  24841. 'greater': 584,
  24842. 'question': 556,
  24843. 'at': 1015,
  24844. 'A': 667,
  24845. 'B': 667,
  24846. 'C': 722,
  24847. 'D': 722,
  24848. 'E': 667,
  24849. 'F': 611,
  24850. 'G': 778,
  24851. 'H': 722,
  24852. 'I': 278,
  24853. 'J': 500,
  24854. 'K': 667,
  24855. 'L': 556,
  24856. 'M': 833,
  24857. 'N': 722,
  24858. 'O': 778,
  24859. 'P': 667,
  24860. 'Q': 778,
  24861. 'R': 722,
  24862. 'S': 667,
  24863. 'T': 611,
  24864. 'U': 722,
  24865. 'V': 667,
  24866. 'W': 944,
  24867. 'X': 667,
  24868. 'Y': 667,
  24869. 'Z': 611,
  24870. 'bracketleft': 278,
  24871. 'backslash': 278,
  24872. 'bracketright': 278,
  24873. 'asciicircum': 469,
  24874. 'underscore': 556,
  24875. 'quoteleft': 222,
  24876. 'a': 556,
  24877. 'b': 556,
  24878. 'c': 500,
  24879. 'd': 556,
  24880. 'e': 556,
  24881. 'f': 278,
  24882. 'g': 556,
  24883. 'h': 556,
  24884. 'i': 222,
  24885. 'j': 222,
  24886. 'k': 500,
  24887. 'l': 222,
  24888. 'm': 833,
  24889. 'n': 556,
  24890. 'o': 556,
  24891. 'p': 556,
  24892. 'q': 556,
  24893. 'r': 333,
  24894. 's': 500,
  24895. 't': 278,
  24896. 'u': 556,
  24897. 'v': 500,
  24898. 'w': 722,
  24899. 'x': 500,
  24900. 'y': 500,
  24901. 'z': 500,
  24902. 'braceleft': 334,
  24903. 'bar': 260,
  24904. 'braceright': 334,
  24905. 'asciitilde': 584,
  24906. 'exclamdown': 333,
  24907. 'cent': 556,
  24908. 'sterling': 556,
  24909. 'fraction': 167,
  24910. 'yen': 556,
  24911. 'florin': 556,
  24912. 'section': 556,
  24913. 'currency': 556,
  24914. 'quotesingle': 191,
  24915. 'quotedblleft': 333,
  24916. 'guillemotleft': 556,
  24917. 'guilsinglleft': 333,
  24918. 'guilsinglright': 333,
  24919. 'fi': 500,
  24920. 'fl': 500,
  24921. 'endash': 556,
  24922. 'dagger': 556,
  24923. 'daggerdbl': 556,
  24924. 'periodcentered': 278,
  24925. 'paragraph': 537,
  24926. 'bullet': 350,
  24927. 'quotesinglbase': 222,
  24928. 'quotedblbase': 333,
  24929. 'quotedblright': 333,
  24930. 'guillemotright': 556,
  24931. 'ellipsis': 1000,
  24932. 'perthousand': 1000,
  24933. 'questiondown': 611,
  24934. 'grave': 333,
  24935. 'acute': 333,
  24936. 'circumflex': 333,
  24937. 'tilde': 333,
  24938. 'macron': 333,
  24939. 'breve': 333,
  24940. 'dotaccent': 333,
  24941. 'dieresis': 333,
  24942. 'ring': 333,
  24943. 'cedilla': 333,
  24944. 'hungarumlaut': 333,
  24945. 'ogonek': 333,
  24946. 'caron': 333,
  24947. 'emdash': 1000,
  24948. 'AE': 1000,
  24949. 'ordfeminine': 370,
  24950. 'Lslash': 556,
  24951. 'Oslash': 778,
  24952. 'OE': 1000,
  24953. 'ordmasculine': 365,
  24954. 'ae': 889,
  24955. 'dotlessi': 278,
  24956. 'lslash': 222,
  24957. 'oslash': 611,
  24958. 'oe': 944,
  24959. 'germandbls': 611,
  24960. 'Idieresis': 278,
  24961. 'eacute': 556,
  24962. 'abreve': 556,
  24963. 'uhungarumlaut': 556,
  24964. 'ecaron': 556,
  24965. 'Ydieresis': 667,
  24966. 'divide': 584,
  24967. 'Yacute': 667,
  24968. 'Acircumflex': 667,
  24969. 'aacute': 556,
  24970. 'Ucircumflex': 722,
  24971. 'yacute': 500,
  24972. 'scommaaccent': 500,
  24973. 'ecircumflex': 556,
  24974. 'Uring': 722,
  24975. 'Udieresis': 722,
  24976. 'aogonek': 556,
  24977. 'Uacute': 722,
  24978. 'uogonek': 556,
  24979. 'Edieresis': 667,
  24980. 'Dcroat': 722,
  24981. 'commaaccent': 250,
  24982. 'copyright': 737,
  24983. 'Emacron': 667,
  24984. 'ccaron': 500,
  24985. 'aring': 556,
  24986. 'Ncommaaccent': 722,
  24987. 'lacute': 222,
  24988. 'agrave': 556,
  24989. 'Tcommaaccent': 611,
  24990. 'Cacute': 722,
  24991. 'atilde': 556,
  24992. 'Edotaccent': 667,
  24993. 'scaron': 500,
  24994. 'scedilla': 500,
  24995. 'iacute': 278,
  24996. 'lozenge': 471,
  24997. 'Rcaron': 722,
  24998. 'Gcommaaccent': 778,
  24999. 'ucircumflex': 556,
  25000. 'acircumflex': 556,
  25001. 'Amacron': 667,
  25002. 'rcaron': 333,
  25003. 'ccedilla': 500,
  25004. 'Zdotaccent': 611,
  25005. 'Thorn': 667,
  25006. 'Omacron': 778,
  25007. 'Racute': 722,
  25008. 'Sacute': 667,
  25009. 'dcaron': 643,
  25010. 'Umacron': 722,
  25011. 'uring': 556,
  25012. 'threesuperior': 333,
  25013. 'Ograve': 778,
  25014. 'Agrave': 667,
  25015. 'Abreve': 667,
  25016. 'multiply': 584,
  25017. 'uacute': 556,
  25018. 'Tcaron': 611,
  25019. 'partialdiff': 476,
  25020. 'ydieresis': 500,
  25021. 'Nacute': 722,
  25022. 'icircumflex': 278,
  25023. 'Ecircumflex': 667,
  25024. 'adieresis': 556,
  25025. 'edieresis': 556,
  25026. 'cacute': 500,
  25027. 'nacute': 556,
  25028. 'umacron': 556,
  25029. 'Ncaron': 722,
  25030. 'Iacute': 278,
  25031. 'plusminus': 584,
  25032. 'brokenbar': 260,
  25033. 'registered': 737,
  25034. 'Gbreve': 778,
  25035. 'Idotaccent': 278,
  25036. 'summation': 600,
  25037. 'Egrave': 667,
  25038. 'racute': 333,
  25039. 'omacron': 556,
  25040. 'Zacute': 611,
  25041. 'Zcaron': 611,
  25042. 'greaterequal': 549,
  25043. 'Eth': 722,
  25044. 'Ccedilla': 722,
  25045. 'lcommaaccent': 222,
  25046. 'tcaron': 317,
  25047. 'eogonek': 556,
  25048. 'Uogonek': 722,
  25049. 'Aacute': 667,
  25050. 'Adieresis': 667,
  25051. 'egrave': 556,
  25052. 'zacute': 500,
  25053. 'iogonek': 222,
  25054. 'Oacute': 778,
  25055. 'oacute': 556,
  25056. 'amacron': 556,
  25057. 'sacute': 500,
  25058. 'idieresis': 278,
  25059. 'Ocircumflex': 778,
  25060. 'Ugrave': 722,
  25061. 'Delta': 612,
  25062. 'thorn': 556,
  25063. 'twosuperior': 333,
  25064. 'Odieresis': 778,
  25065. 'mu': 556,
  25066. 'igrave': 278,
  25067. 'ohungarumlaut': 556,
  25068. 'Eogonek': 667,
  25069. 'dcroat': 556,
  25070. 'threequarters': 834,
  25071. 'Scedilla': 667,
  25072. 'lcaron': 299,
  25073. 'Kcommaaccent': 667,
  25074. 'Lacute': 556,
  25075. 'trademark': 1000,
  25076. 'edotaccent': 556,
  25077. 'Igrave': 278,
  25078. 'Imacron': 278,
  25079. 'Lcaron': 556,
  25080. 'onehalf': 834,
  25081. 'lessequal': 549,
  25082. 'ocircumflex': 556,
  25083. 'ntilde': 556,
  25084. 'Uhungarumlaut': 722,
  25085. 'Eacute': 667,
  25086. 'emacron': 556,
  25087. 'gbreve': 556,
  25088. 'onequarter': 834,
  25089. 'Scaron': 667,
  25090. 'Scommaaccent': 667,
  25091. 'Ohungarumlaut': 778,
  25092. 'degree': 400,
  25093. 'ograve': 556,
  25094. 'Ccaron': 722,
  25095. 'ugrave': 556,
  25096. 'radical': 453,
  25097. 'Dcaron': 722,
  25098. 'rcommaaccent': 333,
  25099. 'Ntilde': 722,
  25100. 'otilde': 556,
  25101. 'Rcommaaccent': 722,
  25102. 'Lcommaaccent': 556,
  25103. 'Atilde': 667,
  25104. 'Aogonek': 667,
  25105. 'Aring': 667,
  25106. 'Otilde': 778,
  25107. 'zdotaccent': 500,
  25108. 'Ecaron': 667,
  25109. 'Iogonek': 278,
  25110. 'kcommaaccent': 500,
  25111. 'minus': 584,
  25112. 'Icircumflex': 278,
  25113. 'ncaron': 556,
  25114. 'tcommaaccent': 278,
  25115. 'logicalnot': 584,
  25116. 'odieresis': 556,
  25117. 'udieresis': 556,
  25118. 'notequal': 549,
  25119. 'gcommaaccent': 556,
  25120. 'eth': 556,
  25121. 'zcaron': 500,
  25122. 'ncommaaccent': 556,
  25123. 'onesuperior': 333,
  25124. 'imacron': 278,
  25125. 'Euro': 556
  25126. },
  25127. 'Helvetica-Bold': {
  25128. 'space': 278,
  25129. 'exclam': 333,
  25130. 'quotedbl': 474,
  25131. 'numbersign': 556,
  25132. 'dollar': 556,
  25133. 'percent': 889,
  25134. 'ampersand': 722,
  25135. 'quoteright': 278,
  25136. 'parenleft': 333,
  25137. 'parenright': 333,
  25138. 'asterisk': 389,
  25139. 'plus': 584,
  25140. 'comma': 278,
  25141. 'hyphen': 333,
  25142. 'period': 278,
  25143. 'slash': 278,
  25144. 'zero': 556,
  25145. 'one': 556,
  25146. 'two': 556,
  25147. 'three': 556,
  25148. 'four': 556,
  25149. 'five': 556,
  25150. 'six': 556,
  25151. 'seven': 556,
  25152. 'eight': 556,
  25153. 'nine': 556,
  25154. 'colon': 333,
  25155. 'semicolon': 333,
  25156. 'less': 584,
  25157. 'equal': 584,
  25158. 'greater': 584,
  25159. 'question': 611,
  25160. 'at': 975,
  25161. 'A': 722,
  25162. 'B': 722,
  25163. 'C': 722,
  25164. 'D': 722,
  25165. 'E': 667,
  25166. 'F': 611,
  25167. 'G': 778,
  25168. 'H': 722,
  25169. 'I': 278,
  25170. 'J': 556,
  25171. 'K': 722,
  25172. 'L': 611,
  25173. 'M': 833,
  25174. 'N': 722,
  25175. 'O': 778,
  25176. 'P': 667,
  25177. 'Q': 778,
  25178. 'R': 722,
  25179. 'S': 667,
  25180. 'T': 611,
  25181. 'U': 722,
  25182. 'V': 667,
  25183. 'W': 944,
  25184. 'X': 667,
  25185. 'Y': 667,
  25186. 'Z': 611,
  25187. 'bracketleft': 333,
  25188. 'backslash': 278,
  25189. 'bracketright': 333,
  25190. 'asciicircum': 584,
  25191. 'underscore': 556,
  25192. 'quoteleft': 278,
  25193. 'a': 556,
  25194. 'b': 611,
  25195. 'c': 556,
  25196. 'd': 611,
  25197. 'e': 556,
  25198. 'f': 333,
  25199. 'g': 611,
  25200. 'h': 611,
  25201. 'i': 278,
  25202. 'j': 278,
  25203. 'k': 556,
  25204. 'l': 278,
  25205. 'm': 889,
  25206. 'n': 611,
  25207. 'o': 611,
  25208. 'p': 611,
  25209. 'q': 611,
  25210. 'r': 389,
  25211. 's': 556,
  25212. 't': 333,
  25213. 'u': 611,
  25214. 'v': 556,
  25215. 'w': 778,
  25216. 'x': 556,
  25217. 'y': 556,
  25218. 'z': 500,
  25219. 'braceleft': 389,
  25220. 'bar': 280,
  25221. 'braceright': 389,
  25222. 'asciitilde': 584,
  25223. 'exclamdown': 333,
  25224. 'cent': 556,
  25225. 'sterling': 556,
  25226. 'fraction': 167,
  25227. 'yen': 556,
  25228. 'florin': 556,
  25229. 'section': 556,
  25230. 'currency': 556,
  25231. 'quotesingle': 238,
  25232. 'quotedblleft': 500,
  25233. 'guillemotleft': 556,
  25234. 'guilsinglleft': 333,
  25235. 'guilsinglright': 333,
  25236. 'fi': 611,
  25237. 'fl': 611,
  25238. 'endash': 556,
  25239. 'dagger': 556,
  25240. 'daggerdbl': 556,
  25241. 'periodcentered': 278,
  25242. 'paragraph': 556,
  25243. 'bullet': 350,
  25244. 'quotesinglbase': 278,
  25245. 'quotedblbase': 500,
  25246. 'quotedblright': 500,
  25247. 'guillemotright': 556,
  25248. 'ellipsis': 1000,
  25249. 'perthousand': 1000,
  25250. 'questiondown': 611,
  25251. 'grave': 333,
  25252. 'acute': 333,
  25253. 'circumflex': 333,
  25254. 'tilde': 333,
  25255. 'macron': 333,
  25256. 'breve': 333,
  25257. 'dotaccent': 333,
  25258. 'dieresis': 333,
  25259. 'ring': 333,
  25260. 'cedilla': 333,
  25261. 'hungarumlaut': 333,
  25262. 'ogonek': 333,
  25263. 'caron': 333,
  25264. 'emdash': 1000,
  25265. 'AE': 1000,
  25266. 'ordfeminine': 370,
  25267. 'Lslash': 611,
  25268. 'Oslash': 778,
  25269. 'OE': 1000,
  25270. 'ordmasculine': 365,
  25271. 'ae': 889,
  25272. 'dotlessi': 278,
  25273. 'lslash': 278,
  25274. 'oslash': 611,
  25275. 'oe': 944,
  25276. 'germandbls': 611,
  25277. 'Idieresis': 278,
  25278. 'eacute': 556,
  25279. 'abreve': 556,
  25280. 'uhungarumlaut': 611,
  25281. 'ecaron': 556,
  25282. 'Ydieresis': 667,
  25283. 'divide': 584,
  25284. 'Yacute': 667,
  25285. 'Acircumflex': 722,
  25286. 'aacute': 556,
  25287. 'Ucircumflex': 722,
  25288. 'yacute': 556,
  25289. 'scommaaccent': 556,
  25290. 'ecircumflex': 556,
  25291. 'Uring': 722,
  25292. 'Udieresis': 722,
  25293. 'aogonek': 556,
  25294. 'Uacute': 722,
  25295. 'uogonek': 611,
  25296. 'Edieresis': 667,
  25297. 'Dcroat': 722,
  25298. 'commaaccent': 250,
  25299. 'copyright': 737,
  25300. 'Emacron': 667,
  25301. 'ccaron': 556,
  25302. 'aring': 556,
  25303. 'Ncommaaccent': 722,
  25304. 'lacute': 278,
  25305. 'agrave': 556,
  25306. 'Tcommaaccent': 611,
  25307. 'Cacute': 722,
  25308. 'atilde': 556,
  25309. 'Edotaccent': 667,
  25310. 'scaron': 556,
  25311. 'scedilla': 556,
  25312. 'iacute': 278,
  25313. 'lozenge': 494,
  25314. 'Rcaron': 722,
  25315. 'Gcommaaccent': 778,
  25316. 'ucircumflex': 611,
  25317. 'acircumflex': 556,
  25318. 'Amacron': 722,
  25319. 'rcaron': 389,
  25320. 'ccedilla': 556,
  25321. 'Zdotaccent': 611,
  25322. 'Thorn': 667,
  25323. 'Omacron': 778,
  25324. 'Racute': 722,
  25325. 'Sacute': 667,
  25326. 'dcaron': 743,
  25327. 'Umacron': 722,
  25328. 'uring': 611,
  25329. 'threesuperior': 333,
  25330. 'Ograve': 778,
  25331. 'Agrave': 722,
  25332. 'Abreve': 722,
  25333. 'multiply': 584,
  25334. 'uacute': 611,
  25335. 'Tcaron': 611,
  25336. 'partialdiff': 494,
  25337. 'ydieresis': 556,
  25338. 'Nacute': 722,
  25339. 'icircumflex': 278,
  25340. 'Ecircumflex': 667,
  25341. 'adieresis': 556,
  25342. 'edieresis': 556,
  25343. 'cacute': 556,
  25344. 'nacute': 611,
  25345. 'umacron': 611,
  25346. 'Ncaron': 722,
  25347. 'Iacute': 278,
  25348. 'plusminus': 584,
  25349. 'brokenbar': 280,
  25350. 'registered': 737,
  25351. 'Gbreve': 778,
  25352. 'Idotaccent': 278,
  25353. 'summation': 600,
  25354. 'Egrave': 667,
  25355. 'racute': 389,
  25356. 'omacron': 611,
  25357. 'Zacute': 611,
  25358. 'Zcaron': 611,
  25359. 'greaterequal': 549,
  25360. 'Eth': 722,
  25361. 'Ccedilla': 722,
  25362. 'lcommaaccent': 278,
  25363. 'tcaron': 389,
  25364. 'eogonek': 556,
  25365. 'Uogonek': 722,
  25366. 'Aacute': 722,
  25367. 'Adieresis': 722,
  25368. 'egrave': 556,
  25369. 'zacute': 500,
  25370. 'iogonek': 278,
  25371. 'Oacute': 778,
  25372. 'oacute': 611,
  25373. 'amacron': 556,
  25374. 'sacute': 556,
  25375. 'idieresis': 278,
  25376. 'Ocircumflex': 778,
  25377. 'Ugrave': 722,
  25378. 'Delta': 612,
  25379. 'thorn': 611,
  25380. 'twosuperior': 333,
  25381. 'Odieresis': 778,
  25382. 'mu': 611,
  25383. 'igrave': 278,
  25384. 'ohungarumlaut': 611,
  25385. 'Eogonek': 667,
  25386. 'dcroat': 611,
  25387. 'threequarters': 834,
  25388. 'Scedilla': 667,
  25389. 'lcaron': 400,
  25390. 'Kcommaaccent': 722,
  25391. 'Lacute': 611,
  25392. 'trademark': 1000,
  25393. 'edotaccent': 556,
  25394. 'Igrave': 278,
  25395. 'Imacron': 278,
  25396. 'Lcaron': 611,
  25397. 'onehalf': 834,
  25398. 'lessequal': 549,
  25399. 'ocircumflex': 611,
  25400. 'ntilde': 611,
  25401. 'Uhungarumlaut': 722,
  25402. 'Eacute': 667,
  25403. 'emacron': 556,
  25404. 'gbreve': 611,
  25405. 'onequarter': 834,
  25406. 'Scaron': 667,
  25407. 'Scommaaccent': 667,
  25408. 'Ohungarumlaut': 778,
  25409. 'degree': 400,
  25410. 'ograve': 611,
  25411. 'Ccaron': 722,
  25412. 'ugrave': 611,
  25413. 'radical': 549,
  25414. 'Dcaron': 722,
  25415. 'rcommaaccent': 389,
  25416. 'Ntilde': 722,
  25417. 'otilde': 611,
  25418. 'Rcommaaccent': 722,
  25419. 'Lcommaaccent': 611,
  25420. 'Atilde': 722,
  25421. 'Aogonek': 722,
  25422. 'Aring': 722,
  25423. 'Otilde': 778,
  25424. 'zdotaccent': 500,
  25425. 'Ecaron': 667,
  25426. 'Iogonek': 278,
  25427. 'kcommaaccent': 556,
  25428. 'minus': 584,
  25429. 'Icircumflex': 278,
  25430. 'ncaron': 611,
  25431. 'tcommaaccent': 333,
  25432. 'logicalnot': 584,
  25433. 'odieresis': 611,
  25434. 'udieresis': 611,
  25435. 'notequal': 549,
  25436. 'gcommaaccent': 611,
  25437. 'eth': 611,
  25438. 'zcaron': 500,
  25439. 'ncommaaccent': 611,
  25440. 'onesuperior': 333,
  25441. 'imacron': 278,
  25442. 'Euro': 556
  25443. },
  25444. 'Helvetica-BoldOblique': {
  25445. 'space': 278,
  25446. 'exclam': 333,
  25447. 'quotedbl': 474,
  25448. 'numbersign': 556,
  25449. 'dollar': 556,
  25450. 'percent': 889,
  25451. 'ampersand': 722,
  25452. 'quoteright': 278,
  25453. 'parenleft': 333,
  25454. 'parenright': 333,
  25455. 'asterisk': 389,
  25456. 'plus': 584,
  25457. 'comma': 278,
  25458. 'hyphen': 333,
  25459. 'period': 278,
  25460. 'slash': 278,
  25461. 'zero': 556,
  25462. 'one': 556,
  25463. 'two': 556,
  25464. 'three': 556,
  25465. 'four': 556,
  25466. 'five': 556,
  25467. 'six': 556,
  25468. 'seven': 556,
  25469. 'eight': 556,
  25470. 'nine': 556,
  25471. 'colon': 333,
  25472. 'semicolon': 333,
  25473. 'less': 584,
  25474. 'equal': 584,
  25475. 'greater': 584,
  25476. 'question': 611,
  25477. 'at': 975,
  25478. 'A': 722,
  25479. 'B': 722,
  25480. 'C': 722,
  25481. 'D': 722,
  25482. 'E': 667,
  25483. 'F': 611,
  25484. 'G': 778,
  25485. 'H': 722,
  25486. 'I': 278,
  25487. 'J': 556,
  25488. 'K': 722,
  25489. 'L': 611,
  25490. 'M': 833,
  25491. 'N': 722,
  25492. 'O': 778,
  25493. 'P': 667,
  25494. 'Q': 778,
  25495. 'R': 722,
  25496. 'S': 667,
  25497. 'T': 611,
  25498. 'U': 722,
  25499. 'V': 667,
  25500. 'W': 944,
  25501. 'X': 667,
  25502. 'Y': 667,
  25503. 'Z': 611,
  25504. 'bracketleft': 333,
  25505. 'backslash': 278,
  25506. 'bracketright': 333,
  25507. 'asciicircum': 584,
  25508. 'underscore': 556,
  25509. 'quoteleft': 278,
  25510. 'a': 556,
  25511. 'b': 611,
  25512. 'c': 556,
  25513. 'd': 611,
  25514. 'e': 556,
  25515. 'f': 333,
  25516. 'g': 611,
  25517. 'h': 611,
  25518. 'i': 278,
  25519. 'j': 278,
  25520. 'k': 556,
  25521. 'l': 278,
  25522. 'm': 889,
  25523. 'n': 611,
  25524. 'o': 611,
  25525. 'p': 611,
  25526. 'q': 611,
  25527. 'r': 389,
  25528. 's': 556,
  25529. 't': 333,
  25530. 'u': 611,
  25531. 'v': 556,
  25532. 'w': 778,
  25533. 'x': 556,
  25534. 'y': 556,
  25535. 'z': 500,
  25536. 'braceleft': 389,
  25537. 'bar': 280,
  25538. 'braceright': 389,
  25539. 'asciitilde': 584,
  25540. 'exclamdown': 333,
  25541. 'cent': 556,
  25542. 'sterling': 556,
  25543. 'fraction': 167,
  25544. 'yen': 556,
  25545. 'florin': 556,
  25546. 'section': 556,
  25547. 'currency': 556,
  25548. 'quotesingle': 238,
  25549. 'quotedblleft': 500,
  25550. 'guillemotleft': 556,
  25551. 'guilsinglleft': 333,
  25552. 'guilsinglright': 333,
  25553. 'fi': 611,
  25554. 'fl': 611,
  25555. 'endash': 556,
  25556. 'dagger': 556,
  25557. 'daggerdbl': 556,
  25558. 'periodcentered': 278,
  25559. 'paragraph': 556,
  25560. 'bullet': 350,
  25561. 'quotesinglbase': 278,
  25562. 'quotedblbase': 500,
  25563. 'quotedblright': 500,
  25564. 'guillemotright': 556,
  25565. 'ellipsis': 1000,
  25566. 'perthousand': 1000,
  25567. 'questiondown': 611,
  25568. 'grave': 333,
  25569. 'acute': 333,
  25570. 'circumflex': 333,
  25571. 'tilde': 333,
  25572. 'macron': 333,
  25573. 'breve': 333,
  25574. 'dotaccent': 333,
  25575. 'dieresis': 333,
  25576. 'ring': 333,
  25577. 'cedilla': 333,
  25578. 'hungarumlaut': 333,
  25579. 'ogonek': 333,
  25580. 'caron': 333,
  25581. 'emdash': 1000,
  25582. 'AE': 1000,
  25583. 'ordfeminine': 370,
  25584. 'Lslash': 611,
  25585. 'Oslash': 778,
  25586. 'OE': 1000,
  25587. 'ordmasculine': 365,
  25588. 'ae': 889,
  25589. 'dotlessi': 278,
  25590. 'lslash': 278,
  25591. 'oslash': 611,
  25592. 'oe': 944,
  25593. 'germandbls': 611,
  25594. 'Idieresis': 278,
  25595. 'eacute': 556,
  25596. 'abreve': 556,
  25597. 'uhungarumlaut': 611,
  25598. 'ecaron': 556,
  25599. 'Ydieresis': 667,
  25600. 'divide': 584,
  25601. 'Yacute': 667,
  25602. 'Acircumflex': 722,
  25603. 'aacute': 556,
  25604. 'Ucircumflex': 722,
  25605. 'yacute': 556,
  25606. 'scommaaccent': 556,
  25607. 'ecircumflex': 556,
  25608. 'Uring': 722,
  25609. 'Udieresis': 722,
  25610. 'aogonek': 556,
  25611. 'Uacute': 722,
  25612. 'uogonek': 611,
  25613. 'Edieresis': 667,
  25614. 'Dcroat': 722,
  25615. 'commaaccent': 250,
  25616. 'copyright': 737,
  25617. 'Emacron': 667,
  25618. 'ccaron': 556,
  25619. 'aring': 556,
  25620. 'Ncommaaccent': 722,
  25621. 'lacute': 278,
  25622. 'agrave': 556,
  25623. 'Tcommaaccent': 611,
  25624. 'Cacute': 722,
  25625. 'atilde': 556,
  25626. 'Edotaccent': 667,
  25627. 'scaron': 556,
  25628. 'scedilla': 556,
  25629. 'iacute': 278,
  25630. 'lozenge': 494,
  25631. 'Rcaron': 722,
  25632. 'Gcommaaccent': 778,
  25633. 'ucircumflex': 611,
  25634. 'acircumflex': 556,
  25635. 'Amacron': 722,
  25636. 'rcaron': 389,
  25637. 'ccedilla': 556,
  25638. 'Zdotaccent': 611,
  25639. 'Thorn': 667,
  25640. 'Omacron': 778,
  25641. 'Racute': 722,
  25642. 'Sacute': 667,
  25643. 'dcaron': 743,
  25644. 'Umacron': 722,
  25645. 'uring': 611,
  25646. 'threesuperior': 333,
  25647. 'Ograve': 778,
  25648. 'Agrave': 722,
  25649. 'Abreve': 722,
  25650. 'multiply': 584,
  25651. 'uacute': 611,
  25652. 'Tcaron': 611,
  25653. 'partialdiff': 494,
  25654. 'ydieresis': 556,
  25655. 'Nacute': 722,
  25656. 'icircumflex': 278,
  25657. 'Ecircumflex': 667,
  25658. 'adieresis': 556,
  25659. 'edieresis': 556,
  25660. 'cacute': 556,
  25661. 'nacute': 611,
  25662. 'umacron': 611,
  25663. 'Ncaron': 722,
  25664. 'Iacute': 278,
  25665. 'plusminus': 584,
  25666. 'brokenbar': 280,
  25667. 'registered': 737,
  25668. 'Gbreve': 778,
  25669. 'Idotaccent': 278,
  25670. 'summation': 600,
  25671. 'Egrave': 667,
  25672. 'racute': 389,
  25673. 'omacron': 611,
  25674. 'Zacute': 611,
  25675. 'Zcaron': 611,
  25676. 'greaterequal': 549,
  25677. 'Eth': 722,
  25678. 'Ccedilla': 722,
  25679. 'lcommaaccent': 278,
  25680. 'tcaron': 389,
  25681. 'eogonek': 556,
  25682. 'Uogonek': 722,
  25683. 'Aacute': 722,
  25684. 'Adieresis': 722,
  25685. 'egrave': 556,
  25686. 'zacute': 500,
  25687. 'iogonek': 278,
  25688. 'Oacute': 778,
  25689. 'oacute': 611,
  25690. 'amacron': 556,
  25691. 'sacute': 556,
  25692. 'idieresis': 278,
  25693. 'Ocircumflex': 778,
  25694. 'Ugrave': 722,
  25695. 'Delta': 612,
  25696. 'thorn': 611,
  25697. 'twosuperior': 333,
  25698. 'Odieresis': 778,
  25699. 'mu': 611,
  25700. 'igrave': 278,
  25701. 'ohungarumlaut': 611,
  25702. 'Eogonek': 667,
  25703. 'dcroat': 611,
  25704. 'threequarters': 834,
  25705. 'Scedilla': 667,
  25706. 'lcaron': 400,
  25707. 'Kcommaaccent': 722,
  25708. 'Lacute': 611,
  25709. 'trademark': 1000,
  25710. 'edotaccent': 556,
  25711. 'Igrave': 278,
  25712. 'Imacron': 278,
  25713. 'Lcaron': 611,
  25714. 'onehalf': 834,
  25715. 'lessequal': 549,
  25716. 'ocircumflex': 611,
  25717. 'ntilde': 611,
  25718. 'Uhungarumlaut': 722,
  25719. 'Eacute': 667,
  25720. 'emacron': 556,
  25721. 'gbreve': 611,
  25722. 'onequarter': 834,
  25723. 'Scaron': 667,
  25724. 'Scommaaccent': 667,
  25725. 'Ohungarumlaut': 778,
  25726. 'degree': 400,
  25727. 'ograve': 611,
  25728. 'Ccaron': 722,
  25729. 'ugrave': 611,
  25730. 'radical': 549,
  25731. 'Dcaron': 722,
  25732. 'rcommaaccent': 389,
  25733. 'Ntilde': 722,
  25734. 'otilde': 611,
  25735. 'Rcommaaccent': 722,
  25736. 'Lcommaaccent': 611,
  25737. 'Atilde': 722,
  25738. 'Aogonek': 722,
  25739. 'Aring': 722,
  25740. 'Otilde': 778,
  25741. 'zdotaccent': 500,
  25742. 'Ecaron': 667,
  25743. 'Iogonek': 278,
  25744. 'kcommaaccent': 556,
  25745. 'minus': 584,
  25746. 'Icircumflex': 278,
  25747. 'ncaron': 611,
  25748. 'tcommaaccent': 333,
  25749. 'logicalnot': 584,
  25750. 'odieresis': 611,
  25751. 'udieresis': 611,
  25752. 'notequal': 549,
  25753. 'gcommaaccent': 611,
  25754. 'eth': 611,
  25755. 'zcaron': 500,
  25756. 'ncommaaccent': 611,
  25757. 'onesuperior': 333,
  25758. 'imacron': 278,
  25759. 'Euro': 556
  25760. },
  25761. 'Helvetica-Oblique' : {
  25762. 'space': 278,
  25763. 'exclam': 278,
  25764. 'quotedbl': 355,
  25765. 'numbersign': 556,
  25766. 'dollar': 556,
  25767. 'percent': 889,
  25768. 'ampersand': 667,
  25769. 'quoteright': 222,
  25770. 'parenleft': 333,
  25771. 'parenright': 333,
  25772. 'asterisk': 389,
  25773. 'plus': 584,
  25774. 'comma': 278,
  25775. 'hyphen': 333,
  25776. 'period': 278,
  25777. 'slash': 278,
  25778. 'zero': 556,
  25779. 'one': 556,
  25780. 'two': 556,
  25781. 'three': 556,
  25782. 'four': 556,
  25783. 'five': 556,
  25784. 'six': 556,
  25785. 'seven': 556,
  25786. 'eight': 556,
  25787. 'nine': 556,
  25788. 'colon': 278,
  25789. 'semicolon': 278,
  25790. 'less': 584,
  25791. 'equal': 584,
  25792. 'greater': 584,
  25793. 'question': 556,
  25794. 'at': 1015,
  25795. 'A': 667,
  25796. 'B': 667,
  25797. 'C': 722,
  25798. 'D': 722,
  25799. 'E': 667,
  25800. 'F': 611,
  25801. 'G': 778,
  25802. 'H': 722,
  25803. 'I': 278,
  25804. 'J': 500,
  25805. 'K': 667,
  25806. 'L': 556,
  25807. 'M': 833,
  25808. 'N': 722,
  25809. 'O': 778,
  25810. 'P': 667,
  25811. 'Q': 778,
  25812. 'R': 722,
  25813. 'S': 667,
  25814. 'T': 611,
  25815. 'U': 722,
  25816. 'V': 667,
  25817. 'W': 944,
  25818. 'X': 667,
  25819. 'Y': 667,
  25820. 'Z': 611,
  25821. 'bracketleft': 278,
  25822. 'backslash': 278,
  25823. 'bracketright': 278,
  25824. 'asciicircum': 469,
  25825. 'underscore': 556,
  25826. 'quoteleft': 222,
  25827. 'a': 556,
  25828. 'b': 556,
  25829. 'c': 500,
  25830. 'd': 556,
  25831. 'e': 556,
  25832. 'f': 278,
  25833. 'g': 556,
  25834. 'h': 556,
  25835. 'i': 222,
  25836. 'j': 222,
  25837. 'k': 500,
  25838. 'l': 222,
  25839. 'm': 833,
  25840. 'n': 556,
  25841. 'o': 556,
  25842. 'p': 556,
  25843. 'q': 556,
  25844. 'r': 333,
  25845. 's': 500,
  25846. 't': 278,
  25847. 'u': 556,
  25848. 'v': 500,
  25849. 'w': 722,
  25850. 'x': 500,
  25851. 'y': 500,
  25852. 'z': 500,
  25853. 'braceleft': 334,
  25854. 'bar': 260,
  25855. 'braceright': 334,
  25856. 'asciitilde': 584,
  25857. 'exclamdown': 333,
  25858. 'cent': 556,
  25859. 'sterling': 556,
  25860. 'fraction': 167,
  25861. 'yen': 556,
  25862. 'florin': 556,
  25863. 'section': 556,
  25864. 'currency': 556,
  25865. 'quotesingle': 191,
  25866. 'quotedblleft': 333,
  25867. 'guillemotleft': 556,
  25868. 'guilsinglleft': 333,
  25869. 'guilsinglright': 333,
  25870. 'fi': 500,
  25871. 'fl': 500,
  25872. 'endash': 556,
  25873. 'dagger': 556,
  25874. 'daggerdbl': 556,
  25875. 'periodcentered': 278,
  25876. 'paragraph': 537,
  25877. 'bullet': 350,
  25878. 'quotesinglbase': 222,
  25879. 'quotedblbase': 333,
  25880. 'quotedblright': 333,
  25881. 'guillemotright': 556,
  25882. 'ellipsis': 1000,
  25883. 'perthousand': 1000,
  25884. 'questiondown': 611,
  25885. 'grave': 333,
  25886. 'acute': 333,
  25887. 'circumflex': 333,
  25888. 'tilde': 333,
  25889. 'macron': 333,
  25890. 'breve': 333,
  25891. 'dotaccent': 333,
  25892. 'dieresis': 333,
  25893. 'ring': 333,
  25894. 'cedilla': 333,
  25895. 'hungarumlaut': 333,
  25896. 'ogonek': 333,
  25897. 'caron': 333,
  25898. 'emdash': 1000,
  25899. 'AE': 1000,
  25900. 'ordfeminine': 370,
  25901. 'Lslash': 556,
  25902. 'Oslash': 778,
  25903. 'OE': 1000,
  25904. 'ordmasculine': 365,
  25905. 'ae': 889,
  25906. 'dotlessi': 278,
  25907. 'lslash': 222,
  25908. 'oslash': 611,
  25909. 'oe': 944,
  25910. 'germandbls': 611,
  25911. 'Idieresis': 278,
  25912. 'eacute': 556,
  25913. 'abreve': 556,
  25914. 'uhungarumlaut': 556,
  25915. 'ecaron': 556,
  25916. 'Ydieresis': 667,
  25917. 'divide': 584,
  25918. 'Yacute': 667,
  25919. 'Acircumflex': 667,
  25920. 'aacute': 556,
  25921. 'Ucircumflex': 722,
  25922. 'yacute': 500,
  25923. 'scommaaccent': 500,
  25924. 'ecircumflex': 556,
  25925. 'Uring': 722,
  25926. 'Udieresis': 722,
  25927. 'aogonek': 556,
  25928. 'Uacute': 722,
  25929. 'uogonek': 556,
  25930. 'Edieresis': 667,
  25931. 'Dcroat': 722,
  25932. 'commaaccent': 250,
  25933. 'copyright': 737,
  25934. 'Emacron': 667,
  25935. 'ccaron': 500,
  25936. 'aring': 556,
  25937. 'Ncommaaccent': 722,
  25938. 'lacute': 222,
  25939. 'agrave': 556,
  25940. 'Tcommaaccent': 611,
  25941. 'Cacute': 722,
  25942. 'atilde': 556,
  25943. 'Edotaccent': 667,
  25944. 'scaron': 500,
  25945. 'scedilla': 500,
  25946. 'iacute': 278,
  25947. 'lozenge': 471,
  25948. 'Rcaron': 722,
  25949. 'Gcommaaccent': 778,
  25950. 'ucircumflex': 556,
  25951. 'acircumflex': 556,
  25952. 'Amacron': 667,
  25953. 'rcaron': 333,
  25954. 'ccedilla': 500,
  25955. 'Zdotaccent': 611,
  25956. 'Thorn': 667,
  25957. 'Omacron': 778,
  25958. 'Racute': 722,
  25959. 'Sacute': 667,
  25960. 'dcaron': 643,
  25961. 'Umacron': 722,
  25962. 'uring': 556,
  25963. 'threesuperior': 333,
  25964. 'Ograve': 778,
  25965. 'Agrave': 667,
  25966. 'Abreve': 667,
  25967. 'multiply': 584,
  25968. 'uacute': 556,
  25969. 'Tcaron': 611,
  25970. 'partialdiff': 476,
  25971. 'ydieresis': 500,
  25972. 'Nacute': 722,
  25973. 'icircumflex': 278,
  25974. 'Ecircumflex': 667,
  25975. 'adieresis': 556,
  25976. 'edieresis': 556,
  25977. 'cacute': 500,
  25978. 'nacute': 556,
  25979. 'umacron': 556,
  25980. 'Ncaron': 722,
  25981. 'Iacute': 278,
  25982. 'plusminus': 584,
  25983. 'brokenbar': 260,
  25984. 'registered': 737,
  25985. 'Gbreve': 778,
  25986. 'Idotaccent': 278,
  25987. 'summation': 600,
  25988. 'Egrave': 667,
  25989. 'racute': 333,
  25990. 'omacron': 556,
  25991. 'Zacute': 611,
  25992. 'Zcaron': 611,
  25993. 'greaterequal': 549,
  25994. 'Eth': 722,
  25995. 'Ccedilla': 722,
  25996. 'lcommaaccent': 222,
  25997. 'tcaron': 317,
  25998. 'eogonek': 556,
  25999. 'Uogonek': 722,
  26000. 'Aacute': 667,
  26001. 'Adieresis': 667,
  26002. 'egrave': 556,
  26003. 'zacute': 500,
  26004. 'iogonek': 222,
  26005. 'Oacute': 778,
  26006. 'oacute': 556,
  26007. 'amacron': 556,
  26008. 'sacute': 500,
  26009. 'idieresis': 278,
  26010. 'Ocircumflex': 778,
  26011. 'Ugrave': 722,
  26012. 'Delta': 612,
  26013. 'thorn': 556,
  26014. 'twosuperior': 333,
  26015. 'Odieresis': 778,
  26016. 'mu': 556,
  26017. 'igrave': 278,
  26018. 'ohungarumlaut': 556,
  26019. 'Eogonek': 667,
  26020. 'dcroat': 556,
  26021. 'threequarters': 834,
  26022. 'Scedilla': 667,
  26023. 'lcaron': 299,
  26024. 'Kcommaaccent': 667,
  26025. 'Lacute': 556,
  26026. 'trademark': 1000,
  26027. 'edotaccent': 556,
  26028. 'Igrave': 278,
  26029. 'Imacron': 278,
  26030. 'Lcaron': 556,
  26031. 'onehalf': 834,
  26032. 'lessequal': 549,
  26033. 'ocircumflex': 556,
  26034. 'ntilde': 556,
  26035. 'Uhungarumlaut': 722,
  26036. 'Eacute': 667,
  26037. 'emacron': 556,
  26038. 'gbreve': 556,
  26039. 'onequarter': 834,
  26040. 'Scaron': 667,
  26041. 'Scommaaccent': 667,
  26042. 'Ohungarumlaut': 778,
  26043. 'degree': 400,
  26044. 'ograve': 556,
  26045. 'Ccaron': 722,
  26046. 'ugrave': 556,
  26047. 'radical': 453,
  26048. 'Dcaron': 722,
  26049. 'rcommaaccent': 333,
  26050. 'Ntilde': 722,
  26051. 'otilde': 556,
  26052. 'Rcommaaccent': 722,
  26053. 'Lcommaaccent': 556,
  26054. 'Atilde': 667,
  26055. 'Aogonek': 667,
  26056. 'Aring': 667,
  26057. 'Otilde': 778,
  26058. 'zdotaccent': 500,
  26059. 'Ecaron': 667,
  26060. 'Iogonek': 278,
  26061. 'kcommaaccent': 500,
  26062. 'minus': 584,
  26063. 'Icircumflex': 278,
  26064. 'ncaron': 556,
  26065. 'tcommaaccent': 278,
  26066. 'logicalnot': 584,
  26067. 'odieresis': 556,
  26068. 'udieresis': 556,
  26069. 'notequal': 549,
  26070. 'gcommaaccent': 556,
  26071. 'eth': 556,
  26072. 'zcaron': 500,
  26073. 'ncommaaccent': 556,
  26074. 'onesuperior': 333,
  26075. 'imacron': 278,
  26076. 'Euro': 556
  26077. },
  26078. 'Symbol': {
  26079. 'space': 250,
  26080. 'exclam': 333,
  26081. 'universal': 713,
  26082. 'numbersign': 500,
  26083. 'existential': 549,
  26084. 'percent': 833,
  26085. 'ampersand': 778,
  26086. 'suchthat': 439,
  26087. 'parenleft': 333,
  26088. 'parenright': 333,
  26089. 'asteriskmath': 500,
  26090. 'plus': 549,
  26091. 'comma': 250,
  26092. 'minus': 549,
  26093. 'period': 250,
  26094. 'slash': 278,
  26095. 'zero': 500,
  26096. 'one': 500,
  26097. 'two': 500,
  26098. 'three': 500,
  26099. 'four': 500,
  26100. 'five': 500,
  26101. 'six': 500,
  26102. 'seven': 500,
  26103. 'eight': 500,
  26104. 'nine': 500,
  26105. 'colon': 278,
  26106. 'semicolon': 278,
  26107. 'less': 549,
  26108. 'equal': 549,
  26109. 'greater': 549,
  26110. 'question': 444,
  26111. 'congruent': 549,
  26112. 'Alpha': 722,
  26113. 'Beta': 667,
  26114. 'Chi': 722,
  26115. 'Delta': 612,
  26116. 'Epsilon': 611,
  26117. 'Phi': 763,
  26118. 'Gamma': 603,
  26119. 'Eta': 722,
  26120. 'Iota': 333,
  26121. 'theta1': 631,
  26122. 'Kappa': 722,
  26123. 'Lambda': 686,
  26124. 'Mu': 889,
  26125. 'Nu': 722,
  26126. 'Omicron': 722,
  26127. 'Pi': 768,
  26128. 'Theta': 741,
  26129. 'Rho': 556,
  26130. 'Sigma': 592,
  26131. 'Tau': 611,
  26132. 'Upsilon': 690,
  26133. 'sigma1': 439,
  26134. 'Omega': 768,
  26135. 'Xi': 645,
  26136. 'Psi': 795,
  26137. 'Zeta': 611,
  26138. 'bracketleft': 333,
  26139. 'therefore': 863,
  26140. 'bracketright': 333,
  26141. 'perpendicular': 658,
  26142. 'underscore': 500,
  26143. 'radicalex': 500,
  26144. 'alpha': 631,
  26145. 'beta': 549,
  26146. 'chi': 549,
  26147. 'delta': 494,
  26148. 'epsilon': 439,
  26149. 'phi': 521,
  26150. 'gamma': 411,
  26151. 'eta': 603,
  26152. 'iota': 329,
  26153. 'phi1': 603,
  26154. 'kappa': 549,
  26155. 'lambda': 549,
  26156. 'mu': 576,
  26157. 'nu': 521,
  26158. 'omicron': 549,
  26159. 'pi': 549,
  26160. 'theta': 521,
  26161. 'rho': 549,
  26162. 'sigma': 603,
  26163. 'tau': 439,
  26164. 'upsilon': 576,
  26165. 'omega1': 713,
  26166. 'omega': 686,
  26167. 'xi': 493,
  26168. 'psi': 686,
  26169. 'zeta': 494,
  26170. 'braceleft': 480,
  26171. 'bar': 200,
  26172. 'braceright': 480,
  26173. 'similar': 549,
  26174. 'Euro': 750,
  26175. 'Upsilon1': 620,
  26176. 'minute': 247,
  26177. 'lessequal': 549,
  26178. 'fraction': 167,
  26179. 'infinity': 713,
  26180. 'florin': 500,
  26181. 'club': 753,
  26182. 'diamond': 753,
  26183. 'heart': 753,
  26184. 'spade': 753,
  26185. 'arrowboth': 1042,
  26186. 'arrowleft': 987,
  26187. 'arrowup': 603,
  26188. 'arrowright': 987,
  26189. 'arrowdown': 603,
  26190. 'degree': 400,
  26191. 'plusminus': 549,
  26192. 'second': 411,
  26193. 'greaterequal': 549,
  26194. 'multiply': 549,
  26195. 'proportional': 713,
  26196. 'partialdiff': 494,
  26197. 'bullet': 460,
  26198. 'divide': 549,
  26199. 'notequal': 549,
  26200. 'equivalence': 549,
  26201. 'approxequal': 549,
  26202. 'ellipsis': 1000,
  26203. 'arrowvertex': 603,
  26204. 'arrowhorizex': 1000,
  26205. 'carriagereturn': 658,
  26206. 'aleph': 823,
  26207. 'Ifraktur': 686,
  26208. 'Rfraktur': 795,
  26209. 'weierstrass': 987,
  26210. 'circlemultiply': 768,
  26211. 'circleplus': 768,
  26212. 'emptyset': 823,
  26213. 'intersection': 768,
  26214. 'union': 768,
  26215. 'propersuperset': 713,
  26216. 'reflexsuperset': 713,
  26217. 'notsubset': 713,
  26218. 'propersubset': 713,
  26219. 'reflexsubset': 713,
  26220. 'element': 713,
  26221. 'notelement': 713,
  26222. 'angle': 768,
  26223. 'gradient': 713,
  26224. 'registerserif': 790,
  26225. 'copyrightserif': 790,
  26226. 'trademarkserif': 890,
  26227. 'product': 823,
  26228. 'radical': 549,
  26229. 'dotmath': 250,
  26230. 'logicalnot': 713,
  26231. 'logicaland': 603,
  26232. 'logicalor': 603,
  26233. 'arrowdblboth': 1042,
  26234. 'arrowdblleft': 987,
  26235. 'arrowdblup': 603,
  26236. 'arrowdblright': 987,
  26237. 'arrowdbldown': 603,
  26238. 'lozenge': 494,
  26239. 'angleleft': 329,
  26240. 'registersans': 790,
  26241. 'copyrightsans': 790,
  26242. 'trademarksans': 786,
  26243. 'summation': 713,
  26244. 'parenlefttp': 384,
  26245. 'parenleftex': 384,
  26246. 'parenleftbt': 384,
  26247. 'bracketlefttp': 384,
  26248. 'bracketleftex': 384,
  26249. 'bracketleftbt': 384,
  26250. 'bracelefttp': 494,
  26251. 'braceleftmid': 494,
  26252. 'braceleftbt': 494,
  26253. 'braceex': 494,
  26254. 'angleright': 329,
  26255. 'integral': 274,
  26256. 'integraltp': 686,
  26257. 'integralex': 686,
  26258. 'integralbt': 686,
  26259. 'parenrighttp': 384,
  26260. 'parenrightex': 384,
  26261. 'parenrightbt': 384,
  26262. 'bracketrighttp': 384,
  26263. 'bracketrightex': 384,
  26264. 'bracketrightbt': 384,
  26265. 'bracerighttp': 494,
  26266. 'bracerightmid': 494,
  26267. 'bracerightbt': 494,
  26268. 'apple': 790
  26269. },
  26270. 'Times-Roman': {
  26271. 'space': 250,
  26272. 'exclam': 333,
  26273. 'quotedbl': 408,
  26274. 'numbersign': 500,
  26275. 'dollar': 500,
  26276. 'percent': 833,
  26277. 'ampersand': 778,
  26278. 'quoteright': 333,
  26279. 'parenleft': 333,
  26280. 'parenright': 333,
  26281. 'asterisk': 500,
  26282. 'plus': 564,
  26283. 'comma': 250,
  26284. 'hyphen': 333,
  26285. 'period': 250,
  26286. 'slash': 278,
  26287. 'zero': 500,
  26288. 'one': 500,
  26289. 'two': 500,
  26290. 'three': 500,
  26291. 'four': 500,
  26292. 'five': 500,
  26293. 'six': 500,
  26294. 'seven': 500,
  26295. 'eight': 500,
  26296. 'nine': 500,
  26297. 'colon': 278,
  26298. 'semicolon': 278,
  26299. 'less': 564,
  26300. 'equal': 564,
  26301. 'greater': 564,
  26302. 'question': 444,
  26303. 'at': 921,
  26304. 'A': 722,
  26305. 'B': 667,
  26306. 'C': 667,
  26307. 'D': 722,
  26308. 'E': 611,
  26309. 'F': 556,
  26310. 'G': 722,
  26311. 'H': 722,
  26312. 'I': 333,
  26313. 'J': 389,
  26314. 'K': 722,
  26315. 'L': 611,
  26316. 'M': 889,
  26317. 'N': 722,
  26318. 'O': 722,
  26319. 'P': 556,
  26320. 'Q': 722,
  26321. 'R': 667,
  26322. 'S': 556,
  26323. 'T': 611,
  26324. 'U': 722,
  26325. 'V': 722,
  26326. 'W': 944,
  26327. 'X': 722,
  26328. 'Y': 722,
  26329. 'Z': 611,
  26330. 'bracketleft': 333,
  26331. 'backslash': 278,
  26332. 'bracketright': 333,
  26333. 'asciicircum': 469,
  26334. 'underscore': 500,
  26335. 'quoteleft': 333,
  26336. 'a': 444,
  26337. 'b': 500,
  26338. 'c': 444,
  26339. 'd': 500,
  26340. 'e': 444,
  26341. 'f': 333,
  26342. 'g': 500,
  26343. 'h': 500,
  26344. 'i': 278,
  26345. 'j': 278,
  26346. 'k': 500,
  26347. 'l': 278,
  26348. 'm': 778,
  26349. 'n': 500,
  26350. 'o': 500,
  26351. 'p': 500,
  26352. 'q': 500,
  26353. 'r': 333,
  26354. 's': 389,
  26355. 't': 278,
  26356. 'u': 500,
  26357. 'v': 500,
  26358. 'w': 722,
  26359. 'x': 500,
  26360. 'y': 500,
  26361. 'z': 444,
  26362. 'braceleft': 480,
  26363. 'bar': 200,
  26364. 'braceright': 480,
  26365. 'asciitilde': 541,
  26366. 'exclamdown': 333,
  26367. 'cent': 500,
  26368. 'sterling': 500,
  26369. 'fraction': 167,
  26370. 'yen': 500,
  26371. 'florin': 500,
  26372. 'section': 500,
  26373. 'currency': 500,
  26374. 'quotesingle': 180,
  26375. 'quotedblleft': 444,
  26376. 'guillemotleft': 500,
  26377. 'guilsinglleft': 333,
  26378. 'guilsinglright': 333,
  26379. 'fi': 556,
  26380. 'fl': 556,
  26381. 'endash': 500,
  26382. 'dagger': 500,
  26383. 'daggerdbl': 500,
  26384. 'periodcentered': 250,
  26385. 'paragraph': 453,
  26386. 'bullet': 350,
  26387. 'quotesinglbase': 333,
  26388. 'quotedblbase': 444,
  26389. 'quotedblright': 444,
  26390. 'guillemotright': 500,
  26391. 'ellipsis': 1000,
  26392. 'perthousand': 1000,
  26393. 'questiondown': 444,
  26394. 'grave': 333,
  26395. 'acute': 333,
  26396. 'circumflex': 333,
  26397. 'tilde': 333,
  26398. 'macron': 333,
  26399. 'breve': 333,
  26400. 'dotaccent': 333,
  26401. 'dieresis': 333,
  26402. 'ring': 333,
  26403. 'cedilla': 333,
  26404. 'hungarumlaut': 333,
  26405. 'ogonek': 333,
  26406. 'caron': 333,
  26407. 'emdash': 1000,
  26408. 'AE': 889,
  26409. 'ordfeminine': 276,
  26410. 'Lslash': 611,
  26411. 'Oslash': 722,
  26412. 'OE': 889,
  26413. 'ordmasculine': 310,
  26414. 'ae': 667,
  26415. 'dotlessi': 278,
  26416. 'lslash': 278,
  26417. 'oslash': 500,
  26418. 'oe': 722,
  26419. 'germandbls': 500,
  26420. 'Idieresis': 333,
  26421. 'eacute': 444,
  26422. 'abreve': 444,
  26423. 'uhungarumlaut': 500,
  26424. 'ecaron': 444,
  26425. 'Ydieresis': 722,
  26426. 'divide': 564,
  26427. 'Yacute': 722,
  26428. 'Acircumflex': 722,
  26429. 'aacute': 444,
  26430. 'Ucircumflex': 722,
  26431. 'yacute': 500,
  26432. 'scommaaccent': 389,
  26433. 'ecircumflex': 444,
  26434. 'Uring': 722,
  26435. 'Udieresis': 722,
  26436. 'aogonek': 444,
  26437. 'Uacute': 722,
  26438. 'uogonek': 500,
  26439. 'Edieresis': 611,
  26440. 'Dcroat': 722,
  26441. 'commaaccent': 250,
  26442. 'copyright': 760,
  26443. 'Emacron': 611,
  26444. 'ccaron': 444,
  26445. 'aring': 444,
  26446. 'Ncommaaccent': 722,
  26447. 'lacute': 278,
  26448. 'agrave': 444,
  26449. 'Tcommaaccent': 611,
  26450. 'Cacute': 667,
  26451. 'atilde': 444,
  26452. 'Edotaccent': 611,
  26453. 'scaron': 389,
  26454. 'scedilla': 389,
  26455. 'iacute': 278,
  26456. 'lozenge': 471,
  26457. 'Rcaron': 667,
  26458. 'Gcommaaccent': 722,
  26459. 'ucircumflex': 500,
  26460. 'acircumflex': 444,
  26461. 'Amacron': 722,
  26462. 'rcaron': 333,
  26463. 'ccedilla': 444,
  26464. 'Zdotaccent': 611,
  26465. 'Thorn': 556,
  26466. 'Omacron': 722,
  26467. 'Racute': 667,
  26468. 'Sacute': 556,
  26469. 'dcaron': 588,
  26470. 'Umacron': 722,
  26471. 'uring': 500,
  26472. 'threesuperior': 300,
  26473. 'Ograve': 722,
  26474. 'Agrave': 722,
  26475. 'Abreve': 722,
  26476. 'multiply': 564,
  26477. 'uacute': 500,
  26478. 'Tcaron': 611,
  26479. 'partialdiff': 476,
  26480. 'ydieresis': 500,
  26481. 'Nacute': 722,
  26482. 'icircumflex': 278,
  26483. 'Ecircumflex': 611,
  26484. 'adieresis': 444,
  26485. 'edieresis': 444,
  26486. 'cacute': 444,
  26487. 'nacute': 500,
  26488. 'umacron': 500,
  26489. 'Ncaron': 722,
  26490. 'Iacute': 333,
  26491. 'plusminus': 564,
  26492. 'brokenbar': 200,
  26493. 'registered': 760,
  26494. 'Gbreve': 722,
  26495. 'Idotaccent': 333,
  26496. 'summation': 600,
  26497. 'Egrave': 611,
  26498. 'racute': 333,
  26499. 'omacron': 500,
  26500. 'Zacute': 611,
  26501. 'Zcaron': 611,
  26502. 'greaterequal': 549,
  26503. 'Eth': 722,
  26504. 'Ccedilla': 667,
  26505. 'lcommaaccent': 278,
  26506. 'tcaron': 326,
  26507. 'eogonek': 444,
  26508. 'Uogonek': 722,
  26509. 'Aacute': 722,
  26510. 'Adieresis': 722,
  26511. 'egrave': 444,
  26512. 'zacute': 444,
  26513. 'iogonek': 278,
  26514. 'Oacute': 722,
  26515. 'oacute': 500,
  26516. 'amacron': 444,
  26517. 'sacute': 389,
  26518. 'idieresis': 278,
  26519. 'Ocircumflex': 722,
  26520. 'Ugrave': 722,
  26521. 'Delta': 612,
  26522. 'thorn': 500,
  26523. 'twosuperior': 300,
  26524. 'Odieresis': 722,
  26525. 'mu': 500,
  26526. 'igrave': 278,
  26527. 'ohungarumlaut': 500,
  26528. 'Eogonek': 611,
  26529. 'dcroat': 500,
  26530. 'threequarters': 750,
  26531. 'Scedilla': 556,
  26532. 'lcaron': 344,
  26533. 'Kcommaaccent': 722,
  26534. 'Lacute': 611,
  26535. 'trademark': 980,
  26536. 'edotaccent': 444,
  26537. 'Igrave': 333,
  26538. 'Imacron': 333,
  26539. 'Lcaron': 611,
  26540. 'onehalf': 750,
  26541. 'lessequal': 549,
  26542. 'ocircumflex': 500,
  26543. 'ntilde': 500,
  26544. 'Uhungarumlaut': 722,
  26545. 'Eacute': 611,
  26546. 'emacron': 444,
  26547. 'gbreve': 500,
  26548. 'onequarter': 750,
  26549. 'Scaron': 556,
  26550. 'Scommaaccent': 556,
  26551. 'Ohungarumlaut': 722,
  26552. 'degree': 400,
  26553. 'ograve': 500,
  26554. 'Ccaron': 667,
  26555. 'ugrave': 500,
  26556. 'radical': 453,
  26557. 'Dcaron': 722,
  26558. 'rcommaaccent': 333,
  26559. 'Ntilde': 722,
  26560. 'otilde': 500,
  26561. 'Rcommaaccent': 667,
  26562. 'Lcommaaccent': 611,
  26563. 'Atilde': 722,
  26564. 'Aogonek': 722,
  26565. 'Aring': 722,
  26566. 'Otilde': 722,
  26567. 'zdotaccent': 444,
  26568. 'Ecaron': 611,
  26569. 'Iogonek': 333,
  26570. 'kcommaaccent': 500,
  26571. 'minus': 564,
  26572. 'Icircumflex': 333,
  26573. 'ncaron': 500,
  26574. 'tcommaaccent': 278,
  26575. 'logicalnot': 564,
  26576. 'odieresis': 500,
  26577. 'udieresis': 500,
  26578. 'notequal': 549,
  26579. 'gcommaaccent': 500,
  26580. 'eth': 500,
  26581. 'zcaron': 444,
  26582. 'ncommaaccent': 500,
  26583. 'onesuperior': 300,
  26584. 'imacron': 278,
  26585. 'Euro': 500
  26586. },
  26587. 'Times-Bold': {
  26588. 'space': 250,
  26589. 'exclam': 333,
  26590. 'quotedbl': 555,
  26591. 'numbersign': 500,
  26592. 'dollar': 500,
  26593. 'percent': 1000,
  26594. 'ampersand': 833,
  26595. 'quoteright': 333,
  26596. 'parenleft': 333,
  26597. 'parenright': 333,
  26598. 'asterisk': 500,
  26599. 'plus': 570,
  26600. 'comma': 250,
  26601. 'hyphen': 333,
  26602. 'period': 250,
  26603. 'slash': 278,
  26604. 'zero': 500,
  26605. 'one': 500,
  26606. 'two': 500,
  26607. 'three': 500,
  26608. 'four': 500,
  26609. 'five': 500,
  26610. 'six': 500,
  26611. 'seven': 500,
  26612. 'eight': 500,
  26613. 'nine': 500,
  26614. 'colon': 333,
  26615. 'semicolon': 333,
  26616. 'less': 570,
  26617. 'equal': 570,
  26618. 'greater': 570,
  26619. 'question': 500,
  26620. 'at': 930,
  26621. 'A': 722,
  26622. 'B': 667,
  26623. 'C': 722,
  26624. 'D': 722,
  26625. 'E': 667,
  26626. 'F': 611,
  26627. 'G': 778,
  26628. 'H': 778,
  26629. 'I': 389,
  26630. 'J': 500,
  26631. 'K': 778,
  26632. 'L': 667,
  26633. 'M': 944,
  26634. 'N': 722,
  26635. 'O': 778,
  26636. 'P': 611,
  26637. 'Q': 778,
  26638. 'R': 722,
  26639. 'S': 556,
  26640. 'T': 667,
  26641. 'U': 722,
  26642. 'V': 722,
  26643. 'W': 1000,
  26644. 'X': 722,
  26645. 'Y': 722,
  26646. 'Z': 667,
  26647. 'bracketleft': 333,
  26648. 'backslash': 278,
  26649. 'bracketright': 333,
  26650. 'asciicircum': 581,
  26651. 'underscore': 500,
  26652. 'quoteleft': 333,
  26653. 'a': 500,
  26654. 'b': 556,
  26655. 'c': 444,
  26656. 'd': 556,
  26657. 'e': 444,
  26658. 'f': 333,
  26659. 'g': 500,
  26660. 'h': 556,
  26661. 'i': 278,
  26662. 'j': 333,
  26663. 'k': 556,
  26664. 'l': 278,
  26665. 'm': 833,
  26666. 'n': 556,
  26667. 'o': 500,
  26668. 'p': 556,
  26669. 'q': 556,
  26670. 'r': 444,
  26671. 's': 389,
  26672. 't': 333,
  26673. 'u': 556,
  26674. 'v': 500,
  26675. 'w': 722,
  26676. 'x': 500,
  26677. 'y': 500,
  26678. 'z': 444,
  26679. 'braceleft': 394,
  26680. 'bar': 220,
  26681. 'braceright': 394,
  26682. 'asciitilde': 520,
  26683. 'exclamdown': 333,
  26684. 'cent': 500,
  26685. 'sterling': 500,
  26686. 'fraction': 167,
  26687. 'yen': 500,
  26688. 'florin': 500,
  26689. 'section': 500,
  26690. 'currency': 500,
  26691. 'quotesingle': 278,
  26692. 'quotedblleft': 500,
  26693. 'guillemotleft': 500,
  26694. 'guilsinglleft': 333,
  26695. 'guilsinglright': 333,
  26696. 'fi': 556,
  26697. 'fl': 556,
  26698. 'endash': 500,
  26699. 'dagger': 500,
  26700. 'daggerdbl': 500,
  26701. 'periodcentered': 250,
  26702. 'paragraph': 540,
  26703. 'bullet': 350,
  26704. 'quotesinglbase': 333,
  26705. 'quotedblbase': 500,
  26706. 'quotedblright': 500,
  26707. 'guillemotright': 500,
  26708. 'ellipsis': 1000,
  26709. 'perthousand': 1000,
  26710. 'questiondown': 500,
  26711. 'grave': 333,
  26712. 'acute': 333,
  26713. 'circumflex': 333,
  26714. 'tilde': 333,
  26715. 'macron': 333,
  26716. 'breve': 333,
  26717. 'dotaccent': 333,
  26718. 'dieresis': 333,
  26719. 'ring': 333,
  26720. 'cedilla': 333,
  26721. 'hungarumlaut': 333,
  26722. 'ogonek': 333,
  26723. 'caron': 333,
  26724. 'emdash': 1000,
  26725. 'AE': 1000,
  26726. 'ordfeminine': 300,
  26727. 'Lslash': 667,
  26728. 'Oslash': 778,
  26729. 'OE': 1000,
  26730. 'ordmasculine': 330,
  26731. 'ae': 722,
  26732. 'dotlessi': 278,
  26733. 'lslash': 278,
  26734. 'oslash': 500,
  26735. 'oe': 722,
  26736. 'germandbls': 556,
  26737. 'Idieresis': 389,
  26738. 'eacute': 444,
  26739. 'abreve': 500,
  26740. 'uhungarumlaut': 556,
  26741. 'ecaron': 444,
  26742. 'Ydieresis': 722,
  26743. 'divide': 570,
  26744. 'Yacute': 722,
  26745. 'Acircumflex': 722,
  26746. 'aacute': 500,
  26747. 'Ucircumflex': 722,
  26748. 'yacute': 500,
  26749. 'scommaaccent': 389,
  26750. 'ecircumflex': 444,
  26751. 'Uring': 722,
  26752. 'Udieresis': 722,
  26753. 'aogonek': 500,
  26754. 'Uacute': 722,
  26755. 'uogonek': 556,
  26756. 'Edieresis': 667,
  26757. 'Dcroat': 722,
  26758. 'commaaccent': 250,
  26759. 'copyright': 747,
  26760. 'Emacron': 667,
  26761. 'ccaron': 444,
  26762. 'aring': 500,
  26763. 'Ncommaaccent': 722,
  26764. 'lacute': 278,
  26765. 'agrave': 500,
  26766. 'Tcommaaccent': 667,
  26767. 'Cacute': 722,
  26768. 'atilde': 500,
  26769. 'Edotaccent': 667,
  26770. 'scaron': 389,
  26771. 'scedilla': 389,
  26772. 'iacute': 278,
  26773. 'lozenge': 494,
  26774. 'Rcaron': 722,
  26775. 'Gcommaaccent': 778,
  26776. 'ucircumflex': 556,
  26777. 'acircumflex': 500,
  26778. 'Amacron': 722,
  26779. 'rcaron': 444,
  26780. 'ccedilla': 444,
  26781. 'Zdotaccent': 667,
  26782. 'Thorn': 611,
  26783. 'Omacron': 778,
  26784. 'Racute': 722,
  26785. 'Sacute': 556,
  26786. 'dcaron': 672,
  26787. 'Umacron': 722,
  26788. 'uring': 556,
  26789. 'threesuperior': 300,
  26790. 'Ograve': 778,
  26791. 'Agrave': 722,
  26792. 'Abreve': 722,
  26793. 'multiply': 570,
  26794. 'uacute': 556,
  26795. 'Tcaron': 667,
  26796. 'partialdiff': 494,
  26797. 'ydieresis': 500,
  26798. 'Nacute': 722,
  26799. 'icircumflex': 278,
  26800. 'Ecircumflex': 667,
  26801. 'adieresis': 500,
  26802. 'edieresis': 444,
  26803. 'cacute': 444,
  26804. 'nacute': 556,
  26805. 'umacron': 556,
  26806. 'Ncaron': 722,
  26807. 'Iacute': 389,
  26808. 'plusminus': 570,
  26809. 'brokenbar': 220,
  26810. 'registered': 747,
  26811. 'Gbreve': 778,
  26812. 'Idotaccent': 389,
  26813. 'summation': 600,
  26814. 'Egrave': 667,
  26815. 'racute': 444,
  26816. 'omacron': 500,
  26817. 'Zacute': 667,
  26818. 'Zcaron': 667,
  26819. 'greaterequal': 549,
  26820. 'Eth': 722,
  26821. 'Ccedilla': 722,
  26822. 'lcommaaccent': 278,
  26823. 'tcaron': 416,
  26824. 'eogonek': 444,
  26825. 'Uogonek': 722,
  26826. 'Aacute': 722,
  26827. 'Adieresis': 722,
  26828. 'egrave': 444,
  26829. 'zacute': 444,
  26830. 'iogonek': 278,
  26831. 'Oacute': 778,
  26832. 'oacute': 500,
  26833. 'amacron': 500,
  26834. 'sacute': 389,
  26835. 'idieresis': 278,
  26836. 'Ocircumflex': 778,
  26837. 'Ugrave': 722,
  26838. 'Delta': 612,
  26839. 'thorn': 556,
  26840. 'twosuperior': 300,
  26841. 'Odieresis': 778,
  26842. 'mu': 556,
  26843. 'igrave': 278,
  26844. 'ohungarumlaut': 500,
  26845. 'Eogonek': 667,
  26846. 'dcroat': 556,
  26847. 'threequarters': 750,
  26848. 'Scedilla': 556,
  26849. 'lcaron': 394,
  26850. 'Kcommaaccent': 778,
  26851. 'Lacute': 667,
  26852. 'trademark': 1000,
  26853. 'edotaccent': 444,
  26854. 'Igrave': 389,
  26855. 'Imacron': 389,
  26856. 'Lcaron': 667,
  26857. 'onehalf': 750,
  26858. 'lessequal': 549,
  26859. 'ocircumflex': 500,
  26860. 'ntilde': 556,
  26861. 'Uhungarumlaut': 722,
  26862. 'Eacute': 667,
  26863. 'emacron': 444,
  26864. 'gbreve': 500,
  26865. 'onequarter': 750,
  26866. 'Scaron': 556,
  26867. 'Scommaaccent': 556,
  26868. 'Ohungarumlaut': 778,
  26869. 'degree': 400,
  26870. 'ograve': 500,
  26871. 'Ccaron': 722,
  26872. 'ugrave': 556,
  26873. 'radical': 549,
  26874. 'Dcaron': 722,
  26875. 'rcommaaccent': 444,
  26876. 'Ntilde': 722,
  26877. 'otilde': 500,
  26878. 'Rcommaaccent': 722,
  26879. 'Lcommaaccent': 667,
  26880. 'Atilde': 722,
  26881. 'Aogonek': 722,
  26882. 'Aring': 722,
  26883. 'Otilde': 778,
  26884. 'zdotaccent': 444,
  26885. 'Ecaron': 667,
  26886. 'Iogonek': 389,
  26887. 'kcommaaccent': 556,
  26888. 'minus': 570,
  26889. 'Icircumflex': 389,
  26890. 'ncaron': 556,
  26891. 'tcommaaccent': 333,
  26892. 'logicalnot': 570,
  26893. 'odieresis': 500,
  26894. 'udieresis': 556,
  26895. 'notequal': 549,
  26896. 'gcommaaccent': 500,
  26897. 'eth': 500,
  26898. 'zcaron': 444,
  26899. 'ncommaaccent': 556,
  26900. 'onesuperior': 300,
  26901. 'imacron': 278,
  26902. 'Euro': 500
  26903. },
  26904. 'Times-BoldItalic': {
  26905. 'space': 250,
  26906. 'exclam': 389,
  26907. 'quotedbl': 555,
  26908. 'numbersign': 500,
  26909. 'dollar': 500,
  26910. 'percent': 833,
  26911. 'ampersand': 778,
  26912. 'quoteright': 333,
  26913. 'parenleft': 333,
  26914. 'parenright': 333,
  26915. 'asterisk': 500,
  26916. 'plus': 570,
  26917. 'comma': 250,
  26918. 'hyphen': 333,
  26919. 'period': 250,
  26920. 'slash': 278,
  26921. 'zero': 500,
  26922. 'one': 500,
  26923. 'two': 500,
  26924. 'three': 500,
  26925. 'four': 500,
  26926. 'five': 500,
  26927. 'six': 500,
  26928. 'seven': 500,
  26929. 'eight': 500,
  26930. 'nine': 500,
  26931. 'colon': 333,
  26932. 'semicolon': 333,
  26933. 'less': 570,
  26934. 'equal': 570,
  26935. 'greater': 570,
  26936. 'question': 500,
  26937. 'at': 832,
  26938. 'A': 667,
  26939. 'B': 667,
  26940. 'C': 667,
  26941. 'D': 722,
  26942. 'E': 667,
  26943. 'F': 667,
  26944. 'G': 722,
  26945. 'H': 778,
  26946. 'I': 389,
  26947. 'J': 500,
  26948. 'K': 667,
  26949. 'L': 611,
  26950. 'M': 889,
  26951. 'N': 722,
  26952. 'O': 722,
  26953. 'P': 611,
  26954. 'Q': 722,
  26955. 'R': 667,
  26956. 'S': 556,
  26957. 'T': 611,
  26958. 'U': 722,
  26959. 'V': 667,
  26960. 'W': 889,
  26961. 'X': 667,
  26962. 'Y': 611,
  26963. 'Z': 611,
  26964. 'bracketleft': 333,
  26965. 'backslash': 278,
  26966. 'bracketright': 333,
  26967. 'asciicircum': 570,
  26968. 'underscore': 500,
  26969. 'quoteleft': 333,
  26970. 'a': 500,
  26971. 'b': 500,
  26972. 'c': 444,
  26973. 'd': 500,
  26974. 'e': 444,
  26975. 'f': 333,
  26976. 'g': 500,
  26977. 'h': 556,
  26978. 'i': 278,
  26979. 'j': 278,
  26980. 'k': 500,
  26981. 'l': 278,
  26982. 'm': 778,
  26983. 'n': 556,
  26984. 'o': 500,
  26985. 'p': 500,
  26986. 'q': 500,
  26987. 'r': 389,
  26988. 's': 389,
  26989. 't': 278,
  26990. 'u': 556,
  26991. 'v': 444,
  26992. 'w': 667,
  26993. 'x': 500,
  26994. 'y': 444,
  26995. 'z': 389,
  26996. 'braceleft': 348,
  26997. 'bar': 220,
  26998. 'braceright': 348,
  26999. 'asciitilde': 570,
  27000. 'exclamdown': 389,
  27001. 'cent': 500,
  27002. 'sterling': 500,
  27003. 'fraction': 167,
  27004. 'yen': 500,
  27005. 'florin': 500,
  27006. 'section': 500,
  27007. 'currency': 500,
  27008. 'quotesingle': 278,
  27009. 'quotedblleft': 500,
  27010. 'guillemotleft': 500,
  27011. 'guilsinglleft': 333,
  27012. 'guilsinglright': 333,
  27013. 'fi': 556,
  27014. 'fl': 556,
  27015. 'endash': 500,
  27016. 'dagger': 500,
  27017. 'daggerdbl': 500,
  27018. 'periodcentered': 250,
  27019. 'paragraph': 500,
  27020. 'bullet': 350,
  27021. 'quotesinglbase': 333,
  27022. 'quotedblbase': 500,
  27023. 'quotedblright': 500,
  27024. 'guillemotright': 500,
  27025. 'ellipsis': 1000,
  27026. 'perthousand': 1000,
  27027. 'questiondown': 500,
  27028. 'grave': 333,
  27029. 'acute': 333,
  27030. 'circumflex': 333,
  27031. 'tilde': 333,
  27032. 'macron': 333,
  27033. 'breve': 333,
  27034. 'dotaccent': 333,
  27035. 'dieresis': 333,
  27036. 'ring': 333,
  27037. 'cedilla': 333,
  27038. 'hungarumlaut': 333,
  27039. 'ogonek': 333,
  27040. 'caron': 333,
  27041. 'emdash': 1000,
  27042. 'AE': 944,
  27043. 'ordfeminine': 266,
  27044. 'Lslash': 611,
  27045. 'Oslash': 722,
  27046. 'OE': 944,
  27047. 'ordmasculine': 300,
  27048. 'ae': 722,
  27049. 'dotlessi': 278,
  27050. 'lslash': 278,
  27051. 'oslash': 500,
  27052. 'oe': 722,
  27053. 'germandbls': 500,
  27054. 'Idieresis': 389,
  27055. 'eacute': 444,
  27056. 'abreve': 500,
  27057. 'uhungarumlaut': 556,
  27058. 'ecaron': 444,
  27059. 'Ydieresis': 611,
  27060. 'divide': 570,
  27061. 'Yacute': 611,
  27062. 'Acircumflex': 667,
  27063. 'aacute': 500,
  27064. 'Ucircumflex': 722,
  27065. 'yacute': 444,
  27066. 'scommaaccent': 389,
  27067. 'ecircumflex': 444,
  27068. 'Uring': 722,
  27069. 'Udieresis': 722,
  27070. 'aogonek': 500,
  27071. 'Uacute': 722,
  27072. 'uogonek': 556,
  27073. 'Edieresis': 667,
  27074. 'Dcroat': 722,
  27075. 'commaaccent': 250,
  27076. 'copyright': 747,
  27077. 'Emacron': 667,
  27078. 'ccaron': 444,
  27079. 'aring': 500,
  27080. 'Ncommaaccent': 722,
  27081. 'lacute': 278,
  27082. 'agrave': 500,
  27083. 'Tcommaaccent': 611,
  27084. 'Cacute': 667,
  27085. 'atilde': 500,
  27086. 'Edotaccent': 667,
  27087. 'scaron': 389,
  27088. 'scedilla': 389,
  27089. 'iacute': 278,
  27090. 'lozenge': 494,
  27091. 'Rcaron': 667,
  27092. 'Gcommaaccent': 722,
  27093. 'ucircumflex': 556,
  27094. 'acircumflex': 500,
  27095. 'Amacron': 667,
  27096. 'rcaron': 389,
  27097. 'ccedilla': 444,
  27098. 'Zdotaccent': 611,
  27099. 'Thorn': 611,
  27100. 'Omacron': 722,
  27101. 'Racute': 667,
  27102. 'Sacute': 556,
  27103. 'dcaron': 608,
  27104. 'Umacron': 722,
  27105. 'uring': 556,
  27106. 'threesuperior': 300,
  27107. 'Ograve': 722,
  27108. 'Agrave': 667,
  27109. 'Abreve': 667,
  27110. 'multiply': 570,
  27111. 'uacute': 556,
  27112. 'Tcaron': 611,
  27113. 'partialdiff': 494,
  27114. 'ydieresis': 444,
  27115. 'Nacute': 722,
  27116. 'icircumflex': 278,
  27117. 'Ecircumflex': 667,
  27118. 'adieresis': 500,
  27119. 'edieresis': 444,
  27120. 'cacute': 444,
  27121. 'nacute': 556,
  27122. 'umacron': 556,
  27123. 'Ncaron': 722,
  27124. 'Iacute': 389,
  27125. 'plusminus': 570,
  27126. 'brokenbar': 220,
  27127. 'registered': 747,
  27128. 'Gbreve': 722,
  27129. 'Idotaccent': 389,
  27130. 'summation': 600,
  27131. 'Egrave': 667,
  27132. 'racute': 389,
  27133. 'omacron': 500,
  27134. 'Zacute': 611,
  27135. 'Zcaron': 611,
  27136. 'greaterequal': 549,
  27137. 'Eth': 722,
  27138. 'Ccedilla': 667,
  27139. 'lcommaaccent': 278,
  27140. 'tcaron': 366,
  27141. 'eogonek': 444,
  27142. 'Uogonek': 722,
  27143. 'Aacute': 667,
  27144. 'Adieresis': 667,
  27145. 'egrave': 444,
  27146. 'zacute': 389,
  27147. 'iogonek': 278,
  27148. 'Oacute': 722,
  27149. 'oacute': 500,
  27150. 'amacron': 500,
  27151. 'sacute': 389,
  27152. 'idieresis': 278,
  27153. 'Ocircumflex': 722,
  27154. 'Ugrave': 722,
  27155. 'Delta': 612,
  27156. 'thorn': 500,
  27157. 'twosuperior': 300,
  27158. 'Odieresis': 722,
  27159. 'mu': 576,
  27160. 'igrave': 278,
  27161. 'ohungarumlaut': 500,
  27162. 'Eogonek': 667,
  27163. 'dcroat': 500,
  27164. 'threequarters': 750,
  27165. 'Scedilla': 556,
  27166. 'lcaron': 382,
  27167. 'Kcommaaccent': 667,
  27168. 'Lacute': 611,
  27169. 'trademark': 1000,
  27170. 'edotaccent': 444,
  27171. 'Igrave': 389,
  27172. 'Imacron': 389,
  27173. 'Lcaron': 611,
  27174. 'onehalf': 750,
  27175. 'lessequal': 549,
  27176. 'ocircumflex': 500,
  27177. 'ntilde': 556,
  27178. 'Uhungarumlaut': 722,
  27179. 'Eacute': 667,
  27180. 'emacron': 444,
  27181. 'gbreve': 500,
  27182. 'onequarter': 750,
  27183. 'Scaron': 556,
  27184. 'Scommaaccent': 556,
  27185. 'Ohungarumlaut': 722,
  27186. 'degree': 400,
  27187. 'ograve': 500,
  27188. 'Ccaron': 667,
  27189. 'ugrave': 556,
  27190. 'radical': 549,
  27191. 'Dcaron': 722,
  27192. 'rcommaaccent': 389,
  27193. 'Ntilde': 722,
  27194. 'otilde': 500,
  27195. 'Rcommaaccent': 667,
  27196. 'Lcommaaccent': 611,
  27197. 'Atilde': 667,
  27198. 'Aogonek': 667,
  27199. 'Aring': 667,
  27200. 'Otilde': 722,
  27201. 'zdotaccent': 389,
  27202. 'Ecaron': 667,
  27203. 'Iogonek': 389,
  27204. 'kcommaaccent': 500,
  27205. 'minus': 606,
  27206. 'Icircumflex': 389,
  27207. 'ncaron': 556,
  27208. 'tcommaaccent': 278,
  27209. 'logicalnot': 606,
  27210. 'odieresis': 500,
  27211. 'udieresis': 556,
  27212. 'notequal': 549,
  27213. 'gcommaaccent': 500,
  27214. 'eth': 500,
  27215. 'zcaron': 389,
  27216. 'ncommaaccent': 556,
  27217. 'onesuperior': 300,
  27218. 'imacron': 278,
  27219. 'Euro': 500
  27220. },
  27221. 'Times-Italic': {
  27222. 'space': 250,
  27223. 'exclam': 333,
  27224. 'quotedbl': 420,
  27225. 'numbersign': 500,
  27226. 'dollar': 500,
  27227. 'percent': 833,
  27228. 'ampersand': 778,
  27229. 'quoteright': 333,
  27230. 'parenleft': 333,
  27231. 'parenright': 333,
  27232. 'asterisk': 500,
  27233. 'plus': 675,
  27234. 'comma': 250,
  27235. 'hyphen': 333,
  27236. 'period': 250,
  27237. 'slash': 278,
  27238. 'zero': 500,
  27239. 'one': 500,
  27240. 'two': 500,
  27241. 'three': 500,
  27242. 'four': 500,
  27243. 'five': 500,
  27244. 'six': 500,
  27245. 'seven': 500,
  27246. 'eight': 500,
  27247. 'nine': 500,
  27248. 'colon': 333,
  27249. 'semicolon': 333,
  27250. 'less': 675,
  27251. 'equal': 675,
  27252. 'greater': 675,
  27253. 'question': 500,
  27254. 'at': 920,
  27255. 'A': 611,
  27256. 'B': 611,
  27257. 'C': 667,
  27258. 'D': 722,
  27259. 'E': 611,
  27260. 'F': 611,
  27261. 'G': 722,
  27262. 'H': 722,
  27263. 'I': 333,
  27264. 'J': 444,
  27265. 'K': 667,
  27266. 'L': 556,
  27267. 'M': 833,
  27268. 'N': 667,
  27269. 'O': 722,
  27270. 'P': 611,
  27271. 'Q': 722,
  27272. 'R': 611,
  27273. 'S': 500,
  27274. 'T': 556,
  27275. 'U': 722,
  27276. 'V': 611,
  27277. 'W': 833,
  27278. 'X': 611,
  27279. 'Y': 556,
  27280. 'Z': 556,
  27281. 'bracketleft': 389,
  27282. 'backslash': 278,
  27283. 'bracketright': 389,
  27284. 'asciicircum': 422,
  27285. 'underscore': 500,
  27286. 'quoteleft': 333,
  27287. 'a': 500,
  27288. 'b': 500,
  27289. 'c': 444,
  27290. 'd': 500,
  27291. 'e': 444,
  27292. 'f': 278,
  27293. 'g': 500,
  27294. 'h': 500,
  27295. 'i': 278,
  27296. 'j': 278,
  27297. 'k': 444,
  27298. 'l': 278,
  27299. 'm': 722,
  27300. 'n': 500,
  27301. 'o': 500,
  27302. 'p': 500,
  27303. 'q': 500,
  27304. 'r': 389,
  27305. 's': 389,
  27306. 't': 278,
  27307. 'u': 500,
  27308. 'v': 444,
  27309. 'w': 667,
  27310. 'x': 444,
  27311. 'y': 444,
  27312. 'z': 389,
  27313. 'braceleft': 400,
  27314. 'bar': 275,
  27315. 'braceright': 400,
  27316. 'asciitilde': 541,
  27317. 'exclamdown': 389,
  27318. 'cent': 500,
  27319. 'sterling': 500,
  27320. 'fraction': 167,
  27321. 'yen': 500,
  27322. 'florin': 500,
  27323. 'section': 500,
  27324. 'currency': 500,
  27325. 'quotesingle': 214,
  27326. 'quotedblleft': 556,
  27327. 'guillemotleft': 500,
  27328. 'guilsinglleft': 333,
  27329. 'guilsinglright': 333,
  27330. 'fi': 500,
  27331. 'fl': 500,
  27332. 'endash': 500,
  27333. 'dagger': 500,
  27334. 'daggerdbl': 500,
  27335. 'periodcentered': 250,
  27336. 'paragraph': 523,
  27337. 'bullet': 350,
  27338. 'quotesinglbase': 333,
  27339. 'quotedblbase': 556,
  27340. 'quotedblright': 556,
  27341. 'guillemotright': 500,
  27342. 'ellipsis': 889,
  27343. 'perthousand': 1000,
  27344. 'questiondown': 500,
  27345. 'grave': 333,
  27346. 'acute': 333,
  27347. 'circumflex': 333,
  27348. 'tilde': 333,
  27349. 'macron': 333,
  27350. 'breve': 333,
  27351. 'dotaccent': 333,
  27352. 'dieresis': 333,
  27353. 'ring': 333,
  27354. 'cedilla': 333,
  27355. 'hungarumlaut': 333,
  27356. 'ogonek': 333,
  27357. 'caron': 333,
  27358. 'emdash': 889,
  27359. 'AE': 889,
  27360. 'ordfeminine': 276,
  27361. 'Lslash': 556,
  27362. 'Oslash': 722,
  27363. 'OE': 944,
  27364. 'ordmasculine': 310,
  27365. 'ae': 667,
  27366. 'dotlessi': 278,
  27367. 'lslash': 278,
  27368. 'oslash': 500,
  27369. 'oe': 667,
  27370. 'germandbls': 500,
  27371. 'Idieresis': 333,
  27372. 'eacute': 444,
  27373. 'abreve': 500,
  27374. 'uhungarumlaut': 500,
  27375. 'ecaron': 444,
  27376. 'Ydieresis': 556,
  27377. 'divide': 675,
  27378. 'Yacute': 556,
  27379. 'Acircumflex': 611,
  27380. 'aacute': 500,
  27381. 'Ucircumflex': 722,
  27382. 'yacute': 444,
  27383. 'scommaaccent': 389,
  27384. 'ecircumflex': 444,
  27385. 'Uring': 722,
  27386. 'Udieresis': 722,
  27387. 'aogonek': 500,
  27388. 'Uacute': 722,
  27389. 'uogonek': 500,
  27390. 'Edieresis': 611,
  27391. 'Dcroat': 722,
  27392. 'commaaccent': 250,
  27393. 'copyright': 760,
  27394. 'Emacron': 611,
  27395. 'ccaron': 444,
  27396. 'aring': 500,
  27397. 'Ncommaaccent': 667,
  27398. 'lacute': 278,
  27399. 'agrave': 500,
  27400. 'Tcommaaccent': 556,
  27401. 'Cacute': 667,
  27402. 'atilde': 500,
  27403. 'Edotaccent': 611,
  27404. 'scaron': 389,
  27405. 'scedilla': 389,
  27406. 'iacute': 278,
  27407. 'lozenge': 471,
  27408. 'Rcaron': 611,
  27409. 'Gcommaaccent': 722,
  27410. 'ucircumflex': 500,
  27411. 'acircumflex': 500,
  27412. 'Amacron': 611,
  27413. 'rcaron': 389,
  27414. 'ccedilla': 444,
  27415. 'Zdotaccent': 556,
  27416. 'Thorn': 611,
  27417. 'Omacron': 722,
  27418. 'Racute': 611,
  27419. 'Sacute': 500,
  27420. 'dcaron': 544,
  27421. 'Umacron': 722,
  27422. 'uring': 500,
  27423. 'threesuperior': 300,
  27424. 'Ograve': 722,
  27425. 'Agrave': 611,
  27426. 'Abreve': 611,
  27427. 'multiply': 675,
  27428. 'uacute': 500,
  27429. 'Tcaron': 556,
  27430. 'partialdiff': 476,
  27431. 'ydieresis': 444,
  27432. 'Nacute': 667,
  27433. 'icircumflex': 278,
  27434. 'Ecircumflex': 611,
  27435. 'adieresis': 500,
  27436. 'edieresis': 444,
  27437. 'cacute': 444,
  27438. 'nacute': 500,
  27439. 'umacron': 500,
  27440. 'Ncaron': 667,
  27441. 'Iacute': 333,
  27442. 'plusminus': 675,
  27443. 'brokenbar': 275,
  27444. 'registered': 760,
  27445. 'Gbreve': 722,
  27446. 'Idotaccent': 333,
  27447. 'summation': 600,
  27448. 'Egrave': 611,
  27449. 'racute': 389,
  27450. 'omacron': 500,
  27451. 'Zacute': 556,
  27452. 'Zcaron': 556,
  27453. 'greaterequal': 549,
  27454. 'Eth': 722,
  27455. 'Ccedilla': 667,
  27456. 'lcommaaccent': 278,
  27457. 'tcaron': 300,
  27458. 'eogonek': 444,
  27459. 'Uogonek': 722,
  27460. 'Aacute': 611,
  27461. 'Adieresis': 611,
  27462. 'egrave': 444,
  27463. 'zacute': 389,
  27464. 'iogonek': 278,
  27465. 'Oacute': 722,
  27466. 'oacute': 500,
  27467. 'amacron': 500,
  27468. 'sacute': 389,
  27469. 'idieresis': 278,
  27470. 'Ocircumflex': 722,
  27471. 'Ugrave': 722,
  27472. 'Delta': 612,
  27473. 'thorn': 500,
  27474. 'twosuperior': 300,
  27475. 'Odieresis': 722,
  27476. 'mu': 500,
  27477. 'igrave': 278,
  27478. 'ohungarumlaut': 500,
  27479. 'Eogonek': 611,
  27480. 'dcroat': 500,
  27481. 'threequarters': 750,
  27482. 'Scedilla': 500,
  27483. 'lcaron': 300,
  27484. 'Kcommaaccent': 667,
  27485. 'Lacute': 556,
  27486. 'trademark': 980,
  27487. 'edotaccent': 444,
  27488. 'Igrave': 333,
  27489. 'Imacron': 333,
  27490. 'Lcaron': 611,
  27491. 'onehalf': 750,
  27492. 'lessequal': 549,
  27493. 'ocircumflex': 500,
  27494. 'ntilde': 500,
  27495. 'Uhungarumlaut': 722,
  27496. 'Eacute': 611,
  27497. 'emacron': 444,
  27498. 'gbreve': 500,
  27499. 'onequarter': 750,
  27500. 'Scaron': 500,
  27501. 'Scommaaccent': 500,
  27502. 'Ohungarumlaut': 722,
  27503. 'degree': 400,
  27504. 'ograve': 500,
  27505. 'Ccaron': 667,
  27506. 'ugrave': 500,
  27507. 'radical': 453,
  27508. 'Dcaron': 722,
  27509. 'rcommaaccent': 389,
  27510. 'Ntilde': 667,
  27511. 'otilde': 500,
  27512. 'Rcommaaccent': 611,
  27513. 'Lcommaaccent': 556,
  27514. 'Atilde': 611,
  27515. 'Aogonek': 611,
  27516. 'Aring': 611,
  27517. 'Otilde': 722,
  27518. 'zdotaccent': 389,
  27519. 'Ecaron': 611,
  27520. 'Iogonek': 333,
  27521. 'kcommaaccent': 444,
  27522. 'minus': 675,
  27523. 'Icircumflex': 333,
  27524. 'ncaron': 500,
  27525. 'tcommaaccent': 278,
  27526. 'logicalnot': 675,
  27527. 'odieresis': 500,
  27528. 'udieresis': 500,
  27529. 'notequal': 549,
  27530. 'gcommaaccent': 500,
  27531. 'eth': 500,
  27532. 'zcaron': 389,
  27533. 'ncommaaccent': 500,
  27534. 'onesuperior': 300,
  27535. 'imacron': 278,
  27536. 'Euro': 500
  27537. },
  27538. 'ZapfDingbats': {
  27539. 'space': 278,
  27540. 'a1': 974,
  27541. 'a2': 961,
  27542. 'a202': 974,
  27543. 'a3': 980,
  27544. 'a4': 719,
  27545. 'a5': 789,
  27546. 'a119': 790,
  27547. 'a118': 791,
  27548. 'a117': 690,
  27549. 'a11': 960,
  27550. 'a12': 939,
  27551. 'a13': 549,
  27552. 'a14': 855,
  27553. 'a15': 911,
  27554. 'a16': 933,
  27555. 'a105': 911,
  27556. 'a17': 945,
  27557. 'a18': 974,
  27558. 'a19': 755,
  27559. 'a20': 846,
  27560. 'a21': 762,
  27561. 'a22': 761,
  27562. 'a23': 571,
  27563. 'a24': 677,
  27564. 'a25': 763,
  27565. 'a26': 760,
  27566. 'a27': 759,
  27567. 'a28': 754,
  27568. 'a6': 494,
  27569. 'a7': 552,
  27570. 'a8': 537,
  27571. 'a9': 577,
  27572. 'a10': 692,
  27573. 'a29': 786,
  27574. 'a30': 788,
  27575. 'a31': 788,
  27576. 'a32': 790,
  27577. 'a33': 793,
  27578. 'a34': 794,
  27579. 'a35': 816,
  27580. 'a36': 823,
  27581. 'a37': 789,
  27582. 'a38': 841,
  27583. 'a39': 823,
  27584. 'a40': 833,
  27585. 'a41': 816,
  27586. 'a42': 831,
  27587. 'a43': 923,
  27588. 'a44': 744,
  27589. 'a45': 723,
  27590. 'a46': 749,
  27591. 'a47': 790,
  27592. 'a48': 792,
  27593. 'a49': 695,
  27594. 'a50': 776,
  27595. 'a51': 768,
  27596. 'a52': 792,
  27597. 'a53': 759,
  27598. 'a54': 707,
  27599. 'a55': 708,
  27600. 'a56': 682,
  27601. 'a57': 701,
  27602. 'a58': 826,
  27603. 'a59': 815,
  27604. 'a60': 789,
  27605. 'a61': 789,
  27606. 'a62': 707,
  27607. 'a63': 687,
  27608. 'a64': 696,
  27609. 'a65': 689,
  27610. 'a66': 786,
  27611. 'a67': 787,
  27612. 'a68': 713,
  27613. 'a69': 791,
  27614. 'a70': 785,
  27615. 'a71': 791,
  27616. 'a72': 873,
  27617. 'a73': 761,
  27618. 'a74': 762,
  27619. 'a203': 762,
  27620. 'a75': 759,
  27621. 'a204': 759,
  27622. 'a76': 892,
  27623. 'a77': 892,
  27624. 'a78': 788,
  27625. 'a79': 784,
  27626. 'a81': 438,
  27627. 'a82': 138,
  27628. 'a83': 277,
  27629. 'a84': 415,
  27630. 'a97': 392,
  27631. 'a98': 392,
  27632. 'a99': 668,
  27633. 'a100': 668,
  27634. 'a89': 390,
  27635. 'a90': 390,
  27636. 'a93': 317,
  27637. 'a94': 317,
  27638. 'a91': 276,
  27639. 'a92': 276,
  27640. 'a205': 509,
  27641. 'a85': 509,
  27642. 'a206': 410,
  27643. 'a86': 410,
  27644. 'a87': 234,
  27645. 'a88': 234,
  27646. 'a95': 334,
  27647. 'a96': 334,
  27648. 'a101': 732,
  27649. 'a102': 544,
  27650. 'a103': 544,
  27651. 'a104': 910,
  27652. 'a106': 667,
  27653. 'a107': 760,
  27654. 'a108': 760,
  27655. 'a112': 776,
  27656. 'a111': 595,
  27657. 'a110': 694,
  27658. 'a109': 626,
  27659. 'a120': 788,
  27660. 'a121': 788,
  27661. 'a122': 788,
  27662. 'a123': 788,
  27663. 'a124': 788,
  27664. 'a125': 788,
  27665. 'a126': 788,
  27666. 'a127': 788,
  27667. 'a128': 788,
  27668. 'a129': 788,
  27669. 'a130': 788,
  27670. 'a131': 788,
  27671. 'a132': 788,
  27672. 'a133': 788,
  27673. 'a134': 788,
  27674. 'a135': 788,
  27675. 'a136': 788,
  27676. 'a137': 788,
  27677. 'a138': 788,
  27678. 'a139': 788,
  27679. 'a140': 788,
  27680. 'a141': 788,
  27681. 'a142': 788,
  27682. 'a143': 788,
  27683. 'a144': 788,
  27684. 'a145': 788,
  27685. 'a146': 788,
  27686. 'a147': 788,
  27687. 'a148': 788,
  27688. 'a149': 788,
  27689. 'a150': 788,
  27690. 'a151': 788,
  27691. 'a152': 788,
  27692. 'a153': 788,
  27693. 'a154': 788,
  27694. 'a155': 788,
  27695. 'a156': 788,
  27696. 'a157': 788,
  27697. 'a158': 788,
  27698. 'a159': 788,
  27699. 'a160': 894,
  27700. 'a161': 838,
  27701. 'a163': 1016,
  27702. 'a164': 458,
  27703. 'a196': 748,
  27704. 'a165': 924,
  27705. 'a192': 748,
  27706. 'a166': 918,
  27707. 'a167': 927,
  27708. 'a168': 928,
  27709. 'a169': 928,
  27710. 'a170': 834,
  27711. 'a171': 873,
  27712. 'a172': 828,
  27713. 'a173': 924,
  27714. 'a162': 924,
  27715. 'a174': 917,
  27716. 'a175': 930,
  27717. 'a176': 931,
  27718. 'a177': 463,
  27719. 'a178': 883,
  27720. 'a179': 836,
  27721. 'a193': 836,
  27722. 'a180': 867,
  27723. 'a199': 867,
  27724. 'a181': 696,
  27725. 'a200': 696,
  27726. 'a182': 874,
  27727. 'a201': 874,
  27728. 'a183': 760,
  27729. 'a184': 946,
  27730. 'a197': 771,
  27731. 'a185': 865,
  27732. 'a194': 771,
  27733. 'a198': 888,
  27734. 'a186': 967,
  27735. 'a195': 888,
  27736. 'a187': 831,
  27737. 'a188': 873,
  27738. 'a189': 927,
  27739. 'a190': 970,
  27740. 'a191': 918
  27741. }
  27742. };
  27743. var EOF = {};
  27744. function isEOF(v) {
  27745. return (v === EOF);
  27746. }
  27747. var Parser = (function ParserClosure() {
  27748. function Parser(lexer, allowStreams, xref) {
  27749. this.lexer = lexer;
  27750. this.allowStreams = allowStreams;
  27751. this.xref = xref;
  27752. this.imageCache = {
  27753. length: 0,
  27754. adler32: 0,
  27755. stream: null
  27756. };
  27757. this.refill();
  27758. }
  27759. Parser.prototype = {
  27760. refill: function Parser_refill() {
  27761. this.buf1 = this.lexer.getObj();
  27762. this.buf2 = this.lexer.getObj();
  27763. },
  27764. shift: function Parser_shift() {
  27765. if (isCmd(this.buf2, 'ID')) {
  27766. this.buf1 = this.buf2;
  27767. this.buf2 = null;
  27768. } else {
  27769. this.buf1 = this.buf2;
  27770. this.buf2 = this.lexer.getObj();
  27771. }
  27772. },
  27773. getObj: function Parser_getObj(cipherTransform) {
  27774. var buf1 = this.buf1;
  27775. this.shift();
  27776. if (buf1 instanceof Cmd) {
  27777. switch (buf1.cmd) {
  27778. case 'BI': // inline image
  27779. return this.makeInlineImage(cipherTransform);
  27780. case '[': // array
  27781. var array = [];
  27782. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  27783. array.push(this.getObj(cipherTransform));
  27784. }
  27785. if (isEOF(this.buf1)) {
  27786. error('End of file inside array');
  27787. }
  27788. this.shift();
  27789. return array;
  27790. case '<<': // dictionary or stream
  27791. var dict = new Dict(this.xref);
  27792. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  27793. if (!isName(this.buf1)) {
  27794. info('Malformed dictionary: key must be a name object');
  27795. this.shift();
  27796. continue;
  27797. }
  27798. var key = this.buf1.name;
  27799. this.shift();
  27800. if (isEOF(this.buf1)) {
  27801. break;
  27802. }
  27803. dict.set(key, this.getObj(cipherTransform));
  27804. }
  27805. if (isEOF(this.buf1)) {
  27806. error('End of file inside dictionary');
  27807. }
  27808. // Stream objects are not allowed inside content streams or
  27809. // object streams.
  27810. if (isCmd(this.buf2, 'stream')) {
  27811. return (this.allowStreams ?
  27812. this.makeStream(dict, cipherTransform) : dict);
  27813. }
  27814. this.shift();
  27815. return dict;
  27816. default: // simple object
  27817. return buf1;
  27818. }
  27819. }
  27820. if (isInt(buf1)) { // indirect reference or integer
  27821. var num = buf1;
  27822. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  27823. var ref = new Ref(num, this.buf1);
  27824. this.shift();
  27825. this.shift();
  27826. return ref;
  27827. }
  27828. return num;
  27829. }
  27830. if (isString(buf1)) { // string
  27831. var str = buf1;
  27832. if (cipherTransform) {
  27833. str = cipherTransform.decryptString(str);
  27834. }
  27835. return str;
  27836. }
  27837. // simple object
  27838. return buf1;
  27839. },
  27840. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27841. var lexer = this.lexer;
  27842. var stream = lexer.stream;
  27843. // parse dictionary
  27844. var dict = new Dict(null);
  27845. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27846. if (!isName(this.buf1)) {
  27847. error('Dictionary key must be a name object');
  27848. }
  27849. var key = this.buf1.name;
  27850. this.shift();
  27851. if (isEOF(this.buf1)) {
  27852. break;
  27853. }
  27854. dict.set(key, this.getObj(cipherTransform));
  27855. }
  27856. // parse image stream
  27857. var startPos = stream.pos;
  27858. // searching for the /EI\s/
  27859. var state = 0, ch, i, ii;
  27860. var E = 0x45, I = 0x49, SPACE = 0x20, NL = 0xA, CR = 0xD;
  27861. while ((ch = stream.getByte()) !== -1) {
  27862. if (state === 0) {
  27863. state = (ch === E) ? 1 : 0;
  27864. } else if (state === 1) {
  27865. state = (ch === I) ? 2 : 0;
  27866. } else {
  27867. assert(state === 2);
  27868. if (ch === SPACE || ch === NL || ch === CR) {
  27869. // Let's check the next five bytes are ASCII... just be sure.
  27870. var n = 5;
  27871. var followingBytes = stream.peekBytes(n);
  27872. for (i = 0; i < n; i++) {
  27873. ch = followingBytes[i];
  27874. if (ch !== NL && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  27875. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  27876. // it's binary stuff. Resetting the state.
  27877. state = 0;
  27878. break;
  27879. }
  27880. }
  27881. if (state === 2) {
  27882. break; // finished!
  27883. }
  27884. } else {
  27885. state = 0;
  27886. }
  27887. }
  27888. }
  27889. var length = (stream.pos - 4) - startPos;
  27890. var imageStream = stream.makeSubStream(startPos, length, dict);
  27891. // trying to cache repeat images, first we are trying to "warm up" caching
  27892. // using length, then comparing adler32
  27893. var MAX_LENGTH_TO_CACHE = 1000;
  27894. var cacheImage = false, adler32;
  27895. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  27896. var imageBytes = imageStream.getBytes();
  27897. imageStream.reset();
  27898. var a = 1;
  27899. var b = 0;
  27900. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27901. a = (a + (imageBytes[i] & 0xff)) % 65521;
  27902. b = (b + a) % 65521;
  27903. }
  27904. adler32 = (b << 16) | a;
  27905. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  27906. this.buf2 = Cmd.get('EI');
  27907. this.shift();
  27908. this.imageCache.stream.reset();
  27909. return this.imageCache.stream;
  27910. }
  27911. cacheImage = true;
  27912. }
  27913. if (!cacheImage && !this.imageCache.stream) {
  27914. this.imageCache.length = length;
  27915. this.imageCache.stream = null;
  27916. }
  27917. if (cipherTransform) {
  27918. imageStream = cipherTransform.createStream(imageStream, length);
  27919. }
  27920. imageStream = this.filter(imageStream, dict, length);
  27921. imageStream.dict = dict;
  27922. if (cacheImage) {
  27923. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27924. this.imageCache.adler32 = adler32;
  27925. this.imageCache.stream = imageStream;
  27926. }
  27927. this.buf2 = Cmd.get('EI');
  27928. this.shift();
  27929. return imageStream;
  27930. },
  27931. fetchIfRef: function Parser_fetchIfRef(obj) {
  27932. // not relying on the xref.fetchIfRef -- xref might not be set
  27933. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  27934. },
  27935. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27936. var lexer = this.lexer;
  27937. var stream = lexer.stream;
  27938. // get stream start position
  27939. lexer.skipToNextLine();
  27940. var pos = stream.pos - 1;
  27941. // get length
  27942. var length = this.fetchIfRef(dict.get('Length'));
  27943. if (!isInt(length)) {
  27944. info('Bad ' + length + ' attribute in stream');
  27945. length = 0;
  27946. }
  27947. // skip over the stream data
  27948. stream.pos = pos + length;
  27949. lexer.nextChar();
  27950. this.shift(); // '>>'
  27951. this.shift(); // 'stream'
  27952. if (!isCmd(this.buf1, 'endstream')) {
  27953. // bad stream length, scanning for endstream
  27954. stream.pos = pos;
  27955. var SCAN_BLOCK_SIZE = 2048;
  27956. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27957. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27958. 0x61, 0x6D];
  27959. var skipped = 0, found = false, i, j;
  27960. while (stream.pos < stream.end) {
  27961. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27962. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27963. if (scanLength <= 0) {
  27964. break;
  27965. }
  27966. found = false;
  27967. for (i = 0, j = 0; i < scanLength; i++) {
  27968. var b = scanBytes[i];
  27969. if (b !== ENDSTREAM_SIGNATURE[j]) {
  27970. i -= j;
  27971. j = 0;
  27972. } else {
  27973. j++;
  27974. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27975. i++;
  27976. found = true;
  27977. break;
  27978. }
  27979. }
  27980. }
  27981. if (found) {
  27982. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  27983. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  27984. break;
  27985. }
  27986. skipped += scanLength;
  27987. stream.pos += scanLength;
  27988. }
  27989. if (!found) {
  27990. error('Missing endstream');
  27991. }
  27992. length = skipped;
  27993. lexer.nextChar();
  27994. this.shift();
  27995. this.shift();
  27996. }
  27997. this.shift(); // 'endstream'
  27998. stream = stream.makeSubStream(pos, length, dict);
  27999. if (cipherTransform) {
  28000. stream = cipherTransform.createStream(stream, length);
  28001. }
  28002. stream = this.filter(stream, dict, length);
  28003. stream.dict = dict;
  28004. return stream;
  28005. },
  28006. filter: function Parser_filter(stream, dict, length) {
  28007. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28008. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28009. if (isName(filter)) {
  28010. return this.makeFilter(stream, filter.name, length, params);
  28011. }
  28012. var maybeLength = length;
  28013. if (isArray(filter)) {
  28014. var filterArray = filter;
  28015. var paramsArray = params;
  28016. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28017. filter = filterArray[i];
  28018. if (!isName(filter)) {
  28019. error('Bad filter name: ' + filter);
  28020. }
  28021. params = null;
  28022. if (isArray(paramsArray) && (i in paramsArray)) {
  28023. params = paramsArray[i];
  28024. }
  28025. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28026. // after the first stream the length variable is invalid
  28027. maybeLength = null;
  28028. }
  28029. }
  28030. return stream;
  28031. },
  28032. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28033. if (stream.dict.get('Length') === 0) {
  28034. return new NullStream(stream);
  28035. }
  28036. try {
  28037. var xrefStreamStats = this.xref.stats.streamTypes;
  28038. if (name === 'FlateDecode' || name === 'Fl') {
  28039. xrefStreamStats[StreamType.FLATE] = true;
  28040. if (params) {
  28041. return new PredictorStream(new FlateStream(stream, maybeLength),
  28042. maybeLength, params);
  28043. }
  28044. return new FlateStream(stream, maybeLength);
  28045. }
  28046. if (name === 'LZWDecode' || name === 'LZW') {
  28047. xrefStreamStats[StreamType.LZW] = true;
  28048. var earlyChange = 1;
  28049. if (params) {
  28050. if (params.has('EarlyChange')) {
  28051. earlyChange = params.get('EarlyChange');
  28052. }
  28053. return new PredictorStream(
  28054. new LZWStream(stream, maybeLength, earlyChange),
  28055. maybeLength, params);
  28056. }
  28057. return new LZWStream(stream, maybeLength, earlyChange);
  28058. }
  28059. if (name === 'DCTDecode' || name === 'DCT') {
  28060. xrefStreamStats[StreamType.DCT] = true;
  28061. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28062. }
  28063. if (name === 'JPXDecode' || name === 'JPX') {
  28064. xrefStreamStats[StreamType.JPX] = true;
  28065. return new JpxStream(stream, maybeLength, stream.dict);
  28066. }
  28067. if (name === 'ASCII85Decode' || name === 'A85') {
  28068. xrefStreamStats[StreamType.A85] = true;
  28069. return new Ascii85Stream(stream, maybeLength);
  28070. }
  28071. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28072. xrefStreamStats[StreamType.AHX] = true;
  28073. return new AsciiHexStream(stream, maybeLength);
  28074. }
  28075. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28076. xrefStreamStats[StreamType.CCF] = true;
  28077. return new CCITTFaxStream(stream, maybeLength, params);
  28078. }
  28079. if (name === 'RunLengthDecode' || name === 'RL') {
  28080. xrefStreamStats[StreamType.RL] = true;
  28081. return new RunLengthStream(stream, maybeLength);
  28082. }
  28083. if (name === 'JBIG2Decode') {
  28084. xrefStreamStats[StreamType.JBIG] = true;
  28085. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28086. }
  28087. warn('filter "' + name + '" not supported yet');
  28088. return stream;
  28089. } catch (ex) {
  28090. if (ex instanceof MissingDataException) {
  28091. throw ex;
  28092. }
  28093. warn('Invalid stream: \"' + ex + '\"');
  28094. return new NullStream(stream);
  28095. }
  28096. }
  28097. };
  28098. return Parser;
  28099. })();
  28100. var Lexer = (function LexerClosure() {
  28101. function Lexer(stream, knownCommands) {
  28102. this.stream = stream;
  28103. this.nextChar();
  28104. // While lexing, we build up many strings one char at a time. Using += for
  28105. // this can result in lots of garbage strings. It's better to build an
  28106. // array of single-char strings and then join() them together at the end.
  28107. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28108. // purpose uses less memory than using a new array for each string.
  28109. this.strBuf = [];
  28110. // The PDFs might have "glued" commands with other commands, operands or
  28111. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28112. // commands and their prefixes. The prefixes are built the following way:
  28113. // if there a command that is a prefix of the other valid command or
  28114. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28115. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28116. // other commands or literals as a prefix. The knowCommands is optional.
  28117. this.knownCommands = knownCommands;
  28118. }
  28119. Lexer.isSpace = function Lexer_isSpace(ch) {
  28120. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28121. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28122. };
  28123. // A '1' in this array means the character is white space. A '1' or
  28124. // '2' means the character ends a name or command.
  28125. var specialChars = [
  28126. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28128. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28142. ];
  28143. function toHexDigit(ch) {
  28144. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28145. return ch & 0x0F;
  28146. }
  28147. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28148. // 'A'-'F', 'a'-'f'
  28149. return (ch & 0x0F) + 9;
  28150. }
  28151. return -1;
  28152. }
  28153. Lexer.prototype = {
  28154. nextChar: function Lexer_nextChar() {
  28155. return (this.currentChar = this.stream.getByte());
  28156. },
  28157. peekChar: function Lexer_peekChar() {
  28158. return this.stream.peekBytes(1)[0];
  28159. },
  28160. getNumber: function Lexer_getNumber() {
  28161. var ch = this.currentChar;
  28162. var eNotation = false;
  28163. var divideBy = 0; // different from 0 if it's a floating point value
  28164. var sign = 1;
  28165. if (ch === 0x2D) { // '-'
  28166. sign = -1;
  28167. ch = this.nextChar();
  28168. } else if (ch === 0x2B) { // '+'
  28169. ch = this.nextChar();
  28170. }
  28171. if (ch === 0x2E) { // '.'
  28172. divideBy = 10;
  28173. ch = this.nextChar();
  28174. }
  28175. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28176. error('Invalid number: ' + String.fromCharCode(ch));
  28177. return 0;
  28178. }
  28179. var baseValue = ch - 0x30; // '0'
  28180. var powerValue = 0;
  28181. var powerValueSign = 1;
  28182. while ((ch = this.nextChar()) >= 0) {
  28183. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28184. var currentDigit = ch - 0x30; // '0'
  28185. if (eNotation) { // We are after an 'e' or 'E'
  28186. powerValue = powerValue * 10 + currentDigit;
  28187. } else {
  28188. if (divideBy !== 0) { // We are after a point
  28189. divideBy *= 10;
  28190. }
  28191. baseValue = baseValue * 10 + currentDigit;
  28192. }
  28193. } else if (ch === 0x2E) { // '.'
  28194. if (divideBy === 0) {
  28195. divideBy = 1;
  28196. } else {
  28197. // A number can have only one '.'
  28198. break;
  28199. }
  28200. } else if (ch === 0x2D) { // '-'
  28201. // ignore minus signs in the middle of numbers to match
  28202. // Adobe's behavior
  28203. warn('Badly formated number');
  28204. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28205. // 'E' can be either a scientific notation or the beginning of a new
  28206. // operator
  28207. ch = this.peekChar();
  28208. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28209. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28210. this.nextChar(); // Consume the sign character
  28211. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28212. // The 'E' must be the beginning of a new operator
  28213. break;
  28214. }
  28215. eNotation = true;
  28216. } else {
  28217. // the last character doesn't belong to us
  28218. break;
  28219. }
  28220. }
  28221. if (divideBy !== 0) {
  28222. baseValue /= divideBy;
  28223. }
  28224. if (eNotation) {
  28225. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28226. }
  28227. return sign * baseValue;
  28228. },
  28229. getString: function Lexer_getString() {
  28230. var numParen = 1;
  28231. var done = false;
  28232. var strBuf = this.strBuf;
  28233. strBuf.length = 0;
  28234. var ch = this.nextChar();
  28235. while (true) {
  28236. var charBuffered = false;
  28237. switch (ch | 0) {
  28238. case -1:
  28239. warn('Unterminated string');
  28240. done = true;
  28241. break;
  28242. case 0x28: // '('
  28243. ++numParen;
  28244. strBuf.push('(');
  28245. break;
  28246. case 0x29: // ')'
  28247. if (--numParen === 0) {
  28248. this.nextChar(); // consume strings ')'
  28249. done = true;
  28250. } else {
  28251. strBuf.push(')');
  28252. }
  28253. break;
  28254. case 0x5C: // '\\'
  28255. ch = this.nextChar();
  28256. switch (ch) {
  28257. case -1:
  28258. warn('Unterminated string');
  28259. done = true;
  28260. break;
  28261. case 0x6E: // 'n'
  28262. strBuf.push('\n');
  28263. break;
  28264. case 0x72: // 'r'
  28265. strBuf.push('\r');
  28266. break;
  28267. case 0x74: // 't'
  28268. strBuf.push('\t');
  28269. break;
  28270. case 0x62: // 'b'
  28271. strBuf.push('\b');
  28272. break;
  28273. case 0x66: // 'f'
  28274. strBuf.push('\f');
  28275. break;
  28276. case 0x5C: // '\'
  28277. case 0x28: // '('
  28278. case 0x29: // ')'
  28279. strBuf.push(String.fromCharCode(ch));
  28280. break;
  28281. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28282. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28283. var x = ch & 0x0F;
  28284. ch = this.nextChar();
  28285. charBuffered = true;
  28286. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28287. x = (x << 3) + (ch & 0x0F);
  28288. ch = this.nextChar();
  28289. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28290. charBuffered = false;
  28291. x = (x << 3) + (ch & 0x0F);
  28292. }
  28293. }
  28294. strBuf.push(String.fromCharCode(x));
  28295. break;
  28296. case 0x0D: // CR
  28297. if (this.peekChar() === 0x0A) { // LF
  28298. this.nextChar();
  28299. }
  28300. break;
  28301. case 0x0A: // LF
  28302. break;
  28303. default:
  28304. strBuf.push(String.fromCharCode(ch));
  28305. break;
  28306. }
  28307. break;
  28308. default:
  28309. strBuf.push(String.fromCharCode(ch));
  28310. break;
  28311. }
  28312. if (done) {
  28313. break;
  28314. }
  28315. if (!charBuffered) {
  28316. ch = this.nextChar();
  28317. }
  28318. }
  28319. return strBuf.join('');
  28320. },
  28321. getName: function Lexer_getName() {
  28322. var ch;
  28323. var strBuf = this.strBuf;
  28324. strBuf.length = 0;
  28325. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28326. if (ch === 0x23) { // '#'
  28327. ch = this.nextChar();
  28328. var x = toHexDigit(ch);
  28329. if (x !== -1) {
  28330. var x2 = toHexDigit(this.nextChar());
  28331. if (x2 === -1) {
  28332. error('Illegal digit in hex char in name: ' + x2);
  28333. }
  28334. strBuf.push(String.fromCharCode((x << 4) | x2));
  28335. } else {
  28336. strBuf.push('#', String.fromCharCode(ch));
  28337. }
  28338. } else {
  28339. strBuf.push(String.fromCharCode(ch));
  28340. }
  28341. }
  28342. if (strBuf.length > 128) {
  28343. error('Warning: name token is longer than allowed by the spec: ' +
  28344. strBuf.length);
  28345. }
  28346. return Name.get(strBuf.join(''));
  28347. },
  28348. getHexString: function Lexer_getHexString() {
  28349. var strBuf = this.strBuf;
  28350. strBuf.length = 0;
  28351. var ch = this.currentChar;
  28352. var isFirstHex = true;
  28353. var firstDigit;
  28354. var secondDigit;
  28355. while (true) {
  28356. if (ch < 0) {
  28357. warn('Unterminated hex string');
  28358. break;
  28359. } else if (ch === 0x3E) { // '>'
  28360. this.nextChar();
  28361. break;
  28362. } else if (specialChars[ch] === 1) {
  28363. ch = this.nextChar();
  28364. continue;
  28365. } else {
  28366. if (isFirstHex) {
  28367. firstDigit = toHexDigit(ch);
  28368. if (firstDigit === -1) {
  28369. warn('Ignoring invalid character "' + ch + '" in hex string');
  28370. ch = this.nextChar();
  28371. continue;
  28372. }
  28373. } else {
  28374. secondDigit = toHexDigit(ch);
  28375. if (secondDigit === -1) {
  28376. warn('Ignoring invalid character "' + ch + '" in hex string');
  28377. ch = this.nextChar();
  28378. continue;
  28379. }
  28380. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  28381. }
  28382. isFirstHex = !isFirstHex;
  28383. ch = this.nextChar();
  28384. }
  28385. }
  28386. return strBuf.join('');
  28387. },
  28388. getObj: function Lexer_getObj() {
  28389. // skip whitespace and comments
  28390. var comment = false;
  28391. var ch = this.currentChar;
  28392. while (true) {
  28393. if (ch < 0) {
  28394. return EOF;
  28395. }
  28396. if (comment) {
  28397. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  28398. comment = false;
  28399. }
  28400. } else if (ch === 0x25) { // '%'
  28401. comment = true;
  28402. } else if (specialChars[ch] !== 1) {
  28403. break;
  28404. }
  28405. ch = this.nextChar();
  28406. }
  28407. // start reading token
  28408. switch (ch | 0) {
  28409. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28410. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28411. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28412. return this.getNumber();
  28413. case 0x28: // '('
  28414. return this.getString();
  28415. case 0x2F: // '/'
  28416. return this.getName();
  28417. // array punctuation
  28418. case 0x5B: // '['
  28419. this.nextChar();
  28420. return Cmd.get('[');
  28421. case 0x5D: // ']'
  28422. this.nextChar();
  28423. return Cmd.get(']');
  28424. // hex string or dict punctuation
  28425. case 0x3C: // '<'
  28426. ch = this.nextChar();
  28427. if (ch === 0x3C) {
  28428. // dict punctuation
  28429. this.nextChar();
  28430. return Cmd.get('<<');
  28431. }
  28432. return this.getHexString();
  28433. // dict punctuation
  28434. case 0x3E: // '>'
  28435. ch = this.nextChar();
  28436. if (ch === 0x3E) {
  28437. this.nextChar();
  28438. return Cmd.get('>>');
  28439. }
  28440. return Cmd.get('>');
  28441. case 0x7B: // '{'
  28442. this.nextChar();
  28443. return Cmd.get('{');
  28444. case 0x7D: // '}'
  28445. this.nextChar();
  28446. return Cmd.get('}');
  28447. case 0x29: // ')'
  28448. error('Illegal character: ' + ch);
  28449. break;
  28450. }
  28451. // command
  28452. var str = String.fromCharCode(ch);
  28453. var knownCommands = this.knownCommands;
  28454. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28455. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28456. // stop if known command is found and next character does not make
  28457. // the str a command
  28458. var possibleCommand = str + String.fromCharCode(ch);
  28459. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  28460. break;
  28461. }
  28462. if (str.length === 128) {
  28463. error('Command token too long: ' + str.length);
  28464. }
  28465. str = possibleCommand;
  28466. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  28467. }
  28468. if (str === 'true') {
  28469. return true;
  28470. }
  28471. if (str === 'false') {
  28472. return false;
  28473. }
  28474. if (str === 'null') {
  28475. return null;
  28476. }
  28477. return Cmd.get(str);
  28478. },
  28479. skipToNextLine: function Lexer_skipToNextLine() {
  28480. var ch = this.currentChar;
  28481. while (ch >= 0) {
  28482. if (ch === 0x0D) { // CR
  28483. ch = this.nextChar();
  28484. if (ch === 0x0A) { // LF
  28485. this.nextChar();
  28486. }
  28487. break;
  28488. } else if (ch === 0x0A) { // LF
  28489. this.nextChar();
  28490. break;
  28491. }
  28492. ch = this.nextChar();
  28493. }
  28494. }
  28495. };
  28496. return Lexer;
  28497. })();
  28498. var Linearization = {
  28499. create: function LinearizationCreate(stream) {
  28500. function getInt(name, allowZeroValue) {
  28501. var obj = linDict.get(name);
  28502. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  28503. return obj;
  28504. }
  28505. throw new Error('The "' + name + '" parameter in the linearization ' +
  28506. 'dictionary is invalid.');
  28507. }
  28508. function getHints() {
  28509. var hints = linDict.get('H'), hintsLength, item;
  28510. if (isArray(hints) &&
  28511. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  28512. for (var index = 0; index < hintsLength; index++) {
  28513. if (!(isInt(item = hints[index]) && item > 0)) {
  28514. throw new Error('Hint (' + index +
  28515. ') in the linearization dictionary is invalid.');
  28516. }
  28517. }
  28518. return hints;
  28519. }
  28520. throw new Error('Hint array in the linearization dictionary is invalid.');
  28521. }
  28522. var parser = new Parser(new Lexer(stream), false, null);
  28523. var obj1 = parser.getObj();
  28524. var obj2 = parser.getObj();
  28525. var obj3 = parser.getObj();
  28526. var linDict = parser.getObj();
  28527. var obj, length;
  28528. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  28529. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  28530. return null; // No valid linearization dictionary found.
  28531. } else if ((length = getInt('L')) !== stream.length) {
  28532. throw new Error('The "L" parameter in the linearization dictionary ' +
  28533. 'does not equal the stream length.');
  28534. }
  28535. return {
  28536. length: length,
  28537. hints: getHints(),
  28538. objectNumberFirst: getInt('O'),
  28539. endFirst: getInt('E'),
  28540. numPages: getInt('N'),
  28541. mainXRefEntriesOffset: getInt('T'),
  28542. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  28543. };
  28544. }
  28545. };
  28546. var PostScriptParser = (function PostScriptParserClosure() {
  28547. function PostScriptParser(lexer) {
  28548. this.lexer = lexer;
  28549. this.operators = [];
  28550. this.token = null;
  28551. this.prev = null;
  28552. }
  28553. PostScriptParser.prototype = {
  28554. nextToken: function PostScriptParser_nextToken() {
  28555. this.prev = this.token;
  28556. this.token = this.lexer.getToken();
  28557. },
  28558. accept: function PostScriptParser_accept(type) {
  28559. if (this.token.type === type) {
  28560. this.nextToken();
  28561. return true;
  28562. }
  28563. return false;
  28564. },
  28565. expect: function PostScriptParser_expect(type) {
  28566. if (this.accept(type)) {
  28567. return true;
  28568. }
  28569. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  28570. type + '.');
  28571. },
  28572. parse: function PostScriptParser_parse() {
  28573. this.nextToken();
  28574. this.expect(PostScriptTokenTypes.LBRACE);
  28575. this.parseBlock();
  28576. this.expect(PostScriptTokenTypes.RBRACE);
  28577. return this.operators;
  28578. },
  28579. parseBlock: function PostScriptParser_parseBlock() {
  28580. while (true) {
  28581. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  28582. this.operators.push(this.prev.value);
  28583. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  28584. this.operators.push(this.prev.value);
  28585. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28586. this.parseCondition();
  28587. } else {
  28588. return;
  28589. }
  28590. }
  28591. },
  28592. parseCondition: function PostScriptParser_parseCondition() {
  28593. // Add two place holders that will be updated later
  28594. var conditionLocation = this.operators.length;
  28595. this.operators.push(null, null);
  28596. this.parseBlock();
  28597. this.expect(PostScriptTokenTypes.RBRACE);
  28598. if (this.accept(PostScriptTokenTypes.IF)) {
  28599. // The true block is right after the 'if' so it just falls through on
  28600. // true else it jumps and skips the true block.
  28601. this.operators[conditionLocation] = this.operators.length;
  28602. this.operators[conditionLocation + 1] = 'jz';
  28603. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  28604. var jumpLocation = this.operators.length;
  28605. this.operators.push(null, null);
  28606. var endOfTrue = this.operators.length;
  28607. this.parseBlock();
  28608. this.expect(PostScriptTokenTypes.RBRACE);
  28609. this.expect(PostScriptTokenTypes.IFELSE);
  28610. // The jump is added at the end of the true block to skip the false
  28611. // block.
  28612. this.operators[jumpLocation] = this.operators.length;
  28613. this.operators[jumpLocation + 1] = 'j';
  28614. this.operators[conditionLocation] = endOfTrue;
  28615. this.operators[conditionLocation + 1] = 'jz';
  28616. } else {
  28617. error('PS Function: error parsing conditional.');
  28618. }
  28619. }
  28620. };
  28621. return PostScriptParser;
  28622. })();
  28623. var PostScriptTokenTypes = {
  28624. LBRACE: 0,
  28625. RBRACE: 1,
  28626. NUMBER: 2,
  28627. OPERATOR: 3,
  28628. IF: 4,
  28629. IFELSE: 5
  28630. };
  28631. var PostScriptToken = (function PostScriptTokenClosure() {
  28632. function PostScriptToken(type, value) {
  28633. this.type = type;
  28634. this.value = value;
  28635. }
  28636. var opCache = {};
  28637. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  28638. var opValue = opCache[op];
  28639. if (opValue) {
  28640. return opValue;
  28641. }
  28642. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  28643. };
  28644. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  28645. '{');
  28646. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  28647. '}');
  28648. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  28649. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  28650. 'IFELSE');
  28651. return PostScriptToken;
  28652. })();
  28653. var PostScriptLexer = (function PostScriptLexerClosure() {
  28654. function PostScriptLexer(stream) {
  28655. this.stream = stream;
  28656. this.nextChar();
  28657. this.strBuf = [];
  28658. }
  28659. PostScriptLexer.prototype = {
  28660. nextChar: function PostScriptLexer_nextChar() {
  28661. return (this.currentChar = this.stream.getByte());
  28662. },
  28663. getToken: function PostScriptLexer_getToken() {
  28664. var comment = false;
  28665. var ch = this.currentChar;
  28666. // skip comments
  28667. while (true) {
  28668. if (ch < 0) {
  28669. return EOF;
  28670. }
  28671. if (comment) {
  28672. if (ch === 0x0A || ch === 0x0D) {
  28673. comment = false;
  28674. }
  28675. } else if (ch === 0x25) { // '%'
  28676. comment = true;
  28677. } else if (!Lexer.isSpace(ch)) {
  28678. break;
  28679. }
  28680. ch = this.nextChar();
  28681. }
  28682. switch (ch | 0) {
  28683. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  28684. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  28685. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  28686. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  28687. this.getNumber());
  28688. case 0x7B: // '{'
  28689. this.nextChar();
  28690. return PostScriptToken.LBRACE;
  28691. case 0x7D: // '}'
  28692. this.nextChar();
  28693. return PostScriptToken.RBRACE;
  28694. }
  28695. // operator
  28696. var strBuf = this.strBuf;
  28697. strBuf.length = 0;
  28698. strBuf[0] = String.fromCharCode(ch);
  28699. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  28700. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  28701. strBuf.push(String.fromCharCode(ch));
  28702. }
  28703. var str = strBuf.join('');
  28704. switch (str.toLowerCase()) {
  28705. case 'if':
  28706. return PostScriptToken.IF;
  28707. case 'ifelse':
  28708. return PostScriptToken.IFELSE;
  28709. default:
  28710. return PostScriptToken.getOperator(str);
  28711. }
  28712. },
  28713. getNumber: function PostScriptLexer_getNumber() {
  28714. var ch = this.currentChar;
  28715. var strBuf = this.strBuf;
  28716. strBuf.length = 0;
  28717. strBuf[0] = String.fromCharCode(ch);
  28718. while ((ch = this.nextChar()) >= 0) {
  28719. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  28720. ch === 0x2D || ch === 0x2E) { // '-', '.'
  28721. strBuf.push(String.fromCharCode(ch));
  28722. } else {
  28723. break;
  28724. }
  28725. }
  28726. var value = parseFloat(strBuf.join(''));
  28727. if (isNaN(value)) {
  28728. error('Invalid floating point number: ' + value);
  28729. }
  28730. return value;
  28731. }
  28732. };
  28733. return PostScriptLexer;
  28734. })();
  28735. var Stream = (function StreamClosure() {
  28736. function Stream(arrayBuffer, start, length, dict) {
  28737. this.bytes = (arrayBuffer instanceof Uint8Array ?
  28738. arrayBuffer : new Uint8Array(arrayBuffer));
  28739. this.start = start || 0;
  28740. this.pos = this.start;
  28741. this.end = (start + length) || this.bytes.length;
  28742. this.dict = dict;
  28743. }
  28744. // required methods for a stream. if a particular stream does not
  28745. // implement these, an error should be thrown
  28746. Stream.prototype = {
  28747. get length() {
  28748. return this.end - this.start;
  28749. },
  28750. get isEmpty() {
  28751. return this.length === 0;
  28752. },
  28753. getByte: function Stream_getByte() {
  28754. if (this.pos >= this.end) {
  28755. return -1;
  28756. }
  28757. return this.bytes[this.pos++];
  28758. },
  28759. getUint16: function Stream_getUint16() {
  28760. var b0 = this.getByte();
  28761. var b1 = this.getByte();
  28762. return (b0 << 8) + b1;
  28763. },
  28764. getInt32: function Stream_getInt32() {
  28765. var b0 = this.getByte();
  28766. var b1 = this.getByte();
  28767. var b2 = this.getByte();
  28768. var b3 = this.getByte();
  28769. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  28770. },
  28771. // returns subarray of original buffer
  28772. // should only be read
  28773. getBytes: function Stream_getBytes(length) {
  28774. var bytes = this.bytes;
  28775. var pos = this.pos;
  28776. var strEnd = this.end;
  28777. if (!length) {
  28778. return bytes.subarray(pos, strEnd);
  28779. }
  28780. var end = pos + length;
  28781. if (end > strEnd) {
  28782. end = strEnd;
  28783. }
  28784. this.pos = end;
  28785. return bytes.subarray(pos, end);
  28786. },
  28787. peekBytes: function Stream_peekBytes(length) {
  28788. var bytes = this.getBytes(length);
  28789. this.pos -= bytes.length;
  28790. return bytes;
  28791. },
  28792. skip: function Stream_skip(n) {
  28793. if (!n) {
  28794. n = 1;
  28795. }
  28796. this.pos += n;
  28797. },
  28798. reset: function Stream_reset() {
  28799. this.pos = this.start;
  28800. },
  28801. moveStart: function Stream_moveStart() {
  28802. this.start = this.pos;
  28803. },
  28804. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  28805. return new Stream(this.bytes.buffer, start, length, dict);
  28806. },
  28807. isStream: true
  28808. };
  28809. return Stream;
  28810. })();
  28811. var StringStream = (function StringStreamClosure() {
  28812. function StringStream(str) {
  28813. var length = str.length;
  28814. var bytes = new Uint8Array(length);
  28815. for (var n = 0; n < length; ++n) {
  28816. bytes[n] = str.charCodeAt(n);
  28817. }
  28818. Stream.call(this, bytes);
  28819. }
  28820. StringStream.prototype = Stream.prototype;
  28821. return StringStream;
  28822. })();
  28823. // super class for the decoding streams
  28824. var DecodeStream = (function DecodeStreamClosure() {
  28825. // Lots of DecodeStreams are created whose buffers are never used. For these
  28826. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  28827. // having special cases that would be required if we used |null| for an empty
  28828. // buffer.
  28829. var emptyBuffer = new Uint8Array(0);
  28830. function DecodeStream(maybeMinBufferLength) {
  28831. this.pos = 0;
  28832. this.bufferLength = 0;
  28833. this.eof = false;
  28834. this.buffer = emptyBuffer;
  28835. this.minBufferLength = 512;
  28836. if (maybeMinBufferLength) {
  28837. // Compute the first power of two that is as big as maybeMinBufferLength.
  28838. while (this.minBufferLength < maybeMinBufferLength) {
  28839. this.minBufferLength *= 2;
  28840. }
  28841. }
  28842. }
  28843. DecodeStream.prototype = {
  28844. get isEmpty() {
  28845. while (!this.eof && this.bufferLength === 0) {
  28846. this.readBlock();
  28847. }
  28848. return this.bufferLength === 0;
  28849. },
  28850. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  28851. var buffer = this.buffer;
  28852. if (requested <= buffer.byteLength) {
  28853. return buffer;
  28854. }
  28855. var size = this.minBufferLength;
  28856. while (size < requested) {
  28857. size *= 2;
  28858. }
  28859. var buffer2 = new Uint8Array(size);
  28860. buffer2.set(buffer);
  28861. return (this.buffer = buffer2);
  28862. },
  28863. getByte: function DecodeStream_getByte() {
  28864. var pos = this.pos;
  28865. while (this.bufferLength <= pos) {
  28866. if (this.eof) {
  28867. return -1;
  28868. }
  28869. this.readBlock();
  28870. }
  28871. return this.buffer[this.pos++];
  28872. },
  28873. getUint16: function DecodeStream_getUint16() {
  28874. var b0 = this.getByte();
  28875. var b1 = this.getByte();
  28876. return (b0 << 8) + b1;
  28877. },
  28878. getInt32: function DecodeStream_getInt32() {
  28879. var b0 = this.getByte();
  28880. var b1 = this.getByte();
  28881. var b2 = this.getByte();
  28882. var b3 = this.getByte();
  28883. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  28884. },
  28885. getBytes: function DecodeStream_getBytes(length) {
  28886. var end, pos = this.pos;
  28887. if (length) {
  28888. this.ensureBuffer(pos + length);
  28889. end = pos + length;
  28890. while (!this.eof && this.bufferLength < end) {
  28891. this.readBlock();
  28892. }
  28893. var bufEnd = this.bufferLength;
  28894. if (end > bufEnd) {
  28895. end = bufEnd;
  28896. }
  28897. } else {
  28898. while (!this.eof) {
  28899. this.readBlock();
  28900. }
  28901. end = this.bufferLength;
  28902. }
  28903. this.pos = end;
  28904. return this.buffer.subarray(pos, end);
  28905. },
  28906. peekBytes: function DecodeStream_peekBytes(length) {
  28907. var bytes = this.getBytes(length);
  28908. this.pos -= bytes.length;
  28909. return bytes;
  28910. },
  28911. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  28912. var end = start + length;
  28913. while (this.bufferLength <= end && !this.eof) {
  28914. this.readBlock();
  28915. }
  28916. return new Stream(this.buffer, start, length, dict);
  28917. },
  28918. skip: function DecodeStream_skip(n) {
  28919. if (!n) {
  28920. n = 1;
  28921. }
  28922. this.pos += n;
  28923. },
  28924. reset: function DecodeStream_reset() {
  28925. this.pos = 0;
  28926. },
  28927. getBaseStreams: function DecodeStream_getBaseStreams() {
  28928. if (this.str && this.str.getBaseStreams) {
  28929. return this.str.getBaseStreams();
  28930. }
  28931. return [];
  28932. }
  28933. };
  28934. return DecodeStream;
  28935. })();
  28936. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  28937. function StreamsSequenceStream(streams) {
  28938. this.streams = streams;
  28939. DecodeStream.call(this, /* maybeLength = */ null);
  28940. }
  28941. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  28942. StreamsSequenceStream.prototype.readBlock =
  28943. function streamSequenceStreamReadBlock() {
  28944. var streams = this.streams;
  28945. if (streams.length === 0) {
  28946. this.eof = true;
  28947. return;
  28948. }
  28949. var stream = streams.shift();
  28950. var chunk = stream.getBytes();
  28951. var bufferLength = this.bufferLength;
  28952. var newLength = bufferLength + chunk.length;
  28953. var buffer = this.ensureBuffer(newLength);
  28954. buffer.set(chunk, bufferLength);
  28955. this.bufferLength = newLength;
  28956. };
  28957. StreamsSequenceStream.prototype.getBaseStreams =
  28958. function StreamsSequenceStream_getBaseStreams() {
  28959. var baseStreams = [];
  28960. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  28961. var stream = this.streams[i];
  28962. if (stream.getBaseStreams) {
  28963. Util.appendToArray(baseStreams, stream.getBaseStreams());
  28964. }
  28965. }
  28966. return baseStreams;
  28967. };
  28968. return StreamsSequenceStream;
  28969. })();
  28970. var FlateStream = (function FlateStreamClosure() {
  28971. var codeLenCodeMap = new Uint32Array([
  28972. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  28973. ]);
  28974. var lengthDecode = new Uint32Array([
  28975. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  28976. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  28977. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  28978. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  28979. ]);
  28980. var distDecode = new Uint32Array([
  28981. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  28982. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  28983. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  28984. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  28985. ]);
  28986. var fixedLitCodeTab = [new Uint32Array([
  28987. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  28988. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  28989. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  28990. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  28991. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  28992. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  28993. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  28994. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  28995. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  28996. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  28997. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  28998. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  28999. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29000. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29001. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29002. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29003. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29004. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29005. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29006. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29007. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29008. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29009. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29010. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29011. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29012. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29013. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29014. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29015. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29016. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29017. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29018. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29019. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29020. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29021. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29022. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29023. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29024. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29025. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29026. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29027. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29028. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29029. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29030. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29031. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29032. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29033. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29034. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29035. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29036. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29037. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29038. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29039. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29040. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29041. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29042. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29043. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29044. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29045. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29046. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29047. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29048. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29049. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29050. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29051. ]), 9];
  29052. var fixedDistCodeTab = [new Uint32Array([
  29053. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29054. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29055. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29056. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29057. ]), 5];
  29058. function FlateStream(str, maybeLength) {
  29059. this.str = str;
  29060. this.dict = str.dict;
  29061. var cmf = str.getByte();
  29062. var flg = str.getByte();
  29063. if (cmf === -1 || flg === -1) {
  29064. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29065. }
  29066. if ((cmf & 0x0f) !== 0x08) {
  29067. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29068. }
  29069. if ((((cmf << 8) + flg) % 31) !== 0) {
  29070. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29071. }
  29072. if (flg & 0x20) {
  29073. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29074. }
  29075. this.codeSize = 0;
  29076. this.codeBuf = 0;
  29077. DecodeStream.call(this, maybeLength);
  29078. }
  29079. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29080. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29081. var str = this.str;
  29082. var codeSize = this.codeSize;
  29083. var codeBuf = this.codeBuf;
  29084. var b;
  29085. while (codeSize < bits) {
  29086. if ((b = str.getByte()) === -1) {
  29087. error('Bad encoding in flate stream');
  29088. }
  29089. codeBuf |= b << codeSize;
  29090. codeSize += 8;
  29091. }
  29092. b = codeBuf & ((1 << bits) - 1);
  29093. this.codeBuf = codeBuf >> bits;
  29094. this.codeSize = codeSize -= bits;
  29095. return b;
  29096. };
  29097. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29098. var str = this.str;
  29099. var codes = table[0];
  29100. var maxLen = table[1];
  29101. var codeSize = this.codeSize;
  29102. var codeBuf = this.codeBuf;
  29103. var b;
  29104. while (codeSize < maxLen) {
  29105. if ((b = str.getByte()) === -1) {
  29106. // premature end of stream. code might however still be valid.
  29107. // codeSize < codeLen check below guards against incomplete codeVal.
  29108. break;
  29109. }
  29110. codeBuf |= (b << codeSize);
  29111. codeSize += 8;
  29112. }
  29113. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29114. var codeLen = code >> 16;
  29115. var codeVal = code & 0xffff;
  29116. if (codeLen < 1 || codeSize < codeLen) {
  29117. error('Bad encoding in flate stream');
  29118. }
  29119. this.codeBuf = (codeBuf >> codeLen);
  29120. this.codeSize = (codeSize - codeLen);
  29121. return codeVal;
  29122. };
  29123. FlateStream.prototype.generateHuffmanTable =
  29124. function flateStreamGenerateHuffmanTable(lengths) {
  29125. var n = lengths.length;
  29126. // find max code length
  29127. var maxLen = 0;
  29128. var i;
  29129. for (i = 0; i < n; ++i) {
  29130. if (lengths[i] > maxLen) {
  29131. maxLen = lengths[i];
  29132. }
  29133. }
  29134. // build the table
  29135. var size = 1 << maxLen;
  29136. var codes = new Uint32Array(size);
  29137. for (var len = 1, code = 0, skip = 2;
  29138. len <= maxLen;
  29139. ++len, code <<= 1, skip <<= 1) {
  29140. for (var val = 0; val < n; ++val) {
  29141. if (lengths[val] === len) {
  29142. // bit-reverse the code
  29143. var code2 = 0;
  29144. var t = code;
  29145. for (i = 0; i < len; ++i) {
  29146. code2 = (code2 << 1) | (t & 1);
  29147. t >>= 1;
  29148. }
  29149. // fill the table entries
  29150. for (i = code2; i < size; i += skip) {
  29151. codes[i] = (len << 16) | val;
  29152. }
  29153. ++code;
  29154. }
  29155. }
  29156. }
  29157. return [codes, maxLen];
  29158. };
  29159. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29160. var buffer, len;
  29161. var str = this.str;
  29162. // read block header
  29163. var hdr = this.getBits(3);
  29164. if (hdr & 1) {
  29165. this.eof = true;
  29166. }
  29167. hdr >>= 1;
  29168. if (hdr === 0) { // uncompressed block
  29169. var b;
  29170. if ((b = str.getByte()) === -1) {
  29171. error('Bad block header in flate stream');
  29172. }
  29173. var blockLen = b;
  29174. if ((b = str.getByte()) === -1) {
  29175. error('Bad block header in flate stream');
  29176. }
  29177. blockLen |= (b << 8);
  29178. if ((b = str.getByte()) === -1) {
  29179. error('Bad block header in flate stream');
  29180. }
  29181. var check = b;
  29182. if ((b = str.getByte()) === -1) {
  29183. error('Bad block header in flate stream');
  29184. }
  29185. check |= (b << 8);
  29186. if (check !== (~blockLen & 0xffff) &&
  29187. (blockLen !== 0 || check !== 0)) {
  29188. // Ignoring error for bad "empty" block (see issue 1277)
  29189. error('Bad uncompressed block length in flate stream');
  29190. }
  29191. this.codeBuf = 0;
  29192. this.codeSize = 0;
  29193. var bufferLength = this.bufferLength;
  29194. buffer = this.ensureBuffer(bufferLength + blockLen);
  29195. var end = bufferLength + blockLen;
  29196. this.bufferLength = end;
  29197. if (blockLen === 0) {
  29198. if (str.peekBytes(1).length === 0) {
  29199. this.eof = true;
  29200. }
  29201. } else {
  29202. for (var n = bufferLength; n < end; ++n) {
  29203. if ((b = str.getByte()) === -1) {
  29204. this.eof = true;
  29205. break;
  29206. }
  29207. buffer[n] = b;
  29208. }
  29209. }
  29210. return;
  29211. }
  29212. var litCodeTable;
  29213. var distCodeTable;
  29214. if (hdr === 1) { // compressed block, fixed codes
  29215. litCodeTable = fixedLitCodeTab;
  29216. distCodeTable = fixedDistCodeTab;
  29217. } else if (hdr === 2) { // compressed block, dynamic codes
  29218. var numLitCodes = this.getBits(5) + 257;
  29219. var numDistCodes = this.getBits(5) + 1;
  29220. var numCodeLenCodes = this.getBits(4) + 4;
  29221. // build the code lengths code table
  29222. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29223. var i;
  29224. for (i = 0; i < numCodeLenCodes; ++i) {
  29225. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29226. }
  29227. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29228. // build the literal and distance code tables
  29229. len = 0;
  29230. i = 0;
  29231. var codes = numLitCodes + numDistCodes;
  29232. var codeLengths = new Uint8Array(codes);
  29233. var bitsLength, bitsOffset, what;
  29234. while (i < codes) {
  29235. var code = this.getCode(codeLenCodeTab);
  29236. if (code === 16) {
  29237. bitsLength = 2; bitsOffset = 3; what = len;
  29238. } else if (code === 17) {
  29239. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29240. } else if (code === 18) {
  29241. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29242. } else {
  29243. codeLengths[i++] = len = code;
  29244. continue;
  29245. }
  29246. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29247. while (repeatLength-- > 0) {
  29248. codeLengths[i++] = what;
  29249. }
  29250. }
  29251. litCodeTable =
  29252. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29253. distCodeTable =
  29254. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29255. } else {
  29256. error('Unknown block type in flate stream');
  29257. }
  29258. buffer = this.buffer;
  29259. var limit = buffer ? buffer.length : 0;
  29260. var pos = this.bufferLength;
  29261. while (true) {
  29262. var code1 = this.getCode(litCodeTable);
  29263. if (code1 < 256) {
  29264. if (pos + 1 >= limit) {
  29265. buffer = this.ensureBuffer(pos + 1);
  29266. limit = buffer.length;
  29267. }
  29268. buffer[pos++] = code1;
  29269. continue;
  29270. }
  29271. if (code1 === 256) {
  29272. this.bufferLength = pos;
  29273. return;
  29274. }
  29275. code1 -= 257;
  29276. code1 = lengthDecode[code1];
  29277. var code2 = code1 >> 16;
  29278. if (code2 > 0) {
  29279. code2 = this.getBits(code2);
  29280. }
  29281. len = (code1 & 0xffff) + code2;
  29282. code1 = this.getCode(distCodeTable);
  29283. code1 = distDecode[code1];
  29284. code2 = code1 >> 16;
  29285. if (code2 > 0) {
  29286. code2 = this.getBits(code2);
  29287. }
  29288. var dist = (code1 & 0xffff) + code2;
  29289. if (pos + len >= limit) {
  29290. buffer = this.ensureBuffer(pos + len);
  29291. limit = buffer.length;
  29292. }
  29293. for (var k = 0; k < len; ++k, ++pos) {
  29294. buffer[pos] = buffer[pos - dist];
  29295. }
  29296. }
  29297. };
  29298. return FlateStream;
  29299. })();
  29300. var PredictorStream = (function PredictorStreamClosure() {
  29301. function PredictorStream(str, maybeLength, params) {
  29302. var predictor = this.predictor = params.get('Predictor') || 1;
  29303. if (predictor <= 1) {
  29304. return str; // no prediction
  29305. }
  29306. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29307. error('Unsupported predictor: ' + predictor);
  29308. }
  29309. if (predictor === 2) {
  29310. this.readBlock = this.readBlockTiff;
  29311. } else {
  29312. this.readBlock = this.readBlockPng;
  29313. }
  29314. this.str = str;
  29315. this.dict = str.dict;
  29316. var colors = this.colors = params.get('Colors') || 1;
  29317. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29318. var columns = this.columns = params.get('Columns') || 1;
  29319. this.pixBytes = (colors * bits + 7) >> 3;
  29320. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29321. DecodeStream.call(this, maybeLength);
  29322. return this;
  29323. }
  29324. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29325. PredictorStream.prototype.readBlockTiff =
  29326. function predictorStreamReadBlockTiff() {
  29327. var rowBytes = this.rowBytes;
  29328. var bufferLength = this.bufferLength;
  29329. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29330. var bits = this.bits;
  29331. var colors = this.colors;
  29332. var rawBytes = this.str.getBytes(rowBytes);
  29333. this.eof = !rawBytes.length;
  29334. if (this.eof) {
  29335. return;
  29336. }
  29337. var inbuf = 0, outbuf = 0;
  29338. var inbits = 0, outbits = 0;
  29339. var pos = bufferLength;
  29340. var i;
  29341. if (bits === 1) {
  29342. for (i = 0; i < rowBytes; ++i) {
  29343. var c = rawBytes[i];
  29344. inbuf = (inbuf << 8) | c;
  29345. // bitwise addition is exclusive or
  29346. // first shift inbuf and then add
  29347. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  29348. // truncate inbuf (assumes colors < 16)
  29349. inbuf &= 0xFFFF;
  29350. }
  29351. } else if (bits === 8) {
  29352. for (i = 0; i < colors; ++i) {
  29353. buffer[pos++] = rawBytes[i];
  29354. }
  29355. for (; i < rowBytes; ++i) {
  29356. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  29357. pos++;
  29358. }
  29359. } else {
  29360. var compArray = new Uint8Array(colors + 1);
  29361. var bitMask = (1 << bits) - 1;
  29362. var j = 0, k = bufferLength;
  29363. var columns = this.columns;
  29364. for (i = 0; i < columns; ++i) {
  29365. for (var kk = 0; kk < colors; ++kk) {
  29366. if (inbits < bits) {
  29367. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  29368. inbits += 8;
  29369. }
  29370. compArray[kk] = (compArray[kk] +
  29371. (inbuf >> (inbits - bits))) & bitMask;
  29372. inbits -= bits;
  29373. outbuf = (outbuf << bits) | compArray[kk];
  29374. outbits += bits;
  29375. if (outbits >= 8) {
  29376. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  29377. outbits -= 8;
  29378. }
  29379. }
  29380. }
  29381. if (outbits > 0) {
  29382. buffer[k++] = (outbuf << (8 - outbits)) +
  29383. (inbuf & ((1 << (8 - outbits)) - 1));
  29384. }
  29385. }
  29386. this.bufferLength += rowBytes;
  29387. };
  29388. PredictorStream.prototype.readBlockPng =
  29389. function predictorStreamReadBlockPng() {
  29390. var rowBytes = this.rowBytes;
  29391. var pixBytes = this.pixBytes;
  29392. var predictor = this.str.getByte();
  29393. var rawBytes = this.str.getBytes(rowBytes);
  29394. this.eof = !rawBytes.length;
  29395. if (this.eof) {
  29396. return;
  29397. }
  29398. var bufferLength = this.bufferLength;
  29399. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  29400. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  29401. if (prevRow.length === 0) {
  29402. prevRow = new Uint8Array(rowBytes);
  29403. }
  29404. var i, j = bufferLength, up, c;
  29405. switch (predictor) {
  29406. case 0:
  29407. for (i = 0; i < rowBytes; ++i) {
  29408. buffer[j++] = rawBytes[i];
  29409. }
  29410. break;
  29411. case 1:
  29412. for (i = 0; i < pixBytes; ++i) {
  29413. buffer[j++] = rawBytes[i];
  29414. }
  29415. for (; i < rowBytes; ++i) {
  29416. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  29417. j++;
  29418. }
  29419. break;
  29420. case 2:
  29421. for (i = 0; i < rowBytes; ++i) {
  29422. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  29423. }
  29424. break;
  29425. case 3:
  29426. for (i = 0; i < pixBytes; ++i) {
  29427. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  29428. }
  29429. for (; i < rowBytes; ++i) {
  29430. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  29431. rawBytes[i]) & 0xFF;
  29432. j++;
  29433. }
  29434. break;
  29435. case 4:
  29436. // we need to save the up left pixels values. the simplest way
  29437. // is to create a new buffer
  29438. for (i = 0; i < pixBytes; ++i) {
  29439. up = prevRow[i];
  29440. c = rawBytes[i];
  29441. buffer[j++] = up + c;
  29442. }
  29443. for (; i < rowBytes; ++i) {
  29444. up = prevRow[i];
  29445. var upLeft = prevRow[i - pixBytes];
  29446. var left = buffer[j - pixBytes];
  29447. var p = left + up - upLeft;
  29448. var pa = p - left;
  29449. if (pa < 0) {
  29450. pa = -pa;
  29451. }
  29452. var pb = p - up;
  29453. if (pb < 0) {
  29454. pb = -pb;
  29455. }
  29456. var pc = p - upLeft;
  29457. if (pc < 0) {
  29458. pc = -pc;
  29459. }
  29460. c = rawBytes[i];
  29461. if (pa <= pb && pa <= pc) {
  29462. buffer[j++] = left + c;
  29463. } else if (pb <= pc) {
  29464. buffer[j++] = up + c;
  29465. } else {
  29466. buffer[j++] = upLeft + c;
  29467. }
  29468. }
  29469. break;
  29470. default:
  29471. error('Unsupported predictor: ' + predictor);
  29472. }
  29473. this.bufferLength += rowBytes;
  29474. };
  29475. return PredictorStream;
  29476. })();
  29477. /**
  29478. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  29479. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  29480. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  29481. * a library to decode these images and the stream behaves like all the other
  29482. * DecodeStreams.
  29483. */
  29484. var JpegStream = (function JpegStreamClosure() {
  29485. function JpegStream(stream, maybeLength, dict, xref) {
  29486. // TODO: per poppler, some images may have 'junk' before that
  29487. // need to be removed
  29488. this.stream = stream;
  29489. this.maybeLength = maybeLength;
  29490. this.dict = dict;
  29491. DecodeStream.call(this, maybeLength);
  29492. }
  29493. JpegStream.prototype = Object.create(DecodeStream.prototype);
  29494. Object.defineProperty(JpegStream.prototype, 'bytes', {
  29495. get: function JpegStream_bytes() {
  29496. // If this.maybeLength is null, we'll get the entire stream.
  29497. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29498. },
  29499. configurable: true
  29500. });
  29501. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  29502. if (this.bufferLength) {
  29503. return;
  29504. }
  29505. try {
  29506. var jpegImage = new JpegImage();
  29507. // checking if values needs to be transformed before conversion
  29508. if (this.dict && isArray(this.dict.get('Decode'))) {
  29509. var decodeArr = this.dict.get('Decode');
  29510. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  29511. var decodeArrLength = decodeArr.length;
  29512. var transform = new Int32Array(decodeArrLength);
  29513. var transformNeeded = false;
  29514. var maxValue = (1 << bitsPerComponent) - 1;
  29515. for (var i = 0; i < decodeArrLength; i += 2) {
  29516. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  29517. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  29518. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  29519. transformNeeded = true;
  29520. }
  29521. }
  29522. if (transformNeeded) {
  29523. jpegImage.decodeTransform = transform;
  29524. }
  29525. }
  29526. jpegImage.parse(this.bytes);
  29527. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  29528. this.forceRGB);
  29529. this.buffer = data;
  29530. this.bufferLength = data.length;
  29531. this.eof = true;
  29532. } catch (e) {
  29533. error('JPEG error: ' + e);
  29534. }
  29535. };
  29536. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  29537. this.ensureBuffer();
  29538. return this.buffer;
  29539. };
  29540. JpegStream.prototype.getIR = function JpegStream_getIR() {
  29541. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  29542. };
  29543. /**
  29544. * Checks if the image can be decoded and displayed by the browser without any
  29545. * further processing such as color space conversions.
  29546. */
  29547. JpegStream.prototype.isNativelySupported =
  29548. function JpegStream_isNativelySupported(xref, res) {
  29549. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29550. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  29551. };
  29552. /**
  29553. * Checks if the image can be decoded by the browser.
  29554. */
  29555. JpegStream.prototype.isNativelyDecodable =
  29556. function JpegStream_isNativelyDecodable(xref, res) {
  29557. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  29558. var numComps = cs.numComps;
  29559. return numComps === 1 || numComps === 3;
  29560. };
  29561. return JpegStream;
  29562. })();
  29563. /**
  29564. * For JPEG 2000's we use a library to decode these images and
  29565. * the stream behaves like all the other DecodeStreams.
  29566. */
  29567. var JpxStream = (function JpxStreamClosure() {
  29568. function JpxStream(stream, maybeLength, dict) {
  29569. this.stream = stream;
  29570. this.maybeLength = maybeLength;
  29571. this.dict = dict;
  29572. DecodeStream.call(this, maybeLength);
  29573. }
  29574. JpxStream.prototype = Object.create(DecodeStream.prototype);
  29575. Object.defineProperty(JpxStream.prototype, 'bytes', {
  29576. get: function JpxStream_bytes() {
  29577. // If this.maybeLength is null, we'll get the entire stream.
  29578. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29579. },
  29580. configurable: true
  29581. });
  29582. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  29583. if (this.bufferLength) {
  29584. return;
  29585. }
  29586. var jpxImage = new JpxImage();
  29587. jpxImage.parse(this.bytes);
  29588. var width = jpxImage.width;
  29589. var height = jpxImage.height;
  29590. var componentsCount = jpxImage.componentsCount;
  29591. var tileCount = jpxImage.tiles.length;
  29592. if (tileCount === 1) {
  29593. this.buffer = jpxImage.tiles[0].items;
  29594. } else {
  29595. var data = new Uint8Array(width * height * componentsCount);
  29596. for (var k = 0; k < tileCount; k++) {
  29597. var tileComponents = jpxImage.tiles[k];
  29598. var tileWidth = tileComponents.width;
  29599. var tileHeight = tileComponents.height;
  29600. var tileLeft = tileComponents.left;
  29601. var tileTop = tileComponents.top;
  29602. var src = tileComponents.items;
  29603. var srcPosition = 0;
  29604. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  29605. var imgRowSize = width * componentsCount;
  29606. var tileRowSize = tileWidth * componentsCount;
  29607. for (var j = 0; j < tileHeight; j++) {
  29608. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  29609. data.set(rowBytes, dataPosition);
  29610. srcPosition += tileRowSize;
  29611. dataPosition += imgRowSize;
  29612. }
  29613. }
  29614. this.buffer = data;
  29615. }
  29616. this.bufferLength = this.buffer.length;
  29617. this.eof = true;
  29618. };
  29619. return JpxStream;
  29620. })();
  29621. /**
  29622. * For JBIG2's we use a library to decode these images and
  29623. * the stream behaves like all the other DecodeStreams.
  29624. */
  29625. var Jbig2Stream = (function Jbig2StreamClosure() {
  29626. function Jbig2Stream(stream, maybeLength, dict) {
  29627. this.stream = stream;
  29628. this.maybeLength = maybeLength;
  29629. this.dict = dict;
  29630. DecodeStream.call(this, maybeLength);
  29631. }
  29632. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  29633. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  29634. get: function Jbig2Stream_bytes() {
  29635. // If this.maybeLength is null, we'll get the entire stream.
  29636. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  29637. },
  29638. configurable: true
  29639. });
  29640. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  29641. if (this.bufferLength) {
  29642. return;
  29643. }
  29644. var jbig2Image = new Jbig2Image();
  29645. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  29646. // According to the PDF specification, DecodeParms can be either
  29647. // a dictionary, or an array whose elements are dictionaries.
  29648. if (isArray(decodeParams)) {
  29649. if (decodeParams.length > 1) {
  29650. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  29651. 'not supported.');
  29652. }
  29653. decodeParams = decodeParams[0];
  29654. }
  29655. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  29656. var globalsStream = decodeParams.get('JBIG2Globals');
  29657. var globals = globalsStream.getBytes();
  29658. chunks.push({data: globals, start: 0, end: globals.length});
  29659. }
  29660. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  29661. var data = jbig2Image.parseChunks(chunks);
  29662. var dataLength = data.length;
  29663. // JBIG2 had black as 1 and white as 0, inverting the colors
  29664. for (var i = 0; i < dataLength; i++) {
  29665. data[i] ^= 0xFF;
  29666. }
  29667. this.buffer = data;
  29668. this.bufferLength = dataLength;
  29669. this.eof = true;
  29670. };
  29671. return Jbig2Stream;
  29672. })();
  29673. var DecryptStream = (function DecryptStreamClosure() {
  29674. function DecryptStream(str, maybeLength, decrypt) {
  29675. this.str = str;
  29676. this.dict = str.dict;
  29677. this.decrypt = decrypt;
  29678. this.nextChunk = null;
  29679. this.initialized = false;
  29680. DecodeStream.call(this, maybeLength);
  29681. }
  29682. var chunkSize = 512;
  29683. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  29684. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  29685. var chunk;
  29686. if (this.initialized) {
  29687. chunk = this.nextChunk;
  29688. } else {
  29689. chunk = this.str.getBytes(chunkSize);
  29690. this.initialized = true;
  29691. }
  29692. if (!chunk || chunk.length === 0) {
  29693. this.eof = true;
  29694. return;
  29695. }
  29696. this.nextChunk = this.str.getBytes(chunkSize);
  29697. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  29698. var decrypt = this.decrypt;
  29699. chunk = decrypt(chunk, !hasMoreData);
  29700. var bufferLength = this.bufferLength;
  29701. var i, n = chunk.length;
  29702. var buffer = this.ensureBuffer(bufferLength + n);
  29703. for (i = 0; i < n; i++) {
  29704. buffer[bufferLength++] = chunk[i];
  29705. }
  29706. this.bufferLength = bufferLength;
  29707. };
  29708. return DecryptStream;
  29709. })();
  29710. var Ascii85Stream = (function Ascii85StreamClosure() {
  29711. function Ascii85Stream(str, maybeLength) {
  29712. this.str = str;
  29713. this.dict = str.dict;
  29714. this.input = new Uint8Array(5);
  29715. // Most streams increase in size when decoded, but Ascii85 streams
  29716. // typically shrink by ~20%.
  29717. if (maybeLength) {
  29718. maybeLength = 0.8 * maybeLength;
  29719. }
  29720. DecodeStream.call(this, maybeLength);
  29721. }
  29722. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  29723. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  29724. var TILDA_CHAR = 0x7E; // '~'
  29725. var Z_LOWER_CHAR = 0x7A; // 'z'
  29726. var EOF = -1;
  29727. var str = this.str;
  29728. var c = str.getByte();
  29729. while (Lexer.isSpace(c)) {
  29730. c = str.getByte();
  29731. }
  29732. if (c === EOF || c === TILDA_CHAR) {
  29733. this.eof = true;
  29734. return;
  29735. }
  29736. var bufferLength = this.bufferLength, buffer;
  29737. var i;
  29738. // special code for z
  29739. if (c === Z_LOWER_CHAR) {
  29740. buffer = this.ensureBuffer(bufferLength + 4);
  29741. for (i = 0; i < 4; ++i) {
  29742. buffer[bufferLength + i] = 0;
  29743. }
  29744. this.bufferLength += 4;
  29745. } else {
  29746. var input = this.input;
  29747. input[0] = c;
  29748. for (i = 1; i < 5; ++i) {
  29749. c = str.getByte();
  29750. while (Lexer.isSpace(c)) {
  29751. c = str.getByte();
  29752. }
  29753. input[i] = c;
  29754. if (c === EOF || c === TILDA_CHAR) {
  29755. break;
  29756. }
  29757. }
  29758. buffer = this.ensureBuffer(bufferLength + i - 1);
  29759. this.bufferLength += i - 1;
  29760. // partial ending;
  29761. if (i < 5) {
  29762. for (; i < 5; ++i) {
  29763. input[i] = 0x21 + 84;
  29764. }
  29765. this.eof = true;
  29766. }
  29767. var t = 0;
  29768. for (i = 0; i < 5; ++i) {
  29769. t = t * 85 + (input[i] - 0x21);
  29770. }
  29771. for (i = 3; i >= 0; --i) {
  29772. buffer[bufferLength + i] = t & 0xFF;
  29773. t >>= 8;
  29774. }
  29775. }
  29776. };
  29777. return Ascii85Stream;
  29778. })();
  29779. var AsciiHexStream = (function AsciiHexStreamClosure() {
  29780. function AsciiHexStream(str, maybeLength) {
  29781. this.str = str;
  29782. this.dict = str.dict;
  29783. this.firstDigit = -1;
  29784. // Most streams increase in size when decoded, but AsciiHex streams shrink
  29785. // by 50%.
  29786. if (maybeLength) {
  29787. maybeLength = 0.5 * maybeLength;
  29788. }
  29789. DecodeStream.call(this, maybeLength);
  29790. }
  29791. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  29792. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  29793. var UPSTREAM_BLOCK_SIZE = 8000;
  29794. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  29795. if (!bytes.length) {
  29796. this.eof = true;
  29797. return;
  29798. }
  29799. var maxDecodeLength = (bytes.length + 1) >> 1;
  29800. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  29801. var bufferLength = this.bufferLength;
  29802. var firstDigit = this.firstDigit;
  29803. for (var i = 0, ii = bytes.length; i < ii; i++) {
  29804. var ch = bytes[i], digit;
  29805. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29806. digit = ch & 0x0F;
  29807. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29808. // 'A'-'Z', 'a'-'z'
  29809. digit = (ch & 0x0F) + 9;
  29810. } else if (ch === 0x3E) { // '>'
  29811. this.eof = true;
  29812. break;
  29813. } else { // probably whitespace
  29814. continue; // ignoring
  29815. }
  29816. if (firstDigit < 0) {
  29817. firstDigit = digit;
  29818. } else {
  29819. buffer[bufferLength++] = (firstDigit << 4) | digit;
  29820. firstDigit = -1;
  29821. }
  29822. }
  29823. if (firstDigit >= 0 && this.eof) {
  29824. // incomplete byte
  29825. buffer[bufferLength++] = (firstDigit << 4);
  29826. firstDigit = -1;
  29827. }
  29828. this.firstDigit = firstDigit;
  29829. this.bufferLength = bufferLength;
  29830. };
  29831. return AsciiHexStream;
  29832. })();
  29833. var RunLengthStream = (function RunLengthStreamClosure() {
  29834. function RunLengthStream(str, maybeLength) {
  29835. this.str = str;
  29836. this.dict = str.dict;
  29837. DecodeStream.call(this, maybeLength);
  29838. }
  29839. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  29840. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  29841. // The repeatHeader has following format. The first byte defines type of run
  29842. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  29843. // (in addition to the second byte from the header), n = 129 through 255 -
  29844. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  29845. var repeatHeader = this.str.getBytes(2);
  29846. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  29847. this.eof = true;
  29848. return;
  29849. }
  29850. var buffer;
  29851. var bufferLength = this.bufferLength;
  29852. var n = repeatHeader[0];
  29853. if (n < 128) {
  29854. // copy n bytes
  29855. buffer = this.ensureBuffer(bufferLength + n + 1);
  29856. buffer[bufferLength++] = repeatHeader[1];
  29857. if (n > 0) {
  29858. var source = this.str.getBytes(n);
  29859. buffer.set(source, bufferLength);
  29860. bufferLength += n;
  29861. }
  29862. } else {
  29863. n = 257 - n;
  29864. var b = repeatHeader[1];
  29865. buffer = this.ensureBuffer(bufferLength + n + 1);
  29866. for (var i = 0; i < n; i++) {
  29867. buffer[bufferLength++] = b;
  29868. }
  29869. }
  29870. this.bufferLength = bufferLength;
  29871. };
  29872. return RunLengthStream;
  29873. })();
  29874. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  29875. var ccittEOL = -2;
  29876. var twoDimPass = 0;
  29877. var twoDimHoriz = 1;
  29878. var twoDimVert0 = 2;
  29879. var twoDimVertR1 = 3;
  29880. var twoDimVertL1 = 4;
  29881. var twoDimVertR2 = 5;
  29882. var twoDimVertL2 = 6;
  29883. var twoDimVertR3 = 7;
  29884. var twoDimVertL3 = 8;
  29885. var twoDimTable = [
  29886. [-1, -1], [-1, -1], // 000000x
  29887. [7, twoDimVertL3], // 0000010
  29888. [7, twoDimVertR3], // 0000011
  29889. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  29890. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  29891. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  29892. [4, twoDimPass], [4, twoDimPass],
  29893. [4, twoDimPass], [4, twoDimPass],
  29894. [4, twoDimPass], [4, twoDimPass],
  29895. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  29896. [3, twoDimHoriz], [3, twoDimHoriz],
  29897. [3, twoDimHoriz], [3, twoDimHoriz],
  29898. [3, twoDimHoriz], [3, twoDimHoriz],
  29899. [3, twoDimHoriz], [3, twoDimHoriz],
  29900. [3, twoDimHoriz], [3, twoDimHoriz],
  29901. [3, twoDimHoriz], [3, twoDimHoriz],
  29902. [3, twoDimHoriz], [3, twoDimHoriz],
  29903. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  29904. [3, twoDimVertL1], [3, twoDimVertL1],
  29905. [3, twoDimVertL1], [3, twoDimVertL1],
  29906. [3, twoDimVertL1], [3, twoDimVertL1],
  29907. [3, twoDimVertL1], [3, twoDimVertL1],
  29908. [3, twoDimVertL1], [3, twoDimVertL1],
  29909. [3, twoDimVertL1], [3, twoDimVertL1],
  29910. [3, twoDimVertL1], [3, twoDimVertL1],
  29911. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  29912. [3, twoDimVertR1], [3, twoDimVertR1],
  29913. [3, twoDimVertR1], [3, twoDimVertR1],
  29914. [3, twoDimVertR1], [3, twoDimVertR1],
  29915. [3, twoDimVertR1], [3, twoDimVertR1],
  29916. [3, twoDimVertR1], [3, twoDimVertR1],
  29917. [3, twoDimVertR1], [3, twoDimVertR1],
  29918. [3, twoDimVertR1], [3, twoDimVertR1],
  29919. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  29920. [1, twoDimVert0], [1, twoDimVert0],
  29921. [1, twoDimVert0], [1, twoDimVert0],
  29922. [1, twoDimVert0], [1, twoDimVert0],
  29923. [1, twoDimVert0], [1, twoDimVert0],
  29924. [1, twoDimVert0], [1, twoDimVert0],
  29925. [1, twoDimVert0], [1, twoDimVert0],
  29926. [1, twoDimVert0], [1, twoDimVert0],
  29927. [1, twoDimVert0], [1, twoDimVert0],
  29928. [1, twoDimVert0], [1, twoDimVert0],
  29929. [1, twoDimVert0], [1, twoDimVert0],
  29930. [1, twoDimVert0], [1, twoDimVert0],
  29931. [1, twoDimVert0], [1, twoDimVert0],
  29932. [1, twoDimVert0], [1, twoDimVert0],
  29933. [1, twoDimVert0], [1, twoDimVert0],
  29934. [1, twoDimVert0], [1, twoDimVert0],
  29935. [1, twoDimVert0], [1, twoDimVert0],
  29936. [1, twoDimVert0], [1, twoDimVert0],
  29937. [1, twoDimVert0], [1, twoDimVert0],
  29938. [1, twoDimVert0], [1, twoDimVert0],
  29939. [1, twoDimVert0], [1, twoDimVert0],
  29940. [1, twoDimVert0], [1, twoDimVert0],
  29941. [1, twoDimVert0], [1, twoDimVert0],
  29942. [1, twoDimVert0], [1, twoDimVert0],
  29943. [1, twoDimVert0], [1, twoDimVert0],
  29944. [1, twoDimVert0], [1, twoDimVert0],
  29945. [1, twoDimVert0], [1, twoDimVert0],
  29946. [1, twoDimVert0], [1, twoDimVert0],
  29947. [1, twoDimVert0], [1, twoDimVert0],
  29948. [1, twoDimVert0], [1, twoDimVert0],
  29949. [1, twoDimVert0], [1, twoDimVert0],
  29950. [1, twoDimVert0], [1, twoDimVert0]
  29951. ];
  29952. var whiteTable1 = [
  29953. [-1, -1], // 00000
  29954. [12, ccittEOL], // 00001
  29955. [-1, -1], [-1, -1], // 0001x
  29956. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  29957. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  29958. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  29959. [11, 1792], [11, 1792], // 1000x
  29960. [12, 1984], // 10010
  29961. [12, 2048], // 10011
  29962. [12, 2112], // 10100
  29963. [12, 2176], // 10101
  29964. [12, 2240], // 10110
  29965. [12, 2304], // 10111
  29966. [11, 1856], [11, 1856], // 1100x
  29967. [11, 1920], [11, 1920], // 1101x
  29968. [12, 2368], // 11100
  29969. [12, 2432], // 11101
  29970. [12, 2496], // 11110
  29971. [12, 2560] // 11111
  29972. ];
  29973. var whiteTable2 = [
  29974. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  29975. [8, 29], [8, 29], // 00000010x
  29976. [8, 30], [8, 30], // 00000011x
  29977. [8, 45], [8, 45], // 00000100x
  29978. [8, 46], [8, 46], // 00000101x
  29979. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  29980. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  29981. [8, 47], [8, 47], // 00001010x
  29982. [8, 48], [8, 48], // 00001011x
  29983. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  29984. [6, 13], [6, 13], [6, 13], [6, 13],
  29985. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  29986. [8, 33], [8, 33], // 00010010x
  29987. [8, 34], [8, 34], // 00010011x
  29988. [8, 35], [8, 35], // 00010100x
  29989. [8, 36], [8, 36], // 00010101x
  29990. [8, 37], [8, 37], // 00010110x
  29991. [8, 38], [8, 38], // 00010111x
  29992. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  29993. [8, 31], [8, 31], // 00011010x
  29994. [8, 32], [8, 32], // 00011011x
  29995. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  29996. [6, 1], [6, 1], [6, 1], [6, 1],
  29997. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  29998. [6, 12], [6, 12], [6, 12], [6, 12],
  29999. [8, 53], [8, 53], // 00100100x
  30000. [8, 54], [8, 54], // 00100101x
  30001. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30002. [8, 39], [8, 39], // 00101000x
  30003. [8, 40], [8, 40], // 00101001x
  30004. [8, 41], [8, 41], // 00101010x
  30005. [8, 42], [8, 42], // 00101011x
  30006. [8, 43], [8, 43], // 00101100x
  30007. [8, 44], [8, 44], // 00101101x
  30008. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30009. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30010. [8, 61], [8, 61], // 00110010x
  30011. [8, 62], [8, 62], // 00110011x
  30012. [8, 63], [8, 63], // 00110100x
  30013. [8, 0], [8, 0], // 00110101x
  30014. [8, 320], [8, 320], // 00110110x
  30015. [8, 384], [8, 384], // 00110111x
  30016. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30017. [5, 10], [5, 10], [5, 10], [5, 10],
  30018. [5, 10], [5, 10], [5, 10], [5, 10],
  30019. [5, 10], [5, 10], [5, 10], [5, 10],
  30020. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30021. [5, 11], [5, 11], [5, 11], [5, 11],
  30022. [5, 11], [5, 11], [5, 11], [5, 11],
  30023. [5, 11], [5, 11], [5, 11], [5, 11],
  30024. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30025. [8, 59], [8, 59], // 01001010x
  30026. [8, 60], [8, 60], // 01001011x
  30027. [9, 1472], // 010011000
  30028. [9, 1536], // 010011001
  30029. [9, 1600], // 010011010
  30030. [9, 1728], // 010011011
  30031. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30032. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30033. [8, 49], [8, 49], // 01010010x
  30034. [8, 50], [8, 50], // 01010011x
  30035. [8, 51], [8, 51], // 01010100x
  30036. [8, 52], [8, 52], // 01010101x
  30037. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30038. [8, 55], [8, 55], // 01011000x
  30039. [8, 56], [8, 56], // 01011001x
  30040. [8, 57], [8, 57], // 01011010x
  30041. [8, 58], [8, 58], // 01011011x
  30042. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30043. [6, 192], [6, 192], [6, 192], [6, 192],
  30044. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30045. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30046. [8, 448], [8, 448], // 01100100x
  30047. [8, 512], [8, 512], // 01100101x
  30048. [9, 704], // 011001100
  30049. [9, 768], // 011001101
  30050. [8, 640], [8, 640], // 01100111x
  30051. [8, 576], [8, 576], // 01101000x
  30052. [9, 832], // 011010010
  30053. [9, 896], // 011010011
  30054. [9, 960], // 011010100
  30055. [9, 1024], // 011010101
  30056. [9, 1088], // 011010110
  30057. [9, 1152], // 011010111
  30058. [9, 1216], // 011011000
  30059. [9, 1280], // 011011001
  30060. [9, 1344], // 011011010
  30061. [9, 1408], // 011011011
  30062. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30063. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30064. [4, 2], [4, 2], [4, 2], [4, 2],
  30065. [4, 2], [4, 2], [4, 2], [4, 2],
  30066. [4, 2], [4, 2], [4, 2], [4, 2],
  30067. [4, 2], [4, 2], [4, 2], [4, 2],
  30068. [4, 2], [4, 2], [4, 2], [4, 2],
  30069. [4, 2], [4, 2], [4, 2], [4, 2],
  30070. [4, 2], [4, 2], [4, 2], [4, 2],
  30071. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30072. [4, 3], [4, 3], [4, 3], [4, 3],
  30073. [4, 3], [4, 3], [4, 3], [4, 3],
  30074. [4, 3], [4, 3], [4, 3], [4, 3],
  30075. [4, 3], [4, 3], [4, 3], [4, 3],
  30076. [4, 3], [4, 3], [4, 3], [4, 3],
  30077. [4, 3], [4, 3], [4, 3], [4, 3],
  30078. [4, 3], [4, 3], [4, 3], [4, 3],
  30079. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30080. [5, 128], [5, 128], [5, 128], [5, 128],
  30081. [5, 128], [5, 128], [5, 128], [5, 128],
  30082. [5, 128], [5, 128], [5, 128], [5, 128],
  30083. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30084. [5, 8], [5, 8], [5, 8], [5, 8],
  30085. [5, 8], [5, 8], [5, 8], [5, 8],
  30086. [5, 8], [5, 8], [5, 8], [5, 8],
  30087. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30088. [5, 9], [5, 9], [5, 9], [5, 9],
  30089. [5, 9], [5, 9], [5, 9], [5, 9],
  30090. [5, 9], [5, 9], [5, 9], [5, 9],
  30091. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30092. [6, 16], [6, 16], [6, 16], [6, 16],
  30093. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30094. [6, 17], [6, 17], [6, 17], [6, 17],
  30095. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30096. [4, 4], [4, 4], [4, 4], [4, 4],
  30097. [4, 4], [4, 4], [4, 4], [4, 4],
  30098. [4, 4], [4, 4], [4, 4], [4, 4],
  30099. [4, 4], [4, 4], [4, 4], [4, 4],
  30100. [4, 4], [4, 4], [4, 4], [4, 4],
  30101. [4, 4], [4, 4], [4, 4], [4, 4],
  30102. [4, 4], [4, 4], [4, 4], [4, 4],
  30103. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30104. [4, 5], [4, 5], [4, 5], [4, 5],
  30105. [4, 5], [4, 5], [4, 5], [4, 5],
  30106. [4, 5], [4, 5], [4, 5], [4, 5],
  30107. [4, 5], [4, 5], [4, 5], [4, 5],
  30108. [4, 5], [4, 5], [4, 5], [4, 5],
  30109. [4, 5], [4, 5], [4, 5], [4, 5],
  30110. [4, 5], [4, 5], [4, 5], [4, 5],
  30111. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30112. [6, 14], [6, 14], [6, 14], [6, 14],
  30113. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30114. [6, 15], [6, 15], [6, 15], [6, 15],
  30115. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30116. [5, 64], [5, 64], [5, 64], [5, 64],
  30117. [5, 64], [5, 64], [5, 64], [5, 64],
  30118. [5, 64], [5, 64], [5, 64], [5, 64],
  30119. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30120. [4, 6], [4, 6], [4, 6], [4, 6],
  30121. [4, 6], [4, 6], [4, 6], [4, 6],
  30122. [4, 6], [4, 6], [4, 6], [4, 6],
  30123. [4, 6], [4, 6], [4, 6], [4, 6],
  30124. [4, 6], [4, 6], [4, 6], [4, 6],
  30125. [4, 6], [4, 6], [4, 6], [4, 6],
  30126. [4, 6], [4, 6], [4, 6], [4, 6],
  30127. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30128. [4, 7], [4, 7], [4, 7], [4, 7],
  30129. [4, 7], [4, 7], [4, 7], [4, 7],
  30130. [4, 7], [4, 7], [4, 7], [4, 7],
  30131. [4, 7], [4, 7], [4, 7], [4, 7],
  30132. [4, 7], [4, 7], [4, 7], [4, 7],
  30133. [4, 7], [4, 7], [4, 7], [4, 7],
  30134. [4, 7], [4, 7], [4, 7], [4, 7]
  30135. ];
  30136. var blackTable1 = [
  30137. [-1, -1], [-1, -1], // 000000000000x
  30138. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30139. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30140. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30141. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30142. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30143. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30144. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30145. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30146. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30147. [12, 1984], [12, 1984], // 000000010010x
  30148. [12, 2048], [12, 2048], // 000000010011x
  30149. [12, 2112], [12, 2112], // 000000010100x
  30150. [12, 2176], [12, 2176], // 000000010101x
  30151. [12, 2240], [12, 2240], // 000000010110x
  30152. [12, 2304], [12, 2304], // 000000010111x
  30153. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30154. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30155. [12, 2368], [12, 2368], // 000000011100x
  30156. [12, 2432], [12, 2432], // 000000011101x
  30157. [12, 2496], [12, 2496], // 000000011110x
  30158. [12, 2560], [12, 2560], // 000000011111x
  30159. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30160. [10, 18], [10, 18], [10, 18], [10, 18],
  30161. [12, 52], [12, 52], // 000000100100x
  30162. [13, 640], // 0000001001010
  30163. [13, 704], // 0000001001011
  30164. [13, 768], // 0000001001100
  30165. [13, 832], // 0000001001101
  30166. [12, 55], [12, 55], // 000000100111x
  30167. [12, 56], [12, 56], // 000000101000x
  30168. [13, 1280], // 0000001010010
  30169. [13, 1344], // 0000001010011
  30170. [13, 1408], // 0000001010100
  30171. [13, 1472], // 0000001010101
  30172. [12, 59], [12, 59], // 000000101011x
  30173. [12, 60], [12, 60], // 000000101100x
  30174. [13, 1536], // 0000001011010
  30175. [13, 1600], // 0000001011011
  30176. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30177. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30178. [13, 1664], // 0000001100100
  30179. [13, 1728], // 0000001100101
  30180. [12, 320], [12, 320], // 000000110011x
  30181. [12, 384], [12, 384], // 000000110100x
  30182. [12, 448], [12, 448], // 000000110101x
  30183. [13, 512], // 0000001101100
  30184. [13, 576], // 0000001101101
  30185. [12, 53], [12, 53], // 000000110111x
  30186. [12, 54], [12, 54], // 000000111000x
  30187. [13, 896], // 0000001110010
  30188. [13, 960], // 0000001110011
  30189. [13, 1024], // 0000001110100
  30190. [13, 1088], // 0000001110101
  30191. [13, 1152], // 0000001110110
  30192. [13, 1216], // 0000001110111
  30193. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30194. [10, 64], [10, 64], [10, 64], [10, 64]
  30195. ];
  30196. var blackTable2 = [
  30197. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30198. [8, 13], [8, 13], [8, 13], [8, 13],
  30199. [8, 13], [8, 13], [8, 13], [8, 13],
  30200. [8, 13], [8, 13], [8, 13], [8, 13],
  30201. [11, 23], [11, 23], // 00000101000x
  30202. [12, 50], // 000001010010
  30203. [12, 51], // 000001010011
  30204. [12, 44], // 000001010100
  30205. [12, 45], // 000001010101
  30206. [12, 46], // 000001010110
  30207. [12, 47], // 000001010111
  30208. [12, 57], // 000001011000
  30209. [12, 58], // 000001011001
  30210. [12, 61], // 000001011010
  30211. [12, 256], // 000001011011
  30212. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30213. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30214. [12, 48], // 000001100100
  30215. [12, 49], // 000001100101
  30216. [12, 62], // 000001100110
  30217. [12, 63], // 000001100111
  30218. [12, 30], // 000001101000
  30219. [12, 31], // 000001101001
  30220. [12, 32], // 000001101010
  30221. [12, 33], // 000001101011
  30222. [12, 40], // 000001101100
  30223. [12, 41], // 000001101101
  30224. [11, 22], [11, 22], // 00000110111x
  30225. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30226. [8, 14], [8, 14], [8, 14], [8, 14],
  30227. [8, 14], [8, 14], [8, 14], [8, 14],
  30228. [8, 14], [8, 14], [8, 14], [8, 14],
  30229. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30230. [7, 10], [7, 10], [7, 10], [7, 10],
  30231. [7, 10], [7, 10], [7, 10], [7, 10],
  30232. [7, 10], [7, 10], [7, 10], [7, 10],
  30233. [7, 10], [7, 10], [7, 10], [7, 10],
  30234. [7, 10], [7, 10], [7, 10], [7, 10],
  30235. [7, 10], [7, 10], [7, 10], [7, 10],
  30236. [7, 10], [7, 10], [7, 10], [7, 10],
  30237. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30238. [7, 11], [7, 11], [7, 11], [7, 11],
  30239. [7, 11], [7, 11], [7, 11], [7, 11],
  30240. [7, 11], [7, 11], [7, 11], [7, 11],
  30241. [7, 11], [7, 11], [7, 11], [7, 11],
  30242. [7, 11], [7, 11], [7, 11], [7, 11],
  30243. [7, 11], [7, 11], [7, 11], [7, 11],
  30244. [7, 11], [7, 11], [7, 11], [7, 11],
  30245. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30246. [9, 15], [9, 15], [9, 15], [9, 15],
  30247. [12, 128], // 000011001000
  30248. [12, 192], // 000011001001
  30249. [12, 26], // 000011001010
  30250. [12, 27], // 000011001011
  30251. [12, 28], // 000011001100
  30252. [12, 29], // 000011001101
  30253. [11, 19], [11, 19], // 00001100111x
  30254. [11, 20], [11, 20], // 00001101000x
  30255. [12, 34], // 000011010010
  30256. [12, 35], // 000011010011
  30257. [12, 36], // 000011010100
  30258. [12, 37], // 000011010101
  30259. [12, 38], // 000011010110
  30260. [12, 39], // 000011010111
  30261. [11, 21], [11, 21], // 00001101100x
  30262. [12, 42], // 000011011010
  30263. [12, 43], // 000011011011
  30264. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30265. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30266. [7, 12], [7, 12], [7, 12], [7, 12],
  30267. [7, 12], [7, 12], [7, 12], [7, 12],
  30268. [7, 12], [7, 12], [7, 12], [7, 12],
  30269. [7, 12], [7, 12], [7, 12], [7, 12],
  30270. [7, 12], [7, 12], [7, 12], [7, 12],
  30271. [7, 12], [7, 12], [7, 12], [7, 12],
  30272. [7, 12], [7, 12], [7, 12], [7, 12]
  30273. ];
  30274. var blackTable3 = [
  30275. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30276. [6, 9], // 000100
  30277. [6, 8], // 000101
  30278. [5, 7], [5, 7], // 00011x
  30279. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30280. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30281. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30282. [3, 1], [3, 1], [3, 1], [3, 1],
  30283. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30284. [3, 4], [3, 4], [3, 4], [3, 4],
  30285. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30286. [2, 3], [2, 3], [2, 3], [2, 3],
  30287. [2, 3], [2, 3], [2, 3], [2, 3],
  30288. [2, 3], [2, 3], [2, 3], [2, 3],
  30289. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30290. [2, 2], [2, 2], [2, 2], [2, 2],
  30291. [2, 2], [2, 2], [2, 2], [2, 2],
  30292. [2, 2], [2, 2], [2, 2], [2, 2]
  30293. ];
  30294. function CCITTFaxStream(str, maybeLength, params) {
  30295. this.str = str;
  30296. this.dict = str.dict;
  30297. params = params || Dict.empty;
  30298. this.encoding = params.get('K') || 0;
  30299. this.eoline = params.get('EndOfLine') || false;
  30300. this.byteAlign = params.get('EncodedByteAlign') || false;
  30301. this.columns = params.get('Columns') || 1728;
  30302. this.rows = params.get('Rows') || 0;
  30303. var eoblock = params.get('EndOfBlock');
  30304. if (eoblock === null || eoblock === undefined) {
  30305. eoblock = true;
  30306. }
  30307. this.eoblock = eoblock;
  30308. this.black = params.get('BlackIs1') || false;
  30309. this.codingLine = new Uint32Array(this.columns + 1);
  30310. this.refLine = new Uint32Array(this.columns + 2);
  30311. this.codingLine[0] = this.columns;
  30312. this.codingPos = 0;
  30313. this.row = 0;
  30314. this.nextLine2D = this.encoding < 0;
  30315. this.inputBits = 0;
  30316. this.inputBuf = 0;
  30317. this.outputBits = 0;
  30318. var code1;
  30319. while ((code1 = this.lookBits(12)) === 0) {
  30320. this.eatBits(1);
  30321. }
  30322. if (code1 === 1) {
  30323. this.eatBits(12);
  30324. }
  30325. if (this.encoding > 0) {
  30326. this.nextLine2D = !this.lookBits(1);
  30327. this.eatBits(1);
  30328. }
  30329. DecodeStream.call(this, maybeLength);
  30330. }
  30331. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  30332. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  30333. while (!this.eof) {
  30334. var c = this.lookChar();
  30335. this.ensureBuffer(this.bufferLength + 1);
  30336. this.buffer[this.bufferLength++] = c;
  30337. }
  30338. };
  30339. CCITTFaxStream.prototype.addPixels =
  30340. function ccittFaxStreamAddPixels(a1, blackPixels) {
  30341. var codingLine = this.codingLine;
  30342. var codingPos = this.codingPos;
  30343. if (a1 > codingLine[codingPos]) {
  30344. if (a1 > this.columns) {
  30345. info('row is wrong length');
  30346. this.err = true;
  30347. a1 = this.columns;
  30348. }
  30349. if ((codingPos & 1) ^ blackPixels) {
  30350. ++codingPos;
  30351. }
  30352. codingLine[codingPos] = a1;
  30353. }
  30354. this.codingPos = codingPos;
  30355. };
  30356. CCITTFaxStream.prototype.addPixelsNeg =
  30357. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  30358. var codingLine = this.codingLine;
  30359. var codingPos = this.codingPos;
  30360. if (a1 > codingLine[codingPos]) {
  30361. if (a1 > this.columns) {
  30362. info('row is wrong length');
  30363. this.err = true;
  30364. a1 = this.columns;
  30365. }
  30366. if ((codingPos & 1) ^ blackPixels) {
  30367. ++codingPos;
  30368. }
  30369. codingLine[codingPos] = a1;
  30370. } else if (a1 < codingLine[codingPos]) {
  30371. if (a1 < 0) {
  30372. info('invalid code');
  30373. this.err = true;
  30374. a1 = 0;
  30375. }
  30376. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  30377. --codingPos;
  30378. }
  30379. codingLine[codingPos] = a1;
  30380. }
  30381. this.codingPos = codingPos;
  30382. };
  30383. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  30384. var refLine = this.refLine;
  30385. var codingLine = this.codingLine;
  30386. var columns = this.columns;
  30387. var refPos, blackPixels, bits, i;
  30388. if (this.outputBits === 0) {
  30389. if (this.eof) {
  30390. return null;
  30391. }
  30392. this.err = false;
  30393. var code1, code2, code3;
  30394. if (this.nextLine2D) {
  30395. for (i = 0; codingLine[i] < columns; ++i) {
  30396. refLine[i] = codingLine[i];
  30397. }
  30398. refLine[i++] = columns;
  30399. refLine[i] = columns;
  30400. codingLine[0] = 0;
  30401. this.codingPos = 0;
  30402. refPos = 0;
  30403. blackPixels = 0;
  30404. while (codingLine[this.codingPos] < columns) {
  30405. code1 = this.getTwoDimCode();
  30406. switch (code1) {
  30407. case twoDimPass:
  30408. this.addPixels(refLine[refPos + 1], blackPixels);
  30409. if (refLine[refPos + 1] < columns) {
  30410. refPos += 2;
  30411. }
  30412. break;
  30413. case twoDimHoriz:
  30414. code1 = code2 = 0;
  30415. if (blackPixels) {
  30416. do {
  30417. code1 += (code3 = this.getBlackCode());
  30418. } while (code3 >= 64);
  30419. do {
  30420. code2 += (code3 = this.getWhiteCode());
  30421. } while (code3 >= 64);
  30422. } else {
  30423. do {
  30424. code1 += (code3 = this.getWhiteCode());
  30425. } while (code3 >= 64);
  30426. do {
  30427. code2 += (code3 = this.getBlackCode());
  30428. } while (code3 >= 64);
  30429. }
  30430. this.addPixels(codingLine[this.codingPos] +
  30431. code1, blackPixels);
  30432. if (codingLine[this.codingPos] < columns) {
  30433. this.addPixels(codingLine[this.codingPos] + code2,
  30434. blackPixels ^ 1);
  30435. }
  30436. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30437. refLine[refPos] < columns) {
  30438. refPos += 2;
  30439. }
  30440. break;
  30441. case twoDimVertR3:
  30442. this.addPixels(refLine[refPos] + 3, blackPixels);
  30443. blackPixels ^= 1;
  30444. if (codingLine[this.codingPos] < columns) {
  30445. ++refPos;
  30446. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30447. refLine[refPos] < columns) {
  30448. refPos += 2;
  30449. }
  30450. }
  30451. break;
  30452. case twoDimVertR2:
  30453. this.addPixels(refLine[refPos] + 2, blackPixels);
  30454. blackPixels ^= 1;
  30455. if (codingLine[this.codingPos] < columns) {
  30456. ++refPos;
  30457. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30458. refLine[refPos] < columns) {
  30459. refPos += 2;
  30460. }
  30461. }
  30462. break;
  30463. case twoDimVertR1:
  30464. this.addPixels(refLine[refPos] + 1, blackPixels);
  30465. blackPixels ^= 1;
  30466. if (codingLine[this.codingPos] < columns) {
  30467. ++refPos;
  30468. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30469. refLine[refPos] < columns) {
  30470. refPos += 2;
  30471. }
  30472. }
  30473. break;
  30474. case twoDimVert0:
  30475. this.addPixels(refLine[refPos], blackPixels);
  30476. blackPixels ^= 1;
  30477. if (codingLine[this.codingPos] < columns) {
  30478. ++refPos;
  30479. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30480. refLine[refPos] < columns) {
  30481. refPos += 2;
  30482. }
  30483. }
  30484. break;
  30485. case twoDimVertL3:
  30486. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  30487. blackPixels ^= 1;
  30488. if (codingLine[this.codingPos] < columns) {
  30489. if (refPos > 0) {
  30490. --refPos;
  30491. } else {
  30492. ++refPos;
  30493. }
  30494. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30495. refLine[refPos] < columns) {
  30496. refPos += 2;
  30497. }
  30498. }
  30499. break;
  30500. case twoDimVertL2:
  30501. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  30502. blackPixels ^= 1;
  30503. if (codingLine[this.codingPos] < columns) {
  30504. if (refPos > 0) {
  30505. --refPos;
  30506. } else {
  30507. ++refPos;
  30508. }
  30509. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30510. refLine[refPos] < columns) {
  30511. refPos += 2;
  30512. }
  30513. }
  30514. break;
  30515. case twoDimVertL1:
  30516. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  30517. blackPixels ^= 1;
  30518. if (codingLine[this.codingPos] < columns) {
  30519. if (refPos > 0) {
  30520. --refPos;
  30521. } else {
  30522. ++refPos;
  30523. }
  30524. while (refLine[refPos] <= codingLine[this.codingPos] &&
  30525. refLine[refPos] < columns) {
  30526. refPos += 2;
  30527. }
  30528. }
  30529. break;
  30530. case EOF:
  30531. this.addPixels(columns, 0);
  30532. this.eof = true;
  30533. break;
  30534. default:
  30535. info('bad 2d code');
  30536. this.addPixels(columns, 0);
  30537. this.err = true;
  30538. }
  30539. }
  30540. } else {
  30541. codingLine[0] = 0;
  30542. this.codingPos = 0;
  30543. blackPixels = 0;
  30544. while (codingLine[this.codingPos] < columns) {
  30545. code1 = 0;
  30546. if (blackPixels) {
  30547. do {
  30548. code1 += (code3 = this.getBlackCode());
  30549. } while (code3 >= 64);
  30550. } else {
  30551. do {
  30552. code1 += (code3 = this.getWhiteCode());
  30553. } while (code3 >= 64);
  30554. }
  30555. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  30556. blackPixels ^= 1;
  30557. }
  30558. }
  30559. var gotEOL = false;
  30560. if (!this.eoblock && this.row === this.rows - 1) {
  30561. this.eof = true;
  30562. } else if (this.eoline || !this.byteAlign) {
  30563. code1 = this.lookBits(12);
  30564. if (this.eoline) {
  30565. while (code1 !== EOF && code1 !== 1) {
  30566. this.eatBits(1);
  30567. code1 = this.lookBits(12);
  30568. }
  30569. } else {
  30570. while (code1 === 0) {
  30571. this.eatBits(1);
  30572. code1 = this.lookBits(12);
  30573. }
  30574. }
  30575. if (code1 === 1) {
  30576. this.eatBits(12);
  30577. gotEOL = true;
  30578. } else if (code1 === EOF) {
  30579. this.eof = true;
  30580. }
  30581. }
  30582. if (this.byteAlign && !gotEOL) {
  30583. this.inputBits &= ~7;
  30584. }
  30585. if (!this.eof && this.encoding > 0) {
  30586. this.nextLine2D = !this.lookBits(1);
  30587. this.eatBits(1);
  30588. }
  30589. if (this.eoblock && gotEOL && this.byteAlign) {
  30590. code1 = this.lookBits(12);
  30591. if (code1 === 1) {
  30592. this.eatBits(12);
  30593. if (this.encoding > 0) {
  30594. this.lookBits(1);
  30595. this.eatBits(1);
  30596. }
  30597. if (this.encoding >= 0) {
  30598. for (i = 0; i < 4; ++i) {
  30599. code1 = this.lookBits(12);
  30600. if (code1 !== 1) {
  30601. info('bad rtc code: ' + code1);
  30602. }
  30603. this.eatBits(12);
  30604. if (this.encoding > 0) {
  30605. this.lookBits(1);
  30606. this.eatBits(1);
  30607. }
  30608. }
  30609. }
  30610. this.eof = true;
  30611. }
  30612. } else if (this.err && this.eoline) {
  30613. while (true) {
  30614. code1 = this.lookBits(13);
  30615. if (code1 === EOF) {
  30616. this.eof = true;
  30617. return null;
  30618. }
  30619. if ((code1 >> 1) === 1) {
  30620. break;
  30621. }
  30622. this.eatBits(1);
  30623. }
  30624. this.eatBits(12);
  30625. if (this.encoding > 0) {
  30626. this.eatBits(1);
  30627. this.nextLine2D = !(code1 & 1);
  30628. }
  30629. }
  30630. if (codingLine[0] > 0) {
  30631. this.outputBits = codingLine[this.codingPos = 0];
  30632. } else {
  30633. this.outputBits = codingLine[this.codingPos = 1];
  30634. }
  30635. this.row++;
  30636. }
  30637. var c;
  30638. if (this.outputBits >= 8) {
  30639. c = (this.codingPos & 1) ? 0 : 0xFF;
  30640. this.outputBits -= 8;
  30641. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  30642. this.codingPos++;
  30643. this.outputBits = (codingLine[this.codingPos] -
  30644. codingLine[this.codingPos - 1]);
  30645. }
  30646. } else {
  30647. bits = 8;
  30648. c = 0;
  30649. do {
  30650. if (this.outputBits > bits) {
  30651. c <<= bits;
  30652. if (!(this.codingPos & 1)) {
  30653. c |= 0xFF >> (8 - bits);
  30654. }
  30655. this.outputBits -= bits;
  30656. bits = 0;
  30657. } else {
  30658. c <<= this.outputBits;
  30659. if (!(this.codingPos & 1)) {
  30660. c |= 0xFF >> (8 - this.outputBits);
  30661. }
  30662. bits -= this.outputBits;
  30663. this.outputBits = 0;
  30664. if (codingLine[this.codingPos] < columns) {
  30665. this.codingPos++;
  30666. this.outputBits = (codingLine[this.codingPos] -
  30667. codingLine[this.codingPos - 1]);
  30668. } else if (bits > 0) {
  30669. c <<= bits;
  30670. bits = 0;
  30671. }
  30672. }
  30673. } while (bits);
  30674. }
  30675. if (this.black) {
  30676. c ^= 0xFF;
  30677. }
  30678. return c;
  30679. };
  30680. // This functions returns the code found from the table.
  30681. // The start and end parameters set the boundaries for searching the table.
  30682. // The limit parameter is optional. Function returns an array with three
  30683. // values. The first array element indicates whether a valid code is being
  30684. // returned. The second array element is the actual code. The third array
  30685. // element indicates whether EOF was reached.
  30686. CCITTFaxStream.prototype.findTableCode =
  30687. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  30688. var limitValue = limit || 0;
  30689. for (var i = start; i <= end; ++i) {
  30690. var code = this.lookBits(i);
  30691. if (code === EOF) {
  30692. return [true, 1, false];
  30693. }
  30694. if (i < end) {
  30695. code <<= end - i;
  30696. }
  30697. if (!limitValue || code >= limitValue) {
  30698. var p = table[code - limitValue];
  30699. if (p[0] === i) {
  30700. this.eatBits(i);
  30701. return [true, p[1], true];
  30702. }
  30703. }
  30704. }
  30705. return [false, 0, false];
  30706. };
  30707. CCITTFaxStream.prototype.getTwoDimCode =
  30708. function ccittFaxStreamGetTwoDimCode() {
  30709. var code = 0;
  30710. var p;
  30711. if (this.eoblock) {
  30712. code = this.lookBits(7);
  30713. p = twoDimTable[code];
  30714. if (p && p[0] > 0) {
  30715. this.eatBits(p[0]);
  30716. return p[1];
  30717. }
  30718. } else {
  30719. var result = this.findTableCode(1, 7, twoDimTable);
  30720. if (result[0] && result[2]) {
  30721. return result[1];
  30722. }
  30723. }
  30724. info('Bad two dim code');
  30725. return EOF;
  30726. };
  30727. CCITTFaxStream.prototype.getWhiteCode =
  30728. function ccittFaxStreamGetWhiteCode() {
  30729. var code = 0;
  30730. var p;
  30731. if (this.eoblock) {
  30732. code = this.lookBits(12);
  30733. if (code === EOF) {
  30734. return 1;
  30735. }
  30736. if ((code >> 5) === 0) {
  30737. p = whiteTable1[code];
  30738. } else {
  30739. p = whiteTable2[code >> 3];
  30740. }
  30741. if (p[0] > 0) {
  30742. this.eatBits(p[0]);
  30743. return p[1];
  30744. }
  30745. } else {
  30746. var result = this.findTableCode(1, 9, whiteTable2);
  30747. if (result[0]) {
  30748. return result[1];
  30749. }
  30750. result = this.findTableCode(11, 12, whiteTable1);
  30751. if (result[0]) {
  30752. return result[1];
  30753. }
  30754. }
  30755. info('bad white code');
  30756. this.eatBits(1);
  30757. return 1;
  30758. };
  30759. CCITTFaxStream.prototype.getBlackCode =
  30760. function ccittFaxStreamGetBlackCode() {
  30761. var code, p;
  30762. if (this.eoblock) {
  30763. code = this.lookBits(13);
  30764. if (code === EOF) {
  30765. return 1;
  30766. }
  30767. if ((code >> 7) === 0) {
  30768. p = blackTable1[code];
  30769. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  30770. p = blackTable2[(code >> 1) - 64];
  30771. } else {
  30772. p = blackTable3[code >> 7];
  30773. }
  30774. if (p[0] > 0) {
  30775. this.eatBits(p[0]);
  30776. return p[1];
  30777. }
  30778. } else {
  30779. var result = this.findTableCode(2, 6, blackTable3);
  30780. if (result[0]) {
  30781. return result[1];
  30782. }
  30783. result = this.findTableCode(7, 12, blackTable2, 64);
  30784. if (result[0]) {
  30785. return result[1];
  30786. }
  30787. result = this.findTableCode(10, 13, blackTable1);
  30788. if (result[0]) {
  30789. return result[1];
  30790. }
  30791. }
  30792. info('bad black code');
  30793. this.eatBits(1);
  30794. return 1;
  30795. };
  30796. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  30797. var c;
  30798. while (this.inputBits < n) {
  30799. if ((c = this.str.getByte()) === -1) {
  30800. if (this.inputBits === 0) {
  30801. return EOF;
  30802. }
  30803. return ((this.inputBuf << (n - this.inputBits)) &
  30804. (0xFFFF >> (16 - n)));
  30805. }
  30806. this.inputBuf = (this.inputBuf << 8) + c;
  30807. this.inputBits += 8;
  30808. }
  30809. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  30810. };
  30811. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  30812. if ((this.inputBits -= n) < 0) {
  30813. this.inputBits = 0;
  30814. }
  30815. };
  30816. return CCITTFaxStream;
  30817. })();
  30818. var LZWStream = (function LZWStreamClosure() {
  30819. function LZWStream(str, maybeLength, earlyChange) {
  30820. this.str = str;
  30821. this.dict = str.dict;
  30822. this.cachedData = 0;
  30823. this.bitsCached = 0;
  30824. var maxLzwDictionarySize = 4096;
  30825. var lzwState = {
  30826. earlyChange: earlyChange,
  30827. codeLength: 9,
  30828. nextCode: 258,
  30829. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  30830. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  30831. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  30832. currentSequence: new Uint8Array(maxLzwDictionarySize),
  30833. currentSequenceLength: 0
  30834. };
  30835. for (var i = 0; i < 256; ++i) {
  30836. lzwState.dictionaryValues[i] = i;
  30837. lzwState.dictionaryLengths[i] = 1;
  30838. }
  30839. this.lzwState = lzwState;
  30840. DecodeStream.call(this, maybeLength);
  30841. }
  30842. LZWStream.prototype = Object.create(DecodeStream.prototype);
  30843. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  30844. var bitsCached = this.bitsCached;
  30845. var cachedData = this.cachedData;
  30846. while (bitsCached < n) {
  30847. var c = this.str.getByte();
  30848. if (c === -1) {
  30849. this.eof = true;
  30850. return null;
  30851. }
  30852. cachedData = (cachedData << 8) | c;
  30853. bitsCached += 8;
  30854. }
  30855. this.bitsCached = (bitsCached -= n);
  30856. this.cachedData = cachedData;
  30857. this.lastCode = null;
  30858. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  30859. };
  30860. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30861. var blockSize = 512;
  30862. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30863. var i, j, q;
  30864. var lzwState = this.lzwState;
  30865. if (!lzwState) {
  30866. return; // eof was found
  30867. }
  30868. var earlyChange = lzwState.earlyChange;
  30869. var nextCode = lzwState.nextCode;
  30870. var dictionaryValues = lzwState.dictionaryValues;
  30871. var dictionaryLengths = lzwState.dictionaryLengths;
  30872. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30873. var codeLength = lzwState.codeLength;
  30874. var prevCode = lzwState.prevCode;
  30875. var currentSequence = lzwState.currentSequence;
  30876. var currentSequenceLength = lzwState.currentSequenceLength;
  30877. var decodedLength = 0;
  30878. var currentBufferLength = this.bufferLength;
  30879. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30880. for (i = 0; i < blockSize; i++) {
  30881. var code = this.readBits(codeLength);
  30882. var hasPrev = currentSequenceLength > 0;
  30883. if (code < 256) {
  30884. currentSequence[0] = code;
  30885. currentSequenceLength = 1;
  30886. } else if (code >= 258) {
  30887. if (code < nextCode) {
  30888. currentSequenceLength = dictionaryLengths[code];
  30889. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30890. currentSequence[j] = dictionaryValues[q];
  30891. q = dictionaryPrevCodes[q];
  30892. }
  30893. } else {
  30894. currentSequence[currentSequenceLength++] = currentSequence[0];
  30895. }
  30896. } else if (code === 256) {
  30897. codeLength = 9;
  30898. nextCode = 258;
  30899. currentSequenceLength = 0;
  30900. continue;
  30901. } else {
  30902. this.eof = true;
  30903. delete this.lzwState;
  30904. break;
  30905. }
  30906. if (hasPrev) {
  30907. dictionaryPrevCodes[nextCode] = prevCode;
  30908. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30909. dictionaryValues[nextCode] = currentSequence[0];
  30910. nextCode++;
  30911. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  30912. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  30913. 0.6931471805599453 + 1, 12) | 0;
  30914. }
  30915. prevCode = code;
  30916. decodedLength += currentSequenceLength;
  30917. if (estimatedDecodedSize < decodedLength) {
  30918. do {
  30919. estimatedDecodedSize += decodedSizeDelta;
  30920. } while (estimatedDecodedSize < decodedLength);
  30921. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30922. }
  30923. for (j = 0; j < currentSequenceLength; j++) {
  30924. buffer[currentBufferLength++] = currentSequence[j];
  30925. }
  30926. }
  30927. lzwState.nextCode = nextCode;
  30928. lzwState.codeLength = codeLength;
  30929. lzwState.prevCode = prevCode;
  30930. lzwState.currentSequenceLength = currentSequenceLength;
  30931. this.bufferLength = currentBufferLength;
  30932. };
  30933. return LZWStream;
  30934. })();
  30935. var NullStream = (function NullStreamClosure() {
  30936. function NullStream() {
  30937. Stream.call(this, new Uint8Array(0));
  30938. }
  30939. NullStream.prototype = Stream.prototype;
  30940. return NullStream;
  30941. })();
  30942. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  30943. setup: function wphSetup(handler) {
  30944. var pdfManager;
  30945. function loadDocument(recoveryMode) {
  30946. var loadDocumentCapability = createPromiseCapability();
  30947. var parseSuccess = function parseSuccess() {
  30948. var numPagesPromise = pdfManager.ensureDoc('numPages');
  30949. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  30950. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  30951. Promise.all([numPagesPromise, fingerprintPromise,
  30952. encryptedPromise]).then(function onDocReady(results) {
  30953. var doc = {
  30954. numPages: results[0],
  30955. fingerprint: results[1],
  30956. encrypted: !!results[2],
  30957. };
  30958. loadDocumentCapability.resolve(doc);
  30959. },
  30960. parseFailure);
  30961. };
  30962. var parseFailure = function parseFailure(e) {
  30963. loadDocumentCapability.reject(e);
  30964. };
  30965. pdfManager.ensureDoc('checkHeader', []).then(function() {
  30966. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  30967. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  30968. parseSuccess, parseFailure);
  30969. }, parseFailure);
  30970. }, parseFailure);
  30971. return loadDocumentCapability.promise;
  30972. }
  30973. function getPdfManager(data) {
  30974. var pdfManagerCapability = createPromiseCapability();
  30975. var source = data.source;
  30976. var disableRange = data.disableRange;
  30977. if (source.data) {
  30978. try {
  30979. pdfManager = new LocalPdfManager(source.data, source.password);
  30980. pdfManagerCapability.resolve();
  30981. } catch (ex) {
  30982. pdfManagerCapability.reject(ex);
  30983. }
  30984. return pdfManagerCapability.promise;
  30985. } else if (source.chunkedViewerLoading) {
  30986. try {
  30987. pdfManager = new NetworkPdfManager(source, handler);
  30988. pdfManagerCapability.resolve();
  30989. } catch (ex) {
  30990. pdfManagerCapability.reject(ex);
  30991. }
  30992. return pdfManagerCapability.promise;
  30993. }
  30994. var networkManager = new NetworkManager(source.url, {
  30995. httpHeaders: source.httpHeaders,
  30996. withCredentials: source.withCredentials
  30997. });
  30998. var fullRequestXhrId = networkManager.requestFull({
  30999. onHeadersReceived: function onHeadersReceived() {
  31000. if (disableRange) {
  31001. return;
  31002. }
  31003. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31004. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31005. return;
  31006. }
  31007. var contentEncoding =
  31008. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31009. if (contentEncoding !== 'identity') {
  31010. return;
  31011. }
  31012. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31013. length = parseInt(length, 10);
  31014. if (!isInt(length)) {
  31015. return;
  31016. }
  31017. source.length = length;
  31018. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31019. // The file size is smaller than the size of two chunks, so it does
  31020. // not make any sense to abort the request and retry with a range
  31021. // request.
  31022. return;
  31023. }
  31024. // NOTE: by cancelling the full request, and then issuing range
  31025. // requests, there will be an issue for sites where you can only
  31026. // request the pdf once. However, if this is the case, then the
  31027. // server should not be returning that it can support range requests.
  31028. networkManager.abortRequest(fullRequestXhrId);
  31029. try {
  31030. pdfManager = new NetworkPdfManager(source, handler);
  31031. pdfManagerCapability.resolve(pdfManager);
  31032. } catch (ex) {
  31033. pdfManagerCapability.reject(ex);
  31034. }
  31035. },
  31036. onDone: function onDone(args) {
  31037. // the data is array, instantiating directly from it
  31038. try {
  31039. pdfManager = new LocalPdfManager(args.chunk, source.password);
  31040. pdfManagerCapability.resolve();
  31041. } catch (ex) {
  31042. pdfManagerCapability.reject(ex);
  31043. }
  31044. },
  31045. onError: function onError(status) {
  31046. if (status === 404) {
  31047. var exception = new MissingPDFException('Missing PDF "' +
  31048. source.url + '".');
  31049. handler.send('MissingPDF', { exception: exception });
  31050. } else {
  31051. handler.send('DocError', 'Unexpected server response (' +
  31052. status + ') while retrieving PDF "' +
  31053. source.url + '".');
  31054. }
  31055. },
  31056. onProgress: function onProgress(evt) {
  31057. handler.send('DocProgress', {
  31058. loaded: evt.loaded,
  31059. total: evt.lengthComputable ? evt.total : source.length
  31060. });
  31061. }
  31062. });
  31063. return pdfManagerCapability.promise;
  31064. }
  31065. handler.on('test', function wphSetupTest(data) {
  31066. // check if Uint8Array can be sent to worker
  31067. if (!(data instanceof Uint8Array)) {
  31068. handler.send('test', false);
  31069. return;
  31070. }
  31071. // making sure postMessage transfers are working
  31072. var supportTransfers = data[0] === 255;
  31073. handler.postMessageTransfers = supportTransfers;
  31074. // check if the response property is supported by xhr
  31075. var xhr = new XMLHttpRequest();
  31076. var responseExists = 'response' in xhr;
  31077. // check if the property is actually implemented
  31078. try {
  31079. var dummy = xhr.responseType;
  31080. } catch (e) {
  31081. responseExists = false;
  31082. }
  31083. if (!responseExists) {
  31084. handler.send('test', false);
  31085. return;
  31086. }
  31087. handler.send('test', {
  31088. supportTypedArray: true,
  31089. supportTransfers: supportTransfers
  31090. });
  31091. });
  31092. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31093. var onSuccess = function(doc) {
  31094. handler.send('GetDoc', { pdfInfo: doc });
  31095. };
  31096. var onFailure = function(e) {
  31097. if (e instanceof PasswordException) {
  31098. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31099. handler.send('NeedPassword', {
  31100. exception: e
  31101. });
  31102. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31103. handler.send('IncorrectPassword', {
  31104. exception: e
  31105. });
  31106. }
  31107. } else if (e instanceof InvalidPDFException) {
  31108. handler.send('InvalidPDF', {
  31109. exception: e
  31110. });
  31111. } else if (e instanceof MissingPDFException) {
  31112. handler.send('MissingPDF', {
  31113. exception: e
  31114. });
  31115. } else {
  31116. handler.send('UnknownError', {
  31117. exception: new UnknownErrorException(e.message, e.toString())
  31118. });
  31119. }
  31120. };
  31121. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31122. -1 : data.maxImageSize;
  31123. PDFJS.disableFontFace = data.disableFontFace;
  31124. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31125. PDFJS.verbosity = data.verbosity;
  31126. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31127. null : data.cMapUrl;
  31128. PDFJS.cMapPacked = data.cMapPacked === true;
  31129. getPdfManager(data).then(function () {
  31130. pdfManager.onLoadedStream().then(function(stream) {
  31131. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31132. });
  31133. }).then(function pdfManagerReady() {
  31134. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31135. // Try again with recoveryMode == true
  31136. if (!(ex instanceof XRefParseException)) {
  31137. if (ex instanceof PasswordException) {
  31138. // after password exception prepare to receive a new password
  31139. // to repeat loading
  31140. pdfManager.passwordChanged().then(pdfManagerReady);
  31141. }
  31142. onFailure(ex);
  31143. return;
  31144. }
  31145. pdfManager.requestLoadedStream();
  31146. pdfManager.onLoadedStream().then(function() {
  31147. loadDocument(true).then(onSuccess, onFailure);
  31148. });
  31149. }, onFailure);
  31150. }, onFailure);
  31151. });
  31152. handler.on('GetPage', function wphSetupGetPage(data) {
  31153. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31154. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31155. var refPromise = pdfManager.ensure(page, 'ref');
  31156. var viewPromise = pdfManager.ensure(page, 'view');
  31157. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31158. function(results) {
  31159. return {
  31160. rotate: results[0],
  31161. ref: results[1],
  31162. view: results[2]
  31163. };
  31164. });
  31165. });
  31166. });
  31167. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31168. var ref = new Ref(data.ref.num, data.ref.gen);
  31169. var catalog = pdfManager.pdfDocument.catalog;
  31170. return catalog.getPageIndex(ref);
  31171. });
  31172. handler.on('GetDestinations',
  31173. function wphSetupGetDestinations(data) {
  31174. return pdfManager.ensureCatalog('destinations');
  31175. }
  31176. );
  31177. handler.on('GetAttachments',
  31178. function wphSetupGetAttachments(data) {
  31179. return pdfManager.ensureCatalog('attachments');
  31180. }
  31181. );
  31182. handler.on('GetJavaScript',
  31183. function wphSetupGetJavaScript(data) {
  31184. return pdfManager.ensureCatalog('javaScript');
  31185. }
  31186. );
  31187. handler.on('GetOutline',
  31188. function wphSetupGetOutline(data) {
  31189. return pdfManager.ensureCatalog('documentOutline');
  31190. }
  31191. );
  31192. handler.on('GetMetadata',
  31193. function wphSetupGetMetadata(data) {
  31194. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31195. pdfManager.ensureCatalog('metadata')]);
  31196. }
  31197. );
  31198. handler.on('GetData', function wphSetupGetData(data) {
  31199. pdfManager.requestLoadedStream();
  31200. return pdfManager.onLoadedStream().then(function(stream) {
  31201. return stream.bytes;
  31202. });
  31203. });
  31204. handler.on('GetStats',
  31205. function wphSetupGetStats(data) {
  31206. return pdfManager.pdfDocument.xref.stats;
  31207. }
  31208. );
  31209. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31210. pdfManager.updatePassword(data);
  31211. });
  31212. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31213. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31214. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31215. });
  31216. });
  31217. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31218. pdfManager.getPage(data.pageIndex).then(function(page) {
  31219. var pageNum = data.pageIndex + 1;
  31220. var start = Date.now();
  31221. // Pre compile the pdf page and fetch the fonts/images.
  31222. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31223. info('page=' + pageNum + ' - getOperatorList: time=' +
  31224. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31225. }, function(e) {
  31226. var minimumStackMessage =
  31227. 'worker.js: while trying to getPage() and getOperatorList()';
  31228. var wrappedException;
  31229. // Turn the error into an obj that can be serialized
  31230. if (typeof e === 'string') {
  31231. wrappedException = {
  31232. message: e,
  31233. stack: minimumStackMessage
  31234. };
  31235. } else if (typeof e === 'object') {
  31236. wrappedException = {
  31237. message: e.message || e.toString(),
  31238. stack: e.stack || minimumStackMessage
  31239. };
  31240. } else {
  31241. wrappedException = {
  31242. message: 'Unknown exception type: ' + (typeof e),
  31243. stack: minimumStackMessage
  31244. };
  31245. }
  31246. handler.send('PageError', {
  31247. pageNum: pageNum,
  31248. error: wrappedException,
  31249. intent: data.intent
  31250. });
  31251. });
  31252. });
  31253. }, this);
  31254. handler.on('GetTextContent', function wphExtractText(data) {
  31255. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31256. var pageNum = data.pageIndex + 1;
  31257. var start = Date.now();
  31258. return page.extractTextContent().then(function(textContent) {
  31259. info('text indexing: page=' + pageNum + ' - time=' +
  31260. (Date.now() - start) + 'ms');
  31261. return textContent;
  31262. });
  31263. });
  31264. });
  31265. handler.on('Cleanup', function wphCleanup(data) {
  31266. return pdfManager.cleanup();
  31267. });
  31268. handler.on('Terminate', function wphTerminate(data) {
  31269. pdfManager.terminate();
  31270. });
  31271. }
  31272. };
  31273. var consoleTimer = {};
  31274. var workerConsole = {
  31275. log: function log() {
  31276. var args = Array.prototype.slice.call(arguments);
  31277. globalScope.postMessage({
  31278. action: 'console_log',
  31279. data: args
  31280. });
  31281. },
  31282. error: function error() {
  31283. var args = Array.prototype.slice.call(arguments);
  31284. globalScope.postMessage({
  31285. action: 'console_error',
  31286. data: args
  31287. });
  31288. throw 'pdf.js execution error';
  31289. },
  31290. time: function time(name) {
  31291. consoleTimer[name] = Date.now();
  31292. },
  31293. timeEnd: function timeEnd(name) {
  31294. var time = consoleTimer[name];
  31295. if (!time) {
  31296. error('Unknown timer name ' + name);
  31297. }
  31298. this.log('Timer:', name, Date.now() - time);
  31299. }
  31300. };
  31301. // Worker thread?
  31302. if (typeof window === 'undefined') {
  31303. if (!('console' in globalScope)) {
  31304. globalScope.console = workerConsole;
  31305. }
  31306. // Listen for unsupported features so we can pass them on to the main thread.
  31307. PDFJS.UnsupportedManager.listen(function (msg) {
  31308. globalScope.postMessage({
  31309. action: '_unsupported_feature',
  31310. data: msg
  31311. });
  31312. });
  31313. var handler = new MessageHandler('worker_processor', this);
  31314. WorkerMessageHandler.setup(handler);
  31315. }
  31316. /* This class implements the QM Coder decoding as defined in
  31317. * JPEG 2000 Part I Final Committee Draft Version 1.0
  31318. * Annex C.3 Arithmetic decoding procedure
  31319. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  31320. *
  31321. * The arithmetic decoder is used in conjunction with context models to decode
  31322. * JPEG2000 and JBIG2 streams.
  31323. */
  31324. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  31325. // Table C-2
  31326. var QeTable = [
  31327. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  31328. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  31329. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  31330. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  31331. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  31332. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  31333. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  31334. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  31335. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  31336. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  31337. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  31338. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  31339. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  31340. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  31341. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  31342. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  31343. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  31344. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  31345. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  31346. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  31347. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  31348. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  31349. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  31350. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  31351. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  31352. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  31353. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  31354. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  31355. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  31356. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  31357. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  31358. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  31359. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  31360. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  31361. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  31362. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  31363. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  31364. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  31365. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  31366. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  31367. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  31368. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  31369. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  31370. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  31371. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  31372. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  31373. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  31374. ];
  31375. // C.3.5 Initialisation of the decoder (INITDEC)
  31376. function ArithmeticDecoder(data, start, end) {
  31377. this.data = data;
  31378. this.bp = start;
  31379. this.dataEnd = end;
  31380. this.chigh = data[start];
  31381. this.clow = 0;
  31382. this.byteIn();
  31383. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  31384. this.clow = (this.clow << 7) & 0xFFFF;
  31385. this.ct -= 7;
  31386. this.a = 0x8000;
  31387. }
  31388. ArithmeticDecoder.prototype = {
  31389. // C.3.4 Compressed data input (BYTEIN)
  31390. byteIn: function ArithmeticDecoder_byteIn() {
  31391. var data = this.data;
  31392. var bp = this.bp;
  31393. if (data[bp] === 0xFF) {
  31394. var b1 = data[bp + 1];
  31395. if (b1 > 0x8F) {
  31396. this.clow += 0xFF00;
  31397. this.ct = 8;
  31398. } else {
  31399. bp++;
  31400. this.clow += (data[bp] << 9);
  31401. this.ct = 7;
  31402. this.bp = bp;
  31403. }
  31404. } else {
  31405. bp++;
  31406. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  31407. this.ct = 8;
  31408. this.bp = bp;
  31409. }
  31410. if (this.clow > 0xFFFF) {
  31411. this.chigh += (this.clow >> 16);
  31412. this.clow &= 0xFFFF;
  31413. }
  31414. },
  31415. // C.3.2 Decoding a decision (DECODE)
  31416. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  31417. // contexts are packed into 1 byte:
  31418. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  31419. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  31420. var qeTableIcx = QeTable[cx_index];
  31421. var qeIcx = qeTableIcx.qe;
  31422. var d;
  31423. var a = this.a - qeIcx;
  31424. if (this.chigh < qeIcx) {
  31425. // exchangeLps
  31426. if (a < qeIcx) {
  31427. a = qeIcx;
  31428. d = cx_mps;
  31429. cx_index = qeTableIcx.nmps;
  31430. } else {
  31431. a = qeIcx;
  31432. d = 1 ^ cx_mps;
  31433. if (qeTableIcx.switchFlag === 1) {
  31434. cx_mps = d;
  31435. }
  31436. cx_index = qeTableIcx.nlps;
  31437. }
  31438. } else {
  31439. this.chigh -= qeIcx;
  31440. if ((a & 0x8000) !== 0) {
  31441. this.a = a;
  31442. return cx_mps;
  31443. }
  31444. // exchangeMps
  31445. if (a < qeIcx) {
  31446. d = 1 ^ cx_mps;
  31447. if (qeTableIcx.switchFlag === 1) {
  31448. cx_mps = d;
  31449. }
  31450. cx_index = qeTableIcx.nlps;
  31451. } else {
  31452. d = cx_mps;
  31453. cx_index = qeTableIcx.nmps;
  31454. }
  31455. }
  31456. // C.3.3 renormD;
  31457. do {
  31458. if (this.ct === 0) {
  31459. this.byteIn();
  31460. }
  31461. a <<= 1;
  31462. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  31463. this.clow = (this.clow << 1) & 0xFFFF;
  31464. this.ct--;
  31465. } while ((a & 0x8000) === 0);
  31466. this.a = a;
  31467. contexts[pos] = cx_index << 1 | cx_mps;
  31468. return d;
  31469. }
  31470. };
  31471. return ArithmeticDecoder;
  31472. })();
  31473. var JpegImage = (function jpegImage() {
  31474. var dctZigZag = new Uint8Array([
  31475. 0,
  31476. 1, 8,
  31477. 16, 9, 2,
  31478. 3, 10, 17, 24,
  31479. 32, 25, 18, 11, 4,
  31480. 5, 12, 19, 26, 33, 40,
  31481. 48, 41, 34, 27, 20, 13, 6,
  31482. 7, 14, 21, 28, 35, 42, 49, 56,
  31483. 57, 50, 43, 36, 29, 22, 15,
  31484. 23, 30, 37, 44, 51, 58,
  31485. 59, 52, 45, 38, 31,
  31486. 39, 46, 53, 60,
  31487. 61, 54, 47,
  31488. 55, 62,
  31489. 63
  31490. ]);
  31491. var dctCos1 = 4017; // cos(pi/16)
  31492. var dctSin1 = 799; // sin(pi/16)
  31493. var dctCos3 = 3406; // cos(3*pi/16)
  31494. var dctSin3 = 2276; // sin(3*pi/16)
  31495. var dctCos6 = 1567; // cos(6*pi/16)
  31496. var dctSin6 = 3784; // sin(6*pi/16)
  31497. var dctSqrt2 = 5793; // sqrt(2)
  31498. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  31499. function constructor() {
  31500. }
  31501. function buildHuffmanTable(codeLengths, values) {
  31502. var k = 0, code = [], i, j, length = 16;
  31503. while (length > 0 && !codeLengths[length - 1]) {
  31504. length--;
  31505. }
  31506. code.push({children: [], index: 0});
  31507. var p = code[0], q;
  31508. for (i = 0; i < length; i++) {
  31509. for (j = 0; j < codeLengths[i]; j++) {
  31510. p = code.pop();
  31511. p.children[p.index] = values[k];
  31512. while (p.index > 0) {
  31513. p = code.pop();
  31514. }
  31515. p.index++;
  31516. code.push(p);
  31517. while (code.length <= i) {
  31518. code.push(q = {children: [], index: 0});
  31519. p.children[p.index] = q.children;
  31520. p = q;
  31521. }
  31522. k++;
  31523. }
  31524. if (i + 1 < length) {
  31525. // p here points to last code
  31526. code.push(q = {children: [], index: 0});
  31527. p.children[p.index] = q.children;
  31528. p = q;
  31529. }
  31530. }
  31531. return code[0].children;
  31532. }
  31533. function getBlockBufferOffset(component, row, col) {
  31534. return 64 * ((component.blocksPerLine + 1) * row + col);
  31535. }
  31536. function decodeScan(data, offset, frame, components, resetInterval,
  31537. spectralStart, spectralEnd, successivePrev, successive) {
  31538. var precision = frame.precision;
  31539. var samplesPerLine = frame.samplesPerLine;
  31540. var scanLines = frame.scanLines;
  31541. var mcusPerLine = frame.mcusPerLine;
  31542. var progressive = frame.progressive;
  31543. var maxH = frame.maxH, maxV = frame.maxV;
  31544. var startOffset = offset, bitsData = 0, bitsCount = 0;
  31545. function readBit() {
  31546. if (bitsCount > 0) {
  31547. bitsCount--;
  31548. return (bitsData >> bitsCount) & 1;
  31549. }
  31550. bitsData = data[offset++];
  31551. if (bitsData === 0xFF) {
  31552. var nextByte = data[offset++];
  31553. if (nextByte) {
  31554. throw 'unexpected marker: ' +
  31555. ((bitsData << 8) | nextByte).toString(16);
  31556. }
  31557. // unstuff 0
  31558. }
  31559. bitsCount = 7;
  31560. return bitsData >>> 7;
  31561. }
  31562. function decodeHuffman(tree) {
  31563. var node = tree;
  31564. var bit;
  31565. while ((bit = readBit()) !== null) {
  31566. node = node[bit];
  31567. if (typeof node === 'number') {
  31568. return node;
  31569. }
  31570. if (typeof node !== 'object') {
  31571. throw 'invalid huffman sequence';
  31572. }
  31573. }
  31574. return null;
  31575. }
  31576. function receive(length) {
  31577. var n = 0;
  31578. while (length > 0) {
  31579. var bit = readBit();
  31580. if (bit === null) {
  31581. return;
  31582. }
  31583. n = (n << 1) | bit;
  31584. length--;
  31585. }
  31586. return n;
  31587. }
  31588. function receiveAndExtend(length) {
  31589. if (length === 1) {
  31590. return readBit() === 1 ? 1 : -1;
  31591. }
  31592. var n = receive(length);
  31593. if (n >= 1 << (length - 1)) {
  31594. return n;
  31595. }
  31596. return n + (-1 << length) + 1;
  31597. }
  31598. function decodeBaseline(component, offset) {
  31599. var t = decodeHuffman(component.huffmanTableDC);
  31600. var diff = t === 0 ? 0 : receiveAndExtend(t);
  31601. component.blockData[offset] = (component.pred += diff);
  31602. var k = 1;
  31603. while (k < 64) {
  31604. var rs = decodeHuffman(component.huffmanTableAC);
  31605. var s = rs & 15, r = rs >> 4;
  31606. if (s === 0) {
  31607. if (r < 15) {
  31608. break;
  31609. }
  31610. k += 16;
  31611. continue;
  31612. }
  31613. k += r;
  31614. var z = dctZigZag[k];
  31615. component.blockData[offset + z] = receiveAndExtend(s);
  31616. k++;
  31617. }
  31618. }
  31619. function decodeDCFirst(component, offset) {
  31620. var t = decodeHuffman(component.huffmanTableDC);
  31621. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  31622. component.blockData[offset] = (component.pred += diff);
  31623. }
  31624. function decodeDCSuccessive(component, offset) {
  31625. component.blockData[offset] |= readBit() << successive;
  31626. }
  31627. var eobrun = 0;
  31628. function decodeACFirst(component, offset) {
  31629. if (eobrun > 0) {
  31630. eobrun--;
  31631. return;
  31632. }
  31633. var k = spectralStart, e = spectralEnd;
  31634. while (k <= e) {
  31635. var rs = decodeHuffman(component.huffmanTableAC);
  31636. var s = rs & 15, r = rs >> 4;
  31637. if (s === 0) {
  31638. if (r < 15) {
  31639. eobrun = receive(r) + (1 << r) - 1;
  31640. break;
  31641. }
  31642. k += 16;
  31643. continue;
  31644. }
  31645. k += r;
  31646. var z = dctZigZag[k];
  31647. component.blockData[offset + z] =
  31648. receiveAndExtend(s) * (1 << successive);
  31649. k++;
  31650. }
  31651. }
  31652. var successiveACState = 0, successiveACNextValue;
  31653. function decodeACSuccessive(component, offset) {
  31654. var k = spectralStart;
  31655. var e = spectralEnd;
  31656. var r = 0;
  31657. var s;
  31658. var rs;
  31659. while (k <= e) {
  31660. var z = dctZigZag[k];
  31661. switch (successiveACState) {
  31662. case 0: // initial state
  31663. rs = decodeHuffman(component.huffmanTableAC);
  31664. s = rs & 15;
  31665. r = rs >> 4;
  31666. if (s === 0) {
  31667. if (r < 15) {
  31668. eobrun = receive(r) + (1 << r);
  31669. successiveACState = 4;
  31670. } else {
  31671. r = 16;
  31672. successiveACState = 1;
  31673. }
  31674. } else {
  31675. if (s !== 1) {
  31676. throw 'invalid ACn encoding';
  31677. }
  31678. successiveACNextValue = receiveAndExtend(s);
  31679. successiveACState = r ? 2 : 3;
  31680. }
  31681. continue;
  31682. case 1: // skipping r zero items
  31683. case 2:
  31684. if (component.blockData[offset + z]) {
  31685. component.blockData[offset + z] += (readBit() << successive);
  31686. } else {
  31687. r--;
  31688. if (r === 0) {
  31689. successiveACState = successiveACState === 2 ? 3 : 0;
  31690. }
  31691. }
  31692. break;
  31693. case 3: // set value for a zero item
  31694. if (component.blockData[offset + z]) {
  31695. component.blockData[offset + z] += (readBit() << successive);
  31696. } else {
  31697. component.blockData[offset + z] =
  31698. successiveACNextValue << successive;
  31699. successiveACState = 0;
  31700. }
  31701. break;
  31702. case 4: // eob
  31703. if (component.blockData[offset + z]) {
  31704. component.blockData[offset + z] += (readBit() << successive);
  31705. }
  31706. break;
  31707. }
  31708. k++;
  31709. }
  31710. if (successiveACState === 4) {
  31711. eobrun--;
  31712. if (eobrun === 0) {
  31713. successiveACState = 0;
  31714. }
  31715. }
  31716. }
  31717. function decodeMcu(component, decode, mcu, row, col) {
  31718. var mcuRow = (mcu / mcusPerLine) | 0;
  31719. var mcuCol = mcu % mcusPerLine;
  31720. var blockRow = mcuRow * component.v + row;
  31721. var blockCol = mcuCol * component.h + col;
  31722. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31723. decode(component, offset);
  31724. }
  31725. function decodeBlock(component, decode, mcu) {
  31726. var blockRow = (mcu / component.blocksPerLine) | 0;
  31727. var blockCol = mcu % component.blocksPerLine;
  31728. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31729. decode(component, offset);
  31730. }
  31731. var componentsLength = components.length;
  31732. var component, i, j, k, n;
  31733. var decodeFn;
  31734. if (progressive) {
  31735. if (spectralStart === 0) {
  31736. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  31737. } else {
  31738. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  31739. }
  31740. } else {
  31741. decodeFn = decodeBaseline;
  31742. }
  31743. var mcu = 0, marker;
  31744. var mcuExpected;
  31745. if (componentsLength === 1) {
  31746. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  31747. } else {
  31748. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  31749. }
  31750. if (!resetInterval) {
  31751. resetInterval = mcuExpected;
  31752. }
  31753. var h, v;
  31754. while (mcu < mcuExpected) {
  31755. // reset interval stuff
  31756. for (i = 0; i < componentsLength; i++) {
  31757. components[i].pred = 0;
  31758. }
  31759. eobrun = 0;
  31760. if (componentsLength === 1) {
  31761. component = components[0];
  31762. for (n = 0; n < resetInterval; n++) {
  31763. decodeBlock(component, decodeFn, mcu);
  31764. mcu++;
  31765. }
  31766. } else {
  31767. for (n = 0; n < resetInterval; n++) {
  31768. for (i = 0; i < componentsLength; i++) {
  31769. component = components[i];
  31770. h = component.h;
  31771. v = component.v;
  31772. for (j = 0; j < v; j++) {
  31773. for (k = 0; k < h; k++) {
  31774. decodeMcu(component, decodeFn, mcu, j, k);
  31775. }
  31776. }
  31777. }
  31778. mcu++;
  31779. }
  31780. }
  31781. // find marker
  31782. bitsCount = 0;
  31783. marker = (data[offset] << 8) | data[offset + 1];
  31784. if (marker <= 0xFF00) {
  31785. throw 'marker was not found';
  31786. }
  31787. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  31788. offset += 2;
  31789. } else {
  31790. break;
  31791. }
  31792. }
  31793. return offset - startOffset;
  31794. }
  31795. // A port of poppler's IDCT method which in turn is taken from:
  31796. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  31797. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  31798. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  31799. // 988-991.
  31800. function quantizeAndInverse(component, blockBufferOffset, p) {
  31801. var qt = component.quantizationTable, blockData = component.blockData;
  31802. var v0, v1, v2, v3, v4, v5, v6, v7;
  31803. var p0, p1, p2, p3, p4, p5, p6, p7;
  31804. var t;
  31805. // inverse DCT on rows
  31806. for (var row = 0; row < 64; row += 8) {
  31807. // gather block data
  31808. p0 = blockData[blockBufferOffset + row];
  31809. p1 = blockData[blockBufferOffset + row + 1];
  31810. p2 = blockData[blockBufferOffset + row + 2];
  31811. p3 = blockData[blockBufferOffset + row + 3];
  31812. p4 = blockData[blockBufferOffset + row + 4];
  31813. p5 = blockData[blockBufferOffset + row + 5];
  31814. p6 = blockData[blockBufferOffset + row + 6];
  31815. p7 = blockData[blockBufferOffset + row + 7];
  31816. // dequant p0
  31817. p0 *= qt[row];
  31818. // check for all-zero AC coefficients
  31819. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  31820. t = (dctSqrt2 * p0 + 512) >> 10;
  31821. p[row] = t;
  31822. p[row + 1] = t;
  31823. p[row + 2] = t;
  31824. p[row + 3] = t;
  31825. p[row + 4] = t;
  31826. p[row + 5] = t;
  31827. p[row + 6] = t;
  31828. p[row + 7] = t;
  31829. continue;
  31830. }
  31831. // dequant p1 ... p7
  31832. p1 *= qt[row + 1];
  31833. p2 *= qt[row + 2];
  31834. p3 *= qt[row + 3];
  31835. p4 *= qt[row + 4];
  31836. p5 *= qt[row + 5];
  31837. p6 *= qt[row + 6];
  31838. p7 *= qt[row + 7];
  31839. // stage 4
  31840. v0 = (dctSqrt2 * p0 + 128) >> 8;
  31841. v1 = (dctSqrt2 * p4 + 128) >> 8;
  31842. v2 = p2;
  31843. v3 = p6;
  31844. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  31845. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  31846. v5 = p3 << 4;
  31847. v6 = p5 << 4;
  31848. // stage 3
  31849. v0 = (v0 + v1 + 1) >> 1;
  31850. v1 = v0 - v1;
  31851. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  31852. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  31853. v3 = t;
  31854. v4 = (v4 + v6 + 1) >> 1;
  31855. v6 = v4 - v6;
  31856. v7 = (v7 + v5 + 1) >> 1;
  31857. v5 = v7 - v5;
  31858. // stage 2
  31859. v0 = (v0 + v3 + 1) >> 1;
  31860. v3 = v0 - v3;
  31861. v1 = (v1 + v2 + 1) >> 1;
  31862. v2 = v1 - v2;
  31863. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31864. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31865. v7 = t;
  31866. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31867. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31868. v6 = t;
  31869. // stage 1
  31870. p[row] = v0 + v7;
  31871. p[row + 7] = v0 - v7;
  31872. p[row + 1] = v1 + v6;
  31873. p[row + 6] = v1 - v6;
  31874. p[row + 2] = v2 + v5;
  31875. p[row + 5] = v2 - v5;
  31876. p[row + 3] = v3 + v4;
  31877. p[row + 4] = v3 - v4;
  31878. }
  31879. // inverse DCT on columns
  31880. for (var col = 0; col < 8; ++col) {
  31881. p0 = p[col];
  31882. p1 = p[col + 8];
  31883. p2 = p[col + 16];
  31884. p3 = p[col + 24];
  31885. p4 = p[col + 32];
  31886. p5 = p[col + 40];
  31887. p6 = p[col + 48];
  31888. p7 = p[col + 56];
  31889. // check for all-zero AC coefficients
  31890. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  31891. t = (dctSqrt2 * p0 + 8192) >> 14;
  31892. // convert to 8 bit
  31893. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  31894. blockData[blockBufferOffset + col] = t;
  31895. blockData[blockBufferOffset + col + 8] = t;
  31896. blockData[blockBufferOffset + col + 16] = t;
  31897. blockData[blockBufferOffset + col + 24] = t;
  31898. blockData[blockBufferOffset + col + 32] = t;
  31899. blockData[blockBufferOffset + col + 40] = t;
  31900. blockData[blockBufferOffset + col + 48] = t;
  31901. blockData[blockBufferOffset + col + 56] = t;
  31902. continue;
  31903. }
  31904. // stage 4
  31905. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  31906. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  31907. v2 = p2;
  31908. v3 = p6;
  31909. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  31910. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  31911. v5 = p3;
  31912. v6 = p5;
  31913. // stage 3
  31914. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  31915. // converting to UInt8 range later.
  31916. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  31917. v1 = v0 - v1;
  31918. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  31919. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  31920. v3 = t;
  31921. v4 = (v4 + v6 + 1) >> 1;
  31922. v6 = v4 - v6;
  31923. v7 = (v7 + v5 + 1) >> 1;
  31924. v5 = v7 - v5;
  31925. // stage 2
  31926. v0 = (v0 + v3 + 1) >> 1;
  31927. v3 = v0 - v3;
  31928. v1 = (v1 + v2 + 1) >> 1;
  31929. v2 = v1 - v2;
  31930. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31931. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31932. v7 = t;
  31933. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31934. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31935. v6 = t;
  31936. // stage 1
  31937. p0 = v0 + v7;
  31938. p7 = v0 - v7;
  31939. p1 = v1 + v6;
  31940. p6 = v1 - v6;
  31941. p2 = v2 + v5;
  31942. p5 = v2 - v5;
  31943. p3 = v3 + v4;
  31944. p4 = v3 - v4;
  31945. // convert to 8-bit integers
  31946. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  31947. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  31948. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  31949. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  31950. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  31951. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  31952. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  31953. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  31954. // store block data
  31955. blockData[blockBufferOffset + col] = p0;
  31956. blockData[blockBufferOffset + col + 8] = p1;
  31957. blockData[blockBufferOffset + col + 16] = p2;
  31958. blockData[blockBufferOffset + col + 24] = p3;
  31959. blockData[blockBufferOffset + col + 32] = p4;
  31960. blockData[blockBufferOffset + col + 40] = p5;
  31961. blockData[blockBufferOffset + col + 48] = p6;
  31962. blockData[blockBufferOffset + col + 56] = p7;
  31963. }
  31964. }
  31965. function buildComponentData(frame, component) {
  31966. var blocksPerLine = component.blocksPerLine;
  31967. var blocksPerColumn = component.blocksPerColumn;
  31968. var computationBuffer = new Int16Array(64);
  31969. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  31970. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  31971. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31972. quantizeAndInverse(component, offset, computationBuffer);
  31973. }
  31974. }
  31975. return component.blockData;
  31976. }
  31977. function clamp0to255(a) {
  31978. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  31979. }
  31980. constructor.prototype = {
  31981. parse: function parse(data) {
  31982. function readUint16() {
  31983. var value = (data[offset] << 8) | data[offset + 1];
  31984. offset += 2;
  31985. return value;
  31986. }
  31987. function readDataBlock() {
  31988. var length = readUint16();
  31989. var array = data.subarray(offset, offset + length - 2);
  31990. offset += array.length;
  31991. return array;
  31992. }
  31993. function prepareComponents(frame) {
  31994. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  31995. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  31996. for (var i = 0; i < frame.components.length; i++) {
  31997. component = frame.components[i];
  31998. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  31999. component.h / frame.maxH);
  32000. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32001. component.v / frame.maxV);
  32002. var blocksPerLineForMcu = mcusPerLine * component.h;
  32003. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32004. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32005. (blocksPerLineForMcu + 1);
  32006. component.blockData = new Int16Array(blocksBufferSize);
  32007. component.blocksPerLine = blocksPerLine;
  32008. component.blocksPerColumn = blocksPerColumn;
  32009. }
  32010. frame.mcusPerLine = mcusPerLine;
  32011. frame.mcusPerColumn = mcusPerColumn;
  32012. }
  32013. var offset = 0, length = data.length;
  32014. var jfif = null;
  32015. var adobe = null;
  32016. var pixels = null;
  32017. var frame, resetInterval;
  32018. var quantizationTables = [];
  32019. var huffmanTablesAC = [], huffmanTablesDC = [];
  32020. var fileMarker = readUint16();
  32021. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32022. throw 'SOI not found';
  32023. }
  32024. fileMarker = readUint16();
  32025. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32026. var i, j, l;
  32027. switch(fileMarker) {
  32028. case 0xFFE0: // APP0 (Application Specific)
  32029. case 0xFFE1: // APP1
  32030. case 0xFFE2: // APP2
  32031. case 0xFFE3: // APP3
  32032. case 0xFFE4: // APP4
  32033. case 0xFFE5: // APP5
  32034. case 0xFFE6: // APP6
  32035. case 0xFFE7: // APP7
  32036. case 0xFFE8: // APP8
  32037. case 0xFFE9: // APP9
  32038. case 0xFFEA: // APP10
  32039. case 0xFFEB: // APP11
  32040. case 0xFFEC: // APP12
  32041. case 0xFFED: // APP13
  32042. case 0xFFEE: // APP14
  32043. case 0xFFEF: // APP15
  32044. case 0xFFFE: // COM (Comment)
  32045. var appData = readDataBlock();
  32046. if (fileMarker === 0xFFE0) {
  32047. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32048. appData[2] === 0x49 && appData[3] === 0x46 &&
  32049. appData[4] === 0) { // 'JFIF\x00'
  32050. jfif = {
  32051. version: { major: appData[5], minor: appData[6] },
  32052. densityUnits: appData[7],
  32053. xDensity: (appData[8] << 8) | appData[9],
  32054. yDensity: (appData[10] << 8) | appData[11],
  32055. thumbWidth: appData[12],
  32056. thumbHeight: appData[13],
  32057. thumbData: appData.subarray(14, 14 +
  32058. 3 * appData[12] * appData[13])
  32059. };
  32060. }
  32061. }
  32062. // TODO APP1 - Exif
  32063. if (fileMarker === 0xFFEE) {
  32064. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32065. appData[2] === 0x6F && appData[3] === 0x62 &&
  32066. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32067. adobe = {
  32068. version: appData[6],
  32069. flags0: (appData[7] << 8) | appData[8],
  32070. flags1: (appData[9] << 8) | appData[10],
  32071. transformCode: appData[11]
  32072. };
  32073. }
  32074. }
  32075. break;
  32076. case 0xFFDB: // DQT (Define Quantization Tables)
  32077. var quantizationTablesLength = readUint16();
  32078. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32079. var z;
  32080. while (offset < quantizationTablesEnd) {
  32081. var quantizationTableSpec = data[offset++];
  32082. var tableData = new Uint16Array(64);
  32083. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32084. for (j = 0; j < 64; j++) {
  32085. z = dctZigZag[j];
  32086. tableData[z] = data[offset++];
  32087. }
  32088. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32089. for (j = 0; j < 64; j++) {
  32090. z = dctZigZag[j];
  32091. tableData[z] = readUint16();
  32092. }
  32093. } else {
  32094. throw 'DQT: invalid table spec';
  32095. }
  32096. quantizationTables[quantizationTableSpec & 15] = tableData;
  32097. }
  32098. break;
  32099. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32100. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32101. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32102. if (frame) {
  32103. throw 'Only single frame JPEGs supported';
  32104. }
  32105. readUint16(); // skip data length
  32106. frame = {};
  32107. frame.extended = (fileMarker === 0xFFC1);
  32108. frame.progressive = (fileMarker === 0xFFC2);
  32109. frame.precision = data[offset++];
  32110. frame.scanLines = readUint16();
  32111. frame.samplesPerLine = readUint16();
  32112. frame.components = [];
  32113. frame.componentIds = {};
  32114. var componentsCount = data[offset++], componentId;
  32115. var maxH = 0, maxV = 0;
  32116. for (i = 0; i < componentsCount; i++) {
  32117. componentId = data[offset];
  32118. var h = data[offset + 1] >> 4;
  32119. var v = data[offset + 1] & 15;
  32120. if (maxH < h) {
  32121. maxH = h;
  32122. }
  32123. if (maxV < v) {
  32124. maxV = v;
  32125. }
  32126. var qId = data[offset + 2];
  32127. l = frame.components.push({
  32128. h: h,
  32129. v: v,
  32130. quantizationTable: quantizationTables[qId]
  32131. });
  32132. frame.componentIds[componentId] = l - 1;
  32133. offset += 3;
  32134. }
  32135. frame.maxH = maxH;
  32136. frame.maxV = maxV;
  32137. prepareComponents(frame);
  32138. break;
  32139. case 0xFFC4: // DHT (Define Huffman Tables)
  32140. var huffmanLength = readUint16();
  32141. for (i = 2; i < huffmanLength;) {
  32142. var huffmanTableSpec = data[offset++];
  32143. var codeLengths = new Uint8Array(16);
  32144. var codeLengthSum = 0;
  32145. for (j = 0; j < 16; j++, offset++) {
  32146. codeLengthSum += (codeLengths[j] = data[offset]);
  32147. }
  32148. var huffmanValues = new Uint8Array(codeLengthSum);
  32149. for (j = 0; j < codeLengthSum; j++, offset++) {
  32150. huffmanValues[j] = data[offset];
  32151. }
  32152. i += 17 + codeLengthSum;
  32153. ((huffmanTableSpec >> 4) === 0 ?
  32154. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32155. buildHuffmanTable(codeLengths, huffmanValues);
  32156. }
  32157. break;
  32158. case 0xFFDD: // DRI (Define Restart Interval)
  32159. readUint16(); // skip data length
  32160. resetInterval = readUint16();
  32161. break;
  32162. case 0xFFDA: // SOS (Start of Scan)
  32163. var scanLength = readUint16();
  32164. var selectorsCount = data[offset++];
  32165. var components = [], component;
  32166. for (i = 0; i < selectorsCount; i++) {
  32167. var componentIndex = frame.componentIds[data[offset++]];
  32168. component = frame.components[componentIndex];
  32169. var tableSpec = data[offset++];
  32170. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32171. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32172. components.push(component);
  32173. }
  32174. var spectralStart = data[offset++];
  32175. var spectralEnd = data[offset++];
  32176. var successiveApproximation = data[offset++];
  32177. var processed = decodeScan(data, offset,
  32178. frame, components, resetInterval,
  32179. spectralStart, spectralEnd,
  32180. successiveApproximation >> 4, successiveApproximation & 15);
  32181. offset += processed;
  32182. break;
  32183. default:
  32184. if (data[offset - 3] === 0xFF &&
  32185. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32186. // could be incorrect encoding -- last 0xFF byte of the previous
  32187. // block was eaten by the encoder
  32188. offset -= 3;
  32189. break;
  32190. }
  32191. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32192. }
  32193. fileMarker = readUint16();
  32194. }
  32195. this.width = frame.samplesPerLine;
  32196. this.height = frame.scanLines;
  32197. this.jfif = jfif;
  32198. this.adobe = adobe;
  32199. this.components = [];
  32200. for (i = 0; i < frame.components.length; i++) {
  32201. component = frame.components[i];
  32202. this.components.push({
  32203. output: buildComponentData(frame, component),
  32204. scaleX: component.h / frame.maxH,
  32205. scaleY: component.v / frame.maxV,
  32206. blocksPerLine: component.blocksPerLine,
  32207. blocksPerColumn: component.blocksPerColumn
  32208. });
  32209. }
  32210. this.numComponents = this.components.length;
  32211. },
  32212. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32213. var scaleX = this.width / width, scaleY = this.height / height;
  32214. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32215. var x, y, i, j, k;
  32216. var index;
  32217. var offset = 0;
  32218. var output;
  32219. var numComponents = this.components.length;
  32220. var dataLength = width * height * numComponents;
  32221. var data = new Uint8Array(dataLength);
  32222. var xScaleBlockOffset = new Uint32Array(width);
  32223. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32224. for (i = 0; i < numComponents; i++) {
  32225. component = this.components[i];
  32226. componentScaleX = component.scaleX * scaleX;
  32227. componentScaleY = component.scaleY * scaleY;
  32228. offset = i;
  32229. output = component.output;
  32230. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32231. // precalculate the xScaleBlockOffset
  32232. for (x = 0; x < width; x++) {
  32233. j = 0 | (x * componentScaleX);
  32234. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32235. }
  32236. // linearize the blocks of the component
  32237. for (y = 0; y < height; y++) {
  32238. j = 0 | (y * componentScaleY);
  32239. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32240. for (x = 0; x < width; x++) {
  32241. data[offset] = output[index + xScaleBlockOffset[x]];
  32242. offset += numComponents;
  32243. }
  32244. }
  32245. }
  32246. // decodeTransform will contains pairs of multiplier (-256..256) and
  32247. // additive
  32248. var transform = this.decodeTransform;
  32249. if (transform) {
  32250. for (i = 0; i < dataLength;) {
  32251. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32252. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32253. }
  32254. }
  32255. }
  32256. return data;
  32257. },
  32258. _isColorConversionNeeded: function isColorConversionNeeded() {
  32259. if (this.adobe && this.adobe.transformCode) {
  32260. // The adobe transform marker overrides any previous setting
  32261. return true;
  32262. } else if (this.numComponents === 3) {
  32263. return true;
  32264. } else {
  32265. return false;
  32266. }
  32267. },
  32268. _convertYccToRgb: function convertYccToRgb(data) {
  32269. var Y, Cb, Cr;
  32270. for (var i = 0, length = data.length; i < length; i += 3) {
  32271. Y = data[i ];
  32272. Cb = data[i + 1];
  32273. Cr = data[i + 2];
  32274. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  32275. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  32276. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  32277. }
  32278. return data;
  32279. },
  32280. _convertYcckToRgb: function convertYcckToRgb(data) {
  32281. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  32282. var offset = 0;
  32283. for (var i = 0, length = data.length; i < length; i += 4) {
  32284. Y = data[i];
  32285. Cb = data[i + 1];
  32286. Cr = data[i + 2];
  32287. k = data[i + 3];
  32288. CbCb = Cb * Cb;
  32289. CbCr = Cb * Cr;
  32290. CbY = Cb * Y;
  32291. Cbk = Cb * k;
  32292. CrCr = Cr * Cr;
  32293. Crk = Cr * k;
  32294. CrY = Cr * Y;
  32295. YY = Y * Y;
  32296. Yk = Y * k;
  32297. kk = k * k;
  32298. var r = - 122.67195406894 -
  32299. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  32300. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  32301. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  32302. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  32303. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  32304. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  32305. 0.000336197177618394 * kk + 0.484791561490776 * k;
  32306. var g = 107.268039397724 +
  32307. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  32308. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  32309. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  32310. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  32311. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  32312. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  32313. 0.000318913117588328 * kk - 0.213742400323665 * k;
  32314. var b = - 20.810012546947 -
  32315. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  32316. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  32317. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  32318. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  32319. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  32320. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  32321. 0.000343531996510555 * kk + 0.24165260232407 * k;
  32322. data[offset++] = clamp0to255(r);
  32323. data[offset++] = clamp0to255(g);
  32324. data[offset++] = clamp0to255(b);
  32325. }
  32326. return data;
  32327. },
  32328. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  32329. var Y, Cb, Cr;
  32330. for (var i = 0, length = data.length; i < length; i += 4) {
  32331. Y = data[i];
  32332. Cb = data[i + 1];
  32333. Cr = data[i + 2];
  32334. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  32335. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  32336. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  32337. // K in data[i + 3] is unchanged
  32338. }
  32339. return data;
  32340. },
  32341. _convertCmykToRgb: function convertCmykToRgb(data) {
  32342. var c, m, y, k;
  32343. var offset = 0;
  32344. var min = -255 * 255 * 255;
  32345. var scale = 1 / 255 / 255;
  32346. for (var i = 0, length = data.length; i < length; i += 4) {
  32347. c = data[i];
  32348. m = data[i + 1];
  32349. y = data[i + 2];
  32350. k = data[i + 3];
  32351. var r =
  32352. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32353. 18.82290502165302 * y + 212.25662451639585 * k -
  32354. 72734.4411664936) +
  32355. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  32356. 17.873870861415444 * k - 1401.7366389350734) +
  32357. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32358. 4465.541406466231) -
  32359. k * (21.86122147463605 * k + 48317.86113160301);
  32360. var g =
  32361. c * (8.841041422036149 * c + 60.118027045597366 * m +
  32362. 6.871425592049007 * y + 31.159100130055922 * k -
  32363. 20220.756542821975) +
  32364. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32365. 131.35250912493976 * k - 48691.05921601825) +
  32366. y * (4.444339102852739 * y + 9.8632861493405 * k -
  32367. 6341.191035517494) -
  32368. k * (20.737325471181034 * k + 47890.15695978492);
  32369. var b =
  32370. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32371. 30.89978309703729 * y - 0.23883238689178934 * k -
  32372. 3616.812083916688) +
  32373. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32374. 50.606957656360734 * k - 28620.90484698408) +
  32375. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  32376. 49363.43385999684) -
  32377. k * (22.33816807309886 * k + 45932.16563550634);
  32378. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  32379. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  32380. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  32381. }
  32382. return data;
  32383. },
  32384. getData: function getData(width, height, forceRGBoutput) {
  32385. if (this.numComponents > 4) {
  32386. throw 'Unsupported color mode';
  32387. }
  32388. // type of data: Uint8Array(width * height * numComponents)
  32389. var data = this._getLinearizedBlockData(width, height);
  32390. if (this.numComponents === 3) {
  32391. return this._convertYccToRgb(data);
  32392. } else if (this.numComponents === 4) {
  32393. if (this._isColorConversionNeeded()) {
  32394. if (forceRGBoutput) {
  32395. return this._convertYcckToRgb(data);
  32396. } else {
  32397. return this._convertYcckToCmyk(data);
  32398. }
  32399. } else if (forceRGBoutput) {
  32400. return this._convertCmykToRgb(data);
  32401. }
  32402. }
  32403. return data;
  32404. }
  32405. };
  32406. return constructor;
  32407. })();
  32408. var JpxImage = (function JpxImageClosure() {
  32409. // Table E.1
  32410. var SubbandsGainLog2 = {
  32411. 'LL': 0,
  32412. 'LH': 1,
  32413. 'HL': 1,
  32414. 'HH': 2
  32415. };
  32416. function JpxImage() {
  32417. this.failOnCorruptedImage = false;
  32418. }
  32419. JpxImage.prototype = {
  32420. parse: function JpxImage_parse(data) {
  32421. var head = readUint16(data, 0);
  32422. // No box header, immediate start of codestream (SOC)
  32423. if (head === 0xFF4F) {
  32424. this.parseCodestream(data, 0, data.length);
  32425. return;
  32426. }
  32427. var position = 0, length = data.length;
  32428. while (position < length) {
  32429. var headerSize = 8;
  32430. var lbox = readUint32(data, position);
  32431. var tbox = readUint32(data, position + 4);
  32432. position += headerSize;
  32433. if (lbox === 1) {
  32434. // XLBox: read UInt64 according to spec.
  32435. // JavaScript's int precision of 53 bit should be sufficient here.
  32436. lbox = readUint32(data, position) * 4294967296 +
  32437. readUint32(data, position + 4);
  32438. position += 8;
  32439. headerSize += 8;
  32440. }
  32441. if (lbox === 0) {
  32442. lbox = length - position + headerSize;
  32443. }
  32444. if (lbox < headerSize) {
  32445. throw new Error('JPX Error: Invalid box field size');
  32446. }
  32447. var dataLength = lbox - headerSize;
  32448. var jumpDataLength = true;
  32449. switch (tbox) {
  32450. case 0x6A501A1A: // 'jP\032\032'
  32451. // TODO
  32452. break;
  32453. case 0x6A703268: // 'jp2h'
  32454. jumpDataLength = false; // parsing child boxes
  32455. break;
  32456. case 0x636F6C72: // 'colr'
  32457. // TODO
  32458. break;
  32459. case 0x6A703263: // 'jp2c'
  32460. this.parseCodestream(data, position, position + dataLength);
  32461. break;
  32462. }
  32463. if (jumpDataLength) {
  32464. position += dataLength;
  32465. }
  32466. }
  32467. },
  32468. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  32469. var newByte = stream.getByte();
  32470. while (newByte >= 0) {
  32471. var oldByte = newByte;
  32472. newByte = stream.getByte();
  32473. var code = (oldByte << 8) | newByte;
  32474. // Image and tile size (SIZ)
  32475. if (code === 0xFF51) {
  32476. stream.skip(4);
  32477. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  32478. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  32479. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  32480. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  32481. stream.skip(16);
  32482. var Csiz = stream.getUint16(); // Byte 36
  32483. this.width = Xsiz - XOsiz;
  32484. this.height = Ysiz - YOsiz;
  32485. this.componentsCount = Csiz;
  32486. // Results are always returned as Uint8Arrays
  32487. this.bitsPerComponent = 8;
  32488. return;
  32489. }
  32490. }
  32491. throw new Error('JPX Error: No size marker found in JPX stream');
  32492. },
  32493. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  32494. var context = {};
  32495. try {
  32496. var doNotRecover = false;
  32497. var position = start;
  32498. while (position + 1 < end) {
  32499. var code = readUint16(data, position);
  32500. position += 2;
  32501. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  32502. switch (code) {
  32503. case 0xFF4F: // Start of codestream (SOC)
  32504. context.mainHeader = true;
  32505. break;
  32506. case 0xFFD9: // End of codestream (EOC)
  32507. break;
  32508. case 0xFF51: // Image and tile size (SIZ)
  32509. length = readUint16(data, position);
  32510. var siz = {};
  32511. siz.Xsiz = readUint32(data, position + 4);
  32512. siz.Ysiz = readUint32(data, position + 8);
  32513. siz.XOsiz = readUint32(data, position + 12);
  32514. siz.YOsiz = readUint32(data, position + 16);
  32515. siz.XTsiz = readUint32(data, position + 20);
  32516. siz.YTsiz = readUint32(data, position + 24);
  32517. siz.XTOsiz = readUint32(data, position + 28);
  32518. siz.YTOsiz = readUint32(data, position + 32);
  32519. var componentsCount = readUint16(data, position + 36);
  32520. siz.Csiz = componentsCount;
  32521. var components = [];
  32522. j = position + 38;
  32523. for (var i = 0; i < componentsCount; i++) {
  32524. var component = {
  32525. precision: (data[j] & 0x7F) + 1,
  32526. isSigned: !!(data[j] & 0x80),
  32527. XRsiz: data[j + 1],
  32528. YRsiz: data[j + 1]
  32529. };
  32530. calculateComponentDimensions(component, siz);
  32531. components.push(component);
  32532. }
  32533. context.SIZ = siz;
  32534. context.components = components;
  32535. calculateTileGrids(context, components);
  32536. context.QCC = [];
  32537. context.COC = [];
  32538. break;
  32539. case 0xFF55: // Tile-part lengths, main header (TLM)
  32540. var Ltlm = readUint16(data, position); // Marker segment length
  32541. // Skip tile length markers
  32542. position += Ltlm;
  32543. break;
  32544. case 0xFF5C: // Quantization default (QCD)
  32545. length = readUint16(data, position);
  32546. var qcd = {};
  32547. j = position + 2;
  32548. sqcd = data[j++];
  32549. switch (sqcd & 0x1F) {
  32550. case 0:
  32551. spqcdSize = 8;
  32552. scalarExpounded = true;
  32553. break;
  32554. case 1:
  32555. spqcdSize = 16;
  32556. scalarExpounded = false;
  32557. break;
  32558. case 2:
  32559. spqcdSize = 16;
  32560. scalarExpounded = true;
  32561. break;
  32562. default:
  32563. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32564. }
  32565. qcd.noQuantization = (spqcdSize === 8);
  32566. qcd.scalarExpounded = scalarExpounded;
  32567. qcd.guardBits = sqcd >> 5;
  32568. spqcds = [];
  32569. while (j < length + position) {
  32570. var spqcd = {};
  32571. if (spqcdSize === 8) {
  32572. spqcd.epsilon = data[j++] >> 3;
  32573. spqcd.mu = 0;
  32574. } else {
  32575. spqcd.epsilon = data[j] >> 3;
  32576. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32577. j += 2;
  32578. }
  32579. spqcds.push(spqcd);
  32580. }
  32581. qcd.SPqcds = spqcds;
  32582. if (context.mainHeader) {
  32583. context.QCD = qcd;
  32584. } else {
  32585. context.currentTile.QCD = qcd;
  32586. context.currentTile.QCC = [];
  32587. }
  32588. break;
  32589. case 0xFF5D: // Quantization component (QCC)
  32590. length = readUint16(data, position);
  32591. var qcc = {};
  32592. j = position + 2;
  32593. var cqcc;
  32594. if (context.SIZ.Csiz < 257) {
  32595. cqcc = data[j++];
  32596. } else {
  32597. cqcc = readUint16(data, j);
  32598. j += 2;
  32599. }
  32600. sqcd = data[j++];
  32601. switch (sqcd & 0x1F) {
  32602. case 0:
  32603. spqcdSize = 8;
  32604. scalarExpounded = true;
  32605. break;
  32606. case 1:
  32607. spqcdSize = 16;
  32608. scalarExpounded = false;
  32609. break;
  32610. case 2:
  32611. spqcdSize = 16;
  32612. scalarExpounded = true;
  32613. break;
  32614. default:
  32615. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  32616. }
  32617. qcc.noQuantization = (spqcdSize === 8);
  32618. qcc.scalarExpounded = scalarExpounded;
  32619. qcc.guardBits = sqcd >> 5;
  32620. spqcds = [];
  32621. while (j < (length + position)) {
  32622. spqcd = {};
  32623. if (spqcdSize === 8) {
  32624. spqcd.epsilon = data[j++] >> 3;
  32625. spqcd.mu = 0;
  32626. } else {
  32627. spqcd.epsilon = data[j] >> 3;
  32628. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  32629. j += 2;
  32630. }
  32631. spqcds.push(spqcd);
  32632. }
  32633. qcc.SPqcds = spqcds;
  32634. if (context.mainHeader) {
  32635. context.QCC[cqcc] = qcc;
  32636. } else {
  32637. context.currentTile.QCC[cqcc] = qcc;
  32638. }
  32639. break;
  32640. case 0xFF52: // Coding style default (COD)
  32641. length = readUint16(data, position);
  32642. var cod = {};
  32643. j = position + 2;
  32644. var scod = data[j++];
  32645. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  32646. cod.sopMarkerUsed = !!(scod & 2);
  32647. cod.ephMarkerUsed = !!(scod & 4);
  32648. cod.progressionOrder = data[j++];
  32649. cod.layersCount = readUint16(data, j);
  32650. j += 2;
  32651. cod.multipleComponentTransform = data[j++];
  32652. cod.decompositionLevelsCount = data[j++];
  32653. cod.xcb = (data[j++] & 0xF) + 2;
  32654. cod.ycb = (data[j++] & 0xF) + 2;
  32655. var blockStyle = data[j++];
  32656. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  32657. cod.resetContextProbabilities = !!(blockStyle & 2);
  32658. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  32659. cod.verticalyStripe = !!(blockStyle & 8);
  32660. cod.predictableTermination = !!(blockStyle & 16);
  32661. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  32662. cod.reversibleTransformation = data[j++];
  32663. if (cod.entropyCoderWithCustomPrecincts) {
  32664. var precinctsSizes = [];
  32665. while (j < length + position) {
  32666. var precinctsSize = data[j++];
  32667. precinctsSizes.push({
  32668. PPx: precinctsSize & 0xF,
  32669. PPy: precinctsSize >> 4
  32670. });
  32671. }
  32672. cod.precinctsSizes = precinctsSizes;
  32673. }
  32674. var unsupported = [];
  32675. if (cod.sopMarkerUsed) {
  32676. unsupported.push('sopMarkerUsed');
  32677. }
  32678. if (cod.ephMarkerUsed) {
  32679. unsupported.push('ephMarkerUsed');
  32680. }
  32681. if (cod.selectiveArithmeticCodingBypass) {
  32682. unsupported.push('selectiveArithmeticCodingBypass');
  32683. }
  32684. if (cod.resetContextProbabilities) {
  32685. unsupported.push('resetContextProbabilities');
  32686. }
  32687. if (cod.terminationOnEachCodingPass) {
  32688. unsupported.push('terminationOnEachCodingPass');
  32689. }
  32690. if (cod.verticalyStripe) {
  32691. unsupported.push('verticalyStripe');
  32692. }
  32693. if (cod.predictableTermination) {
  32694. unsupported.push('predictableTermination');
  32695. }
  32696. if (unsupported.length > 0) {
  32697. doNotRecover = true;
  32698. throw new Error('JPX Error: Unsupported COD options (' +
  32699. unsupported.join(', ') + ')');
  32700. }
  32701. if (context.mainHeader) {
  32702. context.COD = cod;
  32703. } else {
  32704. context.currentTile.COD = cod;
  32705. context.currentTile.COC = [];
  32706. }
  32707. break;
  32708. case 0xFF90: // Start of tile-part (SOT)
  32709. length = readUint16(data, position);
  32710. tile = {};
  32711. tile.index = readUint16(data, position + 2);
  32712. tile.length = readUint32(data, position + 4);
  32713. tile.dataEnd = tile.length + position - 2;
  32714. tile.partIndex = data[position + 8];
  32715. tile.partsCount = data[position + 9];
  32716. context.mainHeader = false;
  32717. if (tile.partIndex === 0) {
  32718. // reset component specific settings
  32719. tile.COD = context.COD;
  32720. tile.COC = context.COC.slice(0); // clone of the global COC
  32721. tile.QCD = context.QCD;
  32722. tile.QCC = context.QCC.slice(0); // clone of the global COC
  32723. }
  32724. context.currentTile = tile;
  32725. break;
  32726. case 0xFF93: // Start of data (SOD)
  32727. tile = context.currentTile;
  32728. if (tile.partIndex === 0) {
  32729. initializeTile(context, tile.index);
  32730. buildPackets(context);
  32731. }
  32732. // moving to the end of the data
  32733. length = tile.dataEnd - position;
  32734. parseTilePackets(context, data, position, length);
  32735. break;
  32736. case 0xFF64: // Comment (COM)
  32737. length = readUint16(data, position);
  32738. // skipping content
  32739. break;
  32740. case 0xFF53: // Coding style component (COC)
  32741. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  32742. 'not implemented');
  32743. default:
  32744. throw new Error('JPX Error: Unknown codestream code: ' +
  32745. code.toString(16));
  32746. }
  32747. position += length;
  32748. }
  32749. } catch (e) {
  32750. if (doNotRecover || this.failOnCorruptedImage) {
  32751. throw e;
  32752. } else {
  32753. warn('Trying to recover from ' + e.message);
  32754. }
  32755. }
  32756. this.tiles = transformComponents(context);
  32757. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  32758. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  32759. this.componentsCount = context.SIZ.Csiz;
  32760. }
  32761. };
  32762. function calculateComponentDimensions(component, siz) {
  32763. // Section B.2 Component mapping
  32764. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  32765. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  32766. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  32767. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  32768. component.width = component.x1 - component.x0;
  32769. component.height = component.y1 - component.y0;
  32770. }
  32771. function calculateTileGrids(context, components) {
  32772. var siz = context.SIZ;
  32773. // Section B.3 Division into tile and tile-components
  32774. var tile, tiles = [];
  32775. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  32776. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  32777. for (var q = 0; q < numYtiles; q++) {
  32778. for (var p = 0; p < numXtiles; p++) {
  32779. tile = {};
  32780. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  32781. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  32782. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  32783. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  32784. tile.width = tile.tx1 - tile.tx0;
  32785. tile.height = tile.ty1 - tile.ty0;
  32786. tile.components = [];
  32787. tiles.push(tile);
  32788. }
  32789. }
  32790. context.tiles = tiles;
  32791. var componentsCount = siz.Csiz;
  32792. for (var i = 0, ii = componentsCount; i < ii; i++) {
  32793. var component = components[i];
  32794. for (var j = 0, jj = tiles.length; j < jj; j++) {
  32795. var tileComponent = {};
  32796. tile = tiles[j];
  32797. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  32798. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  32799. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  32800. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  32801. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  32802. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  32803. tile.components[i] = tileComponent;
  32804. }
  32805. }
  32806. }
  32807. function getBlocksDimensions(context, component, r) {
  32808. var codOrCoc = component.codingStyleParameters;
  32809. var result = {};
  32810. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  32811. result.PPx = 15;
  32812. result.PPy = 15;
  32813. } else {
  32814. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  32815. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  32816. }
  32817. // calculate codeblock size as described in section B.7
  32818. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  32819. Math.min(codOrCoc.xcb, result.PPx));
  32820. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  32821. Math.min(codOrCoc.ycb, result.PPy));
  32822. return result;
  32823. }
  32824. function buildPrecincts(context, resolution, dimensions) {
  32825. // Section B.6 Division resolution to precincts
  32826. var precinctWidth = 1 << dimensions.PPx;
  32827. var precinctHeight = 1 << dimensions.PPy;
  32828. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  32829. Math.ceil(resolution.trx1 / precinctWidth) -
  32830. Math.floor(resolution.trx0 / precinctWidth) : 0);
  32831. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  32832. Math.ceil(resolution.try1 / precinctHeight) -
  32833. Math.floor(resolution.try0 / precinctHeight) : 0);
  32834. var numprecincts = numprecinctswide * numprecinctshigh;
  32835. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  32836. precinctWidth;
  32837. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  32838. precinctHeight;
  32839. resolution.precinctParameters = {
  32840. precinctXOffset: precinctXOffset,
  32841. precinctYOffset: precinctYOffset,
  32842. precinctWidth: precinctWidth,
  32843. precinctHeight: precinctHeight,
  32844. numprecinctswide: numprecinctswide,
  32845. numprecinctshigh: numprecinctshigh,
  32846. numprecincts: numprecincts
  32847. };
  32848. }
  32849. function buildCodeblocks(context, subband, dimensions) {
  32850. // Section B.7 Division sub-band into code-blocks
  32851. var xcb_ = dimensions.xcb_;
  32852. var ycb_ = dimensions.ycb_;
  32853. var codeblockWidth = 1 << xcb_;
  32854. var codeblockHeight = 1 << ycb_;
  32855. var cbx0 = subband.tbx0 >> xcb_;
  32856. var cby0 = subband.tby0 >> ycb_;
  32857. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  32858. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  32859. var precinctParameters = subband.resolution.precinctParameters;
  32860. var codeblocks = [];
  32861. var precincts = [];
  32862. var i, j, codeblock, precinctNumber;
  32863. for (j = cby0; j < cby1; j++) {
  32864. for (i = cbx0; i < cbx1; i++) {
  32865. codeblock = {
  32866. cbx: i,
  32867. cby: j,
  32868. tbx0: codeblockWidth * i,
  32869. tby0: codeblockHeight * j,
  32870. tbx1: codeblockWidth * (i + 1),
  32871. tby1: codeblockHeight * (j + 1)
  32872. };
  32873. // calculate precinct number
  32874. var pi = Math.floor((codeblock.tbx0 -
  32875. precinctParameters.precinctXOffset) /
  32876. precinctParameters.precinctWidth);
  32877. var pj = Math.floor((codeblock.tby0 -
  32878. precinctParameters.precinctYOffset) /
  32879. precinctParameters.precinctHeight);
  32880. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  32881. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  32882. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  32883. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  32884. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  32885. codeblock.precinctNumber = precinctNumber;
  32886. codeblock.subbandType = subband.type;
  32887. codeblock.Lblock = 3;
  32888. codeblocks.push(codeblock);
  32889. // building precinct for the sub-band
  32890. var precinct = precincts[precinctNumber];
  32891. if (precinct !== undefined) {
  32892. if (i < precinct.cbxMin) {
  32893. precinct.cbxMin = i;
  32894. } else if (i > precinct.cbxMax) {
  32895. precinct.cbxMax = i;
  32896. }
  32897. if (j < precinct.cbyMin) {
  32898. precinct.cbxMin = j;
  32899. } else if (j > precinct.cbyMax) {
  32900. precinct.cbyMax = j;
  32901. }
  32902. } else {
  32903. precincts[precinctNumber] = precinct = {
  32904. cbxMin: i,
  32905. cbyMin: j,
  32906. cbxMax: i,
  32907. cbyMax: j
  32908. };
  32909. }
  32910. codeblock.precinct = precinct;
  32911. }
  32912. }
  32913. subband.codeblockParameters = {
  32914. codeblockWidth: xcb_,
  32915. codeblockHeight: ycb_,
  32916. numcodeblockwide: cbx1 - cbx0 + 1,
  32917. numcodeblockhigh: cby1 - cby1 + 1
  32918. };
  32919. subband.codeblocks = codeblocks;
  32920. subband.precincts = precincts;
  32921. }
  32922. function createPacket(resolution, precinctNumber, layerNumber) {
  32923. var precinctCodeblocks = [];
  32924. // Section B.10.8 Order of info in packet
  32925. var subbands = resolution.subbands;
  32926. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  32927. for (var i = 0, ii = subbands.length; i < ii; i++) {
  32928. var subband = subbands[i];
  32929. var codeblocks = subband.codeblocks;
  32930. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  32931. var codeblock = codeblocks[j];
  32932. if (codeblock.precinctNumber !== precinctNumber) {
  32933. continue;
  32934. }
  32935. precinctCodeblocks.push(codeblock);
  32936. }
  32937. }
  32938. return {
  32939. layerNumber: layerNumber,
  32940. codeblocks: precinctCodeblocks
  32941. };
  32942. }
  32943. function LayerResolutionComponentPositionIterator(context) {
  32944. var siz = context.SIZ;
  32945. var tileIndex = context.currentTile.index;
  32946. var tile = context.tiles[tileIndex];
  32947. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32948. var componentsCount = siz.Csiz;
  32949. var maxDecompositionLevelsCount = 0;
  32950. for (var q = 0; q < componentsCount; q++) {
  32951. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32952. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32953. }
  32954. var l = 0, r = 0, i = 0, k = 0;
  32955. this.nextPacket = function JpxImage_nextPacket() {
  32956. // Section B.12.1.1 Layer-resolution-component-position
  32957. for (; l < layersCount; l++) {
  32958. for (; r <= maxDecompositionLevelsCount; r++) {
  32959. for (; i < componentsCount; i++) {
  32960. var component = tile.components[i];
  32961. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32962. continue;
  32963. }
  32964. var resolution = component.resolutions[r];
  32965. var numprecincts = resolution.precinctParameters.numprecincts;
  32966. for (; k < numprecincts;) {
  32967. var packet = createPacket(resolution, k, l);
  32968. k++;
  32969. return packet;
  32970. }
  32971. k = 0;
  32972. }
  32973. i = 0;
  32974. }
  32975. r = 0;
  32976. }
  32977. throw new Error('JPX Error: Out of packets');
  32978. };
  32979. }
  32980. function ResolutionLayerComponentPositionIterator(context) {
  32981. var siz = context.SIZ;
  32982. var tileIndex = context.currentTile.index;
  32983. var tile = context.tiles[tileIndex];
  32984. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32985. var componentsCount = siz.Csiz;
  32986. var maxDecompositionLevelsCount = 0;
  32987. for (var q = 0; q < componentsCount; q++) {
  32988. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32989. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32990. }
  32991. var r = 0, l = 0, i = 0, k = 0;
  32992. this.nextPacket = function JpxImage_nextPacket() {
  32993. // Section B.12.1.2 Resolution-layer-component-position
  32994. for (; r <= maxDecompositionLevelsCount; r++) {
  32995. for (; l < layersCount; l++) {
  32996. for (; i < componentsCount; i++) {
  32997. var component = tile.components[i];
  32998. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32999. continue;
  33000. }
  33001. var resolution = component.resolutions[r];
  33002. var numprecincts = resolution.precinctParameters.numprecincts;
  33003. for (; k < numprecincts;) {
  33004. var packet = createPacket(resolution, k, l);
  33005. k++;
  33006. return packet;
  33007. }
  33008. k = 0;
  33009. }
  33010. i = 0;
  33011. }
  33012. l = 0;
  33013. }
  33014. throw new Error('JPX Error: Out of packets');
  33015. };
  33016. }
  33017. function buildPackets(context) {
  33018. var siz = context.SIZ;
  33019. var tileIndex = context.currentTile.index;
  33020. var tile = context.tiles[tileIndex];
  33021. var componentsCount = siz.Csiz;
  33022. // Creating resolutions and sub-bands for each component
  33023. for (var c = 0; c < componentsCount; c++) {
  33024. var component = tile.components[c];
  33025. var decompositionLevelsCount =
  33026. component.codingStyleParameters.decompositionLevelsCount;
  33027. // Section B.5 Resolution levels and sub-bands
  33028. var resolutions = [];
  33029. var subbands = [];
  33030. for (var r = 0; r <= decompositionLevelsCount; r++) {
  33031. var blocksDimensions = getBlocksDimensions(context, component, r);
  33032. var resolution = {};
  33033. var scale = 1 << (decompositionLevelsCount - r);
  33034. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  33035. resolution.try0 = Math.ceil(component.tcy0 / scale);
  33036. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  33037. resolution.try1 = Math.ceil(component.tcy1 / scale);
  33038. buildPrecincts(context, resolution, blocksDimensions);
  33039. resolutions.push(resolution);
  33040. var subband;
  33041. if (r === 0) {
  33042. // one sub-band (LL) with last decomposition
  33043. subband = {};
  33044. subband.type = 'LL';
  33045. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  33046. subband.tby0 = Math.ceil(component.tcy0 / scale);
  33047. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  33048. subband.tby1 = Math.ceil(component.tcy1 / scale);
  33049. subband.resolution = resolution;
  33050. buildCodeblocks(context, subband, blocksDimensions);
  33051. subbands.push(subband);
  33052. resolution.subbands = [subband];
  33053. } else {
  33054. var bscale = 1 << (decompositionLevelsCount - r + 1);
  33055. var resolutionSubbands = [];
  33056. // three sub-bands (HL, LH and HH) with rest of decompositions
  33057. subband = {};
  33058. subband.type = 'HL';
  33059. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33060. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  33061. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33062. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  33063. subband.resolution = resolution;
  33064. buildCodeblocks(context, subband, blocksDimensions);
  33065. subbands.push(subband);
  33066. resolutionSubbands.push(subband);
  33067. subband = {};
  33068. subband.type = 'LH';
  33069. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  33070. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33071. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  33072. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33073. subband.resolution = resolution;
  33074. buildCodeblocks(context, subband, blocksDimensions);
  33075. subbands.push(subband);
  33076. resolutionSubbands.push(subband);
  33077. subband = {};
  33078. subband.type = 'HH';
  33079. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  33080. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  33081. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  33082. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  33083. subband.resolution = resolution;
  33084. buildCodeblocks(context, subband, blocksDimensions);
  33085. subbands.push(subband);
  33086. resolutionSubbands.push(subband);
  33087. resolution.subbands = resolutionSubbands;
  33088. }
  33089. }
  33090. component.resolutions = resolutions;
  33091. component.subbands = subbands;
  33092. }
  33093. // Generate the packets sequence
  33094. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  33095. switch (progressionOrder) {
  33096. case 0:
  33097. tile.packetsIterator =
  33098. new LayerResolutionComponentPositionIterator(context);
  33099. break;
  33100. case 1:
  33101. tile.packetsIterator =
  33102. new ResolutionLayerComponentPositionIterator(context);
  33103. break;
  33104. default:
  33105. throw new Error('JPX Error: Unsupported progression order ' +
  33106. progressionOrder);
  33107. }
  33108. }
  33109. function parseTilePackets(context, data, offset, dataLength) {
  33110. var position = 0;
  33111. var buffer, bufferSize = 0, skipNextBit = false;
  33112. function readBits(count) {
  33113. while (bufferSize < count) {
  33114. var b = data[offset + position];
  33115. position++;
  33116. if (skipNextBit) {
  33117. buffer = (buffer << 7) | b;
  33118. bufferSize += 7;
  33119. skipNextBit = false;
  33120. } else {
  33121. buffer = (buffer << 8) | b;
  33122. bufferSize += 8;
  33123. }
  33124. if (b === 0xFF) {
  33125. skipNextBit = true;
  33126. }
  33127. }
  33128. bufferSize -= count;
  33129. return (buffer >>> bufferSize) & ((1 << count) - 1);
  33130. }
  33131. function alignToByte() {
  33132. bufferSize = 0;
  33133. if (skipNextBit) {
  33134. position++;
  33135. skipNextBit = false;
  33136. }
  33137. }
  33138. function readCodingpasses() {
  33139. if (readBits(1) === 0) {
  33140. return 1;
  33141. }
  33142. if (readBits(1) === 0) {
  33143. return 2;
  33144. }
  33145. var value = readBits(2);
  33146. if (value < 3) {
  33147. return value + 3;
  33148. }
  33149. value = readBits(5);
  33150. if (value < 31) {
  33151. return value + 6;
  33152. }
  33153. value = readBits(7);
  33154. return value + 37;
  33155. }
  33156. var tileIndex = context.currentTile.index;
  33157. var tile = context.tiles[tileIndex];
  33158. var packetsIterator = tile.packetsIterator;
  33159. while (position < dataLength) {
  33160. var packet = packetsIterator.nextPacket();
  33161. if (!readBits(1)) {
  33162. alignToByte();
  33163. continue;
  33164. }
  33165. var layerNumber = packet.layerNumber;
  33166. var queue = [], codeblock;
  33167. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  33168. codeblock = packet.codeblocks[i];
  33169. var precinct = codeblock.precinct;
  33170. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  33171. var codeblockRow = codeblock.cby - precinct.cbyMin;
  33172. var codeblockIncluded = false;
  33173. var firstTimeInclusion = false;
  33174. var valueReady;
  33175. if ('included' in codeblock) {
  33176. codeblockIncluded = !!readBits(1);
  33177. } else {
  33178. // reading inclusion tree
  33179. precinct = codeblock.precinct;
  33180. var inclusionTree, zeroBitPlanesTree;
  33181. if ('inclusionTree' in precinct) {
  33182. inclusionTree = precinct.inclusionTree;
  33183. } else {
  33184. // building inclusion and zero bit-planes trees
  33185. var width = precinct.cbxMax - precinct.cbxMin + 1;
  33186. var height = precinct.cbyMax - precinct.cbyMin + 1;
  33187. inclusionTree = new InclusionTree(width, height, layerNumber);
  33188. zeroBitPlanesTree = new TagTree(width, height);
  33189. precinct.inclusionTree = inclusionTree;
  33190. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  33191. }
  33192. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  33193. while (true) {
  33194. if (readBits(1)) {
  33195. valueReady = !inclusionTree.nextLevel();
  33196. if (valueReady) {
  33197. codeblock.included = true;
  33198. codeblockIncluded = firstTimeInclusion = true;
  33199. break;
  33200. }
  33201. } else {
  33202. inclusionTree.incrementValue(layerNumber);
  33203. break;
  33204. }
  33205. }
  33206. }
  33207. }
  33208. if (!codeblockIncluded) {
  33209. continue;
  33210. }
  33211. if (firstTimeInclusion) {
  33212. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  33213. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  33214. while (true) {
  33215. if (readBits(1)) {
  33216. valueReady = !zeroBitPlanesTree.nextLevel();
  33217. if (valueReady) {
  33218. break;
  33219. }
  33220. } else {
  33221. zeroBitPlanesTree.incrementValue();
  33222. }
  33223. }
  33224. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  33225. }
  33226. var codingpasses = readCodingpasses();
  33227. while (readBits(1)) {
  33228. codeblock.Lblock++;
  33229. }
  33230. var codingpassesLog2 = log2(codingpasses);
  33231. // rounding down log2
  33232. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  33233. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  33234. var codedDataLength = readBits(bits);
  33235. queue.push({
  33236. codeblock: codeblock,
  33237. codingpasses: codingpasses,
  33238. dataLength: codedDataLength
  33239. });
  33240. }
  33241. alignToByte();
  33242. while (queue.length > 0) {
  33243. var packetItem = queue.shift();
  33244. codeblock = packetItem.codeblock;
  33245. if (!('data' in codeblock)) {
  33246. codeblock.data = [];
  33247. }
  33248. codeblock.data.push({
  33249. data: data,
  33250. start: offset + position,
  33251. end: offset + position + packetItem.dataLength,
  33252. codingpasses: packetItem.codingpasses
  33253. });
  33254. position += packetItem.dataLength;
  33255. }
  33256. }
  33257. return position;
  33258. }
  33259. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  33260. delta, mb, reversible, segmentationSymbolUsed) {
  33261. var x0 = subband.tbx0;
  33262. var y0 = subband.tby0;
  33263. var width = subband.tbx1 - subband.tbx0;
  33264. var codeblocks = subband.codeblocks;
  33265. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  33266. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  33267. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  33268. var codeblock = codeblocks[i];
  33269. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  33270. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  33271. if (blockWidth === 0 || blockHeight === 0) {
  33272. continue;
  33273. }
  33274. if (!('data' in codeblock)) {
  33275. continue;
  33276. }
  33277. var bitModel, currentCodingpassType;
  33278. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  33279. codeblock.zeroBitPlanes, mb);
  33280. currentCodingpassType = 2; // first bit plane starts from cleanup
  33281. // collect data
  33282. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  33283. var j, jj, dataItem;
  33284. for (j = 0, jj = data.length; j < jj; j++) {
  33285. dataItem = data[j];
  33286. totalLength += dataItem.end - dataItem.start;
  33287. codingpasses += dataItem.codingpasses;
  33288. }
  33289. var encodedData = new Uint8Array(totalLength);
  33290. var position = 0;
  33291. for (j = 0, jj = data.length; j < jj; j++) {
  33292. dataItem = data[j];
  33293. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  33294. encodedData.set(chunk, position);
  33295. position += chunk.length;
  33296. }
  33297. // decoding the item
  33298. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  33299. bitModel.setDecoder(decoder);
  33300. for (j = 0; j < codingpasses; j++) {
  33301. switch (currentCodingpassType) {
  33302. case 0:
  33303. bitModel.runSignificancePropogationPass();
  33304. break;
  33305. case 1:
  33306. bitModel.runMagnitudeRefinementPass();
  33307. break;
  33308. case 2:
  33309. bitModel.runCleanupPass();
  33310. if (segmentationSymbolUsed) {
  33311. bitModel.checkSegmentationSymbol();
  33312. }
  33313. break;
  33314. }
  33315. currentCodingpassType = (currentCodingpassType + 1) % 3;
  33316. }
  33317. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  33318. var sign = bitModel.coefficentsSign;
  33319. var magnitude = bitModel.coefficentsMagnitude;
  33320. var bitsDecoded = bitModel.bitsDecoded;
  33321. var magnitudeCorrection = reversible ? 0 : 0.5;
  33322. var k, n, nb;
  33323. position = 0;
  33324. // Do the interleaving of Section F.3.3 here, so we do not need
  33325. // to copy later. LL level is not interleaved, just copied.
  33326. var interleave = (subband.type !== 'LL');
  33327. for (j = 0; j < blockHeight; j++) {
  33328. var row = (offset / width) | 0; // row in the non-interleaved subband
  33329. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  33330. for (k = 0; k < blockWidth; k++) {
  33331. n = magnitude[position];
  33332. if (n !== 0) {
  33333. n = (n + magnitudeCorrection) * delta;
  33334. if (sign[position] !== 0) {
  33335. n = -n;
  33336. }
  33337. nb = bitsDecoded[position];
  33338. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  33339. if (reversible && (nb >= mb)) {
  33340. coefficients[pos] = n;
  33341. } else {
  33342. coefficients[pos] = n * (1 << (mb - nb));
  33343. }
  33344. }
  33345. offset++;
  33346. position++;
  33347. }
  33348. offset += width - blockWidth;
  33349. }
  33350. }
  33351. }
  33352. function transformTile(context, tile, c) {
  33353. var component = tile.components[c];
  33354. var codingStyleParameters = component.codingStyleParameters;
  33355. var quantizationParameters = component.quantizationParameters;
  33356. var decompositionLevelsCount =
  33357. codingStyleParameters.decompositionLevelsCount;
  33358. var spqcds = quantizationParameters.SPqcds;
  33359. var scalarExpounded = quantizationParameters.scalarExpounded;
  33360. var guardBits = quantizationParameters.guardBits;
  33361. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  33362. var precision = context.components[c].precision;
  33363. var reversible = codingStyleParameters.reversibleTransformation;
  33364. var transform = (reversible ? new ReversibleTransform() :
  33365. new IrreversibleTransform());
  33366. var subbandCoefficients = [];
  33367. var b = 0;
  33368. for (var i = 0; i <= decompositionLevelsCount; i++) {
  33369. var resolution = component.resolutions[i];
  33370. var width = resolution.trx1 - resolution.trx0;
  33371. var height = resolution.try1 - resolution.try0;
  33372. // Allocate space for the whole sublevel.
  33373. var coefficients = new Float32Array(width * height);
  33374. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  33375. var mu, epsilon;
  33376. if (!scalarExpounded) {
  33377. // formula E-5
  33378. mu = spqcds[0].mu;
  33379. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  33380. } else {
  33381. mu = spqcds[b].mu;
  33382. epsilon = spqcds[b].epsilon;
  33383. b++;
  33384. }
  33385. var subband = resolution.subbands[j];
  33386. var gainLog2 = SubbandsGainLog2[subband.type];
  33387. // calulate quantization coefficient (Section E.1.1.1)
  33388. var delta = (reversible ? 1 :
  33389. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  33390. var mb = (guardBits + epsilon - 1);
  33391. // In the first resolution level, copyCoefficients will fill the
  33392. // whole array with coefficients. In the succeding passes,
  33393. // copyCoefficients will consecutively fill in the values that belong
  33394. // to the interleaved positions of the HL, LH, and HH coefficients.
  33395. // The LL coefficients will then be interleaved in Transform.iterate().
  33396. copyCoefficients(coefficients, width, height, subband, delta, mb,
  33397. reversible, segmentationSymbolUsed);
  33398. }
  33399. subbandCoefficients.push({
  33400. width: width,
  33401. height: height,
  33402. items: coefficients
  33403. });
  33404. }
  33405. var result = transform.calculate(subbandCoefficients,
  33406. component.tcx0, component.tcy0);
  33407. return {
  33408. left: component.tcx0,
  33409. top: component.tcy0,
  33410. width: result.width,
  33411. height: result.height,
  33412. items: result.items
  33413. };
  33414. }
  33415. function transformComponents(context) {
  33416. var siz = context.SIZ;
  33417. var components = context.components;
  33418. var componentsCount = siz.Csiz;
  33419. var resultImages = [];
  33420. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  33421. var tile = context.tiles[i];
  33422. var transformedTiles = [];
  33423. var c;
  33424. for (c = 0; c < componentsCount; c++) {
  33425. transformedTiles[c] = transformTile(context, tile, c);
  33426. }
  33427. var tile0 = transformedTiles[0];
  33428. var out = new Uint8Array(tile0.items.length * componentsCount);
  33429. var result = {
  33430. left: tile0.left,
  33431. top: tile0.top,
  33432. width: tile0.width,
  33433. height: tile0.height,
  33434. items: out
  33435. };
  33436. // Section G.2.2 Inverse multi component transform
  33437. var shift, offset, max, min, maxK;
  33438. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  33439. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  33440. var fourComponents = componentsCount === 4;
  33441. var y0items = transformedTiles[0].items;
  33442. var y1items = transformedTiles[1].items;
  33443. var y2items = transformedTiles[2].items;
  33444. var y3items = fourComponents ? transformedTiles[3].items : null;
  33445. // HACK: The multiple component transform formulas below assume that
  33446. // all components have the same precision. With this in mind, we
  33447. // compute shift and offset only once.
  33448. shift = components[0].precision - 8;
  33449. offset = (128 << shift) + 0.5;
  33450. max = 255 * (1 << shift);
  33451. maxK = max * 0.5;
  33452. min = -maxK;
  33453. var component0 = tile.components[0];
  33454. var alpha01 = componentsCount - 3;
  33455. jj = y0items.length;
  33456. if (!component0.codingStyleParameters.reversibleTransformation) {
  33457. // inverse irreversible multiple component transform
  33458. for (j = 0; j < jj; j++, pos += alpha01) {
  33459. y0 = y0items[j] + offset;
  33460. y1 = y1items[j];
  33461. y2 = y2items[j];
  33462. r = y0 + 1.402 * y2;
  33463. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  33464. b = y0 + 1.772 * y1;
  33465. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33466. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33467. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33468. }
  33469. } else {
  33470. // inverse reversible multiple component transform
  33471. for (j = 0; j < jj; j++, pos += alpha01) {
  33472. y0 = y0items[j] + offset;
  33473. y1 = y1items[j];
  33474. y2 = y2items[j];
  33475. g = y0 - ((y2 + y1) >> 2);
  33476. r = g + y2;
  33477. b = g + y1;
  33478. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  33479. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  33480. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  33481. }
  33482. }
  33483. if (fourComponents) {
  33484. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  33485. k = y3items[j];
  33486. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  33487. }
  33488. }
  33489. } else { // no multi-component transform
  33490. for (c = 0; c < componentsCount; c++) {
  33491. var items = transformedTiles[c].items;
  33492. shift = components[c].precision - 8;
  33493. offset = (128 << shift) + 0.5;
  33494. max = (127.5 * (1 << shift));
  33495. min = -max;
  33496. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  33497. val = items[j];
  33498. out[pos] = val <= min ? 0 :
  33499. val >= max ? 255 : (val + offset) >> shift;
  33500. pos += componentsCount;
  33501. }
  33502. }
  33503. }
  33504. resultImages.push(result);
  33505. }
  33506. return resultImages;
  33507. }
  33508. function initializeTile(context, tileIndex) {
  33509. var siz = context.SIZ;
  33510. var componentsCount = siz.Csiz;
  33511. var tile = context.tiles[tileIndex];
  33512. for (var c = 0; c < componentsCount; c++) {
  33513. var component = tile.components[c];
  33514. var qcdOrQcc = (c in context.currentTile.QCC ?
  33515. context.currentTile.QCC[c] : context.currentTile.QCD);
  33516. component.quantizationParameters = qcdOrQcc;
  33517. var codOrCoc = (c in context.currentTile.COC ?
  33518. context.currentTile.COC[c] : context.currentTile.COD);
  33519. component.codingStyleParameters = codOrCoc;
  33520. }
  33521. tile.codingStyleDefaultParameters = context.currentTile.COD;
  33522. }
  33523. // Section B.10.2 Tag trees
  33524. var TagTree = (function TagTreeClosure() {
  33525. function TagTree(width, height) {
  33526. var levelsLength = log2(Math.max(width, height)) + 1;
  33527. this.levels = [];
  33528. for (var i = 0; i < levelsLength; i++) {
  33529. var level = {
  33530. width: width,
  33531. height: height,
  33532. items: []
  33533. };
  33534. this.levels.push(level);
  33535. width = Math.ceil(width / 2);
  33536. height = Math.ceil(height / 2);
  33537. }
  33538. }
  33539. TagTree.prototype = {
  33540. reset: function TagTree_reset(i, j) {
  33541. var currentLevel = 0, value = 0, level;
  33542. while (currentLevel < this.levels.length) {
  33543. level = this.levels[currentLevel];
  33544. var index = i + j * level.width;
  33545. if (index in level.items) {
  33546. value = level.items[index];
  33547. break;
  33548. }
  33549. level.index = index;
  33550. i >>= 1;
  33551. j >>= 1;
  33552. currentLevel++;
  33553. }
  33554. currentLevel--;
  33555. level = this.levels[currentLevel];
  33556. level.items[level.index] = value;
  33557. this.currentLevel = currentLevel;
  33558. delete this.value;
  33559. },
  33560. incrementValue: function TagTree_incrementValue() {
  33561. var level = this.levels[this.currentLevel];
  33562. level.items[level.index]++;
  33563. },
  33564. nextLevel: function TagTree_nextLevel() {
  33565. var currentLevel = this.currentLevel;
  33566. var level = this.levels[currentLevel];
  33567. var value = level.items[level.index];
  33568. currentLevel--;
  33569. if (currentLevel < 0) {
  33570. this.value = value;
  33571. return false;
  33572. }
  33573. this.currentLevel = currentLevel;
  33574. level = this.levels[currentLevel];
  33575. level.items[level.index] = value;
  33576. return true;
  33577. }
  33578. };
  33579. return TagTree;
  33580. })();
  33581. var InclusionTree = (function InclusionTreeClosure() {
  33582. function InclusionTree(width, height, defaultValue) {
  33583. var levelsLength = log2(Math.max(width, height)) + 1;
  33584. this.levels = [];
  33585. for (var i = 0; i < levelsLength; i++) {
  33586. var items = new Uint8Array(width * height);
  33587. for (var j = 0, jj = items.length; j < jj; j++) {
  33588. items[j] = defaultValue;
  33589. }
  33590. var level = {
  33591. width: width,
  33592. height: height,
  33593. items: items
  33594. };
  33595. this.levels.push(level);
  33596. width = Math.ceil(width / 2);
  33597. height = Math.ceil(height / 2);
  33598. }
  33599. }
  33600. InclusionTree.prototype = {
  33601. reset: function InclusionTree_reset(i, j, stopValue) {
  33602. var currentLevel = 0;
  33603. while (currentLevel < this.levels.length) {
  33604. var level = this.levels[currentLevel];
  33605. var index = i + j * level.width;
  33606. level.index = index;
  33607. var value = level.items[index];
  33608. if (value === 0xFF) {
  33609. break;
  33610. }
  33611. if (value > stopValue) {
  33612. this.currentLevel = currentLevel;
  33613. // already know about this one, propagating the value to top levels
  33614. this.propagateValues();
  33615. return false;
  33616. }
  33617. i >>= 1;
  33618. j >>= 1;
  33619. currentLevel++;
  33620. }
  33621. this.currentLevel = currentLevel - 1;
  33622. return true;
  33623. },
  33624. incrementValue: function InclusionTree_incrementValue(stopValue) {
  33625. var level = this.levels[this.currentLevel];
  33626. level.items[level.index] = stopValue + 1;
  33627. this.propagateValues();
  33628. },
  33629. propagateValues: function InclusionTree_propagateValues() {
  33630. var levelIndex = this.currentLevel;
  33631. var level = this.levels[levelIndex];
  33632. var currentValue = level.items[level.index];
  33633. while (--levelIndex >= 0) {
  33634. level = this.levels[levelIndex];
  33635. level.items[level.index] = currentValue;
  33636. }
  33637. },
  33638. nextLevel: function InclusionTree_nextLevel() {
  33639. var currentLevel = this.currentLevel;
  33640. var level = this.levels[currentLevel];
  33641. var value = level.items[level.index];
  33642. level.items[level.index] = 0xFF;
  33643. currentLevel--;
  33644. if (currentLevel < 0) {
  33645. return false;
  33646. }
  33647. this.currentLevel = currentLevel;
  33648. level = this.levels[currentLevel];
  33649. level.items[level.index] = value;
  33650. return true;
  33651. }
  33652. };
  33653. return InclusionTree;
  33654. })();
  33655. // Section D. Coefficient bit modeling
  33656. var BitModel = (function BitModelClosure() {
  33657. var UNIFORM_CONTEXT = 17;
  33658. var RUNLENGTH_CONTEXT = 18;
  33659. // Table D-1
  33660. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  33661. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  33662. var LLAndLHContextsLabel = new Uint8Array([
  33663. 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,
  33664. 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,
  33665. 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
  33666. ]);
  33667. var HLContextLabel = new Uint8Array([
  33668. 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,
  33669. 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,
  33670. 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
  33671. ]);
  33672. var HHContextLabel = new Uint8Array([
  33673. 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,
  33674. 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,
  33675. 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
  33676. ]);
  33677. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  33678. this.width = width;
  33679. this.height = height;
  33680. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  33681. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  33682. var coefficientCount = width * height;
  33683. // coefficients outside the encoding region treated as insignificant
  33684. // add border state cells for significanceState
  33685. this.neighborsSignificance = new Uint8Array(coefficientCount);
  33686. this.coefficentsSign = new Uint8Array(coefficientCount);
  33687. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  33688. mb > 6 ? new Uint16Array(coefficientCount) :
  33689. new Uint8Array(coefficientCount);
  33690. this.processingFlags = new Uint8Array(coefficientCount);
  33691. var bitsDecoded = new Uint8Array(coefficientCount);
  33692. if (zeroBitPlanes !== 0) {
  33693. for (var i = 0; i < coefficientCount; i++) {
  33694. bitsDecoded[i] = zeroBitPlanes;
  33695. }
  33696. }
  33697. this.bitsDecoded = bitsDecoded;
  33698. this.reset();
  33699. }
  33700. BitModel.prototype = {
  33701. setDecoder: function BitModel_setDecoder(decoder) {
  33702. this.decoder = decoder;
  33703. },
  33704. reset: function BitModel_reset() {
  33705. // We have 17 contexts that are accessed via context labels,
  33706. // plus the uniform and runlength context.
  33707. this.contexts = new Int8Array(19);
  33708. // Contexts are packed into 1 byte:
  33709. // highest 7 bits carry the index, lowest bit carries mps
  33710. this.contexts[0] = (4 << 1) | 0;
  33711. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  33712. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  33713. },
  33714. setNeighborsSignificance:
  33715. function BitModel_setNeighborsSignificance(row, column, index) {
  33716. var neighborsSignificance = this.neighborsSignificance;
  33717. var width = this.width, height = this.height;
  33718. var left = (column > 0);
  33719. var right = (column + 1 < width);
  33720. var i;
  33721. if (row > 0) {
  33722. i = index - width;
  33723. if (left) {
  33724. neighborsSignificance[i - 1] += 0x10;
  33725. }
  33726. if (right) {
  33727. neighborsSignificance[i + 1] += 0x10;
  33728. }
  33729. neighborsSignificance[i] += 0x04;
  33730. }
  33731. if (row + 1 < height) {
  33732. i = index + width;
  33733. if (left) {
  33734. neighborsSignificance[i - 1] += 0x10;
  33735. }
  33736. if (right) {
  33737. neighborsSignificance[i + 1] += 0x10;
  33738. }
  33739. neighborsSignificance[i] += 0x04;
  33740. }
  33741. if (left) {
  33742. neighborsSignificance[index - 1] += 0x01;
  33743. }
  33744. if (right) {
  33745. neighborsSignificance[index + 1] += 0x01;
  33746. }
  33747. neighborsSignificance[index] |= 0x80;
  33748. },
  33749. runSignificancePropogationPass:
  33750. function BitModel_runSignificancePropogationPass() {
  33751. var decoder = this.decoder;
  33752. var width = this.width, height = this.height;
  33753. var coefficentsMagnitude = this.coefficentsMagnitude;
  33754. var coefficentsSign = this.coefficentsSign;
  33755. var neighborsSignificance = this.neighborsSignificance;
  33756. var processingFlags = this.processingFlags;
  33757. var contexts = this.contexts;
  33758. var labels = this.contextLabelTable;
  33759. var bitsDecoded = this.bitsDecoded;
  33760. var processedInverseMask = ~1;
  33761. var processedMask = 1;
  33762. var firstMagnitudeBitMask = 2;
  33763. for (var i0 = 0; i0 < height; i0 += 4) {
  33764. for (var j = 0; j < width; j++) {
  33765. var index = i0 * width + j;
  33766. for (var i1 = 0; i1 < 4; i1++, index += width) {
  33767. var i = i0 + i1;
  33768. if (i >= height) {
  33769. break;
  33770. }
  33771. // clear processed flag first
  33772. processingFlags[index] &= processedInverseMask;
  33773. if (coefficentsMagnitude[index] ||
  33774. !neighborsSignificance[index]) {
  33775. continue;
  33776. }
  33777. var contextLabel = labels[neighborsSignificance[index]];
  33778. var decision = decoder.readBit(contexts, contextLabel);
  33779. if (decision) {
  33780. var sign = this.decodeSignBit(i, j, index);
  33781. coefficentsSign[index] = sign;
  33782. coefficentsMagnitude[index] = 1;
  33783. this.setNeighborsSignificance(i, j, index);
  33784. processingFlags[index] |= firstMagnitudeBitMask;
  33785. }
  33786. bitsDecoded[index]++;
  33787. processingFlags[index] |= processedMask;
  33788. }
  33789. }
  33790. }
  33791. },
  33792. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  33793. var width = this.width, height = this.height;
  33794. var coefficentsMagnitude = this.coefficentsMagnitude;
  33795. var coefficentsSign = this.coefficentsSign;
  33796. var contribution, sign0, sign1, significance1;
  33797. var contextLabel, decoded;
  33798. // calculate horizontal contribution
  33799. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  33800. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  33801. sign1 = coefficentsSign[index + 1];
  33802. if (significance1) {
  33803. sign0 = coefficentsSign[index - 1];
  33804. contribution = 1 - sign1 - sign0;
  33805. } else {
  33806. contribution = 1 - sign1 - sign1;
  33807. }
  33808. } else if (significance1) {
  33809. sign0 = coefficentsSign[index - 1];
  33810. contribution = 1 - sign0 - sign0;
  33811. } else {
  33812. contribution = 0;
  33813. }
  33814. var horizontalContribution = 3 * contribution;
  33815. // calculate vertical contribution and combine with the horizontal
  33816. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  33817. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  33818. sign1 = coefficentsSign[index + width];
  33819. if (significance1) {
  33820. sign0 = coefficentsSign[index - width];
  33821. contribution = 1 - sign1 - sign0 + horizontalContribution;
  33822. } else {
  33823. contribution = 1 - sign1 - sign1 + horizontalContribution;
  33824. }
  33825. } else if (significance1) {
  33826. sign0 = coefficentsSign[index - width];
  33827. contribution = 1 - sign0 - sign0 + horizontalContribution;
  33828. } else {
  33829. contribution = horizontalContribution;
  33830. }
  33831. if (contribution >= 0) {
  33832. contextLabel = 9 + contribution;
  33833. decoded = this.decoder.readBit(this.contexts, contextLabel);
  33834. } else {
  33835. contextLabel = 9 - contribution;
  33836. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  33837. }
  33838. return decoded;
  33839. },
  33840. runMagnitudeRefinementPass:
  33841. function BitModel_runMagnitudeRefinementPass() {
  33842. var decoder = this.decoder;
  33843. var width = this.width, height = this.height;
  33844. var coefficentsMagnitude = this.coefficentsMagnitude;
  33845. var neighborsSignificance = this.neighborsSignificance;
  33846. var contexts = this.contexts;
  33847. var bitsDecoded = this.bitsDecoded;
  33848. var processingFlags = this.processingFlags;
  33849. var processedMask = 1;
  33850. var firstMagnitudeBitMask = 2;
  33851. var length = width * height;
  33852. var width4 = width * 4;
  33853. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  33854. indexNext = Math.min(length, index0 + width4);
  33855. for (var j = 0; j < width; j++) {
  33856. for (var index = index0 + j; index < indexNext; index += width) {
  33857. // significant but not those that have just become
  33858. if (!coefficentsMagnitude[index] ||
  33859. (processingFlags[index] & processedMask) !== 0) {
  33860. continue;
  33861. }
  33862. var contextLabel = 16;
  33863. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  33864. processingFlags[index] ^= firstMagnitudeBitMask;
  33865. // first refinement
  33866. var significance = neighborsSignificance[index] & 127;
  33867. contextLabel = significance === 0 ? 15 : 14;
  33868. }
  33869. var bit = decoder.readBit(contexts, contextLabel);
  33870. coefficentsMagnitude[index] =
  33871. (coefficentsMagnitude[index] << 1) | bit;
  33872. bitsDecoded[index]++;
  33873. processingFlags[index] |= processedMask;
  33874. }
  33875. }
  33876. }
  33877. },
  33878. runCleanupPass: function BitModel_runCleanupPass() {
  33879. var decoder = this.decoder;
  33880. var width = this.width, height = this.height;
  33881. var neighborsSignificance = this.neighborsSignificance;
  33882. var coefficentsMagnitude = this.coefficentsMagnitude;
  33883. var coefficentsSign = this.coefficentsSign;
  33884. var contexts = this.contexts;
  33885. var labels = this.contextLabelTable;
  33886. var bitsDecoded = this.bitsDecoded;
  33887. var processingFlags = this.processingFlags;
  33888. var processedMask = 1;
  33889. var firstMagnitudeBitMask = 2;
  33890. var oneRowDown = width;
  33891. var twoRowsDown = width * 2;
  33892. var threeRowsDown = width * 3;
  33893. var iNext;
  33894. for (var i0 = 0; i0 < height; i0 = iNext) {
  33895. iNext = Math.min(i0 + 4, height);
  33896. var indexBase = i0 * width;
  33897. var checkAllEmpty = i0 + 3 < height;
  33898. for (var j = 0; j < width; j++) {
  33899. var index0 = indexBase + j;
  33900. // using the property: labels[neighborsSignificance[index]] === 0
  33901. // when neighborsSignificance[index] === 0
  33902. var allEmpty = (checkAllEmpty &&
  33903. processingFlags[index0] === 0 &&
  33904. processingFlags[index0 + oneRowDown] === 0 &&
  33905. processingFlags[index0 + twoRowsDown] === 0 &&
  33906. processingFlags[index0 + threeRowsDown] === 0 &&
  33907. neighborsSignificance[index0] === 0 &&
  33908. neighborsSignificance[index0 + oneRowDown] === 0 &&
  33909. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  33910. neighborsSignificance[index0 + threeRowsDown] === 0);
  33911. var i1 = 0, index = index0;
  33912. var i = i0, sign;
  33913. if (allEmpty) {
  33914. var hasSignificantCoefficent =
  33915. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  33916. if (!hasSignificantCoefficent) {
  33917. bitsDecoded[index0]++;
  33918. bitsDecoded[index0 + oneRowDown]++;
  33919. bitsDecoded[index0 + twoRowsDown]++;
  33920. bitsDecoded[index0 + threeRowsDown]++;
  33921. continue; // next column
  33922. }
  33923. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33924. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33925. if (i1 !== 0) {
  33926. i = i0 + i1;
  33927. index += i1 * width;
  33928. }
  33929. sign = this.decodeSignBit(i, j, index);
  33930. coefficentsSign[index] = sign;
  33931. coefficentsMagnitude[index] = 1;
  33932. this.setNeighborsSignificance(i, j, index);
  33933. processingFlags[index] |= firstMagnitudeBitMask;
  33934. index = index0;
  33935. for (var i2 = i0; i2 <= i; i2++, index += width) {
  33936. bitsDecoded[index]++;
  33937. }
  33938. i1++;
  33939. }
  33940. for (i = i0 + i1; i < iNext; i++, index += width) {
  33941. if (coefficentsMagnitude[index] ||
  33942. (processingFlags[index] & processedMask) !== 0) {
  33943. continue;
  33944. }
  33945. var contextLabel = labels[neighborsSignificance[index]];
  33946. var decision = decoder.readBit(contexts, contextLabel);
  33947. if (decision === 1) {
  33948. sign = this.decodeSignBit(i, j, index);
  33949. coefficentsSign[index] = sign;
  33950. coefficentsMagnitude[index] = 1;
  33951. this.setNeighborsSignificance(i, j, index);
  33952. processingFlags[index] |= firstMagnitudeBitMask;
  33953. }
  33954. bitsDecoded[index]++;
  33955. }
  33956. }
  33957. }
  33958. },
  33959. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  33960. var decoder = this.decoder;
  33961. var contexts = this.contexts;
  33962. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  33963. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  33964. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33965. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33966. if (symbol !== 0xA) {
  33967. throw new Error('JPX Error: Invalid segmentation symbol');
  33968. }
  33969. }
  33970. };
  33971. return BitModel;
  33972. })();
  33973. // Section F, Discrete wavelet transformation
  33974. var Transform = (function TransformClosure() {
  33975. function Transform() {}
  33976. Transform.prototype.calculate =
  33977. function transformCalculate(subbands, u0, v0) {
  33978. var ll = subbands[0];
  33979. for (var i = 1, ii = subbands.length; i < ii; i++) {
  33980. ll = this.iterate(ll, subbands[i], u0, v0);
  33981. }
  33982. return ll;
  33983. };
  33984. Transform.prototype.extend = function extend(buffer, offset, size) {
  33985. // Section F.3.7 extending... using max extension of 4
  33986. var i1 = offset - 1, j1 = offset + 1;
  33987. var i2 = offset + size - 2, j2 = offset + size;
  33988. buffer[i1--] = buffer[j1++];
  33989. buffer[j2++] = buffer[i2--];
  33990. buffer[i1--] = buffer[j1++];
  33991. buffer[j2++] = buffer[i2--];
  33992. buffer[i1--] = buffer[j1++];
  33993. buffer[j2++] = buffer[i2--];
  33994. buffer[i1] = buffer[j1];
  33995. buffer[j2] = buffer[i2];
  33996. };
  33997. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  33998. u0, v0) {
  33999. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  34000. var width = hl_lh_hh.width;
  34001. var height = hl_lh_hh.height;
  34002. var items = hl_lh_hh.items;
  34003. var i, j, k, l, u, v;
  34004. // Interleave LL according to Section F.3.3
  34005. for (k = 0, i = 0; i < llHeight; i++) {
  34006. l = i * 2 * width;
  34007. for (j = 0; j < llWidth; j++, k++, l += 2) {
  34008. items[l] = llItems[k];
  34009. }
  34010. }
  34011. // The LL band is not needed anymore.
  34012. llItems = ll.items = null;
  34013. var bufferPadding = 4;
  34014. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  34015. // Section F.3.4 HOR_SR
  34016. if (width === 1) {
  34017. // if width = 1, when u0 even keep items as is, when odd divide by 2
  34018. if ((u0 & 1) !== 0) {
  34019. for (v = 0, k = 0; v < height; v++, k += width) {
  34020. items[k] *= 0.5;
  34021. }
  34022. }
  34023. } else {
  34024. for (v = 0, k = 0; v < height; v++, k += width) {
  34025. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  34026. this.extend(rowBuffer, bufferPadding, width);
  34027. this.filter(rowBuffer, bufferPadding, width);
  34028. items.set(
  34029. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  34030. k);
  34031. }
  34032. }
  34033. // Accesses to the items array can take long, because it may not fit into
  34034. // CPU cache and has to be fetched from main memory. Since subsequent
  34035. // accesses to the items array are not local when reading columns, we
  34036. // have a cache miss every time. To reduce cache misses, get up to
  34037. // 'numBuffers' items at a time and store them into the individual
  34038. // buffers. The colBuffers should be small enough to fit into CPU cache.
  34039. var numBuffers = 16;
  34040. var colBuffers = [];
  34041. for (i = 0; i < numBuffers; i++) {
  34042. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  34043. }
  34044. var b, currentBuffer = 0;
  34045. ll = bufferPadding + height;
  34046. // Section F.3.5 VER_SR
  34047. if (height === 1) {
  34048. // if height = 1, when v0 even keep items as is, when odd divide by 2
  34049. if ((v0 & 1) !== 0) {
  34050. for (u = 0; u < width; u++) {
  34051. items[u] *= 0.5;
  34052. }
  34053. }
  34054. } else {
  34055. for (u = 0; u < width; u++) {
  34056. // if we ran out of buffers, copy several image columns at once
  34057. if (currentBuffer === 0) {
  34058. numBuffers = Math.min(width - u, numBuffers);
  34059. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  34060. for (b = 0; b < numBuffers; b++) {
  34061. colBuffers[b][l] = items[k + b];
  34062. }
  34063. }
  34064. currentBuffer = numBuffers;
  34065. }
  34066. currentBuffer--;
  34067. var buffer = colBuffers[currentBuffer];
  34068. this.extend(buffer, bufferPadding, height);
  34069. this.filter(buffer, bufferPadding, height);
  34070. // If this is last buffer in this group of buffers, flush all buffers.
  34071. if (currentBuffer === 0) {
  34072. k = u - numBuffers + 1;
  34073. for (l = bufferPadding; l < ll; k += width, l++) {
  34074. for (b = 0; b < numBuffers; b++) {
  34075. items[k + b] = colBuffers[b][l];
  34076. }
  34077. }
  34078. }
  34079. }
  34080. }
  34081. return {
  34082. width: width,
  34083. height: height,
  34084. items: items
  34085. };
  34086. };
  34087. return Transform;
  34088. })();
  34089. // Section 3.8.2 Irreversible 9-7 filter
  34090. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  34091. function IrreversibleTransform() {
  34092. Transform.call(this);
  34093. }
  34094. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  34095. IrreversibleTransform.prototype.filter =
  34096. function irreversibleTransformFilter(x, offset, length) {
  34097. var len = length >> 1;
  34098. offset = offset | 0;
  34099. var j, n, current, next;
  34100. var alpha = -1.586134342059924;
  34101. var beta = -0.052980118572961;
  34102. var gamma = 0.882911075530934;
  34103. var delta = 0.443506852043971;
  34104. var K = 1.230174104914001;
  34105. var K_ = 1 / K;
  34106. // step 1 is combined with step 3
  34107. // step 2
  34108. j = offset - 3;
  34109. for (n = len + 4; n--; j += 2) {
  34110. x[j] *= K_;
  34111. }
  34112. // step 1 & 3
  34113. j = offset - 2;
  34114. current = delta * x[j -1];
  34115. for (n = len + 3; n--; j += 2) {
  34116. next = delta * x[j + 1];
  34117. x[j] = K * x[j] - current - next;
  34118. if (n--) {
  34119. j += 2;
  34120. current = delta * x[j + 1];
  34121. x[j] = K * x[j] - current - next;
  34122. } else {
  34123. break;
  34124. }
  34125. }
  34126. // step 4
  34127. j = offset - 1;
  34128. current = gamma * x[j - 1];
  34129. for (n = len + 2; n--; j += 2) {
  34130. next = gamma * x[j + 1];
  34131. x[j] -= current + next;
  34132. if (n--) {
  34133. j += 2;
  34134. current = gamma * x[j + 1];
  34135. x[j] -= current + next;
  34136. } else {
  34137. break;
  34138. }
  34139. }
  34140. // step 5
  34141. j = offset;
  34142. current = beta * x[j - 1];
  34143. for (n = len + 1; n--; j += 2) {
  34144. next = beta * x[j + 1];
  34145. x[j] -= current + next;
  34146. if (n--) {
  34147. j += 2;
  34148. current = beta * x[j + 1];
  34149. x[j] -= current + next;
  34150. } else {
  34151. break;
  34152. }
  34153. }
  34154. // step 6
  34155. if (len !== 0) {
  34156. j = offset + 1;
  34157. current = alpha * x[j - 1];
  34158. for (n = len; n--; j += 2) {
  34159. next = alpha * x[j + 1];
  34160. x[j] -= current + next;
  34161. if (n--) {
  34162. j += 2;
  34163. current = alpha * x[j + 1];
  34164. x[j] -= current + next;
  34165. } else {
  34166. break;
  34167. }
  34168. }
  34169. }
  34170. };
  34171. return IrreversibleTransform;
  34172. })();
  34173. // Section 3.8.1 Reversible 5-3 filter
  34174. var ReversibleTransform = (function ReversibleTransformClosure() {
  34175. function ReversibleTransform() {
  34176. Transform.call(this);
  34177. }
  34178. ReversibleTransform.prototype = Object.create(Transform.prototype);
  34179. ReversibleTransform.prototype.filter =
  34180. function reversibleTransformFilter(x, offset, length) {
  34181. var len = length >> 1;
  34182. offset = offset | 0;
  34183. var j, n;
  34184. for (j = offset, n = len + 1; n--; j += 2) {
  34185. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  34186. }
  34187. for (j = offset + 1, n = len; n--; j += 2) {
  34188. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  34189. }
  34190. };
  34191. return ReversibleTransform;
  34192. })();
  34193. return JpxImage;
  34194. })();
  34195. var Jbig2Image = (function Jbig2ImageClosure() {
  34196. // Utility data structures
  34197. function ContextCache() {}
  34198. ContextCache.prototype = {
  34199. getContexts: function(id) {
  34200. if (id in this) {
  34201. return this[id];
  34202. }
  34203. return (this[id] = new Int8Array(1 << 16));
  34204. }
  34205. };
  34206. function DecodingContext(data, start, end) {
  34207. this.data = data;
  34208. this.start = start;
  34209. this.end = end;
  34210. }
  34211. DecodingContext.prototype = {
  34212. get decoder() {
  34213. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  34214. return shadow(this, 'decoder', decoder);
  34215. },
  34216. get contextCache() {
  34217. var cache = new ContextCache();
  34218. return shadow(this, 'contextCache', cache);
  34219. }
  34220. };
  34221. // Annex A. Arithmetic Integer Decoding Procedure
  34222. // A.2 Procedure for decoding values
  34223. function decodeInteger(contextCache, procedure, decoder) {
  34224. var contexts = contextCache.getContexts(procedure);
  34225. var prev = 1;
  34226. function readBits(length) {
  34227. var v = 0;
  34228. for (var i = 0; i < length; i++) {
  34229. var bit = decoder.readBit(contexts, prev);
  34230. prev = (prev < 256 ? (prev << 1) | bit :
  34231. (((prev << 1) | bit) & 511) | 256);
  34232. v = (v << 1) | bit;
  34233. }
  34234. return v >>> 0;
  34235. }
  34236. var sign = readBits(1);
  34237. var value = readBits(1) ?
  34238. (readBits(1) ?
  34239. (readBits(1) ?
  34240. (readBits(1) ?
  34241. (readBits(1) ?
  34242. (readBits(32) + 4436) :
  34243. readBits(12) + 340) :
  34244. readBits(8) + 84) :
  34245. readBits(6) + 20) :
  34246. readBits(4) + 4) :
  34247. readBits(2);
  34248. return (sign === 0 ? value : (value > 0 ? -value : null));
  34249. }
  34250. // A.3 The IAID decoding procedure
  34251. function decodeIAID(contextCache, decoder, codeLength) {
  34252. var contexts = contextCache.getContexts('IAID');
  34253. var prev = 1;
  34254. for (var i = 0; i < codeLength; i++) {
  34255. var bit = decoder.readBit(contexts, prev);
  34256. prev = (prev << 1) | bit;
  34257. }
  34258. if (codeLength < 31) {
  34259. return prev & ((1 << codeLength) - 1);
  34260. }
  34261. return prev & 0x7FFFFFFF;
  34262. }
  34263. // 7.3 Segment types
  34264. var SegmentTypes = [
  34265. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  34266. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  34267. null, null, null, null, null, 'patternDictionary', null, null, null,
  34268. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  34269. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  34270. null, null, null, null, null, 'IntermediateGenericRegion', null,
  34271. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  34272. 'IntermediateGenericRefinementRegion', null,
  34273. 'ImmediateGenericRefinementRegion',
  34274. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  34275. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  34276. 'Tables', null, null, null, null, null, null, null, null,
  34277. 'Extension'
  34278. ];
  34279. var CodingTemplates = [
  34280. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34281. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  34282. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34283. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  34284. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  34285. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  34286. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  34287. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  34288. {x: -1, y: 0}],
  34289. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  34290. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  34291. ];
  34292. var RefinementTemplates = [
  34293. {
  34294. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34295. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  34296. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  34297. },
  34298. {
  34299. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  34300. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  34301. {x: 0, y: 1}, {x: 1, y: 1}]
  34302. }
  34303. ];
  34304. // See 6.2.5.7 Decoding the bitmap.
  34305. var ReusedContexts = [
  34306. 0x9B25, // 10011 0110010 0101
  34307. 0x0795, // 0011 110010 101
  34308. 0x00E5, // 001 11001 01
  34309. 0x0195 // 011001 0101
  34310. ];
  34311. var RefinementReusedContexts = [
  34312. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  34313. 0x0008 // '0000' + '001000'
  34314. ];
  34315. function decodeBitmapTemplate0(width, height, decodingContext) {
  34316. var decoder = decodingContext.decoder;
  34317. var contexts = decodingContext.contextCache.getContexts('GB');
  34318. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  34319. // ...ooooo....
  34320. // ..ooooooo... Context template for current pixel (X)
  34321. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  34322. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  34323. for (i = 0; i < height; i++) {
  34324. row = bitmap[i] = new Uint8Array(width);
  34325. row1 = (i < 1) ? row : bitmap[i - 1];
  34326. row2 = (i < 2) ? row : bitmap[i - 2];
  34327. // At the beginning of each row:
  34328. // Fill contextLabel with pixels that are above/right of (X)
  34329. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  34330. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  34331. (row1[3] << 4);
  34332. for (j = 0; j < width; j++) {
  34333. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  34334. // At each pixel: Clear contextLabel pixels that are shifted
  34335. // out of the context, then add new ones.
  34336. // If j + n is out of range at the right image border, then
  34337. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  34338. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  34339. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  34340. }
  34341. }
  34342. return bitmap;
  34343. }
  34344. // 6.2 Generic Region Decoding Procedure
  34345. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  34346. decodingContext) {
  34347. if (mmr) {
  34348. error('JBIG2 error: MMR encoding is not supported');
  34349. }
  34350. // Use optimized version for the most common case
  34351. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  34352. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  34353. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  34354. return decodeBitmapTemplate0(width, height, decodingContext);
  34355. }
  34356. var useskip = !!skip;
  34357. var template = CodingTemplates[templateIndex].concat(at);
  34358. // Sorting is non-standard, and it is not required. But sorting increases
  34359. // the number of template bits that can be reused from the previous
  34360. // contextLabel in the main loop.
  34361. template.sort(function (a, b) {
  34362. return (a.y - b.y) || (a.x - b.x);
  34363. });
  34364. var templateLength = template.length;
  34365. var templateX = new Int8Array(templateLength);
  34366. var templateY = new Int8Array(templateLength);
  34367. var changingTemplateEntries = [];
  34368. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  34369. var c, k;
  34370. for (k = 0; k < templateLength; k++) {
  34371. templateX[k] = template[k].x;
  34372. templateY[k] = template[k].y;
  34373. minX = Math.min(minX, template[k].x);
  34374. maxX = Math.max(maxX, template[k].x);
  34375. minY = Math.min(minY, template[k].y);
  34376. // Check if the template pixel appears in two consecutive context labels,
  34377. // so it can be reused. Otherwise, we add it to the list of changing
  34378. // template entries.
  34379. if (k < templateLength - 1 &&
  34380. template[k].y === template[k + 1].y &&
  34381. template[k].x === template[k + 1].x - 1) {
  34382. reuseMask |= 1 << (templateLength - 1 - k);
  34383. } else {
  34384. changingTemplateEntries.push(k);
  34385. }
  34386. }
  34387. var changingEntriesLength = changingTemplateEntries.length;
  34388. var changingTemplateX = new Int8Array(changingEntriesLength);
  34389. var changingTemplateY = new Int8Array(changingEntriesLength);
  34390. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  34391. for (c = 0; c < changingEntriesLength; c++) {
  34392. k = changingTemplateEntries[c];
  34393. changingTemplateX[c] = template[k].x;
  34394. changingTemplateY[c] = template[k].y;
  34395. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  34396. }
  34397. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  34398. var sbb_left = -minX;
  34399. var sbb_top = -minY;
  34400. var sbb_right = width - maxX;
  34401. var pseudoPixelContext = ReusedContexts[templateIndex];
  34402. var row = new Uint8Array(width);
  34403. var bitmap = [];
  34404. var decoder = decodingContext.decoder;
  34405. var contexts = decodingContext.contextCache.getContexts('GB');
  34406. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  34407. for (var i = 0; i < height; i++) {
  34408. if (prediction) {
  34409. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34410. ltp ^= sltp;
  34411. if (ltp) {
  34412. bitmap.push(row); // duplicate previous row
  34413. continue;
  34414. }
  34415. }
  34416. row = new Uint8Array(row);
  34417. bitmap.push(row);
  34418. for (j = 0; j < width; j++) {
  34419. if (useskip && skip[i][j]) {
  34420. row[j] = 0;
  34421. continue;
  34422. }
  34423. // Are we in the middle of a scanline, so we can reuse contextLabel
  34424. // bits?
  34425. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  34426. // If yes, we can just shift the bits that are reusable and only
  34427. // fetch the remaining ones.
  34428. contextLabel = (contextLabel << 1) & reuseMask;
  34429. for (k = 0; k < changingEntriesLength; k++) {
  34430. i0 = i + changingTemplateY[k];
  34431. j0 = j + changingTemplateX[k];
  34432. bit = bitmap[i0][j0];
  34433. if (bit) {
  34434. bit = changingTemplateBit[k];
  34435. contextLabel |= bit;
  34436. }
  34437. }
  34438. } else {
  34439. // compute the contextLabel from scratch
  34440. contextLabel = 0;
  34441. shift = templateLength - 1;
  34442. for (k = 0; k < templateLength; k++, shift--) {
  34443. j0 = j + templateX[k];
  34444. if (j0 >= 0 && j0 < width) {
  34445. i0 = i + templateY[k];
  34446. if (i0 >= 0) {
  34447. bit = bitmap[i0][j0];
  34448. if (bit) {
  34449. contextLabel |= bit << shift;
  34450. }
  34451. }
  34452. }
  34453. }
  34454. }
  34455. var pixel = decoder.readBit(contexts, contextLabel);
  34456. row[j] = pixel;
  34457. }
  34458. }
  34459. return bitmap;
  34460. }
  34461. // 6.3.2 Generic Refinement Region Decoding Procedure
  34462. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  34463. offsetX, offsetY, prediction, at,
  34464. decodingContext) {
  34465. var codingTemplate = RefinementTemplates[templateIndex].coding;
  34466. if (templateIndex === 0) {
  34467. codingTemplate = codingTemplate.concat([at[0]]);
  34468. }
  34469. var codingTemplateLength = codingTemplate.length;
  34470. var codingTemplateX = new Int32Array(codingTemplateLength);
  34471. var codingTemplateY = new Int32Array(codingTemplateLength);
  34472. var k;
  34473. for (k = 0; k < codingTemplateLength; k++) {
  34474. codingTemplateX[k] = codingTemplate[k].x;
  34475. codingTemplateY[k] = codingTemplate[k].y;
  34476. }
  34477. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  34478. if (templateIndex === 0) {
  34479. referenceTemplate = referenceTemplate.concat([at[1]]);
  34480. }
  34481. var referenceTemplateLength = referenceTemplate.length;
  34482. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  34483. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  34484. for (k = 0; k < referenceTemplateLength; k++) {
  34485. referenceTemplateX[k] = referenceTemplate[k].x;
  34486. referenceTemplateY[k] = referenceTemplate[k].y;
  34487. }
  34488. var referenceWidth = referenceBitmap[0].length;
  34489. var referenceHeight = referenceBitmap.length;
  34490. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  34491. var bitmap = [];
  34492. var decoder = decodingContext.decoder;
  34493. var contexts = decodingContext.contextCache.getContexts('GR');
  34494. var ltp = 0;
  34495. for (var i = 0; i < height; i++) {
  34496. if (prediction) {
  34497. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  34498. ltp ^= sltp;
  34499. if (ltp) {
  34500. error('JBIG2 error: prediction is not supported');
  34501. }
  34502. }
  34503. var row = new Uint8Array(width);
  34504. bitmap.push(row);
  34505. for (var j = 0; j < width; j++) {
  34506. var i0, j0;
  34507. var contextLabel = 0;
  34508. for (k = 0; k < codingTemplateLength; k++) {
  34509. i0 = i + codingTemplateY[k];
  34510. j0 = j + codingTemplateX[k];
  34511. if (i0 < 0 || j0 < 0 || j0 >= width) {
  34512. contextLabel <<= 1; // out of bound pixel
  34513. } else {
  34514. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  34515. }
  34516. }
  34517. for (k = 0; k < referenceTemplateLength; k++) {
  34518. i0 = i + referenceTemplateY[k] + offsetY;
  34519. j0 = j + referenceTemplateX[k] + offsetX;
  34520. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  34521. j0 >= referenceWidth) {
  34522. contextLabel <<= 1; // out of bound pixel
  34523. } else {
  34524. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  34525. }
  34526. }
  34527. var pixel = decoder.readBit(contexts, contextLabel);
  34528. row[j] = pixel;
  34529. }
  34530. }
  34531. return bitmap;
  34532. }
  34533. // 6.5.5 Decoding the symbol dictionary
  34534. function decodeSymbolDictionary(huffman, refinement, symbols,
  34535. numberOfNewSymbols, numberOfExportedSymbols,
  34536. huffmanTables, templateIndex, at,
  34537. refinementTemplateIndex, refinementAt,
  34538. decodingContext) {
  34539. if (huffman) {
  34540. error('JBIG2 error: huffman is not supported');
  34541. }
  34542. var newSymbols = [];
  34543. var currentHeight = 0;
  34544. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  34545. var decoder = decodingContext.decoder;
  34546. var contextCache = decodingContext.contextCache;
  34547. while (newSymbols.length < numberOfNewSymbols) {
  34548. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  34549. currentHeight += deltaHeight;
  34550. var currentWidth = 0;
  34551. var totalWidth = 0;
  34552. while (true) {
  34553. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  34554. if (deltaWidth === null) {
  34555. break; // OOB
  34556. }
  34557. currentWidth += deltaWidth;
  34558. totalWidth += currentWidth;
  34559. var bitmap;
  34560. if (refinement) {
  34561. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  34562. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  34563. if (numberOfInstances > 1) {
  34564. bitmap = decodeTextRegion(huffman, refinement,
  34565. currentWidth, currentHeight, 0,
  34566. numberOfInstances, 1, //strip size
  34567. symbols.concat(newSymbols),
  34568. symbolCodeLength,
  34569. 0, //transposed
  34570. 0, //ds offset
  34571. 1, //top left 7.4.3.1.1
  34572. 0, //OR operator
  34573. huffmanTables,
  34574. refinementTemplateIndex, refinementAt,
  34575. decodingContext);
  34576. } else {
  34577. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34578. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34579. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34580. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  34581. newSymbols[symbolId - symbols.length]);
  34582. bitmap = decodeRefinement(currentWidth, currentHeight,
  34583. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  34584. decodingContext);
  34585. }
  34586. } else {
  34587. // 6.5.8.1 Direct-coded symbol bitmap
  34588. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  34589. templateIndex, false, null, at, decodingContext);
  34590. }
  34591. newSymbols.push(bitmap);
  34592. }
  34593. }
  34594. // 6.5.10 Exported symbols
  34595. var exportedSymbols = [];
  34596. var flags = [], currentFlag = false;
  34597. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  34598. while (flags.length < totalSymbolsLength) {
  34599. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  34600. while (runLength--) {
  34601. flags.push(currentFlag);
  34602. }
  34603. currentFlag = !currentFlag;
  34604. }
  34605. for (var i = 0, ii = symbols.length; i < ii; i++) {
  34606. if (flags[i]) {
  34607. exportedSymbols.push(symbols[i]);
  34608. }
  34609. }
  34610. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  34611. if (flags[i]) {
  34612. exportedSymbols.push(newSymbols[j]);
  34613. }
  34614. }
  34615. return exportedSymbols;
  34616. }
  34617. function decodeTextRegion(huffman, refinement, width, height,
  34618. defaultPixelValue, numberOfSymbolInstances,
  34619. stripSize, inputSymbols, symbolCodeLength,
  34620. transposed, dsOffset, referenceCorner,
  34621. combinationOperator, huffmanTables,
  34622. refinementTemplateIndex, refinementAt,
  34623. decodingContext) {
  34624. if (huffman) {
  34625. error('JBIG2 error: huffman is not supported');
  34626. }
  34627. // Prepare bitmap
  34628. var bitmap = [];
  34629. var i, row;
  34630. for (i = 0; i < height; i++) {
  34631. row = new Uint8Array(width);
  34632. if (defaultPixelValue) {
  34633. for (var j = 0; j < width; j++) {
  34634. row[j] = defaultPixelValue;
  34635. }
  34636. }
  34637. bitmap.push(row);
  34638. }
  34639. var decoder = decodingContext.decoder;
  34640. var contextCache = decodingContext.contextCache;
  34641. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34642. var firstS = 0;
  34643. i = 0;
  34644. while (i < numberOfSymbolInstances) {
  34645. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  34646. stripT += deltaT;
  34647. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  34648. firstS += deltaFirstS;
  34649. var currentS = firstS;
  34650. do {
  34651. var currentT = (stripSize === 1 ? 0 :
  34652. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  34653. var t = stripSize * stripT + currentT;
  34654. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  34655. var applyRefinement = (refinement &&
  34656. decodeInteger(contextCache, 'IARI', decoder));
  34657. var symbolBitmap = inputSymbols[symbolId];
  34658. var symbolWidth = symbolBitmap[0].length;
  34659. var symbolHeight = symbolBitmap.length;
  34660. if (applyRefinement) {
  34661. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  34662. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  34663. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  34664. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  34665. symbolWidth += rdw;
  34666. symbolHeight += rdh;
  34667. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  34668. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  34669. (rdh >> 1) + rdy, false, refinementAt,
  34670. decodingContext);
  34671. }
  34672. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  34673. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  34674. var s2, t2, symbolRow;
  34675. if (transposed) {
  34676. // Place Symbol Bitmap from T1,S1
  34677. for (s2 = 0; s2 < symbolHeight; s2++) {
  34678. row = bitmap[offsetS + s2];
  34679. if (!row) {
  34680. continue;
  34681. }
  34682. symbolRow = symbolBitmap[s2];
  34683. // To ignore Parts of Symbol bitmap which goes
  34684. // outside bitmap region
  34685. var maxWidth = Math.min(width - offsetT, symbolWidth);
  34686. switch (combinationOperator) {
  34687. case 0: // OR
  34688. for (t2 = 0; t2 < maxWidth; t2++) {
  34689. row[offsetT + t2] |= symbolRow[t2];
  34690. }
  34691. break;
  34692. case 2: // XOR
  34693. for (t2 = 0; t2 < maxWidth; t2++) {
  34694. row[offsetT + t2] ^= symbolRow[t2];
  34695. }
  34696. break;
  34697. default:
  34698. error('JBIG2 error: operator ' + combinationOperator +
  34699. ' is not supported');
  34700. }
  34701. }
  34702. currentS += symbolHeight - 1;
  34703. } else {
  34704. for (t2 = 0; t2 < symbolHeight; t2++) {
  34705. row = bitmap[offsetT + t2];
  34706. if (!row) {
  34707. continue;
  34708. }
  34709. symbolRow = symbolBitmap[t2];
  34710. switch (combinationOperator) {
  34711. case 0: // OR
  34712. for (s2 = 0; s2 < symbolWidth; s2++) {
  34713. row[offsetS + s2] |= symbolRow[s2];
  34714. }
  34715. break;
  34716. case 2: // XOR
  34717. for (s2 = 0; s2 < symbolWidth; s2++) {
  34718. row[offsetS + s2] ^= symbolRow[s2];
  34719. }
  34720. break;
  34721. default:
  34722. error('JBIG2 error: operator ' + combinationOperator +
  34723. ' is not supported');
  34724. }
  34725. }
  34726. currentS += symbolWidth - 1;
  34727. }
  34728. i++;
  34729. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  34730. if (deltaS === null) {
  34731. break; // OOB
  34732. }
  34733. currentS += deltaS + dsOffset;
  34734. } while (true);
  34735. }
  34736. return bitmap;
  34737. }
  34738. function readSegmentHeader(data, start) {
  34739. var segmentHeader = {};
  34740. segmentHeader.number = readUint32(data, start);
  34741. var flags = data[start + 4];
  34742. var segmentType = flags & 0x3F;
  34743. if (!SegmentTypes[segmentType]) {
  34744. error('JBIG2 error: invalid segment type: ' + segmentType);
  34745. }
  34746. segmentHeader.type = segmentType;
  34747. segmentHeader.typeName = SegmentTypes[segmentType];
  34748. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  34749. var pageAssociationFieldSize = !!(flags & 0x40);
  34750. var referredFlags = data[start + 5];
  34751. var referredToCount = (referredFlags >> 5) & 7;
  34752. var retainBits = [referredFlags & 31];
  34753. var position = start + 6;
  34754. if (referredFlags === 7) {
  34755. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  34756. position += 3;
  34757. var bytes = (referredToCount + 7) >> 3;
  34758. retainBits[0] = data[position++];
  34759. while (--bytes > 0) {
  34760. retainBits.push(data[position++]);
  34761. }
  34762. } else if (referredFlags === 5 || referredFlags === 6) {
  34763. error('JBIG2 error: invalid referred-to flags');
  34764. }
  34765. segmentHeader.retainBits = retainBits;
  34766. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  34767. (segmentHeader.number <= 65536 ? 2 : 4));
  34768. var referredTo = [];
  34769. var i, ii;
  34770. for (i = 0; i < referredToCount; i++) {
  34771. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  34772. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  34773. readUint32(data, position)));
  34774. referredTo.push(number);
  34775. position += referredToSegmentNumberSize;
  34776. }
  34777. segmentHeader.referredTo = referredTo;
  34778. if (!pageAssociationFieldSize) {
  34779. segmentHeader.pageAssociation = data[position++];
  34780. } else {
  34781. segmentHeader.pageAssociation = readUint32(data, position);
  34782. position += 4;
  34783. }
  34784. segmentHeader.length = readUint32(data, position);
  34785. position += 4;
  34786. if (segmentHeader.length === 0xFFFFFFFF) {
  34787. // 7.2.7 Segment data length, unknown segment length
  34788. if (segmentType === 38) { // ImmediateGenericRegion
  34789. var genericRegionInfo = readRegionSegmentInformation(data, position);
  34790. var genericRegionSegmentFlags = data[position +
  34791. RegionSegmentInformationFieldLength];
  34792. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  34793. // searching for the segment end
  34794. var searchPatternLength = 6;
  34795. var searchPattern = new Uint8Array(searchPatternLength);
  34796. if (!genericRegionMmr) {
  34797. searchPattern[0] = 0xFF;
  34798. searchPattern[1] = 0xAC;
  34799. }
  34800. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  34801. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  34802. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  34803. searchPattern[5] = genericRegionInfo.height & 0xFF;
  34804. for (i = position, ii = data.length; i < ii; i++) {
  34805. var j = 0;
  34806. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  34807. j++;
  34808. }
  34809. if (j === searchPatternLength) {
  34810. segmentHeader.length = i + searchPatternLength;
  34811. break;
  34812. }
  34813. }
  34814. if (segmentHeader.length === 0xFFFFFFFF) {
  34815. error('JBIG2 error: segment end was not found');
  34816. }
  34817. } else {
  34818. error('JBIG2 error: invalid unknown segment length');
  34819. }
  34820. }
  34821. segmentHeader.headerEnd = position;
  34822. return segmentHeader;
  34823. }
  34824. function readSegments(header, data, start, end) {
  34825. var segments = [];
  34826. var position = start;
  34827. while (position < end) {
  34828. var segmentHeader = readSegmentHeader(data, position);
  34829. position = segmentHeader.headerEnd;
  34830. var segment = {
  34831. header: segmentHeader,
  34832. data: data
  34833. };
  34834. if (!header.randomAccess) {
  34835. segment.start = position;
  34836. position += segmentHeader.length;
  34837. segment.end = position;
  34838. }
  34839. segments.push(segment);
  34840. if (segmentHeader.type === 51) {
  34841. break; // end of file is found
  34842. }
  34843. }
  34844. if (header.randomAccess) {
  34845. for (var i = 0, ii = segments.length; i < ii; i++) {
  34846. segments[i].start = position;
  34847. position += segments[i].header.length;
  34848. segments[i].end = position;
  34849. }
  34850. }
  34851. return segments;
  34852. }
  34853. // 7.4.1 Region segment information field
  34854. function readRegionSegmentInformation(data, start) {
  34855. return {
  34856. width: readUint32(data, start),
  34857. height: readUint32(data, start + 4),
  34858. x: readUint32(data, start + 8),
  34859. y: readUint32(data, start + 12),
  34860. combinationOperator: data[start + 16] & 7
  34861. };
  34862. }
  34863. var RegionSegmentInformationFieldLength = 17;
  34864. function processSegment(segment, visitor) {
  34865. var header = segment.header;
  34866. var data = segment.data, position = segment.start, end = segment.end;
  34867. var args, at, i, atLength;
  34868. switch (header.type) {
  34869. case 0: // SymbolDictionary
  34870. // 7.4.2 Symbol dictionary segment syntax
  34871. var dictionary = {};
  34872. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  34873. dictionary.huffman = !!(dictionaryFlags & 1);
  34874. dictionary.refinement = !!(dictionaryFlags & 2);
  34875. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  34876. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  34877. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  34878. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  34879. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  34880. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  34881. dictionary.template = (dictionaryFlags >> 10) & 3;
  34882. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  34883. position += 2;
  34884. if (!dictionary.huffman) {
  34885. atLength = dictionary.template === 0 ? 4 : 1;
  34886. at = [];
  34887. for (i = 0; i < atLength; i++) {
  34888. at.push({
  34889. x: readInt8(data, position),
  34890. y: readInt8(data, position + 1)
  34891. });
  34892. position += 2;
  34893. }
  34894. dictionary.at = at;
  34895. }
  34896. if (dictionary.refinement && !dictionary.refinementTemplate) {
  34897. at = [];
  34898. for (i = 0; i < 2; i++) {
  34899. at.push({
  34900. x: readInt8(data, position),
  34901. y: readInt8(data, position + 1)
  34902. });
  34903. position += 2;
  34904. }
  34905. dictionary.refinementAt = at;
  34906. }
  34907. dictionary.numberOfExportedSymbols = readUint32(data, position);
  34908. position += 4;
  34909. dictionary.numberOfNewSymbols = readUint32(data, position);
  34910. position += 4;
  34911. args = [dictionary, header.number, header.referredTo,
  34912. data, position, end];
  34913. break;
  34914. case 6: // ImmediateTextRegion
  34915. case 7: // ImmediateLosslessTextRegion
  34916. var textRegion = {};
  34917. textRegion.info = readRegionSegmentInformation(data, position);
  34918. position += RegionSegmentInformationFieldLength;
  34919. var textRegionSegmentFlags = readUint16(data, position);
  34920. position += 2;
  34921. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  34922. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  34923. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  34924. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  34925. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  34926. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  34927. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  34928. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  34929. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  34930. if (textRegion.huffman) {
  34931. var textRegionHuffmanFlags = readUint16(data, position);
  34932. position += 2;
  34933. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  34934. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  34935. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  34936. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  34937. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  34938. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  34939. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  34940. textRegion.huffmanRefinementSizeSelector =
  34941. !!(textRegionHuffmanFlags & 14);
  34942. }
  34943. if (textRegion.refinement && !textRegion.refinementTemplate) {
  34944. at = [];
  34945. for (i = 0; i < 2; i++) {
  34946. at.push({
  34947. x: readInt8(data, position),
  34948. y: readInt8(data, position + 1)
  34949. });
  34950. position += 2;
  34951. }
  34952. textRegion.refinementAt = at;
  34953. }
  34954. textRegion.numberOfSymbolInstances = readUint32(data, position);
  34955. position += 4;
  34956. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  34957. if (textRegion.huffman) {
  34958. error('JBIG2 error: huffman is not supported');
  34959. }
  34960. args = [textRegion, header.referredTo, data, position, end];
  34961. break;
  34962. case 38: // ImmediateGenericRegion
  34963. case 39: // ImmediateLosslessGenericRegion
  34964. var genericRegion = {};
  34965. genericRegion.info = readRegionSegmentInformation(data, position);
  34966. position += RegionSegmentInformationFieldLength;
  34967. var genericRegionSegmentFlags = data[position++];
  34968. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  34969. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  34970. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  34971. if (!genericRegion.mmr) {
  34972. atLength = genericRegion.template === 0 ? 4 : 1;
  34973. at = [];
  34974. for (i = 0; i < atLength; i++) {
  34975. at.push({
  34976. x: readInt8(data, position),
  34977. y: readInt8(data, position + 1)
  34978. });
  34979. position += 2;
  34980. }
  34981. genericRegion.at = at;
  34982. }
  34983. args = [genericRegion, data, position, end];
  34984. break;
  34985. case 48: // PageInformation
  34986. var pageInfo = {
  34987. width: readUint32(data, position),
  34988. height: readUint32(data, position + 4),
  34989. resolutionX: readUint32(data, position + 8),
  34990. resolutionY: readUint32(data, position + 12)
  34991. };
  34992. if (pageInfo.height === 0xFFFFFFFF) {
  34993. delete pageInfo.height;
  34994. }
  34995. var pageSegmentFlags = data[position + 16];
  34996. var pageStripingInformatiom = readUint16(data, position + 17);
  34997. pageInfo.lossless = !!(pageSegmentFlags & 1);
  34998. pageInfo.refinement = !!(pageSegmentFlags & 2);
  34999. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  35000. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  35001. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  35002. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  35003. args = [pageInfo];
  35004. break;
  35005. case 49: // EndOfPage
  35006. break;
  35007. case 50: // EndOfStripe
  35008. break;
  35009. case 51: // EndOfFile
  35010. break;
  35011. case 62: // 7.4.15 defines 2 extension types which
  35012. // are comments and can be ignored.
  35013. break;
  35014. default:
  35015. error('JBIG2 error: segment type ' + header.typeName + '(' +
  35016. header.type + ') is not implemented');
  35017. }
  35018. var callbackName = 'on' + header.typeName;
  35019. if (callbackName in visitor) {
  35020. visitor[callbackName].apply(visitor, args);
  35021. }
  35022. }
  35023. function processSegments(segments, visitor) {
  35024. for (var i = 0, ii = segments.length; i < ii; i++) {
  35025. processSegment(segments[i], visitor);
  35026. }
  35027. }
  35028. function parseJbig2(data, start, end) {
  35029. var position = start;
  35030. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  35031. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  35032. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  35033. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  35034. error('JBIG2 error: invalid header');
  35035. }
  35036. var header = {};
  35037. position += 8;
  35038. var flags = data[position++];
  35039. header.randomAccess = !(flags & 1);
  35040. if (!(flags & 2)) {
  35041. header.numberOfPages = readUint32(data, position);
  35042. position += 4;
  35043. }
  35044. var segments = readSegments(header, data, position, end);
  35045. error('Not implemented');
  35046. // processSegments(segments, new SimpleSegmentVisitor());
  35047. }
  35048. function parseJbig2Chunks(chunks) {
  35049. var visitor = new SimpleSegmentVisitor();
  35050. for (var i = 0, ii = chunks.length; i < ii; i++) {
  35051. var chunk = chunks[i];
  35052. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  35053. processSegments(segments, visitor);
  35054. }
  35055. return visitor.buffer;
  35056. }
  35057. function SimpleSegmentVisitor() {}
  35058. SimpleSegmentVisitor.prototype = {
  35059. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  35060. this.currentPageInfo = info;
  35061. var rowSize = (info.width + 7) >> 3;
  35062. var buffer = new Uint8Array(rowSize * info.height);
  35063. // The contents of ArrayBuffers are initialized to 0.
  35064. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  35065. if (info.defaultPixelValue) {
  35066. for (var i = 0, ii = buffer.length; i < ii; i++) {
  35067. buffer[i] = 0xFF;
  35068. }
  35069. }
  35070. this.buffer = buffer;
  35071. },
  35072. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  35073. var pageInfo = this.currentPageInfo;
  35074. var width = regionInfo.width, height = regionInfo.height;
  35075. var rowSize = (pageInfo.width + 7) >> 3;
  35076. var combinationOperator = pageInfo.combinationOperatorOverride ?
  35077. regionInfo.combinationOperator : pageInfo.combinationOperator;
  35078. var buffer = this.buffer;
  35079. var mask0 = 128 >> (regionInfo.x & 7);
  35080. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  35081. var i, j, mask, offset;
  35082. switch (combinationOperator) {
  35083. case 0: // OR
  35084. for (i = 0; i < height; i++) {
  35085. mask = mask0;
  35086. offset = offset0;
  35087. for (j = 0; j < width; j++) {
  35088. if (bitmap[i][j]) {
  35089. buffer[offset] |= mask;
  35090. }
  35091. mask >>= 1;
  35092. if (!mask) {
  35093. mask = 128;
  35094. offset++;
  35095. }
  35096. }
  35097. offset0 += rowSize;
  35098. }
  35099. break;
  35100. case 2: // XOR
  35101. for (i = 0; i < height; i++) {
  35102. mask = mask0;
  35103. offset = offset0;
  35104. for (j = 0; j < width; j++) {
  35105. if (bitmap[i][j]) {
  35106. buffer[offset] ^= mask;
  35107. }
  35108. mask >>= 1;
  35109. if (!mask) {
  35110. mask = 128;
  35111. offset++;
  35112. }
  35113. }
  35114. offset0 += rowSize;
  35115. }
  35116. break;
  35117. default:
  35118. error('JBIG2 error: operator ' + combinationOperator +
  35119. ' is not supported');
  35120. }
  35121. },
  35122. onImmediateGenericRegion:
  35123. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  35124. start, end) {
  35125. var regionInfo = region.info;
  35126. var decodingContext = new DecodingContext(data, start, end);
  35127. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  35128. region.template, region.prediction, null,
  35129. region.at, decodingContext);
  35130. this.drawBitmap(regionInfo, bitmap);
  35131. },
  35132. onImmediateLosslessGenericRegion:
  35133. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  35134. this.onImmediateGenericRegion.apply(this, arguments);
  35135. },
  35136. onSymbolDictionary:
  35137. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  35138. currentSegment,
  35139. referredSegments,
  35140. data, start, end) {
  35141. var huffmanTables;
  35142. if (dictionary.huffman) {
  35143. error('JBIG2 error: huffman is not supported');
  35144. }
  35145. // Combines exported symbols from all referred segments
  35146. var symbols = this.symbols;
  35147. if (!symbols) {
  35148. this.symbols = symbols = {};
  35149. }
  35150. var inputSymbols = [];
  35151. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35152. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35153. }
  35154. var decodingContext = new DecodingContext(data, start, end);
  35155. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  35156. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  35157. dictionary.numberOfExportedSymbols, huffmanTables,
  35158. dictionary.template, dictionary.at,
  35159. dictionary.refinementTemplate, dictionary.refinementAt,
  35160. decodingContext);
  35161. },
  35162. onImmediateTextRegion:
  35163. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  35164. referredSegments,
  35165. data, start, end) {
  35166. var regionInfo = region.info;
  35167. var huffmanTables;
  35168. // Combines exported symbols from all referred segments
  35169. var symbols = this.symbols;
  35170. var inputSymbols = [];
  35171. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  35172. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  35173. }
  35174. var symbolCodeLength = log2(inputSymbols.length);
  35175. var decodingContext = new DecodingContext(data, start, end);
  35176. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  35177. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  35178. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  35179. symbolCodeLength, region.transposed, region.dsOffset,
  35180. region.referenceCorner, region.combinationOperator, huffmanTables,
  35181. region.refinementTemplate, region.refinementAt, decodingContext);
  35182. this.drawBitmap(regionInfo, bitmap);
  35183. },
  35184. onImmediateLosslessTextRegion:
  35185. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  35186. this.onImmediateTextRegion.apply(this, arguments);
  35187. }
  35188. };
  35189. function Jbig2Image() {}
  35190. Jbig2Image.prototype = {
  35191. parseChunks: function Jbig2Image_parseChunks(chunks) {
  35192. return parseJbig2Chunks(chunks);
  35193. }
  35194. };
  35195. return Jbig2Image;
  35196. })();
  35197. var bidi = PDFJS.bidi = (function bidiClosure() {
  35198. // Character types for symbols from 0000 to 00FF.
  35199. var baseTypes = [
  35200. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  35201. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35202. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  35203. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  35204. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  35205. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35206. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  35207. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35208. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35209. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  35210. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35211. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  35212. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  35213. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  35214. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35215. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35216. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35217. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  35218. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  35219. ];
  35220. // Character types for symbols from 0600 to 06FF
  35221. var arabicTypes = [
  35222. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35223. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  35224. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35225. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35226. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35227. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35228. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35229. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35230. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  35231. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  35232. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35233. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35234. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35235. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35236. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35237. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35238. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35240. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  35241. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  35242. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  35243. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  35244. ];
  35245. function isOdd(i) {
  35246. return (i & 1) !== 0;
  35247. }
  35248. function isEven(i) {
  35249. return (i & 1) === 0;
  35250. }
  35251. function findUnequal(arr, start, value) {
  35252. for (var j = start, jj = arr.length; j < jj; ++j) {
  35253. if (arr[j] !== value) {
  35254. return j;
  35255. }
  35256. }
  35257. return j;
  35258. }
  35259. function setValues(arr, start, end, value) {
  35260. for (var j = start; j < end; ++j) {
  35261. arr[j] = value;
  35262. }
  35263. }
  35264. function reverseValues(arr, start, end) {
  35265. for (var i = start, j = end - 1; i < j; ++i, --j) {
  35266. var temp = arr[i];
  35267. arr[i] = arr[j];
  35268. arr[j] = temp;
  35269. }
  35270. }
  35271. function createBidiText(str, isLTR, vertical) {
  35272. return {
  35273. str: str,
  35274. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  35275. };
  35276. }
  35277. // These are used in bidi(), which is called frequently. We re-use them on
  35278. // each call to avoid unnecessary allocations.
  35279. var chars = [];
  35280. var types = [];
  35281. function bidi(str, startLevel, vertical) {
  35282. var isLTR = true;
  35283. var strLength = str.length;
  35284. if (strLength === 0 || vertical) {
  35285. return createBidiText(str, isLTR, vertical);
  35286. }
  35287. // Get types and fill arrays
  35288. chars.length = strLength;
  35289. types.length = strLength;
  35290. var numBidi = 0;
  35291. var i, ii;
  35292. for (i = 0; i < strLength; ++i) {
  35293. chars[i] = str.charAt(i);
  35294. var charCode = str.charCodeAt(i);
  35295. var charType = 'L';
  35296. if (charCode <= 0x00ff) {
  35297. charType = baseTypes[charCode];
  35298. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  35299. charType = 'R';
  35300. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  35301. charType = arabicTypes[charCode & 0xff];
  35302. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  35303. charType = 'AL';
  35304. }
  35305. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  35306. numBidi++;
  35307. }
  35308. types[i] = charType;
  35309. }
  35310. // Detect the bidi method
  35311. // - If there are no rtl characters then no bidi needed
  35312. // - If less than 30% chars are rtl then string is primarily ltr
  35313. // - If more than 30% chars are rtl then string is primarily rtl
  35314. if (numBidi === 0) {
  35315. isLTR = true;
  35316. return createBidiText(str, isLTR);
  35317. }
  35318. if (startLevel === -1) {
  35319. if ((strLength / numBidi) < 0.3) {
  35320. isLTR = true;
  35321. startLevel = 0;
  35322. } else {
  35323. isLTR = false;
  35324. startLevel = 1;
  35325. }
  35326. }
  35327. var levels = [];
  35328. for (i = 0; i < strLength; ++i) {
  35329. levels[i] = startLevel;
  35330. }
  35331. /*
  35332. X1-X10: skip most of this, since we are NOT doing the embeddings.
  35333. */
  35334. var e = (isOdd(startLevel) ? 'R' : 'L');
  35335. var sor = e;
  35336. var eor = sor;
  35337. /*
  35338. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  35339. type of the NSM to the type of the previous character. If the NSM is at the
  35340. start of the level run, it will get the type of sor.
  35341. */
  35342. var lastType = sor;
  35343. for (i = 0; i < strLength; ++i) {
  35344. if (types[i] === 'NSM') {
  35345. types[i] = lastType;
  35346. } else {
  35347. lastType = types[i];
  35348. }
  35349. }
  35350. /*
  35351. W2. Search backwards from each instance of a European number until the
  35352. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  35353. the type of the European number to Arabic number.
  35354. */
  35355. lastType = sor;
  35356. var t;
  35357. for (i = 0; i < strLength; ++i) {
  35358. t = types[i];
  35359. if (t === 'EN') {
  35360. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  35361. } else if (t === 'R' || t === 'L' || t === 'AL') {
  35362. lastType = t;
  35363. }
  35364. }
  35365. /*
  35366. W3. Change all ALs to R.
  35367. */
  35368. for (i = 0; i < strLength; ++i) {
  35369. t = types[i];
  35370. if (t === 'AL') {
  35371. types[i] = 'R';
  35372. }
  35373. }
  35374. /*
  35375. W4. A single European separator between two European numbers changes to a
  35376. European number. A single common separator between two numbers of the same
  35377. type changes to that type:
  35378. */
  35379. for (i = 1; i < strLength - 1; ++i) {
  35380. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  35381. types[i] = 'EN';
  35382. }
  35383. if (types[i] === 'CS' &&
  35384. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  35385. types[i + 1] === types[i - 1]) {
  35386. types[i] = types[i - 1];
  35387. }
  35388. }
  35389. /*
  35390. W5. A sequence of European terminators adjacent to European numbers changes
  35391. to all European numbers:
  35392. */
  35393. for (i = 0; i < strLength; ++i) {
  35394. if (types[i] === 'EN') {
  35395. // do before
  35396. var j;
  35397. for (j = i - 1; j >= 0; --j) {
  35398. if (types[j] !== 'ET') {
  35399. break;
  35400. }
  35401. types[j] = 'EN';
  35402. }
  35403. // do after
  35404. for (j = i + 1; j < strLength; --j) {
  35405. if (types[j] !== 'ET') {
  35406. break;
  35407. }
  35408. types[j] = 'EN';
  35409. }
  35410. }
  35411. }
  35412. /*
  35413. W6. Otherwise, separators and terminators change to Other Neutral:
  35414. */
  35415. for (i = 0; i < strLength; ++i) {
  35416. t = types[i];
  35417. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  35418. types[i] = 'ON';
  35419. }
  35420. }
  35421. /*
  35422. W7. Search backwards from each instance of a European number until the
  35423. first strong type (R, L, or sor) is found. If an L is found, then change
  35424. the type of the European number to L.
  35425. */
  35426. lastType = sor;
  35427. for (i = 0; i < strLength; ++i) {
  35428. t = types[i];
  35429. if (t === 'EN') {
  35430. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  35431. } else if (t === 'R' || t === 'L') {
  35432. lastType = t;
  35433. }
  35434. }
  35435. /*
  35436. N1. A sequence of neutrals takes the direction of the surrounding strong
  35437. text if the text on both sides has the same direction. European and Arabic
  35438. numbers are treated as though they were R. Start-of-level-run (sor) and
  35439. end-of-level-run (eor) are used at level run boundaries.
  35440. */
  35441. for (i = 0; i < strLength; ++i) {
  35442. if (types[i] === 'ON') {
  35443. var end = findUnequal(types, i + 1, 'ON');
  35444. var before = sor;
  35445. if (i > 0) {
  35446. before = types[i - 1];
  35447. }
  35448. var after = eor;
  35449. if (end + 1 < strLength) {
  35450. after = types[end + 1];
  35451. }
  35452. if (before !== 'L') {
  35453. before = 'R';
  35454. }
  35455. if (after !== 'L') {
  35456. after = 'R';
  35457. }
  35458. if (before === after) {
  35459. setValues(types, i, end, before);
  35460. }
  35461. i = end - 1; // reset to end (-1 so next iteration is ok)
  35462. }
  35463. }
  35464. /*
  35465. N2. Any remaining neutrals take the embedding direction.
  35466. */
  35467. for (i = 0; i < strLength; ++i) {
  35468. if (types[i] === 'ON') {
  35469. types[i] = e;
  35470. }
  35471. }
  35472. /*
  35473. I1. For all characters with an even (left-to-right) embedding direction,
  35474. those of type R go up one level and those of type AN or EN go up two
  35475. levels.
  35476. I2. For all characters with an odd (right-to-left) embedding direction,
  35477. those of type L, EN or AN go up one level.
  35478. */
  35479. for (i = 0; i < strLength; ++i) {
  35480. t = types[i];
  35481. if (isEven(levels[i])) {
  35482. if (t === 'R') {
  35483. levels[i] += 1;
  35484. } else if (t === 'AN' || t === 'EN') {
  35485. levels[i] += 2;
  35486. }
  35487. } else { // isOdd
  35488. if (t === 'L' || t === 'AN' || t === 'EN') {
  35489. levels[i] += 1;
  35490. }
  35491. }
  35492. }
  35493. /*
  35494. L1. On each line, reset the embedding level of the following characters to
  35495. the paragraph embedding level:
  35496. segment separators,
  35497. paragraph separators,
  35498. any sequence of whitespace characters preceding a segment separator or
  35499. paragraph separator, and any sequence of white space characters at the end
  35500. of the line.
  35501. */
  35502. // don't bother as text is only single line
  35503. /*
  35504. L2. From the highest level found in the text to the lowest odd level on
  35505. each line, reverse any contiguous sequence of characters that are at that
  35506. level or higher.
  35507. */
  35508. // find highest level & lowest odd level
  35509. var highestLevel = -1;
  35510. var lowestOddLevel = 99;
  35511. var level;
  35512. for (i = 0, ii = levels.length; i < ii; ++i) {
  35513. level = levels[i];
  35514. if (highestLevel < level) {
  35515. highestLevel = level;
  35516. }
  35517. if (lowestOddLevel > level && isOdd(level)) {
  35518. lowestOddLevel = level;
  35519. }
  35520. }
  35521. // now reverse between those limits
  35522. for (level = highestLevel; level >= lowestOddLevel; --level) {
  35523. // find segments to reverse
  35524. var start = -1;
  35525. for (i = 0, ii = levels.length; i < ii; ++i) {
  35526. if (levels[i] < level) {
  35527. if (start >= 0) {
  35528. reverseValues(chars, start, i);
  35529. start = -1;
  35530. }
  35531. } else if (start < 0) {
  35532. start = i;
  35533. }
  35534. }
  35535. if (start >= 0) {
  35536. reverseValues(chars, start, levels.length);
  35537. }
  35538. }
  35539. /*
  35540. L3. Combining marks applied to a right-to-left base character will at this
  35541. point precede their base character. If the rendering engine expects them to
  35542. follow the base characters in the final display process, then the ordering
  35543. of the marks and the base character must be reversed.
  35544. */
  35545. // don't bother for now
  35546. /*
  35547. L4. A character that possesses the mirrored property as specified by
  35548. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  35549. directionality of that character is R.
  35550. */
  35551. // don't mirror as characters are already mirrored in the pdf
  35552. // Finally, return string
  35553. var result = '';
  35554. for (i = 0, ii = chars.length; i < ii; ++i) {
  35555. var ch = chars[i];
  35556. if (ch !== '<' && ch !== '>') {
  35557. result += ch;
  35558. }
  35559. }
  35560. return createBidiText(result, isLTR);
  35561. }
  35562. return bidi;
  35563. })();
  35564. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  35565. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  35566. /* Copyright 2014 Opera Software ASA
  35567. *
  35568. * Licensed under the Apache License, Version 2.0 (the "License");
  35569. * you may not use this file except in compliance with the License.
  35570. * You may obtain a copy of the License at
  35571. *
  35572. * http://www.apache.org/licenses/LICENSE-2.0
  35573. *
  35574. * Unless required by applicable law or agreed to in writing, software
  35575. * distributed under the License is distributed on an "AS IS" BASIS,
  35576. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  35577. * See the License for the specific language governing permissions and
  35578. * limitations under the License.
  35579. *
  35580. *
  35581. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  35582. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  35583. */
  35584. /* globals Uint32ArrayView */
  35585. 'use strict';
  35586. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  35587. // Workaround for missing math precison in JS.
  35588. var MASK_HIGH = 0xffff0000;
  35589. var MASK_LOW = 0xffff;
  35590. function MurmurHash3_64 (seed) {
  35591. var SEED = 0xc3d2e1f0;
  35592. this.h1 = seed ? seed & 0xffffffff : SEED;
  35593. this.h2 = seed ? seed & 0xffffffff : SEED;
  35594. }
  35595. var alwaysUseUint32ArrayView = false;
  35596. // old webkits have issues with non-aligned arrays
  35597. try {
  35598. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  35599. } catch (e) {
  35600. alwaysUseUint32ArrayView = true;
  35601. }
  35602. MurmurHash3_64.prototype = {
  35603. update: function MurmurHash3_64_update(input) {
  35604. var useUint32ArrayView = alwaysUseUint32ArrayView;
  35605. var i;
  35606. if (typeof input === 'string') {
  35607. var data = new Uint8Array(input.length * 2);
  35608. var length = 0;
  35609. for (i = 0; i < input.length; i++) {
  35610. var code = input.charCodeAt(i);
  35611. if (code <= 0xff) {
  35612. data[length++] = code;
  35613. }
  35614. else {
  35615. data[length++] = code >>> 8;
  35616. data[length++] = code & 0xff;
  35617. }
  35618. }
  35619. } else if (input instanceof Uint8Array) {
  35620. data = input;
  35621. length = data.length;
  35622. } else if (typeof input === 'object' && ('length' in input)) {
  35623. // processing regular arrays as well, e.g. for IE9
  35624. data = input;
  35625. length = data.length;
  35626. useUint32ArrayView = true;
  35627. } else {
  35628. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  35629. 'Input must be a string or array.');
  35630. }
  35631. var blockCounts = length >> 2;
  35632. var tailLength = length - blockCounts * 4;
  35633. // we don't care about endianness here
  35634. var dataUint32 = useUint32ArrayView ?
  35635. new Uint32ArrayView(data, blockCounts) :
  35636. new Uint32Array(data.buffer, 0, blockCounts);
  35637. var k1 = 0;
  35638. var k2 = 0;
  35639. var h1 = this.h1;
  35640. var h2 = this.h2;
  35641. var C1 = 0xcc9e2d51;
  35642. var C2 = 0x1b873593;
  35643. var C1_LOW = C1 & MASK_LOW;
  35644. var C2_LOW = C2 & MASK_LOW;
  35645. for (i = 0; i < blockCounts; i++) {
  35646. if (i & 1) {
  35647. k1 = dataUint32[i];
  35648. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35649. k1 = k1 << 15 | k1 >>> 17;
  35650. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35651. h1 ^= k1;
  35652. h1 = h1 << 13 | h1 >>> 19;
  35653. h1 = h1 * 5 + 0xe6546b64;
  35654. } else {
  35655. k2 = dataUint32[i];
  35656. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  35657. k2 = k2 << 15 | k2 >>> 17;
  35658. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  35659. h2 ^= k2;
  35660. h2 = h2 << 13 | h2 >>> 19;
  35661. h2 = h2 * 5 + 0xe6546b64;
  35662. }
  35663. }
  35664. k1 = 0;
  35665. switch (tailLength) {
  35666. case 3:
  35667. k1 ^= data[blockCounts * 4 + 2] << 16;
  35668. /* falls through */
  35669. case 2:
  35670. k1 ^= data[blockCounts * 4 + 1] << 8;
  35671. /* falls through */
  35672. case 1:
  35673. k1 ^= data[blockCounts * 4];
  35674. /* falls through */
  35675. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  35676. k1 = k1 << 15 | k1 >>> 17;
  35677. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  35678. if (blockCounts & 1) {
  35679. h1 ^= k1;
  35680. } else {
  35681. h2 ^= k1;
  35682. }
  35683. }
  35684. this.h1 = h1;
  35685. this.h2 = h2;
  35686. return this;
  35687. },
  35688. hexdigest: function MurmurHash3_64_hexdigest () {
  35689. var h1 = this.h1;
  35690. var h2 = this.h2;
  35691. h1 ^= h2 >>> 1;
  35692. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  35693. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  35694. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  35695. h1 ^= h2 >>> 1;
  35696. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  35697. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  35698. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  35699. h1 ^= h2 >>> 1;
  35700. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  35701. var hex = (arr[i] >>> 0).toString(16);
  35702. while (hex.length < 8) {
  35703. hex = '0' + hex;
  35704. }
  35705. str += hex;
  35706. }
  35707. return str;
  35708. }
  35709. };
  35710. return MurmurHash3_64;
  35711. })();
  35712. }).call((typeof window === 'undefined') ? this : window);
  35713. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  35714. // workerSrc is not set -- using last script url to define default location
  35715. PDFJS.workerSrc = (function () {
  35716. 'use strict';
  35717. var scriptTagContainer = document.body ||
  35718. document.getElementsByTagName('head')[0];
  35719. var pdfjsSrc = scriptTagContainer.lastChild.src;
  35720. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  35721. })();
  35722. }