pdf.worker.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203
  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.1092';
  24. PDFJS.build = '8389f1d';
  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. case 'tel':
  319. return true;
  320. default:
  321. return false;
  322. }
  323. }
  324. PDFJS.isValidUrl = isValidUrl;
  325. function shadow(obj, prop, value) {
  326. Object.defineProperty(obj, prop, { value: value,
  327. enumerable: true,
  328. configurable: true,
  329. writable: false });
  330. return value;
  331. }
  332. var PasswordResponses = PDFJS.PasswordResponses = {
  333. NEED_PASSWORD: 1,
  334. INCORRECT_PASSWORD: 2
  335. };
  336. var PasswordException = (function PasswordExceptionClosure() {
  337. function PasswordException(msg, code) {
  338. this.name = 'PasswordException';
  339. this.message = msg;
  340. this.code = code;
  341. }
  342. PasswordException.prototype = new Error();
  343. PasswordException.constructor = PasswordException;
  344. return PasswordException;
  345. })();
  346. PDFJS.PasswordException = PasswordException;
  347. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  348. function UnknownErrorException(msg, details) {
  349. this.name = 'UnknownErrorException';
  350. this.message = msg;
  351. this.details = details;
  352. }
  353. UnknownErrorException.prototype = new Error();
  354. UnknownErrorException.constructor = UnknownErrorException;
  355. return UnknownErrorException;
  356. })();
  357. PDFJS.UnknownErrorException = UnknownErrorException;
  358. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  359. function InvalidPDFException(msg) {
  360. this.name = 'InvalidPDFException';
  361. this.message = msg;
  362. }
  363. InvalidPDFException.prototype = new Error();
  364. InvalidPDFException.constructor = InvalidPDFException;
  365. return InvalidPDFException;
  366. })();
  367. PDFJS.InvalidPDFException = InvalidPDFException;
  368. var MissingPDFException = (function MissingPDFExceptionClosure() {
  369. function MissingPDFException(msg) {
  370. this.name = 'MissingPDFException';
  371. this.message = msg;
  372. }
  373. MissingPDFException.prototype = new Error();
  374. MissingPDFException.constructor = MissingPDFException;
  375. return MissingPDFException;
  376. })();
  377. PDFJS.MissingPDFException = MissingPDFException;
  378. var UnexpectedResponseException =
  379. (function UnexpectedResponseExceptionClosure() {
  380. function UnexpectedResponseException(msg, status) {
  381. this.name = 'UnexpectedResponseException';
  382. this.message = msg;
  383. this.status = status;
  384. }
  385. UnexpectedResponseException.prototype = new Error();
  386. UnexpectedResponseException.constructor = UnexpectedResponseException;
  387. return UnexpectedResponseException;
  388. })();
  389. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  390. var NotImplementedException = (function NotImplementedExceptionClosure() {
  391. function NotImplementedException(msg) {
  392. this.message = msg;
  393. }
  394. NotImplementedException.prototype = new Error();
  395. NotImplementedException.prototype.name = 'NotImplementedException';
  396. NotImplementedException.constructor = NotImplementedException;
  397. return NotImplementedException;
  398. })();
  399. var MissingDataException = (function MissingDataExceptionClosure() {
  400. function MissingDataException(begin, end) {
  401. this.begin = begin;
  402. this.end = end;
  403. this.message = 'Missing data [' + begin + ', ' + end + ')';
  404. }
  405. MissingDataException.prototype = new Error();
  406. MissingDataException.prototype.name = 'MissingDataException';
  407. MissingDataException.constructor = MissingDataException;
  408. return MissingDataException;
  409. })();
  410. var XRefParseException = (function XRefParseExceptionClosure() {
  411. function XRefParseException(msg) {
  412. this.message = msg;
  413. }
  414. XRefParseException.prototype = new Error();
  415. XRefParseException.prototype.name = 'XRefParseException';
  416. XRefParseException.constructor = XRefParseException;
  417. return XRefParseException;
  418. })();
  419. function bytesToString(bytes) {
  420. assert(bytes !== null && typeof bytes === 'object' &&
  421. bytes.length !== undefined, 'Invalid argument for bytesToString');
  422. var length = bytes.length;
  423. var MAX_ARGUMENT_COUNT = 8192;
  424. if (length < MAX_ARGUMENT_COUNT) {
  425. return String.fromCharCode.apply(null, bytes);
  426. }
  427. var strBuf = [];
  428. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  429. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  430. var chunk = bytes.subarray(i, chunkEnd);
  431. strBuf.push(String.fromCharCode.apply(null, chunk));
  432. }
  433. return strBuf.join('');
  434. }
  435. function stringToBytes(str) {
  436. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  437. var length = str.length;
  438. var bytes = new Uint8Array(length);
  439. for (var i = 0; i < length; ++i) {
  440. bytes[i] = str.charCodeAt(i) & 0xFF;
  441. }
  442. return bytes;
  443. }
  444. function string32(value) {
  445. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  446. (value >> 8) & 0xff, value & 0xff);
  447. }
  448. function log2(x) {
  449. var n = 1, i = 0;
  450. while (x > n) {
  451. n <<= 1;
  452. i++;
  453. }
  454. return i;
  455. }
  456. function readInt8(data, start) {
  457. return (data[start] << 24) >> 24;
  458. }
  459. function readUint16(data, offset) {
  460. return (data[offset] << 8) | data[offset + 1];
  461. }
  462. function readUint32(data, offset) {
  463. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  464. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  465. }
  466. // Lazy test the endianness of the platform
  467. // NOTE: This will be 'true' for simulated TypedArrays
  468. function isLittleEndian() {
  469. var buffer8 = new Uint8Array(2);
  470. buffer8[0] = 1;
  471. var buffer16 = new Uint16Array(buffer8.buffer);
  472. return (buffer16[0] === 1);
  473. }
  474. Object.defineProperty(PDFJS, 'isLittleEndian', {
  475. configurable: true,
  476. get: function PDFJS_isLittleEndian() {
  477. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  478. }
  479. });
  480. // Lazy test if the userAgant support CanvasTypedArrays
  481. function hasCanvasTypedArrays() {
  482. var canvas = document.createElement('canvas');
  483. canvas.width = canvas.height = 1;
  484. var ctx = canvas.getContext('2d');
  485. var imageData = ctx.createImageData(1, 1);
  486. return (typeof imageData.data.buffer !== 'undefined');
  487. }
  488. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  489. configurable: true,
  490. get: function PDFJS_hasCanvasTypedArrays() {
  491. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  492. }
  493. });
  494. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  495. function Uint32ArrayView(buffer, length) {
  496. this.buffer = buffer;
  497. this.byteLength = buffer.length;
  498. this.length = length === undefined ? (this.byteLength >> 2) : length;
  499. ensureUint32ArrayViewProps(this.length);
  500. }
  501. Uint32ArrayView.prototype = Object.create(null);
  502. var uint32ArrayViewSetters = 0;
  503. function createUint32ArrayProp(index) {
  504. return {
  505. get: function () {
  506. var buffer = this.buffer, offset = index << 2;
  507. return (buffer[offset] | (buffer[offset + 1] << 8) |
  508. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  509. },
  510. set: function (value) {
  511. var buffer = this.buffer, offset = index << 2;
  512. buffer[offset] = value & 255;
  513. buffer[offset + 1] = (value >> 8) & 255;
  514. buffer[offset + 2] = (value >> 16) & 255;
  515. buffer[offset + 3] = (value >>> 24) & 255;
  516. }
  517. };
  518. }
  519. function ensureUint32ArrayViewProps(length) {
  520. while (uint32ArrayViewSetters < length) {
  521. Object.defineProperty(Uint32ArrayView.prototype,
  522. uint32ArrayViewSetters,
  523. createUint32ArrayProp(uint32ArrayViewSetters));
  524. uint32ArrayViewSetters++;
  525. }
  526. }
  527. return Uint32ArrayView;
  528. })();
  529. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  530. var Util = PDFJS.Util = (function UtilClosure() {
  531. function Util() {}
  532. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  533. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  534. // creating many intermediate strings.
  535. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  536. rgbBuf[1] = r;
  537. rgbBuf[3] = g;
  538. rgbBuf[5] = b;
  539. return rgbBuf.join('');
  540. };
  541. // Concatenates two transformation matrices together and returns the result.
  542. Util.transform = function Util_transform(m1, m2) {
  543. return [
  544. m1[0] * m2[0] + m1[2] * m2[1],
  545. m1[1] * m2[0] + m1[3] * m2[1],
  546. m1[0] * m2[2] + m1[2] * m2[3],
  547. m1[1] * m2[2] + m1[3] * m2[3],
  548. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  549. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  550. ];
  551. };
  552. // For 2d affine transforms
  553. Util.applyTransform = function Util_applyTransform(p, m) {
  554. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  555. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  556. return [xt, yt];
  557. };
  558. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  559. var d = m[0] * m[3] - m[1] * m[2];
  560. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  561. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  562. return [xt, yt];
  563. };
  564. // Applies the transform to the rectangle and finds the minimum axially
  565. // aligned bounding box.
  566. Util.getAxialAlignedBoundingBox =
  567. function Util_getAxialAlignedBoundingBox(r, m) {
  568. var p1 = Util.applyTransform(r, m);
  569. var p2 = Util.applyTransform(r.slice(2, 4), m);
  570. var p3 = Util.applyTransform([r[0], r[3]], m);
  571. var p4 = Util.applyTransform([r[2], r[1]], m);
  572. return [
  573. Math.min(p1[0], p2[0], p3[0], p4[0]),
  574. Math.min(p1[1], p2[1], p3[1], p4[1]),
  575. Math.max(p1[0], p2[0], p3[0], p4[0]),
  576. Math.max(p1[1], p2[1], p3[1], p4[1])
  577. ];
  578. };
  579. Util.inverseTransform = function Util_inverseTransform(m) {
  580. var d = m[0] * m[3] - m[1] * m[2];
  581. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  582. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  583. };
  584. // Apply a generic 3d matrix M on a 3-vector v:
  585. // | a b c | | X |
  586. // | d e f | x | Y |
  587. // | g h i | | Z |
  588. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  589. // with v as [X,Y,Z]
  590. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  591. return [
  592. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  593. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  594. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  595. ];
  596. };
  597. // This calculation uses Singular Value Decomposition.
  598. // The SVD can be represented with formula A = USV. We are interested in the
  599. // matrix S here because it represents the scale values.
  600. Util.singularValueDecompose2dScale =
  601. function Util_singularValueDecompose2dScale(m) {
  602. var transpose = [m[0], m[2], m[1], m[3]];
  603. // Multiply matrix m with its transpose.
  604. var a = m[0] * transpose[0] + m[1] * transpose[2];
  605. var b = m[0] * transpose[1] + m[1] * transpose[3];
  606. var c = m[2] * transpose[0] + m[3] * transpose[2];
  607. var d = m[2] * transpose[1] + m[3] * transpose[3];
  608. // Solve the second degree polynomial to get roots.
  609. var first = (a + d) / 2;
  610. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  611. var sx = first + second || 1;
  612. var sy = first - second || 1;
  613. // Scale values are the square roots of the eigenvalues.
  614. return [Math.sqrt(sx), Math.sqrt(sy)];
  615. };
  616. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  617. // For coordinate systems whose origin lies in the bottom-left, this
  618. // means normalization to (BL,TR) ordering. For systems with origin in the
  619. // top-left, this means (TL,BR) ordering.
  620. Util.normalizeRect = function Util_normalizeRect(rect) {
  621. var r = rect.slice(0); // clone rect
  622. if (rect[0] > rect[2]) {
  623. r[0] = rect[2];
  624. r[2] = rect[0];
  625. }
  626. if (rect[1] > rect[3]) {
  627. r[1] = rect[3];
  628. r[3] = rect[1];
  629. }
  630. return r;
  631. };
  632. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  633. // intersection of rect1 and rect2. If no intersection, returns 'false'
  634. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  635. Util.intersect = function Util_intersect(rect1, rect2) {
  636. function compare(a, b) {
  637. return a - b;
  638. }
  639. // Order points along the axes
  640. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  641. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  642. result = [];
  643. rect1 = Util.normalizeRect(rect1);
  644. rect2 = Util.normalizeRect(rect2);
  645. // X: first and second points belong to different rectangles?
  646. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  647. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  648. // Intersection must be between second and third points
  649. result[0] = orderedX[1];
  650. result[2] = orderedX[2];
  651. } else {
  652. return false;
  653. }
  654. // Y: first and second points belong to different rectangles?
  655. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  656. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  657. // Intersection must be between second and third points
  658. result[1] = orderedY[1];
  659. result[3] = orderedY[2];
  660. } else {
  661. return false;
  662. }
  663. return result;
  664. };
  665. Util.sign = function Util_sign(num) {
  666. return num < 0 ? -1 : 1;
  667. };
  668. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  669. Array.prototype.push.apply(arr1, arr2);
  670. };
  671. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  672. Array.prototype.unshift.apply(arr1, arr2);
  673. };
  674. Util.extendObj = function extendObj(obj1, obj2) {
  675. for (var key in obj2) {
  676. obj1[key] = obj2[key];
  677. }
  678. };
  679. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  680. name) {
  681. while (dict && !dict.has(name)) {
  682. dict = dict.get('Parent');
  683. }
  684. if (!dict) {
  685. return null;
  686. }
  687. return dict.get(name);
  688. };
  689. Util.inherit = function Util_inherit(sub, base, prototype) {
  690. sub.prototype = Object.create(base.prototype);
  691. sub.prototype.constructor = sub;
  692. for (var prop in prototype) {
  693. sub.prototype[prop] = prototype[prop];
  694. }
  695. };
  696. Util.loadScript = function Util_loadScript(src, callback) {
  697. var script = document.createElement('script');
  698. var loaded = false;
  699. script.setAttribute('src', src);
  700. if (callback) {
  701. script.onload = function() {
  702. if (!loaded) {
  703. callback();
  704. }
  705. loaded = true;
  706. };
  707. }
  708. document.getElementsByTagName('head')[0].appendChild(script);
  709. };
  710. return Util;
  711. })();
  712. /**
  713. * PDF page viewport created based on scale, rotation and offset.
  714. * @class
  715. * @alias PDFJS.PageViewport
  716. */
  717. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  718. /**
  719. * @constructor
  720. * @private
  721. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  722. * @param scale {number} scale of the viewport.
  723. * @param rotation {number} rotations of the viewport in degrees.
  724. * @param offsetX {number} offset X
  725. * @param offsetY {number} offset Y
  726. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  727. */
  728. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  729. this.viewBox = viewBox;
  730. this.scale = scale;
  731. this.rotation = rotation;
  732. this.offsetX = offsetX;
  733. this.offsetY = offsetY;
  734. // creating transform to convert pdf coordinate system to the normal
  735. // canvas like coordinates taking in account scale and rotation
  736. var centerX = (viewBox[2] + viewBox[0]) / 2;
  737. var centerY = (viewBox[3] + viewBox[1]) / 2;
  738. var rotateA, rotateB, rotateC, rotateD;
  739. rotation = rotation % 360;
  740. rotation = rotation < 0 ? rotation + 360 : rotation;
  741. switch (rotation) {
  742. case 180:
  743. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  744. break;
  745. case 90:
  746. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  747. break;
  748. case 270:
  749. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  750. break;
  751. //case 0:
  752. default:
  753. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  754. break;
  755. }
  756. if (dontFlip) {
  757. rotateC = -rotateC; rotateD = -rotateD;
  758. }
  759. var offsetCanvasX, offsetCanvasY;
  760. var width, height;
  761. if (rotateA === 0) {
  762. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  763. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  764. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  765. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  766. } else {
  767. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  768. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  769. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  770. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  771. }
  772. // creating transform for the following operations:
  773. // translate(-centerX, -centerY), rotate and flip vertically,
  774. // scale, and translate(offsetCanvasX, offsetCanvasY)
  775. this.transform = [
  776. rotateA * scale,
  777. rotateB * scale,
  778. rotateC * scale,
  779. rotateD * scale,
  780. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  781. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  782. ];
  783. this.width = width;
  784. this.height = height;
  785. this.fontScale = scale;
  786. }
  787. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  788. /**
  789. * Clones viewport with additional properties.
  790. * @param args {Object} (optional) If specified, may contain the 'scale' or
  791. * 'rotation' properties to override the corresponding properties in
  792. * the cloned viewport.
  793. * @returns {PDFJS.PageViewport} Cloned viewport.
  794. */
  795. clone: function PageViewPort_clone(args) {
  796. args = args || {};
  797. var scale = 'scale' in args ? args.scale : this.scale;
  798. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  799. return new PageViewport(this.viewBox.slice(), scale, rotation,
  800. this.offsetX, this.offsetY, args.dontFlip);
  801. },
  802. /**
  803. * Converts PDF point to the viewport coordinates. For examples, useful for
  804. * converting PDF location into canvas pixel coordinates.
  805. * @param x {number} X coordinate.
  806. * @param y {number} Y coordinate.
  807. * @returns {Object} Object that contains 'x' and 'y' properties of the
  808. * point in the viewport coordinate space.
  809. * @see {@link convertToPdfPoint}
  810. * @see {@link convertToViewportRectangle}
  811. */
  812. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  813. return Util.applyTransform([x, y], this.transform);
  814. },
  815. /**
  816. * Converts PDF rectangle to the viewport coordinates.
  817. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  818. * @returns {Array} Contains corresponding coordinates of the rectangle
  819. * in the viewport coordinate space.
  820. * @see {@link convertToViewportPoint}
  821. */
  822. convertToViewportRectangle:
  823. function PageViewport_convertToViewportRectangle(rect) {
  824. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  825. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  826. return [tl[0], tl[1], br[0], br[1]];
  827. },
  828. /**
  829. * Converts viewport coordinates to the PDF location. For examples, useful
  830. * for converting canvas pixel location into PDF one.
  831. * @param x {number} X coordinate.
  832. * @param y {number} Y coordinate.
  833. * @returns {Object} Object that contains 'x' and 'y' properties of the
  834. * point in the PDF coordinate space.
  835. * @see {@link convertToViewportPoint}
  836. */
  837. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  838. return Util.applyInverseTransform([x, y], this.transform);
  839. }
  840. };
  841. return PageViewport;
  842. })();
  843. var PDFStringTranslateTable = [
  844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  845. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  846. 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,
  847. 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,
  848. 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,
  849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  850. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  851. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  852. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  853. ];
  854. function stringToPDFString(str) {
  855. var i, n = str.length, strBuf = [];
  856. if (str[0] === '\xFE' && str[1] === '\xFF') {
  857. // UTF16BE BOM
  858. for (i = 2; i < n; i += 2) {
  859. strBuf.push(String.fromCharCode(
  860. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  861. }
  862. } else {
  863. for (i = 0; i < n; ++i) {
  864. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  865. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  866. }
  867. }
  868. return strBuf.join('');
  869. }
  870. function stringToUTF8String(str) {
  871. return decodeURIComponent(escape(str));
  872. }
  873. function isEmptyObj(obj) {
  874. for (var key in obj) {
  875. return false;
  876. }
  877. return true;
  878. }
  879. function isBool(v) {
  880. return typeof v === 'boolean';
  881. }
  882. function isInt(v) {
  883. return typeof v === 'number' && ((v | 0) === v);
  884. }
  885. function isNum(v) {
  886. return typeof v === 'number';
  887. }
  888. function isString(v) {
  889. return typeof v === 'string';
  890. }
  891. function isNull(v) {
  892. return v === null;
  893. }
  894. function isName(v) {
  895. return v instanceof Name;
  896. }
  897. function isCmd(v, cmd) {
  898. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  899. }
  900. function isDict(v, type) {
  901. if (!(v instanceof Dict)) {
  902. return false;
  903. }
  904. if (!type) {
  905. return true;
  906. }
  907. var dictType = v.get('Type');
  908. return isName(dictType) && dictType.name === type;
  909. }
  910. function isArray(v) {
  911. return v instanceof Array;
  912. }
  913. function isStream(v) {
  914. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  915. }
  916. function isArrayBuffer(v) {
  917. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  918. }
  919. function isRef(v) {
  920. return v instanceof Ref;
  921. }
  922. /**
  923. * Promise Capability object.
  924. *
  925. * @typedef {Object} PromiseCapability
  926. * @property {Promise} promise - A promise object.
  927. * @property {function} resolve - Fullfills the promise.
  928. * @property {function} reject - Rejects the promise.
  929. */
  930. /**
  931. * Creates a promise capability object.
  932. * @alias PDFJS.createPromiseCapability
  933. *
  934. * @return {PromiseCapability} A capability object contains:
  935. * - a Promise, resolve and reject methods.
  936. */
  937. function createPromiseCapability() {
  938. var capability = {};
  939. capability.promise = new Promise(function (resolve, reject) {
  940. capability.resolve = resolve;
  941. capability.reject = reject;
  942. });
  943. return capability;
  944. }
  945. PDFJS.createPromiseCapability = createPromiseCapability;
  946. /**
  947. * Polyfill for Promises:
  948. * The following promise implementation tries to generally implement the
  949. * Promise/A+ spec. Some notable differences from other promise libaries are:
  950. * - There currently isn't a seperate deferred and promise object.
  951. * - Unhandled rejections eventually show an error if they aren't handled.
  952. *
  953. * Based off of the work in:
  954. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  955. */
  956. (function PromiseClosure() {
  957. if (globalScope.Promise) {
  958. // Promises existing in the DOM/Worker, checking presence of all/resolve
  959. if (typeof globalScope.Promise.all !== 'function') {
  960. globalScope.Promise.all = function (iterable) {
  961. var count = 0, results = [], resolve, reject;
  962. var promise = new globalScope.Promise(function (resolve_, reject_) {
  963. resolve = resolve_;
  964. reject = reject_;
  965. });
  966. iterable.forEach(function (p, i) {
  967. count++;
  968. p.then(function (result) {
  969. results[i] = result;
  970. count--;
  971. if (count === 0) {
  972. resolve(results);
  973. }
  974. }, reject);
  975. });
  976. if (count === 0) {
  977. resolve(results);
  978. }
  979. return promise;
  980. };
  981. }
  982. if (typeof globalScope.Promise.resolve !== 'function') {
  983. globalScope.Promise.resolve = function (value) {
  984. return new globalScope.Promise(function (resolve) { resolve(value); });
  985. };
  986. }
  987. if (typeof globalScope.Promise.reject !== 'function') {
  988. globalScope.Promise.reject = function (reason) {
  989. return new globalScope.Promise(function (resolve, reject) {
  990. reject(reason);
  991. });
  992. };
  993. }
  994. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  995. globalScope.Promise.prototype.catch = function (onReject) {
  996. return globalScope.Promise.prototype.then(undefined, onReject);
  997. };
  998. }
  999. return;
  1000. }
  1001. var STATUS_PENDING = 0;
  1002. var STATUS_RESOLVED = 1;
  1003. var STATUS_REJECTED = 2;
  1004. // In an attempt to avoid silent exceptions, unhandled rejections are
  1005. // tracked and if they aren't handled in a certain amount of time an
  1006. // error is logged.
  1007. var REJECTION_TIMEOUT = 500;
  1008. var HandlerManager = {
  1009. handlers: [],
  1010. running: false,
  1011. unhandledRejections: [],
  1012. pendingRejectionCheck: false,
  1013. scheduleHandlers: function scheduleHandlers(promise) {
  1014. if (promise._status === STATUS_PENDING) {
  1015. return;
  1016. }
  1017. this.handlers = this.handlers.concat(promise._handlers);
  1018. promise._handlers = [];
  1019. if (this.running) {
  1020. return;
  1021. }
  1022. this.running = true;
  1023. setTimeout(this.runHandlers.bind(this), 0);
  1024. },
  1025. runHandlers: function runHandlers() {
  1026. var RUN_TIMEOUT = 1; // ms
  1027. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1028. while (this.handlers.length > 0) {
  1029. var handler = this.handlers.shift();
  1030. var nextStatus = handler.thisPromise._status;
  1031. var nextValue = handler.thisPromise._value;
  1032. try {
  1033. if (nextStatus === STATUS_RESOLVED) {
  1034. if (typeof handler.onResolve === 'function') {
  1035. nextValue = handler.onResolve(nextValue);
  1036. }
  1037. } else if (typeof handler.onReject === 'function') {
  1038. nextValue = handler.onReject(nextValue);
  1039. nextStatus = STATUS_RESOLVED;
  1040. if (handler.thisPromise._unhandledRejection) {
  1041. this.removeUnhandeledRejection(handler.thisPromise);
  1042. }
  1043. }
  1044. } catch (ex) {
  1045. nextStatus = STATUS_REJECTED;
  1046. nextValue = ex;
  1047. }
  1048. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1049. if (Date.now() >= timeoutAt) {
  1050. break;
  1051. }
  1052. }
  1053. if (this.handlers.length > 0) {
  1054. setTimeout(this.runHandlers.bind(this), 0);
  1055. return;
  1056. }
  1057. this.running = false;
  1058. },
  1059. addUnhandledRejection: function addUnhandledRejection(promise) {
  1060. this.unhandledRejections.push({
  1061. promise: promise,
  1062. time: Date.now()
  1063. });
  1064. this.scheduleRejectionCheck();
  1065. },
  1066. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1067. promise._unhandledRejection = false;
  1068. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1069. if (this.unhandledRejections[i].promise === promise) {
  1070. this.unhandledRejections.splice(i);
  1071. i--;
  1072. }
  1073. }
  1074. },
  1075. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1076. if (this.pendingRejectionCheck) {
  1077. return;
  1078. }
  1079. this.pendingRejectionCheck = true;
  1080. setTimeout(function rejectionCheck() {
  1081. this.pendingRejectionCheck = false;
  1082. var now = Date.now();
  1083. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1084. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1085. var unhandled = this.unhandledRejections[i].promise._value;
  1086. var msg = 'Unhandled rejection: ' + unhandled;
  1087. if (unhandled.stack) {
  1088. msg += '\n' + unhandled.stack;
  1089. }
  1090. warn(msg);
  1091. this.unhandledRejections.splice(i);
  1092. i--;
  1093. }
  1094. }
  1095. if (this.unhandledRejections.length) {
  1096. this.scheduleRejectionCheck();
  1097. }
  1098. }.bind(this), REJECTION_TIMEOUT);
  1099. }
  1100. };
  1101. function Promise(resolver) {
  1102. this._status = STATUS_PENDING;
  1103. this._handlers = [];
  1104. try {
  1105. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1106. } catch (e) {
  1107. this._reject(e);
  1108. }
  1109. }
  1110. /**
  1111. * Builds a promise that is resolved when all the passed in promises are
  1112. * resolved.
  1113. * @param {array} array of data and/or promises to wait for.
  1114. * @return {Promise} New dependant promise.
  1115. */
  1116. Promise.all = function Promise_all(promises) {
  1117. var resolveAll, rejectAll;
  1118. var deferred = new Promise(function (resolve, reject) {
  1119. resolveAll = resolve;
  1120. rejectAll = reject;
  1121. });
  1122. var unresolved = promises.length;
  1123. var results = [];
  1124. if (unresolved === 0) {
  1125. resolveAll(results);
  1126. return deferred;
  1127. }
  1128. function reject(reason) {
  1129. if (deferred._status === STATUS_REJECTED) {
  1130. return;
  1131. }
  1132. results = [];
  1133. rejectAll(reason);
  1134. }
  1135. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1136. var promise = promises[i];
  1137. var resolve = (function(i) {
  1138. return function(value) {
  1139. if (deferred._status === STATUS_REJECTED) {
  1140. return;
  1141. }
  1142. results[i] = value;
  1143. unresolved--;
  1144. if (unresolved === 0) {
  1145. resolveAll(results);
  1146. }
  1147. };
  1148. })(i);
  1149. if (Promise.isPromise(promise)) {
  1150. promise.then(resolve, reject);
  1151. } else {
  1152. resolve(promise);
  1153. }
  1154. }
  1155. return deferred;
  1156. };
  1157. /**
  1158. * Checks if the value is likely a promise (has a 'then' function).
  1159. * @return {boolean} true if value is thenable
  1160. */
  1161. Promise.isPromise = function Promise_isPromise(value) {
  1162. return value && typeof value.then === 'function';
  1163. };
  1164. /**
  1165. * Creates resolved promise
  1166. * @param value resolve value
  1167. * @returns {Promise}
  1168. */
  1169. Promise.resolve = function Promise_resolve(value) {
  1170. return new Promise(function (resolve) { resolve(value); });
  1171. };
  1172. /**
  1173. * Creates rejected promise
  1174. * @param reason rejection value
  1175. * @returns {Promise}
  1176. */
  1177. Promise.reject = function Promise_reject(reason) {
  1178. return new Promise(function (resolve, reject) { reject(reason); });
  1179. };
  1180. Promise.prototype = {
  1181. _status: null,
  1182. _value: null,
  1183. _handlers: null,
  1184. _unhandledRejection: null,
  1185. _updateStatus: function Promise__updateStatus(status, value) {
  1186. if (this._status === STATUS_RESOLVED ||
  1187. this._status === STATUS_REJECTED) {
  1188. return;
  1189. }
  1190. if (status === STATUS_RESOLVED &&
  1191. Promise.isPromise(value)) {
  1192. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1193. this._updateStatus.bind(this, STATUS_REJECTED));
  1194. return;
  1195. }
  1196. this._status = status;
  1197. this._value = value;
  1198. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1199. this._unhandledRejection = true;
  1200. HandlerManager.addUnhandledRejection(this);
  1201. }
  1202. HandlerManager.scheduleHandlers(this);
  1203. },
  1204. _resolve: function Promise_resolve(value) {
  1205. this._updateStatus(STATUS_RESOLVED, value);
  1206. },
  1207. _reject: function Promise_reject(reason) {
  1208. this._updateStatus(STATUS_REJECTED, reason);
  1209. },
  1210. then: function Promise_then(onResolve, onReject) {
  1211. var nextPromise = new Promise(function (resolve, reject) {
  1212. this.resolve = resolve;
  1213. this.reject = reject;
  1214. });
  1215. this._handlers.push({
  1216. thisPromise: this,
  1217. onResolve: onResolve,
  1218. onReject: onReject,
  1219. nextPromise: nextPromise
  1220. });
  1221. HandlerManager.scheduleHandlers(this);
  1222. return nextPromise;
  1223. },
  1224. catch: function Promise_catch(onReject) {
  1225. return this.then(undefined, onReject);
  1226. }
  1227. };
  1228. globalScope.Promise = Promise;
  1229. })();
  1230. var StatTimer = (function StatTimerClosure() {
  1231. function rpad(str, pad, length) {
  1232. while (str.length < length) {
  1233. str += pad;
  1234. }
  1235. return str;
  1236. }
  1237. function StatTimer() {
  1238. this.started = {};
  1239. this.times = [];
  1240. this.enabled = true;
  1241. }
  1242. StatTimer.prototype = {
  1243. time: function StatTimer_time(name) {
  1244. if (!this.enabled) {
  1245. return;
  1246. }
  1247. if (name in this.started) {
  1248. warn('Timer is already running for ' + name);
  1249. }
  1250. this.started[name] = Date.now();
  1251. },
  1252. timeEnd: function StatTimer_timeEnd(name) {
  1253. if (!this.enabled) {
  1254. return;
  1255. }
  1256. if (!(name in this.started)) {
  1257. warn('Timer has not been started for ' + name);
  1258. }
  1259. this.times.push({
  1260. 'name': name,
  1261. 'start': this.started[name],
  1262. 'end': Date.now()
  1263. });
  1264. // Remove timer from started so it can be called again.
  1265. delete this.started[name];
  1266. },
  1267. toString: function StatTimer_toString() {
  1268. var i, ii;
  1269. var times = this.times;
  1270. var out = '';
  1271. // Find the longest name for padding purposes.
  1272. var longest = 0;
  1273. for (i = 0, ii = times.length; i < ii; ++i) {
  1274. var name = times[i]['name'];
  1275. if (name.length > longest) {
  1276. longest = name.length;
  1277. }
  1278. }
  1279. for (i = 0, ii = times.length; i < ii; ++i) {
  1280. var span = times[i];
  1281. var duration = span.end - span.start;
  1282. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1283. }
  1284. return out;
  1285. }
  1286. };
  1287. return StatTimer;
  1288. })();
  1289. PDFJS.createBlob = function createBlob(data, contentType) {
  1290. if (typeof Blob !== 'undefined') {
  1291. return new Blob([data], { type: contentType });
  1292. }
  1293. // Blob builder is deprecated in FF14 and removed in FF18.
  1294. var bb = new MozBlobBuilder();
  1295. bb.append(data);
  1296. return bb.getBlob(contentType);
  1297. };
  1298. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1299. // Blob/createObjectURL is not available, falling back to data schema.
  1300. var digits =
  1301. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1302. return function createObjectURL(data, contentType) {
  1303. if (!PDFJS.disableCreateObjectURL &&
  1304. typeof URL !== 'undefined' && URL.createObjectURL) {
  1305. var blob = PDFJS.createBlob(data, contentType);
  1306. return URL.createObjectURL(blob);
  1307. }
  1308. var buffer = 'data:' + contentType + ';base64,';
  1309. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1310. var b1 = data[i] & 0xFF;
  1311. var b2 = data[i + 1] & 0xFF;
  1312. var b3 = data[i + 2] & 0xFF;
  1313. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1314. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1315. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1316. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1317. }
  1318. return buffer;
  1319. };
  1320. })();
  1321. function MessageHandler(name, comObj) {
  1322. this.name = name;
  1323. this.comObj = comObj;
  1324. this.callbackIndex = 1;
  1325. this.postMessageTransfers = true;
  1326. var callbacksCapabilities = this.callbacksCapabilities = {};
  1327. var ah = this.actionHandler = {};
  1328. ah['console_log'] = [function ahConsoleLog(data) {
  1329. console.log.apply(console, data);
  1330. }];
  1331. ah['console_error'] = [function ahConsoleError(data) {
  1332. console.error.apply(console, data);
  1333. }];
  1334. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1335. UnsupportedManager.notify(data);
  1336. }];
  1337. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1338. var data = event.data;
  1339. if (data.isReply) {
  1340. var callbackId = data.callbackId;
  1341. if (data.callbackId in callbacksCapabilities) {
  1342. var callback = callbacksCapabilities[callbackId];
  1343. delete callbacksCapabilities[callbackId];
  1344. if ('error' in data) {
  1345. callback.reject(data.error);
  1346. } else {
  1347. callback.resolve(data.data);
  1348. }
  1349. } else {
  1350. error('Cannot resolve callback ' + callbackId);
  1351. }
  1352. } else if (data.action in ah) {
  1353. var action = ah[data.action];
  1354. if (data.callbackId) {
  1355. Promise.resolve().then(function () {
  1356. return action[0].call(action[1], data.data);
  1357. }).then(function (result) {
  1358. comObj.postMessage({
  1359. isReply: true,
  1360. callbackId: data.callbackId,
  1361. data: result
  1362. });
  1363. }, function (reason) {
  1364. comObj.postMessage({
  1365. isReply: true,
  1366. callbackId: data.callbackId,
  1367. error: reason
  1368. });
  1369. });
  1370. } else {
  1371. action[0].call(action[1], data.data);
  1372. }
  1373. } else {
  1374. error('Unknown action from worker: ' + data.action);
  1375. }
  1376. };
  1377. }
  1378. MessageHandler.prototype = {
  1379. on: function messageHandlerOn(actionName, handler, scope) {
  1380. var ah = this.actionHandler;
  1381. if (ah[actionName]) {
  1382. error('There is already an actionName called "' + actionName + '"');
  1383. }
  1384. ah[actionName] = [handler, scope];
  1385. },
  1386. /**
  1387. * Sends a message to the comObj to invoke the action with the supplied data.
  1388. * @param {String} actionName Action to call.
  1389. * @param {JSON} data JSON data to send.
  1390. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1391. */
  1392. send: function messageHandlerSend(actionName, data, transfers) {
  1393. var message = {
  1394. action: actionName,
  1395. data: data
  1396. };
  1397. this.postMessage(message, transfers);
  1398. },
  1399. /**
  1400. * Sends a message to the comObj to invoke the action with the supplied data.
  1401. * Expects that other side will callback with the response.
  1402. * @param {String} actionName Action to call.
  1403. * @param {JSON} data JSON data to send.
  1404. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1405. * @returns {Promise} Promise to be resolved with response data.
  1406. */
  1407. sendWithPromise:
  1408. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1409. var callbackId = this.callbackIndex++;
  1410. var message = {
  1411. action: actionName,
  1412. data: data,
  1413. callbackId: callbackId
  1414. };
  1415. var capability = createPromiseCapability();
  1416. this.callbacksCapabilities[callbackId] = capability;
  1417. try {
  1418. this.postMessage(message, transfers);
  1419. } catch (e) {
  1420. capability.reject(e);
  1421. }
  1422. return capability.promise;
  1423. },
  1424. /**
  1425. * Sends raw message to the comObj.
  1426. * @private
  1427. * @param message {Object} Raw message.
  1428. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1429. */
  1430. postMessage: function (message, transfers) {
  1431. if (transfers && this.postMessageTransfers) {
  1432. this.comObj.postMessage(message, transfers);
  1433. } else {
  1434. this.comObj.postMessage(message);
  1435. }
  1436. }
  1437. };
  1438. function loadJpegStream(id, imageUrl, objs) {
  1439. var img = new Image();
  1440. img.onload = (function loadJpegStream_onloadClosure() {
  1441. objs.resolve(id, img);
  1442. });
  1443. img.onerror = (function loadJpegStream_onerrorClosure() {
  1444. objs.resolve(id, null);
  1445. warn('Error during JPEG image loading');
  1446. });
  1447. img.src = imageUrl;
  1448. }
  1449. var NetworkManager = (function NetworkManagerClosure() {
  1450. var OK_RESPONSE = 200;
  1451. var PARTIAL_CONTENT_RESPONSE = 206;
  1452. function NetworkManager(url, args) {
  1453. this.url = url;
  1454. args = args || {};
  1455. this.isHttp = /^https?:/i.test(url);
  1456. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1457. this.withCredentials = args.withCredentials || false;
  1458. this.getXhr = args.getXhr ||
  1459. function NetworkManager_getXhr() {
  1460. return new XMLHttpRequest();
  1461. };
  1462. this.currXhrId = 0;
  1463. this.pendingRequests = {};
  1464. this.loadedRequests = {};
  1465. }
  1466. function getArrayBuffer(xhr) {
  1467. var data = xhr.response;
  1468. if (typeof data !== 'string') {
  1469. return data;
  1470. }
  1471. var length = data.length;
  1472. var array = new Uint8Array(length);
  1473. for (var i = 0; i < length; i++) {
  1474. array[i] = data.charCodeAt(i) & 0xFF;
  1475. }
  1476. return array.buffer;
  1477. }
  1478. NetworkManager.prototype = {
  1479. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1480. var args = {
  1481. begin: begin,
  1482. end: end
  1483. };
  1484. for (var prop in listeners) {
  1485. args[prop] = listeners[prop];
  1486. }
  1487. return this.request(args);
  1488. },
  1489. requestFull: function NetworkManager_requestFull(listeners) {
  1490. return this.request(listeners);
  1491. },
  1492. request: function NetworkManager_request(args) {
  1493. var xhr = this.getXhr();
  1494. var xhrId = this.currXhrId++;
  1495. var pendingRequest = this.pendingRequests[xhrId] = {
  1496. xhr: xhr
  1497. };
  1498. xhr.open('GET', this.url);
  1499. xhr.withCredentials = this.withCredentials;
  1500. for (var property in this.httpHeaders) {
  1501. var value = this.httpHeaders[property];
  1502. if (typeof value === 'undefined') {
  1503. continue;
  1504. }
  1505. xhr.setRequestHeader(property, value);
  1506. }
  1507. if (this.isHttp && 'begin' in args && 'end' in args) {
  1508. var rangeStr = args.begin + '-' + (args.end - 1);
  1509. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1510. pendingRequest.expectedStatus = 206;
  1511. } else {
  1512. pendingRequest.expectedStatus = 200;
  1513. }
  1514. if (args.onProgressiveData) {
  1515. // Some legacy browsers might throw an exception.
  1516. try {
  1517. xhr.responseType = 'moz-chunked-arraybuffer';
  1518. } catch(e) {}
  1519. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1520. pendingRequest.onProgressiveData = args.onProgressiveData;
  1521. pendingRequest.mozChunked = true;
  1522. } else {
  1523. xhr.responseType = 'arraybuffer';
  1524. }
  1525. } else {
  1526. xhr.responseType = 'arraybuffer';
  1527. }
  1528. if (args.onError) {
  1529. xhr.onerror = function(evt) {
  1530. args.onError(xhr.status);
  1531. };
  1532. }
  1533. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1534. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1535. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1536. pendingRequest.onDone = args.onDone;
  1537. pendingRequest.onError = args.onError;
  1538. pendingRequest.onProgress = args.onProgress;
  1539. xhr.send(null);
  1540. return xhrId;
  1541. },
  1542. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1543. var pendingRequest = this.pendingRequests[xhrId];
  1544. if (!pendingRequest) {
  1545. // Maybe abortRequest was called...
  1546. return;
  1547. }
  1548. if (pendingRequest.mozChunked) {
  1549. var chunk = getArrayBuffer(pendingRequest.xhr);
  1550. pendingRequest.onProgressiveData(chunk);
  1551. }
  1552. var onProgress = pendingRequest.onProgress;
  1553. if (onProgress) {
  1554. onProgress(evt);
  1555. }
  1556. },
  1557. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1558. var pendingRequest = this.pendingRequests[xhrId];
  1559. if (!pendingRequest) {
  1560. // Maybe abortRequest was called...
  1561. return;
  1562. }
  1563. var xhr = pendingRequest.xhr;
  1564. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1565. pendingRequest.onHeadersReceived();
  1566. delete pendingRequest.onHeadersReceived;
  1567. }
  1568. if (xhr.readyState !== 4) {
  1569. return;
  1570. }
  1571. if (!(xhrId in this.pendingRequests)) {
  1572. // The XHR request might have been aborted in onHeadersReceived()
  1573. // callback, in which case we should abort request
  1574. return;
  1575. }
  1576. delete this.pendingRequests[xhrId];
  1577. // success status == 0 can be on ftp, file and other protocols
  1578. if (xhr.status === 0 && this.isHttp) {
  1579. if (pendingRequest.onError) {
  1580. pendingRequest.onError(xhr.status);
  1581. }
  1582. return;
  1583. }
  1584. var xhrStatus = xhr.status || OK_RESPONSE;
  1585. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1586. // "A server MAY ignore the Range header". This means it's possible to
  1587. // get a 200 rather than a 206 response from a range request.
  1588. var ok_response_on_range_request =
  1589. xhrStatus === OK_RESPONSE &&
  1590. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1591. if (!ok_response_on_range_request &&
  1592. xhrStatus !== pendingRequest.expectedStatus) {
  1593. if (pendingRequest.onError) {
  1594. pendingRequest.onError(xhr.status);
  1595. }
  1596. return;
  1597. }
  1598. this.loadedRequests[xhrId] = true;
  1599. var chunk = getArrayBuffer(xhr);
  1600. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1601. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1602. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1603. var begin = parseInt(matches[1], 10);
  1604. pendingRequest.onDone({
  1605. begin: begin,
  1606. chunk: chunk
  1607. });
  1608. } else if (pendingRequest.onProgressiveData) {
  1609. pendingRequest.onDone(null);
  1610. } else {
  1611. pendingRequest.onDone({
  1612. begin: 0,
  1613. chunk: chunk
  1614. });
  1615. }
  1616. },
  1617. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1618. for (var xhrId in this.pendingRequests) {
  1619. return true;
  1620. }
  1621. return false;
  1622. },
  1623. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1624. return this.pendingRequests[xhrId].xhr;
  1625. },
  1626. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1627. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1628. },
  1629. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1630. return xhrId in this.pendingRequests;
  1631. },
  1632. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1633. return xhrId in this.loadedRequests;
  1634. },
  1635. abortAllRequests: function NetworkManager_abortAllRequests() {
  1636. for (var xhrId in this.pendingRequests) {
  1637. this.abortRequest(xhrId | 0);
  1638. }
  1639. },
  1640. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1641. var xhr = this.pendingRequests[xhrId].xhr;
  1642. delete this.pendingRequests[xhrId];
  1643. xhr.abort();
  1644. }
  1645. };
  1646. return NetworkManager;
  1647. })();
  1648. var ChunkedStream = (function ChunkedStreamClosure() {
  1649. function ChunkedStream(length, chunkSize, manager) {
  1650. this.bytes = new Uint8Array(length);
  1651. this.start = 0;
  1652. this.pos = 0;
  1653. this.end = length;
  1654. this.chunkSize = chunkSize;
  1655. this.loadedChunks = [];
  1656. this.numChunksLoaded = 0;
  1657. this.numChunks = Math.ceil(length / chunkSize);
  1658. this.manager = manager;
  1659. this.progressiveDataLength = 0;
  1660. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1661. }
  1662. // required methods for a stream. if a particular stream does not
  1663. // implement these, an error should be thrown
  1664. ChunkedStream.prototype = {
  1665. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1666. var chunks = [];
  1667. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1668. if (!this.loadedChunks[chunk]) {
  1669. chunks.push(chunk);
  1670. }
  1671. }
  1672. return chunks;
  1673. },
  1674. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1675. return [this];
  1676. },
  1677. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1678. return this.numChunksLoaded === this.numChunks;
  1679. },
  1680. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1681. var end = begin + chunk.byteLength;
  1682. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1683. // Using this.length is inaccurate here since this.start can be moved
  1684. // See ChunkedStream.moveStart()
  1685. var length = this.bytes.length;
  1686. assert(end % this.chunkSize === 0 || end === length,
  1687. 'Bad end offset: ' + end);
  1688. this.bytes.set(new Uint8Array(chunk), begin);
  1689. var chunkSize = this.chunkSize;
  1690. var beginChunk = Math.floor(begin / chunkSize);
  1691. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1692. var curChunk;
  1693. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1694. if (!this.loadedChunks[curChunk]) {
  1695. this.loadedChunks[curChunk] = true;
  1696. ++this.numChunksLoaded;
  1697. }
  1698. }
  1699. },
  1700. onReceiveProgressiveData:
  1701. function ChunkedStream_onReceiveProgressiveData(data) {
  1702. var position = this.progressiveDataLength;
  1703. var beginChunk = Math.floor(position / this.chunkSize);
  1704. this.bytes.set(new Uint8Array(data), position);
  1705. position += data.byteLength;
  1706. this.progressiveDataLength = position;
  1707. var endChunk = position >= this.end ? this.numChunks :
  1708. Math.floor(position / this.chunkSize);
  1709. var curChunk;
  1710. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1711. if (!this.loadedChunks[curChunk]) {
  1712. this.loadedChunks[curChunk] = true;
  1713. ++this.numChunksLoaded;
  1714. }
  1715. }
  1716. },
  1717. ensureByte: function ChunkedStream_ensureByte(pos) {
  1718. var chunk = Math.floor(pos / this.chunkSize);
  1719. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1720. return;
  1721. }
  1722. if (!this.loadedChunks[chunk]) {
  1723. throw new MissingDataException(pos, pos + 1);
  1724. }
  1725. this.lastSuccessfulEnsureByteChunk = chunk;
  1726. },
  1727. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1728. if (begin >= end) {
  1729. return;
  1730. }
  1731. if (end <= this.progressiveDataLength) {
  1732. return;
  1733. }
  1734. var chunkSize = this.chunkSize;
  1735. var beginChunk = Math.floor(begin / chunkSize);
  1736. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1737. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1738. if (!this.loadedChunks[chunk]) {
  1739. throw new MissingDataException(begin, end);
  1740. }
  1741. }
  1742. },
  1743. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1744. var chunk, n;
  1745. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1746. if (!this.loadedChunks[chunk]) {
  1747. return chunk;
  1748. }
  1749. }
  1750. // Wrap around to beginning
  1751. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1752. if (!this.loadedChunks[chunk]) {
  1753. return chunk;
  1754. }
  1755. }
  1756. return null;
  1757. },
  1758. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1759. return !!this.loadedChunks[chunk];
  1760. },
  1761. get length() {
  1762. return this.end - this.start;
  1763. },
  1764. get isEmpty() {
  1765. return this.length === 0;
  1766. },
  1767. getByte: function ChunkedStream_getByte() {
  1768. var pos = this.pos;
  1769. if (pos >= this.end) {
  1770. return -1;
  1771. }
  1772. this.ensureByte(pos);
  1773. return this.bytes[this.pos++];
  1774. },
  1775. getUint16: function ChunkedStream_getUint16() {
  1776. var b0 = this.getByte();
  1777. var b1 = this.getByte();
  1778. if (b0 === -1 || b1 === -1) {
  1779. return -1;
  1780. }
  1781. return (b0 << 8) + b1;
  1782. },
  1783. getInt32: function ChunkedStream_getInt32() {
  1784. var b0 = this.getByte();
  1785. var b1 = this.getByte();
  1786. var b2 = this.getByte();
  1787. var b3 = this.getByte();
  1788. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1789. },
  1790. // returns subarray of original buffer
  1791. // should only be read
  1792. getBytes: function ChunkedStream_getBytes(length) {
  1793. var bytes = this.bytes;
  1794. var pos = this.pos;
  1795. var strEnd = this.end;
  1796. if (!length) {
  1797. this.ensureRange(pos, strEnd);
  1798. return bytes.subarray(pos, strEnd);
  1799. }
  1800. var end = pos + length;
  1801. if (end > strEnd) {
  1802. end = strEnd;
  1803. }
  1804. this.ensureRange(pos, end);
  1805. this.pos = end;
  1806. return bytes.subarray(pos, end);
  1807. },
  1808. peekByte: function ChunkedStream_peekByte() {
  1809. var peekedByte = this.getByte();
  1810. this.pos--;
  1811. return peekedByte;
  1812. },
  1813. peekBytes: function ChunkedStream_peekBytes(length) {
  1814. var bytes = this.getBytes(length);
  1815. this.pos -= bytes.length;
  1816. return bytes;
  1817. },
  1818. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1819. this.ensureRange(begin, end);
  1820. return this.bytes.subarray(begin, end);
  1821. },
  1822. skip: function ChunkedStream_skip(n) {
  1823. if (!n) {
  1824. n = 1;
  1825. }
  1826. this.pos += n;
  1827. },
  1828. reset: function ChunkedStream_reset() {
  1829. this.pos = this.start;
  1830. },
  1831. moveStart: function ChunkedStream_moveStart() {
  1832. this.start = this.pos;
  1833. },
  1834. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1835. this.ensureRange(start, start + length);
  1836. function ChunkedStreamSubstream() {}
  1837. ChunkedStreamSubstream.prototype = Object.create(this);
  1838. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1839. var chunkSize = this.chunkSize;
  1840. var beginChunk = Math.floor(this.start / chunkSize);
  1841. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1842. var missingChunks = [];
  1843. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1844. if (!this.loadedChunks[chunk]) {
  1845. missingChunks.push(chunk);
  1846. }
  1847. }
  1848. return missingChunks;
  1849. };
  1850. var subStream = new ChunkedStreamSubstream();
  1851. subStream.pos = subStream.start = start;
  1852. subStream.end = start + length || this.end;
  1853. subStream.dict = dict;
  1854. return subStream;
  1855. },
  1856. isStream: true
  1857. };
  1858. return ChunkedStream;
  1859. })();
  1860. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1861. function ChunkedStreamManager(length, chunkSize, url, args) {
  1862. this.stream = new ChunkedStream(length, chunkSize, this);
  1863. this.length = length;
  1864. this.chunkSize = chunkSize;
  1865. this.url = url;
  1866. this.disableAutoFetch = args.disableAutoFetch;
  1867. var msgHandler = this.msgHandler = args.msgHandler;
  1868. if (args.chunkedViewerLoading) {
  1869. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1870. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1871. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1872. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1873. };
  1874. } else {
  1875. var getXhr = function getXhr() {
  1876. return new XMLHttpRequest();
  1877. };
  1878. this.networkManager = new NetworkManager(this.url, {
  1879. getXhr: getXhr,
  1880. httpHeaders: args.httpHeaders,
  1881. withCredentials: args.withCredentials
  1882. });
  1883. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1884. this.networkManager.requestRange(begin, end, {
  1885. onDone: this.onReceiveData.bind(this),
  1886. onProgress: this.onProgress.bind(this)
  1887. });
  1888. };
  1889. }
  1890. this.currRequestId = 0;
  1891. this.chunksNeededByRequest = {};
  1892. this.requestsByChunk = {};
  1893. this.callbacksByRequest = {};
  1894. this.progressiveDataLength = 0;
  1895. this._loadedStreamCapability = createPromiseCapability();
  1896. if (args.initialData) {
  1897. this.onReceiveData({chunk: args.initialData});
  1898. }
  1899. }
  1900. ChunkedStreamManager.prototype = {
  1901. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1902. return this._loadedStreamCapability.promise;
  1903. },
  1904. // Get all the chunks that are not yet loaded and groups them into
  1905. // contiguous ranges to load in as few requests as possible
  1906. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1907. var missingChunks = this.stream.getMissingChunks();
  1908. this.requestChunks(missingChunks);
  1909. return this._loadedStreamCapability.promise;
  1910. },
  1911. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1912. callback) {
  1913. var requestId = this.currRequestId++;
  1914. var chunksNeeded;
  1915. var i, ii;
  1916. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1917. for (i = 0, ii = chunks.length; i < ii; i++) {
  1918. if (!this.stream.hasChunk(chunks[i])) {
  1919. chunksNeeded[chunks[i]] = true;
  1920. }
  1921. }
  1922. if (isEmptyObj(chunksNeeded)) {
  1923. if (callback) {
  1924. callback();
  1925. }
  1926. return;
  1927. }
  1928. this.callbacksByRequest[requestId] = callback;
  1929. var chunksToRequest = [];
  1930. for (var chunk in chunksNeeded) {
  1931. chunk = chunk | 0;
  1932. if (!(chunk in this.requestsByChunk)) {
  1933. this.requestsByChunk[chunk] = [];
  1934. chunksToRequest.push(chunk);
  1935. }
  1936. this.requestsByChunk[chunk].push(requestId);
  1937. }
  1938. if (!chunksToRequest.length) {
  1939. return;
  1940. }
  1941. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1942. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1943. var groupedChunk = groupedChunksToRequest[i];
  1944. var begin = groupedChunk.beginChunk * this.chunkSize;
  1945. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1946. this.sendRequest(begin, end);
  1947. }
  1948. },
  1949. getStream: function ChunkedStreamManager_getStream() {
  1950. return this.stream;
  1951. },
  1952. // Loads any chunks in the requested range that are not yet loaded
  1953. requestRange: function ChunkedStreamManager_requestRange(
  1954. begin, end, callback) {
  1955. end = Math.min(end, this.length);
  1956. var beginChunk = this.getBeginChunk(begin);
  1957. var endChunk = this.getEndChunk(end);
  1958. var chunks = [];
  1959. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1960. chunks.push(chunk);
  1961. }
  1962. this.requestChunks(chunks, callback);
  1963. },
  1964. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1965. callback) {
  1966. ranges = ranges || [];
  1967. var chunksToRequest = [];
  1968. for (var i = 0; i < ranges.length; i++) {
  1969. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1970. var endChunk = this.getEndChunk(ranges[i].end);
  1971. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1972. if (chunksToRequest.indexOf(chunk) < 0) {
  1973. chunksToRequest.push(chunk);
  1974. }
  1975. }
  1976. }
  1977. chunksToRequest.sort(function(a, b) { return a - b; });
  1978. this.requestChunks(chunksToRequest, callback);
  1979. },
  1980. // Groups a sorted array of chunks into as few continguous larger
  1981. // chunks as possible
  1982. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1983. var groupedChunks = [];
  1984. var beginChunk = -1;
  1985. var prevChunk = -1;
  1986. for (var i = 0; i < chunks.length; ++i) {
  1987. var chunk = chunks[i];
  1988. if (beginChunk < 0) {
  1989. beginChunk = chunk;
  1990. }
  1991. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1992. groupedChunks.push({ beginChunk: beginChunk,
  1993. endChunk: prevChunk + 1 });
  1994. beginChunk = chunk;
  1995. }
  1996. if (i + 1 === chunks.length) {
  1997. groupedChunks.push({ beginChunk: beginChunk,
  1998. endChunk: chunk + 1 });
  1999. }
  2000. prevChunk = chunk;
  2001. }
  2002. return groupedChunks;
  2003. },
  2004. onProgress: function ChunkedStreamManager_onProgress(args) {
  2005. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2006. args.loaded);
  2007. this.msgHandler.send('DocProgress', {
  2008. loaded: bytesLoaded,
  2009. total: this.length
  2010. });
  2011. },
  2012. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2013. var chunk = args.chunk;
  2014. var isProgressive = args.begin === undefined;
  2015. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2016. var end = begin + chunk.byteLength;
  2017. var beginChunk = Math.floor(begin / this.chunkSize);
  2018. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2019. Math.ceil(end / this.chunkSize);
  2020. if (isProgressive) {
  2021. this.stream.onReceiveProgressiveData(chunk);
  2022. this.progressiveDataLength = end;
  2023. } else {
  2024. this.stream.onReceiveData(begin, chunk);
  2025. }
  2026. if (this.stream.allChunksLoaded()) {
  2027. this._loadedStreamCapability.resolve(this.stream);
  2028. }
  2029. var loadedRequests = [];
  2030. var i, requestId;
  2031. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2032. // The server might return more chunks than requested
  2033. var requestIds = this.requestsByChunk[chunk] || [];
  2034. delete this.requestsByChunk[chunk];
  2035. for (i = 0; i < requestIds.length; ++i) {
  2036. requestId = requestIds[i];
  2037. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2038. if (chunk in chunksNeeded) {
  2039. delete chunksNeeded[chunk];
  2040. }
  2041. if (!isEmptyObj(chunksNeeded)) {
  2042. continue;
  2043. }
  2044. loadedRequests.push(requestId);
  2045. }
  2046. }
  2047. // If there are no pending requests, automatically fetch the next
  2048. // unfetched chunk of the PDF
  2049. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2050. var nextEmptyChunk;
  2051. if (this.stream.numChunksLoaded === 1) {
  2052. // This is a special optimization so that after fetching the first
  2053. // chunk, rather than fetching the second chunk, we fetch the last
  2054. // chunk.
  2055. var lastChunk = this.stream.numChunks - 1;
  2056. if (!this.stream.hasChunk(lastChunk)) {
  2057. nextEmptyChunk = lastChunk;
  2058. }
  2059. } else {
  2060. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2061. }
  2062. if (isInt(nextEmptyChunk)) {
  2063. this.requestChunks([nextEmptyChunk]);
  2064. }
  2065. }
  2066. for (i = 0; i < loadedRequests.length; ++i) {
  2067. requestId = loadedRequests[i];
  2068. var callback = this.callbacksByRequest[requestId];
  2069. delete this.callbacksByRequest[requestId];
  2070. if (callback) {
  2071. callback();
  2072. }
  2073. }
  2074. this.msgHandler.send('DocProgress', {
  2075. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2076. total: this.length
  2077. });
  2078. },
  2079. onError: function ChunkedStreamManager_onError(err) {
  2080. this._loadedStreamCapability.reject(err);
  2081. },
  2082. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2083. var chunk = Math.floor(begin / this.chunkSize);
  2084. return chunk;
  2085. },
  2086. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2087. if (end % this.chunkSize === 0) {
  2088. return end / this.chunkSize;
  2089. }
  2090. // 0 -> 0
  2091. // 1 -> 1
  2092. // 99 -> 1
  2093. // 100 -> 1
  2094. // 101 -> 2
  2095. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2096. return chunk;
  2097. }
  2098. };
  2099. return ChunkedStreamManager;
  2100. })();
  2101. // The maximum number of bytes fetched per range request
  2102. var RANGE_CHUNK_SIZE = 65536;
  2103. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2104. var BasePdfManager = (function BasePdfManagerClosure() {
  2105. function BasePdfManager() {
  2106. throw new Error('Cannot initialize BaseManagerManager');
  2107. }
  2108. BasePdfManager.prototype = {
  2109. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2110. throw new NotImplementedException();
  2111. },
  2112. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2113. return this.ensure(this.pdfDocument, prop, args);
  2114. },
  2115. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2116. return this.ensure(this.pdfDocument.xref, prop, args);
  2117. },
  2118. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2119. return this.ensure(this.pdfDocument.catalog, prop, args);
  2120. },
  2121. getPage: function BasePdfManager_pagePage(pageIndex) {
  2122. return this.pdfDocument.getPage(pageIndex);
  2123. },
  2124. cleanup: function BasePdfManager_cleanup() {
  2125. return this.pdfDocument.cleanup();
  2126. },
  2127. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2128. return new NotImplementedException();
  2129. },
  2130. requestRange: function BasePdfManager_ensure(begin, end) {
  2131. return new NotImplementedException();
  2132. },
  2133. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2134. return new NotImplementedException();
  2135. },
  2136. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2137. return new NotImplementedException();
  2138. },
  2139. updatePassword: function BasePdfManager_updatePassword(password) {
  2140. this.pdfDocument.xref.password = this.password = password;
  2141. if (this._passwordChangedCapability) {
  2142. this._passwordChangedCapability.resolve();
  2143. }
  2144. },
  2145. passwordChanged: function BasePdfManager_passwordChanged() {
  2146. this._passwordChangedCapability = createPromiseCapability();
  2147. return this._passwordChangedCapability.promise;
  2148. },
  2149. terminate: function BasePdfManager_terminate() {
  2150. return new NotImplementedException();
  2151. }
  2152. };
  2153. return BasePdfManager;
  2154. })();
  2155. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2156. function LocalPdfManager(data, password) {
  2157. var stream = new Stream(data);
  2158. this.pdfDocument = new PDFDocument(this, stream, password);
  2159. this._loadedStreamCapability = createPromiseCapability();
  2160. this._loadedStreamCapability.resolve(stream);
  2161. }
  2162. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2163. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2164. LocalPdfManager.prototype.ensure =
  2165. function LocalPdfManager_ensure(obj, prop, args) {
  2166. return new Promise(function (resolve, reject) {
  2167. try {
  2168. var value = obj[prop];
  2169. var result;
  2170. if (typeof value === 'function') {
  2171. result = value.apply(obj, args);
  2172. } else {
  2173. result = value;
  2174. }
  2175. resolve(result);
  2176. } catch (e) {
  2177. reject(e);
  2178. }
  2179. });
  2180. };
  2181. LocalPdfManager.prototype.requestRange =
  2182. function LocalPdfManager_requestRange(begin, end) {
  2183. return Promise.resolve();
  2184. };
  2185. LocalPdfManager.prototype.requestLoadedStream =
  2186. function LocalPdfManager_requestLoadedStream() {
  2187. };
  2188. LocalPdfManager.prototype.onLoadedStream =
  2189. function LocalPdfManager_getLoadedStream() {
  2190. return this._loadedStreamCapability.promise;
  2191. };
  2192. LocalPdfManager.prototype.terminate =
  2193. function LocalPdfManager_terminate() {
  2194. return;
  2195. };
  2196. return LocalPdfManager;
  2197. })();
  2198. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2199. function NetworkPdfManager(args, msgHandler) {
  2200. this.msgHandler = msgHandler;
  2201. var params = {
  2202. msgHandler: msgHandler,
  2203. httpHeaders: args.httpHeaders,
  2204. withCredentials: args.withCredentials,
  2205. chunkedViewerLoading: args.chunkedViewerLoading,
  2206. disableAutoFetch: args.disableAutoFetch,
  2207. initialData: args.initialData
  2208. };
  2209. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2210. args.url, params);
  2211. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2212. args.password);
  2213. }
  2214. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2215. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2216. NetworkPdfManager.prototype.ensure =
  2217. function NetworkPdfManager_ensure(obj, prop, args) {
  2218. var pdfManager = this;
  2219. return new Promise(function (resolve, reject) {
  2220. function ensureHelper() {
  2221. try {
  2222. var result;
  2223. var value = obj[prop];
  2224. if (typeof value === 'function') {
  2225. result = value.apply(obj, args);
  2226. } else {
  2227. result = value;
  2228. }
  2229. resolve(result);
  2230. } catch(e) {
  2231. if (!(e instanceof MissingDataException)) {
  2232. reject(e);
  2233. return;
  2234. }
  2235. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2236. }
  2237. }
  2238. ensureHelper();
  2239. });
  2240. };
  2241. NetworkPdfManager.prototype.requestRange =
  2242. function NetworkPdfManager_requestRange(begin, end) {
  2243. return new Promise(function (resolve) {
  2244. this.streamManager.requestRange(begin, end, function() {
  2245. resolve();
  2246. });
  2247. }.bind(this));
  2248. };
  2249. NetworkPdfManager.prototype.requestLoadedStream =
  2250. function NetworkPdfManager_requestLoadedStream() {
  2251. this.streamManager.requestAllChunks();
  2252. };
  2253. NetworkPdfManager.prototype.sendProgressiveData =
  2254. function NetworkPdfManager_sendProgressiveData(chunk) {
  2255. this.streamManager.onReceiveData({ chunk: chunk });
  2256. };
  2257. NetworkPdfManager.prototype.onLoadedStream =
  2258. function NetworkPdfManager_getLoadedStream() {
  2259. return this.streamManager.onLoadedStream();
  2260. };
  2261. NetworkPdfManager.prototype.terminate =
  2262. function NetworkPdfManager_terminate() {
  2263. this.streamManager.networkManager.abortAllRequests();
  2264. };
  2265. return NetworkPdfManager;
  2266. })();
  2267. var Page = (function PageClosure() {
  2268. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2269. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2270. this.pdfManager = pdfManager;
  2271. this.pageIndex = pageIndex;
  2272. this.pageDict = pageDict;
  2273. this.xref = xref;
  2274. this.ref = ref;
  2275. this.fontCache = fontCache;
  2276. this.idCounters = {
  2277. obj: 0
  2278. };
  2279. this.resourcesPromise = null;
  2280. }
  2281. Page.prototype = {
  2282. getPageProp: function Page_getPageProp(key) {
  2283. return this.pageDict.get(key);
  2284. },
  2285. getInheritedPageProp: function Page_inheritPageProp(key) {
  2286. var dict = this.pageDict;
  2287. var value = dict.get(key);
  2288. while (value === undefined) {
  2289. dict = dict.get('Parent');
  2290. if (!dict) {
  2291. break;
  2292. }
  2293. value = dict.get(key);
  2294. }
  2295. return value;
  2296. },
  2297. get content() {
  2298. return this.getPageProp('Contents');
  2299. },
  2300. get resources() {
  2301. var value = this.getInheritedPageProp('Resources');
  2302. // For robustness: The spec states that a \Resources entry has to be
  2303. // present, but can be empty. Some document omit it still. In this case
  2304. // return an empty dictionary:
  2305. if (value === undefined) {
  2306. value = Dict.empty;
  2307. }
  2308. return shadow(this, 'resources', value);
  2309. },
  2310. get mediaBox() {
  2311. var obj = this.getInheritedPageProp('MediaBox');
  2312. // Reset invalid media box to letter size.
  2313. if (!isArray(obj) || obj.length !== 4) {
  2314. obj = LETTER_SIZE_MEDIABOX;
  2315. }
  2316. return shadow(this, 'mediaBox', obj);
  2317. },
  2318. get view() {
  2319. var mediaBox = this.mediaBox;
  2320. var cropBox = this.getInheritedPageProp('CropBox');
  2321. if (!isArray(cropBox) || cropBox.length !== 4) {
  2322. return shadow(this, 'view', mediaBox);
  2323. }
  2324. // From the spec, 6th ed., p.963:
  2325. // "The crop, bleed, trim, and art boxes should not ordinarily
  2326. // extend beyond the boundaries of the media box. If they do, they are
  2327. // effectively reduced to their intersection with the media box."
  2328. cropBox = Util.intersect(cropBox, mediaBox);
  2329. if (!cropBox) {
  2330. return shadow(this, 'view', mediaBox);
  2331. }
  2332. return shadow(this, 'view', cropBox);
  2333. },
  2334. get annotationRefs() {
  2335. return shadow(this, 'annotationRefs',
  2336. this.getInheritedPageProp('Annots'));
  2337. },
  2338. get rotate() {
  2339. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2340. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2341. if (rotate % 90 !== 0) {
  2342. rotate = 0;
  2343. } else if (rotate >= 360) {
  2344. rotate = rotate % 360;
  2345. } else if (rotate < 0) {
  2346. // The spec doesn't cover negatives, assume its counterclockwise
  2347. // rotation. The following is the other implementation of modulo.
  2348. rotate = ((rotate % 360) + 360) % 360;
  2349. }
  2350. return shadow(this, 'rotate', rotate);
  2351. },
  2352. getContentStream: function Page_getContentStream() {
  2353. var content = this.content;
  2354. var stream;
  2355. if (isArray(content)) {
  2356. // fetching items
  2357. var xref = this.xref;
  2358. var i, n = content.length;
  2359. var streams = [];
  2360. for (i = 0; i < n; ++i) {
  2361. streams.push(xref.fetchIfRef(content[i]));
  2362. }
  2363. stream = new StreamsSequenceStream(streams);
  2364. } else if (isStream(content)) {
  2365. stream = content;
  2366. } else {
  2367. // replacing non-existent page content with empty one
  2368. stream = new NullStream();
  2369. }
  2370. return stream;
  2371. },
  2372. loadResources: function Page_loadResources(keys) {
  2373. if (!this.resourcesPromise) {
  2374. // TODO: add async getInheritedPageProp and remove this.
  2375. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2376. }
  2377. return this.resourcesPromise.then(function resourceSuccess() {
  2378. var objectLoader = new ObjectLoader(this.resources.map,
  2379. keys,
  2380. this.xref);
  2381. return objectLoader.load();
  2382. }.bind(this));
  2383. },
  2384. getOperatorList: function Page_getOperatorList(handler, intent) {
  2385. var self = this;
  2386. var pdfManager = this.pdfManager;
  2387. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2388. []);
  2389. var resourcesPromise = this.loadResources([
  2390. 'ExtGState',
  2391. 'ColorSpace',
  2392. 'Pattern',
  2393. 'Shading',
  2394. 'XObject',
  2395. 'Font'
  2396. // ProcSet
  2397. // Properties
  2398. ]);
  2399. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2400. handler, this.pageIndex,
  2401. 'p' + this.pageIndex + '_',
  2402. this.idCounters,
  2403. this.fontCache);
  2404. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2405. var pageListPromise = dataPromises.then(function(data) {
  2406. var contentStream = data[0];
  2407. var opList = new OperatorList(intent, handler, self.pageIndex);
  2408. handler.send('StartRenderPage', {
  2409. transparency: partialEvaluator.hasBlendModes(self.resources),
  2410. pageIndex: self.pageIndex,
  2411. intent: intent
  2412. });
  2413. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2414. opList).then(function () {
  2415. return opList;
  2416. });
  2417. });
  2418. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2419. return Promise.all([pageListPromise, annotationsPromise]).then(
  2420. function(datas) {
  2421. var pageOpList = datas[0];
  2422. var annotations = datas[1];
  2423. if (annotations.length === 0) {
  2424. pageOpList.flush(true);
  2425. return pageOpList;
  2426. }
  2427. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2428. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2429. return annotationsReadyPromise.then(function () {
  2430. pageOpList.flush(true);
  2431. return pageOpList;
  2432. });
  2433. });
  2434. },
  2435. extractTextContent: function Page_extractTextContent() {
  2436. var handler = {
  2437. on: function nullHandlerOn() {},
  2438. send: function nullHandlerSend() {}
  2439. };
  2440. var self = this;
  2441. var pdfManager = this.pdfManager;
  2442. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2443. []);
  2444. var resourcesPromise = this.loadResources([
  2445. 'ExtGState',
  2446. 'XObject',
  2447. 'Font'
  2448. ]);
  2449. var dataPromises = Promise.all([contentStreamPromise,
  2450. resourcesPromise]);
  2451. return dataPromises.then(function(data) {
  2452. var contentStream = data[0];
  2453. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2454. handler, self.pageIndex,
  2455. 'p' + self.pageIndex + '_',
  2456. self.idCounters,
  2457. self.fontCache);
  2458. return partialEvaluator.getTextContent(contentStream,
  2459. self.resources);
  2460. });
  2461. },
  2462. getAnnotationsData: function Page_getAnnotationsData() {
  2463. var annotations = this.annotations;
  2464. var annotationsData = [];
  2465. for (var i = 0, n = annotations.length; i < n; ++i) {
  2466. annotationsData.push(annotations[i].getData());
  2467. }
  2468. return annotationsData;
  2469. },
  2470. get annotations() {
  2471. var annotations = [];
  2472. var annotationRefs = (this.annotationRefs || []);
  2473. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2474. var annotationRef = annotationRefs[i];
  2475. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2476. if (annotation) {
  2477. annotations.push(annotation);
  2478. }
  2479. }
  2480. return shadow(this, 'annotations', annotations);
  2481. }
  2482. };
  2483. return Page;
  2484. })();
  2485. /**
  2486. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2487. * `PDFDoc`, this one doesn't have any job management code.
  2488. * Right now there exists one PDFDocument on the main thread + one object
  2489. * for each worker. If there is no worker support enabled, there are two
  2490. * `PDFDocument` objects on the main thread created.
  2491. */
  2492. var PDFDocument = (function PDFDocumentClosure() {
  2493. var FINGERPRINT_FIRST_BYTES = 1024;
  2494. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2495. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2496. function PDFDocument(pdfManager, arg, password) {
  2497. if (isStream(arg)) {
  2498. init.call(this, pdfManager, arg, password);
  2499. } else if (isArrayBuffer(arg)) {
  2500. init.call(this, pdfManager, new Stream(arg), password);
  2501. } else {
  2502. error('PDFDocument: Unknown argument type');
  2503. }
  2504. }
  2505. function init(pdfManager, stream, password) {
  2506. assert(stream.length > 0, 'stream must have data');
  2507. this.pdfManager = pdfManager;
  2508. this.stream = stream;
  2509. var xref = new XRef(this.stream, password, pdfManager);
  2510. this.xref = xref;
  2511. }
  2512. function find(stream, needle, limit, backwards) {
  2513. var pos = stream.pos;
  2514. var end = stream.end;
  2515. var strBuf = [];
  2516. if (pos + limit > end) {
  2517. limit = end - pos;
  2518. }
  2519. for (var n = 0; n < limit; ++n) {
  2520. strBuf.push(String.fromCharCode(stream.getByte()));
  2521. }
  2522. var str = strBuf.join('');
  2523. stream.pos = pos;
  2524. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2525. if (index === -1) {
  2526. return false; /* not found */
  2527. }
  2528. stream.pos += index;
  2529. return true; /* found */
  2530. }
  2531. var DocumentInfoValidators = {
  2532. get entries() {
  2533. // Lazily build this since all the validation functions below are not
  2534. // defined until after this file loads.
  2535. return shadow(this, 'entries', {
  2536. Title: isString,
  2537. Author: isString,
  2538. Subject: isString,
  2539. Keywords: isString,
  2540. Creator: isString,
  2541. Producer: isString,
  2542. CreationDate: isString,
  2543. ModDate: isString,
  2544. Trapped: isName
  2545. });
  2546. }
  2547. };
  2548. PDFDocument.prototype = {
  2549. parse: function PDFDocument_parse(recoveryMode) {
  2550. this.setup(recoveryMode);
  2551. try {
  2552. // checking if AcroForm is present
  2553. this.acroForm = this.catalog.catDict.get('AcroForm');
  2554. if (this.acroForm) {
  2555. this.xfa = this.acroForm.get('XFA');
  2556. var fields = this.acroForm.get('Fields');
  2557. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2558. !this.xfa) {
  2559. // no fields and no XFA -- not a form (?)
  2560. this.acroForm = null;
  2561. }
  2562. }
  2563. } catch (ex) {
  2564. info('Something wrong with AcroForm entry');
  2565. this.acroForm = null;
  2566. }
  2567. },
  2568. get linearization() {
  2569. var linearization = null;
  2570. if (this.stream.length) {
  2571. try {
  2572. linearization = Linearization.create(this.stream);
  2573. } catch (err) {
  2574. if (err instanceof MissingDataException) {
  2575. throw err;
  2576. }
  2577. info(err);
  2578. }
  2579. }
  2580. // shadow the prototype getter with a data property
  2581. return shadow(this, 'linearization', linearization);
  2582. },
  2583. get startXRef() {
  2584. var stream = this.stream;
  2585. var startXRef = 0;
  2586. var linearization = this.linearization;
  2587. if (linearization) {
  2588. // Find end of first obj.
  2589. stream.reset();
  2590. if (find(stream, 'endobj', 1024)) {
  2591. startXRef = stream.pos + 6;
  2592. }
  2593. } else {
  2594. // Find startxref by jumping backward from the end of the file.
  2595. var step = 1024;
  2596. var found = false, pos = stream.end;
  2597. while (!found && pos > 0) {
  2598. pos -= step - 'startxref'.length;
  2599. if (pos < 0) {
  2600. pos = 0;
  2601. }
  2602. stream.pos = pos;
  2603. found = find(stream, 'startxref', step, true);
  2604. }
  2605. if (found) {
  2606. stream.skip(9);
  2607. var ch;
  2608. do {
  2609. ch = stream.getByte();
  2610. } while (Lexer.isSpace(ch));
  2611. var str = '';
  2612. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2613. str += String.fromCharCode(ch);
  2614. ch = stream.getByte();
  2615. }
  2616. startXRef = parseInt(str, 10);
  2617. if (isNaN(startXRef)) {
  2618. startXRef = 0;
  2619. }
  2620. }
  2621. }
  2622. // shadow the prototype getter with a data property
  2623. return shadow(this, 'startXRef', startXRef);
  2624. },
  2625. get mainXRefEntriesOffset() {
  2626. var mainXRefEntriesOffset = 0;
  2627. var linearization = this.linearization;
  2628. if (linearization) {
  2629. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2630. }
  2631. // shadow the prototype getter with a data property
  2632. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2633. },
  2634. // Find the header, remove leading garbage and setup the stream
  2635. // starting from the header.
  2636. checkHeader: function PDFDocument_checkHeader() {
  2637. var stream = this.stream;
  2638. stream.reset();
  2639. if (find(stream, '%PDF-', 1024)) {
  2640. // Found the header, trim off any garbage before it.
  2641. stream.moveStart();
  2642. // Reading file format version
  2643. var MAX_VERSION_LENGTH = 12;
  2644. var version = '', ch;
  2645. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2646. if (version.length >= MAX_VERSION_LENGTH) {
  2647. break;
  2648. }
  2649. version += String.fromCharCode(ch);
  2650. }
  2651. // removing "%PDF-"-prefix
  2652. this.pdfFormatVersion = version.substring(5);
  2653. return;
  2654. }
  2655. // May not be a PDF file, continue anyway.
  2656. },
  2657. parseStartXRef: function PDFDocument_parseStartXRef() {
  2658. var startXRef = this.startXRef;
  2659. this.xref.setStartXRef(startXRef);
  2660. },
  2661. setup: function PDFDocument_setup(recoveryMode) {
  2662. this.xref.parse(recoveryMode);
  2663. this.catalog = new Catalog(this.pdfManager, this.xref);
  2664. },
  2665. get numPages() {
  2666. var linearization = this.linearization;
  2667. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2668. // shadow the prototype getter
  2669. return shadow(this, 'numPages', num);
  2670. },
  2671. get documentInfo() {
  2672. var docInfo = {
  2673. PDFFormatVersion: this.pdfFormatVersion,
  2674. IsAcroFormPresent: !!this.acroForm,
  2675. IsXFAPresent: !!this.xfa
  2676. };
  2677. var infoDict;
  2678. try {
  2679. infoDict = this.xref.trailer.get('Info');
  2680. } catch (err) {
  2681. info('The document information dictionary is invalid.');
  2682. }
  2683. if (infoDict) {
  2684. var validEntries = DocumentInfoValidators.entries;
  2685. // Only fill the document info with valid entries from the spec.
  2686. for (var key in validEntries) {
  2687. if (infoDict.has(key)) {
  2688. var value = infoDict.get(key);
  2689. // Make sure the value conforms to the spec.
  2690. if (validEntries[key](value)) {
  2691. docInfo[key] = (typeof value !== 'string' ?
  2692. value : stringToPDFString(value));
  2693. } else {
  2694. info('Bad value in document info for "' + key + '"');
  2695. }
  2696. }
  2697. }
  2698. }
  2699. return shadow(this, 'documentInfo', docInfo);
  2700. },
  2701. get fingerprint() {
  2702. var xref = this.xref, idArray, hash, fileID = '';
  2703. if (xref.trailer.has('ID')) {
  2704. idArray = xref.trailer.get('ID');
  2705. }
  2706. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2707. hash = stringToBytes(idArray[0]);
  2708. } else {
  2709. if (this.stream.ensureRange) {
  2710. this.stream.ensureRange(0,
  2711. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2712. }
  2713. hash = calculateMD5(this.stream.bytes.subarray(0,
  2714. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2715. }
  2716. for (var i = 0, n = hash.length; i < n; i++) {
  2717. var hex = hash[i].toString(16);
  2718. fileID += hex.length === 1 ? '0' + hex : hex;
  2719. }
  2720. return shadow(this, 'fingerprint', fileID);
  2721. },
  2722. getPage: function PDFDocument_getPage(pageIndex) {
  2723. return this.catalog.getPage(pageIndex);
  2724. },
  2725. cleanup: function PDFDocument_cleanup() {
  2726. return this.catalog.cleanup();
  2727. }
  2728. };
  2729. return PDFDocument;
  2730. })();
  2731. var Name = (function NameClosure() {
  2732. function Name(name) {
  2733. this.name = name;
  2734. }
  2735. Name.prototype = {};
  2736. var nameCache = {};
  2737. Name.get = function Name_get(name) {
  2738. var nameValue = nameCache[name];
  2739. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2740. };
  2741. return Name;
  2742. })();
  2743. var Cmd = (function CmdClosure() {
  2744. function Cmd(cmd) {
  2745. this.cmd = cmd;
  2746. }
  2747. Cmd.prototype = {};
  2748. var cmdCache = {};
  2749. Cmd.get = function Cmd_get(cmd) {
  2750. var cmdValue = cmdCache[cmd];
  2751. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2752. };
  2753. return Cmd;
  2754. })();
  2755. var Dict = (function DictClosure() {
  2756. var nonSerializable = function nonSerializableClosure() {
  2757. return nonSerializable; // creating closure on some variable
  2758. };
  2759. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2760. 'Background': true,
  2761. 'ExtGState': true,
  2762. 'Halftone': true,
  2763. 'Layout': true,
  2764. 'Mask': true,
  2765. 'Pagination': true,
  2766. 'Printing': true
  2767. };
  2768. function isRecursionAllowedFor(dict) {
  2769. if (!isName(dict.Type)) {
  2770. return true;
  2771. }
  2772. var dictType = dict.Type.name;
  2773. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2774. }
  2775. // xref is optional
  2776. function Dict(xref) {
  2777. // Map should only be used internally, use functions below to access.
  2778. this.map = Object.create(null);
  2779. this.xref = xref;
  2780. this.objId = null;
  2781. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2782. }
  2783. Dict.prototype = {
  2784. assignXref: function Dict_assignXref(newXref) {
  2785. this.xref = newXref;
  2786. },
  2787. // automatically dereferences Ref objects
  2788. get: function Dict_get(key1, key2, key3) {
  2789. var value;
  2790. var xref = this.xref;
  2791. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2792. typeof key2 === 'undefined') {
  2793. return xref ? xref.fetchIfRef(value) : value;
  2794. }
  2795. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2796. typeof key3 === 'undefined') {
  2797. return xref ? xref.fetchIfRef(value) : value;
  2798. }
  2799. value = this.map[key3] || null;
  2800. return xref ? xref.fetchIfRef(value) : value;
  2801. },
  2802. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2803. getAsync: function Dict_getAsync(key1, key2, key3) {
  2804. var value;
  2805. var xref = this.xref;
  2806. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2807. typeof key2 === 'undefined') {
  2808. if (xref) {
  2809. return xref.fetchIfRefAsync(value);
  2810. }
  2811. return Promise.resolve(value);
  2812. }
  2813. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2814. typeof key3 === 'undefined') {
  2815. if (xref) {
  2816. return xref.fetchIfRefAsync(value);
  2817. }
  2818. return Promise.resolve(value);
  2819. }
  2820. value = this.map[key3] || null;
  2821. if (xref) {
  2822. return xref.fetchIfRefAsync(value);
  2823. }
  2824. return Promise.resolve(value);
  2825. },
  2826. // no dereferencing
  2827. getRaw: function Dict_getRaw(key) {
  2828. return this.map[key];
  2829. },
  2830. // creates new map and dereferences all Refs
  2831. getAll: function Dict_getAll() {
  2832. var all = Object.create(null);
  2833. var queue = null;
  2834. var key, obj;
  2835. for (key in this.map) {
  2836. obj = this.get(key);
  2837. if (obj instanceof Dict) {
  2838. if (isRecursionAllowedFor(obj)) {
  2839. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2840. } else {
  2841. all[key] = this.getRaw(key);
  2842. }
  2843. } else {
  2844. all[key] = obj;
  2845. }
  2846. }
  2847. if (!queue) {
  2848. return all;
  2849. }
  2850. // trying to take cyclic references into the account
  2851. var processed = Object.create(null);
  2852. while (queue.length > 0) {
  2853. var item = queue.shift();
  2854. var itemObj = item.obj;
  2855. var objId = itemObj.objId;
  2856. if (objId && objId in processed) {
  2857. item.target[item.key] = processed[objId];
  2858. continue;
  2859. }
  2860. var dereferenced = Object.create(null);
  2861. for (key in itemObj.map) {
  2862. obj = itemObj.get(key);
  2863. if (obj instanceof Dict) {
  2864. if (isRecursionAllowedFor(obj)) {
  2865. queue.push({target: dereferenced, key: key, obj: obj});
  2866. } else {
  2867. dereferenced[key] = itemObj.getRaw(key);
  2868. }
  2869. } else {
  2870. dereferenced[key] = obj;
  2871. }
  2872. }
  2873. if (objId) {
  2874. processed[objId] = dereferenced;
  2875. }
  2876. item.target[item.key] = dereferenced;
  2877. }
  2878. return all;
  2879. },
  2880. set: function Dict_set(key, value) {
  2881. this.map[key] = value;
  2882. },
  2883. has: function Dict_has(key) {
  2884. return key in this.map;
  2885. },
  2886. forEach: function Dict_forEach(callback) {
  2887. for (var key in this.map) {
  2888. callback(key, this.get(key));
  2889. }
  2890. }
  2891. };
  2892. Dict.empty = new Dict(null);
  2893. return Dict;
  2894. })();
  2895. var Ref = (function RefClosure() {
  2896. function Ref(num, gen) {
  2897. this.num = num;
  2898. this.gen = gen;
  2899. }
  2900. Ref.prototype = {
  2901. toString: function Ref_toString() {
  2902. // This function is hot, so we make the string as compact as possible.
  2903. // |this.gen| is almost always zero, so we treat that case specially.
  2904. var str = this.num + 'R';
  2905. if (this.gen !== 0) {
  2906. str += this.gen;
  2907. }
  2908. return str;
  2909. }
  2910. };
  2911. return Ref;
  2912. })();
  2913. // The reference is identified by number and generation.
  2914. // This structure stores only one instance of the reference.
  2915. var RefSet = (function RefSetClosure() {
  2916. function RefSet() {
  2917. this.dict = {};
  2918. }
  2919. RefSet.prototype = {
  2920. has: function RefSet_has(ref) {
  2921. return ref.toString() in this.dict;
  2922. },
  2923. put: function RefSet_put(ref) {
  2924. this.dict[ref.toString()] = true;
  2925. },
  2926. remove: function RefSet_remove(ref) {
  2927. delete this.dict[ref.toString()];
  2928. }
  2929. };
  2930. return RefSet;
  2931. })();
  2932. var RefSetCache = (function RefSetCacheClosure() {
  2933. function RefSetCache() {
  2934. this.dict = Object.create(null);
  2935. }
  2936. RefSetCache.prototype = {
  2937. get: function RefSetCache_get(ref) {
  2938. return this.dict[ref.toString()];
  2939. },
  2940. has: function RefSetCache_has(ref) {
  2941. return ref.toString() in this.dict;
  2942. },
  2943. put: function RefSetCache_put(ref, obj) {
  2944. this.dict[ref.toString()] = obj;
  2945. },
  2946. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2947. this.dict[ref.toString()] = this.get(aliasRef);
  2948. },
  2949. forEach: function RefSetCache_forEach(fn, thisArg) {
  2950. for (var i in this.dict) {
  2951. fn.call(thisArg, this.dict[i]);
  2952. }
  2953. },
  2954. clear: function RefSetCache_clear() {
  2955. this.dict = Object.create(null);
  2956. }
  2957. };
  2958. return RefSetCache;
  2959. })();
  2960. var Catalog = (function CatalogClosure() {
  2961. function Catalog(pdfManager, xref) {
  2962. this.pdfManager = pdfManager;
  2963. this.xref = xref;
  2964. this.catDict = xref.getCatalogObj();
  2965. this.fontCache = new RefSetCache();
  2966. assert(isDict(this.catDict),
  2967. 'catalog object is not a dictionary');
  2968. this.pagePromises = [];
  2969. }
  2970. Catalog.prototype = {
  2971. get metadata() {
  2972. var streamRef = this.catDict.getRaw('Metadata');
  2973. if (!isRef(streamRef)) {
  2974. return shadow(this, 'metadata', null);
  2975. }
  2976. var encryptMetadata = (!this.xref.encrypt ? false :
  2977. this.xref.encrypt.encryptMetadata);
  2978. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2979. var metadata;
  2980. if (stream && isDict(stream.dict)) {
  2981. var type = stream.dict.get('Type');
  2982. var subtype = stream.dict.get('Subtype');
  2983. if (isName(type) && isName(subtype) &&
  2984. type.name === 'Metadata' && subtype.name === 'XML') {
  2985. // XXX: This should examine the charset the XML document defines,
  2986. // however since there are currently no real means to decode
  2987. // arbitrary charsets, let's just hope that the author of the PDF
  2988. // was reasonable enough to stick with the XML default charset,
  2989. // which is UTF-8.
  2990. try {
  2991. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2992. } catch (e) {
  2993. info('Skipping invalid metadata.');
  2994. }
  2995. }
  2996. }
  2997. return shadow(this, 'metadata', metadata);
  2998. },
  2999. get toplevelPagesDict() {
  3000. var pagesObj = this.catDict.get('Pages');
  3001. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3002. // shadow the prototype getter
  3003. return shadow(this, 'toplevelPagesDict', pagesObj);
  3004. },
  3005. get documentOutline() {
  3006. var obj = null;
  3007. try {
  3008. obj = this.readDocumentOutline();
  3009. } catch (ex) {
  3010. if (ex instanceof MissingDataException) {
  3011. throw ex;
  3012. }
  3013. warn('Unable to read document outline');
  3014. }
  3015. return shadow(this, 'documentOutline', obj);
  3016. },
  3017. readDocumentOutline: function Catalog_readDocumentOutline() {
  3018. var xref = this.xref;
  3019. var obj = this.catDict.get('Outlines');
  3020. var root = { items: [] };
  3021. if (isDict(obj)) {
  3022. obj = obj.getRaw('First');
  3023. var processed = new RefSet();
  3024. if (isRef(obj)) {
  3025. var queue = [{obj: obj, parent: root}];
  3026. // to avoid recursion keeping track of the items
  3027. // in the processed dictionary
  3028. processed.put(obj);
  3029. while (queue.length > 0) {
  3030. var i = queue.shift();
  3031. var outlineDict = xref.fetchIfRef(i.obj);
  3032. if (outlineDict === null) {
  3033. continue;
  3034. }
  3035. if (!outlineDict.has('Title')) {
  3036. error('Invalid outline item');
  3037. }
  3038. var dest = outlineDict.get('A');
  3039. if (dest) {
  3040. dest = dest.get('D');
  3041. } else if (outlineDict.has('Dest')) {
  3042. dest = outlineDict.getRaw('Dest');
  3043. if (isName(dest)) {
  3044. dest = dest.name;
  3045. }
  3046. }
  3047. var title = outlineDict.get('Title');
  3048. var outlineItem = {
  3049. dest: dest,
  3050. title: stringToPDFString(title),
  3051. color: outlineDict.get('C') || [0, 0, 0],
  3052. count: outlineDict.get('Count'),
  3053. bold: !!(outlineDict.get('F') & 2),
  3054. italic: !!(outlineDict.get('F') & 1),
  3055. items: []
  3056. };
  3057. i.parent.items.push(outlineItem);
  3058. obj = outlineDict.getRaw('First');
  3059. if (isRef(obj) && !processed.has(obj)) {
  3060. queue.push({obj: obj, parent: outlineItem});
  3061. processed.put(obj);
  3062. }
  3063. obj = outlineDict.getRaw('Next');
  3064. if (isRef(obj) && !processed.has(obj)) {
  3065. queue.push({obj: obj, parent: i.parent});
  3066. processed.put(obj);
  3067. }
  3068. }
  3069. }
  3070. }
  3071. return (root.items.length > 0 ? root.items : null);
  3072. },
  3073. get numPages() {
  3074. var obj = this.toplevelPagesDict.get('Count');
  3075. assert(
  3076. isInt(obj),
  3077. 'page count in top level pages object is not an integer'
  3078. );
  3079. // shadow the prototype getter
  3080. return shadow(this, 'num', obj);
  3081. },
  3082. get destinations() {
  3083. function fetchDestination(dest) {
  3084. return isDict(dest) ? dest.get('D') : dest;
  3085. }
  3086. var xref = this.xref;
  3087. var dests = {}, nameTreeRef, nameDictionaryRef;
  3088. var obj = this.catDict.get('Names');
  3089. if (obj && obj.has('Dests')) {
  3090. nameTreeRef = obj.getRaw('Dests');
  3091. } else if (this.catDict.has('Dests')) {
  3092. nameDictionaryRef = this.catDict.get('Dests');
  3093. }
  3094. if (nameDictionaryRef) {
  3095. // reading simple destination dictionary
  3096. obj = nameDictionaryRef;
  3097. obj.forEach(function catalogForEach(key, value) {
  3098. if (!value) {
  3099. return;
  3100. }
  3101. dests[key] = fetchDestination(value);
  3102. });
  3103. }
  3104. if (nameTreeRef) {
  3105. var nameTree = new NameTree(nameTreeRef, xref);
  3106. var names = nameTree.getAll();
  3107. for (var name in names) {
  3108. if (!names.hasOwnProperty(name)) {
  3109. continue;
  3110. }
  3111. dests[name] = fetchDestination(names[name]);
  3112. }
  3113. }
  3114. return shadow(this, 'destinations', dests);
  3115. },
  3116. getDestination: function Catalog_getDestination(destinationId) {
  3117. function fetchDestination(dest) {
  3118. return isDict(dest) ? dest.get('D') : dest;
  3119. }
  3120. var xref = this.xref;
  3121. var dest, nameTreeRef, nameDictionaryRef;
  3122. var obj = this.catDict.get('Names');
  3123. if (obj && obj.has('Dests')) {
  3124. nameTreeRef = obj.getRaw('Dests');
  3125. } else if (this.catDict.has('Dests')) {
  3126. nameDictionaryRef = this.catDict.get('Dests');
  3127. }
  3128. if (nameDictionaryRef) {
  3129. // reading simple destination dictionary
  3130. obj = nameDictionaryRef;
  3131. obj.forEach(function catalogForEach(key, value) {
  3132. if (!value) {
  3133. return;
  3134. }
  3135. if (key === destinationId) {
  3136. dest = fetchDestination(value);
  3137. }
  3138. });
  3139. }
  3140. if (nameTreeRef) {
  3141. var nameTree = new NameTree(nameTreeRef, xref);
  3142. dest = fetchDestination(nameTree.get(destinationId));
  3143. }
  3144. return dest;
  3145. },
  3146. get attachments() {
  3147. var xref = this.xref;
  3148. var attachments = null, nameTreeRef;
  3149. var obj = this.catDict.get('Names');
  3150. if (obj) {
  3151. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3152. }
  3153. if (nameTreeRef) {
  3154. var nameTree = new NameTree(nameTreeRef, xref);
  3155. var names = nameTree.getAll();
  3156. for (var name in names) {
  3157. if (!names.hasOwnProperty(name)) {
  3158. continue;
  3159. }
  3160. var fs = new FileSpec(names[name], xref);
  3161. if (!attachments) {
  3162. attachments = {};
  3163. }
  3164. attachments[stringToPDFString(name)] = fs.serializable;
  3165. }
  3166. }
  3167. return shadow(this, 'attachments', attachments);
  3168. },
  3169. get javaScript() {
  3170. var xref = this.xref;
  3171. var obj = this.catDict.get('Names');
  3172. var javaScript = [];
  3173. if (obj && obj.has('JavaScript')) {
  3174. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3175. var names = nameTree.getAll();
  3176. for (var name in names) {
  3177. if (!names.hasOwnProperty(name)) {
  3178. continue;
  3179. }
  3180. // We don't really use the JavaScript right now. This code is
  3181. // defensive so we don't cause errors on document load.
  3182. var jsDict = names[name];
  3183. if (!isDict(jsDict)) {
  3184. continue;
  3185. }
  3186. var type = jsDict.get('S');
  3187. if (!isName(type) || type.name !== 'JavaScript') {
  3188. continue;
  3189. }
  3190. var js = jsDict.get('JS');
  3191. if (!isString(js) && !isStream(js)) {
  3192. continue;
  3193. }
  3194. if (isStream(js)) {
  3195. js = bytesToString(js.getBytes());
  3196. }
  3197. javaScript.push(stringToPDFString(js));
  3198. }
  3199. }
  3200. // Append OpenAction actions to javaScript array
  3201. var openactionDict = this.catDict.get('OpenAction');
  3202. if (isDict(openactionDict)) {
  3203. var objType = openactionDict.get('Type');
  3204. var actionType = openactionDict.get('S');
  3205. var action = openactionDict.get('N');
  3206. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3207. isName(actionType) && actionType.name === 'Named' &&
  3208. isName(action) && action.name === 'Print');
  3209. if (isPrintAction) {
  3210. javaScript.push('print(true);');
  3211. }
  3212. }
  3213. return shadow(this, 'javaScript', javaScript);
  3214. },
  3215. cleanup: function Catalog_cleanup() {
  3216. var promises = [];
  3217. this.fontCache.forEach(function (promise) {
  3218. promises.push(promise);
  3219. });
  3220. return Promise.all(promises).then(function (translatedFonts) {
  3221. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3222. var font = translatedFonts[i].dict;
  3223. delete font.translated;
  3224. }
  3225. this.fontCache.clear();
  3226. }.bind(this));
  3227. },
  3228. getPage: function Catalog_getPage(pageIndex) {
  3229. if (!(pageIndex in this.pagePromises)) {
  3230. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3231. function (a) {
  3232. var dict = a[0];
  3233. var ref = a[1];
  3234. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3235. this.fontCache);
  3236. }.bind(this)
  3237. );
  3238. }
  3239. return this.pagePromises[pageIndex];
  3240. },
  3241. getPageDict: function Catalog_getPageDict(pageIndex) {
  3242. var capability = createPromiseCapability();
  3243. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3244. var currentPageIndex = 0;
  3245. var xref = this.xref;
  3246. function next() {
  3247. while (nodesToVisit.length) {
  3248. var currentNode = nodesToVisit.pop();
  3249. if (isRef(currentNode)) {
  3250. xref.fetchAsync(currentNode).then(function (obj) {
  3251. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3252. if (pageIndex === currentPageIndex) {
  3253. capability.resolve([obj, currentNode]);
  3254. } else {
  3255. currentPageIndex++;
  3256. next();
  3257. }
  3258. return;
  3259. }
  3260. nodesToVisit.push(obj);
  3261. next();
  3262. }, capability.reject);
  3263. return;
  3264. }
  3265. // must be a child page dictionary
  3266. assert(
  3267. isDict(currentNode),
  3268. 'page dictionary kid reference points to wrong type of object'
  3269. );
  3270. var count = currentNode.get('Count');
  3271. // Skip nodes where the page can't be.
  3272. if (currentPageIndex + count <= pageIndex) {
  3273. currentPageIndex += count;
  3274. continue;
  3275. }
  3276. var kids = currentNode.get('Kids');
  3277. assert(isArray(kids), 'page dictionary kids object is not an array');
  3278. if (count === kids.length) {
  3279. // Nodes that don't have the page have been skipped and this is the
  3280. // bottom of the tree which means the page requested must be a
  3281. // descendant of this pages node. Ideally we would just resolve the
  3282. // promise with the page ref here, but there is the case where more
  3283. // pages nodes could link to single a page (see issue 3666 pdf). To
  3284. // handle this push it back on the queue so if it is a pages node it
  3285. // will be descended into.
  3286. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3287. currentPageIndex = pageIndex;
  3288. continue;
  3289. } else {
  3290. for (var last = kids.length - 1; last >= 0; last--) {
  3291. nodesToVisit.push(kids[last]);
  3292. }
  3293. }
  3294. }
  3295. capability.reject('Page index ' + pageIndex + ' not found.');
  3296. }
  3297. next();
  3298. return capability.promise;
  3299. },
  3300. getPageIndex: function Catalog_getPageIndex(ref) {
  3301. // The page tree nodes have the count of all the leaves below them. To get
  3302. // how many pages are before we just have to walk up the tree and keep
  3303. // adding the count of siblings to the left of the node.
  3304. var xref = this.xref;
  3305. function pagesBeforeRef(kidRef) {
  3306. var total = 0;
  3307. var parentRef;
  3308. return xref.fetchAsync(kidRef).then(function (node) {
  3309. if (!node) {
  3310. return null;
  3311. }
  3312. parentRef = node.getRaw('Parent');
  3313. return node.getAsync('Parent');
  3314. }).then(function (parent) {
  3315. if (!parent) {
  3316. return null;
  3317. }
  3318. return parent.getAsync('Kids');
  3319. }).then(function (kids) {
  3320. if (!kids) {
  3321. return null;
  3322. }
  3323. var kidPromises = [];
  3324. var found = false;
  3325. for (var i = 0; i < kids.length; i++) {
  3326. var kid = kids[i];
  3327. assert(isRef(kid), 'kids must be a ref');
  3328. if (kid.num === kidRef.num) {
  3329. found = true;
  3330. break;
  3331. }
  3332. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3333. if (kid.has('Count')) {
  3334. var count = kid.get('Count');
  3335. total += count;
  3336. } else { // page leaf node
  3337. total++;
  3338. }
  3339. }));
  3340. }
  3341. if (!found) {
  3342. error('kid ref not found in parents kids');
  3343. }
  3344. return Promise.all(kidPromises).then(function () {
  3345. return [total, parentRef];
  3346. });
  3347. });
  3348. }
  3349. var total = 0;
  3350. function next(ref) {
  3351. return pagesBeforeRef(ref).then(function (args) {
  3352. if (!args) {
  3353. return total;
  3354. }
  3355. var count = args[0];
  3356. var parentRef = args[1];
  3357. total += count;
  3358. return next(parentRef);
  3359. });
  3360. }
  3361. return next(ref);
  3362. }
  3363. };
  3364. return Catalog;
  3365. })();
  3366. var XRef = (function XRefClosure() {
  3367. function XRef(stream, password) {
  3368. this.stream = stream;
  3369. this.entries = [];
  3370. this.xrefstms = {};
  3371. // prepare the XRef cache
  3372. this.cache = [];
  3373. this.password = password;
  3374. this.stats = {
  3375. streamTypes: [],
  3376. fontTypes: []
  3377. };
  3378. }
  3379. XRef.prototype = {
  3380. setStartXRef: function XRef_setStartXRef(startXRef) {
  3381. // Store the starting positions of xref tables as we process them
  3382. // so we can recover from missing data errors
  3383. this.startXRefQueue = [startXRef];
  3384. },
  3385. parse: function XRef_parse(recoveryMode) {
  3386. var trailerDict;
  3387. if (!recoveryMode) {
  3388. trailerDict = this.readXRef();
  3389. } else {
  3390. warn('Indexing all PDF objects');
  3391. trailerDict = this.indexObjects();
  3392. }
  3393. trailerDict.assignXref(this);
  3394. this.trailer = trailerDict;
  3395. var encrypt = trailerDict.get('Encrypt');
  3396. if (encrypt) {
  3397. var ids = trailerDict.get('ID');
  3398. var fileId = (ids && ids.length) ? ids[0] : '';
  3399. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3400. this.password);
  3401. }
  3402. // get the root dictionary (catalog) object
  3403. if (!(this.root = trailerDict.get('Root'))) {
  3404. error('Invalid root reference');
  3405. }
  3406. },
  3407. processXRefTable: function XRef_processXRefTable(parser) {
  3408. if (!('tableState' in this)) {
  3409. // Stores state of the table as we process it so we can resume
  3410. // from middle of table in case of missing data error
  3411. this.tableState = {
  3412. entryNum: 0,
  3413. streamPos: parser.lexer.stream.pos,
  3414. parserBuf1: parser.buf1,
  3415. parserBuf2: parser.buf2
  3416. };
  3417. }
  3418. var obj = this.readXRefTable(parser);
  3419. // Sanity check
  3420. if (!isCmd(obj, 'trailer')) {
  3421. error('Invalid XRef table: could not find trailer dictionary');
  3422. }
  3423. // Read trailer dictionary, e.g.
  3424. // trailer
  3425. // << /Size 22
  3426. // /Root 20R
  3427. // /Info 10R
  3428. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3429. // >>
  3430. // The parser goes through the entire stream << ... >> and provides
  3431. // a getter interface for the key-value table
  3432. var dict = parser.getObj();
  3433. // The pdflib PDF generator can generate a nested trailer dictionary
  3434. if (!isDict(dict) && dict.dict) {
  3435. dict = dict.dict;
  3436. }
  3437. if (!isDict(dict)) {
  3438. error('Invalid XRef table: could not parse trailer dictionary');
  3439. }
  3440. delete this.tableState;
  3441. return dict;
  3442. },
  3443. readXRefTable: function XRef_readXRefTable(parser) {
  3444. // Example of cross-reference table:
  3445. // xref
  3446. // 0 1 <-- subsection header (first obj #, obj count)
  3447. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3448. // 23 2 <-- subsection header ... and so on ...
  3449. // 0000025518 00002 n
  3450. // 0000025635 00000 n
  3451. // trailer
  3452. // ...
  3453. var stream = parser.lexer.stream;
  3454. var tableState = this.tableState;
  3455. stream.pos = tableState.streamPos;
  3456. parser.buf1 = tableState.parserBuf1;
  3457. parser.buf2 = tableState.parserBuf2;
  3458. // Outer loop is over subsection headers
  3459. var obj;
  3460. while (true) {
  3461. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3462. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3463. break;
  3464. }
  3465. tableState.firstEntryNum = obj;
  3466. tableState.entryCount = parser.getObj();
  3467. }
  3468. var first = tableState.firstEntryNum;
  3469. var count = tableState.entryCount;
  3470. if (!isInt(first) || !isInt(count)) {
  3471. error('Invalid XRef table: wrong types in subsection header');
  3472. }
  3473. // Inner loop is over objects themselves
  3474. for (var i = tableState.entryNum; i < count; i++) {
  3475. tableState.streamPos = stream.pos;
  3476. tableState.entryNum = i;
  3477. tableState.parserBuf1 = parser.buf1;
  3478. tableState.parserBuf2 = parser.buf2;
  3479. var entry = {};
  3480. entry.offset = parser.getObj();
  3481. entry.gen = parser.getObj();
  3482. var type = parser.getObj();
  3483. if (isCmd(type, 'f')) {
  3484. entry.free = true;
  3485. } else if (isCmd(type, 'n')) {
  3486. entry.uncompressed = true;
  3487. }
  3488. // Validate entry obj
  3489. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3490. !(entry.free || entry.uncompressed)) {
  3491. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3492. }
  3493. if (!this.entries[i + first]) {
  3494. this.entries[i + first] = entry;
  3495. }
  3496. }
  3497. tableState.entryNum = 0;
  3498. tableState.streamPos = stream.pos;
  3499. tableState.parserBuf1 = parser.buf1;
  3500. tableState.parserBuf2 = parser.buf2;
  3501. delete tableState.firstEntryNum;
  3502. delete tableState.entryCount;
  3503. }
  3504. // Per issue 3248: hp scanners generate bad XRef
  3505. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3506. // shifting the entries
  3507. this.entries.shift();
  3508. }
  3509. // Sanity check: as per spec, first object must be free
  3510. if (this.entries[0] && !this.entries[0].free) {
  3511. error('Invalid XRef table: unexpected first object');
  3512. }
  3513. return obj;
  3514. },
  3515. processXRefStream: function XRef_processXRefStream(stream) {
  3516. if (!('streamState' in this)) {
  3517. // Stores state of the stream as we process it so we can resume
  3518. // from middle of stream in case of missing data error
  3519. var streamParameters = stream.dict;
  3520. var byteWidths = streamParameters.get('W');
  3521. var range = streamParameters.get('Index');
  3522. if (!range) {
  3523. range = [0, streamParameters.get('Size')];
  3524. }
  3525. this.streamState = {
  3526. entryRanges: range,
  3527. byteWidths: byteWidths,
  3528. entryNum: 0,
  3529. streamPos: stream.pos
  3530. };
  3531. }
  3532. this.readXRefStream(stream);
  3533. delete this.streamState;
  3534. return stream.dict;
  3535. },
  3536. readXRefStream: function XRef_readXRefStream(stream) {
  3537. var i, j;
  3538. var streamState = this.streamState;
  3539. stream.pos = streamState.streamPos;
  3540. var byteWidths = streamState.byteWidths;
  3541. var typeFieldWidth = byteWidths[0];
  3542. var offsetFieldWidth = byteWidths[1];
  3543. var generationFieldWidth = byteWidths[2];
  3544. var entryRanges = streamState.entryRanges;
  3545. while (entryRanges.length > 0) {
  3546. var first = entryRanges[0];
  3547. var n = entryRanges[1];
  3548. if (!isInt(first) || !isInt(n)) {
  3549. error('Invalid XRef range fields: ' + first + ', ' + n);
  3550. }
  3551. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3552. !isInt(generationFieldWidth)) {
  3553. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3554. }
  3555. for (i = streamState.entryNum; i < n; ++i) {
  3556. streamState.entryNum = i;
  3557. streamState.streamPos = stream.pos;
  3558. var type = 0, offset = 0, generation = 0;
  3559. for (j = 0; j < typeFieldWidth; ++j) {
  3560. type = (type << 8) | stream.getByte();
  3561. }
  3562. // if type field is absent, its default value is 1
  3563. if (typeFieldWidth === 0) {
  3564. type = 1;
  3565. }
  3566. for (j = 0; j < offsetFieldWidth; ++j) {
  3567. offset = (offset << 8) | stream.getByte();
  3568. }
  3569. for (j = 0; j < generationFieldWidth; ++j) {
  3570. generation = (generation << 8) | stream.getByte();
  3571. }
  3572. var entry = {};
  3573. entry.offset = offset;
  3574. entry.gen = generation;
  3575. switch (type) {
  3576. case 0:
  3577. entry.free = true;
  3578. break;
  3579. case 1:
  3580. entry.uncompressed = true;
  3581. break;
  3582. case 2:
  3583. break;
  3584. default:
  3585. error('Invalid XRef entry type: ' + type);
  3586. }
  3587. if (!this.entries[first + i]) {
  3588. this.entries[first + i] = entry;
  3589. }
  3590. }
  3591. streamState.entryNum = 0;
  3592. streamState.streamPos = stream.pos;
  3593. entryRanges.splice(0, 2);
  3594. }
  3595. },
  3596. indexObjects: function XRef_indexObjects() {
  3597. // Simple scan through the PDF content to find objects,
  3598. // trailers and XRef streams.
  3599. function readToken(data, offset) {
  3600. var token = '', ch = data[offset];
  3601. while (ch !== 13 && ch !== 10) {
  3602. if (++offset >= data.length) {
  3603. break;
  3604. }
  3605. token += String.fromCharCode(ch);
  3606. ch = data[offset];
  3607. }
  3608. return token;
  3609. }
  3610. function skipUntil(data, offset, what) {
  3611. var length = what.length, dataLength = data.length;
  3612. var skipped = 0;
  3613. // finding byte sequence
  3614. while (offset < dataLength) {
  3615. var i = 0;
  3616. while (i < length && data[offset + i] === what[i]) {
  3617. ++i;
  3618. }
  3619. if (i >= length) {
  3620. break; // sequence found
  3621. }
  3622. offset++;
  3623. skipped++;
  3624. }
  3625. return skipped;
  3626. }
  3627. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3628. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3629. 101, 102]);
  3630. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3631. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3632. var stream = this.stream;
  3633. stream.pos = 0;
  3634. var buffer = stream.getBytes();
  3635. var position = stream.start, length = buffer.length;
  3636. var trailers = [], xrefStms = [];
  3637. while (position < length) {
  3638. var ch = buffer[position];
  3639. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3640. ++position;
  3641. continue;
  3642. }
  3643. if (ch === 37) { // %-comment
  3644. do {
  3645. ++position;
  3646. if (position >= length) {
  3647. break;
  3648. }
  3649. ch = buffer[position];
  3650. } while (ch !== 13 && ch !== 10);
  3651. continue;
  3652. }
  3653. var token = readToken(buffer, position);
  3654. var m;
  3655. if (token === 'xref') {
  3656. position += skipUntil(buffer, position, trailerBytes);
  3657. trailers.push(position);
  3658. position += skipUntil(buffer, position, startxrefBytes);
  3659. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3660. this.entries[m[1]] = {
  3661. offset: position,
  3662. gen: m[2] | 0,
  3663. uncompressed: true
  3664. };
  3665. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3666. var content = buffer.subarray(position, position + contentLength);
  3667. // checking XRef stream suspect
  3668. // (it shall have '/XRef' and next char is not a letter)
  3669. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3670. if (xrefTagOffset < contentLength &&
  3671. content[xrefTagOffset + 5] < 64) {
  3672. xrefStms.push(position);
  3673. this.xrefstms[position] = 1; // don't read it recursively
  3674. }
  3675. position += contentLength;
  3676. } else {
  3677. position += token.length + 1;
  3678. }
  3679. }
  3680. // reading XRef streams
  3681. var i, ii;
  3682. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3683. this.startXRefQueue.push(xrefStms[i]);
  3684. this.readXRef(/* recoveryMode */ true);
  3685. }
  3686. // finding main trailer
  3687. var dict;
  3688. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3689. stream.pos = trailers[i];
  3690. var parser = new Parser(new Lexer(stream), true, this);
  3691. var obj = parser.getObj();
  3692. if (!isCmd(obj, 'trailer')) {
  3693. continue;
  3694. }
  3695. // read the trailer dictionary
  3696. if (!isDict(dict = parser.getObj())) {
  3697. continue;
  3698. }
  3699. // taking the first one with 'ID'
  3700. if (dict.has('ID')) {
  3701. return dict;
  3702. }
  3703. }
  3704. // no tailer with 'ID', taking last one (if exists)
  3705. if (dict) {
  3706. return dict;
  3707. }
  3708. // nothing helps
  3709. // calling error() would reject worker with an UnknownErrorException.
  3710. throw new InvalidPDFException('Invalid PDF structure');
  3711. },
  3712. readXRef: function XRef_readXRef(recoveryMode) {
  3713. var stream = this.stream;
  3714. try {
  3715. while (this.startXRefQueue.length) {
  3716. var startXRef = this.startXRefQueue[0];
  3717. stream.pos = startXRef + stream.start;
  3718. var parser = new Parser(new Lexer(stream), true, this);
  3719. var obj = parser.getObj();
  3720. var dict;
  3721. // Get dictionary
  3722. if (isCmd(obj, 'xref')) {
  3723. // Parse end-of-file XRef
  3724. dict = this.processXRefTable(parser);
  3725. if (!this.topDict) {
  3726. this.topDict = dict;
  3727. }
  3728. // Recursively get other XRefs 'XRefStm', if any
  3729. obj = dict.get('XRefStm');
  3730. if (isInt(obj)) {
  3731. var pos = obj;
  3732. // ignore previously loaded xref streams
  3733. // (possible infinite recursion)
  3734. if (!(pos in this.xrefstms)) {
  3735. this.xrefstms[pos] = 1;
  3736. this.startXRefQueue.push(pos);
  3737. }
  3738. }
  3739. } else if (isInt(obj)) {
  3740. // Parse in-stream XRef
  3741. if (!isInt(parser.getObj()) ||
  3742. !isCmd(parser.getObj(), 'obj') ||
  3743. !isStream(obj = parser.getObj())) {
  3744. error('Invalid XRef stream');
  3745. }
  3746. dict = this.processXRefStream(obj);
  3747. if (!this.topDict) {
  3748. this.topDict = dict;
  3749. }
  3750. if (!dict) {
  3751. error('Failed to read XRef stream');
  3752. }
  3753. } else {
  3754. error('Invalid XRef stream header');
  3755. }
  3756. // Recursively get previous dictionary, if any
  3757. obj = dict.get('Prev');
  3758. if (isInt(obj)) {
  3759. this.startXRefQueue.push(obj);
  3760. } else if (isRef(obj)) {
  3761. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3762. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3763. this.startXRefQueue.push(obj.num);
  3764. }
  3765. this.startXRefQueue.shift();
  3766. }
  3767. return this.topDict;
  3768. } catch (e) {
  3769. if (e instanceof MissingDataException) {
  3770. throw e;
  3771. }
  3772. info('(while reading XRef): ' + e);
  3773. }
  3774. if (recoveryMode) {
  3775. return;
  3776. }
  3777. throw new XRefParseException();
  3778. },
  3779. getEntry: function XRef_getEntry(i) {
  3780. var xrefEntry = this.entries[i];
  3781. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3782. return xrefEntry;
  3783. }
  3784. return null;
  3785. },
  3786. fetchIfRef: function XRef_fetchIfRef(obj) {
  3787. if (!isRef(obj)) {
  3788. return obj;
  3789. }
  3790. return this.fetch(obj);
  3791. },
  3792. fetch: function XRef_fetch(ref, suppressEncryption) {
  3793. assert(isRef(ref), 'ref object is not a reference');
  3794. var num = ref.num;
  3795. if (num in this.cache) {
  3796. var cacheEntry = this.cache[num];
  3797. return cacheEntry;
  3798. }
  3799. var xrefEntry = this.getEntry(num);
  3800. // the referenced entry can be free
  3801. if (xrefEntry === null) {
  3802. return (this.cache[num] = null);
  3803. }
  3804. if (xrefEntry.uncompressed) {
  3805. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3806. } else {
  3807. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3808. }
  3809. if (isDict(xrefEntry)){
  3810. xrefEntry.objId = ref.toString();
  3811. } else if (isStream(xrefEntry)) {
  3812. xrefEntry.dict.objId = ref.toString();
  3813. }
  3814. return xrefEntry;
  3815. },
  3816. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3817. suppressEncryption) {
  3818. var gen = ref.gen;
  3819. var num = ref.num;
  3820. if (xrefEntry.gen !== gen) {
  3821. error('inconsistent generation in XRef');
  3822. }
  3823. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3824. this.stream.start);
  3825. var parser = new Parser(new Lexer(stream), true, this);
  3826. var obj1 = parser.getObj();
  3827. var obj2 = parser.getObj();
  3828. var obj3 = parser.getObj();
  3829. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3830. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3831. !isCmd(obj3)) {
  3832. error('bad XRef entry');
  3833. }
  3834. if (!isCmd(obj3, 'obj')) {
  3835. // some bad PDFs use "obj1234" and really mean 1234
  3836. if (obj3.cmd.indexOf('obj') === 0) {
  3837. num = parseInt(obj3.cmd.substring(3), 10);
  3838. if (!isNaN(num)) {
  3839. return num;
  3840. }
  3841. }
  3842. error('bad XRef entry');
  3843. }
  3844. if (this.encrypt && !suppressEncryption) {
  3845. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3846. } else {
  3847. xrefEntry = parser.getObj();
  3848. }
  3849. if (!isStream(xrefEntry)) {
  3850. this.cache[num] = xrefEntry;
  3851. }
  3852. return xrefEntry;
  3853. },
  3854. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3855. suppressEncryption) {
  3856. var tableOffset = xrefEntry.offset;
  3857. var stream = this.fetch(new Ref(tableOffset, 0));
  3858. if (!isStream(stream)) {
  3859. error('bad ObjStm stream');
  3860. }
  3861. var first = stream.dict.get('First');
  3862. var n = stream.dict.get('N');
  3863. if (!isInt(first) || !isInt(n)) {
  3864. error('invalid first and n parameters for ObjStm stream');
  3865. }
  3866. var parser = new Parser(new Lexer(stream), false, this);
  3867. parser.allowStreams = true;
  3868. var i, entries = [], num, nums = [];
  3869. // read the object numbers to populate cache
  3870. for (i = 0; i < n; ++i) {
  3871. num = parser.getObj();
  3872. if (!isInt(num)) {
  3873. error('invalid object number in the ObjStm stream: ' + num);
  3874. }
  3875. nums.push(num);
  3876. var offset = parser.getObj();
  3877. if (!isInt(offset)) {
  3878. error('invalid object offset in the ObjStm stream: ' + offset);
  3879. }
  3880. }
  3881. // read stream objects for cache
  3882. for (i = 0; i < n; ++i) {
  3883. entries.push(parser.getObj());
  3884. num = nums[i];
  3885. var entry = this.entries[num];
  3886. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3887. this.cache[num] = entries[i];
  3888. }
  3889. }
  3890. xrefEntry = entries[xrefEntry.gen];
  3891. if (xrefEntry === undefined) {
  3892. error('bad XRef entry for compressed object');
  3893. }
  3894. return xrefEntry;
  3895. },
  3896. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3897. if (!isRef(obj)) {
  3898. return Promise.resolve(obj);
  3899. }
  3900. return this.fetchAsync(obj);
  3901. },
  3902. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3903. var streamManager = this.stream.manager;
  3904. var xref = this;
  3905. return new Promise(function tryFetch(resolve, reject) {
  3906. try {
  3907. resolve(xref.fetch(ref, suppressEncryption));
  3908. } catch (e) {
  3909. if (e instanceof MissingDataException) {
  3910. streamManager.requestRange(e.begin, e.end, function () {
  3911. tryFetch(resolve, reject);
  3912. });
  3913. return;
  3914. }
  3915. reject(e);
  3916. }
  3917. });
  3918. },
  3919. getCatalogObj: function XRef_getCatalogObj() {
  3920. return this.root;
  3921. }
  3922. };
  3923. return XRef;
  3924. })();
  3925. /**
  3926. * A NameTree is like a Dict but has some advantageous properties, see the
  3927. * spec (7.9.6) for more details.
  3928. * TODO: implement all the Dict functions and make this more efficent.
  3929. */
  3930. var NameTree = (function NameTreeClosure() {
  3931. function NameTree(root, xref) {
  3932. this.root = root;
  3933. this.xref = xref;
  3934. }
  3935. NameTree.prototype = {
  3936. getAll: function NameTree_getAll() {
  3937. var dict = {};
  3938. if (!this.root) {
  3939. return dict;
  3940. }
  3941. var xref = this.xref;
  3942. // reading name tree
  3943. var processed = new RefSet();
  3944. processed.put(this.root);
  3945. var queue = [this.root];
  3946. while (queue.length > 0) {
  3947. var i, n;
  3948. var obj = xref.fetchIfRef(queue.shift());
  3949. if (!isDict(obj)) {
  3950. continue;
  3951. }
  3952. if (obj.has('Kids')) {
  3953. var kids = obj.get('Kids');
  3954. for (i = 0, n = kids.length; i < n; i++) {
  3955. var kid = kids[i];
  3956. if (processed.has(kid)) {
  3957. error('invalid destinations');
  3958. }
  3959. queue.push(kid);
  3960. processed.put(kid);
  3961. }
  3962. continue;
  3963. }
  3964. var names = obj.get('Names');
  3965. if (names) {
  3966. for (i = 0, n = names.length; i < n; i += 2) {
  3967. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3968. }
  3969. }
  3970. }
  3971. return dict;
  3972. },
  3973. get: function NameTree_get(destinationId) {
  3974. if (!this.root) {
  3975. return null;
  3976. }
  3977. var xref = this.xref;
  3978. var kidsOrNames = xref.fetchIfRef(this.root);
  3979. var loopCount = 0;
  3980. var MAX_NAMES_LEVELS = 10;
  3981. var l, r, m;
  3982. // Perform a binary search to quickly find the entry that
  3983. // contains the named destination we are looking for.
  3984. while (kidsOrNames.has('Kids')) {
  3985. loopCount++;
  3986. if (loopCount > MAX_NAMES_LEVELS) {
  3987. warn('Search depth limit for named destionations has been reached.');
  3988. return null;
  3989. }
  3990. var kids = kidsOrNames.get('Kids');
  3991. if (!isArray(kids)) {
  3992. return null;
  3993. }
  3994. l = 0;
  3995. r = kids.length - 1;
  3996. while (l <= r) {
  3997. m = (l + r) >> 1;
  3998. var kid = xref.fetchIfRef(kids[m]);
  3999. var limits = kid.get('Limits');
  4000. if (destinationId < limits[0]) {
  4001. r = m - 1;
  4002. } else if (destinationId > limits[1]) {
  4003. l = m + 1;
  4004. } else {
  4005. kidsOrNames = xref.fetchIfRef(kids[m]);
  4006. break;
  4007. }
  4008. }
  4009. if (l > r) {
  4010. return null;
  4011. }
  4012. }
  4013. // If we get here, then we have found the right entry. Now
  4014. // go through the named destinations in the Named dictionary
  4015. // until we find the exact destination we're looking for.
  4016. var names = kidsOrNames.get('Names');
  4017. if (isArray(names)) {
  4018. // Perform a binary search to reduce the lookup time.
  4019. l = 0;
  4020. r = names.length - 2;
  4021. while (l <= r) {
  4022. // Check only even indices (0, 2, 4, ...) because the
  4023. // odd indices contain the actual D array.
  4024. m = (l + r) & ~1;
  4025. if (destinationId < names[m]) {
  4026. r = m - 2;
  4027. } else if (destinationId > names[m]) {
  4028. l = m + 2;
  4029. } else {
  4030. return xref.fetchIfRef(names[m + 1]);
  4031. }
  4032. }
  4033. }
  4034. return null;
  4035. }
  4036. };
  4037. return NameTree;
  4038. })();
  4039. /**
  4040. * "A PDF file can refer to the contents of another file by using a File
  4041. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4042. * NOTE: Only embedded files are supported (as part of the attachments support)
  4043. * TODO: support the 'URL' file system (with caching if !/V), portable
  4044. * collections attributes and related files (/RF)
  4045. */
  4046. var FileSpec = (function FileSpecClosure() {
  4047. function FileSpec(root, xref) {
  4048. if (!root || !isDict(root)) {
  4049. return;
  4050. }
  4051. this.xref = xref;
  4052. this.root = root;
  4053. if (root.has('FS')) {
  4054. this.fs = root.get('FS');
  4055. }
  4056. this.description = root.has('Desc') ?
  4057. stringToPDFString(root.get('Desc')) :
  4058. '';
  4059. if (root.has('RF')) {
  4060. warn('Related file specifications are not supported');
  4061. }
  4062. this.contentAvailable = true;
  4063. if (!root.has('EF')) {
  4064. this.contentAvailable = false;
  4065. warn('Non-embedded file specifications are not supported');
  4066. }
  4067. }
  4068. function pickPlatformItem(dict) {
  4069. // Look for the filename in this order:
  4070. // UF, F, Unix, Mac, DOS
  4071. if (dict.has('UF')) {
  4072. return dict.get('UF');
  4073. } else if (dict.has('F')) {
  4074. return dict.get('F');
  4075. } else if (dict.has('Unix')) {
  4076. return dict.get('Unix');
  4077. } else if (dict.has('Mac')) {
  4078. return dict.get('Mac');
  4079. } else if (dict.has('DOS')) {
  4080. return dict.get('DOS');
  4081. } else {
  4082. return null;
  4083. }
  4084. }
  4085. FileSpec.prototype = {
  4086. get filename() {
  4087. if (!this._filename && this.root) {
  4088. var filename = pickPlatformItem(this.root) || 'unnamed';
  4089. this._filename = stringToPDFString(filename).
  4090. replace(/\\\\/g, '\\').
  4091. replace(/\\\//g, '/').
  4092. replace(/\\/g, '/');
  4093. }
  4094. return this._filename;
  4095. },
  4096. get content() {
  4097. if (!this.contentAvailable) {
  4098. return null;
  4099. }
  4100. if (!this.contentRef && this.root) {
  4101. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4102. }
  4103. var content = null;
  4104. if (this.contentRef) {
  4105. var xref = this.xref;
  4106. var fileObj = xref.fetchIfRef(this.contentRef);
  4107. if (fileObj && isStream(fileObj)) {
  4108. content = fileObj.getBytes();
  4109. } else {
  4110. warn('Embedded file specification points to non-existing/invalid ' +
  4111. 'content');
  4112. }
  4113. } else {
  4114. warn('Embedded file specification does not have a content');
  4115. }
  4116. return content;
  4117. },
  4118. get serializable() {
  4119. return {
  4120. filename: this.filename,
  4121. content: this.content
  4122. };
  4123. }
  4124. };
  4125. return FileSpec;
  4126. })();
  4127. /**
  4128. * A helper for loading missing data in object graphs. It traverses the graph
  4129. * depth first and queues up any objects that have missing data. Once it has
  4130. * has traversed as many objects that are available it attempts to bundle the
  4131. * missing data requests and then resume from the nodes that weren't ready.
  4132. *
  4133. * NOTE: It provides protection from circular references by keeping track of
  4134. * of loaded references. However, you must be careful not to load any graphs
  4135. * that have references to the catalog or other pages since that will cause the
  4136. * entire PDF document object graph to be traversed.
  4137. */
  4138. var ObjectLoader = (function() {
  4139. function mayHaveChildren(value) {
  4140. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4141. }
  4142. function addChildren(node, nodesToVisit) {
  4143. var value;
  4144. if (isDict(node) || isStream(node)) {
  4145. var map;
  4146. if (isDict(node)) {
  4147. map = node.map;
  4148. } else {
  4149. map = node.dict.map;
  4150. }
  4151. for (var key in map) {
  4152. value = map[key];
  4153. if (mayHaveChildren(value)) {
  4154. nodesToVisit.push(value);
  4155. }
  4156. }
  4157. } else if (isArray(node)) {
  4158. for (var i = 0, ii = node.length; i < ii; i++) {
  4159. value = node[i];
  4160. if (mayHaveChildren(value)) {
  4161. nodesToVisit.push(value);
  4162. }
  4163. }
  4164. }
  4165. }
  4166. function ObjectLoader(obj, keys, xref) {
  4167. this.obj = obj;
  4168. this.keys = keys;
  4169. this.xref = xref;
  4170. this.refSet = null;
  4171. }
  4172. ObjectLoader.prototype = {
  4173. load: function ObjectLoader_load() {
  4174. var keys = this.keys;
  4175. this.capability = createPromiseCapability();
  4176. // Don't walk the graph if all the data is already loaded.
  4177. if (!(this.xref.stream instanceof ChunkedStream) ||
  4178. this.xref.stream.getMissingChunks().length === 0) {
  4179. this.capability.resolve();
  4180. return this.capability.promise;
  4181. }
  4182. this.refSet = new RefSet();
  4183. // Setup the initial nodes to visit.
  4184. var nodesToVisit = [];
  4185. for (var i = 0; i < keys.length; i++) {
  4186. nodesToVisit.push(this.obj[keys[i]]);
  4187. }
  4188. this.walk(nodesToVisit);
  4189. return this.capability.promise;
  4190. },
  4191. walk: function ObjectLoader_walk(nodesToVisit) {
  4192. var nodesToRevisit = [];
  4193. var pendingRequests = [];
  4194. // DFS walk of the object graph.
  4195. while (nodesToVisit.length) {
  4196. var currentNode = nodesToVisit.pop();
  4197. // Only references or chunked streams can cause missing data exceptions.
  4198. if (isRef(currentNode)) {
  4199. // Skip nodes that have already been visited.
  4200. if (this.refSet.has(currentNode)) {
  4201. continue;
  4202. }
  4203. try {
  4204. var ref = currentNode;
  4205. this.refSet.put(ref);
  4206. currentNode = this.xref.fetch(currentNode);
  4207. } catch (e) {
  4208. if (!(e instanceof MissingDataException)) {
  4209. throw e;
  4210. }
  4211. nodesToRevisit.push(currentNode);
  4212. pendingRequests.push({ begin: e.begin, end: e.end });
  4213. }
  4214. }
  4215. if (currentNode && currentNode.getBaseStreams) {
  4216. var baseStreams = currentNode.getBaseStreams();
  4217. var foundMissingData = false;
  4218. for (var i = 0; i < baseStreams.length; i++) {
  4219. var stream = baseStreams[i];
  4220. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4221. foundMissingData = true;
  4222. pendingRequests.push({
  4223. begin: stream.start,
  4224. end: stream.end
  4225. });
  4226. }
  4227. }
  4228. if (foundMissingData) {
  4229. nodesToRevisit.push(currentNode);
  4230. }
  4231. }
  4232. addChildren(currentNode, nodesToVisit);
  4233. }
  4234. if (pendingRequests.length) {
  4235. this.xref.stream.manager.requestRanges(pendingRequests,
  4236. function pendingRequestCallback() {
  4237. nodesToVisit = nodesToRevisit;
  4238. for (var i = 0; i < nodesToRevisit.length; i++) {
  4239. var node = nodesToRevisit[i];
  4240. // Remove any reference nodes from the currrent refset so they
  4241. // aren't skipped when we revist them.
  4242. if (isRef(node)) {
  4243. this.refSet.remove(node);
  4244. }
  4245. }
  4246. this.walk(nodesToVisit);
  4247. }.bind(this));
  4248. return;
  4249. }
  4250. // Everything is loaded.
  4251. this.refSet = null;
  4252. this.capability.resolve();
  4253. }
  4254. };
  4255. return ObjectLoader;
  4256. })();
  4257. var ISOAdobeCharset = [
  4258. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4259. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4260. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4261. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4262. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4263. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4264. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4265. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4266. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4267. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4268. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4269. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4270. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4271. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4272. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4273. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4274. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4275. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4276. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4277. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4278. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4279. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4280. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4281. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4282. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4283. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4284. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4285. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4286. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4287. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4288. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4289. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4290. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4291. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4292. ];
  4293. var ExpertCharset = [
  4294. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4295. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4296. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4297. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4298. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4299. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4300. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4301. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4302. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4303. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4304. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4305. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4306. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4307. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4308. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4309. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4310. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4311. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4312. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4313. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4314. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4315. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4316. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4317. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4318. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4319. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4320. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4321. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4322. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4323. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4324. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4325. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4326. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4327. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4328. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4329. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4330. 'Ydieresissmall'
  4331. ];
  4332. var ExpertSubsetCharset = [
  4333. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4334. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4335. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4336. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4337. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4338. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4339. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4340. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4341. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4342. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4343. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4344. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4345. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4346. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4347. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4348. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4349. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4350. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4351. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4352. 'periodinferior', 'commainferior'
  4353. ];
  4354. var DEFAULT_ICON_SIZE = 22; // px
  4355. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4356. var Annotation = (function AnnotationClosure() {
  4357. // 12.5.5: Algorithm: Appearance streams
  4358. function getTransformMatrix(rect, bbox, matrix) {
  4359. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4360. var minX = bounds[0];
  4361. var minY = bounds[1];
  4362. var maxX = bounds[2];
  4363. var maxY = bounds[3];
  4364. if (minX === maxX || minY === maxY) {
  4365. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4366. // just apply the transform for rect
  4367. return [1, 0, 0, 1, rect[0], rect[1]];
  4368. }
  4369. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4370. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4371. return [
  4372. xRatio,
  4373. 0,
  4374. 0,
  4375. yRatio,
  4376. rect[0] - minX * xRatio,
  4377. rect[1] - minY * yRatio
  4378. ];
  4379. }
  4380. function getDefaultAppearance(dict) {
  4381. var appearanceState = dict.get('AP');
  4382. if (!isDict(appearanceState)) {
  4383. return;
  4384. }
  4385. var appearance;
  4386. var appearances = appearanceState.get('N');
  4387. if (isDict(appearances)) {
  4388. var as = dict.get('AS');
  4389. if (as && appearances.has(as.name)) {
  4390. appearance = appearances.get(as.name);
  4391. }
  4392. } else {
  4393. appearance = appearances;
  4394. }
  4395. return appearance;
  4396. }
  4397. function Annotation(params) {
  4398. var dict = params.dict;
  4399. var data = this.data = {};
  4400. data.subtype = dict.get('Subtype').name;
  4401. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4402. data.rect = Util.normalizeRect(rect);
  4403. data.annotationFlags = dict.get('F');
  4404. var color = dict.get('C');
  4405. if (!color) {
  4406. // The PDF spec does not mention how a missing color array is interpreted.
  4407. // Adobe Reader seems to default to black in this case.
  4408. data.color = [0, 0, 0];
  4409. } else if (isArray(color)) {
  4410. switch (color.length) {
  4411. case 0:
  4412. // Empty array denotes transparent border.
  4413. data.color = null;
  4414. break;
  4415. case 1:
  4416. // TODO: implement DeviceGray
  4417. break;
  4418. case 3:
  4419. data.color = color;
  4420. break;
  4421. case 4:
  4422. // TODO: implement DeviceCMYK
  4423. break;
  4424. }
  4425. }
  4426. // Some types of annotations have border style dict which has more
  4427. // info than the border array
  4428. if (dict.has('BS')) {
  4429. var borderStyle = dict.get('BS');
  4430. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4431. } else {
  4432. var borderArray = dict.get('Border') || [0, 0, 1];
  4433. data.borderWidth = borderArray[2] || 0;
  4434. // TODO: implement proper support for annotations with line dash patterns.
  4435. var dashArray = borderArray[3];
  4436. if (data.borderWidth > 0 && dashArray) {
  4437. if (!isArray(dashArray)) {
  4438. // Ignore the border if dashArray is not actually an array,
  4439. // this is consistent with the behaviour in Adobe Reader.
  4440. data.borderWidth = 0;
  4441. } else {
  4442. var dashArrayLength = dashArray.length;
  4443. if (dashArrayLength > 0) {
  4444. // According to the PDF specification: the elements in a dashArray
  4445. // shall be numbers that are nonnegative and not all equal to zero.
  4446. var isInvalid = false;
  4447. var numPositive = 0;
  4448. for (var i = 0; i < dashArrayLength; i++) {
  4449. var validNumber = (+dashArray[i] >= 0);
  4450. if (!validNumber) {
  4451. isInvalid = true;
  4452. break;
  4453. } else if (dashArray[i] > 0) {
  4454. numPositive++;
  4455. }
  4456. }
  4457. if (isInvalid || numPositive === 0) {
  4458. data.borderWidth = 0;
  4459. }
  4460. }
  4461. }
  4462. }
  4463. }
  4464. this.appearance = getDefaultAppearance(dict);
  4465. data.hasAppearance = !!this.appearance;
  4466. data.id = params.ref.num;
  4467. }
  4468. Annotation.prototype = {
  4469. getData: function Annotation_getData() {
  4470. return this.data;
  4471. },
  4472. isInvisible: function Annotation_isInvisible() {
  4473. var data = this.data;
  4474. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4475. return false;
  4476. } else {
  4477. return !!(data &&
  4478. data.annotationFlags && // Default: not invisible
  4479. data.annotationFlags & 0x1); // Invisible
  4480. }
  4481. },
  4482. isViewable: function Annotation_isViewable() {
  4483. var data = this.data;
  4484. return !!(!this.isInvisible() &&
  4485. data &&
  4486. (!data.annotationFlags ||
  4487. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4488. data.rect); // rectangle is necessary
  4489. },
  4490. isPrintable: function Annotation_isPrintable() {
  4491. var data = this.data;
  4492. return !!(!this.isInvisible() &&
  4493. data &&
  4494. data.annotationFlags && // Default: not printable
  4495. data.annotationFlags & 0x4 && // Print
  4496. !(data.annotationFlags & 0x2) && // Hidden
  4497. data.rect); // rectangle is necessary
  4498. },
  4499. loadResources: function Annotation_loadResources(keys) {
  4500. return new Promise(function (resolve, reject) {
  4501. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4502. if (!resources) {
  4503. resolve();
  4504. return;
  4505. }
  4506. var objectLoader = new ObjectLoader(resources.map,
  4507. keys,
  4508. resources.xref);
  4509. objectLoader.load().then(function() {
  4510. resolve(resources);
  4511. }, reject);
  4512. }, reject);
  4513. }.bind(this));
  4514. },
  4515. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4516. if (!this.appearance) {
  4517. return Promise.resolve(new OperatorList());
  4518. }
  4519. var data = this.data;
  4520. var appearanceDict = this.appearance.dict;
  4521. var resourcesPromise = this.loadResources([
  4522. 'ExtGState',
  4523. 'ColorSpace',
  4524. 'Pattern',
  4525. 'Shading',
  4526. 'XObject',
  4527. 'Font'
  4528. // ProcSet
  4529. // Properties
  4530. ]);
  4531. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4532. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4533. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4534. var self = this;
  4535. return resourcesPromise.then(function(resources) {
  4536. var opList = new OperatorList();
  4537. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4538. return evaluator.getOperatorList(self.appearance, resources, opList).
  4539. then(function () {
  4540. opList.addOp(OPS.endAnnotation, []);
  4541. self.appearance.reset();
  4542. return opList;
  4543. });
  4544. });
  4545. }
  4546. };
  4547. Annotation.getConstructor =
  4548. function Annotation_getConstructor(subtype, fieldType) {
  4549. if (!subtype) {
  4550. return;
  4551. }
  4552. // TODO(mack): Implement FreeText annotations
  4553. if (subtype === 'Link') {
  4554. return LinkAnnotation;
  4555. } else if (subtype === 'Text') {
  4556. return TextAnnotation;
  4557. } else if (subtype === 'Widget') {
  4558. if (!fieldType) {
  4559. return;
  4560. }
  4561. if (fieldType === 'Tx') {
  4562. return TextWidgetAnnotation;
  4563. } else {
  4564. return WidgetAnnotation;
  4565. }
  4566. } else {
  4567. return Annotation;
  4568. }
  4569. };
  4570. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4571. var dict = xref.fetchIfRef(ref);
  4572. if (!isDict(dict)) {
  4573. return;
  4574. }
  4575. var subtype = dict.get('Subtype');
  4576. subtype = isName(subtype) ? subtype.name : '';
  4577. if (!subtype) {
  4578. return;
  4579. }
  4580. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4581. fieldType = isName(fieldType) ? fieldType.name : '';
  4582. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4583. if (!Constructor) {
  4584. return;
  4585. }
  4586. var params = {
  4587. dict: dict,
  4588. ref: ref,
  4589. };
  4590. var annotation = new Constructor(params);
  4591. if (annotation.isViewable() || annotation.isPrintable()) {
  4592. return annotation;
  4593. } else {
  4594. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4595. warn('unimplemented annotation type: ' + subtype);
  4596. }
  4597. }
  4598. };
  4599. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4600. annotations, opList, pdfManager, partialEvaluator, intent) {
  4601. function reject(e) {
  4602. annotationsReadyCapability.reject(e);
  4603. }
  4604. var annotationsReadyCapability = createPromiseCapability();
  4605. var annotationPromises = [];
  4606. for (var i = 0, n = annotations.length; i < n; ++i) {
  4607. if (intent === 'display' && annotations[i].isViewable() ||
  4608. intent === 'print' && annotations[i].isPrintable()) {
  4609. annotationPromises.push(
  4610. annotations[i].getOperatorList(partialEvaluator));
  4611. }
  4612. }
  4613. Promise.all(annotationPromises).then(function(datas) {
  4614. opList.addOp(OPS.beginAnnotations, []);
  4615. for (var i = 0, n = datas.length; i < n; ++i) {
  4616. var annotOpList = datas[i];
  4617. opList.addOpList(annotOpList);
  4618. }
  4619. opList.addOp(OPS.endAnnotations, []);
  4620. annotationsReadyCapability.resolve();
  4621. }, reject);
  4622. return annotationsReadyCapability.promise;
  4623. };
  4624. return Annotation;
  4625. })();
  4626. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4627. function WidgetAnnotation(params) {
  4628. Annotation.call(this, params);
  4629. var dict = params.dict;
  4630. var data = this.data;
  4631. data.fieldValue = stringToPDFString(
  4632. Util.getInheritableProperty(dict, 'V') || '');
  4633. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4634. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4635. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4636. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4637. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4638. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4639. // Building the full field name by collecting the field and
  4640. // its ancestors 'T' data and joining them using '.'.
  4641. var fieldName = [];
  4642. var namedItem = dict;
  4643. var ref = params.ref;
  4644. while (namedItem) {
  4645. var parent = namedItem.get('Parent');
  4646. var parentRef = namedItem.getRaw('Parent');
  4647. var name = namedItem.get('T');
  4648. if (name) {
  4649. fieldName.unshift(stringToPDFString(name));
  4650. } else if (parent && ref) {
  4651. // The field name is absent, that means more than one field
  4652. // with the same name may exist. Replacing the empty name
  4653. // with the '`' plus index in the parent's 'Kids' array.
  4654. // This is not in the PDF spec but necessary to id the
  4655. // the input controls.
  4656. var kids = parent.get('Kids');
  4657. var j, jj;
  4658. for (j = 0, jj = kids.length; j < jj; j++) {
  4659. var kidRef = kids[j];
  4660. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4661. break;
  4662. }
  4663. }
  4664. fieldName.unshift('`' + j);
  4665. }
  4666. namedItem = parent;
  4667. ref = parentRef;
  4668. }
  4669. data.fullName = fieldName.join('.');
  4670. }
  4671. var parent = Annotation.prototype;
  4672. Util.inherit(WidgetAnnotation, Annotation, {
  4673. isViewable: function WidgetAnnotation_isViewable() {
  4674. if (this.data.fieldType === 'Sig') {
  4675. warn('unimplemented annotation type: Widget signature');
  4676. return false;
  4677. }
  4678. return parent.isViewable.call(this);
  4679. }
  4680. });
  4681. return WidgetAnnotation;
  4682. })();
  4683. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4684. function TextWidgetAnnotation(params) {
  4685. WidgetAnnotation.call(this, params);
  4686. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4687. this.data.annotationType = AnnotationType.WIDGET;
  4688. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4689. }
  4690. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4691. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4692. if (this.appearance) {
  4693. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4694. }
  4695. var opList = new OperatorList();
  4696. var data = this.data;
  4697. // Even if there is an appearance stream, ignore it. This is the
  4698. // behaviour used by Adobe Reader.
  4699. if (!data.defaultAppearance) {
  4700. return Promise.resolve(opList);
  4701. }
  4702. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4703. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4704. then(function () {
  4705. return opList;
  4706. });
  4707. }
  4708. });
  4709. return TextWidgetAnnotation;
  4710. })();
  4711. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4712. function InteractiveAnnotation(params) {
  4713. Annotation.call(this, params);
  4714. this.data.hasHtml = true;
  4715. }
  4716. Util.inherit(InteractiveAnnotation, Annotation, { });
  4717. return InteractiveAnnotation;
  4718. })();
  4719. var TextAnnotation = (function TextAnnotationClosure() {
  4720. function TextAnnotation(params) {
  4721. InteractiveAnnotation.call(this, params);
  4722. var dict = params.dict;
  4723. var data = this.data;
  4724. var content = dict.get('Contents');
  4725. var title = dict.get('T');
  4726. data.annotationType = AnnotationType.TEXT;
  4727. data.content = stringToPDFString(content || '');
  4728. data.title = stringToPDFString(title || '');
  4729. if (data.hasAppearance) {
  4730. data.name = 'NoIcon';
  4731. } else {
  4732. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4733. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4734. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4735. }
  4736. if (dict.has('C')) {
  4737. data.hasBgColor = true;
  4738. }
  4739. }
  4740. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4741. return TextAnnotation;
  4742. })();
  4743. var LinkAnnotation = (function LinkAnnotationClosure() {
  4744. function LinkAnnotation(params) {
  4745. InteractiveAnnotation.call(this, params);
  4746. var dict = params.dict;
  4747. var data = this.data;
  4748. data.annotationType = AnnotationType.LINK;
  4749. var action = dict.get('A');
  4750. if (action) {
  4751. var linkType = action.get('S').name;
  4752. if (linkType === 'URI') {
  4753. var url = action.get('URI');
  4754. if (isName(url)) {
  4755. // Some bad PDFs do not put parentheses around relative URLs.
  4756. url = '/' + url.name;
  4757. } else if (url) {
  4758. url = addDefaultProtocolToUrl(url);
  4759. }
  4760. // TODO: pdf spec mentions urls can be relative to a Base
  4761. // entry in the dictionary.
  4762. if (!isValidUrl(url, false)) {
  4763. url = '';
  4764. }
  4765. data.url = url;
  4766. } else if (linkType === 'GoTo') {
  4767. data.dest = action.get('D');
  4768. } else if (linkType === 'GoToR') {
  4769. var urlDict = action.get('F');
  4770. if (isDict(urlDict)) {
  4771. // We assume that the 'url' is a Filspec dictionary
  4772. // and fetch the url without checking any further
  4773. url = urlDict.get('F') || '';
  4774. }
  4775. // TODO: pdf reference says that GoToR
  4776. // can also have 'NewWindow' attribute
  4777. if (!isValidUrl(url, false)) {
  4778. url = '';
  4779. }
  4780. data.url = url;
  4781. data.dest = action.get('D');
  4782. } else if (linkType === 'Named') {
  4783. data.action = action.get('N').name;
  4784. } else {
  4785. warn('unrecognized link type: ' + linkType);
  4786. }
  4787. } else if (dict.has('Dest')) {
  4788. // simple destination link
  4789. var dest = dict.get('Dest');
  4790. data.dest = isName(dest) ? dest.name : dest;
  4791. }
  4792. }
  4793. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4794. function addDefaultProtocolToUrl(url) {
  4795. if (url && url.indexOf('www.') === 0) {
  4796. return ('http://' + url);
  4797. }
  4798. return url;
  4799. }
  4800. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4801. return LinkAnnotation;
  4802. })();
  4803. var PDFFunction = (function PDFFunctionClosure() {
  4804. var CONSTRUCT_SAMPLED = 0;
  4805. var CONSTRUCT_INTERPOLATED = 2;
  4806. var CONSTRUCT_STICHED = 3;
  4807. var CONSTRUCT_POSTSCRIPT = 4;
  4808. return {
  4809. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4810. str) {
  4811. var i, ii;
  4812. var length = 1;
  4813. for (i = 0, ii = size.length; i < ii; i++) {
  4814. length *= size[i];
  4815. }
  4816. length *= outputSize;
  4817. var array = new Array(length);
  4818. var codeSize = 0;
  4819. var codeBuf = 0;
  4820. // 32 is a valid bps so shifting won't work
  4821. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4822. var strBytes = str.getBytes((length * bps + 7) / 8);
  4823. var strIdx = 0;
  4824. for (i = 0; i < length; i++) {
  4825. while (codeSize < bps) {
  4826. codeBuf <<= 8;
  4827. codeBuf |= strBytes[strIdx++];
  4828. codeSize += 8;
  4829. }
  4830. codeSize -= bps;
  4831. array[i] = (codeBuf >> codeSize) * sampleMul;
  4832. codeBuf &= (1 << codeSize) - 1;
  4833. }
  4834. return array;
  4835. },
  4836. getIR: function PDFFunction_getIR(xref, fn) {
  4837. var dict = fn.dict;
  4838. if (!dict) {
  4839. dict = fn;
  4840. }
  4841. var types = [this.constructSampled,
  4842. null,
  4843. this.constructInterpolated,
  4844. this.constructStiched,
  4845. this.constructPostScript];
  4846. var typeNum = dict.get('FunctionType');
  4847. var typeFn = types[typeNum];
  4848. if (!typeFn) {
  4849. error('Unknown type of function');
  4850. }
  4851. return typeFn.call(this, fn, dict, xref);
  4852. },
  4853. fromIR: function PDFFunction_fromIR(IR) {
  4854. var type = IR[0];
  4855. switch (type) {
  4856. case CONSTRUCT_SAMPLED:
  4857. return this.constructSampledFromIR(IR);
  4858. case CONSTRUCT_INTERPOLATED:
  4859. return this.constructInterpolatedFromIR(IR);
  4860. case CONSTRUCT_STICHED:
  4861. return this.constructStichedFromIR(IR);
  4862. //case CONSTRUCT_POSTSCRIPT:
  4863. default:
  4864. return this.constructPostScriptFromIR(IR);
  4865. }
  4866. },
  4867. parse: function PDFFunction_parse(xref, fn) {
  4868. var IR = this.getIR(xref, fn);
  4869. return this.fromIR(IR);
  4870. },
  4871. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  4872. if (!isArray(fnObj)) {
  4873. // not an array -- parsing as regular function
  4874. return this.parse(xref, fnObj);
  4875. }
  4876. var fnArray = [];
  4877. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  4878. var obj = xref.fetchIfRef(fnObj[j]);
  4879. fnArray.push(PDFFunction.parse(xref, obj));
  4880. }
  4881. return function (src, srcOffset, dest, destOffset) {
  4882. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  4883. fnArray[i](src, srcOffset, dest, destOffset + i);
  4884. }
  4885. };
  4886. },
  4887. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4888. function toMultiArray(arr) {
  4889. var inputLength = arr.length;
  4890. var out = [];
  4891. var index = 0;
  4892. for (var i = 0; i < inputLength; i += 2) {
  4893. out[index] = [arr[i], arr[i + 1]];
  4894. ++index;
  4895. }
  4896. return out;
  4897. }
  4898. var domain = dict.get('Domain');
  4899. var range = dict.get('Range');
  4900. if (!domain || !range) {
  4901. error('No domain or range');
  4902. }
  4903. var inputSize = domain.length / 2;
  4904. var outputSize = range.length / 2;
  4905. domain = toMultiArray(domain);
  4906. range = toMultiArray(range);
  4907. var size = dict.get('Size');
  4908. var bps = dict.get('BitsPerSample');
  4909. var order = dict.get('Order') || 1;
  4910. if (order !== 1) {
  4911. // No description how cubic spline interpolation works in PDF32000:2008
  4912. // As in poppler, ignoring order, linear interpolation may work as good
  4913. info('No support for cubic spline interpolation: ' + order);
  4914. }
  4915. var encode = dict.get('Encode');
  4916. if (!encode) {
  4917. encode = [];
  4918. for (var i = 0; i < inputSize; ++i) {
  4919. encode.push(0);
  4920. encode.push(size[i] - 1);
  4921. }
  4922. }
  4923. encode = toMultiArray(encode);
  4924. var decode = dict.get('Decode');
  4925. if (!decode) {
  4926. decode = range;
  4927. } else {
  4928. decode = toMultiArray(decode);
  4929. }
  4930. var samples = this.getSampleArray(size, outputSize, bps, str);
  4931. return [
  4932. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4933. outputSize, Math.pow(2, bps) - 1, range
  4934. ];
  4935. },
  4936. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4937. // See chapter 3, page 109 of the PDF reference
  4938. function interpolate(x, xmin, xmax, ymin, ymax) {
  4939. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4940. }
  4941. return function constructSampledFromIRResult(src, srcOffset,
  4942. dest, destOffset) {
  4943. // See chapter 3, page 110 of the PDF reference.
  4944. var m = IR[1];
  4945. var domain = IR[2];
  4946. var encode = IR[3];
  4947. var decode = IR[4];
  4948. var samples = IR[5];
  4949. var size = IR[6];
  4950. var n = IR[7];
  4951. //var mask = IR[8];
  4952. var range = IR[9];
  4953. // Building the cube vertices: its part and sample index
  4954. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4955. var cubeVertices = 1 << m;
  4956. var cubeN = new Float64Array(cubeVertices);
  4957. var cubeVertex = new Uint32Array(cubeVertices);
  4958. var i, j;
  4959. for (j = 0; j < cubeVertices; j++) {
  4960. cubeN[j] = 1;
  4961. }
  4962. var k = n, pos = 1;
  4963. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4964. for (i = 0; i < m; ++i) {
  4965. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4966. var domain_2i = domain[i][0];
  4967. var domain_2i_1 = domain[i][1];
  4968. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  4969. domain_2i_1);
  4970. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4971. // Encode_2i, Encode_2i+1)
  4972. var e = interpolate(xi, domain_2i, domain_2i_1,
  4973. encode[i][0], encode[i][1]);
  4974. // e_i' = min(max(e_i, 0), Size_i - 1)
  4975. var size_i = size[i];
  4976. e = Math.min(Math.max(e, 0), size_i - 1);
  4977. // Adjusting the cube: N and vertex sample index
  4978. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4979. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4980. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4981. var offset0 = e0 * k;
  4982. var offset1 = offset0 + k; // e1 * k
  4983. for (j = 0; j < cubeVertices; j++) {
  4984. if (j & pos) {
  4985. cubeN[j] *= n1;
  4986. cubeVertex[j] += offset1;
  4987. } else {
  4988. cubeN[j] *= n0;
  4989. cubeVertex[j] += offset0;
  4990. }
  4991. }
  4992. k *= size_i;
  4993. pos <<= 1;
  4994. }
  4995. for (j = 0; j < n; ++j) {
  4996. // Sum all cube vertices' samples portions
  4997. var rj = 0;
  4998. for (i = 0; i < cubeVertices; i++) {
  4999. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5000. }
  5001. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5002. // Decode_2j, Decode_2j+1)
  5003. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5004. // y_j = min(max(r_j, range_2j), range_2j+1)
  5005. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5006. range[j][1]);
  5007. }
  5008. };
  5009. },
  5010. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5011. dict) {
  5012. var c0 = dict.get('C0') || [0];
  5013. var c1 = dict.get('C1') || [1];
  5014. var n = dict.get('N');
  5015. if (!isArray(c0) || !isArray(c1)) {
  5016. error('Illegal dictionary for interpolated function');
  5017. }
  5018. var length = c0.length;
  5019. var diff = [];
  5020. for (var i = 0; i < length; ++i) {
  5021. diff.push(c1[i] - c0[i]);
  5022. }
  5023. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5024. },
  5025. constructInterpolatedFromIR:
  5026. function PDFFunction_constructInterpolatedFromIR(IR) {
  5027. var c0 = IR[1];
  5028. var diff = IR[2];
  5029. var n = IR[3];
  5030. var length = diff.length;
  5031. return function constructInterpolatedFromIRResult(src, srcOffset,
  5032. dest, destOffset) {
  5033. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5034. for (var j = 0; j < length; ++j) {
  5035. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5036. }
  5037. };
  5038. },
  5039. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5040. var domain = dict.get('Domain');
  5041. if (!domain) {
  5042. error('No domain');
  5043. }
  5044. var inputSize = domain.length / 2;
  5045. if (inputSize !== 1) {
  5046. error('Bad domain for stiched function');
  5047. }
  5048. var fnRefs = dict.get('Functions');
  5049. var fns = [];
  5050. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5051. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5052. }
  5053. var bounds = dict.get('Bounds');
  5054. var encode = dict.get('Encode');
  5055. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5056. },
  5057. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5058. var domain = IR[1];
  5059. var bounds = IR[2];
  5060. var encode = IR[3];
  5061. var fnsIR = IR[4];
  5062. var fns = [];
  5063. var tmpBuf = new Float32Array(1);
  5064. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5065. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5066. }
  5067. return function constructStichedFromIRResult(src, srcOffset,
  5068. dest, destOffset) {
  5069. var clip = function constructStichedFromIRClip(v, min, max) {
  5070. if (v > max) {
  5071. v = max;
  5072. } else if (v < min) {
  5073. v = min;
  5074. }
  5075. return v;
  5076. };
  5077. // clip to domain
  5078. var v = clip(src[srcOffset], domain[0], domain[1]);
  5079. // calulate which bound the value is in
  5080. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5081. if (v < bounds[i]) {
  5082. break;
  5083. }
  5084. }
  5085. // encode value into domain of function
  5086. var dmin = domain[0];
  5087. if (i > 0) {
  5088. dmin = bounds[i - 1];
  5089. }
  5090. var dmax = domain[1];
  5091. if (i < bounds.length) {
  5092. dmax = bounds[i];
  5093. }
  5094. var rmin = encode[2 * i];
  5095. var rmax = encode[2 * i + 1];
  5096. tmpBuf[0] = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5097. // call the appropriate function
  5098. fns[i](tmpBuf, 0, dest, destOffset);
  5099. };
  5100. },
  5101. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5102. xref) {
  5103. var domain = dict.get('Domain');
  5104. var range = dict.get('Range');
  5105. if (!domain) {
  5106. error('No domain.');
  5107. }
  5108. if (!range) {
  5109. error('No range.');
  5110. }
  5111. var lexer = new PostScriptLexer(fn);
  5112. var parser = new PostScriptParser(lexer);
  5113. var code = parser.parse();
  5114. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5115. },
  5116. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5117. IR) {
  5118. var domain = IR[1];
  5119. var range = IR[2];
  5120. var code = IR[3];
  5121. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5122. if (compiled) {
  5123. // Compiled function consists of simple expressions such as addition,
  5124. // subtraction, Math.max, and also contains 'var' and 'return'
  5125. // statements. See the generation in the PostScriptCompiler below.
  5126. /*jshint -W054 */
  5127. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5128. }
  5129. info('Unable to compile PS function');
  5130. var numOutputs = range.length >> 1;
  5131. var numInputs = domain.length >> 1;
  5132. var evaluator = new PostScriptEvaluator(code);
  5133. // Cache the values for a big speed up, the cache size is limited though
  5134. // since the number of possible values can be huge from a PS function.
  5135. var cache = {};
  5136. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5137. // seen in our tests.
  5138. var MAX_CACHE_SIZE = 2048 * 4;
  5139. var cache_available = MAX_CACHE_SIZE;
  5140. var tmpBuf = new Float32Array(numInputs);
  5141. return function constructPostScriptFromIRResult(src, srcOffset,
  5142. dest, destOffset) {
  5143. var i, value;
  5144. var key = '';
  5145. var input = tmpBuf;
  5146. for (i = 0; i < numInputs; i++) {
  5147. value = src[srcOffset + i];
  5148. input[i] = value;
  5149. key += value + '_';
  5150. }
  5151. var cachedValue = cache[key];
  5152. if (cachedValue !== undefined) {
  5153. dest.set(cachedValue, destOffset);
  5154. return;
  5155. }
  5156. var output = new Float32Array(numOutputs);
  5157. var stack = evaluator.execute(input);
  5158. var stackIndex = stack.length - numOutputs;
  5159. for (i = 0; i < numOutputs; i++) {
  5160. value = stack[stackIndex + i];
  5161. var bound = range[i * 2];
  5162. if (value < bound) {
  5163. value = bound;
  5164. } else {
  5165. bound = range[i * 2 +1];
  5166. if (value > bound) {
  5167. value = bound;
  5168. }
  5169. }
  5170. output[i] = value;
  5171. }
  5172. if (cache_available > 0) {
  5173. cache_available--;
  5174. cache[key] = output;
  5175. }
  5176. dest.set(output, destOffset);
  5177. };
  5178. }
  5179. };
  5180. })();
  5181. function isPDFFunction(v) {
  5182. var fnDict;
  5183. if (typeof v !== 'object') {
  5184. return false;
  5185. } else if (isDict(v)) {
  5186. fnDict = v;
  5187. } else if (isStream(v)) {
  5188. fnDict = v.dict;
  5189. } else {
  5190. return false;
  5191. }
  5192. return fnDict.has('FunctionType');
  5193. }
  5194. var PostScriptStack = (function PostScriptStackClosure() {
  5195. var MAX_STACK_SIZE = 100;
  5196. function PostScriptStack(initialStack) {
  5197. this.stack = !initialStack ? [] :
  5198. Array.prototype.slice.call(initialStack, 0);
  5199. }
  5200. PostScriptStack.prototype = {
  5201. push: function PostScriptStack_push(value) {
  5202. if (this.stack.length >= MAX_STACK_SIZE) {
  5203. error('PostScript function stack overflow.');
  5204. }
  5205. this.stack.push(value);
  5206. },
  5207. pop: function PostScriptStack_pop() {
  5208. if (this.stack.length <= 0) {
  5209. error('PostScript function stack underflow.');
  5210. }
  5211. return this.stack.pop();
  5212. },
  5213. copy: function PostScriptStack_copy(n) {
  5214. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5215. error('PostScript function stack overflow.');
  5216. }
  5217. var stack = this.stack;
  5218. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5219. stack.push(stack[i]);
  5220. }
  5221. },
  5222. index: function PostScriptStack_index(n) {
  5223. this.push(this.stack[this.stack.length - n - 1]);
  5224. },
  5225. // rotate the last n stack elements p times
  5226. roll: function PostScriptStack_roll(n, p) {
  5227. var stack = this.stack;
  5228. var l = stack.length - n;
  5229. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5230. for (i = l, j = r; i < j; i++, j--) {
  5231. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5232. }
  5233. for (i = l, j = c - 1; i < j; i++, j--) {
  5234. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5235. }
  5236. for (i = c, j = r; i < j; i++, j--) {
  5237. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5238. }
  5239. }
  5240. };
  5241. return PostScriptStack;
  5242. })();
  5243. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5244. function PostScriptEvaluator(operators) {
  5245. this.operators = operators;
  5246. }
  5247. PostScriptEvaluator.prototype = {
  5248. execute: function PostScriptEvaluator_execute(initialStack) {
  5249. var stack = new PostScriptStack(initialStack);
  5250. var counter = 0;
  5251. var operators = this.operators;
  5252. var length = operators.length;
  5253. var operator, a, b;
  5254. while (counter < length) {
  5255. operator = operators[counter++];
  5256. if (typeof operator === 'number') {
  5257. // Operator is really an operand and should be pushed to the stack.
  5258. stack.push(operator);
  5259. continue;
  5260. }
  5261. switch (operator) {
  5262. // non standard ps operators
  5263. case 'jz': // jump if false
  5264. b = stack.pop();
  5265. a = stack.pop();
  5266. if (!a) {
  5267. counter = b;
  5268. }
  5269. break;
  5270. case 'j': // jump
  5271. a = stack.pop();
  5272. counter = a;
  5273. break;
  5274. // all ps operators in alphabetical order (excluding if/ifelse)
  5275. case 'abs':
  5276. a = stack.pop();
  5277. stack.push(Math.abs(a));
  5278. break;
  5279. case 'add':
  5280. b = stack.pop();
  5281. a = stack.pop();
  5282. stack.push(a + b);
  5283. break;
  5284. case 'and':
  5285. b = stack.pop();
  5286. a = stack.pop();
  5287. if (isBool(a) && isBool(b)) {
  5288. stack.push(a && b);
  5289. } else {
  5290. stack.push(a & b);
  5291. }
  5292. break;
  5293. case 'atan':
  5294. a = stack.pop();
  5295. stack.push(Math.atan(a));
  5296. break;
  5297. case 'bitshift':
  5298. b = stack.pop();
  5299. a = stack.pop();
  5300. if (a > 0) {
  5301. stack.push(a << b);
  5302. } else {
  5303. stack.push(a >> b);
  5304. }
  5305. break;
  5306. case 'ceiling':
  5307. a = stack.pop();
  5308. stack.push(Math.ceil(a));
  5309. break;
  5310. case 'copy':
  5311. a = stack.pop();
  5312. stack.copy(a);
  5313. break;
  5314. case 'cos':
  5315. a = stack.pop();
  5316. stack.push(Math.cos(a));
  5317. break;
  5318. case 'cvi':
  5319. a = stack.pop() | 0;
  5320. stack.push(a);
  5321. break;
  5322. case 'cvr':
  5323. // noop
  5324. break;
  5325. case 'div':
  5326. b = stack.pop();
  5327. a = stack.pop();
  5328. stack.push(a / b);
  5329. break;
  5330. case 'dup':
  5331. stack.copy(1);
  5332. break;
  5333. case 'eq':
  5334. b = stack.pop();
  5335. a = stack.pop();
  5336. stack.push(a === b);
  5337. break;
  5338. case 'exch':
  5339. stack.roll(2, 1);
  5340. break;
  5341. case 'exp':
  5342. b = stack.pop();
  5343. a = stack.pop();
  5344. stack.push(Math.pow(a, b));
  5345. break;
  5346. case 'false':
  5347. stack.push(false);
  5348. break;
  5349. case 'floor':
  5350. a = stack.pop();
  5351. stack.push(Math.floor(a));
  5352. break;
  5353. case 'ge':
  5354. b = stack.pop();
  5355. a = stack.pop();
  5356. stack.push(a >= b);
  5357. break;
  5358. case 'gt':
  5359. b = stack.pop();
  5360. a = stack.pop();
  5361. stack.push(a > b);
  5362. break;
  5363. case 'idiv':
  5364. b = stack.pop();
  5365. a = stack.pop();
  5366. stack.push((a / b) | 0);
  5367. break;
  5368. case 'index':
  5369. a = stack.pop();
  5370. stack.index(a);
  5371. break;
  5372. case 'le':
  5373. b = stack.pop();
  5374. a = stack.pop();
  5375. stack.push(a <= b);
  5376. break;
  5377. case 'ln':
  5378. a = stack.pop();
  5379. stack.push(Math.log(a));
  5380. break;
  5381. case 'log':
  5382. a = stack.pop();
  5383. stack.push(Math.log(a) / Math.LN10);
  5384. break;
  5385. case 'lt':
  5386. b = stack.pop();
  5387. a = stack.pop();
  5388. stack.push(a < b);
  5389. break;
  5390. case 'mod':
  5391. b = stack.pop();
  5392. a = stack.pop();
  5393. stack.push(a % b);
  5394. break;
  5395. case 'mul':
  5396. b = stack.pop();
  5397. a = stack.pop();
  5398. stack.push(a * b);
  5399. break;
  5400. case 'ne':
  5401. b = stack.pop();
  5402. a = stack.pop();
  5403. stack.push(a !== b);
  5404. break;
  5405. case 'neg':
  5406. a = stack.pop();
  5407. stack.push(-a);
  5408. break;
  5409. case 'not':
  5410. a = stack.pop();
  5411. if (isBool(a)) {
  5412. stack.push(!a);
  5413. } else {
  5414. stack.push(~a);
  5415. }
  5416. break;
  5417. case 'or':
  5418. b = stack.pop();
  5419. a = stack.pop();
  5420. if (isBool(a) && isBool(b)) {
  5421. stack.push(a || b);
  5422. } else {
  5423. stack.push(a | b);
  5424. }
  5425. break;
  5426. case 'pop':
  5427. stack.pop();
  5428. break;
  5429. case 'roll':
  5430. b = stack.pop();
  5431. a = stack.pop();
  5432. stack.roll(a, b);
  5433. break;
  5434. case 'round':
  5435. a = stack.pop();
  5436. stack.push(Math.round(a));
  5437. break;
  5438. case 'sin':
  5439. a = stack.pop();
  5440. stack.push(Math.sin(a));
  5441. break;
  5442. case 'sqrt':
  5443. a = stack.pop();
  5444. stack.push(Math.sqrt(a));
  5445. break;
  5446. case 'sub':
  5447. b = stack.pop();
  5448. a = stack.pop();
  5449. stack.push(a - b);
  5450. break;
  5451. case 'true':
  5452. stack.push(true);
  5453. break;
  5454. case 'truncate':
  5455. a = stack.pop();
  5456. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5457. stack.push(a);
  5458. break;
  5459. case 'xor':
  5460. b = stack.pop();
  5461. a = stack.pop();
  5462. if (isBool(a) && isBool(b)) {
  5463. stack.push(a !== b);
  5464. } else {
  5465. stack.push(a ^ b);
  5466. }
  5467. break;
  5468. default:
  5469. error('Unknown operator ' + operator);
  5470. break;
  5471. }
  5472. }
  5473. return stack.stack;
  5474. }
  5475. };
  5476. return PostScriptEvaluator;
  5477. })();
  5478. // Most of the PDFs functions consist of simple operations such as:
  5479. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5480. //
  5481. // We can compile most of such programs, and at the same moment, we can
  5482. // optimize some expressions using basic math properties. Keeping track of
  5483. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5484. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5485. function AstNode(type) {
  5486. this.type = type;
  5487. }
  5488. AstNode.prototype.visit = function (visitor) {
  5489. throw new Error('abstract method');
  5490. };
  5491. function AstArgument(index, min, max) {
  5492. AstNode.call(this, 'args');
  5493. this.index = index;
  5494. this.min = min;
  5495. this.max = max;
  5496. }
  5497. AstArgument.prototype = Object.create(AstNode.prototype);
  5498. AstArgument.prototype.visit = function (visitor) {
  5499. visitor.visitArgument(this);
  5500. };
  5501. function AstLiteral(number) {
  5502. AstNode.call(this, 'literal');
  5503. this.number = number;
  5504. this.min = number;
  5505. this.max = number;
  5506. }
  5507. AstLiteral.prototype = Object.create(AstNode.prototype);
  5508. AstLiteral.prototype.visit = function (visitor) {
  5509. visitor.visitLiteral(this);
  5510. };
  5511. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5512. AstNode.call(this, 'binary');
  5513. this.op = op;
  5514. this.arg1 = arg1;
  5515. this.arg2 = arg2;
  5516. this.min = min;
  5517. this.max = max;
  5518. }
  5519. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5520. AstBinaryOperation.prototype.visit = function (visitor) {
  5521. visitor.visitBinaryOperation(this);
  5522. };
  5523. function AstMin(arg, max) {
  5524. AstNode.call(this, 'max');
  5525. this.arg = arg;
  5526. this.min = arg.min;
  5527. this.max = max;
  5528. }
  5529. AstMin.prototype = Object.create(AstNode.prototype);
  5530. AstMin.prototype.visit = function (visitor) {
  5531. visitor.visitMin(this);
  5532. };
  5533. function AstVariable(index, min, max) {
  5534. AstNode.call(this, 'var');
  5535. this.index = index;
  5536. this.min = min;
  5537. this.max = max;
  5538. }
  5539. AstVariable.prototype = Object.create(AstNode.prototype);
  5540. AstVariable.prototype.visit = function (visitor) {
  5541. visitor.visitVariable(this);
  5542. };
  5543. function AstVariableDefinition(variable, arg) {
  5544. AstNode.call(this, 'definition');
  5545. this.variable = variable;
  5546. this.arg = arg;
  5547. }
  5548. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5549. AstVariableDefinition.prototype.visit = function (visitor) {
  5550. visitor.visitVariableDefinition(this);
  5551. };
  5552. function ExpressionBuilderVisitor() {
  5553. this.parts = [];
  5554. }
  5555. ExpressionBuilderVisitor.prototype = {
  5556. visitArgument: function (arg) {
  5557. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5558. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5559. },
  5560. visitVariable: function (variable) {
  5561. this.parts.push('v', variable.index);
  5562. },
  5563. visitLiteral: function (literal) {
  5564. this.parts.push(literal.number);
  5565. },
  5566. visitBinaryOperation: function (operation) {
  5567. this.parts.push('(');
  5568. operation.arg1.visit(this);
  5569. this.parts.push(' ', operation.op, ' ');
  5570. operation.arg2.visit(this);
  5571. this.parts.push(')');
  5572. },
  5573. visitVariableDefinition: function (definition) {
  5574. this.parts.push('var ');
  5575. definition.variable.visit(this);
  5576. this.parts.push(' = ');
  5577. definition.arg.visit(this);
  5578. this.parts.push(';');
  5579. },
  5580. visitMin: function (max) {
  5581. this.parts.push('Math.min(');
  5582. max.arg.visit(this);
  5583. this.parts.push(', ', max.max, ')');
  5584. },
  5585. toString: function () {
  5586. return this.parts.join('');
  5587. }
  5588. };
  5589. function buildAddOperation(num1, num2) {
  5590. if (num2.type === 'literal' && num2.number === 0) {
  5591. // optimization: second operand is 0
  5592. return num1;
  5593. }
  5594. if (num1.type === 'literal' && num1.number === 0) {
  5595. // optimization: first operand is 0
  5596. return num2;
  5597. }
  5598. if (num2.type === 'literal' && num1.type === 'literal') {
  5599. // optimization: operands operand are literals
  5600. return new AstLiteral(num1.number + num2.number);
  5601. }
  5602. return new AstBinaryOperation('+', num1, num2,
  5603. num1.min + num2.min, num1.max + num2.max);
  5604. }
  5605. function buildMulOperation(num1, num2) {
  5606. if (num2.type === 'literal') {
  5607. // optimization: second operands is a literal...
  5608. if (num2.number === 0) {
  5609. return new AstLiteral(0); // and it's 0
  5610. } else if (num2.number === 1) {
  5611. return num1; // and it's 1
  5612. } else if (num1.type === 'literal') {
  5613. // ... and first operands is a literal too
  5614. return new AstLiteral(num1.number * num2.number);
  5615. }
  5616. }
  5617. if (num1.type === 'literal') {
  5618. // optimization: first operands is a literal...
  5619. if (num1.number === 0) {
  5620. return new AstLiteral(0); // and it's 0
  5621. } else if (num1.number === 1) {
  5622. return num2; // and it's 1
  5623. }
  5624. }
  5625. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5626. num1.max * num2.min, num1.max * num2.max);
  5627. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5628. num1.max * num2.min, num1.max * num2.max);
  5629. return new AstBinaryOperation('*', num1, num2, min, max);
  5630. }
  5631. function buildSubOperation(num1, num2) {
  5632. if (num2.type === 'literal') {
  5633. // optimization: second operands is a literal...
  5634. if (num2.number === 0) {
  5635. return num1; // ... and it's 0
  5636. } else if (num1.type === 'literal') {
  5637. // ... and first operands is a literal too
  5638. return new AstLiteral(num1.number - num2.number);
  5639. }
  5640. }
  5641. if (num2.type === 'binary' && num2.op === '-' &&
  5642. num1.type === 'literal' && num1.number === 1 &&
  5643. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5644. // optimization for case: 1 - (1 - x)
  5645. return num2.arg2;
  5646. }
  5647. return new AstBinaryOperation('-', num1, num2,
  5648. num1.min - num2.max, num1.max - num2.min);
  5649. }
  5650. function buildMinOperation(num1, max) {
  5651. if (num1.min >= max) {
  5652. // optimization: num1 min value is not less than required max
  5653. return new AstLiteral(max); // just returning max
  5654. } else if (num1.max <= max) {
  5655. // optimization: num1 max value is not greater than required max
  5656. return num1; // just returning an argument
  5657. }
  5658. return new AstMin(num1, max);
  5659. }
  5660. function PostScriptCompiler() {}
  5661. PostScriptCompiler.prototype = {
  5662. compile: function PostScriptCompiler_compile(code, domain, range) {
  5663. var stack = [];
  5664. var i, ii;
  5665. var instructions = [];
  5666. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5667. var lastRegister = 0;
  5668. var n, j, min, max;
  5669. var num1, num2, ast1, ast2, tmpVar, item;
  5670. for (i = 0; i < inputSize; i++) {
  5671. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5672. }
  5673. for (i = 0, ii = code.length; i < ii; i++) {
  5674. item = code[i];
  5675. if (typeof item === 'number') {
  5676. stack.push(new AstLiteral(item));
  5677. continue;
  5678. }
  5679. switch (item) {
  5680. case 'add':
  5681. if (stack.length < 2) {
  5682. return null;
  5683. }
  5684. num2 = stack.pop();
  5685. num1 = stack.pop();
  5686. stack.push(buildAddOperation(num1, num2));
  5687. break;
  5688. case 'cvr':
  5689. if (stack.length < 1) {
  5690. return null;
  5691. }
  5692. break;
  5693. case 'mul':
  5694. if (stack.length < 2) {
  5695. return null;
  5696. }
  5697. num2 = stack.pop();
  5698. num1 = stack.pop();
  5699. stack.push(buildMulOperation(num1, num2));
  5700. break;
  5701. case 'sub':
  5702. if (stack.length < 2) {
  5703. return null;
  5704. }
  5705. num2 = stack.pop();
  5706. num1 = stack.pop();
  5707. stack.push(buildSubOperation(num1, num2));
  5708. break;
  5709. case 'exch':
  5710. if (stack.length < 2) {
  5711. return null;
  5712. }
  5713. ast1 = stack.pop(); ast2 = stack.pop();
  5714. stack.push(ast1, ast2);
  5715. break;
  5716. case 'pop':
  5717. if (stack.length < 1) {
  5718. return null;
  5719. }
  5720. stack.pop();
  5721. break;
  5722. case 'index':
  5723. if (stack.length < 1) {
  5724. return null;
  5725. }
  5726. num1 = stack.pop();
  5727. if (num1.type !== 'literal') {
  5728. return null;
  5729. }
  5730. n = num1.number;
  5731. if (n < 0 || (n|0) !== n || stack.length < n) {
  5732. return null;
  5733. }
  5734. ast1 = stack[stack.length - n - 1];
  5735. if (ast1.type === 'literal' || ast1.type === 'var') {
  5736. stack.push(ast1);
  5737. break;
  5738. }
  5739. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5740. stack[stack.length - n - 1] = tmpVar;
  5741. stack.push(tmpVar);
  5742. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5743. break;
  5744. case 'dup':
  5745. if (stack.length < 1) {
  5746. return null;
  5747. }
  5748. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5749. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5750. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5751. // special case of the commands sequence for the min operation
  5752. num1 = stack.pop();
  5753. stack.push(buildMinOperation(num1, code[i + 1]));
  5754. i += 6;
  5755. break;
  5756. }
  5757. ast1 = stack[stack.length - 1];
  5758. if (ast1.type === 'literal' || ast1.type === 'var') {
  5759. // we don't have to save into intermediate variable a literal or
  5760. // variable.
  5761. stack.push(ast1);
  5762. break;
  5763. }
  5764. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5765. stack[stack.length - 1] = tmpVar;
  5766. stack.push(tmpVar);
  5767. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5768. break;
  5769. case 'roll':
  5770. if (stack.length < 2) {
  5771. return null;
  5772. }
  5773. num2 = stack.pop();
  5774. num1 = stack.pop();
  5775. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5776. // both roll operands must be numbers
  5777. return null;
  5778. }
  5779. j = num2.number;
  5780. n = num1.number;
  5781. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5782. // ... and integers
  5783. return null;
  5784. }
  5785. j = ((j % n) + n) % n;
  5786. if (j === 0) {
  5787. break; // just skipping -- there are nothing to rotate
  5788. }
  5789. Array.prototype.push.apply(stack,
  5790. stack.splice(stack.length - n, n - j));
  5791. break;
  5792. default:
  5793. return null; // unsupported operator
  5794. }
  5795. }
  5796. if (stack.length !== outputSize) {
  5797. return null;
  5798. }
  5799. var result = [];
  5800. instructions.forEach(function (instruction) {
  5801. var statementBuilder = new ExpressionBuilderVisitor();
  5802. instruction.visit(statementBuilder);
  5803. result.push(statementBuilder.toString());
  5804. });
  5805. stack.forEach(function (expr, i) {
  5806. var statementBuilder = new ExpressionBuilderVisitor();
  5807. expr.visit(statementBuilder);
  5808. var min = range[i * 2], max = range[i * 2 + 1];
  5809. var out = [statementBuilder.toString()];
  5810. if (min > expr.min) {
  5811. out.unshift('Math.max(', min, ', ');
  5812. out.push(')');
  5813. }
  5814. if (max < expr.max) {
  5815. out.unshift('Math.min(', max, ', ');
  5816. out.push(')');
  5817. }
  5818. out.unshift('dest[destOffset + ', i, '] = ');
  5819. out.push(';');
  5820. result.push(out.join(''));
  5821. });
  5822. return result.join('\n');
  5823. }
  5824. };
  5825. return PostScriptCompiler;
  5826. })();
  5827. var ColorSpace = (function ColorSpaceClosure() {
  5828. // Constructor should define this.numComps, this.defaultColor, this.name
  5829. function ColorSpace() {
  5830. error('should not call ColorSpace constructor');
  5831. }
  5832. ColorSpace.prototype = {
  5833. /**
  5834. * Converts the color value to the RGB color. The color components are
  5835. * located in the src array starting from the srcOffset. Returns the array
  5836. * of the rgb components, each value ranging from [0,255].
  5837. */
  5838. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5839. var rgb = new Uint8Array(3);
  5840. this.getRgbItem(src, srcOffset, rgb, 0);
  5841. return rgb;
  5842. },
  5843. /**
  5844. * Converts the color value to the RGB color, similar to the getRgb method.
  5845. * The result placed into the dest array starting from the destOffset.
  5846. */
  5847. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5848. dest, destOffset) {
  5849. error('Should not call ColorSpace.getRgbItem');
  5850. },
  5851. /**
  5852. * Converts the specified number of the color values to the RGB colors.
  5853. * The colors are located in the src array starting from the srcOffset.
  5854. * The result is placed into the dest array starting from the destOffset.
  5855. * The src array items shall be in [0,2^bits) range, the dest array items
  5856. * will be in [0,255] range. alpha01 indicates how many alpha components
  5857. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5858. * array).
  5859. */
  5860. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5861. dest, destOffset, bits,
  5862. alpha01) {
  5863. error('Should not call ColorSpace.getRgbBuffer');
  5864. },
  5865. /**
  5866. * Determines the number of bytes required to store the result of the
  5867. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5868. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5869. */
  5870. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5871. alpha01) {
  5872. error('Should not call ColorSpace.getOutputLength');
  5873. },
  5874. /**
  5875. * Returns true if source data will be equal the result/output data.
  5876. */
  5877. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5878. return false;
  5879. },
  5880. /**
  5881. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5882. * how many alpha components there are in the dest array; it will be either
  5883. * 0 (RGB array) or 1 (RGBA array).
  5884. */
  5885. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5886. originalHeight, width, height,
  5887. actualHeight, bpc, comps, alpha01) {
  5888. var count = originalWidth * originalHeight;
  5889. var rgbBuf = null;
  5890. var numComponentColors = 1 << bpc;
  5891. var needsResizing = originalHeight !== height || originalWidth !== width;
  5892. var i, ii;
  5893. if (this.isPassthrough(bpc)) {
  5894. rgbBuf = comps;
  5895. } else if (this.numComps === 1 && count > numComponentColors &&
  5896. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5897. // Optimization: create a color map when there is just one component and
  5898. // we are converting more colors than the size of the color map. We
  5899. // don't build the map if the colorspace is gray or rgb since those
  5900. // methods are faster than building a map. This mainly offers big speed
  5901. // ups for indexed and alternate colorspaces.
  5902. //
  5903. // TODO it may be worth while to cache the color map. While running
  5904. // testing I never hit a cache so I will leave that out for now (perhaps
  5905. // we are reparsing colorspaces too much?).
  5906. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5907. new Uint16Array(numComponentColors);
  5908. var key;
  5909. for (i = 0; i < numComponentColors; i++) {
  5910. allColors[i] = i;
  5911. }
  5912. var colorMap = new Uint8Array(numComponentColors * 3);
  5913. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5914. /* alpha01 = */ 0);
  5915. var destPos, rgbPos;
  5916. if (!needsResizing) {
  5917. // Fill in the RGB values directly into |dest|.
  5918. destPos = 0;
  5919. for (i = 0; i < count; ++i) {
  5920. key = comps[i] * 3;
  5921. dest[destPos++] = colorMap[key];
  5922. dest[destPos++] = colorMap[key + 1];
  5923. dest[destPos++] = colorMap[key + 2];
  5924. destPos += alpha01;
  5925. }
  5926. } else {
  5927. rgbBuf = new Uint8Array(count * 3);
  5928. rgbPos = 0;
  5929. for (i = 0; i < count; ++i) {
  5930. key = comps[i] * 3;
  5931. rgbBuf[rgbPos++] = colorMap[key];
  5932. rgbBuf[rgbPos++] = colorMap[key + 1];
  5933. rgbBuf[rgbPos++] = colorMap[key + 2];
  5934. }
  5935. }
  5936. } else {
  5937. if (!needsResizing) {
  5938. // Fill in the RGB values directly into |dest|.
  5939. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5940. alpha01);
  5941. } else {
  5942. rgbBuf = new Uint8Array(count * 3);
  5943. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5944. /* alpha01 = */ 0);
  5945. }
  5946. }
  5947. if (rgbBuf) {
  5948. if (needsResizing) {
  5949. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5950. height, dest, alpha01);
  5951. } else {
  5952. rgbPos = 0;
  5953. destPos = 0;
  5954. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5955. dest[destPos++] = rgbBuf[rgbPos++];
  5956. dest[destPos++] = rgbBuf[rgbPos++];
  5957. dest[destPos++] = rgbBuf[rgbPos++];
  5958. destPos += alpha01;
  5959. }
  5960. }
  5961. }
  5962. },
  5963. /**
  5964. * True if the colorspace has components in the default range of [0, 1].
  5965. * This should be true for all colorspaces except for lab color spaces
  5966. * which are [0,100], [-128, 127], [-128, 127].
  5967. */
  5968. usesZeroToOneRange: true
  5969. };
  5970. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5971. var IR = ColorSpace.parseToIR(cs, xref, res);
  5972. if (IR instanceof AlternateCS) {
  5973. return IR;
  5974. }
  5975. return ColorSpace.fromIR(IR);
  5976. };
  5977. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5978. var name = isArray(IR) ? IR[0] : IR;
  5979. var whitePoint, blackPoint, gamma;
  5980. switch (name) {
  5981. case 'DeviceGrayCS':
  5982. return this.singletons.gray;
  5983. case 'DeviceRgbCS':
  5984. return this.singletons.rgb;
  5985. case 'DeviceCmykCS':
  5986. return this.singletons.cmyk;
  5987. case 'CalGrayCS':
  5988. whitePoint = IR[1].WhitePoint;
  5989. blackPoint = IR[1].BlackPoint;
  5990. gamma = IR[1].Gamma;
  5991. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5992. case 'CalRGBCS':
  5993. whitePoint = IR[1].WhitePoint;
  5994. blackPoint = IR[1].BlackPoint;
  5995. gamma = IR[1].Gamma;
  5996. var matrix = IR[1].Matrix;
  5997. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  5998. case 'PatternCS':
  5999. var basePatternCS = IR[1];
  6000. if (basePatternCS) {
  6001. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6002. }
  6003. return new PatternCS(basePatternCS);
  6004. case 'IndexedCS':
  6005. var baseIndexedCS = IR[1];
  6006. var hiVal = IR[2];
  6007. var lookup = IR[3];
  6008. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6009. case 'AlternateCS':
  6010. var numComps = IR[1];
  6011. var alt = IR[2];
  6012. var tintFnIR = IR[3];
  6013. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6014. PDFFunction.fromIR(tintFnIR));
  6015. case 'LabCS':
  6016. whitePoint = IR[1].WhitePoint;
  6017. blackPoint = IR[1].BlackPoint;
  6018. var range = IR[1].Range;
  6019. return new LabCS(whitePoint, blackPoint, range);
  6020. default:
  6021. error('Unknown name ' + name);
  6022. }
  6023. return null;
  6024. };
  6025. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6026. if (isName(cs)) {
  6027. var colorSpaces = res.get('ColorSpace');
  6028. if (isDict(colorSpaces)) {
  6029. var refcs = colorSpaces.get(cs.name);
  6030. if (refcs) {
  6031. cs = refcs;
  6032. }
  6033. }
  6034. }
  6035. cs = xref.fetchIfRef(cs);
  6036. var mode;
  6037. if (isName(cs)) {
  6038. mode = cs.name;
  6039. this.mode = mode;
  6040. switch (mode) {
  6041. case 'DeviceGray':
  6042. case 'G':
  6043. return 'DeviceGrayCS';
  6044. case 'DeviceRGB':
  6045. case 'RGB':
  6046. return 'DeviceRgbCS';
  6047. case 'DeviceCMYK':
  6048. case 'CMYK':
  6049. return 'DeviceCmykCS';
  6050. case 'Pattern':
  6051. return ['PatternCS', null];
  6052. default:
  6053. error('unrecognized colorspace ' + mode);
  6054. }
  6055. } else if (isArray(cs)) {
  6056. mode = cs[0].name;
  6057. this.mode = mode;
  6058. var numComps, params;
  6059. switch (mode) {
  6060. case 'DeviceGray':
  6061. case 'G':
  6062. return 'DeviceGrayCS';
  6063. case 'DeviceRGB':
  6064. case 'RGB':
  6065. return 'DeviceRgbCS';
  6066. case 'DeviceCMYK':
  6067. case 'CMYK':
  6068. return 'DeviceCmykCS';
  6069. case 'CalGray':
  6070. params = cs[1].getAll();
  6071. return ['CalGrayCS', params];
  6072. case 'CalRGB':
  6073. params = cs[1].getAll();
  6074. return ['CalRGBCS', params];
  6075. case 'ICCBased':
  6076. var stream = xref.fetchIfRef(cs[1]);
  6077. var dict = stream.dict;
  6078. numComps = dict.get('N');
  6079. if (numComps === 1) {
  6080. return 'DeviceGrayCS';
  6081. } else if (numComps === 3) {
  6082. return 'DeviceRgbCS';
  6083. } else if (numComps === 4) {
  6084. return 'DeviceCmykCS';
  6085. }
  6086. break;
  6087. case 'Pattern':
  6088. var basePatternCS = cs[1];
  6089. if (basePatternCS) {
  6090. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6091. }
  6092. return ['PatternCS', basePatternCS];
  6093. case 'Indexed':
  6094. case 'I':
  6095. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6096. var hiVal = cs[2] + 1;
  6097. var lookup = xref.fetchIfRef(cs[3]);
  6098. if (isStream(lookup)) {
  6099. lookup = lookup.getBytes();
  6100. }
  6101. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6102. case 'Separation':
  6103. case 'DeviceN':
  6104. var name = cs[1];
  6105. numComps = 1;
  6106. if (isName(name)) {
  6107. numComps = 1;
  6108. } else if (isArray(name)) {
  6109. numComps = name.length;
  6110. }
  6111. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  6112. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6113. return ['AlternateCS', numComps, alt, tintFnIR];
  6114. case 'Lab':
  6115. params = cs[1].getAll();
  6116. return ['LabCS', params];
  6117. default:
  6118. error('unimplemented color space object "' + mode + '"');
  6119. }
  6120. } else {
  6121. error('unrecognized color space object: "' + cs + '"');
  6122. }
  6123. return null;
  6124. };
  6125. /**
  6126. * Checks if a decode map matches the default decode map for a color space.
  6127. * This handles the general decode maps where there are two values per
  6128. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6129. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6130. * slightly different.
  6131. * @param {Array} decode Decode map (usually from an image).
  6132. * @param {Number} n Number of components the color space has.
  6133. */
  6134. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6135. if (!decode) {
  6136. return true;
  6137. }
  6138. if (n * 2 !== decode.length) {
  6139. warn('The decode map is not the correct length');
  6140. return true;
  6141. }
  6142. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6143. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6144. return false;
  6145. }
  6146. }
  6147. return true;
  6148. };
  6149. ColorSpace.singletons = {
  6150. get gray() {
  6151. return shadow(this, 'gray', new DeviceGrayCS());
  6152. },
  6153. get rgb() {
  6154. return shadow(this, 'rgb', new DeviceRgbCS());
  6155. },
  6156. get cmyk() {
  6157. return shadow(this, 'cmyk', new DeviceCmykCS());
  6158. }
  6159. };
  6160. return ColorSpace;
  6161. })();
  6162. /**
  6163. * Alternate color space handles both Separation and DeviceN color spaces. A
  6164. * Separation color space is actually just a DeviceN with one color component.
  6165. * Both color spaces use a tinting function to convert colors to a base color
  6166. * space.
  6167. */
  6168. var AlternateCS = (function AlternateCSClosure() {
  6169. function AlternateCS(numComps, base, tintFn) {
  6170. this.name = 'Alternate';
  6171. this.numComps = numComps;
  6172. this.defaultColor = new Float32Array(numComps);
  6173. for (var i = 0; i < numComps; ++i) {
  6174. this.defaultColor[i] = 1;
  6175. }
  6176. this.base = base;
  6177. this.tintFn = tintFn;
  6178. this.tmpBuf = new Float32Array(base.numComps);
  6179. }
  6180. AlternateCS.prototype = {
  6181. getRgb: ColorSpace.prototype.getRgb,
  6182. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6183. dest, destOffset) {
  6184. var tmpBuf = this.tmpBuf;
  6185. this.tintFn(src, srcOffset, tmpBuf, 0);
  6186. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6187. },
  6188. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6189. dest, destOffset, bits,
  6190. alpha01) {
  6191. var tintFn = this.tintFn;
  6192. var base = this.base;
  6193. var scale = 1 / ((1 << bits) - 1);
  6194. var baseNumComps = base.numComps;
  6195. var usesZeroToOneRange = base.usesZeroToOneRange;
  6196. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6197. alpha01 === 0;
  6198. var pos = isPassthrough ? destOffset : 0;
  6199. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6200. var numComps = this.numComps;
  6201. var scaled = new Float32Array(numComps);
  6202. var tinted = new Float32Array(baseNumComps);
  6203. var i, j;
  6204. if (usesZeroToOneRange) {
  6205. for (i = 0; i < count; i++) {
  6206. for (j = 0; j < numComps; j++) {
  6207. scaled[j] = src[srcOffset++] * scale;
  6208. }
  6209. tintFn(scaled, 0, tinted, 0);
  6210. for (j = 0; j < baseNumComps; j++) {
  6211. baseBuf[pos++] = tinted[j] * 255;
  6212. }
  6213. }
  6214. } else {
  6215. for (i = 0; i < count; i++) {
  6216. for (j = 0; j < numComps; j++) {
  6217. scaled[j] = src[srcOffset++] * scale;
  6218. }
  6219. tintFn(scaled, 0, tinted, 0);
  6220. base.getRgbItem(tinted, 0, baseBuf, pos);
  6221. pos += baseNumComps;
  6222. }
  6223. }
  6224. if (!isPassthrough) {
  6225. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6226. }
  6227. },
  6228. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6229. alpha01) {
  6230. return this.base.getOutputLength(inputLength *
  6231. this.base.numComps / this.numComps,
  6232. alpha01);
  6233. },
  6234. isPassthrough: ColorSpace.prototype.isPassthrough,
  6235. fillRgb: ColorSpace.prototype.fillRgb,
  6236. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6237. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6238. },
  6239. usesZeroToOneRange: true
  6240. };
  6241. return AlternateCS;
  6242. })();
  6243. var PatternCS = (function PatternCSClosure() {
  6244. function PatternCS(baseCS) {
  6245. this.name = 'Pattern';
  6246. this.base = baseCS;
  6247. }
  6248. PatternCS.prototype = {};
  6249. return PatternCS;
  6250. })();
  6251. var IndexedCS = (function IndexedCSClosure() {
  6252. function IndexedCS(base, highVal, lookup) {
  6253. this.name = 'Indexed';
  6254. this.numComps = 1;
  6255. this.defaultColor = new Uint8Array([0]);
  6256. this.base = base;
  6257. this.highVal = highVal;
  6258. var baseNumComps = base.numComps;
  6259. var length = baseNumComps * highVal;
  6260. var lookupArray;
  6261. if (isStream(lookup)) {
  6262. lookupArray = new Uint8Array(length);
  6263. var bytes = lookup.getBytes(length);
  6264. lookupArray.set(bytes);
  6265. } else if (isString(lookup)) {
  6266. lookupArray = new Uint8Array(length);
  6267. for (var i = 0; i < length; ++i) {
  6268. lookupArray[i] = lookup.charCodeAt(i);
  6269. }
  6270. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6271. lookupArray = lookup;
  6272. } else {
  6273. error('Unrecognized lookup table: ' + lookup);
  6274. }
  6275. this.lookup = lookupArray;
  6276. }
  6277. IndexedCS.prototype = {
  6278. getRgb: ColorSpace.prototype.getRgb,
  6279. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6280. dest, destOffset) {
  6281. var numComps = this.base.numComps;
  6282. var start = src[srcOffset] * numComps;
  6283. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6284. },
  6285. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6286. dest, destOffset, bits,
  6287. alpha01) {
  6288. var base = this.base;
  6289. var numComps = base.numComps;
  6290. var outputDelta = base.getOutputLength(numComps, alpha01);
  6291. var lookup = this.lookup;
  6292. for (var i = 0; i < count; ++i) {
  6293. var lookupPos = src[srcOffset++] * numComps;
  6294. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6295. destOffset += outputDelta;
  6296. }
  6297. },
  6298. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6299. return this.base.getOutputLength(inputLength * this.base.numComps,
  6300. alpha01);
  6301. },
  6302. isPassthrough: ColorSpace.prototype.isPassthrough,
  6303. fillRgb: ColorSpace.prototype.fillRgb,
  6304. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6305. // indexed color maps shouldn't be changed
  6306. return true;
  6307. },
  6308. usesZeroToOneRange: true
  6309. };
  6310. return IndexedCS;
  6311. })();
  6312. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6313. function DeviceGrayCS() {
  6314. this.name = 'DeviceGray';
  6315. this.numComps = 1;
  6316. this.defaultColor = new Float32Array([0]);
  6317. }
  6318. DeviceGrayCS.prototype = {
  6319. getRgb: ColorSpace.prototype.getRgb,
  6320. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6321. dest, destOffset) {
  6322. var c = (src[srcOffset] * 255) | 0;
  6323. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6324. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6325. },
  6326. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6327. dest, destOffset, bits,
  6328. alpha01) {
  6329. var scale = 255 / ((1 << bits) - 1);
  6330. var j = srcOffset, q = destOffset;
  6331. for (var i = 0; i < count; ++i) {
  6332. var c = (scale * src[j++]) | 0;
  6333. dest[q++] = c;
  6334. dest[q++] = c;
  6335. dest[q++] = c;
  6336. q += alpha01;
  6337. }
  6338. },
  6339. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6340. alpha01) {
  6341. return inputLength * (3 + alpha01);
  6342. },
  6343. isPassthrough: ColorSpace.prototype.isPassthrough,
  6344. fillRgb: ColorSpace.prototype.fillRgb,
  6345. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6346. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6347. },
  6348. usesZeroToOneRange: true
  6349. };
  6350. return DeviceGrayCS;
  6351. })();
  6352. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6353. function DeviceRgbCS() {
  6354. this.name = 'DeviceRGB';
  6355. this.numComps = 3;
  6356. this.defaultColor = new Float32Array([0, 0, 0]);
  6357. }
  6358. DeviceRgbCS.prototype = {
  6359. getRgb: ColorSpace.prototype.getRgb,
  6360. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6361. dest, destOffset) {
  6362. var r = (src[srcOffset] * 255) | 0;
  6363. var g = (src[srcOffset + 1] * 255) | 0;
  6364. var b = (src[srcOffset + 2] * 255) | 0;
  6365. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6366. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6367. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6368. },
  6369. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6370. dest, destOffset, bits,
  6371. alpha01) {
  6372. if (bits === 8 && alpha01 === 0) {
  6373. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6374. return;
  6375. }
  6376. var scale = 255 / ((1 << bits) - 1);
  6377. var j = srcOffset, q = destOffset;
  6378. for (var i = 0; i < count; ++i) {
  6379. dest[q++] = (scale * src[j++]) | 0;
  6380. dest[q++] = (scale * src[j++]) | 0;
  6381. dest[q++] = (scale * src[j++]) | 0;
  6382. q += alpha01;
  6383. }
  6384. },
  6385. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6386. alpha01) {
  6387. return (inputLength * (3 + alpha01) / 3) | 0;
  6388. },
  6389. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6390. return bits === 8;
  6391. },
  6392. fillRgb: ColorSpace.prototype.fillRgb,
  6393. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6394. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6395. },
  6396. usesZeroToOneRange: true
  6397. };
  6398. return DeviceRgbCS;
  6399. })();
  6400. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6401. // The coefficients below was found using numerical analysis: the method of
  6402. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6403. // where color_value is the tabular value from the table of sampled RGB colors
  6404. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6405. // CMYK color conversion using the estimation below:
  6406. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6407. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6408. var c = src[srcOffset + 0] * srcScale;
  6409. var m = src[srcOffset + 1] * srcScale;
  6410. var y = src[srcOffset + 2] * srcScale;
  6411. var k = src[srcOffset + 3] * srcScale;
  6412. var r =
  6413. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6414. 18.82290502165302 * y + 212.25662451639585 * k +
  6415. -285.2331026137004) +
  6416. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6417. -17.873870861415444 * k - 5.497006427196366) +
  6418. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6419. 17.5119270841813) +
  6420. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6421. var g =
  6422. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6423. 6.871425592049007 * y + 31.159100130055922 * k +
  6424. -79.2970844816548) +
  6425. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6426. 131.35250912493976 * k - 190.9453302588951) +
  6427. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6428. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6429. var b =
  6430. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6431. 30.89978309703729 * y - 0.23883238689178934 * k +
  6432. -14.183576799673286) +
  6433. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6434. 50.606957656360734 * k - 112.23884253719248) +
  6435. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6436. -193.58209356861505) +
  6437. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6438. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6439. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6440. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6441. }
  6442. function DeviceCmykCS() {
  6443. this.name = 'DeviceCMYK';
  6444. this.numComps = 4;
  6445. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6446. }
  6447. DeviceCmykCS.prototype = {
  6448. getRgb: ColorSpace.prototype.getRgb,
  6449. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6450. dest, destOffset) {
  6451. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6452. },
  6453. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6454. dest, destOffset, bits,
  6455. alpha01) {
  6456. var scale = 1 / ((1 << bits) - 1);
  6457. for (var i = 0; i < count; i++) {
  6458. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6459. srcOffset += 4;
  6460. destOffset += 3 + alpha01;
  6461. }
  6462. },
  6463. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6464. alpha01) {
  6465. return (inputLength / 4 * (3 + alpha01)) | 0;
  6466. },
  6467. isPassthrough: ColorSpace.prototype.isPassthrough,
  6468. fillRgb: ColorSpace.prototype.fillRgb,
  6469. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6470. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6471. },
  6472. usesZeroToOneRange: true
  6473. };
  6474. return DeviceCmykCS;
  6475. })();
  6476. //
  6477. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6478. //
  6479. var CalGrayCS = (function CalGrayCSClosure() {
  6480. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6481. this.name = 'CalGray';
  6482. this.numComps = 1;
  6483. this.defaultColor = new Float32Array([0]);
  6484. if (!whitePoint) {
  6485. error('WhitePoint missing - required for color space CalGray');
  6486. }
  6487. blackPoint = blackPoint || [0, 0, 0];
  6488. gamma = gamma || 1;
  6489. // Translate arguments to spec variables.
  6490. this.XW = whitePoint[0];
  6491. this.YW = whitePoint[1];
  6492. this.ZW = whitePoint[2];
  6493. this.XB = blackPoint[0];
  6494. this.YB = blackPoint[1];
  6495. this.ZB = blackPoint[2];
  6496. this.G = gamma;
  6497. // Validate variables as per spec.
  6498. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6499. error('Invalid WhitePoint components for ' + this.name +
  6500. ', no fallback available');
  6501. }
  6502. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6503. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6504. this.XB = this.YB = this.ZB = 0;
  6505. }
  6506. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6507. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6508. ', ZB: ' + this.ZB + ', only default values are supported.');
  6509. }
  6510. if (this.G < 1) {
  6511. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6512. ', falling back to default');
  6513. this.G = 1;
  6514. }
  6515. }
  6516. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6517. // A represents a gray component of a calibrated gray space.
  6518. // A <---> AG in the spec
  6519. var A = src[srcOffset] * scale;
  6520. var AG = Math.pow(A, cs.G);
  6521. // Computes L as per spec. ( = cs.YW * AG )
  6522. // Except if other than default BlackPoint values are used.
  6523. var L = cs.YW * AG;
  6524. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6525. // Convert values to rgb range [0, 255].
  6526. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6527. dest[destOffset] = val;
  6528. dest[destOffset + 1] = val;
  6529. dest[destOffset + 2] = val;
  6530. }
  6531. CalGrayCS.prototype = {
  6532. getRgb: ColorSpace.prototype.getRgb,
  6533. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6534. dest, destOffset) {
  6535. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6536. },
  6537. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6538. dest, destOffset, bits,
  6539. alpha01) {
  6540. var scale = 1 / ((1 << bits) - 1);
  6541. for (var i = 0; i < count; ++i) {
  6542. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6543. srcOffset += 1;
  6544. destOffset += 3 + alpha01;
  6545. }
  6546. },
  6547. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6548. return inputLength * (3 + alpha01);
  6549. },
  6550. isPassthrough: ColorSpace.prototype.isPassthrough,
  6551. fillRgb: ColorSpace.prototype.fillRgb,
  6552. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6553. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6554. },
  6555. usesZeroToOneRange: true
  6556. };
  6557. return CalGrayCS;
  6558. })();
  6559. //
  6560. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6561. //
  6562. var CalRGBCS = (function CalRGBCSClosure() {
  6563. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6564. // matrices.
  6565. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6566. 0.8951, 0.2664, -0.1614,
  6567. -0.7502, 1.7135, 0.0367,
  6568. 0.0389, -0.0685, 1.0296]);
  6569. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6570. 0.9869929, -0.1470543, 0.1599627,
  6571. 0.4323053, 0.5183603, 0.0492912,
  6572. -0.0085287, 0.0400428, 0.9684867]);
  6573. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6574. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6575. 3.2404542, -1.5371385, -0.4985314,
  6576. -0.9692660, 1.8760108, 0.0415560,
  6577. 0.0556434, -0.2040259, 1.0572252]);
  6578. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6579. var tempNormalizeMatrix = new Float32Array(3);
  6580. var tempConvertMatrix1 = new Float32Array(3);
  6581. var tempConvertMatrix2 = new Float32Array(3);
  6582. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6583. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6584. this.name = 'CalRGB';
  6585. this.numComps = 3;
  6586. this.defaultColor = new Float32Array(3);
  6587. if (!whitePoint) {
  6588. error('WhitePoint missing - required for color space CalRGB');
  6589. }
  6590. blackPoint = blackPoint || new Float32Array(3);
  6591. gamma = gamma || new Float32Array([1, 1, 1]);
  6592. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6593. // Translate arguments to spec variables.
  6594. var XW = whitePoint[0];
  6595. var YW = whitePoint[1];
  6596. var ZW = whitePoint[2];
  6597. this.whitePoint = whitePoint;
  6598. var XB = blackPoint[0];
  6599. var YB = blackPoint[1];
  6600. var ZB = blackPoint[2];
  6601. this.blackPoint = blackPoint;
  6602. this.GR = gamma[0];
  6603. this.GG = gamma[1];
  6604. this.GB = gamma[2];
  6605. this.MXA = matrix[0];
  6606. this.MYA = matrix[1];
  6607. this.MZA = matrix[2];
  6608. this.MXB = matrix[3];
  6609. this.MYB = matrix[4];
  6610. this.MZB = matrix[5];
  6611. this.MXC = matrix[6];
  6612. this.MYC = matrix[7];
  6613. this.MZC = matrix[8];
  6614. // Validate variables as per spec.
  6615. if (XW < 0 || ZW < 0 || YW !== 1) {
  6616. error('Invalid WhitePoint components for ' + this.name +
  6617. ', no fallback available');
  6618. }
  6619. if (XB < 0 || YB < 0 || ZB < 0) {
  6620. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6621. ', ' + ZB + '], falling back to default');
  6622. this.blackPoint = new Float32Array(3);
  6623. }
  6624. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6625. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6626. '] for ' + this.name + ', falling back to default');
  6627. this.GR = this.GG = this.GB = 1;
  6628. }
  6629. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6630. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6631. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6632. info('Invalid Matrix for ' + this.name + ' [' +
  6633. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6634. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6635. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6636. '], falling back to default');
  6637. this.MXA = this.MYB = this.MZC = 1;
  6638. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6639. }
  6640. }
  6641. function matrixProduct(a, b, result) {
  6642. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6643. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6644. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6645. }
  6646. function convertToFlat(sourceWhitePoint, LMS, result) {
  6647. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6648. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6649. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6650. }
  6651. function convertToD65(sourceWhitePoint, LMS, result) {
  6652. var D65X = 0.95047;
  6653. var D65Y = 1;
  6654. var D65Z = 1.08883;
  6655. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6656. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6657. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6658. }
  6659. function sRGBTransferFunction(color) {
  6660. // See http://en.wikipedia.org/wiki/SRGB.
  6661. if (color <= 0.0031308){
  6662. return adjustToRange(0, 1, 12.92 * color);
  6663. }
  6664. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6665. }
  6666. function adjustToRange(min, max, value) {
  6667. return Math.max(min, Math.min(max, value));
  6668. }
  6669. function decodeL(L) {
  6670. if (L < 0) {
  6671. return -decodeL(-L);
  6672. }
  6673. if (L > 8.0) {
  6674. return Math.pow(((L + 16) / 116), 3);
  6675. }
  6676. return L * DECODE_L_CONSTANT;
  6677. }
  6678. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6679. // In case the blackPoint is already the default blackPoint then there is
  6680. // no need to do compensation.
  6681. if (sourceBlackPoint[0] === 0 &&
  6682. sourceBlackPoint[1] === 0 &&
  6683. sourceBlackPoint[2] === 0) {
  6684. result[0] = XYZ_Flat[0];
  6685. result[1] = XYZ_Flat[1];
  6686. result[2] = XYZ_Flat[2];
  6687. return;
  6688. }
  6689. // For the blackPoint calculation details, please see
  6690. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6691. // AdobeBPC.pdf.
  6692. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6693. var zeroDecodeL = decodeL(0);
  6694. var X_DST = zeroDecodeL;
  6695. var X_SRC = decodeL(sourceBlackPoint[0]);
  6696. var Y_DST = zeroDecodeL;
  6697. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6698. var Z_DST = zeroDecodeL;
  6699. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6700. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6701. var X_Offset = 1 - X_Scale;
  6702. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6703. var Y_Offset = 1 - Y_Scale;
  6704. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6705. var Z_Offset = 1 - Z_Scale;
  6706. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6707. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6708. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6709. }
  6710. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6711. // In case the whitePoint is already flat then there is no need to do
  6712. // normalization.
  6713. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6714. result[0] = XYZ_In[0];
  6715. result[1] = XYZ_In[1];
  6716. result[2] = XYZ_In[2];
  6717. return;
  6718. }
  6719. var LMS = result;
  6720. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6721. var LMS_Flat = tempNormalizeMatrix;
  6722. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6723. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6724. }
  6725. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6726. var LMS = result;
  6727. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6728. var LMS_D65 = tempNormalizeMatrix;
  6729. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6730. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6731. }
  6732. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6733. // A, B and C represent a red, green and blue components of a calibrated
  6734. // rgb space.
  6735. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6736. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6737. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6738. // A <---> AGR in the spec
  6739. // B <---> BGG in the spec
  6740. // C <---> CGB in the spec
  6741. var AGR = Math.pow(A, cs.GR);
  6742. var BGG = Math.pow(B, cs.GG);
  6743. var CGB = Math.pow(C, cs.GB);
  6744. // Computes intermediate variables L, M, N as per spec.
  6745. // To decode X, Y, Z values map L, M, N directly to them.
  6746. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6747. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6748. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6749. // The following calculations are based on this document:
  6750. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6751. // AdobeBPC.pdf.
  6752. var XYZ = tempConvertMatrix1;
  6753. XYZ[0] = X;
  6754. XYZ[1] = Y;
  6755. XYZ[2] = Z;
  6756. var XYZ_Flat = tempConvertMatrix2;
  6757. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6758. var XYZ_Black = tempConvertMatrix1;
  6759. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6760. var XYZ_D65 = tempConvertMatrix2;
  6761. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6762. var SRGB = tempConvertMatrix1;
  6763. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6764. var sR = sRGBTransferFunction(SRGB[0]);
  6765. var sG = sRGBTransferFunction(SRGB[1]);
  6766. var sB = sRGBTransferFunction(SRGB[2]);
  6767. // Convert the values to rgb range [0, 255].
  6768. dest[destOffset] = Math.round(sR * 255);
  6769. dest[destOffset + 1] = Math.round(sG * 255);
  6770. dest[destOffset + 2] = Math.round(sB * 255);
  6771. }
  6772. CalRGBCS.prototype = {
  6773. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6774. var rgb = new Uint8Array(3);
  6775. this.getRgbItem(src, srcOffset, rgb, 0);
  6776. return rgb;
  6777. },
  6778. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6779. dest, destOffset) {
  6780. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6781. },
  6782. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6783. dest, destOffset, bits,
  6784. alpha01) {
  6785. var scale = 1 / ((1 << bits) - 1);
  6786. for (var i = 0; i < count; ++i) {
  6787. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6788. srcOffset += 3;
  6789. destOffset += 3 + alpha01;
  6790. }
  6791. },
  6792. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6793. return (inputLength * (3 + alpha01) / 3) | 0;
  6794. },
  6795. isPassthrough: ColorSpace.prototype.isPassthrough,
  6796. fillRgb: ColorSpace.prototype.fillRgb,
  6797. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6798. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6799. },
  6800. usesZeroToOneRange: true
  6801. };
  6802. return CalRGBCS;
  6803. })();
  6804. //
  6805. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6806. //
  6807. var LabCS = (function LabCSClosure() {
  6808. function LabCS(whitePoint, blackPoint, range) {
  6809. this.name = 'Lab';
  6810. this.numComps = 3;
  6811. this.defaultColor = new Float32Array([0, 0, 0]);
  6812. if (!whitePoint) {
  6813. error('WhitePoint missing - required for color space Lab');
  6814. }
  6815. blackPoint = blackPoint || [0, 0, 0];
  6816. range = range || [-100, 100, -100, 100];
  6817. // Translate args to spec variables
  6818. this.XW = whitePoint[0];
  6819. this.YW = whitePoint[1];
  6820. this.ZW = whitePoint[2];
  6821. this.amin = range[0];
  6822. this.amax = range[1];
  6823. this.bmin = range[2];
  6824. this.bmax = range[3];
  6825. // These are here just for completeness - the spec doesn't offer any
  6826. // formulas that use BlackPoint in Lab
  6827. this.XB = blackPoint[0];
  6828. this.YB = blackPoint[1];
  6829. this.ZB = blackPoint[2];
  6830. // Validate vars as per spec
  6831. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6832. error('Invalid WhitePoint components, no fallback available');
  6833. }
  6834. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6835. info('Invalid BlackPoint, falling back to default');
  6836. this.XB = this.YB = this.ZB = 0;
  6837. }
  6838. if (this.amin > this.amax || this.bmin > this.bmax) {
  6839. info('Invalid Range, falling back to defaults');
  6840. this.amin = -100;
  6841. this.amax = 100;
  6842. this.bmin = -100;
  6843. this.bmax = 100;
  6844. }
  6845. }
  6846. // Function g(x) from spec
  6847. function fn_g(x) {
  6848. if (x >= 6 / 29) {
  6849. return x * x * x;
  6850. } else {
  6851. return (108 / 841) * (x - 4 / 29);
  6852. }
  6853. }
  6854. function decode(value, high1, low2, high2) {
  6855. return low2 + (value) * (high2 - low2) / (high1);
  6856. }
  6857. // If decoding is needed maxVal should be 2^bits per component - 1.
  6858. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6859. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6860. // not the usual [0, 1]. If a command like setFillColor is used the src
  6861. // values will already be within the correct range. However, if we are
  6862. // converting an image we have to map the values to the correct range given
  6863. // above.
  6864. // Ls,as,bs <---> L*,a*,b* in the spec
  6865. var Ls = src[srcOffset];
  6866. var as = src[srcOffset + 1];
  6867. var bs = src[srcOffset + 2];
  6868. if (maxVal !== false) {
  6869. Ls = decode(Ls, maxVal, 0, 100);
  6870. as = decode(as, maxVal, cs.amin, cs.amax);
  6871. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6872. }
  6873. // Adjust limits of 'as' and 'bs'
  6874. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6875. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6876. // Computes intermediate variables X,Y,Z as per spec
  6877. var M = (Ls + 16) / 116;
  6878. var L = M + (as / 500);
  6879. var N = M - (bs / 200);
  6880. var X = cs.XW * fn_g(L);
  6881. var Y = cs.YW * fn_g(M);
  6882. var Z = cs.ZW * fn_g(N);
  6883. var r, g, b;
  6884. // Using different conversions for D50 and D65 white points,
  6885. // per http://www.color.org/srgb.pdf
  6886. if (cs.ZW < 1) {
  6887. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6888. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6889. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6890. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6891. } else {
  6892. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6893. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6894. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6895. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6896. }
  6897. // clamp color values to [0,1] range then convert to [0,255] range.
  6898. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6899. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6900. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6901. }
  6902. LabCS.prototype = {
  6903. getRgb: ColorSpace.prototype.getRgb,
  6904. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6905. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6906. },
  6907. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6908. dest, destOffset, bits,
  6909. alpha01) {
  6910. var maxVal = (1 << bits) - 1;
  6911. for (var i = 0; i < count; i++) {
  6912. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6913. srcOffset += 3;
  6914. destOffset += 3 + alpha01;
  6915. }
  6916. },
  6917. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6918. return (inputLength * (3 + alpha01) / 3) | 0;
  6919. },
  6920. isPassthrough: ColorSpace.prototype.isPassthrough,
  6921. fillRgb: ColorSpace.prototype.fillRgb,
  6922. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6923. // XXX: Decoding is handled with the lab conversion because of the strange
  6924. // ranges that are used.
  6925. return true;
  6926. },
  6927. usesZeroToOneRange: false
  6928. };
  6929. return LabCS;
  6930. })();
  6931. var ARCFourCipher = (function ARCFourCipherClosure() {
  6932. function ARCFourCipher(key) {
  6933. this.a = 0;
  6934. this.b = 0;
  6935. var s = new Uint8Array(256);
  6936. var i, j = 0, tmp, keyLength = key.length;
  6937. for (i = 0; i < 256; ++i) {
  6938. s[i] = i;
  6939. }
  6940. for (i = 0; i < 256; ++i) {
  6941. tmp = s[i];
  6942. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6943. s[i] = s[j];
  6944. s[j] = tmp;
  6945. }
  6946. this.s = s;
  6947. }
  6948. ARCFourCipher.prototype = {
  6949. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6950. var i, n = data.length, tmp, tmp2;
  6951. var a = this.a, b = this.b, s = this.s;
  6952. var output = new Uint8Array(n);
  6953. for (i = 0; i < n; ++i) {
  6954. a = (a + 1) & 0xFF;
  6955. tmp = s[a];
  6956. b = (b + tmp) & 0xFF;
  6957. tmp2 = s[b];
  6958. s[a] = tmp2;
  6959. s[b] = tmp;
  6960. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6961. }
  6962. this.a = a;
  6963. this.b = b;
  6964. return output;
  6965. }
  6966. };
  6967. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6968. return ARCFourCipher;
  6969. })();
  6970. var calculateMD5 = (function calculateMD5Closure() {
  6971. var r = new Uint8Array([
  6972. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6973. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6974. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6975. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6976. var k = new Int32Array([
  6977. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6978. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6979. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6980. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6981. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6982. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6983. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6984. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6985. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6986. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6987. -145523070, -1120210379, 718787259, -343485551]);
  6988. function hash(data, offset, length) {
  6989. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6990. // pre-processing
  6991. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6992. var padded = new Uint8Array(paddedLength);
  6993. var i, j, n;
  6994. for (i = 0; i < length; ++i) {
  6995. padded[i] = data[offset++];
  6996. }
  6997. padded[i++] = 0x80;
  6998. n = paddedLength - 8;
  6999. while (i < n) {
  7000. padded[i++] = 0;
  7001. }
  7002. padded[i++] = (length << 3) & 0xFF;
  7003. padded[i++] = (length >> 5) & 0xFF;
  7004. padded[i++] = (length >> 13) & 0xFF;
  7005. padded[i++] = (length >> 21) & 0xFF;
  7006. padded[i++] = (length >>> 29) & 0xFF;
  7007. padded[i++] = 0;
  7008. padded[i++] = 0;
  7009. padded[i++] = 0;
  7010. var w = new Int32Array(16);
  7011. for (i = 0; i < paddedLength;) {
  7012. for (j = 0; j < 16; ++j, i += 4) {
  7013. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7014. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7015. }
  7016. var a = h0, b = h1, c = h2, d = h3, f, g;
  7017. for (j = 0; j < 64; ++j) {
  7018. if (j < 16) {
  7019. f = (b & c) | ((~b) & d);
  7020. g = j;
  7021. } else if (j < 32) {
  7022. f = (d & b) | ((~d) & c);
  7023. g = (5 * j + 1) & 15;
  7024. } else if (j < 48) {
  7025. f = b ^ c ^ d;
  7026. g = (3 * j + 5) & 15;
  7027. } else {
  7028. f = c ^ (b | (~d));
  7029. g = (7 * j) & 15;
  7030. }
  7031. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7032. d = c;
  7033. c = b;
  7034. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7035. a = tmp;
  7036. }
  7037. h0 = (h0 + a) | 0;
  7038. h1 = (h1 + b) | 0;
  7039. h2 = (h2 + c) | 0;
  7040. h3 = (h3 + d) | 0;
  7041. }
  7042. return new Uint8Array([
  7043. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7044. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7045. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7046. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7047. ]);
  7048. }
  7049. return hash;
  7050. })();
  7051. var Word64 = (function Word64Closure() {
  7052. function Word64(highInteger, lowInteger) {
  7053. this.high = highInteger | 0;
  7054. this.low = lowInteger | 0;
  7055. }
  7056. Word64.prototype = {
  7057. and: function Word64_and(word) {
  7058. this.high &= word.high;
  7059. this.low &= word.low;
  7060. },
  7061. xor: function Word64_xor(word) {
  7062. this.high ^= word.high;
  7063. this.low ^= word.low;
  7064. },
  7065. or: function Word64_or(word) {
  7066. this.high |= word.high;
  7067. this.low |= word.low;
  7068. },
  7069. shiftRight: function Word64_shiftRight(places) {
  7070. if (places >= 32) {
  7071. this.low = (this.high >>> (places - 32)) | 0;
  7072. this.high = 0;
  7073. } else {
  7074. this.low = (this.low >>> places) | (this.high << (32 - places));
  7075. this.high = (this.high >>> places) | 0;
  7076. }
  7077. },
  7078. shiftLeft: function Word64_shiftLeft(places) {
  7079. if (places >= 32) {
  7080. this.high = this.low << (places - 32);
  7081. this.low = 0;
  7082. } else {
  7083. this.high = (this.high << places) | (this.low >>> (32 - places));
  7084. this.low = this.low << places;
  7085. }
  7086. },
  7087. rotateRight: function Word64_rotateRight(places) {
  7088. var low, high;
  7089. if (places & 32) {
  7090. high = this.low;
  7091. low = this.high;
  7092. } else {
  7093. low = this.low;
  7094. high = this.high;
  7095. }
  7096. places &= 31;
  7097. this.low = (low >>> places) | (high << (32 - places));
  7098. this.high = (high >>> places) | (low << (32 - places));
  7099. },
  7100. not: function Word64_not() {
  7101. this.high = ~this.high;
  7102. this.low = ~this.low;
  7103. },
  7104. add: function Word64_add(word) {
  7105. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7106. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7107. if (lowAdd > 0xFFFFFFFF) {
  7108. highAdd += 1;
  7109. }
  7110. this.low = lowAdd | 0;
  7111. this.high = highAdd | 0;
  7112. },
  7113. copyTo: function Word64_copyTo(bytes, offset) {
  7114. bytes[offset] = (this.high >>> 24) & 0xFF;
  7115. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7116. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7117. bytes[offset + 3] = this.high & 0xFF;
  7118. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7119. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7120. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7121. bytes[offset + 7] = this.low & 0xFF;
  7122. },
  7123. assign: function Word64_assign(word) {
  7124. this.high = word.high;
  7125. this.low = word.low;
  7126. }
  7127. };
  7128. return Word64;
  7129. })();
  7130. var calculateSHA256 = (function calculateSHA256Closure() {
  7131. function rotr(x, n) {
  7132. return (x >>> n) | (x << 32 - n);
  7133. }
  7134. function ch(x, y, z) {
  7135. return (x & y) ^ (~x & z);
  7136. }
  7137. function maj(x, y, z) {
  7138. return (x & y) ^ (x & z) ^ (y & z);
  7139. }
  7140. function sigma(x) {
  7141. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7142. }
  7143. function sigmaPrime(x) {
  7144. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7145. }
  7146. function littleSigma(x) {
  7147. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7148. }
  7149. function littleSigmaPrime(x) {
  7150. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7151. }
  7152. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7153. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7154. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7155. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7156. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7157. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7158. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7159. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7160. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7161. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7162. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7163. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7164. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7165. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7166. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7167. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7168. function hash(data, offset, length) {
  7169. // initial hash values
  7170. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7171. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7172. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7173. // pre-processing
  7174. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7175. var padded = new Uint8Array(paddedLength);
  7176. var i, j, n;
  7177. for (i = 0; i < length; ++i) {
  7178. padded[i] = data[offset++];
  7179. }
  7180. padded[i++] = 0x80;
  7181. n = paddedLength - 8;
  7182. while (i < n) {
  7183. padded[i++] = 0;
  7184. }
  7185. padded[i++] = 0;
  7186. padded[i++] = 0;
  7187. padded[i++] = 0;
  7188. padded[i++] = (length >>> 29) & 0xFF;
  7189. padded[i++] = (length >> 21) & 0xFF;
  7190. padded[i++] = (length >> 13) & 0xFF;
  7191. padded[i++] = (length >> 5) & 0xFF;
  7192. padded[i++] = (length << 3) & 0xFF;
  7193. var w = new Uint32Array(64);
  7194. // for each 512 bit block
  7195. for (i = 0; i < paddedLength;) {
  7196. for (j = 0; j < 16; ++j) {
  7197. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7198. (padded[i + 2] << 8) | (padded[i + 3]));
  7199. i += 4;
  7200. }
  7201. for (j = 16; j < 64; ++j) {
  7202. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7203. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7204. }
  7205. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7206. f = h5, g = h6, h = h7, t1, t2;
  7207. for (j = 0; j < 64; ++j) {
  7208. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7209. t2 = sigma(a) + maj(a, b, c);
  7210. h = g;
  7211. g = f;
  7212. f = e;
  7213. e = (d + t1) | 0;
  7214. d = c;
  7215. c = b;
  7216. b = a;
  7217. a = (t1 + t2) | 0;
  7218. }
  7219. h0 = (h0 + a) | 0;
  7220. h1 = (h1 + b) | 0;
  7221. h2 = (h2 + c) | 0;
  7222. h3 = (h3 + d) | 0;
  7223. h4 = (h4 + e) | 0;
  7224. h5 = (h5 + f) | 0;
  7225. h6 = (h6 + g) | 0;
  7226. h7 = (h7 + h) | 0;
  7227. }
  7228. return new Uint8Array([
  7229. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7230. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7231. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7232. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7233. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7234. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7235. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7236. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7237. ]);
  7238. }
  7239. return hash;
  7240. })();
  7241. var calculateSHA512 = (function calculateSHA512Closure() {
  7242. function ch(result, x, y, z, tmp) {
  7243. result.assign(x);
  7244. result.and(y);
  7245. tmp.assign(x);
  7246. tmp.not();
  7247. tmp.and(z);
  7248. result.xor(tmp);
  7249. }
  7250. function maj(result, x, y, z, tmp) {
  7251. result.assign(x);
  7252. result.and(y);
  7253. tmp.assign(x);
  7254. tmp.and(z);
  7255. result.xor(tmp);
  7256. tmp.assign(y);
  7257. tmp.and(z);
  7258. result.xor(tmp);
  7259. }
  7260. function sigma(result, x, tmp) {
  7261. result.assign(x);
  7262. result.rotateRight(28);
  7263. tmp.assign(x);
  7264. tmp.rotateRight(34);
  7265. result.xor(tmp);
  7266. tmp.assign(x);
  7267. tmp.rotateRight(39);
  7268. result.xor(tmp);
  7269. }
  7270. function sigmaPrime(result, x, tmp) {
  7271. result.assign(x);
  7272. result.rotateRight(14);
  7273. tmp.assign(x);
  7274. tmp.rotateRight(18);
  7275. result.xor(tmp);
  7276. tmp.assign(x);
  7277. tmp.rotateRight(41);
  7278. result.xor(tmp);
  7279. }
  7280. function littleSigma(result, x, tmp) {
  7281. result.assign(x);
  7282. result.rotateRight(1);
  7283. tmp.assign(x);
  7284. tmp.rotateRight(8);
  7285. result.xor(tmp);
  7286. tmp.assign(x);
  7287. tmp.shiftRight(7);
  7288. result.xor(tmp);
  7289. }
  7290. function littleSigmaPrime(result, x, tmp) {
  7291. result.assign(x);
  7292. result.rotateRight(19);
  7293. tmp.assign(x);
  7294. tmp.rotateRight(61);
  7295. result.xor(tmp);
  7296. tmp.assign(x);
  7297. tmp.shiftRight(6);
  7298. result.xor(tmp);
  7299. }
  7300. var k = [
  7301. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7302. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7303. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7304. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7305. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7306. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7307. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7308. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7309. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7310. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7311. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7312. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7313. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7314. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7315. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7316. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7317. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7318. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7319. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7320. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7321. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7322. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7323. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7324. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7325. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7326. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7327. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7328. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7329. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7330. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7331. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7332. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7333. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7334. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7335. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7336. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7337. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7338. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7339. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7340. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7341. function hash(data, offset, length, mode384) {
  7342. mode384 = !!mode384;
  7343. // initial hash values
  7344. var h0, h1, h2, h3, h4, h5, h6, h7;
  7345. if (!mode384) {
  7346. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7347. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7348. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7349. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7350. h4 = new Word64(0x510e527f, 0xade682d1);
  7351. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7352. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7353. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7354. }
  7355. else {
  7356. // SHA384 is exactly the same
  7357. // except with different starting values and a trimmed result
  7358. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7359. h1 = new Word64(0x629a292a, 0x367cd507);
  7360. h2 = new Word64(0x9159015a, 0x3070dd17);
  7361. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7362. h4 = new Word64(0x67332667, 0xffc00b31);
  7363. h5 = new Word64(0x8eb44a87, 0x68581511);
  7364. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7365. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7366. }
  7367. // pre-processing
  7368. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7369. var padded = new Uint8Array(paddedLength);
  7370. var i, j, n;
  7371. for (i = 0; i < length; ++i) {
  7372. padded[i] = data[offset++];
  7373. }
  7374. padded[i++] = 0x80;
  7375. n = paddedLength - 16;
  7376. while (i < n) {
  7377. padded[i++] = 0;
  7378. }
  7379. padded[i++] = 0;
  7380. padded[i++] = 0;
  7381. padded[i++] = 0;
  7382. padded[i++] = 0;
  7383. padded[i++] = 0;
  7384. padded[i++] = 0;
  7385. padded[i++] = 0;
  7386. padded[i++] = 0;
  7387. padded[i++] = 0;
  7388. padded[i++] = 0;
  7389. padded[i++] = 0;
  7390. padded[i++] = (length >>> 29) & 0xFF;
  7391. padded[i++] = (length >> 21) & 0xFF;
  7392. padded[i++] = (length >> 13) & 0xFF;
  7393. padded[i++] = (length >> 5) & 0xFF;
  7394. padded[i++] = (length << 3) & 0xFF;
  7395. var w = new Array(80);
  7396. for (i = 0; i < 80; i++) {
  7397. w[i] = new Word64(0, 0);
  7398. }
  7399. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7400. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7401. var g = new Word64(0, 0), h = new Word64(0, 0);
  7402. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7403. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7404. // for each 1024 bit block
  7405. for (i = 0; i < paddedLength;) {
  7406. for (j = 0; j < 16; ++j) {
  7407. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7408. (padded[i + 2] << 8) | (padded[i + 3]);
  7409. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7410. (padded[i + 6]) << 8 | (padded[i + 7]);
  7411. i += 8;
  7412. }
  7413. for (j = 16; j < 80; ++j) {
  7414. tmp3 = w[j];
  7415. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7416. tmp3.add(w[j - 7]);
  7417. littleSigma(tmp1, w[j - 15], tmp2);
  7418. tmp3.add(tmp1);
  7419. tmp3.add(w[j - 16]);
  7420. }
  7421. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7422. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7423. for (j = 0; j < 80; ++j) {
  7424. t1.assign(h);
  7425. sigmaPrime(tmp1, e, tmp2);
  7426. t1.add(tmp1);
  7427. ch(tmp1, e, f, g, tmp2);
  7428. t1.add(tmp1);
  7429. t1.add(k[j]);
  7430. t1.add(w[j]);
  7431. sigma(t2, a, tmp2);
  7432. maj(tmp1, a, b, c, tmp2);
  7433. t2.add(tmp1);
  7434. tmp3 = h;
  7435. h = g;
  7436. g = f;
  7437. f = e;
  7438. d.add(t1);
  7439. e = d;
  7440. d = c;
  7441. c = b;
  7442. b = a;
  7443. tmp3.assign(t1);
  7444. tmp3.add(t2);
  7445. a = tmp3;
  7446. }
  7447. h0.add(a);
  7448. h1.add(b);
  7449. h2.add(c);
  7450. h3.add(d);
  7451. h4.add(e);
  7452. h5.add(f);
  7453. h6.add(g);
  7454. h7.add(h);
  7455. }
  7456. var result;
  7457. if (!mode384) {
  7458. result = new Uint8Array(64);
  7459. h0.copyTo(result,0);
  7460. h1.copyTo(result,8);
  7461. h2.copyTo(result,16);
  7462. h3.copyTo(result,24);
  7463. h4.copyTo(result,32);
  7464. h5.copyTo(result,40);
  7465. h6.copyTo(result,48);
  7466. h7.copyTo(result,56);
  7467. }
  7468. else {
  7469. result = new Uint8Array(48);
  7470. h0.copyTo(result,0);
  7471. h1.copyTo(result,8);
  7472. h2.copyTo(result,16);
  7473. h3.copyTo(result,24);
  7474. h4.copyTo(result,32);
  7475. h5.copyTo(result,40);
  7476. }
  7477. return result;
  7478. }
  7479. return hash;
  7480. })();
  7481. var calculateSHA384 = (function calculateSHA384Closure() {
  7482. function hash(data, offset, length) {
  7483. return calculateSHA512(data, offset, length, true);
  7484. }
  7485. return hash;
  7486. })();
  7487. var NullCipher = (function NullCipherClosure() {
  7488. function NullCipher() {
  7489. }
  7490. NullCipher.prototype = {
  7491. decryptBlock: function NullCipher_decryptBlock(data) {
  7492. return data;
  7493. }
  7494. };
  7495. return NullCipher;
  7496. })();
  7497. var AES128Cipher = (function AES128CipherClosure() {
  7498. var rcon = new Uint8Array([
  7499. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7500. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7501. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7502. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7503. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7504. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7505. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7506. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7507. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7508. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7509. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7510. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7511. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7512. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7513. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7514. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7515. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7516. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7517. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7518. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7519. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7520. 0x74, 0xe8, 0xcb, 0x8d]);
  7521. var s = new Uint8Array([
  7522. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7523. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7524. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7525. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7526. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7527. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7528. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7529. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7530. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7531. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7532. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7533. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7534. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7535. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7536. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7537. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7538. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7539. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7540. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7541. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7542. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7543. 0xb0, 0x54, 0xbb, 0x16]);
  7544. var inv_s = new Uint8Array([
  7545. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7546. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7547. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7548. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7549. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7550. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7551. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7552. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7553. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7554. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7555. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7556. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7557. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7558. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7559. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7560. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7561. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7562. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7563. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7564. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7565. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7566. 0x55, 0x21, 0x0c, 0x7d]);
  7567. var mixCol = new Uint8Array(256);
  7568. for (var i = 0; i < 256; i++) {
  7569. if (i < 128) {
  7570. mixCol[i] = i << 1;
  7571. } else {
  7572. mixCol[i] = (i << 1) ^ 0x1b;
  7573. }
  7574. }
  7575. var mix = new Uint32Array([
  7576. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7577. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7578. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7579. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7580. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7581. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7582. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7583. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7584. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7585. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7586. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7587. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7588. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7589. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7590. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7591. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7592. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7593. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7594. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7595. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7596. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7597. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7598. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7599. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7600. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7601. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7602. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7603. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7604. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7605. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7606. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7607. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7608. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7609. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7610. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7611. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7612. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7613. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7614. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7615. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7616. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7617. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7618. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7619. function expandKey128(cipherKey) {
  7620. var b = 176, result = new Uint8Array(b);
  7621. result.set(cipherKey);
  7622. for (var j = 16, i = 1; j < b; ++i) {
  7623. // RotWord
  7624. var t1 = result[j - 3], t2 = result[j - 2],
  7625. t3 = result[j - 1], t4 = result[j - 4];
  7626. // SubWord
  7627. t1 = s[t1];
  7628. t2 = s[t2];
  7629. t3 = s[t3];
  7630. t4 = s[t4];
  7631. // Rcon
  7632. t1 = t1 ^ rcon[i];
  7633. for (var n = 0; n < 4; ++n) {
  7634. result[j] = (t1 ^= result[j - 16]);
  7635. j++;
  7636. result[j] = (t2 ^= result[j - 16]);
  7637. j++;
  7638. result[j] = (t3 ^= result[j - 16]);
  7639. j++;
  7640. result[j] = (t4 ^= result[j - 16]);
  7641. j++;
  7642. }
  7643. }
  7644. return result;
  7645. }
  7646. function decrypt128(input, key) {
  7647. var state = new Uint8Array(16);
  7648. state.set(input);
  7649. var i, j, k;
  7650. var t, u, v;
  7651. // AddRoundKey
  7652. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7653. state[j] ^= key[k];
  7654. }
  7655. for (i = 9; i >= 1; --i) {
  7656. // InvShiftRows
  7657. t = state[13];
  7658. state[13] = state[9];
  7659. state[9] = state[5];
  7660. state[5] = state[1];
  7661. state[1] = t;
  7662. t = state[14];
  7663. u = state[10];
  7664. state[14] = state[6];
  7665. state[10] = state[2];
  7666. state[6] = t;
  7667. state[2] = u;
  7668. t = state[15];
  7669. u = state[11];
  7670. v = state[7];
  7671. state[15] = state[3];
  7672. state[11] = t;
  7673. state[7] = u;
  7674. state[3] = v;
  7675. // InvSubBytes
  7676. for (j = 0; j < 16; ++j) {
  7677. state[j] = inv_s[state[j]];
  7678. }
  7679. // AddRoundKey
  7680. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7681. state[j] ^= key[k];
  7682. }
  7683. // InvMixColumns
  7684. for (j = 0; j < 16; j += 4) {
  7685. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7686. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7687. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7688. (s3 >>> 24) ^ (s3 << 8));
  7689. state[j] = (t >>> 24) & 0xFF;
  7690. state[j + 1] = (t >> 16) & 0xFF;
  7691. state[j + 2] = (t >> 8) & 0xFF;
  7692. state[j + 3] = t & 0xFF;
  7693. }
  7694. }
  7695. // InvShiftRows
  7696. t = state[13];
  7697. state[13] = state[9];
  7698. state[9] = state[5];
  7699. state[5] = state[1];
  7700. state[1] = t;
  7701. t = state[14];
  7702. u = state[10];
  7703. state[14] = state[6];
  7704. state[10] = state[2];
  7705. state[6] = t;
  7706. state[2] = u;
  7707. t = state[15];
  7708. u = state[11];
  7709. v = state[7];
  7710. state[15] = state[3];
  7711. state[11] = t;
  7712. state[7] = u;
  7713. state[3] = v;
  7714. for (j = 0; j < 16; ++j) {
  7715. // InvSubBytes
  7716. state[j] = inv_s[state[j]];
  7717. // AddRoundKey
  7718. state[j] ^= key[j];
  7719. }
  7720. return state;
  7721. }
  7722. function encrypt128(input, key) {
  7723. var t, u, v, k;
  7724. var state = new Uint8Array(16);
  7725. state.set(input);
  7726. for (j = 0; j < 16; ++j) {
  7727. // AddRoundKey
  7728. state[j] ^= key[j];
  7729. }
  7730. for (i = 1; i < 10; i++) {
  7731. //SubBytes
  7732. for (j = 0; j < 16; ++j) {
  7733. state[j] = s[state[j]];
  7734. }
  7735. //ShiftRows
  7736. v = state[1];
  7737. state[1] = state[5];
  7738. state[5] = state[9];
  7739. state[9] = state[13];
  7740. state[13] = v;
  7741. v = state[2];
  7742. u = state[6];
  7743. state[2] = state[10];
  7744. state[6] = state[14];
  7745. state[10] = v;
  7746. state[14] = u;
  7747. v = state[3];
  7748. u = state[7];
  7749. t = state[11];
  7750. state[3] = state[15];
  7751. state[7] = v;
  7752. state[11] = u;
  7753. state[15] = t;
  7754. //MixColumns
  7755. for (var j = 0; j < 16; j += 4) {
  7756. var s0 = state[j + 0], s1 = state[j + 1];
  7757. var s2 = state[j + 2], s3 = state[j + 3];
  7758. t = s0 ^ s1 ^ s2 ^ s3;
  7759. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7760. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7761. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7762. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7763. }
  7764. //AddRoundKey
  7765. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7766. state[j] ^= key[k];
  7767. }
  7768. }
  7769. //SubBytes
  7770. for (j = 0; j < 16; ++j) {
  7771. state[j] = s[state[j]];
  7772. }
  7773. //ShiftRows
  7774. v = state[1];
  7775. state[1] = state[5];
  7776. state[5] = state[9];
  7777. state[9] = state[13];
  7778. state[13] = v;
  7779. v = state[2];
  7780. u = state[6];
  7781. state[2] = state[10];
  7782. state[6] = state[14];
  7783. state[10] = v;
  7784. state[14] = u;
  7785. v = state[3];
  7786. u = state[7];
  7787. t = state[11];
  7788. state[3] = state[15];
  7789. state[7] = v;
  7790. state[11] = u;
  7791. state[15] = t;
  7792. //AddRoundKey
  7793. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7794. state[j] ^= key[k];
  7795. }
  7796. return state;
  7797. }
  7798. function AES128Cipher(key) {
  7799. this.key = expandKey128(key);
  7800. this.buffer = new Uint8Array(16);
  7801. this.bufferPosition = 0;
  7802. }
  7803. function decryptBlock2(data, finalize) {
  7804. var i, j, ii, sourceLength = data.length,
  7805. buffer = this.buffer, bufferLength = this.bufferPosition,
  7806. result = [], iv = this.iv;
  7807. for (i = 0; i < sourceLength; ++i) {
  7808. buffer[bufferLength] = data[i];
  7809. ++bufferLength;
  7810. if (bufferLength < 16) {
  7811. continue;
  7812. }
  7813. // buffer is full, decrypting
  7814. var plain = decrypt128(buffer, this.key);
  7815. // xor-ing the IV vector to get plain text
  7816. for (j = 0; j < 16; ++j) {
  7817. plain[j] ^= iv[j];
  7818. }
  7819. iv = buffer;
  7820. result.push(plain);
  7821. buffer = new Uint8Array(16);
  7822. bufferLength = 0;
  7823. }
  7824. // saving incomplete buffer
  7825. this.buffer = buffer;
  7826. this.bufferLength = bufferLength;
  7827. this.iv = iv;
  7828. if (result.length === 0) {
  7829. return new Uint8Array([]);
  7830. }
  7831. // combining plain text blocks into one
  7832. var outputLength = 16 * result.length;
  7833. if (finalize) {
  7834. // undo a padding that is described in RFC 2898
  7835. var lastBlock = result[result.length - 1];
  7836. var psLen = lastBlock[15];
  7837. if (psLen <= 16) {
  7838. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  7839. if (lastBlock[i] !== psLen) {
  7840. // Invalid padding, assume that the block has no padding.
  7841. psLen = 0;
  7842. break;
  7843. }
  7844. }
  7845. outputLength -= psLen;
  7846. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  7847. }
  7848. }
  7849. var output = new Uint8Array(outputLength);
  7850. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7851. output.set(result[i], j);
  7852. }
  7853. return output;
  7854. }
  7855. AES128Cipher.prototype = {
  7856. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7857. var i, sourceLength = data.length;
  7858. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7859. // waiting for IV values -- they are at the start of the stream
  7860. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7861. buffer[bufferLength] = data[i];
  7862. }
  7863. if (bufferLength < 16) {
  7864. // need more data
  7865. this.bufferLength = bufferLength;
  7866. return new Uint8Array([]);
  7867. }
  7868. this.iv = buffer;
  7869. this.buffer = new Uint8Array(16);
  7870. this.bufferLength = 0;
  7871. // starting decryption
  7872. this.decryptBlock = decryptBlock2;
  7873. return this.decryptBlock(data.subarray(16), finalize);
  7874. },
  7875. encrypt: function AES128Cipher_encrypt(data, iv) {
  7876. var i, j, ii, sourceLength = data.length,
  7877. buffer = this.buffer, bufferLength = this.bufferPosition,
  7878. result = [];
  7879. if (!iv) {
  7880. iv = new Uint8Array(16);
  7881. }
  7882. for (i = 0; i < sourceLength; ++i) {
  7883. buffer[bufferLength] = data[i];
  7884. ++bufferLength;
  7885. if (bufferLength < 16) {
  7886. continue;
  7887. }
  7888. for (j = 0; j < 16; ++j) {
  7889. buffer[j] ^= iv[j];
  7890. }
  7891. // buffer is full, encrypting
  7892. var cipher = encrypt128(buffer, this.key);
  7893. iv = cipher;
  7894. result.push(cipher);
  7895. buffer = new Uint8Array(16);
  7896. bufferLength = 0;
  7897. }
  7898. // saving incomplete buffer
  7899. this.buffer = buffer;
  7900. this.bufferLength = bufferLength;
  7901. this.iv = iv;
  7902. if (result.length === 0) {
  7903. return new Uint8Array([]);
  7904. }
  7905. // combining plain text blocks into one
  7906. var outputLength = 16 * result.length;
  7907. var output = new Uint8Array(outputLength);
  7908. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7909. output.set(result[i], j);
  7910. }
  7911. return output;
  7912. }
  7913. };
  7914. return AES128Cipher;
  7915. })();
  7916. var AES256Cipher = (function AES256CipherClosure() {
  7917. var rcon = new Uint8Array([
  7918. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7919. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7920. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7921. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7922. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7923. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7924. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7925. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7926. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7927. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7928. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7929. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7930. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7931. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7932. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7933. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7934. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7935. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7936. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7937. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7938. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7939. 0x74, 0xe8, 0xcb, 0x8d]);
  7940. var s = new Uint8Array([
  7941. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7942. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7943. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7944. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7945. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7946. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7947. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7948. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7949. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7950. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7951. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7952. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7953. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7954. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7955. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7956. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7957. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7958. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7959. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7960. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7961. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7962. 0xb0, 0x54, 0xbb, 0x16]);
  7963. var inv_s = new Uint8Array([
  7964. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7965. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7966. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7967. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7968. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7969. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7970. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7971. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7972. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7973. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7974. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7975. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7976. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7977. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7978. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7979. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7980. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7981. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7982. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7983. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7984. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7985. 0x55, 0x21, 0x0c, 0x7d]);
  7986. var mixCol = new Uint8Array(256);
  7987. for (var i = 0; i < 256; i++) {
  7988. if (i < 128) {
  7989. mixCol[i] = i << 1;
  7990. } else {
  7991. mixCol[i] = (i << 1) ^ 0x1b;
  7992. }
  7993. }
  7994. var mix = new Uint32Array([
  7995. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7996. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7997. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7998. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7999. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8000. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8001. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8002. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8003. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8004. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8005. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8006. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8007. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8008. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8009. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8010. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8011. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8012. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8013. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8014. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8015. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8016. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8017. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8018. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8019. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8020. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8021. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8022. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8023. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8024. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8025. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8026. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8027. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8028. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8029. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8030. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8031. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8032. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8033. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8034. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8035. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8036. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8037. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8038. function expandKey256(cipherKey) {
  8039. var b = 240, result = new Uint8Array(b);
  8040. var r = 1;
  8041. result.set(cipherKey);
  8042. for (var j = 32, i = 1; j < b; ++i) {
  8043. if (j % 32 === 16) {
  8044. t1 = s[t1];
  8045. t2 = s[t2];
  8046. t3 = s[t3];
  8047. t4 = s[t4];
  8048. } else if (j % 32 === 0) {
  8049. // RotWord
  8050. var t1 = result[j - 3], t2 = result[j - 2],
  8051. t3 = result[j - 1], t4 = result[j - 4];
  8052. // SubWord
  8053. t1 = s[t1];
  8054. t2 = s[t2];
  8055. t3 = s[t3];
  8056. t4 = s[t4];
  8057. // Rcon
  8058. t1 = t1 ^ r;
  8059. if ((r <<= 1) >= 256) {
  8060. r = (r ^ 0x1b) & 0xFF;
  8061. }
  8062. }
  8063. for (var n = 0; n < 4; ++n) {
  8064. result[j] = (t1 ^= result[j - 32]);
  8065. j++;
  8066. result[j] = (t2 ^= result[j - 32]);
  8067. j++;
  8068. result[j] = (t3 ^= result[j - 32]);
  8069. j++;
  8070. result[j] = (t4 ^= result[j - 32]);
  8071. j++;
  8072. }
  8073. }
  8074. return result;
  8075. }
  8076. function decrypt256(input, key) {
  8077. var state = new Uint8Array(16);
  8078. state.set(input);
  8079. var i, j, k;
  8080. var t, u, v;
  8081. // AddRoundKey
  8082. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8083. state[j] ^= key[k];
  8084. }
  8085. for (i = 13; i >= 1; --i) {
  8086. // InvShiftRows
  8087. t = state[13];
  8088. state[13] = state[9];
  8089. state[9] = state[5];
  8090. state[5] = state[1];
  8091. state[1] = t;
  8092. t = state[14];
  8093. u = state[10];
  8094. state[14] = state[6];
  8095. state[10] = state[2];
  8096. state[6] = t;
  8097. state[2] = u;
  8098. t = state[15];
  8099. u = state[11];
  8100. v = state[7];
  8101. state[15] = state[3];
  8102. state[11] = t;
  8103. state[7] = u;
  8104. state[3] = v;
  8105. // InvSubBytes
  8106. for (j = 0; j < 16; ++j) {
  8107. state[j] = inv_s[state[j]];
  8108. }
  8109. // AddRoundKey
  8110. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8111. state[j] ^= key[k];
  8112. }
  8113. // InvMixColumns
  8114. for (j = 0; j < 16; j += 4) {
  8115. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8116. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8117. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8118. (s3 >>> 24) ^ (s3 << 8));
  8119. state[j] = (t >>> 24) & 0xFF;
  8120. state[j + 1] = (t >> 16) & 0xFF;
  8121. state[j + 2] = (t >> 8) & 0xFF;
  8122. state[j + 3] = t & 0xFF;
  8123. }
  8124. }
  8125. // InvShiftRows
  8126. t = state[13];
  8127. state[13] = state[9];
  8128. state[9] = state[5];
  8129. state[5] = state[1];
  8130. state[1] = t;
  8131. t = state[14];
  8132. u = state[10];
  8133. state[14] = state[6];
  8134. state[10] = state[2];
  8135. state[6] = t;
  8136. state[2] = u;
  8137. t = state[15];
  8138. u = state[11];
  8139. v = state[7];
  8140. state[15] = state[3];
  8141. state[11] = t;
  8142. state[7] = u;
  8143. state[3] = v;
  8144. for (j = 0; j < 16; ++j) {
  8145. // InvSubBytes
  8146. state[j] = inv_s[state[j]];
  8147. // AddRoundKey
  8148. state[j] ^= key[j];
  8149. }
  8150. return state;
  8151. }
  8152. function encrypt256(input, key) {
  8153. var t, u, v, k;
  8154. var state = new Uint8Array(16);
  8155. state.set(input);
  8156. for (j = 0; j < 16; ++j) {
  8157. // AddRoundKey
  8158. state[j] ^= key[j];
  8159. }
  8160. for (i = 1; i < 14; i++) {
  8161. //SubBytes
  8162. for (j = 0; j < 16; ++j) {
  8163. state[j] = s[state[j]];
  8164. }
  8165. //ShiftRows
  8166. v = state[1];
  8167. state[1] = state[5];
  8168. state[5] = state[9];
  8169. state[9] = state[13];
  8170. state[13] = v;
  8171. v = state[2];
  8172. u = state[6];
  8173. state[2] = state[10];
  8174. state[6] = state[14];
  8175. state[10] = v;
  8176. state[14] = u;
  8177. v = state[3];
  8178. u = state[7];
  8179. t = state[11];
  8180. state[3] = state[15];
  8181. state[7] = v;
  8182. state[11] = u;
  8183. state[15] = t;
  8184. //MixColumns
  8185. for (var j = 0; j < 16; j += 4) {
  8186. var s0 = state[j + 0], s1 = state[j + 1];
  8187. var s2 = state[j + 2], s3 = state[j + 3];
  8188. t = s0 ^ s1 ^ s2 ^ s3;
  8189. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8190. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8191. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8192. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8193. }
  8194. //AddRoundKey
  8195. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8196. state[j] ^= key[k];
  8197. }
  8198. }
  8199. //SubBytes
  8200. for (j = 0; j < 16; ++j) {
  8201. state[j] = s[state[j]];
  8202. }
  8203. //ShiftRows
  8204. v = state[1];
  8205. state[1] = state[5];
  8206. state[5] = state[9];
  8207. state[9] = state[13];
  8208. state[13] = v;
  8209. v = state[2];
  8210. u = state[6];
  8211. state[2] = state[10];
  8212. state[6] = state[14];
  8213. state[10] = v;
  8214. state[14] = u;
  8215. v = state[3];
  8216. u = state[7];
  8217. t = state[11];
  8218. state[3] = state[15];
  8219. state[7] = v;
  8220. state[11] = u;
  8221. state[15] = t;
  8222. //AddRoundKey
  8223. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8224. state[j] ^= key[k];
  8225. }
  8226. return state;
  8227. }
  8228. function AES256Cipher(key) {
  8229. this.key = expandKey256(key);
  8230. this.buffer = new Uint8Array(16);
  8231. this.bufferPosition = 0;
  8232. }
  8233. function decryptBlock2(data, finalize) {
  8234. var i, j, ii, sourceLength = data.length,
  8235. buffer = this.buffer, bufferLength = this.bufferPosition,
  8236. result = [], iv = this.iv;
  8237. for (i = 0; i < sourceLength; ++i) {
  8238. buffer[bufferLength] = data[i];
  8239. ++bufferLength;
  8240. if (bufferLength < 16) {
  8241. continue;
  8242. }
  8243. // buffer is full, decrypting
  8244. var plain = decrypt256(buffer, this.key);
  8245. // xor-ing the IV vector to get plain text
  8246. for (j = 0; j < 16; ++j) {
  8247. plain[j] ^= iv[j];
  8248. }
  8249. iv = buffer;
  8250. result.push(plain);
  8251. buffer = new Uint8Array(16);
  8252. bufferLength = 0;
  8253. }
  8254. // saving incomplete buffer
  8255. this.buffer = buffer;
  8256. this.bufferLength = bufferLength;
  8257. this.iv = iv;
  8258. if (result.length === 0) {
  8259. return new Uint8Array([]);
  8260. }
  8261. // combining plain text blocks into one
  8262. var outputLength = 16 * result.length;
  8263. if (finalize) {
  8264. // undo a padding that is described in RFC 2898
  8265. var lastBlock = result[result.length - 1];
  8266. var psLen = lastBlock[15];
  8267. if (psLen <= 16) {
  8268. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8269. if (lastBlock[i] !== psLen) {
  8270. // Invalid padding, assume that the block has no padding.
  8271. psLen = 0;
  8272. break;
  8273. }
  8274. }
  8275. outputLength -= psLen;
  8276. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8277. }
  8278. }
  8279. var output = new Uint8Array(outputLength);
  8280. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8281. output.set(result[i], j);
  8282. }
  8283. return output;
  8284. }
  8285. AES256Cipher.prototype = {
  8286. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8287. var i, sourceLength = data.length;
  8288. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8289. // if not supplied an IV wait for IV values
  8290. // they are at the start of the stream
  8291. if (iv) {
  8292. this.iv = iv;
  8293. } else {
  8294. for (i = 0; bufferLength < 16 &&
  8295. i < sourceLength; ++i, ++bufferLength) {
  8296. buffer[bufferLength] = data[i];
  8297. }
  8298. if (bufferLength < 16) {
  8299. //need more data
  8300. this.bufferLength = bufferLength;
  8301. return new Uint8Array([]);
  8302. }
  8303. this.iv = buffer;
  8304. data = data.subarray(16);
  8305. }
  8306. this.buffer = new Uint8Array(16);
  8307. this.bufferLength = 0;
  8308. // starting decryption
  8309. this.decryptBlock = decryptBlock2;
  8310. return this.decryptBlock(data, finalize);
  8311. },
  8312. encrypt: function AES256Cipher_encrypt(data, iv) {
  8313. var i, j, ii, sourceLength = data.length,
  8314. buffer = this.buffer, bufferLength = this.bufferPosition,
  8315. result = [];
  8316. if (!iv) {
  8317. iv = new Uint8Array(16);
  8318. }
  8319. for (i = 0; i < sourceLength; ++i) {
  8320. buffer[bufferLength] = data[i];
  8321. ++bufferLength;
  8322. if (bufferLength < 16) {
  8323. continue;
  8324. }
  8325. for (j = 0; j < 16; ++j) {
  8326. buffer[j] ^= iv[j];
  8327. }
  8328. // buffer is full, encrypting
  8329. var cipher = encrypt256(buffer, this.key);
  8330. this.iv = cipher;
  8331. result.push(cipher);
  8332. buffer = new Uint8Array(16);
  8333. bufferLength = 0;
  8334. }
  8335. // saving incomplete buffer
  8336. this.buffer = buffer;
  8337. this.bufferLength = bufferLength;
  8338. this.iv = iv;
  8339. if (result.length === 0) {
  8340. return new Uint8Array([]);
  8341. }
  8342. // combining plain text blocks into one
  8343. var outputLength = 16 * result.length;
  8344. var output = new Uint8Array(outputLength);
  8345. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8346. output.set(result[i], j);
  8347. }
  8348. return output;
  8349. }
  8350. };
  8351. return AES256Cipher;
  8352. })();
  8353. var PDF17 = (function PDF17Closure() {
  8354. function compareByteArrays(array1, array2) {
  8355. if (array1.length !== array2.length) {
  8356. return false;
  8357. }
  8358. for (var i = 0; i < array1.length; i++) {
  8359. if (array1[i] !== array2[i]) {
  8360. return false;
  8361. }
  8362. }
  8363. return true;
  8364. }
  8365. function PDF17() {
  8366. }
  8367. PDF17.prototype = {
  8368. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8369. ownerValidationSalt,
  8370. userBytes,
  8371. ownerPassword) {
  8372. var hashData = new Uint8Array(password.length + 56);
  8373. hashData.set(password, 0);
  8374. hashData.set(ownerValidationSalt, password.length);
  8375. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8376. var result = calculateSHA256(hashData, 0, hashData.length);
  8377. return compareByteArrays(result, ownerPassword);
  8378. },
  8379. checkUserPassword: function PDF17_checkUserPassword(password,
  8380. userValidationSalt,
  8381. userPassword) {
  8382. var hashData = new Uint8Array(password.length + 8);
  8383. hashData.set(password, 0);
  8384. hashData.set(userValidationSalt, password.length);
  8385. var result = calculateSHA256(hashData, 0, hashData.length);
  8386. return compareByteArrays(result, userPassword);
  8387. },
  8388. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8389. ownerEncryption) {
  8390. var hashData = new Uint8Array(password.length + 56);
  8391. hashData.set(password, 0);
  8392. hashData.set(ownerKeySalt, password.length);
  8393. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8394. var key = calculateSHA256(hashData, 0, hashData.length);
  8395. var cipher = new AES256Cipher(key);
  8396. return cipher.decryptBlock(ownerEncryption,
  8397. false,
  8398. new Uint8Array(16));
  8399. },
  8400. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8401. userEncryption) {
  8402. var hashData = new Uint8Array(password.length + 8);
  8403. hashData.set(password, 0);
  8404. hashData.set(userKeySalt, password.length);
  8405. //key is the decryption key for the UE string
  8406. var key = calculateSHA256(hashData, 0, hashData.length);
  8407. var cipher = new AES256Cipher(key);
  8408. return cipher.decryptBlock(userEncryption,
  8409. false,
  8410. new Uint8Array(16));
  8411. }
  8412. };
  8413. return PDF17;
  8414. })();
  8415. var PDF20 = (function PDF20Closure() {
  8416. function concatArrays(array1, array2) {
  8417. var t = new Uint8Array(array1.length + array2.length);
  8418. t.set(array1, 0);
  8419. t.set(array2, array1.length);
  8420. return t;
  8421. }
  8422. function calculatePDF20Hash(password, input, userBytes) {
  8423. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8424. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8425. var e = [0];
  8426. var i = 0;
  8427. while (i < 64 || e[e.length - 1] > i - 32) {
  8428. var arrayLength = password.length + k.length + userBytes.length;
  8429. var k1 = new Uint8Array(arrayLength * 64);
  8430. var array = concatArrays(password, k);
  8431. array = concatArrays(array, userBytes);
  8432. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8433. k1.set(array, pos);
  8434. }
  8435. //AES128 CBC NO PADDING with
  8436. //first 16 bytes of k as the key and the second 16 as the iv.
  8437. var cipher = new AES128Cipher(k.subarray(0, 16));
  8438. e = cipher.encrypt(k1, k.subarray(16, 32));
  8439. //Now we have to take the first 16 bytes of an unsigned
  8440. //big endian integer... and compute the remainder
  8441. //modulo 3.... That is a fairly large number and
  8442. //JavaScript isn't going to handle that well...
  8443. //So we're using a trick that allows us to perform
  8444. //modulo math byte by byte
  8445. var remainder = 0;
  8446. for (var z = 0; z < 16; z++) {
  8447. remainder *= (256 % 3);
  8448. remainder %= 3;
  8449. remainder += ((e[z] >>> 0) % 3);
  8450. remainder %= 3;
  8451. }
  8452. if (remainder === 0) {
  8453. k = calculateSHA256(e, 0, e.length);
  8454. }
  8455. else if (remainder === 1) {
  8456. k = calculateSHA384(e, 0, e.length);
  8457. }
  8458. else if (remainder === 2) {
  8459. k = calculateSHA512(e, 0, e.length);
  8460. }
  8461. i++;
  8462. }
  8463. return k.subarray(0, 32);
  8464. }
  8465. function PDF20() {
  8466. }
  8467. function compareByteArrays(array1, array2) {
  8468. if (array1.length !== array2.length) {
  8469. return false;
  8470. }
  8471. for (var i = 0; i < array1.length; i++) {
  8472. if (array1[i] !== array2[i]) {
  8473. return false;
  8474. }
  8475. }
  8476. return true;
  8477. }
  8478. PDF20.prototype = {
  8479. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8480. return calculatePDF20Hash(password, concatBytes, userBytes);
  8481. },
  8482. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8483. ownerValidationSalt,
  8484. userBytes,
  8485. ownerPassword) {
  8486. var hashData = new Uint8Array(password.length + 56);
  8487. hashData.set(password, 0);
  8488. hashData.set(ownerValidationSalt, password.length);
  8489. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8490. var result = calculatePDF20Hash(password, hashData, userBytes);
  8491. return compareByteArrays(result, ownerPassword);
  8492. },
  8493. checkUserPassword: function PDF20_checkUserPassword(password,
  8494. userValidationSalt,
  8495. userPassword) {
  8496. var hashData = new Uint8Array(password.length + 8);
  8497. hashData.set(password, 0);
  8498. hashData.set(userValidationSalt, password.length);
  8499. var result = calculatePDF20Hash(password, hashData, []);
  8500. return compareByteArrays(result, userPassword);
  8501. },
  8502. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8503. ownerEncryption) {
  8504. var hashData = new Uint8Array(password.length + 56);
  8505. hashData.set(password, 0);
  8506. hashData.set(ownerKeySalt, password.length);
  8507. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8508. var key = calculatePDF20Hash(password, hashData, userBytes);
  8509. var cipher = new AES256Cipher(key);
  8510. return cipher.decryptBlock(ownerEncryption,
  8511. false,
  8512. new Uint8Array(16));
  8513. },
  8514. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8515. userEncryption) {
  8516. var hashData = new Uint8Array(password.length + 8);
  8517. hashData.set(password, 0);
  8518. hashData.set(userKeySalt, password.length);
  8519. //key is the decryption key for the UE string
  8520. var key = calculatePDF20Hash(password, hashData, []);
  8521. var cipher = new AES256Cipher(key);
  8522. return cipher.decryptBlock(userEncryption,
  8523. false,
  8524. new Uint8Array(16));
  8525. }
  8526. };
  8527. return PDF20;
  8528. })();
  8529. var CipherTransform = (function CipherTransformClosure() {
  8530. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8531. this.stringCipherConstructor = stringCipherConstructor;
  8532. this.streamCipherConstructor = streamCipherConstructor;
  8533. }
  8534. CipherTransform.prototype = {
  8535. createStream: function CipherTransform_createStream(stream, length) {
  8536. var cipher = new this.streamCipherConstructor();
  8537. return new DecryptStream(stream, length,
  8538. function cipherTransformDecryptStream(data, finalize) {
  8539. return cipher.decryptBlock(data, finalize);
  8540. }
  8541. );
  8542. },
  8543. decryptString: function CipherTransform_decryptString(s) {
  8544. var cipher = new this.stringCipherConstructor();
  8545. var data = stringToBytes(s);
  8546. data = cipher.decryptBlock(data, true);
  8547. return bytesToString(data);
  8548. }
  8549. };
  8550. return CipherTransform;
  8551. })();
  8552. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8553. var defaultPasswordBytes = new Uint8Array([
  8554. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8555. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8556. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8557. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8558. function createEncryptionKey20(revision, password, ownerPassword,
  8559. ownerValidationSalt, ownerKeySalt, uBytes,
  8560. userPassword, userValidationSalt, userKeySalt,
  8561. ownerEncryption, userEncryption, perms) {
  8562. if (password) {
  8563. var passwordLength = Math.min(127, password.length);
  8564. password = password.subarray(0, passwordLength);
  8565. } else {
  8566. password = [];
  8567. }
  8568. var pdfAlgorithm;
  8569. if (revision === 6) {
  8570. pdfAlgorithm = new PDF20();
  8571. } else {
  8572. pdfAlgorithm = new PDF17();
  8573. }
  8574. if (pdfAlgorithm) {
  8575. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8576. userPassword)) {
  8577. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8578. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8579. uBytes,
  8580. ownerPassword)) {
  8581. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8582. ownerEncryption);
  8583. }
  8584. }
  8585. return null;
  8586. }
  8587. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8588. flags, revision, keyLength, encryptMetadata) {
  8589. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8590. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8591. if (password) {
  8592. n = Math.min(32, password.length);
  8593. for (; i < n; ++i) {
  8594. hashData[i] = password[i];
  8595. }
  8596. }
  8597. j = 0;
  8598. while (i < 32) {
  8599. hashData[i++] = defaultPasswordBytes[j++];
  8600. }
  8601. // as now the padded password in the hashData[0..i]
  8602. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8603. hashData[i++] = ownerPassword[j];
  8604. }
  8605. hashData[i++] = flags & 0xFF;
  8606. hashData[i++] = (flags >> 8) & 0xFF;
  8607. hashData[i++] = (flags >> 16) & 0xFF;
  8608. hashData[i++] = (flags >>> 24) & 0xFF;
  8609. for (j = 0, n = fileId.length; j < n; ++j) {
  8610. hashData[i++] = fileId[j];
  8611. }
  8612. if (revision >= 4 && !encryptMetadata) {
  8613. hashData[i++] = 0xFF;
  8614. hashData[i++] = 0xFF;
  8615. hashData[i++] = 0xFF;
  8616. hashData[i++] = 0xFF;
  8617. }
  8618. var hash = calculateMD5(hashData, 0, i);
  8619. var keyLengthInBytes = keyLength >> 3;
  8620. if (revision >= 3) {
  8621. for (j = 0; j < 50; ++j) {
  8622. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8623. }
  8624. }
  8625. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8626. var cipher, checkData;
  8627. if (revision >= 3) {
  8628. for (i = 0; i < 32; ++i) {
  8629. hashData[i] = defaultPasswordBytes[i];
  8630. }
  8631. for (j = 0, n = fileId.length; j < n; ++j) {
  8632. hashData[i++] = fileId[j];
  8633. }
  8634. cipher = new ARCFourCipher(encryptionKey);
  8635. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8636. n = encryptionKey.length;
  8637. var derivedKey = new Uint8Array(n), k;
  8638. for (j = 1; j <= 19; ++j) {
  8639. for (k = 0; k < n; ++k) {
  8640. derivedKey[k] = encryptionKey[k] ^ j;
  8641. }
  8642. cipher = new ARCFourCipher(derivedKey);
  8643. checkData = cipher.encryptBlock(checkData);
  8644. }
  8645. for (j = 0, n = checkData.length; j < n; ++j) {
  8646. if (userPassword[j] !== checkData[j]) {
  8647. return null;
  8648. }
  8649. }
  8650. } else {
  8651. cipher = new ARCFourCipher(encryptionKey);
  8652. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8653. for (j = 0, n = checkData.length; j < n; ++j) {
  8654. if (userPassword[j] !== checkData[j]) {
  8655. return null;
  8656. }
  8657. }
  8658. }
  8659. return encryptionKey;
  8660. }
  8661. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8662. var hashData = new Uint8Array(32), i = 0, j, n;
  8663. n = Math.min(32, password.length);
  8664. for (; i < n; ++i) {
  8665. hashData[i] = password[i];
  8666. }
  8667. j = 0;
  8668. while (i < 32) {
  8669. hashData[i++] = defaultPasswordBytes[j++];
  8670. }
  8671. var hash = calculateMD5(hashData, 0, i);
  8672. var keyLengthInBytes = keyLength >> 3;
  8673. if (revision >= 3) {
  8674. for (j = 0; j < 50; ++j) {
  8675. hash = calculateMD5(hash, 0, hash.length);
  8676. }
  8677. }
  8678. var cipher, userPassword;
  8679. if (revision >= 3) {
  8680. userPassword = ownerPassword;
  8681. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8682. for (j = 19; j >= 0; j--) {
  8683. for (k = 0; k < keyLengthInBytes; ++k) {
  8684. derivedKey[k] = hash[k] ^ j;
  8685. }
  8686. cipher = new ARCFourCipher(derivedKey);
  8687. userPassword = cipher.encryptBlock(userPassword);
  8688. }
  8689. } else {
  8690. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8691. userPassword = cipher.encryptBlock(ownerPassword);
  8692. }
  8693. return userPassword;
  8694. }
  8695. var identityName = Name.get('Identity');
  8696. function CipherTransformFactory(dict, fileId, password) {
  8697. var filter = dict.get('Filter');
  8698. if (!isName(filter) || filter.name !== 'Standard') {
  8699. error('unknown encryption method');
  8700. }
  8701. this.dict = dict;
  8702. var algorithm = dict.get('V');
  8703. if (!isInt(algorithm) ||
  8704. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8705. algorithm !== 5)) {
  8706. error('unsupported encryption algorithm');
  8707. }
  8708. this.algorithm = algorithm;
  8709. var keyLength = dict.get('Length') || 40;
  8710. if (!isInt(keyLength) ||
  8711. keyLength < 40 || (keyLength % 8) !== 0) {
  8712. error('invalid key length');
  8713. }
  8714. // prepare keys
  8715. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8716. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8717. var flags = dict.get('P');
  8718. var revision = dict.get('R');
  8719. // meaningful when V is 4 or 5
  8720. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8721. dict.get('EncryptMetadata') !== false);
  8722. this.encryptMetadata = encryptMetadata;
  8723. var fileIdBytes = stringToBytes(fileId);
  8724. var passwordBytes;
  8725. if (password) {
  8726. passwordBytes = stringToBytes(password);
  8727. }
  8728. var encryptionKey;
  8729. if (algorithm !== 5) {
  8730. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8731. ownerPassword, userPassword, flags,
  8732. revision, keyLength, encryptMetadata);
  8733. }
  8734. else {
  8735. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8736. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8737. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8738. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8739. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8740. var ownerEncryption = stringToBytes(dict.get('OE'));
  8741. var userEncryption = stringToBytes(dict.get('UE'));
  8742. var perms = stringToBytes(dict.get('Perms'));
  8743. encryptionKey =
  8744. createEncryptionKey20(revision, passwordBytes,
  8745. ownerPassword, ownerValidationSalt,
  8746. ownerKeySalt, uBytes,
  8747. userPassword, userValidationSalt,
  8748. userKeySalt, ownerEncryption,
  8749. userEncryption, perms);
  8750. }
  8751. if (!encryptionKey && !password) {
  8752. throw new PasswordException('No password given',
  8753. PasswordResponses.NEED_PASSWORD);
  8754. } else if (!encryptionKey && password) {
  8755. // Attempting use the password as an owner password
  8756. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8757. revision, keyLength);
  8758. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8759. ownerPassword, userPassword, flags,
  8760. revision, keyLength, encryptMetadata);
  8761. }
  8762. if (!encryptionKey) {
  8763. throw new PasswordException('Incorrect Password',
  8764. PasswordResponses.INCORRECT_PASSWORD);
  8765. }
  8766. this.encryptionKey = encryptionKey;
  8767. if (algorithm >= 4) {
  8768. this.cf = dict.get('CF');
  8769. this.stmf = dict.get('StmF') || identityName;
  8770. this.strf = dict.get('StrF') || identityName;
  8771. this.eff = dict.get('EFF') || this.strf;
  8772. }
  8773. }
  8774. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8775. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8776. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8777. key[i] = encryptionKey[i];
  8778. }
  8779. key[i++] = num & 0xFF;
  8780. key[i++] = (num >> 8) & 0xFF;
  8781. key[i++] = (num >> 16) & 0xFF;
  8782. key[i++] = gen & 0xFF;
  8783. key[i++] = (gen >> 8) & 0xFF;
  8784. if (isAes) {
  8785. key[i++] = 0x73;
  8786. key[i++] = 0x41;
  8787. key[i++] = 0x6C;
  8788. key[i++] = 0x54;
  8789. }
  8790. var hash = calculateMD5(key, 0, i);
  8791. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8792. }
  8793. function buildCipherConstructor(cf, name, num, gen, key) {
  8794. var cryptFilter = cf.get(name.name);
  8795. var cfm;
  8796. if (cryptFilter !== null && cryptFilter !== undefined) {
  8797. cfm = cryptFilter.get('CFM');
  8798. }
  8799. if (!cfm || cfm.name === 'None') {
  8800. return function cipherTransformFactoryBuildCipherConstructorNone() {
  8801. return new NullCipher();
  8802. };
  8803. }
  8804. if ('V2' === cfm.name) {
  8805. return function cipherTransformFactoryBuildCipherConstructorV2() {
  8806. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  8807. };
  8808. }
  8809. if ('AESV2' === cfm.name) {
  8810. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  8811. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  8812. };
  8813. }
  8814. if ('AESV3' === cfm.name) {
  8815. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8816. return new AES256Cipher(key);
  8817. };
  8818. }
  8819. error('Unknown crypto method');
  8820. }
  8821. CipherTransformFactory.prototype = {
  8822. createCipherTransform:
  8823. function CipherTransformFactory_createCipherTransform(num, gen) {
  8824. if (this.algorithm === 4 || this.algorithm === 5) {
  8825. return new CipherTransform(
  8826. buildCipherConstructor(this.cf, this.stmf,
  8827. num, gen, this.encryptionKey),
  8828. buildCipherConstructor(this.cf, this.strf,
  8829. num, gen, this.encryptionKey));
  8830. }
  8831. // algorithms 1 and 2
  8832. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8833. var cipherConstructor = function buildCipherCipherConstructor() {
  8834. return new ARCFourCipher(key);
  8835. };
  8836. return new CipherTransform(cipherConstructor, cipherConstructor);
  8837. }
  8838. };
  8839. return CipherTransformFactory;
  8840. })();
  8841. var PatternType = {
  8842. FUNCTION_BASED: 1,
  8843. AXIAL: 2,
  8844. RADIAL: 3,
  8845. FREE_FORM_MESH: 4,
  8846. LATTICE_FORM_MESH: 5,
  8847. COONS_PATCH_MESH: 6,
  8848. TENSOR_PATCH_MESH: 7
  8849. };
  8850. var Pattern = (function PatternClosure() {
  8851. // Constructor should define this.getPattern
  8852. function Pattern() {
  8853. error('should not call Pattern constructor');
  8854. }
  8855. Pattern.prototype = {
  8856. // Input: current Canvas context
  8857. // Output: the appropriate fillStyle or strokeStyle
  8858. getPattern: function Pattern_getPattern(ctx) {
  8859. error('Should not call Pattern.getStyle: ' + ctx);
  8860. }
  8861. };
  8862. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8863. res) {
  8864. var dict = isStream(shading) ? shading.dict : shading;
  8865. var type = dict.get('ShadingType');
  8866. try {
  8867. switch (type) {
  8868. case PatternType.AXIAL:
  8869. case PatternType.RADIAL:
  8870. // Both radial and axial shadings are handled by RadialAxial shading.
  8871. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8872. case PatternType.FREE_FORM_MESH:
  8873. case PatternType.LATTICE_FORM_MESH:
  8874. case PatternType.COONS_PATCH_MESH:
  8875. case PatternType.TENSOR_PATCH_MESH:
  8876. return new Shadings.Mesh(shading, matrix, xref, res);
  8877. default:
  8878. throw new Error('Unknown PatternType: ' + type);
  8879. }
  8880. } catch (ex) {
  8881. if (ex instanceof MissingDataException) {
  8882. throw ex;
  8883. }
  8884. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8885. warn(ex);
  8886. return new Shadings.Dummy();
  8887. }
  8888. };
  8889. return Pattern;
  8890. })();
  8891. var Shadings = {};
  8892. // A small number to offset the first/last color stops so we can insert ones to
  8893. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8894. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8895. // internally so we have to go bigger.
  8896. Shadings.SMALL_NUMBER = 1e-2;
  8897. // Radial and axial shading have very similar implementations
  8898. // If needed, the implementations can be broken into two classes
  8899. Shadings.RadialAxial = (function RadialAxialClosure() {
  8900. function RadialAxial(dict, matrix, xref, res) {
  8901. this.matrix = matrix;
  8902. this.coordsArr = dict.get('Coords');
  8903. this.shadingType = dict.get('ShadingType');
  8904. this.type = 'Pattern';
  8905. var cs = dict.get('ColorSpace', 'CS');
  8906. cs = ColorSpace.parse(cs, xref, res);
  8907. this.cs = cs;
  8908. var t0 = 0.0, t1 = 1.0;
  8909. if (dict.has('Domain')) {
  8910. var domainArr = dict.get('Domain');
  8911. t0 = domainArr[0];
  8912. t1 = domainArr[1];
  8913. }
  8914. var extendStart = false, extendEnd = false;
  8915. if (dict.has('Extend')) {
  8916. var extendArr = dict.get('Extend');
  8917. extendStart = extendArr[0];
  8918. extendEnd = extendArr[1];
  8919. }
  8920. if (this.shadingType === PatternType.RADIAL &&
  8921. (!extendStart || !extendEnd)) {
  8922. // Radial gradient only currently works if either circle is fully within
  8923. // the other circle.
  8924. var x1 = this.coordsArr[0];
  8925. var y1 = this.coordsArr[1];
  8926. var r1 = this.coordsArr[2];
  8927. var x2 = this.coordsArr[3];
  8928. var y2 = this.coordsArr[4];
  8929. var r2 = this.coordsArr[5];
  8930. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8931. if (r1 <= r2 + distance &&
  8932. r2 <= r1 + distance) {
  8933. warn('Unsupported radial gradient.');
  8934. }
  8935. }
  8936. this.extendStart = extendStart;
  8937. this.extendEnd = extendEnd;
  8938. var fnObj = dict.get('Function');
  8939. var fn = PDFFunction.parseArray(xref, fnObj);
  8940. // 10 samples seems good enough for now, but probably won't work
  8941. // if there are sharp color changes. Ideally, we would implement
  8942. // the spec faithfully and add lossless optimizations.
  8943. var diff = t1 - t0;
  8944. var step = diff / 10;
  8945. var colorStops = this.colorStops = [];
  8946. // Protect against bad domains so we don't end up in an infinte loop below.
  8947. if (t0 >= t1 || step <= 0) {
  8948. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8949. // now.
  8950. info('Bad shading domain.');
  8951. return;
  8952. }
  8953. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  8954. var rgbColor;
  8955. for (var i = t0; i <= t1; i += step) {
  8956. ratio[0] = i;
  8957. fn(ratio, 0, color, 0);
  8958. rgbColor = cs.getRgb(color, 0);
  8959. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8960. colorStops.push([(i - t0) / diff, cssColor]);
  8961. }
  8962. var background = 'transparent';
  8963. if (dict.has('Background')) {
  8964. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8965. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  8966. }
  8967. if (!extendStart) {
  8968. // Insert a color stop at the front and offset the first real color stop
  8969. // so it doesn't conflict with the one we insert.
  8970. colorStops.unshift([0, background]);
  8971. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8972. }
  8973. if (!extendEnd) {
  8974. // Same idea as above in extendStart but for the end.
  8975. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8976. colorStops.push([1, background]);
  8977. }
  8978. this.colorStops = colorStops;
  8979. }
  8980. RadialAxial.prototype = {
  8981. getIR: function RadialAxial_getIR() {
  8982. var coordsArr = this.coordsArr;
  8983. var shadingType = this.shadingType;
  8984. var type, p0, p1, r0, r1;
  8985. if (shadingType === PatternType.AXIAL) {
  8986. p0 = [coordsArr[0], coordsArr[1]];
  8987. p1 = [coordsArr[2], coordsArr[3]];
  8988. r0 = null;
  8989. r1 = null;
  8990. type = 'axial';
  8991. } else if (shadingType === PatternType.RADIAL) {
  8992. p0 = [coordsArr[0], coordsArr[1]];
  8993. p1 = [coordsArr[3], coordsArr[4]];
  8994. r0 = coordsArr[2];
  8995. r1 = coordsArr[5];
  8996. type = 'radial';
  8997. } else {
  8998. error('getPattern type unknown: ' + shadingType);
  8999. }
  9000. var matrix = this.matrix;
  9001. if (matrix) {
  9002. p0 = Util.applyTransform(p0, matrix);
  9003. p1 = Util.applyTransform(p1, matrix);
  9004. }
  9005. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9006. }
  9007. };
  9008. return RadialAxial;
  9009. })();
  9010. // All mesh shading. For now, they will be presented as set of the triangles
  9011. // to be drawn on the canvas and rgb color for each vertex.
  9012. Shadings.Mesh = (function MeshClosure() {
  9013. function MeshStreamReader(stream, context) {
  9014. this.stream = stream;
  9015. this.context = context;
  9016. this.buffer = 0;
  9017. this.bufferLength = 0;
  9018. var numComps = context.numComps;
  9019. this.tmpCompsBuf = new Float32Array(numComps);
  9020. var csNumComps = context.colorSpace;
  9021. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9022. this.tmpCompsBuf;
  9023. }
  9024. MeshStreamReader.prototype = {
  9025. get hasData() {
  9026. if (this.stream.end) {
  9027. return this.stream.pos < this.stream.end;
  9028. }
  9029. if (this.bufferLength > 0) {
  9030. return true;
  9031. }
  9032. var nextByte = this.stream.getByte();
  9033. if (nextByte < 0) {
  9034. return false;
  9035. }
  9036. this.buffer = nextByte;
  9037. this.bufferLength = 8;
  9038. return true;
  9039. },
  9040. readBits: function MeshStreamReader_readBits(n) {
  9041. var buffer = this.buffer;
  9042. var bufferLength = this.bufferLength;
  9043. if (n === 32) {
  9044. if (bufferLength === 0) {
  9045. return ((this.stream.getByte() << 24) |
  9046. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9047. this.stream.getByte()) >>> 0;
  9048. }
  9049. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9050. (this.stream.getByte() << 8) | this.stream.getByte();
  9051. var nextByte = this.stream.getByte();
  9052. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9053. return ((buffer << (8 - bufferLength)) |
  9054. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9055. }
  9056. if (n === 8 && bufferLength === 0) {
  9057. return this.stream.getByte();
  9058. }
  9059. while (bufferLength < n) {
  9060. buffer = (buffer << 8) | this.stream.getByte();
  9061. bufferLength += 8;
  9062. }
  9063. bufferLength -= n;
  9064. this.bufferLength = bufferLength;
  9065. this.buffer = buffer & ((1 << bufferLength) - 1);
  9066. return buffer >> bufferLength;
  9067. },
  9068. align: function MeshStreamReader_align() {
  9069. this.buffer = 0;
  9070. this.bufferLength = 0;
  9071. },
  9072. readFlag: function MeshStreamReader_readFlag() {
  9073. return this.readBits(this.context.bitsPerFlag);
  9074. },
  9075. readCoordinate: function MeshStreamReader_readCoordinate() {
  9076. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9077. var xi = this.readBits(bitsPerCoordinate);
  9078. var yi = this.readBits(bitsPerCoordinate);
  9079. var decode = this.context.decode;
  9080. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9081. 2.3283064365386963e-10; // 2 ^ -32
  9082. return [
  9083. xi * scale * (decode[1] - decode[0]) + decode[0],
  9084. yi * scale * (decode[3] - decode[2]) + decode[2]
  9085. ];
  9086. },
  9087. readComponents: function MeshStreamReader_readComponents() {
  9088. var numComps = this.context.numComps;
  9089. var bitsPerComponent = this.context.bitsPerComponent;
  9090. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9091. 2.3283064365386963e-10; // 2 ^ -32
  9092. var decode = this.context.decode;
  9093. var components = this.tmpCompsBuf;
  9094. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9095. var ci = this.readBits(bitsPerComponent);
  9096. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9097. }
  9098. var color = this.tmpCsCompsBuf;
  9099. if (this.context.colorFn) {
  9100. this.context.colorFn(components, 0, color, 0);
  9101. }
  9102. return this.context.colorSpace.getRgb(color, 0);
  9103. }
  9104. };
  9105. function decodeType4Shading(mesh, reader) {
  9106. var coords = mesh.coords;
  9107. var colors = mesh.colors;
  9108. var operators = [];
  9109. var ps = []; // not maintaining cs since that will match ps
  9110. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9111. while (reader.hasData) {
  9112. var f = reader.readFlag();
  9113. var coord = reader.readCoordinate();
  9114. var color = reader.readComponents();
  9115. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9116. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9117. switch (f) {
  9118. case 0:
  9119. verticesLeft = 3;
  9120. break;
  9121. case 1:
  9122. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9123. verticesLeft = 1;
  9124. break;
  9125. case 2:
  9126. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9127. verticesLeft = 1;
  9128. break;
  9129. }
  9130. operators.push(f);
  9131. }
  9132. ps.push(coords.length);
  9133. coords.push(coord);
  9134. colors.push(color);
  9135. verticesLeft--;
  9136. reader.align();
  9137. }
  9138. var psPacked = new Int32Array(ps);
  9139. mesh.figures.push({
  9140. type: 'triangles',
  9141. coords: psPacked,
  9142. colors: psPacked
  9143. });
  9144. }
  9145. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9146. var coords = mesh.coords;
  9147. var colors = mesh.colors;
  9148. var ps = []; // not maintaining cs since that will match ps
  9149. while (reader.hasData) {
  9150. var coord = reader.readCoordinate();
  9151. var color = reader.readComponents();
  9152. ps.push(coords.length);
  9153. coords.push(coord);
  9154. colors.push(color);
  9155. }
  9156. var psPacked = new Int32Array(ps);
  9157. mesh.figures.push({
  9158. type: 'lattice',
  9159. coords: psPacked,
  9160. colors: psPacked,
  9161. verticesPerRow: verticesPerRow
  9162. });
  9163. }
  9164. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9165. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9166. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9167. var getB = (function getBClosure() {
  9168. function buildB(count) {
  9169. var lut = [];
  9170. for (var i = 0; i <= count; i++) {
  9171. var t = i / count, t_ = 1 - t;
  9172. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9173. 3 * t * t * t_, t * t * t]));
  9174. }
  9175. return lut;
  9176. }
  9177. var cache = [];
  9178. return function getB(count) {
  9179. if (!cache[count]) {
  9180. cache[count] = buildB(count);
  9181. }
  9182. return cache[count];
  9183. };
  9184. })();
  9185. function buildFigureFromPatch(mesh, index) {
  9186. var figure = mesh.figures[index];
  9187. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9188. var coords = mesh.coords, colors = mesh.colors;
  9189. var pi = figure.coords;
  9190. var ci = figure.colors;
  9191. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9192. coords[pi[12]][0], coords[pi[15]][0]);
  9193. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9194. coords[pi[12]][1], coords[pi[15]][1]);
  9195. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9196. coords[pi[12]][0], coords[pi[15]][0]);
  9197. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9198. coords[pi[12]][1], coords[pi[15]][1]);
  9199. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9200. (mesh.bounds[2] - mesh.bounds[0]));
  9201. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9202. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9203. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9204. (mesh.bounds[3] - mesh.bounds[1]));
  9205. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9206. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9207. var verticesPerRow = splitXBy + 1;
  9208. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9209. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9210. var k = 0;
  9211. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9212. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9213. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9214. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9215. for (var row = 0; row <= splitYBy; row++) {
  9216. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9217. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9218. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9219. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9220. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9221. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9222. for (var col = 0; col <= splitXBy; col++, k++) {
  9223. if ((row === 0 || row === splitYBy) &&
  9224. (col === 0 || col === splitXBy)) {
  9225. continue;
  9226. }
  9227. var x = 0, y = 0;
  9228. var q = 0;
  9229. for (var i = 0; i <= 3; i++) {
  9230. for (var j = 0; j <= 3; j++, q++) {
  9231. var m = bRow[row][i] * bCol[col][j];
  9232. x += coords[pi[q]][0] * m;
  9233. y += coords[pi[q]][1] * m;
  9234. }
  9235. }
  9236. figureCoords[k] = coords.length;
  9237. coords.push([x, y]);
  9238. figureColors[k] = colors.length;
  9239. var newColor = new Uint8Array(3);
  9240. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9241. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9242. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9243. colors.push(newColor);
  9244. }
  9245. }
  9246. figureCoords[0] = pi[0];
  9247. figureColors[0] = ci[0];
  9248. figureCoords[splitXBy] = pi[3];
  9249. figureColors[splitXBy] = ci[1];
  9250. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9251. figureColors[verticesPerRow * splitYBy] = ci[2];
  9252. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9253. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9254. mesh.figures[index] = {
  9255. type: 'lattice',
  9256. coords: figureCoords,
  9257. colors: figureColors,
  9258. verticesPerRow: verticesPerRow
  9259. };
  9260. }
  9261. function decodeType6Shading(mesh, reader) {
  9262. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9263. var coords = mesh.coords;
  9264. var colors = mesh.colors;
  9265. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9266. var cs = new Int32Array(4); // c00, c30, c03, c33
  9267. while (reader.hasData) {
  9268. var f = reader.readFlag();
  9269. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9270. var i, ii;
  9271. var pi = coords.length;
  9272. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9273. coords.push(reader.readCoordinate());
  9274. }
  9275. var ci = colors.length;
  9276. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9277. colors.push(reader.readComponents());
  9278. }
  9279. var tmp1, tmp2, tmp3, tmp4;
  9280. switch (f) {
  9281. case 0:
  9282. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9283. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9284. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9285. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9286. cs[2] = ci + 1; cs[3] = ci + 2;
  9287. cs[0] = ci; cs[1] = ci + 3;
  9288. break;
  9289. case 1:
  9290. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9291. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9292. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9293. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9294. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9295. tmp1 = cs[2]; tmp2 = cs[3];
  9296. cs[2] = ci + 1; cs[3] = ci;
  9297. cs[0] = tmp1; cs[1] = tmp2;
  9298. break;
  9299. case 2:
  9300. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9301. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9302. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9303. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9304. cs[2] = cs[3]; cs[3] = ci + 1;
  9305. cs[0] = cs[1]; cs[1] = ci;
  9306. break;
  9307. case 3:
  9308. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9309. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9310. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9311. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9312. cs[2] = cs[0]; cs[3] = cs[1];
  9313. cs[0] = ci; cs[1] = ci + 1;
  9314. break;
  9315. }
  9316. // set p11, p12, p21, p22
  9317. ps[5] = coords.length;
  9318. coords.push([
  9319. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9320. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9321. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9322. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9323. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9324. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9325. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9326. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9327. ]);
  9328. ps[6] = coords.length;
  9329. coords.push([
  9330. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9331. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9332. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9333. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9334. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9335. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9336. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9337. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9338. ]);
  9339. ps[9] = coords.length;
  9340. coords.push([
  9341. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9342. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9343. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9344. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9345. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9346. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9347. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9348. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9349. ]);
  9350. ps[10] = coords.length;
  9351. coords.push([
  9352. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9353. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9354. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9355. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9356. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9357. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9358. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9359. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9360. ]);
  9361. mesh.figures.push({
  9362. type: 'patch',
  9363. coords: new Int32Array(ps), // making copies of ps and cs
  9364. colors: new Int32Array(cs)
  9365. });
  9366. }
  9367. }
  9368. function decodeType7Shading(mesh, reader) {
  9369. var coords = mesh.coords;
  9370. var colors = mesh.colors;
  9371. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9372. var cs = new Int32Array(4); // c00, c30, c03, c33
  9373. while (reader.hasData) {
  9374. var f = reader.readFlag();
  9375. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9376. var i, ii;
  9377. var pi = coords.length;
  9378. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9379. coords.push(reader.readCoordinate());
  9380. }
  9381. var ci = colors.length;
  9382. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9383. colors.push(reader.readComponents());
  9384. }
  9385. var tmp1, tmp2, tmp3, tmp4;
  9386. switch (f) {
  9387. case 0:
  9388. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9389. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9390. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9391. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9392. cs[2] = ci + 1; cs[3] = ci + 2;
  9393. cs[0] = ci; cs[1] = ci + 3;
  9394. break;
  9395. case 1:
  9396. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9397. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9398. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9399. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9400. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9401. tmp1 = cs[2]; tmp2 = cs[3];
  9402. cs[2] = ci + 1; cs[3] = ci;
  9403. cs[0] = tmp1; cs[1] = tmp2;
  9404. break;
  9405. case 2:
  9406. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9407. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9408. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9409. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9410. cs[2] = cs[3]; cs[3] = ci + 1;
  9411. cs[0] = cs[1]; cs[1] = ci;
  9412. break;
  9413. case 3:
  9414. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9415. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9416. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9417. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9418. cs[2] = cs[0]; cs[3] = cs[1];
  9419. cs[0] = ci; cs[1] = ci + 1;
  9420. break;
  9421. }
  9422. mesh.figures.push({
  9423. type: 'patch',
  9424. coords: new Int32Array(ps), // making copies of ps and cs
  9425. colors: new Int32Array(cs)
  9426. });
  9427. }
  9428. }
  9429. function updateBounds(mesh) {
  9430. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9431. maxX = minX, maxY = minY;
  9432. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9433. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9434. minX = minX > x ? x : minX;
  9435. minY = minY > y ? y : minY;
  9436. maxX = maxX < x ? x : maxX;
  9437. maxY = maxY < y ? y : maxY;
  9438. }
  9439. mesh.bounds = [minX, minY, maxX, maxY];
  9440. }
  9441. function packData(mesh) {
  9442. var i, ii, j, jj;
  9443. var coords = mesh.coords;
  9444. var coordsPacked = new Float32Array(coords.length * 2);
  9445. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9446. var xy = coords[i];
  9447. coordsPacked[j++] = xy[0];
  9448. coordsPacked[j++] = xy[1];
  9449. }
  9450. mesh.coords = coordsPacked;
  9451. var colors = mesh.colors;
  9452. var colorsPacked = new Uint8Array(colors.length * 3);
  9453. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9454. var c = colors[i];
  9455. colorsPacked[j++] = c[0];
  9456. colorsPacked[j++] = c[1];
  9457. colorsPacked[j++] = c[2];
  9458. }
  9459. mesh.colors = colorsPacked;
  9460. var figures = mesh.figures;
  9461. for (i = 0, ii = figures.length; i < ii; i++) {
  9462. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9463. for (j = 0, jj = ps.length; j < jj; j++) {
  9464. ps[j] *= 2;
  9465. cs[j] *= 3;
  9466. }
  9467. }
  9468. }
  9469. function Mesh(stream, matrix, xref, res) {
  9470. assert(isStream(stream), 'Mesh data is not a stream');
  9471. var dict = stream.dict;
  9472. this.matrix = matrix;
  9473. this.shadingType = dict.get('ShadingType');
  9474. this.type = 'Pattern';
  9475. this.bbox = dict.get('BBox');
  9476. var cs = dict.get('ColorSpace', 'CS');
  9477. cs = ColorSpace.parse(cs, xref, res);
  9478. this.cs = cs;
  9479. this.background = dict.has('Background') ?
  9480. cs.getRgb(dict.get('Background'), 0) : null;
  9481. var fnObj = dict.get('Function');
  9482. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9483. this.coords = [];
  9484. this.colors = [];
  9485. this.figures = [];
  9486. var decodeContext = {
  9487. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9488. bitsPerComponent: dict.get('BitsPerComponent'),
  9489. bitsPerFlag: dict.get('BitsPerFlag'),
  9490. decode: dict.get('Decode'),
  9491. colorFn: fn,
  9492. colorSpace: cs,
  9493. numComps: fn ? 1 : cs.numComps
  9494. };
  9495. var reader = new MeshStreamReader(stream, decodeContext);
  9496. var patchMesh = false;
  9497. switch (this.shadingType) {
  9498. case PatternType.FREE_FORM_MESH:
  9499. decodeType4Shading(this, reader);
  9500. break;
  9501. case PatternType.LATTICE_FORM_MESH:
  9502. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9503. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9504. decodeType5Shading(this, reader, verticesPerRow);
  9505. break;
  9506. case PatternType.COONS_PATCH_MESH:
  9507. decodeType6Shading(this, reader);
  9508. patchMesh = true;
  9509. break;
  9510. case PatternType.TENSOR_PATCH_MESH:
  9511. decodeType7Shading(this, reader);
  9512. patchMesh = true;
  9513. break;
  9514. default:
  9515. error('Unsupported mesh type.');
  9516. break;
  9517. }
  9518. if (patchMesh) {
  9519. // dirty bounds calculation for determining, how dense shall be triangles
  9520. updateBounds(this);
  9521. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9522. buildFigureFromPatch(this, i);
  9523. }
  9524. }
  9525. // calculate bounds
  9526. updateBounds(this);
  9527. packData(this);
  9528. }
  9529. Mesh.prototype = {
  9530. getIR: function Mesh_getIR() {
  9531. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9532. this.bounds, this.matrix, this.bbox, this.background];
  9533. }
  9534. };
  9535. return Mesh;
  9536. })();
  9537. Shadings.Dummy = (function DummyClosure() {
  9538. function Dummy() {
  9539. this.type = 'Pattern';
  9540. }
  9541. Dummy.prototype = {
  9542. getIR: function Dummy_getIR() {
  9543. return ['Dummy'];
  9544. }
  9545. };
  9546. return Dummy;
  9547. })();
  9548. function getTilingPatternIR(operatorList, dict, args) {
  9549. var matrix = dict.get('Matrix');
  9550. var bbox = dict.get('BBox');
  9551. var xstep = dict.get('XStep');
  9552. var ystep = dict.get('YStep');
  9553. var paintType = dict.get('PaintType');
  9554. var tilingType = dict.get('TilingType');
  9555. return [
  9556. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9557. paintType, tilingType
  9558. ];
  9559. }
  9560. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9561. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9562. uniquePrefix, idCounters, fontCache) {
  9563. this.pdfManager = pdfManager;
  9564. this.xref = xref;
  9565. this.handler = handler;
  9566. this.pageIndex = pageIndex;
  9567. this.uniquePrefix = uniquePrefix;
  9568. this.idCounters = idCounters;
  9569. this.fontCache = fontCache;
  9570. }
  9571. // Trying to minimize Date.now() usage and check every 100 time
  9572. var TIME_SLOT_DURATION_MS = 20;
  9573. var CHECK_TIME_EVERY = 100;
  9574. function TimeSlotManager() {
  9575. this.reset();
  9576. }
  9577. TimeSlotManager.prototype = {
  9578. check: function TimeSlotManager_check() {
  9579. if (++this.checked < CHECK_TIME_EVERY) {
  9580. return false;
  9581. }
  9582. this.checked = 0;
  9583. return this.endTime <= Date.now();
  9584. },
  9585. reset: function TimeSlotManager_reset() {
  9586. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9587. this.checked = 0;
  9588. }
  9589. };
  9590. var deferred = Promise.resolve();
  9591. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9592. PartialEvaluator.prototype = {
  9593. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9594. if (!isDict(resources)) {
  9595. return false;
  9596. }
  9597. var processed = Object.create(null);
  9598. if (resources.objId) {
  9599. processed[resources.objId] = true;
  9600. }
  9601. var nodes = [resources];
  9602. while (nodes.length) {
  9603. var key;
  9604. var node = nodes.shift();
  9605. // First check the current resources for blend modes.
  9606. var graphicStates = node.get('ExtGState');
  9607. if (isDict(graphicStates)) {
  9608. graphicStates = graphicStates.getAll();
  9609. for (key in graphicStates) {
  9610. var graphicState = graphicStates[key];
  9611. var bm = graphicState['BM'];
  9612. if (isName(bm) && bm.name !== 'Normal') {
  9613. return true;
  9614. }
  9615. }
  9616. }
  9617. // Descend into the XObjects to look for more resources and blend modes.
  9618. var xObjects = node.get('XObject');
  9619. if (!isDict(xObjects)) {
  9620. continue;
  9621. }
  9622. xObjects = xObjects.getAll();
  9623. for (key in xObjects) {
  9624. var xObject = xObjects[key];
  9625. if (!isStream(xObject)) {
  9626. continue;
  9627. }
  9628. if (xObject.dict.objId) {
  9629. if (processed[xObject.dict.objId]) {
  9630. // stream has objId and is processed already
  9631. continue;
  9632. }
  9633. processed[xObject.dict.objId] = true;
  9634. }
  9635. var xResources = xObject.dict.get('Resources');
  9636. // Checking objId to detect an infinite loop.
  9637. if (isDict(xResources) &&
  9638. (!xResources.objId || !processed[xResources.objId])) {
  9639. nodes.push(xResources);
  9640. if (xResources.objId) {
  9641. processed[xResources.objId] = true;
  9642. }
  9643. }
  9644. }
  9645. }
  9646. return false;
  9647. },
  9648. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9649. xobj, smask,
  9650. operatorList,
  9651. initialState) {
  9652. var matrix = xobj.dict.get('Matrix');
  9653. var bbox = xobj.dict.get('BBox');
  9654. var group = xobj.dict.get('Group');
  9655. if (group) {
  9656. var groupOptions = {
  9657. matrix: matrix,
  9658. bbox: bbox,
  9659. smask: smask,
  9660. isolated: false,
  9661. knockout: false
  9662. };
  9663. var groupSubtype = group.get('S');
  9664. var colorSpace;
  9665. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9666. groupOptions.isolated = (group.get('I') || false);
  9667. groupOptions.knockout = (group.get('K') || false);
  9668. colorSpace = (group.has('CS') ?
  9669. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9670. }
  9671. if (smask && smask.backdrop) {
  9672. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9673. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9674. }
  9675. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9676. }
  9677. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9678. return this.getOperatorList(xobj,
  9679. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9680. then(function () {
  9681. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9682. if (group) {
  9683. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9684. }
  9685. });
  9686. },
  9687. buildPaintImageXObject:
  9688. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9689. inline, operatorList,
  9690. cacheKey, imageCache) {
  9691. var self = this;
  9692. var dict = image.dict;
  9693. var w = dict.get('Width', 'W');
  9694. var h = dict.get('Height', 'H');
  9695. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9696. warn('Image dimensions are missing, or not numbers.');
  9697. return;
  9698. }
  9699. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9700. warn('Image exceeded maximum allowed size and was removed.');
  9701. return;
  9702. }
  9703. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9704. var imgData, args;
  9705. if (imageMask) {
  9706. // This depends on a tmpCanvas being filled with the
  9707. // current fillStyle, such that processing the pixel
  9708. // data can't be done here. Instead of creating a
  9709. // complete PDFImage, only read the information needed
  9710. // for later.
  9711. var width = dict.get('Width', 'W');
  9712. var height = dict.get('Height', 'H');
  9713. var bitStrideLength = (width + 7) >> 3;
  9714. var imgArray = image.getBytes(bitStrideLength * height);
  9715. var decode = dict.get('Decode', 'D');
  9716. var inverseDecode = (!!decode && decode[0] > 0);
  9717. imgData = PDFImage.createMask(imgArray, width, height,
  9718. image instanceof DecodeStream,
  9719. inverseDecode);
  9720. imgData.cached = true;
  9721. args = [imgData];
  9722. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9723. if (cacheKey) {
  9724. imageCache[cacheKey] = {
  9725. fn: OPS.paintImageMaskXObject,
  9726. args: args
  9727. };
  9728. }
  9729. return;
  9730. }
  9731. var softMask = (dict.get('SMask', 'SM') || false);
  9732. var mask = (dict.get('Mask') || false);
  9733. var SMALL_IMAGE_DIMENSIONS = 200;
  9734. // Inlining small images into the queue as RGB data
  9735. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9736. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9737. var imageObj = new PDFImage(this.xref, resources, image,
  9738. inline, null, null);
  9739. // We force the use of RGBA_32BPP images here, because we can't handle
  9740. // any other kind.
  9741. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9742. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9743. return;
  9744. }
  9745. // If there is no imageMask, create the PDFImage and a lot
  9746. // of image processing can be done here.
  9747. var uniquePrefix = (this.uniquePrefix || '');
  9748. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9749. operatorList.addDependency(objId);
  9750. args = [objId, w, h];
  9751. if (!softMask && !mask && image instanceof JpegStream &&
  9752. image.isNativelySupported(this.xref, resources)) {
  9753. // These JPEGs don't need any more processing so we can just send it.
  9754. operatorList.addOp(OPS.paintJpegXObject, args);
  9755. this.handler.send('obj',
  9756. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9757. return;
  9758. }
  9759. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9760. then(function(imageObj) {
  9761. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9762. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9763. [imgData.data.buffer]);
  9764. }).then(undefined, function (reason) {
  9765. warn('Unable to decode image: ' + reason);
  9766. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9767. });
  9768. operatorList.addOp(OPS.paintImageXObject, args);
  9769. if (cacheKey) {
  9770. imageCache[cacheKey] = {
  9771. fn: OPS.paintImageXObject,
  9772. args: args
  9773. };
  9774. }
  9775. },
  9776. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9777. operatorList,
  9778. stateManager) {
  9779. var smaskContent = smask.get('G');
  9780. var smaskOptions = {
  9781. subtype: smask.get('S').name,
  9782. backdrop: smask.get('BC')
  9783. };
  9784. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9785. operatorList, stateManager.state.clone());
  9786. },
  9787. handleTilingType:
  9788. function PartialEvaluator_handleTilingType(fn, args, resources,
  9789. pattern, patternDict,
  9790. operatorList) {
  9791. // Create an IR of the pattern code.
  9792. var tilingOpList = new OperatorList();
  9793. return this.getOperatorList(pattern,
  9794. (patternDict.get('Resources') || resources), tilingOpList).
  9795. then(function () {
  9796. // Add the dependencies to the parent operator list so they are
  9797. // resolved before sub operator list is executed synchronously.
  9798. operatorList.addDependencies(tilingOpList.dependencies);
  9799. operatorList.addOp(fn, getTilingPatternIR({
  9800. fnArray: tilingOpList.fnArray,
  9801. argsArray: tilingOpList.argsArray
  9802. }, patternDict, args));
  9803. });
  9804. },
  9805. handleSetFont:
  9806. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9807. operatorList, state) {
  9808. // TODO(mack): Not needed?
  9809. var fontName;
  9810. if (fontArgs) {
  9811. fontArgs = fontArgs.slice();
  9812. fontName = fontArgs[0].name;
  9813. }
  9814. var self = this;
  9815. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9816. function (translated) {
  9817. if (!translated.font.isType3Font) {
  9818. return translated;
  9819. }
  9820. return translated.loadType3Data(self, resources, operatorList).then(
  9821. function () {
  9822. return translated;
  9823. });
  9824. }).then(function (translated) {
  9825. state.font = translated.font;
  9826. translated.send(self.handler);
  9827. return translated.loadedName;
  9828. });
  9829. },
  9830. handleText: function PartialEvaluator_handleText(chars, state) {
  9831. var font = state.font;
  9832. var glyphs = font.charsToGlyphs(chars);
  9833. var isAddToPathSet = !!(state.textRenderingMode &
  9834. TextRenderingMode.ADD_TO_PATH_FLAG);
  9835. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9836. var buildPath = function (fontChar) {
  9837. if (!font.renderer.hasBuiltPath(fontChar)) {
  9838. var path = font.renderer.getPathJs(fontChar);
  9839. this.handler.send('commonobj', [
  9840. font.loadedName + '_path_' + fontChar,
  9841. 'FontPath',
  9842. path
  9843. ]);
  9844. }
  9845. }.bind(this);
  9846. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9847. var glyph = glyphs[i];
  9848. if (glyph === null) {
  9849. continue;
  9850. }
  9851. buildPath(glyph.fontChar);
  9852. // If the glyph has an accent we need to build a path for its
  9853. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9854. var accent = glyph.accent;
  9855. if (accent && accent.fontChar) {
  9856. buildPath(accent.fontChar);
  9857. }
  9858. }
  9859. }
  9860. return glyphs;
  9861. },
  9862. setGState: function PartialEvaluator_setGState(resources, gState,
  9863. operatorList, xref,
  9864. stateManager) {
  9865. // This array holds the converted/processed state data.
  9866. var gStateObj = [];
  9867. var gStateMap = gState.map;
  9868. var self = this;
  9869. var promise = Promise.resolve();
  9870. for (var key in gStateMap) {
  9871. var value = gStateMap[key];
  9872. switch (key) {
  9873. case 'Type':
  9874. break;
  9875. case 'LW':
  9876. case 'LC':
  9877. case 'LJ':
  9878. case 'ML':
  9879. case 'D':
  9880. case 'RI':
  9881. case 'FL':
  9882. case 'CA':
  9883. case 'ca':
  9884. gStateObj.push([key, value]);
  9885. break;
  9886. case 'Font':
  9887. promise = promise.then(function () {
  9888. return self.handleSetFont(resources, null, value[0],
  9889. operatorList, stateManager.state).
  9890. then(function (loadedName) {
  9891. operatorList.addDependency(loadedName);
  9892. gStateObj.push([key, [loadedName, value[1]]]);
  9893. });
  9894. });
  9895. break;
  9896. case 'BM':
  9897. gStateObj.push([key, value]);
  9898. break;
  9899. case 'SMask':
  9900. if (isName(value) && value.name === 'None') {
  9901. gStateObj.push([key, false]);
  9902. break;
  9903. }
  9904. var dict = xref.fetchIfRef(value);
  9905. if (isDict(dict)) {
  9906. promise = promise.then(function () {
  9907. return self.handleSMask(dict, resources, operatorList,
  9908. stateManager);
  9909. });
  9910. gStateObj.push([key, true]);
  9911. } else {
  9912. warn('Unsupported SMask type');
  9913. }
  9914. break;
  9915. // Only generate info log messages for the following since
  9916. // they are unlikely to have a big impact on the rendering.
  9917. case 'OP':
  9918. case 'op':
  9919. case 'OPM':
  9920. case 'BG':
  9921. case 'BG2':
  9922. case 'UCR':
  9923. case 'UCR2':
  9924. case 'TR':
  9925. case 'TR2':
  9926. case 'HT':
  9927. case 'SM':
  9928. case 'SA':
  9929. case 'AIS':
  9930. case 'TK':
  9931. // TODO implement these operators.
  9932. info('graphic state operator ' + key);
  9933. break;
  9934. default:
  9935. info('Unknown graphic state operator ' + key);
  9936. break;
  9937. }
  9938. }
  9939. return promise.then(function () {
  9940. if (gStateObj.length >= 0) {
  9941. operatorList.addOp(OPS.setGState, [gStateObj]);
  9942. }
  9943. });
  9944. },
  9945. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9946. resources) {
  9947. function errorFont() {
  9948. return Promise.resolve(new TranslatedFont('g_font_error',
  9949. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9950. }
  9951. var fontRef;
  9952. if (font) { // Loading by ref.
  9953. assert(isRef(font));
  9954. fontRef = font;
  9955. } else { // Loading by name.
  9956. var fontRes = resources.get('Font');
  9957. if (fontRes) {
  9958. fontRef = fontRes.getRaw(fontName);
  9959. } else {
  9960. warn('fontRes not available');
  9961. return errorFont();
  9962. }
  9963. }
  9964. if (!fontRef) {
  9965. warn('fontRef not available');
  9966. return errorFont();
  9967. }
  9968. if (this.fontCache.has(fontRef)) {
  9969. return this.fontCache.get(fontRef);
  9970. }
  9971. font = xref.fetchIfRef(fontRef);
  9972. if (!isDict(font)) {
  9973. return errorFont();
  9974. }
  9975. // We are holding font.translated references just for fontRef that are not
  9976. // dictionaries (Dict). See explanation below.
  9977. if (font.translated) {
  9978. return font.translated;
  9979. }
  9980. var fontCapability = createPromiseCapability();
  9981. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9982. var descriptor = preEvaluatedFont.descriptor;
  9983. var fontID = fontRef.num + '_' + fontRef.gen;
  9984. if (isDict(descriptor)) {
  9985. if (!descriptor.fontAliases) {
  9986. descriptor.fontAliases = Object.create(null);
  9987. }
  9988. var fontAliases = descriptor.fontAliases;
  9989. var hash = preEvaluatedFont.hash;
  9990. if (fontAliases[hash]) {
  9991. var aliasFontRef = fontAliases[hash].aliasRef;
  9992. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9993. this.fontCache.putAlias(fontRef, aliasFontRef);
  9994. return this.fontCache.get(fontRef);
  9995. }
  9996. }
  9997. if (!fontAliases[hash]) {
  9998. fontAliases[hash] = {
  9999. fontID: Font.getFontID()
  10000. };
  10001. }
  10002. fontAliases[hash].aliasRef = fontRef;
  10003. fontID = fontAliases[hash].fontID;
  10004. }
  10005. // Workaround for bad PDF generators that don't reference fonts
  10006. // properly, i.e. by not using an object identifier.
  10007. // Check if the fontRef is a Dict (as opposed to a standard object),
  10008. // in which case we don't cache the font and instead reference it by
  10009. // fontName in font.loadedName below.
  10010. var fontRefIsDict = isDict(fontRef);
  10011. if (!fontRefIsDict) {
  10012. this.fontCache.put(fontRef, fontCapability.promise);
  10013. }
  10014. // Keep track of each font we translated so the caller can
  10015. // load them asynchronously before calling display on a page.
  10016. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10017. fontName.replace(/\W/g, '') : fontID);
  10018. font.translated = fontCapability.promise;
  10019. // TODO move promises into translate font
  10020. var translatedPromise;
  10021. try {
  10022. translatedPromise = Promise.resolve(
  10023. this.translateFont(preEvaluatedFont, xref));
  10024. } catch (e) {
  10025. translatedPromise = Promise.reject(e);
  10026. }
  10027. translatedPromise.then(function (translatedFont) {
  10028. if (translatedFont.fontType !== undefined) {
  10029. var xrefFontStats = xref.stats.fontTypes;
  10030. xrefFontStats[translatedFont.fontType] = true;
  10031. }
  10032. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10033. translatedFont, font));
  10034. }, function (reason) {
  10035. // TODO fontCapability.reject?
  10036. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10037. try {
  10038. // error, but it's still nice to have font type reported
  10039. var descriptor = preEvaluatedFont.descriptor;
  10040. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10041. var subtype = fontFile3 && fontFile3.get('Subtype');
  10042. var fontType = getFontType(preEvaluatedFont.type,
  10043. subtype && subtype.name);
  10044. var xrefFontStats = xref.stats.fontTypes;
  10045. xrefFontStats[fontType] = true;
  10046. } catch (ex) { }
  10047. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10048. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10049. font));
  10050. });
  10051. return fontCapability.promise;
  10052. },
  10053. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10054. var lastIndex = operatorList.length - 1;
  10055. if (!args) {
  10056. args = [];
  10057. }
  10058. if (lastIndex < 0 ||
  10059. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10060. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10061. } else {
  10062. var opArgs = operatorList.argsArray[lastIndex];
  10063. opArgs[0].push(fn);
  10064. Array.prototype.push.apply(opArgs[1], args);
  10065. }
  10066. },
  10067. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10068. cs, patterns, resources, xref) {
  10069. // compile tiling patterns
  10070. var patternName = args[args.length - 1];
  10071. // SCN/scn applies patterns along with normal colors
  10072. var pattern;
  10073. if (isName(patternName) &&
  10074. (pattern = patterns.get(patternName.name))) {
  10075. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10076. var typeNum = dict.get('PatternType');
  10077. if (typeNum === TILING_PATTERN) {
  10078. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10079. return this.handleTilingType(fn, color, resources, pattern,
  10080. dict, operatorList);
  10081. } else if (typeNum === SHADING_PATTERN) {
  10082. var shading = dict.get('Shading');
  10083. var matrix = dict.get('Matrix');
  10084. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10085. operatorList.addOp(fn, pattern.getIR());
  10086. return Promise.resolve();
  10087. } else {
  10088. return Promise.reject('Unknown PatternType: ' + typeNum);
  10089. }
  10090. }
  10091. // TODO shall we fail here?
  10092. operatorList.addOp(fn, args);
  10093. return Promise.resolve();
  10094. },
  10095. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10096. resources,
  10097. operatorList,
  10098. initialState) {
  10099. var self = this;
  10100. var xref = this.xref;
  10101. var imageCache = {};
  10102. assert(operatorList);
  10103. resources = (resources || Dict.empty);
  10104. var xobjs = (resources.get('XObject') || Dict.empty);
  10105. var patterns = (resources.get('Pattern') || Dict.empty);
  10106. var stateManager = new StateManager(initialState || new EvalState());
  10107. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10108. var timeSlotManager = new TimeSlotManager();
  10109. return new Promise(function next(resolve, reject) {
  10110. timeSlotManager.reset();
  10111. var stop, operation = {}, i, ii, cs;
  10112. while (!(stop = timeSlotManager.check())) {
  10113. // The arguments parsed by read() are used beyond this loop, so we
  10114. // cannot reuse the same array on each iteration. Therefore we pass
  10115. // in |null| as the initial value (see the comment on
  10116. // EvaluatorPreprocessor_read() for why).
  10117. operation.args = null;
  10118. if (!(preprocessor.read(operation))) {
  10119. break;
  10120. }
  10121. var args = operation.args;
  10122. var fn = operation.fn;
  10123. switch (fn | 0) {
  10124. case OPS.paintXObject:
  10125. if (args[0].code) {
  10126. break;
  10127. }
  10128. // eagerly compile XForm objects
  10129. var name = args[0].name;
  10130. if (imageCache[name] !== undefined) {
  10131. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10132. args = null;
  10133. continue;
  10134. }
  10135. var xobj = xobjs.get(name);
  10136. if (xobj) {
  10137. assert(isStream(xobj), 'XObject should be a stream');
  10138. var type = xobj.dict.get('Subtype');
  10139. assert(isName(type),
  10140. 'XObject should have a Name subtype');
  10141. if (type.name === 'Form') {
  10142. stateManager.save();
  10143. return self.buildFormXObject(resources, xobj, null,
  10144. operatorList,
  10145. stateManager.state.clone()).
  10146. then(function () {
  10147. stateManager.restore();
  10148. next(resolve, reject);
  10149. }, reject);
  10150. } else if (type.name === 'Image') {
  10151. self.buildPaintImageXObject(resources, xobj, false,
  10152. operatorList, name, imageCache);
  10153. args = null;
  10154. continue;
  10155. } else if (type.name === 'PS') {
  10156. // PostScript XObjects are unused when viewing documents.
  10157. // See section 4.7.1 of Adobe's PDF reference.
  10158. info('Ignored XObject subtype PS');
  10159. continue;
  10160. } else {
  10161. error('Unhandled XObject subtype ' + type.name);
  10162. }
  10163. }
  10164. break;
  10165. case OPS.setFont:
  10166. var fontSize = args[1];
  10167. // eagerly collect all fonts
  10168. return self.handleSetFont(resources, args, null,
  10169. operatorList, stateManager.state).
  10170. then(function (loadedName) {
  10171. operatorList.addDependency(loadedName);
  10172. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10173. next(resolve, reject);
  10174. }, reject);
  10175. case OPS.endInlineImage:
  10176. var cacheKey = args[0].cacheKey;
  10177. if (cacheKey) {
  10178. var cacheEntry = imageCache[cacheKey];
  10179. if (cacheEntry !== undefined) {
  10180. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10181. args = null;
  10182. continue;
  10183. }
  10184. }
  10185. self.buildPaintImageXObject(resources, args[0], true,
  10186. operatorList, cacheKey, imageCache);
  10187. args = null;
  10188. continue;
  10189. case OPS.showText:
  10190. args[0] = self.handleText(args[0], stateManager.state);
  10191. break;
  10192. case OPS.showSpacedText:
  10193. var arr = args[0];
  10194. var combinedGlyphs = [];
  10195. var arrLength = arr.length;
  10196. for (i = 0; i < arrLength; ++i) {
  10197. var arrItem = arr[i];
  10198. if (isString(arrItem)) {
  10199. Array.prototype.push.apply(combinedGlyphs,
  10200. self.handleText(arrItem, stateManager.state));
  10201. } else if (isNum(arrItem)) {
  10202. combinedGlyphs.push(arrItem);
  10203. }
  10204. }
  10205. args[0] = combinedGlyphs;
  10206. fn = OPS.showText;
  10207. break;
  10208. case OPS.nextLineShowText:
  10209. operatorList.addOp(OPS.nextLine);
  10210. args[0] = self.handleText(args[0], stateManager.state);
  10211. fn = OPS.showText;
  10212. break;
  10213. case OPS.nextLineSetSpacingShowText:
  10214. operatorList.addOp(OPS.nextLine);
  10215. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10216. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10217. args[0] = self.handleText(args[0], stateManager.state);
  10218. fn = OPS.showText;
  10219. break;
  10220. case OPS.setTextRenderingMode:
  10221. stateManager.state.textRenderingMode = args[0];
  10222. break;
  10223. case OPS.setFillColorSpace:
  10224. stateManager.state.fillColorSpace =
  10225. ColorSpace.parse(args[0], xref, resources);
  10226. continue;
  10227. case OPS.setStrokeColorSpace:
  10228. stateManager.state.strokeColorSpace =
  10229. ColorSpace.parse(args[0], xref, resources);
  10230. continue;
  10231. case OPS.setFillColor:
  10232. cs = stateManager.state.fillColorSpace;
  10233. args = cs.getRgb(args, 0);
  10234. fn = OPS.setFillRGBColor;
  10235. break;
  10236. case OPS.setStrokeColor:
  10237. cs = stateManager.state.strokeColorSpace;
  10238. args = cs.getRgb(args, 0);
  10239. fn = OPS.setStrokeRGBColor;
  10240. break;
  10241. case OPS.setFillGray:
  10242. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10243. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10244. fn = OPS.setFillRGBColor;
  10245. break;
  10246. case OPS.setStrokeGray:
  10247. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10248. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10249. fn = OPS.setStrokeRGBColor;
  10250. break;
  10251. case OPS.setFillCMYKColor:
  10252. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10253. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10254. fn = OPS.setFillRGBColor;
  10255. break;
  10256. case OPS.setStrokeCMYKColor:
  10257. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10258. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10259. fn = OPS.setStrokeRGBColor;
  10260. break;
  10261. case OPS.setFillRGBColor:
  10262. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10263. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10264. break;
  10265. case OPS.setStrokeRGBColor:
  10266. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10267. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10268. break;
  10269. case OPS.setFillColorN:
  10270. cs = stateManager.state.fillColorSpace;
  10271. if (cs.name === 'Pattern') {
  10272. return self.handleColorN(operatorList, OPS.setFillColorN,
  10273. args, cs, patterns, resources, xref).then(function() {
  10274. next(resolve, reject);
  10275. }, reject);
  10276. }
  10277. args = cs.getRgb(args, 0);
  10278. fn = OPS.setFillRGBColor;
  10279. break;
  10280. case OPS.setStrokeColorN:
  10281. cs = stateManager.state.strokeColorSpace;
  10282. if (cs.name === 'Pattern') {
  10283. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10284. args, cs, patterns, resources, xref).then(function() {
  10285. next(resolve, reject);
  10286. }, reject);
  10287. }
  10288. args = cs.getRgb(args, 0);
  10289. fn = OPS.setStrokeRGBColor;
  10290. break;
  10291. case OPS.shadingFill:
  10292. var shadingRes = resources.get('Shading');
  10293. if (!shadingRes) {
  10294. error('No shading resource found');
  10295. }
  10296. var shading = shadingRes.get(args[0].name);
  10297. if (!shading) {
  10298. error('No shading object found');
  10299. }
  10300. var shadingFill = Pattern.parseShading(shading, null, xref,
  10301. resources);
  10302. var patternIR = shadingFill.getIR();
  10303. args = [patternIR];
  10304. fn = OPS.shadingFill;
  10305. break;
  10306. case OPS.setGState:
  10307. var dictName = args[0];
  10308. var extGState = resources.get('ExtGState');
  10309. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10310. break;
  10311. }
  10312. var gState = extGState.get(dictName.name);
  10313. return self.setGState(resources, gState, operatorList, xref,
  10314. stateManager).then(function() {
  10315. next(resolve, reject);
  10316. }, reject);
  10317. case OPS.moveTo:
  10318. case OPS.lineTo:
  10319. case OPS.curveTo:
  10320. case OPS.curveTo2:
  10321. case OPS.curveTo3:
  10322. case OPS.closePath:
  10323. self.buildPath(operatorList, fn, args);
  10324. continue;
  10325. case OPS.rectangle:
  10326. self.buildPath(operatorList, fn, args);
  10327. continue;
  10328. }
  10329. operatorList.addOp(fn, args);
  10330. }
  10331. if (stop) {
  10332. deferred.then(function () {
  10333. next(resolve, reject);
  10334. });
  10335. return;
  10336. }
  10337. // Some PDFs don't close all restores inside object/form.
  10338. // Closing those for them.
  10339. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10340. operatorList.addOp(OPS.restore, []);
  10341. }
  10342. resolve();
  10343. });
  10344. },
  10345. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10346. stateManager) {
  10347. stateManager = (stateManager || new StateManager(new TextState()));
  10348. var textContent = {
  10349. items: [],
  10350. styles: Object.create(null)
  10351. };
  10352. var bidiTexts = textContent.items;
  10353. var SPACE_FACTOR = 0.35;
  10354. var MULTI_SPACE_FACTOR = 1.5;
  10355. var self = this;
  10356. var xref = this.xref;
  10357. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10358. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10359. var xobjs = null;
  10360. var xobjsCache = {};
  10361. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10362. var textState;
  10363. function newTextChunk() {
  10364. var font = textState.font;
  10365. if (!(font.loadedName in textContent.styles)) {
  10366. textContent.styles[font.loadedName] = {
  10367. fontFamily: font.fallbackName,
  10368. ascent: font.ascent,
  10369. descent: font.descent,
  10370. vertical: font.vertical
  10371. };
  10372. }
  10373. return {
  10374. // |str| is initially an array which we push individual chars to, and
  10375. // then runBidi() overwrites it with the final string.
  10376. str: [],
  10377. dir: null,
  10378. width: 0,
  10379. height: 0,
  10380. transform: null,
  10381. fontName: font.loadedName
  10382. };
  10383. }
  10384. function runBidi(textChunk) {
  10385. var str = textChunk.str.join('');
  10386. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10387. textChunk.str = bidiResult.str;
  10388. textChunk.dir = bidiResult.dir;
  10389. return textChunk;
  10390. }
  10391. function handleSetFont(fontName, fontRef) {
  10392. return self.loadFont(fontName, fontRef, xref, resources).
  10393. then(function (translated) {
  10394. textState.font = translated.font;
  10395. textState.fontMatrix = translated.font.fontMatrix ||
  10396. FONT_IDENTITY_MATRIX;
  10397. });
  10398. }
  10399. function buildTextGeometry(chars, textChunk) {
  10400. var font = textState.font;
  10401. textChunk = textChunk || newTextChunk();
  10402. if (!textChunk.transform) {
  10403. // 9.4.4 Text Space Details
  10404. var tsm = [textState.fontSize * textState.textHScale, 0,
  10405. 0, textState.fontSize,
  10406. 0, textState.textRise];
  10407. var trm = textChunk.transform = Util.transform(textState.ctm,
  10408. Util.transform(textState.textMatrix, tsm));
  10409. if (!font.vertical) {
  10410. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10411. } else {
  10412. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10413. }
  10414. }
  10415. var width = 0;
  10416. var height = 0;
  10417. var glyphs = font.charsToGlyphs(chars);
  10418. var defaultVMetrics = font.defaultVMetrics;
  10419. for (var i = 0; i < glyphs.length; i++) {
  10420. var glyph = glyphs[i];
  10421. if (!glyph) { // Previous glyph was a space.
  10422. width += textState.wordSpacing * textState.textHScale;
  10423. continue;
  10424. }
  10425. var vMetricX = null;
  10426. var vMetricY = null;
  10427. var glyphWidth = null;
  10428. if (font.vertical) {
  10429. if (glyph.vmetric) {
  10430. glyphWidth = glyph.vmetric[0];
  10431. vMetricX = glyph.vmetric[1];
  10432. vMetricY = glyph.vmetric[2];
  10433. } else {
  10434. glyphWidth = glyph.width;
  10435. vMetricX = glyph.width * 0.5;
  10436. vMetricY = defaultVMetrics[2];
  10437. }
  10438. } else {
  10439. glyphWidth = glyph.width;
  10440. }
  10441. var glyphUnicode = glyph.unicode;
  10442. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10443. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10444. }
  10445. glyphUnicode = reverseIfRtl(glyphUnicode);
  10446. // The following will calculate the x and y of the individual glyphs.
  10447. // if (font.vertical) {
  10448. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10449. // textState.fontMatrix[0];
  10450. // tsm[5] -= vMetricY * textState.fontSize *
  10451. // textState.fontMatrix[0];
  10452. // }
  10453. // var trm = Util.transform(textState.textMatrix, tsm);
  10454. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10455. // var x = pt[0];
  10456. // var y = pt[1];
  10457. var tx = 0;
  10458. var ty = 0;
  10459. if (!font.vertical) {
  10460. var w0 = glyphWidth * textState.fontMatrix[0];
  10461. tx = (w0 * textState.fontSize + textState.charSpacing) *
  10462. textState.textHScale;
  10463. width += tx;
  10464. } else {
  10465. var w1 = glyphWidth * textState.fontMatrix[0];
  10466. ty = w1 * textState.fontSize + textState.charSpacing;
  10467. height += ty;
  10468. }
  10469. textState.translateTextMatrix(tx, ty);
  10470. textChunk.str.push(glyphUnicode);
  10471. }
  10472. var a = textState.textLineMatrix[0];
  10473. var b = textState.textLineMatrix[1];
  10474. var scaleLineX = Math.sqrt(a * a + b * b);
  10475. a = textState.ctm[0];
  10476. b = textState.ctm[1];
  10477. var scaleCtmX = Math.sqrt(a * a + b * b);
  10478. if (!font.vertical) {
  10479. textChunk.width += width * scaleCtmX * scaleLineX;
  10480. } else {
  10481. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10482. }
  10483. return textChunk;
  10484. }
  10485. var timeSlotManager = new TimeSlotManager();
  10486. return new Promise(function next(resolve, reject) {
  10487. timeSlotManager.reset();
  10488. var stop, operation = {}, args = [];
  10489. while (!(stop = timeSlotManager.check())) {
  10490. // The arguments parsed by read() are not used beyond this loop, so
  10491. // we can reuse the same array on every iteration, thus avoiding
  10492. // unnecessary allocations.
  10493. args.length = 0;
  10494. operation.args = args;
  10495. if (!(preprocessor.read(operation))) {
  10496. break;
  10497. }
  10498. textState = stateManager.state;
  10499. var fn = operation.fn;
  10500. args = operation.args;
  10501. switch (fn | 0) {
  10502. case OPS.setFont:
  10503. textState.fontSize = args[1];
  10504. return handleSetFont(args[0].name).then(function() {
  10505. next(resolve, reject);
  10506. }, reject);
  10507. case OPS.setTextRise:
  10508. textState.textRise = args[0];
  10509. break;
  10510. case OPS.setHScale:
  10511. textState.textHScale = args[0] / 100;
  10512. break;
  10513. case OPS.setLeading:
  10514. textState.leading = args[0];
  10515. break;
  10516. case OPS.moveText:
  10517. textState.translateTextLineMatrix(args[0], args[1]);
  10518. textState.textMatrix = textState.textLineMatrix.slice();
  10519. break;
  10520. case OPS.setLeadingMoveText:
  10521. textState.leading = -args[1];
  10522. textState.translateTextLineMatrix(args[0], args[1]);
  10523. textState.textMatrix = textState.textLineMatrix.slice();
  10524. break;
  10525. case OPS.nextLine:
  10526. textState.carriageReturn();
  10527. break;
  10528. case OPS.setTextMatrix:
  10529. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10530. args[4], args[5]);
  10531. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10532. args[4], args[5]);
  10533. break;
  10534. case OPS.setCharSpacing:
  10535. textState.charSpacing = args[0];
  10536. break;
  10537. case OPS.setWordSpacing:
  10538. textState.wordSpacing = args[0];
  10539. break;
  10540. case OPS.beginText:
  10541. textState.textMatrix = IDENTITY_MATRIX.slice();
  10542. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10543. break;
  10544. case OPS.showSpacedText:
  10545. var items = args[0];
  10546. var textChunk = newTextChunk();
  10547. var offset;
  10548. for (var j = 0, jj = items.length; j < jj; j++) {
  10549. if (typeof items[j] === 'string') {
  10550. buildTextGeometry(items[j], textChunk);
  10551. } else {
  10552. var val = items[j] / 1000;
  10553. if (!textState.font.vertical) {
  10554. offset = -val * textState.fontSize * textState.textHScale *
  10555. textState.textMatrix[0];
  10556. textState.translateTextMatrix(offset, 0);
  10557. textChunk.width += offset;
  10558. } else {
  10559. offset = -val * textState.fontSize *
  10560. textState.textMatrix[3];
  10561. textState.translateTextMatrix(0, offset);
  10562. textChunk.height += offset;
  10563. }
  10564. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10565. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10566. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10567. fakeSpaces = Math.round(fakeSpaces);
  10568. while (fakeSpaces--) {
  10569. textChunk.str.push(' ');
  10570. }
  10571. } else if (fakeSpaces > SPACE_FACTOR) {
  10572. textChunk.str.push(' ');
  10573. }
  10574. }
  10575. }
  10576. }
  10577. bidiTexts.push(runBidi(textChunk));
  10578. break;
  10579. case OPS.showText:
  10580. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10581. break;
  10582. case OPS.nextLineShowText:
  10583. textState.carriageReturn();
  10584. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10585. break;
  10586. case OPS.nextLineSetSpacingShowText:
  10587. textState.wordSpacing = args[0];
  10588. textState.charSpacing = args[1];
  10589. textState.carriageReturn();
  10590. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10591. break;
  10592. case OPS.paintXObject:
  10593. if (args[0].code) {
  10594. break;
  10595. }
  10596. if (!xobjs) {
  10597. xobjs = (resources.get('XObject') || Dict.empty);
  10598. }
  10599. var name = args[0].name;
  10600. if (xobjsCache.key === name) {
  10601. if (xobjsCache.texts) {
  10602. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10603. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10604. }
  10605. break;
  10606. }
  10607. var xobj = xobjs.get(name);
  10608. if (!xobj) {
  10609. break;
  10610. }
  10611. assert(isStream(xobj), 'XObject should be a stream');
  10612. var type = xobj.dict.get('Subtype');
  10613. assert(isName(type),
  10614. 'XObject should have a Name subtype');
  10615. if ('Form' !== type.name) {
  10616. xobjsCache.key = name;
  10617. xobjsCache.texts = null;
  10618. break;
  10619. }
  10620. stateManager.save();
  10621. var matrix = xobj.dict.get('Matrix');
  10622. if (isArray(matrix) && matrix.length === 6) {
  10623. stateManager.transform(matrix);
  10624. }
  10625. return self.getTextContent(xobj,
  10626. xobj.dict.get('Resources') || resources, stateManager).
  10627. then(function (formTextContent) {
  10628. Util.appendToArray(bidiTexts, formTextContent.items);
  10629. Util.extendObj(textContent.styles, formTextContent.styles);
  10630. stateManager.restore();
  10631. xobjsCache.key = name;
  10632. xobjsCache.texts = formTextContent;
  10633. next(resolve, reject);
  10634. }, reject);
  10635. case OPS.setGState:
  10636. var dictName = args[0];
  10637. var extGState = resources.get('ExtGState');
  10638. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10639. break;
  10640. }
  10641. var gsStateMap = extGState.get(dictName.name);
  10642. var gsStateFont = null;
  10643. for (var key in gsStateMap) {
  10644. if (key === 'Font') {
  10645. assert(!gsStateFont);
  10646. gsStateFont = gsStateMap[key];
  10647. }
  10648. }
  10649. if (gsStateFont) {
  10650. textState.fontSize = gsStateFont[1];
  10651. return handleSetFont(gsStateFont[0]).then(function() {
  10652. next(resolve, reject);
  10653. }, reject);
  10654. }
  10655. break;
  10656. } // switch
  10657. } // while
  10658. if (stop) {
  10659. deferred.then(function () {
  10660. next(resolve, reject);
  10661. });
  10662. return;
  10663. }
  10664. resolve(textContent);
  10665. });
  10666. },
  10667. extractDataStructures: function
  10668. partialEvaluatorExtractDataStructures(dict, baseDict,
  10669. xref, properties) {
  10670. // 9.10.2
  10671. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10672. if (toUnicode) {
  10673. properties.toUnicode = this.readToUnicode(toUnicode);
  10674. }
  10675. if (properties.composite) {
  10676. // CIDSystemInfo helps to match CID to glyphs
  10677. var cidSystemInfo = dict.get('CIDSystemInfo');
  10678. if (isDict(cidSystemInfo)) {
  10679. properties.cidSystemInfo = {
  10680. registry: cidSystemInfo.get('Registry'),
  10681. ordering: cidSystemInfo.get('Ordering'),
  10682. supplement: cidSystemInfo.get('Supplement')
  10683. };
  10684. }
  10685. var cidToGidMap = dict.get('CIDToGIDMap');
  10686. if (isStream(cidToGidMap)) {
  10687. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10688. }
  10689. }
  10690. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10691. // and depends on the font type. The base encoding and differences are
  10692. // read here, but the encoding that is actually used is chosen during
  10693. // glyph mapping in the font.
  10694. // TODO: Loading the built in encoding in the font would allow the
  10695. // differences to be merged in here not require us to hold on to it.
  10696. var differences = [];
  10697. var baseEncodingName = null;
  10698. var encoding;
  10699. if (dict.has('Encoding')) {
  10700. encoding = dict.get('Encoding');
  10701. if (isDict(encoding)) {
  10702. baseEncodingName = encoding.get('BaseEncoding');
  10703. baseEncodingName = (isName(baseEncodingName) ?
  10704. baseEncodingName.name : null);
  10705. // Load the differences between the base and original
  10706. if (encoding.has('Differences')) {
  10707. var diffEncoding = encoding.get('Differences');
  10708. var index = 0;
  10709. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10710. var data = diffEncoding[j];
  10711. if (isNum(data)) {
  10712. index = data;
  10713. } else {
  10714. differences[index++] = data.name;
  10715. }
  10716. }
  10717. }
  10718. } else if (isName(encoding)) {
  10719. baseEncodingName = encoding.name;
  10720. } else {
  10721. error('Encoding is not a Name nor a Dict');
  10722. }
  10723. // According to table 114 if the encoding is a named encoding it must be
  10724. // one of these predefined encodings.
  10725. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10726. baseEncodingName !== 'MacExpertEncoding' &&
  10727. baseEncodingName !== 'WinAnsiEncoding')) {
  10728. baseEncodingName = null;
  10729. }
  10730. }
  10731. if (baseEncodingName) {
  10732. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10733. } else {
  10734. encoding = (properties.type === 'TrueType' ?
  10735. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10736. // The Symbolic attribute can be misused for regular fonts
  10737. // Heuristic: we have to check if the font is a standard one also
  10738. if (!!(properties.flags & FontFlags.Symbolic)) {
  10739. encoding = Encodings.MacRomanEncoding;
  10740. if (!properties.file) {
  10741. if (/Symbol/i.test(properties.name)) {
  10742. encoding = Encodings.SymbolSetEncoding;
  10743. } else if (/Dingbats/i.test(properties.name)) {
  10744. encoding = Encodings.ZapfDingbatsEncoding;
  10745. }
  10746. }
  10747. }
  10748. properties.defaultEncoding = encoding;
  10749. }
  10750. properties.differences = differences;
  10751. properties.baseEncodingName = baseEncodingName;
  10752. properties.dict = dict;
  10753. },
  10754. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10755. var cmap, cmapObj = toUnicode;
  10756. if (isName(cmapObj)) {
  10757. cmap = CMapFactory.create(cmapObj,
  10758. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10759. return new ToUnicodeMap(cmap);
  10760. } else if (isStream(cmapObj)) {
  10761. cmap = CMapFactory.create(cmapObj,
  10762. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  10763. // Convert UTF-16BE
  10764. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10765. // to iterate over all keys.
  10766. cmap.forEach(function(token, i) {
  10767. var str = [];
  10768. for (var k = 0; k < token.length; k += 2) {
  10769. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10770. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  10771. str.push(w1);
  10772. continue;
  10773. }
  10774. k += 2;
  10775. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  10776. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  10777. }
  10778. cmap[i] = String.fromCharCode.apply(String, str);
  10779. });
  10780. return new ToUnicodeMap(cmap);
  10781. }
  10782. return null;
  10783. },
  10784. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  10785. // Extract the encoding from the CIDToGIDMap
  10786. var glyphsData = cidToGidStream.getBytes();
  10787. // Set encoding 0 to later verify the font has an encoding
  10788. var result = [];
  10789. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  10790. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  10791. if (glyphID === 0) {
  10792. continue;
  10793. }
  10794. var code = j >> 1;
  10795. result[code] = glyphID;
  10796. }
  10797. return result;
  10798. },
  10799. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  10800. descriptor,
  10801. properties) {
  10802. var glyphsWidths = [];
  10803. var defaultWidth = 0;
  10804. var glyphsVMetrics = [];
  10805. var defaultVMetrics;
  10806. var i, ii, j, jj, start, code, widths;
  10807. if (properties.composite) {
  10808. defaultWidth = dict.get('DW') || 1000;
  10809. widths = dict.get('W');
  10810. if (widths) {
  10811. for (i = 0, ii = widths.length; i < ii; i++) {
  10812. start = widths[i++];
  10813. code = xref.fetchIfRef(widths[i]);
  10814. if (isArray(code)) {
  10815. for (j = 0, jj = code.length; j < jj; j++) {
  10816. glyphsWidths[start++] = code[j];
  10817. }
  10818. } else {
  10819. var width = widths[++i];
  10820. for (j = start; j <= code; j++) {
  10821. glyphsWidths[j] = width;
  10822. }
  10823. }
  10824. }
  10825. }
  10826. if (properties.vertical) {
  10827. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10828. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10829. vmetrics = dict.get('W2');
  10830. if (vmetrics) {
  10831. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10832. start = vmetrics[i++];
  10833. code = xref.fetchIfRef(vmetrics[i]);
  10834. if (isArray(code)) {
  10835. for (j = 0, jj = code.length; j < jj; j++) {
  10836. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10837. }
  10838. } else {
  10839. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10840. for (j = start; j <= code; j++) {
  10841. glyphsVMetrics[j] = vmetric;
  10842. }
  10843. }
  10844. }
  10845. }
  10846. }
  10847. } else {
  10848. var firstChar = properties.firstChar;
  10849. widths = dict.get('Widths');
  10850. if (widths) {
  10851. j = firstChar;
  10852. for (i = 0, ii = widths.length; i < ii; i++) {
  10853. glyphsWidths[j++] = widths[i];
  10854. }
  10855. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10856. } else {
  10857. // Trying get the BaseFont metrics (see comment above).
  10858. var baseFontName = dict.get('BaseFont');
  10859. if (isName(baseFontName)) {
  10860. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10861. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10862. properties);
  10863. defaultWidth = metrics.defaultWidth;
  10864. }
  10865. }
  10866. }
  10867. // Heuristic: detection of monospace font by checking all non-zero widths
  10868. var isMonospace = true;
  10869. var firstWidth = defaultWidth;
  10870. for (var glyph in glyphsWidths) {
  10871. var glyphWidth = glyphsWidths[glyph];
  10872. if (!glyphWidth) {
  10873. continue;
  10874. }
  10875. if (!firstWidth) {
  10876. firstWidth = glyphWidth;
  10877. continue;
  10878. }
  10879. if (firstWidth !== glyphWidth) {
  10880. isMonospace = false;
  10881. break;
  10882. }
  10883. }
  10884. if (isMonospace) {
  10885. properties.flags |= FontFlags.FixedPitch;
  10886. }
  10887. properties.defaultWidth = defaultWidth;
  10888. properties.widths = glyphsWidths;
  10889. properties.defaultVMetrics = defaultVMetrics;
  10890. properties.vmetrics = glyphsVMetrics;
  10891. },
  10892. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10893. // Simulating descriptor flags attribute
  10894. var fontNameWoStyle = baseFontName.split('-')[0];
  10895. return (fontNameWoStyle in serifFonts) ||
  10896. (fontNameWoStyle.search(/serif/gi) !== -1);
  10897. },
  10898. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10899. var defaultWidth = 0;
  10900. var widths = [];
  10901. var monospace = false;
  10902. var lookupName = (stdFontMap[name] || name);
  10903. if (!(lookupName in Metrics)) {
  10904. // Use default fonts for looking up font metrics if the passed
  10905. // font is not a base font
  10906. if (this.isSerifFont(name)) {
  10907. lookupName = 'Times-Roman';
  10908. } else {
  10909. lookupName = 'Helvetica';
  10910. }
  10911. }
  10912. var glyphWidths = Metrics[lookupName];
  10913. if (isNum(glyphWidths)) {
  10914. defaultWidth = glyphWidths;
  10915. monospace = true;
  10916. } else {
  10917. widths = glyphWidths;
  10918. }
  10919. return {
  10920. defaultWidth: defaultWidth,
  10921. monospace: monospace,
  10922. widths: widths
  10923. };
  10924. },
  10925. buildCharCodeToWidth:
  10926. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10927. properties) {
  10928. var widths = Object.create(null);
  10929. var differences = properties.differences;
  10930. var encoding = properties.defaultEncoding;
  10931. for (var charCode = 0; charCode < 256; charCode++) {
  10932. if (charCode in differences &&
  10933. widthsByGlyphName[differences[charCode]]) {
  10934. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10935. continue;
  10936. }
  10937. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10938. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10939. continue;
  10940. }
  10941. }
  10942. return widths;
  10943. },
  10944. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10945. var baseDict = dict;
  10946. var type = dict.get('Subtype');
  10947. assert(isName(type), 'invalid font Subtype');
  10948. var composite = false;
  10949. var uint8array;
  10950. if (type.name === 'Type0') {
  10951. // If font is a composite
  10952. // - get the descendant font
  10953. // - set the type according to the descendant font
  10954. // - get the FontDescriptor from the descendant font
  10955. var df = dict.get('DescendantFonts');
  10956. if (!df) {
  10957. error('Descendant fonts are not specified');
  10958. }
  10959. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10960. type = dict.get('Subtype');
  10961. assert(isName(type), 'invalid font Subtype');
  10962. composite = true;
  10963. }
  10964. var descriptor = dict.get('FontDescriptor');
  10965. if (descriptor) {
  10966. var hash = new MurmurHash3_64();
  10967. var encoding = baseDict.getRaw('Encoding');
  10968. if (isName(encoding)) {
  10969. hash.update(encoding.name);
  10970. } else if (isRef(encoding)) {
  10971. hash.update(encoding.num + '_' + encoding.gen);
  10972. }
  10973. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10974. if (isStream(toUnicode)) {
  10975. var stream = toUnicode.str || toUnicode;
  10976. uint8array = stream.buffer ?
  10977. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10978. new Uint8Array(stream.bytes.buffer,
  10979. stream.start, stream.end - stream.start);
  10980. hash.update(uint8array);
  10981. } else if (isName(toUnicode)) {
  10982. hash.update(toUnicode.name);
  10983. }
  10984. var widths = dict.get('Widths') || baseDict.get('Widths');
  10985. if (widths) {
  10986. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10987. hash.update(uint8array);
  10988. }
  10989. }
  10990. return {
  10991. descriptor: descriptor,
  10992. dict: dict,
  10993. baseDict: baseDict,
  10994. composite: composite,
  10995. type: type.name,
  10996. hash: hash ? hash.hexdigest() : ''
  10997. };
  10998. },
  10999. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11000. xref) {
  11001. var baseDict = preEvaluatedFont.baseDict;
  11002. var dict = preEvaluatedFont.dict;
  11003. var composite = preEvaluatedFont.composite;
  11004. var descriptor = preEvaluatedFont.descriptor;
  11005. var type = preEvaluatedFont.type;
  11006. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11007. var properties;
  11008. if (!descriptor) {
  11009. if (type === 'Type3') {
  11010. // FontDescriptor is only required for Type3 fonts when the document
  11011. // is a tagged pdf. Create a barbebones one to get by.
  11012. descriptor = new Dict(null);
  11013. descriptor.set('FontName', Name.get(type));
  11014. } else {
  11015. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11016. // FontDescriptor was not required.
  11017. // This case is here for compatibility.
  11018. var baseFontName = dict.get('BaseFont');
  11019. if (!isName(baseFontName)) {
  11020. error('Base font is not specified');
  11021. }
  11022. // Using base font name as a font name.
  11023. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11024. var metrics = this.getBaseFontMetrics(baseFontName);
  11025. // Simulating descriptor flags attribute
  11026. var fontNameWoStyle = baseFontName.split('-')[0];
  11027. var flags =
  11028. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11029. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11030. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11031. FontFlags.Nonsymbolic);
  11032. properties = {
  11033. type: type,
  11034. name: baseFontName,
  11035. widths: metrics.widths,
  11036. defaultWidth: metrics.defaultWidth,
  11037. flags: flags,
  11038. firstChar: 0,
  11039. lastChar: maxCharIndex
  11040. };
  11041. this.extractDataStructures(dict, dict, xref, properties);
  11042. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11043. properties);
  11044. return new Font(baseFontName, null, properties);
  11045. }
  11046. }
  11047. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11048. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11049. // to ignore this rule when a variant of a standart font is used.
  11050. // TODO Fill the width array depending on which of the base font this is
  11051. // a variant.
  11052. var firstChar = (dict.get('FirstChar') || 0);
  11053. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11054. var fontName = descriptor.get('FontName');
  11055. var baseFont = dict.get('BaseFont');
  11056. // Some bad PDFs have a string as the font name.
  11057. if (isString(fontName)) {
  11058. fontName = Name.get(fontName);
  11059. }
  11060. if (isString(baseFont)) {
  11061. baseFont = Name.get(baseFont);
  11062. }
  11063. if (type !== 'Type3') {
  11064. var fontNameStr = fontName && fontName.name;
  11065. var baseFontStr = baseFont && baseFont.name;
  11066. if (fontNameStr !== baseFontStr) {
  11067. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11068. '" but should be the same as the Font\'s BaseFont "' +
  11069. baseFontStr + '"');
  11070. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11071. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11072. if (fontNameStr && baseFontStr &&
  11073. baseFontStr.indexOf(fontNameStr) === 0) {
  11074. fontName = baseFont;
  11075. }
  11076. }
  11077. }
  11078. fontName = (fontName || baseFont);
  11079. assert(isName(fontName), 'invalid font name');
  11080. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11081. if (fontFile) {
  11082. if (fontFile.dict) {
  11083. var subtype = fontFile.dict.get('Subtype');
  11084. if (subtype) {
  11085. subtype = subtype.name;
  11086. }
  11087. var length1 = fontFile.dict.get('Length1');
  11088. var length2 = fontFile.dict.get('Length2');
  11089. }
  11090. }
  11091. properties = {
  11092. type: type,
  11093. name: fontName.name,
  11094. subtype: subtype,
  11095. file: fontFile,
  11096. length1: length1,
  11097. length2: length2,
  11098. loadedName: baseDict.loadedName,
  11099. composite: composite,
  11100. wideChars: composite,
  11101. fixedPitch: false,
  11102. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11103. firstChar: firstChar || 0,
  11104. lastChar: (lastChar || maxCharIndex),
  11105. bbox: descriptor.get('FontBBox'),
  11106. ascent: descriptor.get('Ascent'),
  11107. descent: descriptor.get('Descent'),
  11108. xHeight: descriptor.get('XHeight'),
  11109. capHeight: descriptor.get('CapHeight'),
  11110. flags: descriptor.get('Flags'),
  11111. italicAngle: descriptor.get('ItalicAngle'),
  11112. coded: false
  11113. };
  11114. if (composite) {
  11115. var cidEncoding = baseDict.get('Encoding');
  11116. if (isName(cidEncoding)) {
  11117. properties.cidEncoding = cidEncoding.name;
  11118. }
  11119. properties.cMap = CMapFactory.create(cidEncoding,
  11120. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11121. properties.vertical = properties.cMap.vertical;
  11122. }
  11123. this.extractDataStructures(dict, baseDict, xref, properties);
  11124. this.extractWidths(dict, xref, descriptor, properties);
  11125. if (type === 'Type3') {
  11126. properties.isType3Font = true;
  11127. }
  11128. return new Font(fontName.name, fontFile, properties);
  11129. }
  11130. };
  11131. return PartialEvaluator;
  11132. })();
  11133. var TranslatedFont = (function TranslatedFontClosure() {
  11134. function TranslatedFont(loadedName, font, dict) {
  11135. this.loadedName = loadedName;
  11136. this.font = font;
  11137. this.dict = dict;
  11138. this.type3Loaded = null;
  11139. this.sent = false;
  11140. }
  11141. TranslatedFont.prototype = {
  11142. send: function (handler) {
  11143. if (this.sent) {
  11144. return;
  11145. }
  11146. var fontData = this.font.exportData();
  11147. handler.send('commonobj', [
  11148. this.loadedName,
  11149. 'Font',
  11150. fontData
  11151. ]);
  11152. this.sent = true;
  11153. },
  11154. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11155. assert(this.font.isType3Font);
  11156. if (this.type3Loaded) {
  11157. return this.type3Loaded;
  11158. }
  11159. var translatedFont = this.font;
  11160. var loadCharProcsPromise = Promise.resolve();
  11161. var charProcs = this.dict.get('CharProcs').getAll();
  11162. var fontResources = this.dict.get('Resources') || resources;
  11163. var charProcKeys = Object.keys(charProcs);
  11164. var charProcOperatorList = {};
  11165. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11166. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11167. var glyphStream = charProcs[key];
  11168. var operatorList = new OperatorList();
  11169. return evaluator.getOperatorList(glyphStream, fontResources,
  11170. operatorList).then(function () {
  11171. charProcOperatorList[key] = operatorList.getIR();
  11172. // Add the dependencies to the parent operator list so they are
  11173. // resolved before sub operator list is executed synchronously.
  11174. parentOperatorList.addDependencies(operatorList.dependencies);
  11175. }, function (reason) {
  11176. warn('Type3 font resource \"' + key + '\" is not available');
  11177. var operatorList = new OperatorList();
  11178. charProcOperatorList[key] = operatorList.getIR();
  11179. });
  11180. }.bind(this, charProcKeys[i]));
  11181. }
  11182. this.type3Loaded = loadCharProcsPromise.then(function () {
  11183. translatedFont.charProcOperatorList = charProcOperatorList;
  11184. });
  11185. return this.type3Loaded;
  11186. }
  11187. };
  11188. return TranslatedFont;
  11189. })();
  11190. var OperatorList = (function OperatorListClosure() {
  11191. var CHUNK_SIZE = 1000;
  11192. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11193. function getTransfers(queue) {
  11194. var transfers = [];
  11195. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11196. for (var i = 0, ii = queue.length; i < ii; i++) {
  11197. switch (fnArray[i]) {
  11198. case OPS.paintInlineImageXObject:
  11199. case OPS.paintInlineImageXObjectGroup:
  11200. case OPS.paintImageMaskXObject:
  11201. var arg = argsArray[i][0]; // first param in imgData
  11202. if (!arg.cached) {
  11203. transfers.push(arg.data.buffer);
  11204. }
  11205. break;
  11206. }
  11207. }
  11208. return transfers;
  11209. }
  11210. function OperatorList(intent, messageHandler, pageIndex) {
  11211. this.messageHandler = messageHandler;
  11212. this.fnArray = [];
  11213. this.argsArray = [];
  11214. this.dependencies = {};
  11215. this.pageIndex = pageIndex;
  11216. this.intent = intent;
  11217. }
  11218. OperatorList.prototype = {
  11219. get length() {
  11220. return this.argsArray.length;
  11221. },
  11222. addOp: function(fn, args) {
  11223. this.fnArray.push(fn);
  11224. this.argsArray.push(args);
  11225. if (this.messageHandler) {
  11226. if (this.fnArray.length >= CHUNK_SIZE) {
  11227. this.flush();
  11228. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11229. (fn === OPS.restore || fn === OPS.endText)) {
  11230. // heuristic to flush on boundary of restore or endText
  11231. this.flush();
  11232. }
  11233. }
  11234. },
  11235. addDependency: function(dependency) {
  11236. if (dependency in this.dependencies) {
  11237. return;
  11238. }
  11239. this.dependencies[dependency] = true;
  11240. this.addOp(OPS.dependency, [dependency]);
  11241. },
  11242. addDependencies: function(dependencies) {
  11243. for (var key in dependencies) {
  11244. this.addDependency(key);
  11245. }
  11246. },
  11247. addOpList: function(opList) {
  11248. Util.extendObj(this.dependencies, opList.dependencies);
  11249. for (var i = 0, ii = opList.length; i < ii; i++) {
  11250. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11251. }
  11252. },
  11253. getIR: function() {
  11254. return {
  11255. fnArray: this.fnArray,
  11256. argsArray: this.argsArray,
  11257. length: this.length
  11258. };
  11259. },
  11260. flush: function(lastChunk) {
  11261. if (this.intent !== 'oplist') {
  11262. new QueueOptimizer().optimize(this);
  11263. }
  11264. var transfers = getTransfers(this);
  11265. this.messageHandler.send('RenderPageChunk', {
  11266. operatorList: {
  11267. fnArray: this.fnArray,
  11268. argsArray: this.argsArray,
  11269. lastChunk: lastChunk,
  11270. length: this.length
  11271. },
  11272. pageIndex: this.pageIndex,
  11273. intent: this.intent
  11274. }, transfers);
  11275. this.dependencies = {};
  11276. this.fnArray.length = 0;
  11277. this.argsArray.length = 0;
  11278. }
  11279. };
  11280. return OperatorList;
  11281. })();
  11282. var StateManager = (function StateManagerClosure() {
  11283. function StateManager(initialState) {
  11284. this.state = initialState;
  11285. this.stateStack = [];
  11286. }
  11287. StateManager.prototype = {
  11288. save: function () {
  11289. var old = this.state;
  11290. this.stateStack.push(this.state);
  11291. this.state = old.clone();
  11292. },
  11293. restore: function () {
  11294. var prev = this.stateStack.pop();
  11295. if (prev) {
  11296. this.state = prev;
  11297. }
  11298. },
  11299. transform: function (args) {
  11300. this.state.ctm = Util.transform(this.state.ctm, args);
  11301. }
  11302. };
  11303. return StateManager;
  11304. })();
  11305. var TextState = (function TextStateClosure() {
  11306. function TextState() {
  11307. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11308. this.fontSize = 0;
  11309. this.font = null;
  11310. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11311. this.textMatrix = IDENTITY_MATRIX.slice();
  11312. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11313. this.charSpacing = 0;
  11314. this.wordSpacing = 0;
  11315. this.leading = 0;
  11316. this.textHScale = 1;
  11317. this.textRise = 0;
  11318. }
  11319. TextState.prototype = {
  11320. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11321. var m = this.textMatrix;
  11322. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11323. },
  11324. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11325. var m = this.textLineMatrix;
  11326. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11327. },
  11328. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11329. var m = this.textMatrix;
  11330. m[4] = m[0] * x + m[2] * y + m[4];
  11331. m[5] = m[1] * x + m[3] * y + m[5];
  11332. },
  11333. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11334. var m = this.textLineMatrix;
  11335. m[4] = m[0] * x + m[2] * y + m[4];
  11336. m[5] = m[1] * x + m[3] * y + m[5];
  11337. },
  11338. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11339. // 9.4.4 Text Space Details
  11340. var tsm = [this.fontSize * this.textHScale, 0,
  11341. 0, this.fontSize,
  11342. 0, this.textRise];
  11343. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11344. },
  11345. carriageReturn: function TextState_carriageReturn() {
  11346. this.translateTextLineMatrix(0, -this.leading);
  11347. this.textMatrix = this.textLineMatrix.slice();
  11348. },
  11349. clone: function TextState_clone() {
  11350. var clone = Object.create(this);
  11351. clone.textMatrix = this.textMatrix.slice();
  11352. clone.textLineMatrix = this.textLineMatrix.slice();
  11353. clone.fontMatrix = this.fontMatrix.slice();
  11354. return clone;
  11355. }
  11356. };
  11357. return TextState;
  11358. })();
  11359. var EvalState = (function EvalStateClosure() {
  11360. function EvalState() {
  11361. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11362. this.font = null;
  11363. this.textRenderingMode = TextRenderingMode.FILL;
  11364. this.fillColorSpace = ColorSpace.singletons.gray;
  11365. this.strokeColorSpace = ColorSpace.singletons.gray;
  11366. }
  11367. EvalState.prototype = {
  11368. clone: function CanvasExtraState_clone() {
  11369. return Object.create(this);
  11370. },
  11371. };
  11372. return EvalState;
  11373. })();
  11374. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11375. // Specifies properties for each command
  11376. //
  11377. // If variableArgs === true: [0, `numArgs`] expected
  11378. // If variableArgs === false: exactly `numArgs` expected
  11379. var OP_MAP = {
  11380. // Graphic state
  11381. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11382. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11383. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11384. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11385. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11386. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11387. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11388. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11389. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11390. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11391. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11392. // Path
  11393. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11394. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11395. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11396. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11397. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11398. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11399. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11400. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11401. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11402. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11403. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11404. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11405. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11406. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11407. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11408. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11409. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11410. // Clipping
  11411. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11412. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11413. // Text
  11414. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11415. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11416. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11417. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11418. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11419. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11420. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11421. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11422. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11423. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11424. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11425. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11426. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11427. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11428. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11429. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11430. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11431. variableArgs: false },
  11432. // Type3 fonts
  11433. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11434. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11435. // Color
  11436. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11437. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11438. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11439. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11440. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11441. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11442. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11443. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11444. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11445. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11446. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11447. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11448. // Shading
  11449. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11450. // Images
  11451. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11452. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11453. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11454. // XObjects
  11455. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11456. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11457. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11458. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11459. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11460. variableArgs: false },
  11461. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11462. // Compatibility
  11463. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11464. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11465. // (reserved partial commands for the lexer)
  11466. BM: null,
  11467. BD: null,
  11468. 'true': null,
  11469. fa: null,
  11470. fal: null,
  11471. fals: null,
  11472. 'false': null,
  11473. nu: null,
  11474. nul: null,
  11475. 'null': null
  11476. };
  11477. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11478. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11479. // dictionary
  11480. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11481. this.stateManager = stateManager;
  11482. this.nonProcessedArgs = [];
  11483. }
  11484. EvaluatorPreprocessor.prototype = {
  11485. get savedStatesDepth() {
  11486. return this.stateManager.stateStack.length;
  11487. },
  11488. // |operation| is an object with two fields:
  11489. //
  11490. // - |fn| is an out param.
  11491. //
  11492. // - |args| is an inout param. On entry, it should have one of two values.
  11493. //
  11494. // - An empty array. This indicates that the caller is providing the
  11495. // array in which the args will be stored in. The caller should use
  11496. // this value if it can reuse a single array for each call to read().
  11497. //
  11498. // - |null|. This indicates that the caller needs this function to create
  11499. // the array in which any args are stored in. If there are zero args,
  11500. // this function will leave |operation.args| as |null| (thus avoiding
  11501. // allocations that would occur if we used an empty array to represent
  11502. // zero arguments). Otherwise, it will replace |null| with a new array
  11503. // containing the arguments. The caller should use this value if it
  11504. // cannot reuse an array for each call to read().
  11505. //
  11506. // These two modes are present because this function is very hot and so
  11507. // avoiding allocations where possible is worthwhile.
  11508. //
  11509. read: function EvaluatorPreprocessor_read(operation) {
  11510. var args = operation.args;
  11511. while (true) {
  11512. var obj = this.parser.getObj();
  11513. if (isCmd(obj)) {
  11514. var cmd = obj.cmd;
  11515. // Check that the command is valid
  11516. var opSpec = OP_MAP[cmd];
  11517. if (!opSpec) {
  11518. warn('Unknown command "' + cmd + '"');
  11519. continue;
  11520. }
  11521. var fn = opSpec.id;
  11522. var numArgs = opSpec.numArgs;
  11523. var argsLength = args !== null ? args.length : 0;
  11524. if (!opSpec.variableArgs) {
  11525. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11526. if (argsLength !== numArgs) {
  11527. var nonProcessedArgs = this.nonProcessedArgs;
  11528. while (argsLength > numArgs) {
  11529. nonProcessedArgs.push(args.shift());
  11530. argsLength--;
  11531. }
  11532. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11533. if (!args) {
  11534. args = [];
  11535. }
  11536. args.unshift(nonProcessedArgs.pop());
  11537. argsLength++;
  11538. }
  11539. }
  11540. if (argsLength < numArgs) {
  11541. // If we receive too few args, it's not possible to possible
  11542. // to execute the command, so skip the command
  11543. info('Command ' + fn + ': because expected ' +
  11544. numArgs + ' args, but received ' + argsLength +
  11545. ' args; skipping');
  11546. args = null;
  11547. continue;
  11548. }
  11549. } else if (argsLength > numArgs) {
  11550. info('Command ' + fn + ': expected [0,' + numArgs +
  11551. '] args, but received ' + argsLength + ' args');
  11552. }
  11553. // TODO figure out how to type-check vararg functions
  11554. this.preprocessCommand(fn, args);
  11555. operation.fn = fn;
  11556. operation.args = args;
  11557. return true;
  11558. } else {
  11559. if (isEOF(obj)) {
  11560. return false; // no more commands
  11561. }
  11562. // argument
  11563. if (obj !== null) {
  11564. if (!args) {
  11565. args = [];
  11566. }
  11567. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11568. assert(args.length <= 33, 'Too many arguments');
  11569. }
  11570. }
  11571. }
  11572. },
  11573. preprocessCommand:
  11574. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11575. switch (fn | 0) {
  11576. case OPS.save:
  11577. this.stateManager.save();
  11578. break;
  11579. case OPS.restore:
  11580. this.stateManager.restore();
  11581. break;
  11582. case OPS.transform:
  11583. this.stateManager.transform(args);
  11584. break;
  11585. }
  11586. }
  11587. };
  11588. return EvaluatorPreprocessor;
  11589. })();
  11590. var QueueOptimizer = (function QueueOptimizerClosure() {
  11591. function addState(parentState, pattern, fn) {
  11592. var state = parentState;
  11593. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11594. var item = pattern[i];
  11595. state = (state[item] || (state[item] = []));
  11596. }
  11597. state[pattern[pattern.length - 1]] = fn;
  11598. }
  11599. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11600. argsArray) {
  11601. // Handles special case of mainly LaTeX documents which use image masks to
  11602. // draw lines with the current fill style.
  11603. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11604. // have been found at iFirstSave.
  11605. var iFirstPIMXO = iFirstSave + 2;
  11606. for (var i = 0; i < count; i++) {
  11607. var arg = argsArray[iFirstPIMXO + 4 * i];
  11608. var imageMask = arg.length === 1 && arg[0];
  11609. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11610. (!imageMask.data.length ||
  11611. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11612. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11613. continue;
  11614. }
  11615. break;
  11616. }
  11617. return count - i;
  11618. }
  11619. var InitialState = [];
  11620. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11621. // sequences with one |paintInlineImageXObjectGroup| operation.
  11622. addState(InitialState,
  11623. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11624. function foundInlineImageGroup(context) {
  11625. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11626. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11627. var MAX_WIDTH = 1000;
  11628. var IMAGE_PADDING = 1;
  11629. var fnArray = context.fnArray, argsArray = context.argsArray;
  11630. var curr = context.iCurr;
  11631. var iFirstSave = curr - 3;
  11632. var iFirstTransform = curr - 2;
  11633. var iFirstPIIXO = curr - 1;
  11634. // Look for the quartets.
  11635. var i = iFirstSave + 4;
  11636. var ii = fnArray.length;
  11637. while (i + 3 < ii) {
  11638. if (fnArray[i] !== OPS.save ||
  11639. fnArray[i + 1] !== OPS.transform ||
  11640. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11641. fnArray[i + 3] !== OPS.restore) {
  11642. break; // ops don't match
  11643. }
  11644. i += 4;
  11645. }
  11646. // At this point, i is the index of the first op past the last valid
  11647. // quartet.
  11648. var count = Math.min((i - iFirstSave) / 4,
  11649. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11650. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11651. return i;
  11652. }
  11653. // assuming that heights of those image is too small (~1 pixel)
  11654. // packing as much as possible by lines
  11655. var maxX = 0;
  11656. var map = [], maxLineHeight = 0;
  11657. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11658. var q;
  11659. for (q = 0; q < count; q++) {
  11660. var transform = argsArray[iFirstTransform + (q << 2)];
  11661. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11662. if (currentX + img.width > MAX_WIDTH) {
  11663. // starting new line
  11664. maxX = Math.max(maxX, currentX);
  11665. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11666. currentX = 0;
  11667. maxLineHeight = 0;
  11668. }
  11669. map.push({
  11670. transform: transform,
  11671. x: currentX, y: currentY,
  11672. w: img.width, h: img.height
  11673. });
  11674. currentX += img.width + 2 * IMAGE_PADDING;
  11675. maxLineHeight = Math.max(maxLineHeight, img.height);
  11676. }
  11677. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11678. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11679. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11680. var imgRowSize = imgWidth << 2;
  11681. for (q = 0; q < count; q++) {
  11682. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11683. // Copy image by lines and extends pixels into padding.
  11684. var rowSize = map[q].w << 2;
  11685. var dataOffset = 0;
  11686. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11687. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11688. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11689. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11690. dataOffset += rowSize;
  11691. offset += imgRowSize;
  11692. }
  11693. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11694. while (offset >= 0) {
  11695. data[offset - 4] = data[offset];
  11696. data[offset - 3] = data[offset + 1];
  11697. data[offset - 2] = data[offset + 2];
  11698. data[offset - 1] = data[offset + 3];
  11699. data[offset + rowSize] = data[offset + rowSize - 4];
  11700. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11701. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11702. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11703. offset -= imgRowSize;
  11704. }
  11705. }
  11706. // Replace queue items.
  11707. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11708. argsArray.splice(iFirstSave, count * 4,
  11709. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11710. data: imgData }, map]);
  11711. return iFirstSave + 1;
  11712. });
  11713. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11714. // sequences with one |paintImageMaskXObjectGroup| or one
  11715. // |paintImageMaskXObjectRepeat| operation.
  11716. addState(InitialState,
  11717. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11718. function foundImageMaskGroup(context) {
  11719. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11720. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11721. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11722. var fnArray = context.fnArray, argsArray = context.argsArray;
  11723. var curr = context.iCurr;
  11724. var iFirstSave = curr - 3;
  11725. var iFirstTransform = curr - 2;
  11726. var iFirstPIMXO = curr - 1;
  11727. // Look for the quartets.
  11728. var i = iFirstSave + 4;
  11729. var ii = fnArray.length;
  11730. while (i + 3 < ii) {
  11731. if (fnArray[i] !== OPS.save ||
  11732. fnArray[i + 1] !== OPS.transform ||
  11733. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11734. fnArray[i + 3] !== OPS.restore) {
  11735. break; // ops don't match
  11736. }
  11737. i += 4;
  11738. }
  11739. // At this point, i is the index of the first op past the last valid
  11740. // quartet.
  11741. var count = (i - iFirstSave) / 4;
  11742. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11743. argsArray);
  11744. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11745. return i;
  11746. }
  11747. var q;
  11748. var isSameImage = false;
  11749. var iTransform, transformArgs;
  11750. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11751. if (argsArray[iFirstTransform][1] === 0 &&
  11752. argsArray[iFirstTransform][2] === 0) {
  11753. isSameImage = true;
  11754. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11755. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11756. iTransform = iFirstTransform + 4;
  11757. var iPIMXO = iFirstPIMXO + 4;
  11758. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  11759. transformArgs = argsArray[iTransform];
  11760. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  11761. transformArgs[0] !== firstTransformArg0 ||
  11762. transformArgs[1] !== 0 ||
  11763. transformArgs[2] !== 0 ||
  11764. transformArgs[3] !== firstTransformArg3) {
  11765. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  11766. isSameImage = false;
  11767. } else {
  11768. count = q;
  11769. }
  11770. break; // different image or transform
  11771. }
  11772. }
  11773. }
  11774. if (isSameImage) {
  11775. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  11776. var positions = new Float32Array(count * 2);
  11777. iTransform = iFirstTransform;
  11778. for (q = 0; q < count; q++, iTransform += 4) {
  11779. transformArgs = argsArray[iTransform];
  11780. positions[(q << 1)] = transformArgs[4];
  11781. positions[(q << 1) + 1] = transformArgs[5];
  11782. }
  11783. // Replace queue items.
  11784. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  11785. argsArray.splice(iFirstSave, count * 4,
  11786. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  11787. } else {
  11788. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  11789. var images = [];
  11790. for (q = 0; q < count; q++) {
  11791. transformArgs = argsArray[iFirstTransform + (q << 2)];
  11792. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  11793. images.push({ data: maskParams.data, width: maskParams.width,
  11794. height: maskParams.height,
  11795. transform: transformArgs });
  11796. }
  11797. // Replace queue items.
  11798. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  11799. argsArray.splice(iFirstSave, count * 4, [images]);
  11800. }
  11801. return iFirstSave + 1;
  11802. });
  11803. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  11804. // with one paintImageXObjectRepeat operation, if the |transform| and
  11805. // |paintImageXObjectRepeat| ops are appropriate.
  11806. addState(InitialState,
  11807. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  11808. function (context) {
  11809. var MIN_IMAGES_IN_BLOCK = 3;
  11810. var MAX_IMAGES_IN_BLOCK = 1000;
  11811. var fnArray = context.fnArray, argsArray = context.argsArray;
  11812. var curr = context.iCurr;
  11813. var iFirstSave = curr - 3;
  11814. var iFirstTransform = curr - 2;
  11815. var iFirstPIXO = curr - 1;
  11816. var iFirstRestore = curr;
  11817. if (argsArray[iFirstTransform][1] !== 0 ||
  11818. argsArray[iFirstTransform][2] !== 0) {
  11819. return iFirstRestore + 1; // transform has the wrong form
  11820. }
  11821. // Look for the quartets.
  11822. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  11823. var firstTransformArg0 = argsArray[iFirstTransform][0];
  11824. var firstTransformArg3 = argsArray[iFirstTransform][3];
  11825. var i = iFirstSave + 4;
  11826. var ii = fnArray.length;
  11827. while (i + 3 < ii) {
  11828. if (fnArray[i] !== OPS.save ||
  11829. fnArray[i + 1] !== OPS.transform ||
  11830. fnArray[i + 2] !== OPS.paintImageXObject ||
  11831. fnArray[i + 3] !== OPS.restore) {
  11832. break; // ops don't match
  11833. }
  11834. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  11835. argsArray[i + 1][1] !== 0 ||
  11836. argsArray[i + 1][2] !== 0 ||
  11837. argsArray[i + 1][3] !== firstTransformArg3) {
  11838. break; // transforms don't match
  11839. }
  11840. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  11841. break; // images don't match
  11842. }
  11843. i += 4;
  11844. }
  11845. // At this point, i is the index of the first op past the last valid
  11846. // quartet.
  11847. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  11848. if (count < MIN_IMAGES_IN_BLOCK) {
  11849. return i;
  11850. }
  11851. // Extract the (x,y) positions from all of the matching transforms.
  11852. var positions = new Float32Array(count * 2);
  11853. var iTransform = iFirstTransform;
  11854. for (var q = 0; q < count; q++, iTransform += 4) {
  11855. var transformArgs = argsArray[iTransform];
  11856. positions[(q << 1)] = transformArgs[4];
  11857. positions[(q << 1) + 1] = transformArgs[5];
  11858. }
  11859. // Replace queue items.
  11860. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  11861. positions];
  11862. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  11863. argsArray.splice(iFirstSave, count * 4, args);
  11864. return iFirstSave + 1;
  11865. });
  11866. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  11867. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  11868. // sequences, if the font for each one is the same.
  11869. addState(InitialState,
  11870. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  11871. function (context) {
  11872. var MIN_CHARS_IN_BLOCK = 3;
  11873. var MAX_CHARS_IN_BLOCK = 1000;
  11874. var fnArray = context.fnArray, argsArray = context.argsArray;
  11875. var curr = context.iCurr;
  11876. var iFirstBeginText = curr - 4;
  11877. var iFirstSetFont = curr - 3;
  11878. var iFirstSetTextMatrix = curr - 2;
  11879. var iFirstShowText = curr - 1;
  11880. var iFirstEndText = curr;
  11881. // Look for the quintets.
  11882. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  11883. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  11884. var i = iFirstBeginText + 5;
  11885. var ii = fnArray.length;
  11886. while (i + 4 < ii) {
  11887. if (fnArray[i] !== OPS.beginText ||
  11888. fnArray[i + 1] !== OPS.setFont ||
  11889. fnArray[i + 2] !== OPS.setTextMatrix ||
  11890. fnArray[i + 3] !== OPS.showText ||
  11891. fnArray[i + 4] !== OPS.endText) {
  11892. break; // ops don't match
  11893. }
  11894. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  11895. argsArray[i + 1][1] !== firstSetFontArg1) {
  11896. break; // fonts don't match
  11897. }
  11898. i += 5;
  11899. }
  11900. // At this point, i is the index of the first op past the last valid
  11901. // quintet.
  11902. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  11903. if (count < MIN_CHARS_IN_BLOCK) {
  11904. return i;
  11905. }
  11906. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  11907. // showText, endText), include that as well. (E.g. <something> might be
  11908. // |dependency|.)
  11909. var iFirst = iFirstBeginText;
  11910. if (iFirstBeginText >= 4 &&
  11911. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  11912. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  11913. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  11914. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  11915. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  11916. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  11917. count++;
  11918. iFirst -= 5;
  11919. }
  11920. // Remove (endText, beginText, setFont) trios.
  11921. var iEndText = iFirst + 4;
  11922. for (var q = 1; q < count; q++) {
  11923. fnArray.splice(iEndText, 3);
  11924. argsArray.splice(iEndText, 3);
  11925. iEndText += 2;
  11926. }
  11927. return iEndText + 1;
  11928. });
  11929. function QueueOptimizer() {}
  11930. QueueOptimizer.prototype = {
  11931. optimize: function QueueOptimizer_optimize(queue) {
  11932. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11933. var context = {
  11934. iCurr: 0,
  11935. fnArray: fnArray,
  11936. argsArray: argsArray
  11937. };
  11938. var state;
  11939. var i = 0, ii = fnArray.length;
  11940. while (i < ii) {
  11941. state = (state || InitialState)[fnArray[i]];
  11942. if (typeof state === 'function') { // we found some handler
  11943. context.iCurr = i;
  11944. // state() returns the index of the first non-matching op (if we
  11945. // didn't match) or the first op past the modified ops (if we did
  11946. // match and replace).
  11947. i = state(context);
  11948. state = undefined; // reset the state machine
  11949. ii = context.fnArray.length;
  11950. } else {
  11951. i++;
  11952. }
  11953. }
  11954. }
  11955. };
  11956. return QueueOptimizer;
  11957. })();
  11958. var BUILT_IN_CMAPS = [
  11959. // << Start unicode maps.
  11960. 'Adobe-GB1-UCS2',
  11961. 'Adobe-CNS1-UCS2',
  11962. 'Adobe-Japan1-UCS2',
  11963. 'Adobe-Korea1-UCS2',
  11964. // >> End unicode maps.
  11965. '78-EUC-H',
  11966. '78-EUC-V',
  11967. '78-H',
  11968. '78-RKSJ-H',
  11969. '78-RKSJ-V',
  11970. '78-V',
  11971. '78ms-RKSJ-H',
  11972. '78ms-RKSJ-V',
  11973. '83pv-RKSJ-H',
  11974. '90ms-RKSJ-H',
  11975. '90ms-RKSJ-V',
  11976. '90msp-RKSJ-H',
  11977. '90msp-RKSJ-V',
  11978. '90pv-RKSJ-H',
  11979. '90pv-RKSJ-V',
  11980. 'Add-H',
  11981. 'Add-RKSJ-H',
  11982. 'Add-RKSJ-V',
  11983. 'Add-V',
  11984. 'Adobe-CNS1-0',
  11985. 'Adobe-CNS1-1',
  11986. 'Adobe-CNS1-2',
  11987. 'Adobe-CNS1-3',
  11988. 'Adobe-CNS1-4',
  11989. 'Adobe-CNS1-5',
  11990. 'Adobe-CNS1-6',
  11991. 'Adobe-GB1-0',
  11992. 'Adobe-GB1-1',
  11993. 'Adobe-GB1-2',
  11994. 'Adobe-GB1-3',
  11995. 'Adobe-GB1-4',
  11996. 'Adobe-GB1-5',
  11997. 'Adobe-Japan1-0',
  11998. 'Adobe-Japan1-1',
  11999. 'Adobe-Japan1-2',
  12000. 'Adobe-Japan1-3',
  12001. 'Adobe-Japan1-4',
  12002. 'Adobe-Japan1-5',
  12003. 'Adobe-Japan1-6',
  12004. 'Adobe-Korea1-0',
  12005. 'Adobe-Korea1-1',
  12006. 'Adobe-Korea1-2',
  12007. 'B5-H',
  12008. 'B5-V',
  12009. 'B5pc-H',
  12010. 'B5pc-V',
  12011. 'CNS-EUC-H',
  12012. 'CNS-EUC-V',
  12013. 'CNS1-H',
  12014. 'CNS1-V',
  12015. 'CNS2-H',
  12016. 'CNS2-V',
  12017. 'ETHK-B5-H',
  12018. 'ETHK-B5-V',
  12019. 'ETen-B5-H',
  12020. 'ETen-B5-V',
  12021. 'ETenms-B5-H',
  12022. 'ETenms-B5-V',
  12023. 'EUC-H',
  12024. 'EUC-V',
  12025. 'Ext-H',
  12026. 'Ext-RKSJ-H',
  12027. 'Ext-RKSJ-V',
  12028. 'Ext-V',
  12029. 'GB-EUC-H',
  12030. 'GB-EUC-V',
  12031. 'GB-H',
  12032. 'GB-V',
  12033. 'GBK-EUC-H',
  12034. 'GBK-EUC-V',
  12035. 'GBK2K-H',
  12036. 'GBK2K-V',
  12037. 'GBKp-EUC-H',
  12038. 'GBKp-EUC-V',
  12039. 'GBT-EUC-H',
  12040. 'GBT-EUC-V',
  12041. 'GBT-H',
  12042. 'GBT-V',
  12043. 'GBTpc-EUC-H',
  12044. 'GBTpc-EUC-V',
  12045. 'GBpc-EUC-H',
  12046. 'GBpc-EUC-V',
  12047. 'H',
  12048. 'HKdla-B5-H',
  12049. 'HKdla-B5-V',
  12050. 'HKdlb-B5-H',
  12051. 'HKdlb-B5-V',
  12052. 'HKgccs-B5-H',
  12053. 'HKgccs-B5-V',
  12054. 'HKm314-B5-H',
  12055. 'HKm314-B5-V',
  12056. 'HKm471-B5-H',
  12057. 'HKm471-B5-V',
  12058. 'HKscs-B5-H',
  12059. 'HKscs-B5-V',
  12060. 'Hankaku',
  12061. 'Hiragana',
  12062. 'KSC-EUC-H',
  12063. 'KSC-EUC-V',
  12064. 'KSC-H',
  12065. 'KSC-Johab-H',
  12066. 'KSC-Johab-V',
  12067. 'KSC-V',
  12068. 'KSCms-UHC-H',
  12069. 'KSCms-UHC-HW-H',
  12070. 'KSCms-UHC-HW-V',
  12071. 'KSCms-UHC-V',
  12072. 'KSCpc-EUC-H',
  12073. 'KSCpc-EUC-V',
  12074. 'Katakana',
  12075. 'NWP-H',
  12076. 'NWP-V',
  12077. 'RKSJ-H',
  12078. 'RKSJ-V',
  12079. 'Roman',
  12080. 'UniCNS-UCS2-H',
  12081. 'UniCNS-UCS2-V',
  12082. 'UniCNS-UTF16-H',
  12083. 'UniCNS-UTF16-V',
  12084. 'UniCNS-UTF32-H',
  12085. 'UniCNS-UTF32-V',
  12086. 'UniCNS-UTF8-H',
  12087. 'UniCNS-UTF8-V',
  12088. 'UniGB-UCS2-H',
  12089. 'UniGB-UCS2-V',
  12090. 'UniGB-UTF16-H',
  12091. 'UniGB-UTF16-V',
  12092. 'UniGB-UTF32-H',
  12093. 'UniGB-UTF32-V',
  12094. 'UniGB-UTF8-H',
  12095. 'UniGB-UTF8-V',
  12096. 'UniJIS-UCS2-H',
  12097. 'UniJIS-UCS2-HW-H',
  12098. 'UniJIS-UCS2-HW-V',
  12099. 'UniJIS-UCS2-V',
  12100. 'UniJIS-UTF16-H',
  12101. 'UniJIS-UTF16-V',
  12102. 'UniJIS-UTF32-H',
  12103. 'UniJIS-UTF32-V',
  12104. 'UniJIS-UTF8-H',
  12105. 'UniJIS-UTF8-V',
  12106. 'UniJIS2004-UTF16-H',
  12107. 'UniJIS2004-UTF16-V',
  12108. 'UniJIS2004-UTF32-H',
  12109. 'UniJIS2004-UTF32-V',
  12110. 'UniJIS2004-UTF8-H',
  12111. 'UniJIS2004-UTF8-V',
  12112. 'UniJISPro-UCS2-HW-V',
  12113. 'UniJISPro-UCS2-V',
  12114. 'UniJISPro-UTF8-V',
  12115. 'UniJISX0213-UTF32-H',
  12116. 'UniJISX0213-UTF32-V',
  12117. 'UniJISX02132004-UTF32-H',
  12118. 'UniJISX02132004-UTF32-V',
  12119. 'UniKS-UCS2-H',
  12120. 'UniKS-UCS2-V',
  12121. 'UniKS-UTF16-H',
  12122. 'UniKS-UTF16-V',
  12123. 'UniKS-UTF32-H',
  12124. 'UniKS-UTF32-V',
  12125. 'UniKS-UTF8-H',
  12126. 'UniKS-UTF8-V',
  12127. 'V',
  12128. 'WP-Symbol'];
  12129. // CMap, not to be confused with TrueType's cmap.
  12130. var CMap = (function CMapClosure() {
  12131. function CMap(builtInCMap) {
  12132. // Codespace ranges are stored as follows:
  12133. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12134. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12135. this.codespaceRanges = [[], [], [], []];
  12136. this.numCodespaceRanges = 0;
  12137. // Map entries have one of two forms.
  12138. // - cid chars are 16-bit unsigned integers, stored as integers.
  12139. // - bf chars are variable-length byte sequences, stored as strings, with
  12140. // one byte per character.
  12141. this._map = [];
  12142. this.vertical = false;
  12143. this.useCMap = null;
  12144. this.builtInCMap = builtInCMap;
  12145. }
  12146. CMap.prototype = {
  12147. addCodespaceRange: function(n, low, high) {
  12148. this.codespaceRanges[n - 1].push(low, high);
  12149. this.numCodespaceRanges++;
  12150. },
  12151. mapCidRange: function(low, high, dstLow) {
  12152. while (low <= high) {
  12153. this._map[low++] = dstLow++;
  12154. }
  12155. },
  12156. mapBfRange: function(low, high, dstLow) {
  12157. var lastByte = dstLow.length - 1;
  12158. while (low <= high) {
  12159. this._map[low++] = dstLow;
  12160. // Only the last byte has to be incremented.
  12161. dstLow = dstLow.substr(0, lastByte) +
  12162. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12163. }
  12164. },
  12165. mapBfRangeToArray: function(low, high, array) {
  12166. var i = 0, ii = array.length;
  12167. while (low <= high && i < ii) {
  12168. this._map[low] = array[i++];
  12169. ++low;
  12170. }
  12171. },
  12172. // This is used for both bf and cid chars.
  12173. mapOne: function(src, dst) {
  12174. this._map[src] = dst;
  12175. },
  12176. lookup: function(code) {
  12177. return this._map[code];
  12178. },
  12179. contains: function(code) {
  12180. return this._map[code] !== undefined;
  12181. },
  12182. forEach: function(callback) {
  12183. // Most maps have fewer than 65536 entries, and for those we use normal
  12184. // array iteration. But really sparse tables are possible -- e.g. with
  12185. // indices in the *billions*. For such tables we use for..in, which isn't
  12186. // ideal because it stringifies the indices for all present elements, but
  12187. // it does avoid iterating over every undefined entry.
  12188. var map = this._map;
  12189. var length = map.length;
  12190. var i;
  12191. if (length <= 0x10000) {
  12192. for (i = 0; i < length; i++) {
  12193. if (map[i] !== undefined) {
  12194. callback(i, map[i]);
  12195. }
  12196. }
  12197. } else {
  12198. for (i in this._map) {
  12199. callback(i, map[i]);
  12200. }
  12201. }
  12202. },
  12203. charCodeOf: function(value) {
  12204. return this._map.indexOf(value);
  12205. },
  12206. getMap: function() {
  12207. return this._map;
  12208. },
  12209. readCharCode: function(str, offset, out) {
  12210. var c = 0;
  12211. var codespaceRanges = this.codespaceRanges;
  12212. var codespaceRangesLen = this.codespaceRanges.length;
  12213. // 9.7.6.2 CMap Mapping
  12214. // The code length is at most 4.
  12215. for (var n = 0; n < codespaceRangesLen; n++) {
  12216. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12217. // Check each codespace range to see if it falls within.
  12218. var codespaceRange = codespaceRanges[n];
  12219. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12220. var low = codespaceRange[k++];
  12221. var high = codespaceRange[k++];
  12222. if (c >= low && c <= high) {
  12223. out.charcode = c;
  12224. out.length = n + 1;
  12225. return;
  12226. }
  12227. }
  12228. }
  12229. out.charcode = 0;
  12230. out.length = 1;
  12231. }
  12232. };
  12233. return CMap;
  12234. })();
  12235. // A special case of CMap, where the _map array implicitly has a length of
  12236. // 65535 and each element is equal to its index.
  12237. var IdentityCMap = (function IdentityCMapClosure() {
  12238. function IdentityCMap(vertical, n) {
  12239. CMap.call(this);
  12240. this.vertical = vertical;
  12241. this.addCodespaceRange(n, 0, 0xffff);
  12242. }
  12243. Util.inherit(IdentityCMap, CMap, {});
  12244. IdentityCMap.prototype = {
  12245. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12246. mapCidRange: function(low, high, dstLow) {
  12247. error('should not call mapCidRange');
  12248. },
  12249. mapBfRange: function(low, high, dstLow) {
  12250. error('should not call mapBfRange');
  12251. },
  12252. mapBfRangeToArray: function(low, high, array) {
  12253. error('should not call mapBfRangeToArray');
  12254. },
  12255. mapOne: function(src, dst) {
  12256. error('should not call mapCidOne');
  12257. },
  12258. lookup: function(code) {
  12259. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12260. },
  12261. contains: function(code) {
  12262. return isInt(code) && code <= 0xffff;
  12263. },
  12264. forEach: function(callback) {
  12265. for (var i = 0; i <= 0xffff; i++) {
  12266. callback(i, i);
  12267. }
  12268. },
  12269. charCodeOf: function(value) {
  12270. return (isInt(value) && value <= 0xffff) ? value : -1;
  12271. },
  12272. getMap: function() {
  12273. // Sometimes identity maps must be instantiated, but it's rare.
  12274. var map = new Array(0x10000);
  12275. for (var i = 0; i <= 0xffff; i++) {
  12276. map[i] = i;
  12277. }
  12278. return map;
  12279. },
  12280. readCharCode: CMap.prototype.readCharCode
  12281. };
  12282. return IdentityCMap;
  12283. })();
  12284. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12285. function fetchBinaryData(url) {
  12286. var nonBinaryRequest = PDFJS.disableWorker;
  12287. var request = new XMLHttpRequest();
  12288. request.open('GET', url, false);
  12289. if (!nonBinaryRequest) {
  12290. try {
  12291. request.responseType = 'arraybuffer';
  12292. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12293. } catch (e) {
  12294. nonBinaryRequest = true;
  12295. }
  12296. }
  12297. if (nonBinaryRequest && request.overrideMimeType) {
  12298. request.overrideMimeType('text/plain; charset=x-user-defined');
  12299. }
  12300. request.send(null);
  12301. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12302. error('Unable to get binary cMap at: ' + url);
  12303. }
  12304. if (nonBinaryRequest) {
  12305. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12306. return ch.charCodeAt(0) & 255;
  12307. });
  12308. return new Uint8Array(data);
  12309. }
  12310. return new Uint8Array(request.response);
  12311. }
  12312. function hexToInt(a, size) {
  12313. var n = 0;
  12314. for (var i = 0; i <= size; i++) {
  12315. n = (n << 8) | a[i];
  12316. }
  12317. return n >>> 0;
  12318. }
  12319. function hexToStr(a, size) {
  12320. // This code is hot. Special-case some common values to avoid creating an
  12321. // object with subarray().
  12322. if (size === 1) {
  12323. return String.fromCharCode(a[0], a[1]);
  12324. }
  12325. if (size === 3) {
  12326. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12327. }
  12328. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12329. }
  12330. function addHex(a, b, size) {
  12331. var c = 0;
  12332. for (var i = size; i >= 0; i--) {
  12333. c += a[i] + b[i];
  12334. a[i] = c & 255;
  12335. c >>= 8;
  12336. }
  12337. }
  12338. function incHex(a, size) {
  12339. var c = 1;
  12340. for (var i = size; i >= 0 && c > 0; i--) {
  12341. c += a[i];
  12342. a[i] = c & 255;
  12343. c >>= 8;
  12344. }
  12345. }
  12346. var MAX_NUM_SIZE = 16;
  12347. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12348. function BinaryCMapStream(data) {
  12349. this.buffer = data;
  12350. this.pos = 0;
  12351. this.end = data.length;
  12352. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12353. }
  12354. BinaryCMapStream.prototype = {
  12355. readByte: function () {
  12356. if (this.pos >= this.end) {
  12357. return -1;
  12358. }
  12359. return this.buffer[this.pos++];
  12360. },
  12361. readNumber: function () {
  12362. var n = 0;
  12363. var last;
  12364. do {
  12365. var b = this.readByte();
  12366. if (b < 0) {
  12367. error('unexpected EOF in bcmap');
  12368. }
  12369. last = !(b & 0x80);
  12370. n = (n << 7) | (b & 0x7F);
  12371. } while (!last);
  12372. return n;
  12373. },
  12374. readSigned: function () {
  12375. var n = this.readNumber();
  12376. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12377. },
  12378. readHex: function (num, size) {
  12379. num.set(this.buffer.subarray(this.pos,
  12380. this.pos + size + 1));
  12381. this.pos += size + 1;
  12382. },
  12383. readHexNumber: function (num, size) {
  12384. var last;
  12385. var stack = this.tmpBuf, sp = 0;
  12386. do {
  12387. var b = this.readByte();
  12388. if (b < 0) {
  12389. error('unexpected EOF in bcmap');
  12390. }
  12391. last = !(b & 0x80);
  12392. stack[sp++] = b & 0x7F;
  12393. } while (!last);
  12394. var i = size, buffer = 0, bufferSize = 0;
  12395. while (i >= 0) {
  12396. while (bufferSize < 8 && stack.length > 0) {
  12397. buffer = (stack[--sp] << bufferSize) | buffer;
  12398. bufferSize += 7;
  12399. }
  12400. num[i] = buffer & 255;
  12401. i--;
  12402. buffer >>= 8;
  12403. bufferSize -= 8;
  12404. }
  12405. },
  12406. readHexSigned: function (num, size) {
  12407. this.readHexNumber(num, size);
  12408. var sign = num[size] & 1 ? 255 : 0;
  12409. var c = 0;
  12410. for (var i = 0; i <= size; i++) {
  12411. c = ((c & 1) << 8) | num[i];
  12412. num[i] = (c >> 1) ^ sign;
  12413. }
  12414. },
  12415. readString: function () {
  12416. var len = this.readNumber();
  12417. var s = '';
  12418. for (var i = 0; i < len; i++) {
  12419. s += String.fromCharCode(this.readNumber());
  12420. }
  12421. return s;
  12422. }
  12423. };
  12424. function processBinaryCMap(url, cMap, extend) {
  12425. var data = fetchBinaryData(url);
  12426. var stream = new BinaryCMapStream(data);
  12427. var header = stream.readByte();
  12428. cMap.vertical = !!(header & 1);
  12429. var useCMap = null;
  12430. var start = new Uint8Array(MAX_NUM_SIZE);
  12431. var end = new Uint8Array(MAX_NUM_SIZE);
  12432. var char = new Uint8Array(MAX_NUM_SIZE);
  12433. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12434. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12435. var code;
  12436. var b;
  12437. while ((b = stream.readByte()) >= 0) {
  12438. var type = b >> 5;
  12439. if (type === 7) { // metadata, e.g. comment or usecmap
  12440. switch (b & 0x1F) {
  12441. case 0:
  12442. stream.readString(); // skipping comment
  12443. break;
  12444. case 1:
  12445. useCMap = stream.readString();
  12446. break;
  12447. }
  12448. continue;
  12449. }
  12450. var sequence = !!(b & 0x10);
  12451. var dataSize = b & 15;
  12452. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12453. var ucs2DataSize = 1;
  12454. var subitemsCount = stream.readNumber();
  12455. var i;
  12456. switch (type) {
  12457. case 0: // codespacerange
  12458. stream.readHex(start, dataSize);
  12459. stream.readHexNumber(end, dataSize);
  12460. addHex(end, start, dataSize);
  12461. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12462. hexToInt(end, dataSize));
  12463. for (i = 1; i < subitemsCount; i++) {
  12464. incHex(end, dataSize);
  12465. stream.readHexNumber(start, dataSize);
  12466. addHex(start, end, dataSize);
  12467. stream.readHexNumber(end, dataSize);
  12468. addHex(end, start, dataSize);
  12469. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12470. hexToInt(end, dataSize));
  12471. }
  12472. break;
  12473. case 1: // notdefrange
  12474. stream.readHex(start, dataSize);
  12475. stream.readHexNumber(end, dataSize);
  12476. addHex(end, start, dataSize);
  12477. code = stream.readNumber();
  12478. // undefined range, skipping
  12479. for (i = 1; i < subitemsCount; i++) {
  12480. incHex(end, dataSize);
  12481. stream.readHexNumber(start, dataSize);
  12482. addHex(start, end, dataSize);
  12483. stream.readHexNumber(end, dataSize);
  12484. addHex(end, start, dataSize);
  12485. code = stream.readNumber();
  12486. // nop
  12487. }
  12488. break;
  12489. case 2: // cidchar
  12490. stream.readHex(char, dataSize);
  12491. code = stream.readNumber();
  12492. cMap.mapOne(hexToInt(char, dataSize), code);
  12493. for (i = 1; i < subitemsCount; i++) {
  12494. incHex(char, dataSize);
  12495. if (!sequence) {
  12496. stream.readHexNumber(tmp, dataSize);
  12497. addHex(char, tmp, dataSize);
  12498. }
  12499. code = stream.readSigned() + (code + 1);
  12500. cMap.mapOne(hexToInt(char, dataSize), code);
  12501. }
  12502. break;
  12503. case 3: // cidrange
  12504. stream.readHex(start, dataSize);
  12505. stream.readHexNumber(end, dataSize);
  12506. addHex(end, start, dataSize);
  12507. code = stream.readNumber();
  12508. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12509. code);
  12510. for (i = 1; i < subitemsCount; i++) {
  12511. incHex(end, dataSize);
  12512. if (!sequence) {
  12513. stream.readHexNumber(start, dataSize);
  12514. addHex(start, end, dataSize);
  12515. } else {
  12516. start.set(end);
  12517. }
  12518. stream.readHexNumber(end, dataSize);
  12519. addHex(end, start, dataSize);
  12520. code = stream.readNumber();
  12521. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12522. code);
  12523. }
  12524. break;
  12525. case 4: // bfchar
  12526. stream.readHex(char, ucs2DataSize);
  12527. stream.readHex(charCode, dataSize);
  12528. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12529. hexToStr(charCode, dataSize));
  12530. for (i = 1; i < subitemsCount; i++) {
  12531. incHex(char, ucs2DataSize);
  12532. if (!sequence) {
  12533. stream.readHexNumber(tmp, ucs2DataSize);
  12534. addHex(char, tmp, ucs2DataSize);
  12535. }
  12536. incHex(charCode, dataSize);
  12537. stream.readHexSigned(tmp, dataSize);
  12538. addHex(charCode, tmp, dataSize);
  12539. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12540. hexToStr(charCode, dataSize));
  12541. }
  12542. break;
  12543. case 5: // bfrange
  12544. stream.readHex(start, ucs2DataSize);
  12545. stream.readHexNumber(end, ucs2DataSize);
  12546. addHex(end, start, ucs2DataSize);
  12547. stream.readHex(charCode, dataSize);
  12548. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12549. hexToInt(end, ucs2DataSize),
  12550. hexToStr(charCode, dataSize));
  12551. for (i = 1; i < subitemsCount; i++) {
  12552. incHex(end, ucs2DataSize);
  12553. if (!sequence) {
  12554. stream.readHexNumber(start, ucs2DataSize);
  12555. addHex(start, end, ucs2DataSize);
  12556. } else {
  12557. start.set(end);
  12558. }
  12559. stream.readHexNumber(end, ucs2DataSize);
  12560. addHex(end, start, ucs2DataSize);
  12561. stream.readHex(charCode, dataSize);
  12562. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12563. hexToInt(end, ucs2DataSize),
  12564. hexToStr(charCode, dataSize));
  12565. }
  12566. break;
  12567. default:
  12568. error('Unknown type: ' + type);
  12569. break;
  12570. }
  12571. }
  12572. if (useCMap) {
  12573. extend(useCMap);
  12574. }
  12575. return cMap;
  12576. }
  12577. function BinaryCMapReader() {}
  12578. BinaryCMapReader.prototype = {
  12579. read: processBinaryCMap
  12580. };
  12581. return BinaryCMapReader;
  12582. })();
  12583. var CMapFactory = (function CMapFactoryClosure() {
  12584. function strToInt(str) {
  12585. var a = 0;
  12586. for (var i = 0; i < str.length; i++) {
  12587. a = (a << 8) | str.charCodeAt(i);
  12588. }
  12589. return a >>> 0;
  12590. }
  12591. function expectString(obj) {
  12592. if (!isString(obj)) {
  12593. error('Malformed CMap: expected string.');
  12594. }
  12595. }
  12596. function expectInt(obj) {
  12597. if (!isInt(obj)) {
  12598. error('Malformed CMap: expected int.');
  12599. }
  12600. }
  12601. function parseBfChar(cMap, lexer) {
  12602. while (true) {
  12603. var obj = lexer.getObj();
  12604. if (isEOF(obj)) {
  12605. break;
  12606. }
  12607. if (isCmd(obj, 'endbfchar')) {
  12608. return;
  12609. }
  12610. expectString(obj);
  12611. var src = strToInt(obj);
  12612. obj = lexer.getObj();
  12613. // TODO are /dstName used?
  12614. expectString(obj);
  12615. var dst = obj;
  12616. cMap.mapOne(src, dst);
  12617. }
  12618. }
  12619. function parseBfRange(cMap, lexer) {
  12620. while (true) {
  12621. var obj = lexer.getObj();
  12622. if (isEOF(obj)) {
  12623. break;
  12624. }
  12625. if (isCmd(obj, 'endbfrange')) {
  12626. return;
  12627. }
  12628. expectString(obj);
  12629. var low = strToInt(obj);
  12630. obj = lexer.getObj();
  12631. expectString(obj);
  12632. var high = strToInt(obj);
  12633. obj = lexer.getObj();
  12634. if (isInt(obj) || isString(obj)) {
  12635. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12636. cMap.mapBfRange(low, high, dstLow);
  12637. } else if (isCmd(obj, '[')) {
  12638. obj = lexer.getObj();
  12639. var array = [];
  12640. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12641. array.push(obj);
  12642. obj = lexer.getObj();
  12643. }
  12644. cMap.mapBfRangeToArray(low, high, array);
  12645. } else {
  12646. break;
  12647. }
  12648. }
  12649. error('Invalid bf range.');
  12650. }
  12651. function parseCidChar(cMap, lexer) {
  12652. while (true) {
  12653. var obj = lexer.getObj();
  12654. if (isEOF(obj)) {
  12655. break;
  12656. }
  12657. if (isCmd(obj, 'endcidchar')) {
  12658. return;
  12659. }
  12660. expectString(obj);
  12661. var src = strToInt(obj);
  12662. obj = lexer.getObj();
  12663. expectInt(obj);
  12664. var dst = obj;
  12665. cMap.mapOne(src, dst);
  12666. }
  12667. }
  12668. function parseCidRange(cMap, lexer) {
  12669. while (true) {
  12670. var obj = lexer.getObj();
  12671. if (isEOF(obj)) {
  12672. break;
  12673. }
  12674. if (isCmd(obj, 'endcidrange')) {
  12675. return;
  12676. }
  12677. expectString(obj);
  12678. var low = strToInt(obj);
  12679. obj = lexer.getObj();
  12680. expectString(obj);
  12681. var high = strToInt(obj);
  12682. obj = lexer.getObj();
  12683. expectInt(obj);
  12684. var dstLow = obj;
  12685. cMap.mapCidRange(low, high, dstLow);
  12686. }
  12687. }
  12688. function parseCodespaceRange(cMap, lexer) {
  12689. while (true) {
  12690. var obj = lexer.getObj();
  12691. if (isEOF(obj)) {
  12692. break;
  12693. }
  12694. if (isCmd(obj, 'endcodespacerange')) {
  12695. return;
  12696. }
  12697. if (!isString(obj)) {
  12698. break;
  12699. }
  12700. var low = strToInt(obj);
  12701. obj = lexer.getObj();
  12702. if (!isString(obj)) {
  12703. break;
  12704. }
  12705. var high = strToInt(obj);
  12706. cMap.addCodespaceRange(obj.length, low, high);
  12707. }
  12708. error('Invalid codespace range.');
  12709. }
  12710. function parseWMode(cMap, lexer) {
  12711. var obj = lexer.getObj();
  12712. if (isInt(obj)) {
  12713. cMap.vertical = !!obj;
  12714. }
  12715. }
  12716. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12717. var previous;
  12718. var embededUseCMap;
  12719. objLoop: while (true) {
  12720. var obj = lexer.getObj();
  12721. if (isEOF(obj)) {
  12722. break;
  12723. } else if (isName(obj)) {
  12724. if (obj.name === 'WMode') {
  12725. parseWMode(cMap, lexer);
  12726. }
  12727. previous = obj;
  12728. } else if (isCmd(obj)) {
  12729. switch (obj.cmd) {
  12730. case 'endcmap':
  12731. break objLoop;
  12732. case 'usecmap':
  12733. if (isName(previous)) {
  12734. embededUseCMap = previous.name;
  12735. }
  12736. break;
  12737. case 'begincodespacerange':
  12738. parseCodespaceRange(cMap, lexer);
  12739. break;
  12740. case 'beginbfchar':
  12741. parseBfChar(cMap, lexer);
  12742. break;
  12743. case 'begincidchar':
  12744. parseCidChar(cMap, lexer);
  12745. break;
  12746. case 'beginbfrange':
  12747. parseBfRange(cMap, lexer);
  12748. break;
  12749. case 'begincidrange':
  12750. parseCidRange(cMap, lexer);
  12751. break;
  12752. }
  12753. }
  12754. }
  12755. if (!useCMap && embededUseCMap) {
  12756. // Load the usecmap definition from the file only if there wasn't one
  12757. // specified.
  12758. useCMap = embededUseCMap;
  12759. }
  12760. if (useCMap) {
  12761. extendCMap(cMap, builtInCMapParams, useCMap);
  12762. }
  12763. }
  12764. function extendCMap(cMap, builtInCMapParams, useCMap) {
  12765. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  12766. // If there aren't any code space ranges defined clone all the parent ones
  12767. // into this cMap.
  12768. if (cMap.numCodespaceRanges === 0) {
  12769. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  12770. for (var i = 0; i < useCodespaceRanges.length; i++) {
  12771. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  12772. }
  12773. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  12774. }
  12775. // Merge the map into the current one, making sure not to override
  12776. // any previously defined entries.
  12777. cMap.useCMap.forEach(function(key, value) {
  12778. if (!cMap.contains(key)) {
  12779. cMap.mapOne(key, cMap.useCMap.lookup(key));
  12780. }
  12781. });
  12782. }
  12783. function parseBinaryCMap(name, builtInCMapParams) {
  12784. var url = builtInCMapParams.url + name + '.bcmap';
  12785. var cMap = new CMap(true);
  12786. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  12787. extendCMap(cMap, builtInCMapParams, useCMap);
  12788. });
  12789. return cMap;
  12790. }
  12791. function createBuiltInCMap(name, builtInCMapParams) {
  12792. if (name === 'Identity-H') {
  12793. return new IdentityCMap(false, 2);
  12794. } else if (name === 'Identity-V') {
  12795. return new IdentityCMap(true, 2);
  12796. }
  12797. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  12798. error('Unknown cMap name: ' + name);
  12799. }
  12800. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  12801. if (builtInCMapParams.packed) {
  12802. return parseBinaryCMap(name, builtInCMapParams);
  12803. }
  12804. var request = new XMLHttpRequest();
  12805. var url = builtInCMapParams.url + name;
  12806. request.open('GET', url, false);
  12807. request.send(null);
  12808. if (!request.responseText) {
  12809. error('Unable to get cMap at: ' + url);
  12810. }
  12811. var cMap = new CMap(true);
  12812. var lexer = new Lexer(new StringStream(request.responseText));
  12813. parseCMap(cMap, lexer, builtInCMapParams, null);
  12814. return cMap;
  12815. }
  12816. return {
  12817. create: function (encoding, builtInCMapParams, useCMap) {
  12818. if (isName(encoding)) {
  12819. return createBuiltInCMap(encoding.name, builtInCMapParams);
  12820. } else if (isStream(encoding)) {
  12821. var cMap = new CMap();
  12822. var lexer = new Lexer(encoding);
  12823. try {
  12824. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  12825. } catch (e) {
  12826. warn('Invalid CMap data. ' + e);
  12827. }
  12828. return cMap;
  12829. }
  12830. error('Encoding required.');
  12831. }
  12832. };
  12833. })();
  12834. // Unicode Private Use Area
  12835. var PRIVATE_USE_OFFSET_START = 0xE000;
  12836. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  12837. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  12838. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  12839. // except for Type 3 fonts
  12840. var PDF_GLYPH_SPACE_UNITS = 1000;
  12841. // Hinting is currently disabled due to unknown problems on windows
  12842. // in tracemonkey and various other pdfs with type1 fonts.
  12843. var HINTING_ENABLED = false;
  12844. // Accented charactars are not displayed properly on windows, using this flag
  12845. // to control analysis of seac charstrings.
  12846. var SEAC_ANALYSIS_ENABLED = false;
  12847. var FontFlags = {
  12848. FixedPitch: 1,
  12849. Serif: 2,
  12850. Symbolic: 4,
  12851. Script: 8,
  12852. Nonsymbolic: 32,
  12853. Italic: 64,
  12854. AllCap: 65536,
  12855. SmallCap: 131072,
  12856. ForceBold: 262144
  12857. };
  12858. var Encodings = {
  12859. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12860. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12861. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  12862. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  12863. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  12864. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  12865. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  12866. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  12867. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  12868. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  12869. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  12870. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  12871. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  12872. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  12873. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  12874. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  12875. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  12876. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  12877. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  12878. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12879. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  12880. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  12881. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  12882. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  12883. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  12884. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  12885. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  12886. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  12887. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  12888. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  12889. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  12890. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  12891. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  12892. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  12893. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  12894. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  12895. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  12896. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  12897. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  12898. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  12899. 'Ydieresissmall'],
  12900. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12901. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12902. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  12903. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  12904. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  12905. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  12906. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  12907. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  12908. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  12909. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  12910. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  12911. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  12912. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  12913. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  12914. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  12915. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  12916. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  12917. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  12918. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  12919. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  12920. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  12921. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  12922. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  12923. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  12924. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  12925. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  12926. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  12927. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  12928. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  12929. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  12930. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  12931. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  12932. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  12933. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  12934. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  12935. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  12936. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  12937. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  12938. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  12939. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  12940. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12941. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12942. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12943. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12944. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12945. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12946. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12947. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12948. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12949. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12950. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12951. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  12952. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  12953. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  12954. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12955. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  12956. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  12957. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  12958. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  12959. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12960. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12961. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12962. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12963. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12964. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12965. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12966. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12967. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12968. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12969. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12970. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12971. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12972. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12973. 'ogonek', 'caron'],
  12974. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12975. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12976. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12977. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12978. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12979. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12980. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12981. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12982. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12983. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12984. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12985. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12986. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12987. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12988. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12989. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12990. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12991. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12992. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12993. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12994. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12995. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12996. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12997. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12998. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12999. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13000. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13001. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13002. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13003. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13004. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13005. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13006. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13007. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13008. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13009. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13010. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13011. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13012. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13013. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13014. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13015. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13016. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13017. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13018. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13019. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13020. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13021. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13022. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13023. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13024. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13025. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13026. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13027. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13028. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13029. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13030. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13031. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13032. 'ydieresis'],
  13033. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13034. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13035. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13036. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13037. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13038. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13039. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13040. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13041. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13042. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13043. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13044. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13045. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13046. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13047. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13048. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13049. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13050. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13051. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13052. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13053. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13054. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13055. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13056. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13057. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13058. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13059. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13060. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13061. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13062. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13063. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13064. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13065. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13066. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13067. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13068. 'bracerightbt'],
  13069. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13070. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13071. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13072. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13073. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13074. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13075. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13076. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13077. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13078. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13079. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13080. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13081. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13082. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13083. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13084. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13085. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13086. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13087. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13088. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13089. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13090. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13091. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13092. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13093. };
  13094. /**
  13095. * Hold a map of decoded fonts and of the standard fourteen Type1
  13096. * fonts and their acronyms.
  13097. */
  13098. var stdFontMap = {
  13099. 'ArialNarrow': 'Helvetica',
  13100. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13101. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13102. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13103. 'ArialBlack': 'Helvetica',
  13104. 'ArialBlack-Bold': 'Helvetica-Bold',
  13105. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13106. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13107. 'Arial': 'Helvetica',
  13108. 'Arial-Bold': 'Helvetica-Bold',
  13109. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13110. 'Arial-Italic': 'Helvetica-Oblique',
  13111. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13112. 'Arial-BoldMT': 'Helvetica-Bold',
  13113. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13114. 'ArialMT': 'Helvetica',
  13115. 'Courier-Bold': 'Courier-Bold',
  13116. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13117. 'Courier-Italic': 'Courier-Oblique',
  13118. 'CourierNew': 'Courier',
  13119. 'CourierNew-Bold': 'Courier-Bold',
  13120. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13121. 'CourierNew-Italic': 'Courier-Oblique',
  13122. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13123. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13124. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13125. 'CourierNewPSMT': 'Courier',
  13126. 'Helvetica': 'Helvetica',
  13127. 'Helvetica-Bold': 'Helvetica-Bold',
  13128. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13129. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13130. 'Helvetica-Italic': 'Helvetica-Oblique',
  13131. 'Helvetica-Oblique':'Helvetica-Oblique',
  13132. 'Symbol-Bold': 'Symbol',
  13133. 'Symbol-BoldItalic': 'Symbol',
  13134. 'Symbol-Italic': 'Symbol',
  13135. 'TimesNewRoman': 'Times-Roman',
  13136. 'TimesNewRoman-Bold': 'Times-Bold',
  13137. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13138. 'TimesNewRoman-Italic': 'Times-Italic',
  13139. 'TimesNewRomanPS': 'Times-Roman',
  13140. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13141. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13142. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13143. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13144. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13145. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13146. 'TimesNewRomanPSMT': 'Times-Roman',
  13147. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13148. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13149. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13150. };
  13151. /**
  13152. * Holds the map of the non-standard fonts that might be included as a standard
  13153. * fonts without glyph data.
  13154. */
  13155. var nonStdFontMap = {
  13156. 'CenturyGothic': 'Helvetica',
  13157. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13158. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13159. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13160. 'ComicSansMS': 'Comic Sans MS',
  13161. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13162. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13163. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13164. 'LucidaConsole': 'Courier',
  13165. 'LucidaConsole-Bold': 'Courier-Bold',
  13166. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13167. 'LucidaConsole-Italic': 'Courier-Oblique',
  13168. 'MS-Gothic': 'MS Gothic',
  13169. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13170. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13171. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13172. 'MS-Mincho': 'MS Mincho',
  13173. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13174. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13175. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13176. 'MS-PGothic': 'MS PGothic',
  13177. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13178. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13179. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13180. 'MS-PMincho': 'MS PMincho',
  13181. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13182. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13183. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13184. 'Wingdings': 'ZapfDingbats'
  13185. };
  13186. var serifFonts = {
  13187. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13188. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13189. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13190. 'Arno': true, 'Aster': true, 'Aurora': true,
  13191. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13192. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13193. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13194. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13195. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13196. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13197. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13198. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13199. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13200. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13201. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13202. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13203. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13204. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13205. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13206. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13207. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13208. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13209. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13210. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13211. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13212. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13213. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13214. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13215. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13216. 'Miller': true, 'Minion': true, 'Modern': true,
  13217. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13218. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13219. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13220. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13221. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13222. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13223. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13224. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13225. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13226. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13227. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13228. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13229. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13230. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13231. };
  13232. var symbolsFonts = {
  13233. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13234. };
  13235. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13236. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13237. // glyphs, but common for some set of the standard fonts.
  13238. var GlyphMapForStandardFonts = {
  13239. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13240. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13241. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13242. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13243. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13244. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13245. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13246. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13247. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13248. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13249. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13250. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13251. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13252. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13253. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13254. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13255. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13256. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13257. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13258. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13259. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13260. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13261. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13262. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13263. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13264. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13265. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13266. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13267. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13268. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13269. '298': 380, '305': 963,
  13270. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13271. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13272. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13273. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13274. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13275. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13276. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13277. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13278. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13279. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13280. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13281. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13282. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13283. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13284. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13285. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13286. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13287. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13288. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13289. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13290. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13291. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13292. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13293. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13294. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13295. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13296. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13297. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13298. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13299. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13300. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13301. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13302. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13303. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13304. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13305. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13306. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13307. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13308. };
  13309. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13310. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13311. // to the similar equivalents in the normal characters range.
  13312. var SpecialPUASymbols = {
  13313. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13314. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13315. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13316. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13317. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13318. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13319. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13320. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13321. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13322. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13323. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13324. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13325. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13326. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13327. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13328. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13329. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13330. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13331. '63723': 0x239B, // parenlefttp (0xF8EB)
  13332. '63724': 0x239C, // parenleftex (0xF8EC)
  13333. '63725': 0x239D, // parenleftbt (0xF8ED)
  13334. '63734': 0x239E, // parenrighttp (0xF8F6)
  13335. '63735': 0x239F, // parenrightex (0xF8F7)
  13336. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13337. };
  13338. function mapSpecialUnicodeValues(code) {
  13339. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13340. return 0;
  13341. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13342. return (SpecialPUASymbols[code] || code);
  13343. }
  13344. return code;
  13345. }
  13346. var UnicodeRanges = [
  13347. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13348. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13349. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13350. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13351. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13352. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13353. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13354. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13355. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13356. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13357. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13358. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13359. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13360. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13361. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13362. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13363. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13364. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13365. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13366. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13367. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13368. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13369. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13370. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13371. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13372. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13373. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13374. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13375. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13376. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13377. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13378. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13379. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13380. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13381. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13382. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13383. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13384. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13385. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13386. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13387. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13388. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13389. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13390. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13391. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13392. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13393. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13394. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13395. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13396. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13397. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13398. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13399. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13400. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13401. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13402. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13403. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13404. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13405. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13406. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13407. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13408. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13409. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13410. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13411. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13412. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13413. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13414. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13415. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13416. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13417. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13418. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13419. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13420. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13421. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13422. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13423. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13424. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13425. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13426. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13427. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13428. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13429. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13430. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13431. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13432. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13433. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13434. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13435. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13436. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13437. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13438. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13439. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13440. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13441. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13442. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13443. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13444. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13445. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13446. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13447. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13448. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13449. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13450. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13451. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13452. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13453. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13454. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13455. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13456. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13457. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13458. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13459. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13460. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13461. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13462. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13463. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13464. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13465. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13466. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13467. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13468. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13469. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13470. ];
  13471. var MacStandardGlyphOrdering = [
  13472. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13473. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13474. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13475. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13476. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13477. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13478. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13479. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13480. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13481. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13482. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13483. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13484. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13485. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13486. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13487. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13488. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13489. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13490. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13491. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13492. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13493. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13494. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13495. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13496. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13497. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13498. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13499. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13500. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13501. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13502. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13503. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13504. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13505. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13506. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13507. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13508. function getUnicodeRangeFor(value) {
  13509. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13510. var range = UnicodeRanges[i];
  13511. if (value >= range.begin && value < range.end) {
  13512. return i;
  13513. }
  13514. }
  13515. return -1;
  13516. }
  13517. function isRTLRangeFor(value) {
  13518. var range = UnicodeRanges[13];
  13519. if (value >= range.begin && value < range.end) {
  13520. return true;
  13521. }
  13522. range = UnicodeRanges[11];
  13523. if (value >= range.begin && value < range.end) {
  13524. return true;
  13525. }
  13526. return false;
  13527. }
  13528. // The normalization table is obtained by filtering the Unicode characters
  13529. // database with <compat> entries.
  13530. var NormalizedUnicodes = {
  13531. '\u00A8': '\u0020\u0308',
  13532. '\u00AF': '\u0020\u0304',
  13533. '\u00B4': '\u0020\u0301',
  13534. '\u00B5': '\u03BC',
  13535. '\u00B8': '\u0020\u0327',
  13536. '\u0132': '\u0049\u004A',
  13537. '\u0133': '\u0069\u006A',
  13538. '\u013F': '\u004C\u00B7',
  13539. '\u0140': '\u006C\u00B7',
  13540. '\u0149': '\u02BC\u006E',
  13541. '\u017F': '\u0073',
  13542. '\u01C4': '\u0044\u017D',
  13543. '\u01C5': '\u0044\u017E',
  13544. '\u01C6': '\u0064\u017E',
  13545. '\u01C7': '\u004C\u004A',
  13546. '\u01C8': '\u004C\u006A',
  13547. '\u01C9': '\u006C\u006A',
  13548. '\u01CA': '\u004E\u004A',
  13549. '\u01CB': '\u004E\u006A',
  13550. '\u01CC': '\u006E\u006A',
  13551. '\u01F1': '\u0044\u005A',
  13552. '\u01F2': '\u0044\u007A',
  13553. '\u01F3': '\u0064\u007A',
  13554. '\u02D8': '\u0020\u0306',
  13555. '\u02D9': '\u0020\u0307',
  13556. '\u02DA': '\u0020\u030A',
  13557. '\u02DB': '\u0020\u0328',
  13558. '\u02DC': '\u0020\u0303',
  13559. '\u02DD': '\u0020\u030B',
  13560. '\u037A': '\u0020\u0345',
  13561. '\u0384': '\u0020\u0301',
  13562. '\u03D0': '\u03B2',
  13563. '\u03D1': '\u03B8',
  13564. '\u03D2': '\u03A5',
  13565. '\u03D5': '\u03C6',
  13566. '\u03D6': '\u03C0',
  13567. '\u03F0': '\u03BA',
  13568. '\u03F1': '\u03C1',
  13569. '\u03F2': '\u03C2',
  13570. '\u03F4': '\u0398',
  13571. '\u03F5': '\u03B5',
  13572. '\u03F9': '\u03A3',
  13573. '\u0587': '\u0565\u0582',
  13574. '\u0675': '\u0627\u0674',
  13575. '\u0676': '\u0648\u0674',
  13576. '\u0677': '\u06C7\u0674',
  13577. '\u0678': '\u064A\u0674',
  13578. '\u0E33': '\u0E4D\u0E32',
  13579. '\u0EB3': '\u0ECD\u0EB2',
  13580. '\u0EDC': '\u0EAB\u0E99',
  13581. '\u0EDD': '\u0EAB\u0EA1',
  13582. '\u0F77': '\u0FB2\u0F81',
  13583. '\u0F79': '\u0FB3\u0F81',
  13584. '\u1E9A': '\u0061\u02BE',
  13585. '\u1FBD': '\u0020\u0313',
  13586. '\u1FBF': '\u0020\u0313',
  13587. '\u1FC0': '\u0020\u0342',
  13588. '\u1FFE': '\u0020\u0314',
  13589. '\u2002': '\u0020',
  13590. '\u2003': '\u0020',
  13591. '\u2004': '\u0020',
  13592. '\u2005': '\u0020',
  13593. '\u2006': '\u0020',
  13594. '\u2008': '\u0020',
  13595. '\u2009': '\u0020',
  13596. '\u200A': '\u0020',
  13597. '\u2017': '\u0020\u0333',
  13598. '\u2024': '\u002E',
  13599. '\u2025': '\u002E\u002E',
  13600. '\u2026': '\u002E\u002E\u002E',
  13601. '\u2033': '\u2032\u2032',
  13602. '\u2034': '\u2032\u2032\u2032',
  13603. '\u2036': '\u2035\u2035',
  13604. '\u2037': '\u2035\u2035\u2035',
  13605. '\u203C': '\u0021\u0021',
  13606. '\u203E': '\u0020\u0305',
  13607. '\u2047': '\u003F\u003F',
  13608. '\u2048': '\u003F\u0021',
  13609. '\u2049': '\u0021\u003F',
  13610. '\u2057': '\u2032\u2032\u2032\u2032',
  13611. '\u205F': '\u0020',
  13612. '\u20A8': '\u0052\u0073',
  13613. '\u2100': '\u0061\u002F\u0063',
  13614. '\u2101': '\u0061\u002F\u0073',
  13615. '\u2103': '\u00B0\u0043',
  13616. '\u2105': '\u0063\u002F\u006F',
  13617. '\u2106': '\u0063\u002F\u0075',
  13618. '\u2107': '\u0190',
  13619. '\u2109': '\u00B0\u0046',
  13620. '\u2116': '\u004E\u006F',
  13621. '\u2121': '\u0054\u0045\u004C',
  13622. '\u2135': '\u05D0',
  13623. '\u2136': '\u05D1',
  13624. '\u2137': '\u05D2',
  13625. '\u2138': '\u05D3',
  13626. '\u213B': '\u0046\u0041\u0058',
  13627. '\u2160': '\u0049',
  13628. '\u2161': '\u0049\u0049',
  13629. '\u2162': '\u0049\u0049\u0049',
  13630. '\u2163': '\u0049\u0056',
  13631. '\u2164': '\u0056',
  13632. '\u2165': '\u0056\u0049',
  13633. '\u2166': '\u0056\u0049\u0049',
  13634. '\u2167': '\u0056\u0049\u0049\u0049',
  13635. '\u2168': '\u0049\u0058',
  13636. '\u2169': '\u0058',
  13637. '\u216A': '\u0058\u0049',
  13638. '\u216B': '\u0058\u0049\u0049',
  13639. '\u216C': '\u004C',
  13640. '\u216D': '\u0043',
  13641. '\u216E': '\u0044',
  13642. '\u216F': '\u004D',
  13643. '\u2170': '\u0069',
  13644. '\u2171': '\u0069\u0069',
  13645. '\u2172': '\u0069\u0069\u0069',
  13646. '\u2173': '\u0069\u0076',
  13647. '\u2174': '\u0076',
  13648. '\u2175': '\u0076\u0069',
  13649. '\u2176': '\u0076\u0069\u0069',
  13650. '\u2177': '\u0076\u0069\u0069\u0069',
  13651. '\u2178': '\u0069\u0078',
  13652. '\u2179': '\u0078',
  13653. '\u217A': '\u0078\u0069',
  13654. '\u217B': '\u0078\u0069\u0069',
  13655. '\u217C': '\u006C',
  13656. '\u217D': '\u0063',
  13657. '\u217E': '\u0064',
  13658. '\u217F': '\u006D',
  13659. '\u222C': '\u222B\u222B',
  13660. '\u222D': '\u222B\u222B\u222B',
  13661. '\u222F': '\u222E\u222E',
  13662. '\u2230': '\u222E\u222E\u222E',
  13663. '\u2474': '\u0028\u0031\u0029',
  13664. '\u2475': '\u0028\u0032\u0029',
  13665. '\u2476': '\u0028\u0033\u0029',
  13666. '\u2477': '\u0028\u0034\u0029',
  13667. '\u2478': '\u0028\u0035\u0029',
  13668. '\u2479': '\u0028\u0036\u0029',
  13669. '\u247A': '\u0028\u0037\u0029',
  13670. '\u247B': '\u0028\u0038\u0029',
  13671. '\u247C': '\u0028\u0039\u0029',
  13672. '\u247D': '\u0028\u0031\u0030\u0029',
  13673. '\u247E': '\u0028\u0031\u0031\u0029',
  13674. '\u247F': '\u0028\u0031\u0032\u0029',
  13675. '\u2480': '\u0028\u0031\u0033\u0029',
  13676. '\u2481': '\u0028\u0031\u0034\u0029',
  13677. '\u2482': '\u0028\u0031\u0035\u0029',
  13678. '\u2483': '\u0028\u0031\u0036\u0029',
  13679. '\u2484': '\u0028\u0031\u0037\u0029',
  13680. '\u2485': '\u0028\u0031\u0038\u0029',
  13681. '\u2486': '\u0028\u0031\u0039\u0029',
  13682. '\u2487': '\u0028\u0032\u0030\u0029',
  13683. '\u2488': '\u0031\u002E',
  13684. '\u2489': '\u0032\u002E',
  13685. '\u248A': '\u0033\u002E',
  13686. '\u248B': '\u0034\u002E',
  13687. '\u248C': '\u0035\u002E',
  13688. '\u248D': '\u0036\u002E',
  13689. '\u248E': '\u0037\u002E',
  13690. '\u248F': '\u0038\u002E',
  13691. '\u2490': '\u0039\u002E',
  13692. '\u2491': '\u0031\u0030\u002E',
  13693. '\u2492': '\u0031\u0031\u002E',
  13694. '\u2493': '\u0031\u0032\u002E',
  13695. '\u2494': '\u0031\u0033\u002E',
  13696. '\u2495': '\u0031\u0034\u002E',
  13697. '\u2496': '\u0031\u0035\u002E',
  13698. '\u2497': '\u0031\u0036\u002E',
  13699. '\u2498': '\u0031\u0037\u002E',
  13700. '\u2499': '\u0031\u0038\u002E',
  13701. '\u249A': '\u0031\u0039\u002E',
  13702. '\u249B': '\u0032\u0030\u002E',
  13703. '\u249C': '\u0028\u0061\u0029',
  13704. '\u249D': '\u0028\u0062\u0029',
  13705. '\u249E': '\u0028\u0063\u0029',
  13706. '\u249F': '\u0028\u0064\u0029',
  13707. '\u24A0': '\u0028\u0065\u0029',
  13708. '\u24A1': '\u0028\u0066\u0029',
  13709. '\u24A2': '\u0028\u0067\u0029',
  13710. '\u24A3': '\u0028\u0068\u0029',
  13711. '\u24A4': '\u0028\u0069\u0029',
  13712. '\u24A5': '\u0028\u006A\u0029',
  13713. '\u24A6': '\u0028\u006B\u0029',
  13714. '\u24A7': '\u0028\u006C\u0029',
  13715. '\u24A8': '\u0028\u006D\u0029',
  13716. '\u24A9': '\u0028\u006E\u0029',
  13717. '\u24AA': '\u0028\u006F\u0029',
  13718. '\u24AB': '\u0028\u0070\u0029',
  13719. '\u24AC': '\u0028\u0071\u0029',
  13720. '\u24AD': '\u0028\u0072\u0029',
  13721. '\u24AE': '\u0028\u0073\u0029',
  13722. '\u24AF': '\u0028\u0074\u0029',
  13723. '\u24B0': '\u0028\u0075\u0029',
  13724. '\u24B1': '\u0028\u0076\u0029',
  13725. '\u24B2': '\u0028\u0077\u0029',
  13726. '\u24B3': '\u0028\u0078\u0029',
  13727. '\u24B4': '\u0028\u0079\u0029',
  13728. '\u24B5': '\u0028\u007A\u0029',
  13729. '\u2A0C': '\u222B\u222B\u222B\u222B',
  13730. '\u2A74': '\u003A\u003A\u003D',
  13731. '\u2A75': '\u003D\u003D',
  13732. '\u2A76': '\u003D\u003D\u003D',
  13733. '\u2E9F': '\u6BCD',
  13734. '\u2EF3': '\u9F9F',
  13735. '\u2F00': '\u4E00',
  13736. '\u2F01': '\u4E28',
  13737. '\u2F02': '\u4E36',
  13738. '\u2F03': '\u4E3F',
  13739. '\u2F04': '\u4E59',
  13740. '\u2F05': '\u4E85',
  13741. '\u2F06': '\u4E8C',
  13742. '\u2F07': '\u4EA0',
  13743. '\u2F08': '\u4EBA',
  13744. '\u2F09': '\u513F',
  13745. '\u2F0A': '\u5165',
  13746. '\u2F0B': '\u516B',
  13747. '\u2F0C': '\u5182',
  13748. '\u2F0D': '\u5196',
  13749. '\u2F0E': '\u51AB',
  13750. '\u2F0F': '\u51E0',
  13751. '\u2F10': '\u51F5',
  13752. '\u2F11': '\u5200',
  13753. '\u2F12': '\u529B',
  13754. '\u2F13': '\u52F9',
  13755. '\u2F14': '\u5315',
  13756. '\u2F15': '\u531A',
  13757. '\u2F16': '\u5338',
  13758. '\u2F17': '\u5341',
  13759. '\u2F18': '\u535C',
  13760. '\u2F19': '\u5369',
  13761. '\u2F1A': '\u5382',
  13762. '\u2F1B': '\u53B6',
  13763. '\u2F1C': '\u53C8',
  13764. '\u2F1D': '\u53E3',
  13765. '\u2F1E': '\u56D7',
  13766. '\u2F1F': '\u571F',
  13767. '\u2F20': '\u58EB',
  13768. '\u2F21': '\u5902',
  13769. '\u2F22': '\u590A',
  13770. '\u2F23': '\u5915',
  13771. '\u2F24': '\u5927',
  13772. '\u2F25': '\u5973',
  13773. '\u2F26': '\u5B50',
  13774. '\u2F27': '\u5B80',
  13775. '\u2F28': '\u5BF8',
  13776. '\u2F29': '\u5C0F',
  13777. '\u2F2A': '\u5C22',
  13778. '\u2F2B': '\u5C38',
  13779. '\u2F2C': '\u5C6E',
  13780. '\u2F2D': '\u5C71',
  13781. '\u2F2E': '\u5DDB',
  13782. '\u2F2F': '\u5DE5',
  13783. '\u2F30': '\u5DF1',
  13784. '\u2F31': '\u5DFE',
  13785. '\u2F32': '\u5E72',
  13786. '\u2F33': '\u5E7A',
  13787. '\u2F34': '\u5E7F',
  13788. '\u2F35': '\u5EF4',
  13789. '\u2F36': '\u5EFE',
  13790. '\u2F37': '\u5F0B',
  13791. '\u2F38': '\u5F13',
  13792. '\u2F39': '\u5F50',
  13793. '\u2F3A': '\u5F61',
  13794. '\u2F3B': '\u5F73',
  13795. '\u2F3C': '\u5FC3',
  13796. '\u2F3D': '\u6208',
  13797. '\u2F3E': '\u6236',
  13798. '\u2F3F': '\u624B',
  13799. '\u2F40': '\u652F',
  13800. '\u2F41': '\u6534',
  13801. '\u2F42': '\u6587',
  13802. '\u2F43': '\u6597',
  13803. '\u2F44': '\u65A4',
  13804. '\u2F45': '\u65B9',
  13805. '\u2F46': '\u65E0',
  13806. '\u2F47': '\u65E5',
  13807. '\u2F48': '\u66F0',
  13808. '\u2F49': '\u6708',
  13809. '\u2F4A': '\u6728',
  13810. '\u2F4B': '\u6B20',
  13811. '\u2F4C': '\u6B62',
  13812. '\u2F4D': '\u6B79',
  13813. '\u2F4E': '\u6BB3',
  13814. '\u2F4F': '\u6BCB',
  13815. '\u2F50': '\u6BD4',
  13816. '\u2F51': '\u6BDB',
  13817. '\u2F52': '\u6C0F',
  13818. '\u2F53': '\u6C14',
  13819. '\u2F54': '\u6C34',
  13820. '\u2F55': '\u706B',
  13821. '\u2F56': '\u722A',
  13822. '\u2F57': '\u7236',
  13823. '\u2F58': '\u723B',
  13824. '\u2F59': '\u723F',
  13825. '\u2F5A': '\u7247',
  13826. '\u2F5B': '\u7259',
  13827. '\u2F5C': '\u725B',
  13828. '\u2F5D': '\u72AC',
  13829. '\u2F5E': '\u7384',
  13830. '\u2F5F': '\u7389',
  13831. '\u2F60': '\u74DC',
  13832. '\u2F61': '\u74E6',
  13833. '\u2F62': '\u7518',
  13834. '\u2F63': '\u751F',
  13835. '\u2F64': '\u7528',
  13836. '\u2F65': '\u7530',
  13837. '\u2F66': '\u758B',
  13838. '\u2F67': '\u7592',
  13839. '\u2F68': '\u7676',
  13840. '\u2F69': '\u767D',
  13841. '\u2F6A': '\u76AE',
  13842. '\u2F6B': '\u76BF',
  13843. '\u2F6C': '\u76EE',
  13844. '\u2F6D': '\u77DB',
  13845. '\u2F6E': '\u77E2',
  13846. '\u2F6F': '\u77F3',
  13847. '\u2F70': '\u793A',
  13848. '\u2F71': '\u79B8',
  13849. '\u2F72': '\u79BE',
  13850. '\u2F73': '\u7A74',
  13851. '\u2F74': '\u7ACB',
  13852. '\u2F75': '\u7AF9',
  13853. '\u2F76': '\u7C73',
  13854. '\u2F77': '\u7CF8',
  13855. '\u2F78': '\u7F36',
  13856. '\u2F79': '\u7F51',
  13857. '\u2F7A': '\u7F8A',
  13858. '\u2F7B': '\u7FBD',
  13859. '\u2F7C': '\u8001',
  13860. '\u2F7D': '\u800C',
  13861. '\u2F7E': '\u8012',
  13862. '\u2F7F': '\u8033',
  13863. '\u2F80': '\u807F',
  13864. '\u2F81': '\u8089',
  13865. '\u2F82': '\u81E3',
  13866. '\u2F83': '\u81EA',
  13867. '\u2F84': '\u81F3',
  13868. '\u2F85': '\u81FC',
  13869. '\u2F86': '\u820C',
  13870. '\u2F87': '\u821B',
  13871. '\u2F88': '\u821F',
  13872. '\u2F89': '\u826E',
  13873. '\u2F8A': '\u8272',
  13874. '\u2F8B': '\u8278',
  13875. '\u2F8C': '\u864D',
  13876. '\u2F8D': '\u866B',
  13877. '\u2F8E': '\u8840',
  13878. '\u2F8F': '\u884C',
  13879. '\u2F90': '\u8863',
  13880. '\u2F91': '\u897E',
  13881. '\u2F92': '\u898B',
  13882. '\u2F93': '\u89D2',
  13883. '\u2F94': '\u8A00',
  13884. '\u2F95': '\u8C37',
  13885. '\u2F96': '\u8C46',
  13886. '\u2F97': '\u8C55',
  13887. '\u2F98': '\u8C78',
  13888. '\u2F99': '\u8C9D',
  13889. '\u2F9A': '\u8D64',
  13890. '\u2F9B': '\u8D70',
  13891. '\u2F9C': '\u8DB3',
  13892. '\u2F9D': '\u8EAB',
  13893. '\u2F9E': '\u8ECA',
  13894. '\u2F9F': '\u8F9B',
  13895. '\u2FA0': '\u8FB0',
  13896. '\u2FA1': '\u8FB5',
  13897. '\u2FA2': '\u9091',
  13898. '\u2FA3': '\u9149',
  13899. '\u2FA4': '\u91C6',
  13900. '\u2FA5': '\u91CC',
  13901. '\u2FA6': '\u91D1',
  13902. '\u2FA7': '\u9577',
  13903. '\u2FA8': '\u9580',
  13904. '\u2FA9': '\u961C',
  13905. '\u2FAA': '\u96B6',
  13906. '\u2FAB': '\u96B9',
  13907. '\u2FAC': '\u96E8',
  13908. '\u2FAD': '\u9751',
  13909. '\u2FAE': '\u975E',
  13910. '\u2FAF': '\u9762',
  13911. '\u2FB0': '\u9769',
  13912. '\u2FB1': '\u97CB',
  13913. '\u2FB2': '\u97ED',
  13914. '\u2FB3': '\u97F3',
  13915. '\u2FB4': '\u9801',
  13916. '\u2FB5': '\u98A8',
  13917. '\u2FB6': '\u98DB',
  13918. '\u2FB7': '\u98DF',
  13919. '\u2FB8': '\u9996',
  13920. '\u2FB9': '\u9999',
  13921. '\u2FBA': '\u99AC',
  13922. '\u2FBB': '\u9AA8',
  13923. '\u2FBC': '\u9AD8',
  13924. '\u2FBD': '\u9ADF',
  13925. '\u2FBE': '\u9B25',
  13926. '\u2FBF': '\u9B2F',
  13927. '\u2FC0': '\u9B32',
  13928. '\u2FC1': '\u9B3C',
  13929. '\u2FC2': '\u9B5A',
  13930. '\u2FC3': '\u9CE5',
  13931. '\u2FC4': '\u9E75',
  13932. '\u2FC5': '\u9E7F',
  13933. '\u2FC6': '\u9EA5',
  13934. '\u2FC7': '\u9EBB',
  13935. '\u2FC8': '\u9EC3',
  13936. '\u2FC9': '\u9ECD',
  13937. '\u2FCA': '\u9ED1',
  13938. '\u2FCB': '\u9EF9',
  13939. '\u2FCC': '\u9EFD',
  13940. '\u2FCD': '\u9F0E',
  13941. '\u2FCE': '\u9F13',
  13942. '\u2FCF': '\u9F20',
  13943. '\u2FD0': '\u9F3B',
  13944. '\u2FD1': '\u9F4A',
  13945. '\u2FD2': '\u9F52',
  13946. '\u2FD3': '\u9F8D',
  13947. '\u2FD4': '\u9F9C',
  13948. '\u2FD5': '\u9FA0',
  13949. '\u3036': '\u3012',
  13950. '\u3038': '\u5341',
  13951. '\u3039': '\u5344',
  13952. '\u303A': '\u5345',
  13953. '\u309B': '\u0020\u3099',
  13954. '\u309C': '\u0020\u309A',
  13955. '\u3131': '\u1100',
  13956. '\u3132': '\u1101',
  13957. '\u3133': '\u11AA',
  13958. '\u3134': '\u1102',
  13959. '\u3135': '\u11AC',
  13960. '\u3136': '\u11AD',
  13961. '\u3137': '\u1103',
  13962. '\u3138': '\u1104',
  13963. '\u3139': '\u1105',
  13964. '\u313A': '\u11B0',
  13965. '\u313B': '\u11B1',
  13966. '\u313C': '\u11B2',
  13967. '\u313D': '\u11B3',
  13968. '\u313E': '\u11B4',
  13969. '\u313F': '\u11B5',
  13970. '\u3140': '\u111A',
  13971. '\u3141': '\u1106',
  13972. '\u3142': '\u1107',
  13973. '\u3143': '\u1108',
  13974. '\u3144': '\u1121',
  13975. '\u3145': '\u1109',
  13976. '\u3146': '\u110A',
  13977. '\u3147': '\u110B',
  13978. '\u3148': '\u110C',
  13979. '\u3149': '\u110D',
  13980. '\u314A': '\u110E',
  13981. '\u314B': '\u110F',
  13982. '\u314C': '\u1110',
  13983. '\u314D': '\u1111',
  13984. '\u314E': '\u1112',
  13985. '\u314F': '\u1161',
  13986. '\u3150': '\u1162',
  13987. '\u3151': '\u1163',
  13988. '\u3152': '\u1164',
  13989. '\u3153': '\u1165',
  13990. '\u3154': '\u1166',
  13991. '\u3155': '\u1167',
  13992. '\u3156': '\u1168',
  13993. '\u3157': '\u1169',
  13994. '\u3158': '\u116A',
  13995. '\u3159': '\u116B',
  13996. '\u315A': '\u116C',
  13997. '\u315B': '\u116D',
  13998. '\u315C': '\u116E',
  13999. '\u315D': '\u116F',
  14000. '\u315E': '\u1170',
  14001. '\u315F': '\u1171',
  14002. '\u3160': '\u1172',
  14003. '\u3161': '\u1173',
  14004. '\u3162': '\u1174',
  14005. '\u3163': '\u1175',
  14006. '\u3164': '\u1160',
  14007. '\u3165': '\u1114',
  14008. '\u3166': '\u1115',
  14009. '\u3167': '\u11C7',
  14010. '\u3168': '\u11C8',
  14011. '\u3169': '\u11CC',
  14012. '\u316A': '\u11CE',
  14013. '\u316B': '\u11D3',
  14014. '\u316C': '\u11D7',
  14015. '\u316D': '\u11D9',
  14016. '\u316E': '\u111C',
  14017. '\u316F': '\u11DD',
  14018. '\u3170': '\u11DF',
  14019. '\u3171': '\u111D',
  14020. '\u3172': '\u111E',
  14021. '\u3173': '\u1120',
  14022. '\u3174': '\u1122',
  14023. '\u3175': '\u1123',
  14024. '\u3176': '\u1127',
  14025. '\u3177': '\u1129',
  14026. '\u3178': '\u112B',
  14027. '\u3179': '\u112C',
  14028. '\u317A': '\u112D',
  14029. '\u317B': '\u112E',
  14030. '\u317C': '\u112F',
  14031. '\u317D': '\u1132',
  14032. '\u317E': '\u1136',
  14033. '\u317F': '\u1140',
  14034. '\u3180': '\u1147',
  14035. '\u3181': '\u114C',
  14036. '\u3182': '\u11F1',
  14037. '\u3183': '\u11F2',
  14038. '\u3184': '\u1157',
  14039. '\u3185': '\u1158',
  14040. '\u3186': '\u1159',
  14041. '\u3187': '\u1184',
  14042. '\u3188': '\u1185',
  14043. '\u3189': '\u1188',
  14044. '\u318A': '\u1191',
  14045. '\u318B': '\u1192',
  14046. '\u318C': '\u1194',
  14047. '\u318D': '\u119E',
  14048. '\u318E': '\u11A1',
  14049. '\u3200': '\u0028\u1100\u0029',
  14050. '\u3201': '\u0028\u1102\u0029',
  14051. '\u3202': '\u0028\u1103\u0029',
  14052. '\u3203': '\u0028\u1105\u0029',
  14053. '\u3204': '\u0028\u1106\u0029',
  14054. '\u3205': '\u0028\u1107\u0029',
  14055. '\u3206': '\u0028\u1109\u0029',
  14056. '\u3207': '\u0028\u110B\u0029',
  14057. '\u3208': '\u0028\u110C\u0029',
  14058. '\u3209': '\u0028\u110E\u0029',
  14059. '\u320A': '\u0028\u110F\u0029',
  14060. '\u320B': '\u0028\u1110\u0029',
  14061. '\u320C': '\u0028\u1111\u0029',
  14062. '\u320D': '\u0028\u1112\u0029',
  14063. '\u320E': '\u0028\u1100\u1161\u0029',
  14064. '\u320F': '\u0028\u1102\u1161\u0029',
  14065. '\u3210': '\u0028\u1103\u1161\u0029',
  14066. '\u3211': '\u0028\u1105\u1161\u0029',
  14067. '\u3212': '\u0028\u1106\u1161\u0029',
  14068. '\u3213': '\u0028\u1107\u1161\u0029',
  14069. '\u3214': '\u0028\u1109\u1161\u0029',
  14070. '\u3215': '\u0028\u110B\u1161\u0029',
  14071. '\u3216': '\u0028\u110C\u1161\u0029',
  14072. '\u3217': '\u0028\u110E\u1161\u0029',
  14073. '\u3218': '\u0028\u110F\u1161\u0029',
  14074. '\u3219': '\u0028\u1110\u1161\u0029',
  14075. '\u321A': '\u0028\u1111\u1161\u0029',
  14076. '\u321B': '\u0028\u1112\u1161\u0029',
  14077. '\u321C': '\u0028\u110C\u116E\u0029',
  14078. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14079. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14080. '\u3220': '\u0028\u4E00\u0029',
  14081. '\u3221': '\u0028\u4E8C\u0029',
  14082. '\u3222': '\u0028\u4E09\u0029',
  14083. '\u3223': '\u0028\u56DB\u0029',
  14084. '\u3224': '\u0028\u4E94\u0029',
  14085. '\u3225': '\u0028\u516D\u0029',
  14086. '\u3226': '\u0028\u4E03\u0029',
  14087. '\u3227': '\u0028\u516B\u0029',
  14088. '\u3228': '\u0028\u4E5D\u0029',
  14089. '\u3229': '\u0028\u5341\u0029',
  14090. '\u322A': '\u0028\u6708\u0029',
  14091. '\u322B': '\u0028\u706B\u0029',
  14092. '\u322C': '\u0028\u6C34\u0029',
  14093. '\u322D': '\u0028\u6728\u0029',
  14094. '\u322E': '\u0028\u91D1\u0029',
  14095. '\u322F': '\u0028\u571F\u0029',
  14096. '\u3230': '\u0028\u65E5\u0029',
  14097. '\u3231': '\u0028\u682A\u0029',
  14098. '\u3232': '\u0028\u6709\u0029',
  14099. '\u3233': '\u0028\u793E\u0029',
  14100. '\u3234': '\u0028\u540D\u0029',
  14101. '\u3235': '\u0028\u7279\u0029',
  14102. '\u3236': '\u0028\u8CA1\u0029',
  14103. '\u3237': '\u0028\u795D\u0029',
  14104. '\u3238': '\u0028\u52B4\u0029',
  14105. '\u3239': '\u0028\u4EE3\u0029',
  14106. '\u323A': '\u0028\u547C\u0029',
  14107. '\u323B': '\u0028\u5B66\u0029',
  14108. '\u323C': '\u0028\u76E3\u0029',
  14109. '\u323D': '\u0028\u4F01\u0029',
  14110. '\u323E': '\u0028\u8CC7\u0029',
  14111. '\u323F': '\u0028\u5354\u0029',
  14112. '\u3240': '\u0028\u796D\u0029',
  14113. '\u3241': '\u0028\u4F11\u0029',
  14114. '\u3242': '\u0028\u81EA\u0029',
  14115. '\u3243': '\u0028\u81F3\u0029',
  14116. '\u32C0': '\u0031\u6708',
  14117. '\u32C1': '\u0032\u6708',
  14118. '\u32C2': '\u0033\u6708',
  14119. '\u32C3': '\u0034\u6708',
  14120. '\u32C4': '\u0035\u6708',
  14121. '\u32C5': '\u0036\u6708',
  14122. '\u32C6': '\u0037\u6708',
  14123. '\u32C7': '\u0038\u6708',
  14124. '\u32C8': '\u0039\u6708',
  14125. '\u32C9': '\u0031\u0030\u6708',
  14126. '\u32CA': '\u0031\u0031\u6708',
  14127. '\u32CB': '\u0031\u0032\u6708',
  14128. '\u3358': '\u0030\u70B9',
  14129. '\u3359': '\u0031\u70B9',
  14130. '\u335A': '\u0032\u70B9',
  14131. '\u335B': '\u0033\u70B9',
  14132. '\u335C': '\u0034\u70B9',
  14133. '\u335D': '\u0035\u70B9',
  14134. '\u335E': '\u0036\u70B9',
  14135. '\u335F': '\u0037\u70B9',
  14136. '\u3360': '\u0038\u70B9',
  14137. '\u3361': '\u0039\u70B9',
  14138. '\u3362': '\u0031\u0030\u70B9',
  14139. '\u3363': '\u0031\u0031\u70B9',
  14140. '\u3364': '\u0031\u0032\u70B9',
  14141. '\u3365': '\u0031\u0033\u70B9',
  14142. '\u3366': '\u0031\u0034\u70B9',
  14143. '\u3367': '\u0031\u0035\u70B9',
  14144. '\u3368': '\u0031\u0036\u70B9',
  14145. '\u3369': '\u0031\u0037\u70B9',
  14146. '\u336A': '\u0031\u0038\u70B9',
  14147. '\u336B': '\u0031\u0039\u70B9',
  14148. '\u336C': '\u0032\u0030\u70B9',
  14149. '\u336D': '\u0032\u0031\u70B9',
  14150. '\u336E': '\u0032\u0032\u70B9',
  14151. '\u336F': '\u0032\u0033\u70B9',
  14152. '\u3370': '\u0032\u0034\u70B9',
  14153. '\u33E0': '\u0031\u65E5',
  14154. '\u33E1': '\u0032\u65E5',
  14155. '\u33E2': '\u0033\u65E5',
  14156. '\u33E3': '\u0034\u65E5',
  14157. '\u33E4': '\u0035\u65E5',
  14158. '\u33E5': '\u0036\u65E5',
  14159. '\u33E6': '\u0037\u65E5',
  14160. '\u33E7': '\u0038\u65E5',
  14161. '\u33E8': '\u0039\u65E5',
  14162. '\u33E9': '\u0031\u0030\u65E5',
  14163. '\u33EA': '\u0031\u0031\u65E5',
  14164. '\u33EB': '\u0031\u0032\u65E5',
  14165. '\u33EC': '\u0031\u0033\u65E5',
  14166. '\u33ED': '\u0031\u0034\u65E5',
  14167. '\u33EE': '\u0031\u0035\u65E5',
  14168. '\u33EF': '\u0031\u0036\u65E5',
  14169. '\u33F0': '\u0031\u0037\u65E5',
  14170. '\u33F1': '\u0031\u0038\u65E5',
  14171. '\u33F2': '\u0031\u0039\u65E5',
  14172. '\u33F3': '\u0032\u0030\u65E5',
  14173. '\u33F4': '\u0032\u0031\u65E5',
  14174. '\u33F5': '\u0032\u0032\u65E5',
  14175. '\u33F6': '\u0032\u0033\u65E5',
  14176. '\u33F7': '\u0032\u0034\u65E5',
  14177. '\u33F8': '\u0032\u0035\u65E5',
  14178. '\u33F9': '\u0032\u0036\u65E5',
  14179. '\u33FA': '\u0032\u0037\u65E5',
  14180. '\u33FB': '\u0032\u0038\u65E5',
  14181. '\u33FC': '\u0032\u0039\u65E5',
  14182. '\u33FD': '\u0033\u0030\u65E5',
  14183. '\u33FE': '\u0033\u0031\u65E5',
  14184. '\uFB00': '\u0066\u0066',
  14185. '\uFB01': '\u0066\u0069',
  14186. '\uFB02': '\u0066\u006C',
  14187. '\uFB03': '\u0066\u0066\u0069',
  14188. '\uFB04': '\u0066\u0066\u006C',
  14189. '\uFB05': '\u017F\u0074',
  14190. '\uFB06': '\u0073\u0074',
  14191. '\uFB13': '\u0574\u0576',
  14192. '\uFB14': '\u0574\u0565',
  14193. '\uFB15': '\u0574\u056B',
  14194. '\uFB16': '\u057E\u0576',
  14195. '\uFB17': '\u0574\u056D',
  14196. '\uFB4F': '\u05D0\u05DC',
  14197. '\uFB50': '\u0671',
  14198. '\uFB51': '\u0671',
  14199. '\uFB52': '\u067B',
  14200. '\uFB53': '\u067B',
  14201. '\uFB54': '\u067B',
  14202. '\uFB55': '\u067B',
  14203. '\uFB56': '\u067E',
  14204. '\uFB57': '\u067E',
  14205. '\uFB58': '\u067E',
  14206. '\uFB59': '\u067E',
  14207. '\uFB5A': '\u0680',
  14208. '\uFB5B': '\u0680',
  14209. '\uFB5C': '\u0680',
  14210. '\uFB5D': '\u0680',
  14211. '\uFB5E': '\u067A',
  14212. '\uFB5F': '\u067A',
  14213. '\uFB60': '\u067A',
  14214. '\uFB61': '\u067A',
  14215. '\uFB62': '\u067F',
  14216. '\uFB63': '\u067F',
  14217. '\uFB64': '\u067F',
  14218. '\uFB65': '\u067F',
  14219. '\uFB66': '\u0679',
  14220. '\uFB67': '\u0679',
  14221. '\uFB68': '\u0679',
  14222. '\uFB69': '\u0679',
  14223. '\uFB6A': '\u06A4',
  14224. '\uFB6B': '\u06A4',
  14225. '\uFB6C': '\u06A4',
  14226. '\uFB6D': '\u06A4',
  14227. '\uFB6E': '\u06A6',
  14228. '\uFB6F': '\u06A6',
  14229. '\uFB70': '\u06A6',
  14230. '\uFB71': '\u06A6',
  14231. '\uFB72': '\u0684',
  14232. '\uFB73': '\u0684',
  14233. '\uFB74': '\u0684',
  14234. '\uFB75': '\u0684',
  14235. '\uFB76': '\u0683',
  14236. '\uFB77': '\u0683',
  14237. '\uFB78': '\u0683',
  14238. '\uFB79': '\u0683',
  14239. '\uFB7A': '\u0686',
  14240. '\uFB7B': '\u0686',
  14241. '\uFB7C': '\u0686',
  14242. '\uFB7D': '\u0686',
  14243. '\uFB7E': '\u0687',
  14244. '\uFB7F': '\u0687',
  14245. '\uFB80': '\u0687',
  14246. '\uFB81': '\u0687',
  14247. '\uFB82': '\u068D',
  14248. '\uFB83': '\u068D',
  14249. '\uFB84': '\u068C',
  14250. '\uFB85': '\u068C',
  14251. '\uFB86': '\u068E',
  14252. '\uFB87': '\u068E',
  14253. '\uFB88': '\u0688',
  14254. '\uFB89': '\u0688',
  14255. '\uFB8A': '\u0698',
  14256. '\uFB8B': '\u0698',
  14257. '\uFB8C': '\u0691',
  14258. '\uFB8D': '\u0691',
  14259. '\uFB8E': '\u06A9',
  14260. '\uFB8F': '\u06A9',
  14261. '\uFB90': '\u06A9',
  14262. '\uFB91': '\u06A9',
  14263. '\uFB92': '\u06AF',
  14264. '\uFB93': '\u06AF',
  14265. '\uFB94': '\u06AF',
  14266. '\uFB95': '\u06AF',
  14267. '\uFB96': '\u06B3',
  14268. '\uFB97': '\u06B3',
  14269. '\uFB98': '\u06B3',
  14270. '\uFB99': '\u06B3',
  14271. '\uFB9A': '\u06B1',
  14272. '\uFB9B': '\u06B1',
  14273. '\uFB9C': '\u06B1',
  14274. '\uFB9D': '\u06B1',
  14275. '\uFB9E': '\u06BA',
  14276. '\uFB9F': '\u06BA',
  14277. '\uFBA0': '\u06BB',
  14278. '\uFBA1': '\u06BB',
  14279. '\uFBA2': '\u06BB',
  14280. '\uFBA3': '\u06BB',
  14281. '\uFBA4': '\u06C0',
  14282. '\uFBA5': '\u06C0',
  14283. '\uFBA6': '\u06C1',
  14284. '\uFBA7': '\u06C1',
  14285. '\uFBA8': '\u06C1',
  14286. '\uFBA9': '\u06C1',
  14287. '\uFBAA': '\u06BE',
  14288. '\uFBAB': '\u06BE',
  14289. '\uFBAC': '\u06BE',
  14290. '\uFBAD': '\u06BE',
  14291. '\uFBAE': '\u06D2',
  14292. '\uFBAF': '\u06D2',
  14293. '\uFBB0': '\u06D3',
  14294. '\uFBB1': '\u06D3',
  14295. '\uFBD3': '\u06AD',
  14296. '\uFBD4': '\u06AD',
  14297. '\uFBD5': '\u06AD',
  14298. '\uFBD6': '\u06AD',
  14299. '\uFBD7': '\u06C7',
  14300. '\uFBD8': '\u06C7',
  14301. '\uFBD9': '\u06C6',
  14302. '\uFBDA': '\u06C6',
  14303. '\uFBDB': '\u06C8',
  14304. '\uFBDC': '\u06C8',
  14305. '\uFBDD': '\u0677',
  14306. '\uFBDE': '\u06CB',
  14307. '\uFBDF': '\u06CB',
  14308. '\uFBE0': '\u06C5',
  14309. '\uFBE1': '\u06C5',
  14310. '\uFBE2': '\u06C9',
  14311. '\uFBE3': '\u06C9',
  14312. '\uFBE4': '\u06D0',
  14313. '\uFBE5': '\u06D0',
  14314. '\uFBE6': '\u06D0',
  14315. '\uFBE7': '\u06D0',
  14316. '\uFBE8': '\u0649',
  14317. '\uFBE9': '\u0649',
  14318. '\uFBEA': '\u0626\u0627',
  14319. '\uFBEB': '\u0626\u0627',
  14320. '\uFBEC': '\u0626\u06D5',
  14321. '\uFBED': '\u0626\u06D5',
  14322. '\uFBEE': '\u0626\u0648',
  14323. '\uFBEF': '\u0626\u0648',
  14324. '\uFBF0': '\u0626\u06C7',
  14325. '\uFBF1': '\u0626\u06C7',
  14326. '\uFBF2': '\u0626\u06C6',
  14327. '\uFBF3': '\u0626\u06C6',
  14328. '\uFBF4': '\u0626\u06C8',
  14329. '\uFBF5': '\u0626\u06C8',
  14330. '\uFBF6': '\u0626\u06D0',
  14331. '\uFBF7': '\u0626\u06D0',
  14332. '\uFBF8': '\u0626\u06D0',
  14333. '\uFBF9': '\u0626\u0649',
  14334. '\uFBFA': '\u0626\u0649',
  14335. '\uFBFB': '\u0626\u0649',
  14336. '\uFBFC': '\u06CC',
  14337. '\uFBFD': '\u06CC',
  14338. '\uFBFE': '\u06CC',
  14339. '\uFBFF': '\u06CC',
  14340. '\uFC00': '\u0626\u062C',
  14341. '\uFC01': '\u0626\u062D',
  14342. '\uFC02': '\u0626\u0645',
  14343. '\uFC03': '\u0626\u0649',
  14344. '\uFC04': '\u0626\u064A',
  14345. '\uFC05': '\u0628\u062C',
  14346. '\uFC06': '\u0628\u062D',
  14347. '\uFC07': '\u0628\u062E',
  14348. '\uFC08': '\u0628\u0645',
  14349. '\uFC09': '\u0628\u0649',
  14350. '\uFC0A': '\u0628\u064A',
  14351. '\uFC0B': '\u062A\u062C',
  14352. '\uFC0C': '\u062A\u062D',
  14353. '\uFC0D': '\u062A\u062E',
  14354. '\uFC0E': '\u062A\u0645',
  14355. '\uFC0F': '\u062A\u0649',
  14356. '\uFC10': '\u062A\u064A',
  14357. '\uFC11': '\u062B\u062C',
  14358. '\uFC12': '\u062B\u0645',
  14359. '\uFC13': '\u062B\u0649',
  14360. '\uFC14': '\u062B\u064A',
  14361. '\uFC15': '\u062C\u062D',
  14362. '\uFC16': '\u062C\u0645',
  14363. '\uFC17': '\u062D\u062C',
  14364. '\uFC18': '\u062D\u0645',
  14365. '\uFC19': '\u062E\u062C',
  14366. '\uFC1A': '\u062E\u062D',
  14367. '\uFC1B': '\u062E\u0645',
  14368. '\uFC1C': '\u0633\u062C',
  14369. '\uFC1D': '\u0633\u062D',
  14370. '\uFC1E': '\u0633\u062E',
  14371. '\uFC1F': '\u0633\u0645',
  14372. '\uFC20': '\u0635\u062D',
  14373. '\uFC21': '\u0635\u0645',
  14374. '\uFC22': '\u0636\u062C',
  14375. '\uFC23': '\u0636\u062D',
  14376. '\uFC24': '\u0636\u062E',
  14377. '\uFC25': '\u0636\u0645',
  14378. '\uFC26': '\u0637\u062D',
  14379. '\uFC27': '\u0637\u0645',
  14380. '\uFC28': '\u0638\u0645',
  14381. '\uFC29': '\u0639\u062C',
  14382. '\uFC2A': '\u0639\u0645',
  14383. '\uFC2B': '\u063A\u062C',
  14384. '\uFC2C': '\u063A\u0645',
  14385. '\uFC2D': '\u0641\u062C',
  14386. '\uFC2E': '\u0641\u062D',
  14387. '\uFC2F': '\u0641\u062E',
  14388. '\uFC30': '\u0641\u0645',
  14389. '\uFC31': '\u0641\u0649',
  14390. '\uFC32': '\u0641\u064A',
  14391. '\uFC33': '\u0642\u062D',
  14392. '\uFC34': '\u0642\u0645',
  14393. '\uFC35': '\u0642\u0649',
  14394. '\uFC36': '\u0642\u064A',
  14395. '\uFC37': '\u0643\u0627',
  14396. '\uFC38': '\u0643\u062C',
  14397. '\uFC39': '\u0643\u062D',
  14398. '\uFC3A': '\u0643\u062E',
  14399. '\uFC3B': '\u0643\u0644',
  14400. '\uFC3C': '\u0643\u0645',
  14401. '\uFC3D': '\u0643\u0649',
  14402. '\uFC3E': '\u0643\u064A',
  14403. '\uFC3F': '\u0644\u062C',
  14404. '\uFC40': '\u0644\u062D',
  14405. '\uFC41': '\u0644\u062E',
  14406. '\uFC42': '\u0644\u0645',
  14407. '\uFC43': '\u0644\u0649',
  14408. '\uFC44': '\u0644\u064A',
  14409. '\uFC45': '\u0645\u062C',
  14410. '\uFC46': '\u0645\u062D',
  14411. '\uFC47': '\u0645\u062E',
  14412. '\uFC48': '\u0645\u0645',
  14413. '\uFC49': '\u0645\u0649',
  14414. '\uFC4A': '\u0645\u064A',
  14415. '\uFC4B': '\u0646\u062C',
  14416. '\uFC4C': '\u0646\u062D',
  14417. '\uFC4D': '\u0646\u062E',
  14418. '\uFC4E': '\u0646\u0645',
  14419. '\uFC4F': '\u0646\u0649',
  14420. '\uFC50': '\u0646\u064A',
  14421. '\uFC51': '\u0647\u062C',
  14422. '\uFC52': '\u0647\u0645',
  14423. '\uFC53': '\u0647\u0649',
  14424. '\uFC54': '\u0647\u064A',
  14425. '\uFC55': '\u064A\u062C',
  14426. '\uFC56': '\u064A\u062D',
  14427. '\uFC57': '\u064A\u062E',
  14428. '\uFC58': '\u064A\u0645',
  14429. '\uFC59': '\u064A\u0649',
  14430. '\uFC5A': '\u064A\u064A',
  14431. '\uFC5B': '\u0630\u0670',
  14432. '\uFC5C': '\u0631\u0670',
  14433. '\uFC5D': '\u0649\u0670',
  14434. '\uFC5E': '\u0020\u064C\u0651',
  14435. '\uFC5F': '\u0020\u064D\u0651',
  14436. '\uFC60': '\u0020\u064E\u0651',
  14437. '\uFC61': '\u0020\u064F\u0651',
  14438. '\uFC62': '\u0020\u0650\u0651',
  14439. '\uFC63': '\u0020\u0651\u0670',
  14440. '\uFC64': '\u0626\u0631',
  14441. '\uFC65': '\u0626\u0632',
  14442. '\uFC66': '\u0626\u0645',
  14443. '\uFC67': '\u0626\u0646',
  14444. '\uFC68': '\u0626\u0649',
  14445. '\uFC69': '\u0626\u064A',
  14446. '\uFC6A': '\u0628\u0631',
  14447. '\uFC6B': '\u0628\u0632',
  14448. '\uFC6C': '\u0628\u0645',
  14449. '\uFC6D': '\u0628\u0646',
  14450. '\uFC6E': '\u0628\u0649',
  14451. '\uFC6F': '\u0628\u064A',
  14452. '\uFC70': '\u062A\u0631',
  14453. '\uFC71': '\u062A\u0632',
  14454. '\uFC72': '\u062A\u0645',
  14455. '\uFC73': '\u062A\u0646',
  14456. '\uFC74': '\u062A\u0649',
  14457. '\uFC75': '\u062A\u064A',
  14458. '\uFC76': '\u062B\u0631',
  14459. '\uFC77': '\u062B\u0632',
  14460. '\uFC78': '\u062B\u0645',
  14461. '\uFC79': '\u062B\u0646',
  14462. '\uFC7A': '\u062B\u0649',
  14463. '\uFC7B': '\u062B\u064A',
  14464. '\uFC7C': '\u0641\u0649',
  14465. '\uFC7D': '\u0641\u064A',
  14466. '\uFC7E': '\u0642\u0649',
  14467. '\uFC7F': '\u0642\u064A',
  14468. '\uFC80': '\u0643\u0627',
  14469. '\uFC81': '\u0643\u0644',
  14470. '\uFC82': '\u0643\u0645',
  14471. '\uFC83': '\u0643\u0649',
  14472. '\uFC84': '\u0643\u064A',
  14473. '\uFC85': '\u0644\u0645',
  14474. '\uFC86': '\u0644\u0649',
  14475. '\uFC87': '\u0644\u064A',
  14476. '\uFC88': '\u0645\u0627',
  14477. '\uFC89': '\u0645\u0645',
  14478. '\uFC8A': '\u0646\u0631',
  14479. '\uFC8B': '\u0646\u0632',
  14480. '\uFC8C': '\u0646\u0645',
  14481. '\uFC8D': '\u0646\u0646',
  14482. '\uFC8E': '\u0646\u0649',
  14483. '\uFC8F': '\u0646\u064A',
  14484. '\uFC90': '\u0649\u0670',
  14485. '\uFC91': '\u064A\u0631',
  14486. '\uFC92': '\u064A\u0632',
  14487. '\uFC93': '\u064A\u0645',
  14488. '\uFC94': '\u064A\u0646',
  14489. '\uFC95': '\u064A\u0649',
  14490. '\uFC96': '\u064A\u064A',
  14491. '\uFC97': '\u0626\u062C',
  14492. '\uFC98': '\u0626\u062D',
  14493. '\uFC99': '\u0626\u062E',
  14494. '\uFC9A': '\u0626\u0645',
  14495. '\uFC9B': '\u0626\u0647',
  14496. '\uFC9C': '\u0628\u062C',
  14497. '\uFC9D': '\u0628\u062D',
  14498. '\uFC9E': '\u0628\u062E',
  14499. '\uFC9F': '\u0628\u0645',
  14500. '\uFCA0': '\u0628\u0647',
  14501. '\uFCA1': '\u062A\u062C',
  14502. '\uFCA2': '\u062A\u062D',
  14503. '\uFCA3': '\u062A\u062E',
  14504. '\uFCA4': '\u062A\u0645',
  14505. '\uFCA5': '\u062A\u0647',
  14506. '\uFCA6': '\u062B\u0645',
  14507. '\uFCA7': '\u062C\u062D',
  14508. '\uFCA8': '\u062C\u0645',
  14509. '\uFCA9': '\u062D\u062C',
  14510. '\uFCAA': '\u062D\u0645',
  14511. '\uFCAB': '\u062E\u062C',
  14512. '\uFCAC': '\u062E\u0645',
  14513. '\uFCAD': '\u0633\u062C',
  14514. '\uFCAE': '\u0633\u062D',
  14515. '\uFCAF': '\u0633\u062E',
  14516. '\uFCB0': '\u0633\u0645',
  14517. '\uFCB1': '\u0635\u062D',
  14518. '\uFCB2': '\u0635\u062E',
  14519. '\uFCB3': '\u0635\u0645',
  14520. '\uFCB4': '\u0636\u062C',
  14521. '\uFCB5': '\u0636\u062D',
  14522. '\uFCB6': '\u0636\u062E',
  14523. '\uFCB7': '\u0636\u0645',
  14524. '\uFCB8': '\u0637\u062D',
  14525. '\uFCB9': '\u0638\u0645',
  14526. '\uFCBA': '\u0639\u062C',
  14527. '\uFCBB': '\u0639\u0645',
  14528. '\uFCBC': '\u063A\u062C',
  14529. '\uFCBD': '\u063A\u0645',
  14530. '\uFCBE': '\u0641\u062C',
  14531. '\uFCBF': '\u0641\u062D',
  14532. '\uFCC0': '\u0641\u062E',
  14533. '\uFCC1': '\u0641\u0645',
  14534. '\uFCC2': '\u0642\u062D',
  14535. '\uFCC3': '\u0642\u0645',
  14536. '\uFCC4': '\u0643\u062C',
  14537. '\uFCC5': '\u0643\u062D',
  14538. '\uFCC6': '\u0643\u062E',
  14539. '\uFCC7': '\u0643\u0644',
  14540. '\uFCC8': '\u0643\u0645',
  14541. '\uFCC9': '\u0644\u062C',
  14542. '\uFCCA': '\u0644\u062D',
  14543. '\uFCCB': '\u0644\u062E',
  14544. '\uFCCC': '\u0644\u0645',
  14545. '\uFCCD': '\u0644\u0647',
  14546. '\uFCCE': '\u0645\u062C',
  14547. '\uFCCF': '\u0645\u062D',
  14548. '\uFCD0': '\u0645\u062E',
  14549. '\uFCD1': '\u0645\u0645',
  14550. '\uFCD2': '\u0646\u062C',
  14551. '\uFCD3': '\u0646\u062D',
  14552. '\uFCD4': '\u0646\u062E',
  14553. '\uFCD5': '\u0646\u0645',
  14554. '\uFCD6': '\u0646\u0647',
  14555. '\uFCD7': '\u0647\u062C',
  14556. '\uFCD8': '\u0647\u0645',
  14557. '\uFCD9': '\u0647\u0670',
  14558. '\uFCDA': '\u064A\u062C',
  14559. '\uFCDB': '\u064A\u062D',
  14560. '\uFCDC': '\u064A\u062E',
  14561. '\uFCDD': '\u064A\u0645',
  14562. '\uFCDE': '\u064A\u0647',
  14563. '\uFCDF': '\u0626\u0645',
  14564. '\uFCE0': '\u0626\u0647',
  14565. '\uFCE1': '\u0628\u0645',
  14566. '\uFCE2': '\u0628\u0647',
  14567. '\uFCE3': '\u062A\u0645',
  14568. '\uFCE4': '\u062A\u0647',
  14569. '\uFCE5': '\u062B\u0645',
  14570. '\uFCE6': '\u062B\u0647',
  14571. '\uFCE7': '\u0633\u0645',
  14572. '\uFCE8': '\u0633\u0647',
  14573. '\uFCE9': '\u0634\u0645',
  14574. '\uFCEA': '\u0634\u0647',
  14575. '\uFCEB': '\u0643\u0644',
  14576. '\uFCEC': '\u0643\u0645',
  14577. '\uFCED': '\u0644\u0645',
  14578. '\uFCEE': '\u0646\u0645',
  14579. '\uFCEF': '\u0646\u0647',
  14580. '\uFCF0': '\u064A\u0645',
  14581. '\uFCF1': '\u064A\u0647',
  14582. '\uFCF2': '\u0640\u064E\u0651',
  14583. '\uFCF3': '\u0640\u064F\u0651',
  14584. '\uFCF4': '\u0640\u0650\u0651',
  14585. '\uFCF5': '\u0637\u0649',
  14586. '\uFCF6': '\u0637\u064A',
  14587. '\uFCF7': '\u0639\u0649',
  14588. '\uFCF8': '\u0639\u064A',
  14589. '\uFCF9': '\u063A\u0649',
  14590. '\uFCFA': '\u063A\u064A',
  14591. '\uFCFB': '\u0633\u0649',
  14592. '\uFCFC': '\u0633\u064A',
  14593. '\uFCFD': '\u0634\u0649',
  14594. '\uFCFE': '\u0634\u064A',
  14595. '\uFCFF': '\u062D\u0649',
  14596. '\uFD00': '\u062D\u064A',
  14597. '\uFD01': '\u062C\u0649',
  14598. '\uFD02': '\u062C\u064A',
  14599. '\uFD03': '\u062E\u0649',
  14600. '\uFD04': '\u062E\u064A',
  14601. '\uFD05': '\u0635\u0649',
  14602. '\uFD06': '\u0635\u064A',
  14603. '\uFD07': '\u0636\u0649',
  14604. '\uFD08': '\u0636\u064A',
  14605. '\uFD09': '\u0634\u062C',
  14606. '\uFD0A': '\u0634\u062D',
  14607. '\uFD0B': '\u0634\u062E',
  14608. '\uFD0C': '\u0634\u0645',
  14609. '\uFD0D': '\u0634\u0631',
  14610. '\uFD0E': '\u0633\u0631',
  14611. '\uFD0F': '\u0635\u0631',
  14612. '\uFD10': '\u0636\u0631',
  14613. '\uFD11': '\u0637\u0649',
  14614. '\uFD12': '\u0637\u064A',
  14615. '\uFD13': '\u0639\u0649',
  14616. '\uFD14': '\u0639\u064A',
  14617. '\uFD15': '\u063A\u0649',
  14618. '\uFD16': '\u063A\u064A',
  14619. '\uFD17': '\u0633\u0649',
  14620. '\uFD18': '\u0633\u064A',
  14621. '\uFD19': '\u0634\u0649',
  14622. '\uFD1A': '\u0634\u064A',
  14623. '\uFD1B': '\u062D\u0649',
  14624. '\uFD1C': '\u062D\u064A',
  14625. '\uFD1D': '\u062C\u0649',
  14626. '\uFD1E': '\u062C\u064A',
  14627. '\uFD1F': '\u062E\u0649',
  14628. '\uFD20': '\u062E\u064A',
  14629. '\uFD21': '\u0635\u0649',
  14630. '\uFD22': '\u0635\u064A',
  14631. '\uFD23': '\u0636\u0649',
  14632. '\uFD24': '\u0636\u064A',
  14633. '\uFD25': '\u0634\u062C',
  14634. '\uFD26': '\u0634\u062D',
  14635. '\uFD27': '\u0634\u062E',
  14636. '\uFD28': '\u0634\u0645',
  14637. '\uFD29': '\u0634\u0631',
  14638. '\uFD2A': '\u0633\u0631',
  14639. '\uFD2B': '\u0635\u0631',
  14640. '\uFD2C': '\u0636\u0631',
  14641. '\uFD2D': '\u0634\u062C',
  14642. '\uFD2E': '\u0634\u062D',
  14643. '\uFD2F': '\u0634\u062E',
  14644. '\uFD30': '\u0634\u0645',
  14645. '\uFD31': '\u0633\u0647',
  14646. '\uFD32': '\u0634\u0647',
  14647. '\uFD33': '\u0637\u0645',
  14648. '\uFD34': '\u0633\u062C',
  14649. '\uFD35': '\u0633\u062D',
  14650. '\uFD36': '\u0633\u062E',
  14651. '\uFD37': '\u0634\u062C',
  14652. '\uFD38': '\u0634\u062D',
  14653. '\uFD39': '\u0634\u062E',
  14654. '\uFD3A': '\u0637\u0645',
  14655. '\uFD3B': '\u0638\u0645',
  14656. '\uFD3C': '\u0627\u064B',
  14657. '\uFD3D': '\u0627\u064B',
  14658. '\uFD50': '\u062A\u062C\u0645',
  14659. '\uFD51': '\u062A\u062D\u062C',
  14660. '\uFD52': '\u062A\u062D\u062C',
  14661. '\uFD53': '\u062A\u062D\u0645',
  14662. '\uFD54': '\u062A\u062E\u0645',
  14663. '\uFD55': '\u062A\u0645\u062C',
  14664. '\uFD56': '\u062A\u0645\u062D',
  14665. '\uFD57': '\u062A\u0645\u062E',
  14666. '\uFD58': '\u062C\u0645\u062D',
  14667. '\uFD59': '\u062C\u0645\u062D',
  14668. '\uFD5A': '\u062D\u0645\u064A',
  14669. '\uFD5B': '\u062D\u0645\u0649',
  14670. '\uFD5C': '\u0633\u062D\u062C',
  14671. '\uFD5D': '\u0633\u062C\u062D',
  14672. '\uFD5E': '\u0633\u062C\u0649',
  14673. '\uFD5F': '\u0633\u0645\u062D',
  14674. '\uFD60': '\u0633\u0645\u062D',
  14675. '\uFD61': '\u0633\u0645\u062C',
  14676. '\uFD62': '\u0633\u0645\u0645',
  14677. '\uFD63': '\u0633\u0645\u0645',
  14678. '\uFD64': '\u0635\u062D\u062D',
  14679. '\uFD65': '\u0635\u062D\u062D',
  14680. '\uFD66': '\u0635\u0645\u0645',
  14681. '\uFD67': '\u0634\u062D\u0645',
  14682. '\uFD68': '\u0634\u062D\u0645',
  14683. '\uFD69': '\u0634\u062C\u064A',
  14684. '\uFD6A': '\u0634\u0645\u062E',
  14685. '\uFD6B': '\u0634\u0645\u062E',
  14686. '\uFD6C': '\u0634\u0645\u0645',
  14687. '\uFD6D': '\u0634\u0645\u0645',
  14688. '\uFD6E': '\u0636\u062D\u0649',
  14689. '\uFD6F': '\u0636\u062E\u0645',
  14690. '\uFD70': '\u0636\u062E\u0645',
  14691. '\uFD71': '\u0637\u0645\u062D',
  14692. '\uFD72': '\u0637\u0645\u062D',
  14693. '\uFD73': '\u0637\u0645\u0645',
  14694. '\uFD74': '\u0637\u0645\u064A',
  14695. '\uFD75': '\u0639\u062C\u0645',
  14696. '\uFD76': '\u0639\u0645\u0645',
  14697. '\uFD77': '\u0639\u0645\u0645',
  14698. '\uFD78': '\u0639\u0645\u0649',
  14699. '\uFD79': '\u063A\u0645\u0645',
  14700. '\uFD7A': '\u063A\u0645\u064A',
  14701. '\uFD7B': '\u063A\u0645\u0649',
  14702. '\uFD7C': '\u0641\u062E\u0645',
  14703. '\uFD7D': '\u0641\u062E\u0645',
  14704. '\uFD7E': '\u0642\u0645\u062D',
  14705. '\uFD7F': '\u0642\u0645\u0645',
  14706. '\uFD80': '\u0644\u062D\u0645',
  14707. '\uFD81': '\u0644\u062D\u064A',
  14708. '\uFD82': '\u0644\u062D\u0649',
  14709. '\uFD83': '\u0644\u062C\u062C',
  14710. '\uFD84': '\u0644\u062C\u062C',
  14711. '\uFD85': '\u0644\u062E\u0645',
  14712. '\uFD86': '\u0644\u062E\u0645',
  14713. '\uFD87': '\u0644\u0645\u062D',
  14714. '\uFD88': '\u0644\u0645\u062D',
  14715. '\uFD89': '\u0645\u062D\u062C',
  14716. '\uFD8A': '\u0645\u062D\u0645',
  14717. '\uFD8B': '\u0645\u062D\u064A',
  14718. '\uFD8C': '\u0645\u062C\u062D',
  14719. '\uFD8D': '\u0645\u062C\u0645',
  14720. '\uFD8E': '\u0645\u062E\u062C',
  14721. '\uFD8F': '\u0645\u062E\u0645',
  14722. '\uFD92': '\u0645\u062C\u062E',
  14723. '\uFD93': '\u0647\u0645\u062C',
  14724. '\uFD94': '\u0647\u0645\u0645',
  14725. '\uFD95': '\u0646\u062D\u0645',
  14726. '\uFD96': '\u0646\u062D\u0649',
  14727. '\uFD97': '\u0646\u062C\u0645',
  14728. '\uFD98': '\u0646\u062C\u0645',
  14729. '\uFD99': '\u0646\u062C\u0649',
  14730. '\uFD9A': '\u0646\u0645\u064A',
  14731. '\uFD9B': '\u0646\u0645\u0649',
  14732. '\uFD9C': '\u064A\u0645\u0645',
  14733. '\uFD9D': '\u064A\u0645\u0645',
  14734. '\uFD9E': '\u0628\u062E\u064A',
  14735. '\uFD9F': '\u062A\u062C\u064A',
  14736. '\uFDA0': '\u062A\u062C\u0649',
  14737. '\uFDA1': '\u062A\u062E\u064A',
  14738. '\uFDA2': '\u062A\u062E\u0649',
  14739. '\uFDA3': '\u062A\u0645\u064A',
  14740. '\uFDA4': '\u062A\u0645\u0649',
  14741. '\uFDA5': '\u062C\u0645\u064A',
  14742. '\uFDA6': '\u062C\u062D\u0649',
  14743. '\uFDA7': '\u062C\u0645\u0649',
  14744. '\uFDA8': '\u0633\u062E\u0649',
  14745. '\uFDA9': '\u0635\u062D\u064A',
  14746. '\uFDAA': '\u0634\u062D\u064A',
  14747. '\uFDAB': '\u0636\u062D\u064A',
  14748. '\uFDAC': '\u0644\u062C\u064A',
  14749. '\uFDAD': '\u0644\u0645\u064A',
  14750. '\uFDAE': '\u064A\u062D\u064A',
  14751. '\uFDAF': '\u064A\u062C\u064A',
  14752. '\uFDB0': '\u064A\u0645\u064A',
  14753. '\uFDB1': '\u0645\u0645\u064A',
  14754. '\uFDB2': '\u0642\u0645\u064A',
  14755. '\uFDB3': '\u0646\u062D\u064A',
  14756. '\uFDB4': '\u0642\u0645\u062D',
  14757. '\uFDB5': '\u0644\u062D\u0645',
  14758. '\uFDB6': '\u0639\u0645\u064A',
  14759. '\uFDB7': '\u0643\u0645\u064A',
  14760. '\uFDB8': '\u0646\u062C\u062D',
  14761. '\uFDB9': '\u0645\u062E\u064A',
  14762. '\uFDBA': '\u0644\u062C\u0645',
  14763. '\uFDBB': '\u0643\u0645\u0645',
  14764. '\uFDBC': '\u0644\u062C\u0645',
  14765. '\uFDBD': '\u0646\u062C\u062D',
  14766. '\uFDBE': '\u062C\u062D\u064A',
  14767. '\uFDBF': '\u062D\u062C\u064A',
  14768. '\uFDC0': '\u0645\u062C\u064A',
  14769. '\uFDC1': '\u0641\u0645\u064A',
  14770. '\uFDC2': '\u0628\u062D\u064A',
  14771. '\uFDC3': '\u0643\u0645\u0645',
  14772. '\uFDC4': '\u0639\u062C\u0645',
  14773. '\uFDC5': '\u0635\u0645\u0645',
  14774. '\uFDC6': '\u0633\u062E\u064A',
  14775. '\uFDC7': '\u0646\u062C\u064A',
  14776. '\uFE49': '\u203E',
  14777. '\uFE4A': '\u203E',
  14778. '\uFE4B': '\u203E',
  14779. '\uFE4C': '\u203E',
  14780. '\uFE4D': '\u005F',
  14781. '\uFE4E': '\u005F',
  14782. '\uFE4F': '\u005F',
  14783. '\uFE80': '\u0621',
  14784. '\uFE81': '\u0622',
  14785. '\uFE82': '\u0622',
  14786. '\uFE83': '\u0623',
  14787. '\uFE84': '\u0623',
  14788. '\uFE85': '\u0624',
  14789. '\uFE86': '\u0624',
  14790. '\uFE87': '\u0625',
  14791. '\uFE88': '\u0625',
  14792. '\uFE89': '\u0626',
  14793. '\uFE8A': '\u0626',
  14794. '\uFE8B': '\u0626',
  14795. '\uFE8C': '\u0626',
  14796. '\uFE8D': '\u0627',
  14797. '\uFE8E': '\u0627',
  14798. '\uFE8F': '\u0628',
  14799. '\uFE90': '\u0628',
  14800. '\uFE91': '\u0628',
  14801. '\uFE92': '\u0628',
  14802. '\uFE93': '\u0629',
  14803. '\uFE94': '\u0629',
  14804. '\uFE95': '\u062A',
  14805. '\uFE96': '\u062A',
  14806. '\uFE97': '\u062A',
  14807. '\uFE98': '\u062A',
  14808. '\uFE99': '\u062B',
  14809. '\uFE9A': '\u062B',
  14810. '\uFE9B': '\u062B',
  14811. '\uFE9C': '\u062B',
  14812. '\uFE9D': '\u062C',
  14813. '\uFE9E': '\u062C',
  14814. '\uFE9F': '\u062C',
  14815. '\uFEA0': '\u062C',
  14816. '\uFEA1': '\u062D',
  14817. '\uFEA2': '\u062D',
  14818. '\uFEA3': '\u062D',
  14819. '\uFEA4': '\u062D',
  14820. '\uFEA5': '\u062E',
  14821. '\uFEA6': '\u062E',
  14822. '\uFEA7': '\u062E',
  14823. '\uFEA8': '\u062E',
  14824. '\uFEA9': '\u062F',
  14825. '\uFEAA': '\u062F',
  14826. '\uFEAB': '\u0630',
  14827. '\uFEAC': '\u0630',
  14828. '\uFEAD': '\u0631',
  14829. '\uFEAE': '\u0631',
  14830. '\uFEAF': '\u0632',
  14831. '\uFEB0': '\u0632',
  14832. '\uFEB1': '\u0633',
  14833. '\uFEB2': '\u0633',
  14834. '\uFEB3': '\u0633',
  14835. '\uFEB4': '\u0633',
  14836. '\uFEB5': '\u0634',
  14837. '\uFEB6': '\u0634',
  14838. '\uFEB7': '\u0634',
  14839. '\uFEB8': '\u0634',
  14840. '\uFEB9': '\u0635',
  14841. '\uFEBA': '\u0635',
  14842. '\uFEBB': '\u0635',
  14843. '\uFEBC': '\u0635',
  14844. '\uFEBD': '\u0636',
  14845. '\uFEBE': '\u0636',
  14846. '\uFEBF': '\u0636',
  14847. '\uFEC0': '\u0636',
  14848. '\uFEC1': '\u0637',
  14849. '\uFEC2': '\u0637',
  14850. '\uFEC3': '\u0637',
  14851. '\uFEC4': '\u0637',
  14852. '\uFEC5': '\u0638',
  14853. '\uFEC6': '\u0638',
  14854. '\uFEC7': '\u0638',
  14855. '\uFEC8': '\u0638',
  14856. '\uFEC9': '\u0639',
  14857. '\uFECA': '\u0639',
  14858. '\uFECB': '\u0639',
  14859. '\uFECC': '\u0639',
  14860. '\uFECD': '\u063A',
  14861. '\uFECE': '\u063A',
  14862. '\uFECF': '\u063A',
  14863. '\uFED0': '\u063A',
  14864. '\uFED1': '\u0641',
  14865. '\uFED2': '\u0641',
  14866. '\uFED3': '\u0641',
  14867. '\uFED4': '\u0641',
  14868. '\uFED5': '\u0642',
  14869. '\uFED6': '\u0642',
  14870. '\uFED7': '\u0642',
  14871. '\uFED8': '\u0642',
  14872. '\uFED9': '\u0643',
  14873. '\uFEDA': '\u0643',
  14874. '\uFEDB': '\u0643',
  14875. '\uFEDC': '\u0643',
  14876. '\uFEDD': '\u0644',
  14877. '\uFEDE': '\u0644',
  14878. '\uFEDF': '\u0644',
  14879. '\uFEE0': '\u0644',
  14880. '\uFEE1': '\u0645',
  14881. '\uFEE2': '\u0645',
  14882. '\uFEE3': '\u0645',
  14883. '\uFEE4': '\u0645',
  14884. '\uFEE5': '\u0646',
  14885. '\uFEE6': '\u0646',
  14886. '\uFEE7': '\u0646',
  14887. '\uFEE8': '\u0646',
  14888. '\uFEE9': '\u0647',
  14889. '\uFEEA': '\u0647',
  14890. '\uFEEB': '\u0647',
  14891. '\uFEEC': '\u0647',
  14892. '\uFEED': '\u0648',
  14893. '\uFEEE': '\u0648',
  14894. '\uFEEF': '\u0649',
  14895. '\uFEF0': '\u0649',
  14896. '\uFEF1': '\u064A',
  14897. '\uFEF2': '\u064A',
  14898. '\uFEF3': '\u064A',
  14899. '\uFEF4': '\u064A',
  14900. '\uFEF5': '\u0644\u0622',
  14901. '\uFEF6': '\u0644\u0622',
  14902. '\uFEF7': '\u0644\u0623',
  14903. '\uFEF8': '\u0644\u0623',
  14904. '\uFEF9': '\u0644\u0625',
  14905. '\uFEFA': '\u0644\u0625',
  14906. '\uFEFB': '\u0644\u0627',
  14907. '\uFEFC': '\u0644\u0627'
  14908. };
  14909. function reverseIfRtl(chars) {
  14910. var charsLength = chars.length;
  14911. //reverse an arabic ligature
  14912. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  14913. return chars;
  14914. }
  14915. var s = '';
  14916. for (var ii = charsLength - 1; ii >= 0; ii--) {
  14917. s += chars[ii];
  14918. }
  14919. return s;
  14920. }
  14921. function adjustWidths(properties) {
  14922. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  14923. return;
  14924. }
  14925. // adjusting width to fontMatrix scale
  14926. var scale = 0.001 / properties.fontMatrix[0];
  14927. var glyphsWidths = properties.widths;
  14928. for (var glyph in glyphsWidths) {
  14929. glyphsWidths[glyph] *= scale;
  14930. }
  14931. properties.defaultWidth *= scale;
  14932. }
  14933. function getFontType(type, subtype) {
  14934. switch (type) {
  14935. case 'Type1':
  14936. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  14937. case 'CIDFontType0':
  14938. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  14939. FontType.CIDFONTTYPE0;
  14940. case 'OpenType':
  14941. return FontType.OPENTYPE;
  14942. case 'TrueType':
  14943. return FontType.TRUETYPE;
  14944. case 'CIDFontType2':
  14945. return FontType.CIDFONTTYPE2;
  14946. case 'MMType1':
  14947. return FontType.MMTYPE1;
  14948. case 'Type0':
  14949. return FontType.TYPE0;
  14950. default:
  14951. return FontType.UNKNOWN;
  14952. }
  14953. }
  14954. var Glyph = (function GlyphClosure() {
  14955. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14956. this.fontChar = fontChar;
  14957. this.unicode = unicode;
  14958. this.accent = accent;
  14959. this.width = width;
  14960. this.vmetric = vmetric;
  14961. this.operatorListId = operatorListId;
  14962. }
  14963. Glyph.prototype.matchesForCache =
  14964. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  14965. return this.fontChar === fontChar &&
  14966. this.unicode === unicode &&
  14967. this.accent === accent &&
  14968. this.width === width &&
  14969. this.vmetric === vmetric &&
  14970. this.operatorListId === operatorListId;
  14971. };
  14972. return Glyph;
  14973. })();
  14974. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  14975. function ToUnicodeMap(cmap) {
  14976. // The elements of this._map can be integers or strings, depending on how
  14977. // |cmap| was created.
  14978. this._map = cmap;
  14979. }
  14980. ToUnicodeMap.prototype = {
  14981. get length() {
  14982. return this._map.length;
  14983. },
  14984. forEach: function(callback) {
  14985. for (var charCode in this._map) {
  14986. callback(charCode, this._map[charCode].charCodeAt(0));
  14987. }
  14988. },
  14989. get: function(i) {
  14990. return this._map[i];
  14991. },
  14992. charCodeOf: function(v) {
  14993. return this._map.indexOf(v);
  14994. }
  14995. };
  14996. return ToUnicodeMap;
  14997. })();
  14998. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  14999. function IdentityToUnicodeMap(firstChar, lastChar) {
  15000. this.firstChar = firstChar;
  15001. this.lastChar = lastChar;
  15002. }
  15003. IdentityToUnicodeMap.prototype = {
  15004. get length() {
  15005. error('should not access .length');
  15006. },
  15007. forEach: function (callback) {
  15008. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15009. callback(i, i);
  15010. }
  15011. },
  15012. get: function (i) {
  15013. if (this.firstChar <= i && i <= this.lastChar) {
  15014. return String.fromCharCode(i);
  15015. }
  15016. return undefined;
  15017. },
  15018. charCodeOf: function (v) {
  15019. error('should not call .charCodeOf');
  15020. }
  15021. };
  15022. return IdentityToUnicodeMap;
  15023. })();
  15024. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15025. function writeInt16(dest, offset, num) {
  15026. dest[offset] = (num >> 8) & 0xFF;
  15027. dest[offset + 1] = num & 0xFF;
  15028. }
  15029. function writeInt32(dest, offset, num) {
  15030. dest[offset] = (num >> 24) & 0xFF;
  15031. dest[offset + 1] = (num >> 16) & 0xFF;
  15032. dest[offset + 2] = (num >> 8) & 0xFF;
  15033. dest[offset + 3] = num & 0xFF;
  15034. }
  15035. function writeData(dest, offset, data) {
  15036. var i, ii;
  15037. if (data instanceof Uint8Array) {
  15038. dest.set(data, offset);
  15039. } else if (typeof data === 'string') {
  15040. for (i = 0, ii = data.length; i < ii; i++) {
  15041. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15042. }
  15043. } else {
  15044. // treating everything else as array
  15045. for (i = 0, ii = data.length; i < ii; i++) {
  15046. dest[offset++] = data[i] & 0xFF;
  15047. }
  15048. }
  15049. }
  15050. function OpenTypeFileBuilder(sfnt) {
  15051. this.sfnt = sfnt;
  15052. this.tables = Object.create(null);
  15053. }
  15054. OpenTypeFileBuilder.getSearchParams =
  15055. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15056. var maxPower2 = 1, log2 = 0;
  15057. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15058. maxPower2 <<= 1;
  15059. log2++;
  15060. }
  15061. var searchRange = maxPower2 * entrySize;
  15062. return {
  15063. range: searchRange,
  15064. entry: log2,
  15065. rangeShift: entrySize * entriesCount - searchRange
  15066. };
  15067. };
  15068. var OTF_HEADER_SIZE = 12;
  15069. var OTF_TABLE_ENTRY_SIZE = 16;
  15070. OpenTypeFileBuilder.prototype = {
  15071. toArray: function OpenTypeFileBuilder_toArray() {
  15072. var sfnt = this.sfnt;
  15073. // Tables needs to be written by ascendant alphabetic order
  15074. var tables = this.tables;
  15075. var tablesNames = Object.keys(tables);
  15076. tablesNames.sort();
  15077. var numTables = tablesNames.length;
  15078. var i, j, jj, table, tableName;
  15079. // layout the tables data
  15080. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15081. var tableOffsets = [offset];
  15082. for (i = 0; i < numTables; i++) {
  15083. table = tables[tablesNames[i]];
  15084. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15085. offset += paddedLength;
  15086. tableOffsets.push(offset);
  15087. }
  15088. var file = new Uint8Array(offset);
  15089. // write the table data first (mostly for checksum)
  15090. for (i = 0; i < numTables; i++) {
  15091. table = tables[tablesNames[i]];
  15092. writeData(file, tableOffsets[i], table);
  15093. }
  15094. // sfnt version (4 bytes)
  15095. if (sfnt === 'true') {
  15096. // Windows hates the Mac TrueType sfnt version number
  15097. sfnt = string32(0x00010000);
  15098. }
  15099. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15100. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15101. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15102. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15103. // numTables (2 bytes)
  15104. writeInt16(file, 4, numTables);
  15105. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15106. // searchRange (2 bytes)
  15107. writeInt16(file, 6, searchParams.range);
  15108. // entrySelector (2 bytes)
  15109. writeInt16(file, 8, searchParams.entry);
  15110. // rangeShift (2 bytes)
  15111. writeInt16(file, 10, searchParams.rangeShift);
  15112. offset = OTF_HEADER_SIZE;
  15113. // writing table entries
  15114. for (i = 0; i < numTables; i++) {
  15115. tableName = tablesNames[i];
  15116. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15117. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15118. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15119. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15120. // checksum
  15121. var checksum = 0;
  15122. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15123. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15124. (file[j + 2] << 8) + file[j + 3];
  15125. checksum = (checksum + quad) | 0;
  15126. }
  15127. writeInt32(file, offset + 4, checksum);
  15128. // offset
  15129. writeInt32(file, offset + 8, tableOffsets[i]);
  15130. // length
  15131. writeInt32(file, offset + 12, tables[tableName].length);
  15132. offset += OTF_TABLE_ENTRY_SIZE;
  15133. }
  15134. return file;
  15135. },
  15136. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15137. if (tag in this.tables) {
  15138. throw new Error('Table ' + tag + ' already exists');
  15139. }
  15140. this.tables[tag] = data;
  15141. }
  15142. };
  15143. return OpenTypeFileBuilder;
  15144. })();
  15145. /**
  15146. * 'Font' is the class the outside world should use, it encapsulate all the font
  15147. * decoding logics whatever type it is (assuming the font type is supported).
  15148. *
  15149. * For example to read a Type1 font and to attach it to the document:
  15150. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15151. * type1Font.bind();
  15152. */
  15153. var Font = (function FontClosure() {
  15154. function Font(name, file, properties) {
  15155. var charCode, glyphName, fontChar;
  15156. this.name = name;
  15157. this.loadedName = properties.loadedName;
  15158. this.isType3Font = properties.isType3Font;
  15159. this.sizes = [];
  15160. this.glyphCache = {};
  15161. var names = name.split('+');
  15162. names = names.length > 1 ? names[1] : names[0];
  15163. names = names.split(/[-,_]/g)[0];
  15164. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15165. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15166. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15167. var type = properties.type;
  15168. var subtype = properties.subtype;
  15169. this.type = type;
  15170. this.fallbackName = (this.isMonospace ? 'monospace' :
  15171. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15172. this.differences = properties.differences;
  15173. this.widths = properties.widths;
  15174. this.defaultWidth = properties.defaultWidth;
  15175. this.composite = properties.composite;
  15176. this.wideChars = properties.wideChars;
  15177. this.cMap = properties.cMap;
  15178. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15179. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15180. this.fontMatrix = properties.fontMatrix;
  15181. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15182. this.toFontChar = [];
  15183. if (properties.type === 'Type3') {
  15184. for (charCode = 0; charCode < 256; charCode++) {
  15185. this.toFontChar[charCode] = (this.differences[charCode] ||
  15186. properties.defaultEncoding[charCode]);
  15187. }
  15188. this.fontType = FontType.TYPE3;
  15189. return;
  15190. }
  15191. this.cidEncoding = properties.cidEncoding;
  15192. this.vertical = properties.vertical;
  15193. if (this.vertical) {
  15194. this.vmetrics = properties.vmetrics;
  15195. this.defaultVMetrics = properties.defaultVMetrics;
  15196. }
  15197. if (!file || file.isEmpty) {
  15198. if (file) {
  15199. // Some bad PDF generators will include empty font files,
  15200. // attempting to recover by assuming that no file exists.
  15201. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15202. }
  15203. this.missingFile = true;
  15204. // The file data is not specified. Trying to fix the font name
  15205. // to be used with the canvas.font.
  15206. var fontName = name.replace(/[,_]/g, '-');
  15207. var isStandardFont = !!stdFontMap[fontName] ||
  15208. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15209. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15210. this.bold = (fontName.search(/bold/gi) !== -1);
  15211. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15212. (fontName.search(/italic/gi) !== -1));
  15213. // Use 'name' instead of 'fontName' here because the original
  15214. // name ArialBlack for example will be replaced by Helvetica.
  15215. this.black = (name.search(/Black/g) !== -1);
  15216. // if at least one width is present, remeasure all chars when exists
  15217. this.remeasure = Object.keys(this.widths).length > 0;
  15218. if (isStandardFont && type === 'CIDFontType2' &&
  15219. properties.cidEncoding.indexOf('Identity-') === 0) {
  15220. // Standard fonts might be embedded as CID font without glyph mapping.
  15221. // Building one based on GlyphMapForStandardFonts.
  15222. var map = [];
  15223. for (var code in GlyphMapForStandardFonts) {
  15224. map[+code] = GlyphMapForStandardFonts[code];
  15225. }
  15226. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15227. if (!isIdentityUnicode) {
  15228. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15229. map[+charCode] = unicodeCharCode;
  15230. });
  15231. }
  15232. this.toFontChar = map;
  15233. this.toUnicode = new ToUnicodeMap(map);
  15234. } else if (/Symbol/i.test(fontName)) {
  15235. var symbols = Encodings.SymbolSetEncoding;
  15236. for (charCode in symbols) {
  15237. fontChar = GlyphsUnicode[symbols[charCode]];
  15238. if (!fontChar) {
  15239. continue;
  15240. }
  15241. this.toFontChar[charCode] = fontChar;
  15242. }
  15243. for (charCode in properties.differences) {
  15244. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15245. if (!fontChar) {
  15246. continue;
  15247. }
  15248. this.toFontChar[charCode] = fontChar;
  15249. }
  15250. } else if (/Dingbats/i.test(fontName)) {
  15251. if (/Wingdings/i.test(name)) {
  15252. warn('Wingdings font without embedded font file, ' +
  15253. 'falling back to the ZapfDingbats encoding.');
  15254. }
  15255. var dingbats = Encodings.ZapfDingbatsEncoding;
  15256. for (charCode in dingbats) {
  15257. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15258. if (!fontChar) {
  15259. continue;
  15260. }
  15261. this.toFontChar[charCode] = fontChar;
  15262. }
  15263. for (charCode in properties.differences) {
  15264. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15265. if (!fontChar) {
  15266. continue;
  15267. }
  15268. this.toFontChar[charCode] = fontChar;
  15269. }
  15270. } else if (isStandardFont) {
  15271. this.toFontChar = [];
  15272. for (charCode in properties.defaultEncoding) {
  15273. glyphName = (properties.differences[charCode] ||
  15274. properties.defaultEncoding[charCode]);
  15275. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15276. }
  15277. } else {
  15278. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15279. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15280. if (notCidFont) {
  15281. glyphName = (properties.differences[charCode] ||
  15282. properties.defaultEncoding[charCode]);
  15283. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15284. }
  15285. this.toFontChar[charCode] = unicodeCharCode;
  15286. }.bind(this));
  15287. }
  15288. this.loadedName = fontName.split('-')[0];
  15289. this.loading = false;
  15290. this.fontType = getFontType(type, subtype);
  15291. return;
  15292. }
  15293. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15294. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15295. // Some TrueType fonts by mistake claim Type1C
  15296. if (isTrueTypeFile(file)) {
  15297. subtype = 'TrueType';
  15298. } else {
  15299. type = 'Type1';
  15300. }
  15301. }
  15302. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15303. type = 'CIDFontType0';
  15304. }
  15305. // XXX: Temporarily change the type for open type so we trigger a warning.
  15306. // This should be removed when we add support for open type.
  15307. if (subtype === 'OpenType') {
  15308. type = 'OpenType';
  15309. }
  15310. var data;
  15311. switch (type) {
  15312. case 'MMType1':
  15313. info('MMType1 font (' + name + '), falling back to Type1.');
  15314. /* falls through */
  15315. case 'Type1':
  15316. case 'CIDFontType0':
  15317. this.mimetype = 'font/opentype';
  15318. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15319. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15320. adjustWidths(properties);
  15321. // Wrap the CFF data inside an OTF font file
  15322. data = this.convert(name, cff, properties);
  15323. break;
  15324. case 'OpenType':
  15325. case 'TrueType':
  15326. case 'CIDFontType2':
  15327. this.mimetype = 'font/opentype';
  15328. // Repair the TrueType file. It is can be damaged in the point of
  15329. // view of the sanitizer
  15330. data = this.checkAndRepair(name, file, properties);
  15331. if (this.isOpenType) {
  15332. type = 'OpenType';
  15333. }
  15334. break;
  15335. default:
  15336. error('Font ' + type + ' is not supported');
  15337. break;
  15338. }
  15339. this.data = data;
  15340. this.fontType = getFontType(type, subtype);
  15341. // Transfer some properties again that could change during font conversion
  15342. this.fontMatrix = properties.fontMatrix;
  15343. this.widths = properties.widths;
  15344. this.defaultWidth = properties.defaultWidth;
  15345. this.encoding = properties.baseEncoding;
  15346. this.seacMap = properties.seacMap;
  15347. this.loading = true;
  15348. }
  15349. Font.getFontID = (function () {
  15350. var ID = 1;
  15351. return function Font_getFontID() {
  15352. return String(ID++);
  15353. };
  15354. })();
  15355. function int16(b0, b1) {
  15356. return (b0 << 8) + b1;
  15357. }
  15358. function int32(b0, b1, b2, b3) {
  15359. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15360. }
  15361. function string16(value) {
  15362. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15363. }
  15364. function safeString16(value) {
  15365. // clamp value to the 16-bit int range
  15366. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15367. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15368. }
  15369. function isTrueTypeFile(file) {
  15370. var header = file.peekBytes(4);
  15371. return readUint32(header, 0) === 0x00010000;
  15372. }
  15373. /**
  15374. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15375. * with their unicode value. It also moves char codes that are in known
  15376. * problematic locations.
  15377. * @return {Object} Two properties:
  15378. * 'toFontChar' - maps original char codes(the value that will be read
  15379. * from commands such as show text) to the char codes that will be used in the
  15380. * font that we build
  15381. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15382. */
  15383. function adjustMapping(charCodeToGlyphId, properties) {
  15384. var toUnicode = properties.toUnicode;
  15385. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15386. var isIdentityUnicode =
  15387. properties.toUnicode instanceof IdentityToUnicodeMap;
  15388. var isCidFontType2 = (properties.type === 'CIDFontType2');
  15389. var newMap = Object.create(null);
  15390. var toFontChar = [];
  15391. var usedFontCharCodes = [];
  15392. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15393. for (var originalCharCode in charCodeToGlyphId) {
  15394. originalCharCode |= 0;
  15395. var glyphId = charCodeToGlyphId[originalCharCode];
  15396. var fontCharCode = originalCharCode;
  15397. // First try to map the value to a unicode position if a non identity map
  15398. // was created.
  15399. if (!isIdentityUnicode) {
  15400. if (toUnicode.get(originalCharCode) !== undefined) {
  15401. var unicode = toUnicode.get(fontCharCode);
  15402. // TODO: Try to map ligatures to the correct spot.
  15403. if (unicode.length === 1) {
  15404. fontCharCode = unicode.charCodeAt(0);
  15405. }
  15406. } else if (isCidFontType2) {
  15407. // For CIDFontType2, move characters not present in toUnicode
  15408. // to the private use area (fixes bug 1028735 and issue 4881).
  15409. fontCharCode = nextAvailableFontCharCode;
  15410. }
  15411. }
  15412. // Try to move control characters, special characters and already mapped
  15413. // characters to the private use area since they will not be drawn by
  15414. // canvas if left in their current position. Also, move characters if the
  15415. // font was symbolic and there is only an identity unicode map since the
  15416. // characters probably aren't in the correct position (fixes an issue
  15417. // with firefox and thuluthfont).
  15418. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15419. fontCharCode <= 0x1f || // Control chars
  15420. fontCharCode === 0x7F || // Control char
  15421. fontCharCode === 0xAD || // Soft hyphen
  15422. fontCharCode === 0xA0 || // Non breaking space
  15423. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  15424. // Prevent drawing characters in the specials unicode block.
  15425. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  15426. (isSymbolic && isIdentityUnicode)) &&
  15427. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15428. // Loop to try and find a free spot in the private use area.
  15429. do {
  15430. fontCharCode = nextAvailableFontCharCode++;
  15431. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15432. fontCharCode = 0xF020;
  15433. nextAvailableFontCharCode = fontCharCode + 1;
  15434. }
  15435. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15436. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15437. }
  15438. newMap[fontCharCode] = glyphId;
  15439. toFontChar[originalCharCode] = fontCharCode;
  15440. usedFontCharCodes[fontCharCode] = true;
  15441. }
  15442. return {
  15443. toFontChar: toFontChar,
  15444. charCodeToGlyphId: newMap,
  15445. nextAvailableFontCharCode: nextAvailableFontCharCode
  15446. };
  15447. }
  15448. function getRanges(glyphs) {
  15449. // Array.sort() sorts by characters, not numerically, so convert to an
  15450. // array of characters.
  15451. var codes = [];
  15452. for (var charCode in glyphs) {
  15453. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15454. }
  15455. codes.sort(function fontGetRangesSort(a, b) {
  15456. return a.fontCharCode - b.fontCharCode;
  15457. });
  15458. // Split the sorted codes into ranges.
  15459. var ranges = [];
  15460. var length = codes.length;
  15461. for (var n = 0; n < length; ) {
  15462. var start = codes[n].fontCharCode;
  15463. var codeIndices = [codes[n].glyphId];
  15464. ++n;
  15465. var end = start;
  15466. while (n < length && end + 1 === codes[n].fontCharCode) {
  15467. codeIndices.push(codes[n].glyphId);
  15468. ++end;
  15469. ++n;
  15470. if (end === 0xFFFF) {
  15471. break;
  15472. }
  15473. }
  15474. ranges.push([start, end, codeIndices]);
  15475. }
  15476. return ranges;
  15477. }
  15478. function createCmapTable(glyphs) {
  15479. var ranges = getRanges(glyphs);
  15480. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15481. var cmap = '\x00\x00' + // version
  15482. string16(numTables) + // numTables
  15483. '\x00\x03' + // platformID
  15484. '\x00\x01' + // encodingID
  15485. string32(4 + numTables * 8); // start of the table record
  15486. var i, ii, j, jj;
  15487. for (i = ranges.length - 1; i >= 0; --i) {
  15488. if (ranges[i][0] <= 0xFFFF) { break; }
  15489. }
  15490. var bmpLength = i + 1;
  15491. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15492. ranges[i][1] = 0xFFFE;
  15493. }
  15494. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15495. var segCount = bmpLength + trailingRangesCount;
  15496. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15497. // Fill up the 4 parallel arrays describing the segments.
  15498. var startCount = '';
  15499. var endCount = '';
  15500. var idDeltas = '';
  15501. var idRangeOffsets = '';
  15502. var glyphsIds = '';
  15503. var bias = 0;
  15504. var range, start, end, codes;
  15505. for (i = 0, ii = bmpLength; i < ii; i++) {
  15506. range = ranges[i];
  15507. start = range[0];
  15508. end = range[1];
  15509. startCount += string16(start);
  15510. endCount += string16(end);
  15511. codes = range[2];
  15512. var contiguous = true;
  15513. for (j = 1, jj = codes.length; j < jj; ++j) {
  15514. if (codes[j] !== codes[j - 1] + 1) {
  15515. contiguous = false;
  15516. break;
  15517. }
  15518. }
  15519. if (!contiguous) {
  15520. var offset = (segCount - i) * 2 + bias * 2;
  15521. bias += (end - start + 1);
  15522. idDeltas += string16(0);
  15523. idRangeOffsets += string16(offset);
  15524. for (j = 0, jj = codes.length; j < jj; ++j) {
  15525. glyphsIds += string16(codes[j]);
  15526. }
  15527. } else {
  15528. var startCode = codes[0];
  15529. idDeltas += string16((startCode - start) & 0xFFFF);
  15530. idRangeOffsets += string16(0);
  15531. }
  15532. }
  15533. if (trailingRangesCount > 0) {
  15534. endCount += '\xFF\xFF';
  15535. startCount += '\xFF\xFF';
  15536. idDeltas += '\x00\x01';
  15537. idRangeOffsets += '\x00\x00';
  15538. }
  15539. var format314 = '\x00\x00' + // language
  15540. string16(2 * segCount) +
  15541. string16(searchParams.range) +
  15542. string16(searchParams.entry) +
  15543. string16(searchParams.rangeShift) +
  15544. endCount + '\x00\x00' + startCount +
  15545. idDeltas + idRangeOffsets + glyphsIds;
  15546. var format31012 = '';
  15547. var header31012 = '';
  15548. if (numTables > 1) {
  15549. cmap += '\x00\x03' + // platformID
  15550. '\x00\x0A' + // encodingID
  15551. string32(4 + numTables * 8 +
  15552. 4 + format314.length); // start of the table record
  15553. format31012 = '';
  15554. for (i = 0, ii = ranges.length; i < ii; i++) {
  15555. range = ranges[i];
  15556. start = range[0];
  15557. codes = range[2];
  15558. var code = codes[0];
  15559. for (j = 1, jj = codes.length; j < jj; ++j) {
  15560. if (codes[j] !== codes[j - 1] + 1) {
  15561. end = range[0] + j - 1;
  15562. format31012 += string32(start) + // startCharCode
  15563. string32(end) + // endCharCode
  15564. string32(code); // startGlyphID
  15565. start = end + 1;
  15566. code = codes[j];
  15567. }
  15568. }
  15569. format31012 += string32(start) + // startCharCode
  15570. string32(range[1]) + // endCharCode
  15571. string32(code); // startGlyphID
  15572. }
  15573. header31012 = '\x00\x0C' + // format
  15574. '\x00\x00' + // reserved
  15575. string32(format31012.length + 16) + // length
  15576. '\x00\x00\x00\x00' + // language
  15577. string32(format31012.length / 12); // nGroups
  15578. }
  15579. return cmap + '\x00\x04' + // format
  15580. string16(format314.length + 4) + // length
  15581. format314 + header31012 + format31012;
  15582. }
  15583. function validateOS2Table(os2) {
  15584. var stream = new Stream(os2.data);
  15585. var version = stream.getUint16();
  15586. // TODO verify all OS/2 tables fields, but currently we validate only those
  15587. // that give us issues
  15588. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15589. var selection = stream.getUint16();
  15590. if (version < 4 && (selection & 0x0300)) {
  15591. return false;
  15592. }
  15593. var firstChar = stream.getUint16();
  15594. var lastChar = stream.getUint16();
  15595. if (firstChar > lastChar) {
  15596. return false;
  15597. }
  15598. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15599. var usWinAscent = stream.getUint16();
  15600. if (usWinAscent === 0) { // makes font unreadable by windows
  15601. return false;
  15602. }
  15603. // OS/2 appears to be valid, resetting some fields
  15604. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15605. return true;
  15606. }
  15607. function createOS2Table(properties, charstrings, override) {
  15608. override = override || {
  15609. unitsPerEm: 0,
  15610. yMax: 0,
  15611. yMin: 0,
  15612. ascent: 0,
  15613. descent: 0
  15614. };
  15615. var ulUnicodeRange1 = 0;
  15616. var ulUnicodeRange2 = 0;
  15617. var ulUnicodeRange3 = 0;
  15618. var ulUnicodeRange4 = 0;
  15619. var firstCharIndex = null;
  15620. var lastCharIndex = 0;
  15621. if (charstrings) {
  15622. for (var code in charstrings) {
  15623. code |= 0;
  15624. if (firstCharIndex > code || !firstCharIndex) {
  15625. firstCharIndex = code;
  15626. }
  15627. if (lastCharIndex < code) {
  15628. lastCharIndex = code;
  15629. }
  15630. var position = getUnicodeRangeFor(code);
  15631. if (position < 32) {
  15632. ulUnicodeRange1 |= 1 << position;
  15633. } else if (position < 64) {
  15634. ulUnicodeRange2 |= 1 << position - 32;
  15635. } else if (position < 96) {
  15636. ulUnicodeRange3 |= 1 << position - 64;
  15637. } else if (position < 123) {
  15638. ulUnicodeRange4 |= 1 << position - 96;
  15639. } else {
  15640. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15641. }
  15642. }
  15643. } else {
  15644. // TODO
  15645. firstCharIndex = 0;
  15646. lastCharIndex = 255;
  15647. }
  15648. var bbox = properties.bbox || [0, 0, 0, 0];
  15649. var unitsPerEm = (override.unitsPerEm ||
  15650. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15651. // if the font units differ to the PDF glyph space units
  15652. // then scale up the values
  15653. var scale = (properties.ascentScaled ? 1.0 :
  15654. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15655. var typoAscent = (override.ascent ||
  15656. Math.round(scale * (properties.ascent || bbox[3])));
  15657. var typoDescent = (override.descent ||
  15658. Math.round(scale * (properties.descent || bbox[1])));
  15659. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15660. typoDescent = -typoDescent; // fixing incorrect descent
  15661. }
  15662. var winAscent = override.yMax || typoAscent;
  15663. var winDescent = -override.yMin || -typoDescent;
  15664. return '\x00\x03' + // version
  15665. '\x02\x24' + // xAvgCharWidth
  15666. '\x01\xF4' + // usWeightClass
  15667. '\x00\x05' + // usWidthClass
  15668. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15669. '\x02\x8A' + // ySubscriptXSize
  15670. '\x02\xBB' + // ySubscriptYSize
  15671. '\x00\x00' + // ySubscriptXOffset
  15672. '\x00\x8C' + // ySubscriptYOffset
  15673. '\x02\x8A' + // ySuperScriptXSize
  15674. '\x02\xBB' + // ySuperScriptYSize
  15675. '\x00\x00' + // ySuperScriptXOffset
  15676. '\x01\xDF' + // ySuperScriptYOffset
  15677. '\x00\x31' + // yStrikeOutSize
  15678. '\x01\x02' + // yStrikeOutPosition
  15679. '\x00\x00' + // sFamilyClass
  15680. '\x00\x00\x06' +
  15681. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15682. '\x00\x00\x00\x00\x00\x00' + // Panose
  15683. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  15684. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  15685. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  15686. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  15687. '\x2A\x32\x31\x2A' + // achVendID
  15688. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  15689. string16(firstCharIndex ||
  15690. properties.firstChar) + // usFirstCharIndex
  15691. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  15692. string16(typoAscent) + // sTypoAscender
  15693. string16(typoDescent) + // sTypoDescender
  15694. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  15695. string16(winAscent) + // usWinAscent
  15696. string16(winDescent) + // usWinDescent
  15697. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  15698. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  15699. string16(properties.xHeight) + // sxHeight
  15700. string16(properties.capHeight) + // sCapHeight
  15701. string16(0) + // usDefaultChar
  15702. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  15703. '\x00\x03'; // usMaxContext
  15704. }
  15705. function createPostTable(properties) {
  15706. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  15707. return ('\x00\x03\x00\x00' + // Version number
  15708. string32(angle) + // italicAngle
  15709. '\x00\x00' + // underlinePosition
  15710. '\x00\x00' + // underlineThickness
  15711. string32(properties.fixedPitch) + // isFixedPitch
  15712. '\x00\x00\x00\x00' + // minMemType42
  15713. '\x00\x00\x00\x00' + // maxMemType42
  15714. '\x00\x00\x00\x00' + // minMemType1
  15715. '\x00\x00\x00\x00'); // maxMemType1
  15716. }
  15717. function createNameTable(name, proto) {
  15718. if (!proto) {
  15719. proto = [[], []]; // no strings and unicode strings
  15720. }
  15721. var strings = [
  15722. proto[0][0] || 'Original licence', // 0.Copyright
  15723. proto[0][1] || name, // 1.Font family
  15724. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  15725. proto[0][3] || 'uniqueID', // 3.Unique ID
  15726. proto[0][4] || name, // 4.Full font name
  15727. proto[0][5] || 'Version 0.11', // 5.Version
  15728. proto[0][6] || '', // 6.Postscript name
  15729. proto[0][7] || 'Unknown', // 7.Trademark
  15730. proto[0][8] || 'Unknown', // 8.Manufacturer
  15731. proto[0][9] || 'Unknown' // 9.Designer
  15732. ];
  15733. // Mac want 1-byte per character strings while Windows want
  15734. // 2-bytes per character, so duplicate the names table
  15735. var stringsUnicode = [];
  15736. var i, ii, j, jj, str;
  15737. for (i = 0, ii = strings.length; i < ii; i++) {
  15738. str = proto[1][i] || strings[i];
  15739. var strBufUnicode = [];
  15740. for (j = 0, jj = str.length; j < jj; j++) {
  15741. strBufUnicode.push(string16(str.charCodeAt(j)));
  15742. }
  15743. stringsUnicode.push(strBufUnicode.join(''));
  15744. }
  15745. var names = [strings, stringsUnicode];
  15746. var platforms = ['\x00\x01', '\x00\x03'];
  15747. var encodings = ['\x00\x00', '\x00\x01'];
  15748. var languages = ['\x00\x00', '\x04\x09'];
  15749. var namesRecordCount = strings.length * platforms.length;
  15750. var nameTable =
  15751. '\x00\x00' + // format
  15752. string16(namesRecordCount) + // Number of names Record
  15753. string16(namesRecordCount * 12 + 6); // Storage
  15754. // Build the name records field
  15755. var strOffset = 0;
  15756. for (i = 0, ii = platforms.length; i < ii; i++) {
  15757. var strs = names[i];
  15758. for (j = 0, jj = strs.length; j < jj; j++) {
  15759. str = strs[j];
  15760. var nameRecord =
  15761. platforms[i] + // platform ID
  15762. encodings[i] + // encoding ID
  15763. languages[i] + // language ID
  15764. string16(j) + // name ID
  15765. string16(str.length) +
  15766. string16(strOffset);
  15767. nameTable += nameRecord;
  15768. strOffset += str.length;
  15769. }
  15770. }
  15771. nameTable += strings.join('') + stringsUnicode.join('');
  15772. return nameTable;
  15773. }
  15774. Font.prototype = {
  15775. name: null,
  15776. font: null,
  15777. mimetype: null,
  15778. encoding: null,
  15779. get renderer() {
  15780. var renderer = FontRendererFactory.create(this);
  15781. return shadow(this, 'renderer', renderer);
  15782. },
  15783. exportData: function Font_exportData() {
  15784. var data = {};
  15785. for (var i in this) {
  15786. if (this.hasOwnProperty(i)) {
  15787. data[i] = this[i];
  15788. }
  15789. }
  15790. return data;
  15791. },
  15792. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  15793. function readTableEntry(file) {
  15794. var tag = bytesToString(file.getBytes(4));
  15795. var checksum = file.getInt32();
  15796. var offset = file.getInt32() >>> 0;
  15797. var length = file.getInt32() >>> 0;
  15798. // Read the table associated data
  15799. var previousPosition = file.pos;
  15800. file.pos = file.start ? file.start : 0;
  15801. file.skip(offset);
  15802. var data = file.getBytes(length);
  15803. file.pos = previousPosition;
  15804. if (tag === 'head') {
  15805. // clearing checksum adjustment
  15806. data[8] = data[9] = data[10] = data[11] = 0;
  15807. data[17] |= 0x20; //Set font optimized for cleartype flag
  15808. }
  15809. return {
  15810. tag: tag,
  15811. checksum: checksum,
  15812. length: length,
  15813. offset: offset,
  15814. data: data
  15815. };
  15816. }
  15817. function readOpenTypeHeader(ttf) {
  15818. return {
  15819. version: bytesToString(ttf.getBytes(4)),
  15820. numTables: ttf.getUint16(),
  15821. searchRange: ttf.getUint16(),
  15822. entrySelector: ttf.getUint16(),
  15823. rangeShift: ttf.getUint16()
  15824. };
  15825. }
  15826. /**
  15827. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  15828. * PDF spec
  15829. */
  15830. function readCmapTable(cmap, font, isSymbolicFont) {
  15831. var segment;
  15832. var start = (font.start ? font.start : 0) + cmap.offset;
  15833. font.pos = start;
  15834. var version = font.getUint16();
  15835. var numTables = font.getUint16();
  15836. var potentialTable;
  15837. var canBreak = false;
  15838. // There's an order of preference in terms of which cmap subtable to
  15839. // use:
  15840. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  15841. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  15842. // The following takes advantage of the fact that the tables are sorted
  15843. // to work.
  15844. for (var i = 0; i < numTables; i++) {
  15845. var platformId = font.getUint16();
  15846. var encodingId = font.getUint16();
  15847. var offset = font.getInt32() >>> 0;
  15848. var useTable = false;
  15849. if (platformId === 1 && encodingId === 0) {
  15850. useTable = true;
  15851. // Continue the loop since there still may be a higher priority
  15852. // table.
  15853. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  15854. useTable = true;
  15855. canBreak = true;
  15856. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  15857. useTable = true;
  15858. canBreak = true;
  15859. }
  15860. if (useTable) {
  15861. potentialTable = {
  15862. platformId: platformId,
  15863. encodingId: encodingId,
  15864. offset: offset
  15865. };
  15866. }
  15867. if (canBreak) {
  15868. break;
  15869. }
  15870. }
  15871. if (!potentialTable) {
  15872. warn('Could not find a preferred cmap table.');
  15873. return {
  15874. platformId: -1,
  15875. encodingId: -1,
  15876. mappings: [],
  15877. hasShortCmap: false
  15878. };
  15879. }
  15880. font.pos = start + potentialTable.offset;
  15881. var format = font.getUint16();
  15882. var length = font.getUint16();
  15883. var language = font.getUint16();
  15884. var hasShortCmap = false;
  15885. var mappings = [];
  15886. var j, glyphId;
  15887. // TODO(mack): refactor this cmap subtable reading logic out
  15888. if (format === 0) {
  15889. for (j = 0; j < 256; j++) {
  15890. var index = font.getByte();
  15891. if (!index) {
  15892. continue;
  15893. }
  15894. mappings.push({
  15895. charCode: j,
  15896. glyphId: index
  15897. });
  15898. }
  15899. hasShortCmap = true;
  15900. } else if (format === 4) {
  15901. // re-creating the table in format 4 since the encoding
  15902. // might be changed
  15903. var segCount = (font.getUint16() >> 1);
  15904. font.getBytes(6); // skipping range fields
  15905. var segIndex, segments = [];
  15906. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15907. segments.push({ end: font.getUint16() });
  15908. }
  15909. font.getUint16();
  15910. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15911. segments[segIndex].start = font.getUint16();
  15912. }
  15913. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15914. segments[segIndex].delta = font.getUint16();
  15915. }
  15916. var offsetsCount = 0;
  15917. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15918. segment = segments[segIndex];
  15919. var rangeOffset = font.getUint16();
  15920. if (!rangeOffset) {
  15921. segment.offsetIndex = -1;
  15922. continue;
  15923. }
  15924. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  15925. segment.offsetIndex = offsetIndex;
  15926. offsetsCount = Math.max(offsetsCount, offsetIndex +
  15927. segment.end - segment.start + 1);
  15928. }
  15929. var offsets = [];
  15930. for (j = 0; j < offsetsCount; j++) {
  15931. offsets.push(font.getUint16());
  15932. }
  15933. for (segIndex = 0; segIndex < segCount; segIndex++) {
  15934. segment = segments[segIndex];
  15935. start = segment.start;
  15936. var end = segment.end;
  15937. var delta = segment.delta;
  15938. offsetIndex = segment.offsetIndex;
  15939. for (j = start; j <= end; j++) {
  15940. if (j === 0xFFFF) {
  15941. continue;
  15942. }
  15943. glyphId = (offsetIndex < 0 ?
  15944. j : offsets[offsetIndex + j - start]);
  15945. glyphId = (glyphId + delta) & 0xFFFF;
  15946. if (glyphId === 0) {
  15947. continue;
  15948. }
  15949. mappings.push({
  15950. charCode: j,
  15951. glyphId: glyphId
  15952. });
  15953. }
  15954. }
  15955. } else if (format === 6) {
  15956. // Format 6 is a 2-bytes dense mapping, which means the font data
  15957. // lives glue together even if they are pretty far in the unicode
  15958. // table. (This looks weird, so I can have missed something), this
  15959. // works on Linux but seems to fails on Mac so let's rewrite the
  15960. // cmap table to a 3-1-4 style
  15961. var firstCode = font.getUint16();
  15962. var entryCount = font.getUint16();
  15963. for (j = 0; j < entryCount; j++) {
  15964. glyphId = font.getUint16();
  15965. var charCode = firstCode + j;
  15966. mappings.push({
  15967. charCode: charCode,
  15968. glyphId: glyphId
  15969. });
  15970. }
  15971. } else {
  15972. error('cmap table has unsupported format: ' + format);
  15973. }
  15974. // removing duplicate entries
  15975. mappings.sort(function (a, b) {
  15976. return a.charCode - b.charCode;
  15977. });
  15978. for (i = 1; i < mappings.length; i++) {
  15979. if (mappings[i - 1].charCode === mappings[i].charCode) {
  15980. mappings.splice(i, 1);
  15981. i--;
  15982. }
  15983. }
  15984. return {
  15985. platformId: potentialTable.platformId,
  15986. encodingId: potentialTable.encodingId,
  15987. mappings: mappings,
  15988. hasShortCmap: hasShortCmap
  15989. };
  15990. }
  15991. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  15992. if (!header) {
  15993. if (metrics) {
  15994. metrics.data = null;
  15995. }
  15996. return;
  15997. }
  15998. font.pos = (font.start ? font.start : 0) + header.offset;
  15999. font.pos += header.length - 2;
  16000. var numOfMetrics = font.getUint16();
  16001. if (numOfMetrics > numGlyphs) {
  16002. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16003. 'greater than the numGlyphs (' + numGlyphs + ')');
  16004. // Reduce numOfMetrics if it is greater than numGlyphs
  16005. numOfMetrics = numGlyphs;
  16006. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16007. header.data[35] = numOfMetrics & 0x00ff;
  16008. }
  16009. var numOfSidebearings = numGlyphs - numOfMetrics;
  16010. var numMissing = numOfSidebearings -
  16011. ((metrics.length - numOfMetrics * 4) >> 1);
  16012. if (numMissing > 0) {
  16013. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16014. // Since we need to add two properties for each glyph, this explains
  16015. // the use of |numMissing * 2| when initializing the typed array.
  16016. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16017. entries.set(metrics.data);
  16018. metrics.data = entries;
  16019. }
  16020. }
  16021. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16022. hintsValid) {
  16023. if (sourceEnd - sourceStart <= 12) {
  16024. // glyph with data less than 12 is invalid one
  16025. return 0;
  16026. }
  16027. var glyf = source.subarray(sourceStart, sourceEnd);
  16028. var contoursCount = (glyf[0] << 8) | glyf[1];
  16029. if (contoursCount & 0x8000) {
  16030. // complex glyph, writing as is
  16031. dest.set(glyf, destStart);
  16032. return glyf.length;
  16033. }
  16034. var i, j = 10, flagsCount = 0;
  16035. for (i = 0; i < contoursCount; i++) {
  16036. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16037. flagsCount = endPoint + 1;
  16038. j += 2;
  16039. }
  16040. // skipping instructions
  16041. var instructionsStart = j;
  16042. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16043. j += 2 + instructionsLength;
  16044. var instructionsEnd = j;
  16045. // validating flags
  16046. var coordinatesLength = 0;
  16047. for (i = 0; i < flagsCount; i++) {
  16048. var flag = glyf[j++];
  16049. if (flag & 0xC0) {
  16050. // reserved flags must be zero, cleaning up
  16051. glyf[j - 1] = flag & 0x3F;
  16052. }
  16053. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16054. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16055. coordinatesLength += xyLength;
  16056. if (flag & 8) {
  16057. var repeat = glyf[j++];
  16058. i += repeat;
  16059. coordinatesLength += repeat * xyLength;
  16060. }
  16061. }
  16062. // glyph without coordinates will be rejected
  16063. if (coordinatesLength === 0) {
  16064. return 0;
  16065. }
  16066. var glyphDataLength = j + coordinatesLength;
  16067. if (glyphDataLength > glyf.length) {
  16068. // not enough data for coordinates
  16069. return 0;
  16070. }
  16071. if (!hintsValid && instructionsLength > 0) {
  16072. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16073. dest.set([0, 0], destStart + instructionsStart);
  16074. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16075. destStart + instructionsStart + 2);
  16076. glyphDataLength -= instructionsLength;
  16077. if (glyf.length - glyphDataLength > 3) {
  16078. glyphDataLength = (glyphDataLength + 3) & ~3;
  16079. }
  16080. return glyphDataLength;
  16081. }
  16082. if (glyf.length - glyphDataLength > 3) {
  16083. // truncating and aligning to 4 bytes the long glyph data
  16084. glyphDataLength = (glyphDataLength + 3) & ~3;
  16085. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16086. return glyphDataLength;
  16087. }
  16088. // glyph data is fine
  16089. dest.set(glyf, destStart);
  16090. return glyf.length;
  16091. }
  16092. function sanitizeHead(head, numGlyphs, locaLength) {
  16093. var data = head.data;
  16094. // Validate version:
  16095. // Should always be 0x00010000
  16096. var version = int32(data[0], data[1], data[2], data[3]);
  16097. if (version >> 16 !== 1) {
  16098. info('Attempting to fix invalid version in head table: ' + version);
  16099. data[0] = 0;
  16100. data[1] = 1;
  16101. data[2] = 0;
  16102. data[3] = 0;
  16103. }
  16104. var indexToLocFormat = int16(data[50], data[51]);
  16105. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16106. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16107. indexToLocFormat);
  16108. // The value of indexToLocFormat should be 0 if the loca table
  16109. // consists of short offsets, and should be 1 if the loca table
  16110. // consists of long offsets.
  16111. //
  16112. // The number of entries in the loca table should be numGlyphs + 1.
  16113. //
  16114. // Using this information, we can work backwards to deduce if the
  16115. // size of each offset in the loca table, and thus figure out the
  16116. // appropriate value for indexToLocFormat.
  16117. var numGlyphsPlusOne = numGlyphs + 1;
  16118. if (locaLength === numGlyphsPlusOne << 1) {
  16119. // 0x0000 indicates the loca table consists of short offsets
  16120. data[50] = 0;
  16121. data[51] = 0;
  16122. } else if (locaLength === numGlyphsPlusOne << 2) {
  16123. // 0x0001 indicates the loca table consists of long offsets
  16124. data[50] = 0;
  16125. data[51] = 1;
  16126. } else {
  16127. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16128. }
  16129. }
  16130. }
  16131. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16132. isGlyphLocationsLong, hintsValid,
  16133. dupFirstEntry) {
  16134. var itemSize, itemDecode, itemEncode;
  16135. if (isGlyphLocationsLong) {
  16136. itemSize = 4;
  16137. itemDecode = function fontItemDecodeLong(data, offset) {
  16138. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16139. (data[offset + 2] << 8) | data[offset + 3];
  16140. };
  16141. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16142. data[offset] = (value >>> 24) & 0xFF;
  16143. data[offset + 1] = (value >> 16) & 0xFF;
  16144. data[offset + 2] = (value >> 8) & 0xFF;
  16145. data[offset + 3] = value & 0xFF;
  16146. };
  16147. } else {
  16148. itemSize = 2;
  16149. itemDecode = function fontItemDecode(data, offset) {
  16150. return (data[offset] << 9) | (data[offset + 1] << 1);
  16151. };
  16152. itemEncode = function fontItemEncode(data, offset, value) {
  16153. data[offset] = (value >> 9) & 0xFF;
  16154. data[offset + 1] = (value >> 1) & 0xFF;
  16155. };
  16156. }
  16157. var locaData = loca.data;
  16158. var locaDataSize = itemSize * (1 + numGlyphs);
  16159. // is loca.data too short or long?
  16160. if (locaData.length !== locaDataSize) {
  16161. locaData = new Uint8Array(locaDataSize);
  16162. locaData.set(loca.data.subarray(0, locaDataSize));
  16163. loca.data = locaData;
  16164. }
  16165. // removing the invalid glyphs
  16166. var oldGlyfData = glyf.data;
  16167. var oldGlyfDataLength = oldGlyfData.length;
  16168. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16169. var startOffset = itemDecode(locaData, 0);
  16170. var writeOffset = 0;
  16171. itemEncode(locaData, 0, writeOffset);
  16172. var i, j;
  16173. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16174. var endOffset = itemDecode(locaData, j);
  16175. if (endOffset > oldGlyfDataLength &&
  16176. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16177. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16178. // the glyf table size, which makes last glyph out of range.
  16179. endOffset = oldGlyfDataLength;
  16180. }
  16181. if (endOffset > oldGlyfDataLength) {
  16182. // glyph end offset points outside glyf data, rejecting the glyph
  16183. itemEncode(locaData, j, writeOffset);
  16184. startOffset = endOffset;
  16185. continue;
  16186. }
  16187. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16188. newGlyfData, writeOffset, hintsValid);
  16189. writeOffset += newLength;
  16190. itemEncode(locaData, j, writeOffset);
  16191. startOffset = endOffset;
  16192. }
  16193. if (writeOffset === 0) {
  16194. // glyf table cannot be empty -- redoing the glyf and loca tables
  16195. // to have single glyph with one point
  16196. var simpleGlyph = new Uint8Array(
  16197. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16198. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16199. itemEncode(locaData, j, simpleGlyph.length);
  16200. }
  16201. glyf.data = simpleGlyph;
  16202. return;
  16203. }
  16204. if (dupFirstEntry) {
  16205. var firstEntryLength = itemDecode(locaData, itemSize);
  16206. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16207. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16208. } else {
  16209. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16210. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16211. }
  16212. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16213. itemEncode(loca.data, locaData.length - itemSize,
  16214. writeOffset + firstEntryLength);
  16215. } else {
  16216. glyf.data = newGlyfData.subarray(0, writeOffset);
  16217. }
  16218. }
  16219. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16220. var start = (font.start ? font.start : 0) + post.offset;
  16221. font.pos = start;
  16222. var length = post.length, end = start + length;
  16223. var version = font.getInt32();
  16224. // skip rest to the tables
  16225. font.getBytes(28);
  16226. var glyphNames;
  16227. var valid = true;
  16228. var i;
  16229. switch (version) {
  16230. case 0x00010000:
  16231. glyphNames = MacStandardGlyphOrdering;
  16232. break;
  16233. case 0x00020000:
  16234. var numGlyphs = font.getUint16();
  16235. if (numGlyphs !== maxpNumGlyphs) {
  16236. valid = false;
  16237. break;
  16238. }
  16239. var glyphNameIndexes = [];
  16240. for (i = 0; i < numGlyphs; ++i) {
  16241. var index = font.getUint16();
  16242. if (index >= 32768) {
  16243. valid = false;
  16244. break;
  16245. }
  16246. glyphNameIndexes.push(index);
  16247. }
  16248. if (!valid) {
  16249. break;
  16250. }
  16251. var customNames = [];
  16252. var strBuf = [];
  16253. while (font.pos < end) {
  16254. var stringLength = font.getByte();
  16255. strBuf.length = stringLength;
  16256. for (i = 0; i < stringLength; ++i) {
  16257. strBuf[i] = String.fromCharCode(font.getByte());
  16258. }
  16259. customNames.push(strBuf.join(''));
  16260. }
  16261. glyphNames = [];
  16262. for (i = 0; i < numGlyphs; ++i) {
  16263. var j = glyphNameIndexes[i];
  16264. if (j < 258) {
  16265. glyphNames.push(MacStandardGlyphOrdering[j]);
  16266. continue;
  16267. }
  16268. glyphNames.push(customNames[j - 258]);
  16269. }
  16270. break;
  16271. case 0x00030000:
  16272. break;
  16273. default:
  16274. warn('Unknown/unsupported post table version ' + version);
  16275. valid = false;
  16276. break;
  16277. }
  16278. properties.glyphNames = glyphNames;
  16279. return valid;
  16280. }
  16281. function readNameTable(nameTable) {
  16282. var start = (font.start ? font.start : 0) + nameTable.offset;
  16283. font.pos = start;
  16284. var names = [[], []];
  16285. var length = nameTable.length, end = start + length;
  16286. var format = font.getUint16();
  16287. var FORMAT_0_HEADER_LENGTH = 6;
  16288. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16289. // unsupported name table format or table "too" small
  16290. return names;
  16291. }
  16292. var numRecords = font.getUint16();
  16293. var stringsStart = font.getUint16();
  16294. var records = [];
  16295. var NAME_RECORD_LENGTH = 12;
  16296. var i, ii;
  16297. for (i = 0; i < numRecords &&
  16298. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16299. var r = {
  16300. platform: font.getUint16(),
  16301. encoding: font.getUint16(),
  16302. language: font.getUint16(),
  16303. name: font.getUint16(),
  16304. length: font.getUint16(),
  16305. offset: font.getUint16()
  16306. };
  16307. // using only Macintosh and Windows platform/encoding names
  16308. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16309. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16310. records.push(r);
  16311. }
  16312. }
  16313. for (i = 0, ii = records.length; i < ii; i++) {
  16314. var record = records[i];
  16315. var pos = start + stringsStart + record.offset;
  16316. if (pos + record.length > end) {
  16317. continue; // outside of name table, ignoring
  16318. }
  16319. font.pos = pos;
  16320. var nameIndex = record.name;
  16321. if (record.encoding) {
  16322. // unicode
  16323. var str = '';
  16324. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16325. str += String.fromCharCode(font.getUint16());
  16326. }
  16327. names[1][nameIndex] = str;
  16328. } else {
  16329. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16330. }
  16331. }
  16332. return names;
  16333. }
  16334. var TTOpsStackDeltas = [
  16335. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16336. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16337. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16338. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16339. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16340. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16341. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16342. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16343. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16344. // 0xC0-DF == -1 and 0xE0-FF == -2
  16345. function sanitizeTTProgram(table, ttContext) {
  16346. var data = table.data;
  16347. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16348. var stack = [];
  16349. var callstack = [];
  16350. var functionsCalled = [];
  16351. var tooComplexToFollowFunctions =
  16352. ttContext.tooComplexToFollowFunctions;
  16353. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16354. for (var ii = data.length; i < ii;) {
  16355. var op = data[i++];
  16356. // The TrueType instruction set docs can be found at
  16357. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16358. if (op === 0x40) { // NPUSHB - pushes n bytes
  16359. n = data[i++];
  16360. if (inFDEF || inELSE) {
  16361. i += n;
  16362. } else {
  16363. for (j = 0; j < n; j++) {
  16364. stack.push(data[i++]);
  16365. }
  16366. }
  16367. } else if (op === 0x41) { // NPUSHW - pushes n words
  16368. n = data[i++];
  16369. if (inFDEF || inELSE) {
  16370. i += n * 2;
  16371. } else {
  16372. for (j = 0; j < n; j++) {
  16373. b = data[i++];
  16374. stack.push((b << 8) | data[i++]);
  16375. }
  16376. }
  16377. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16378. n = op - 0xB0 + 1;
  16379. if (inFDEF || inELSE) {
  16380. i += n;
  16381. } else {
  16382. for (j = 0; j < n; j++) {
  16383. stack.push(data[i++]);
  16384. }
  16385. }
  16386. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16387. n = op - 0xB8 + 1;
  16388. if (inFDEF || inELSE) {
  16389. i += n * 2;
  16390. } else {
  16391. for (j = 0; j < n; j++) {
  16392. b = data[i++];
  16393. stack.push((b << 8) | data[i++]);
  16394. }
  16395. }
  16396. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16397. if (!inFDEF && !inELSE) {
  16398. // collecting inforamtion about which functions are used
  16399. funcId = stack[stack.length - 1];
  16400. ttContext.functionsUsed[funcId] = true;
  16401. if (funcId in ttContext.functionsStackDeltas) {
  16402. stack.length += ttContext.functionsStackDeltas[funcId];
  16403. } else if (funcId in ttContext.functionsDefined &&
  16404. functionsCalled.indexOf(funcId) < 0) {
  16405. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16406. functionsCalled.push(funcId);
  16407. pc = ttContext.functionsDefined[funcId];
  16408. if (!pc) {
  16409. warn('TT: CALL non-existent function');
  16410. ttContext.hintsValid = false;
  16411. return;
  16412. }
  16413. data = pc.data;
  16414. i = pc.i;
  16415. }
  16416. }
  16417. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16418. if (inFDEF || inELSE) {
  16419. warn('TT: nested FDEFs not allowed');
  16420. tooComplexToFollowFunctions = true;
  16421. }
  16422. inFDEF = true;
  16423. // collecting inforamtion about which functions are defined
  16424. lastDeff = i;
  16425. funcId = stack.pop();
  16426. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16427. } else if (op === 0x2D) { // ENDF - end of function
  16428. if (inFDEF) {
  16429. inFDEF = false;
  16430. lastEndf = i;
  16431. } else {
  16432. pc = callstack.pop();
  16433. if (!pc) {
  16434. warn('TT: ENDF bad stack');
  16435. ttContext.hintsValid = false;
  16436. return;
  16437. }
  16438. funcId = functionsCalled.pop();
  16439. data = pc.data;
  16440. i = pc.i;
  16441. ttContext.functionsStackDeltas[funcId] =
  16442. stack.length - pc.stackTop;
  16443. }
  16444. } else if (op === 0x89) { // IDEF - instruction definition
  16445. if (inFDEF || inELSE) {
  16446. warn('TT: nested IDEFs not allowed');
  16447. tooComplexToFollowFunctions = true;
  16448. }
  16449. inFDEF = true;
  16450. // recording it as a function to track ENDF
  16451. lastDeff = i;
  16452. } else if (op === 0x58) { // IF
  16453. ++ifLevel;
  16454. } else if (op === 0x1B) { // ELSE
  16455. inELSE = ifLevel;
  16456. } else if (op === 0x59) { // EIF
  16457. if (inELSE === ifLevel) {
  16458. inELSE = 0;
  16459. }
  16460. --ifLevel;
  16461. } else if (op === 0x1C) { // JMPR
  16462. if (!inFDEF && !inELSE) {
  16463. var offset = stack[stack.length - 1];
  16464. // only jumping forward to prevent infinite loop
  16465. if (offset > 0) {
  16466. i += offset - 1;
  16467. }
  16468. }
  16469. }
  16470. // Adjusting stack not extactly, but just enough to get function id
  16471. if (!inFDEF && !inELSE) {
  16472. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16473. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16474. if (op >= 0x71 && op <= 0x75) {
  16475. n = stack.pop();
  16476. if (n === n) {
  16477. stackDelta = -n * 2;
  16478. }
  16479. }
  16480. while (stackDelta < 0 && stack.length > 0) {
  16481. stack.pop();
  16482. stackDelta++;
  16483. }
  16484. while (stackDelta > 0) {
  16485. stack.push(NaN); // pushing any number into stack
  16486. stackDelta--;
  16487. }
  16488. }
  16489. }
  16490. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16491. var content = [data];
  16492. if (i > data.length) {
  16493. content.push(new Uint8Array(i - data.length));
  16494. }
  16495. if (lastDeff > lastEndf) {
  16496. warn('TT: complementing a missing function tail');
  16497. // new function definition started, but not finished
  16498. // complete function by [CLEAR, ENDF]
  16499. content.push(new Uint8Array([0x22, 0x2D]));
  16500. }
  16501. foldTTTable(table, content);
  16502. }
  16503. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16504. if (ttContext.tooComplexToFollowFunctions) {
  16505. return;
  16506. }
  16507. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16508. warn('TT: more functions defined than expected');
  16509. ttContext.hintsValid = false;
  16510. return;
  16511. }
  16512. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16513. if (j > maxFunctionDefs) {
  16514. warn('TT: invalid function id: ' + j);
  16515. ttContext.hintsValid = false;
  16516. return;
  16517. }
  16518. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16519. warn('TT: undefined function: ' + j);
  16520. ttContext.hintsValid = false;
  16521. return;
  16522. }
  16523. }
  16524. }
  16525. function foldTTTable(table, content) {
  16526. if (content.length > 1) {
  16527. // concatenating the content items
  16528. var newLength = 0;
  16529. var j, jj;
  16530. for (j = 0, jj = content.length; j < jj; j++) {
  16531. newLength += content[j].length;
  16532. }
  16533. newLength = (newLength + 3) & ~3;
  16534. var result = new Uint8Array(newLength);
  16535. var pos = 0;
  16536. for (j = 0, jj = content.length; j < jj; j++) {
  16537. result.set(content[j], pos);
  16538. pos += content[j].length;
  16539. }
  16540. table.data = result;
  16541. table.length = newLength;
  16542. }
  16543. }
  16544. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16545. var ttContext = {
  16546. functionsDefined: [],
  16547. functionsUsed: [],
  16548. functionsStackDeltas: [],
  16549. tooComplexToFollowFunctions: false,
  16550. hintsValid: true
  16551. };
  16552. if (fpgm) {
  16553. sanitizeTTProgram(fpgm, ttContext);
  16554. }
  16555. if (prep) {
  16556. sanitizeTTProgram(prep, ttContext);
  16557. }
  16558. if (fpgm) {
  16559. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16560. }
  16561. if (cvt && (cvt.length & 1)) {
  16562. var cvtData = new Uint8Array(cvt.length + 1);
  16563. cvtData.set(cvt.data);
  16564. cvt.data = cvtData;
  16565. }
  16566. return ttContext.hintsValid;
  16567. }
  16568. // The following steps modify the original font data, making copy
  16569. font = new Stream(new Uint8Array(font.getBytes()));
  16570. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16571. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16572. var header = readOpenTypeHeader(font);
  16573. var numTables = header.numTables;
  16574. var cff, cffFile;
  16575. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16576. hmtx: null, maxp: null, name: null, post: null };
  16577. var table;
  16578. for (var i = 0; i < numTables; i++) {
  16579. table = readTableEntry(font);
  16580. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16581. continue; // skipping table if it's not a required or optional table
  16582. }
  16583. if (table.length === 0) {
  16584. continue; // skipping empty tables
  16585. }
  16586. tables[table.tag] = table;
  16587. }
  16588. var isTrueType = !tables['CFF '];
  16589. if (!isTrueType) {
  16590. // OpenType font
  16591. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16592. // no major tables: throwing everything at CFFFont
  16593. cffFile = new Stream(tables['CFF '].data);
  16594. cff = new CFFFont(cffFile, properties);
  16595. return this.convert(name, cff, properties);
  16596. }
  16597. delete tables.glyf;
  16598. delete tables.loca;
  16599. delete tables.fpgm;
  16600. delete tables.prep;
  16601. delete tables['cvt '];
  16602. this.isOpenType = true;
  16603. } else {
  16604. if (!tables.glyf || !tables.loca) {
  16605. error('Required "glyf" or "loca" tables are not found');
  16606. }
  16607. this.isOpenType = false;
  16608. }
  16609. if (!tables.maxp) {
  16610. error('Required "maxp" table is not found');
  16611. }
  16612. font.pos = (font.start || 0) + tables.maxp.offset;
  16613. var version = font.getInt32();
  16614. var numGlyphs = font.getUint16();
  16615. var maxFunctionDefs = 0;
  16616. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16617. // maxZones can be invalid
  16618. font.pos += 8;
  16619. var maxZones = font.getUint16();
  16620. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16621. tables.maxp.data[14] = 0;
  16622. tables.maxp.data[15] = 2;
  16623. }
  16624. font.pos += 4;
  16625. maxFunctionDefs = font.getUint16();
  16626. }
  16627. var dupFirstEntry = false;
  16628. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16629. properties.toUnicode.get(0) > '\u0000') {
  16630. // oracle's defect (see 3427), duplicating first entry
  16631. dupFirstEntry = true;
  16632. numGlyphs++;
  16633. tables.maxp.data[4] = numGlyphs >> 8;
  16634. tables.maxp.data[5] = numGlyphs & 255;
  16635. }
  16636. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16637. tables['cvt '], maxFunctionDefs);
  16638. if (!hintsValid) {
  16639. delete tables.fpgm;
  16640. delete tables.prep;
  16641. delete tables['cvt '];
  16642. }
  16643. // Ensure the hmtx table contains the advance width and
  16644. // sidebearings information for numGlyphs in the maxp table
  16645. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16646. if (!tables.head) {
  16647. error('Required "head" table is not found');
  16648. }
  16649. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16650. if (isTrueType) {
  16651. var isGlyphLocationsLong = int16(tables.head.data[50],
  16652. tables.head.data[51]);
  16653. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  16654. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  16655. }
  16656. if (!tables.hhea) {
  16657. error('Required "hhea" table is not found');
  16658. }
  16659. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16660. // Sometimes it's 0. That needs to be fixed
  16661. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16662. tables.hhea.data[10] = 0xFF;
  16663. tables.hhea.data[11] = 0xFF;
  16664. }
  16665. // The 'post' table has glyphs names.
  16666. if (tables.post) {
  16667. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  16668. if (!valid) {
  16669. tables.post = null;
  16670. }
  16671. }
  16672. var charCodeToGlyphId = [], charCode;
  16673. if (properties.type === 'CIDFontType2') {
  16674. var cidToGidMap = properties.cidToGidMap || [];
  16675. var cidToGidMapLength = cidToGidMap.length;
  16676. properties.cMap.forEach(function(charCode, cid) {
  16677. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  16678. var glyphId = -1;
  16679. if (cidToGidMapLength === 0) {
  16680. glyphId = charCode;
  16681. } else if (cidToGidMap[cid] !== undefined) {
  16682. glyphId = cidToGidMap[cid];
  16683. }
  16684. if (glyphId >= 0 && glyphId < numGlyphs) {
  16685. charCodeToGlyphId[charCode] = glyphId;
  16686. }
  16687. });
  16688. if (dupFirstEntry) {
  16689. charCodeToGlyphId[0] = numGlyphs - 1;
  16690. }
  16691. } else {
  16692. // Most of the following logic in this code branch is based on the
  16693. // 9.6.6.4 of the PDF spec.
  16694. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  16695. var cmapPlatformId = cmapTable.platformId;
  16696. var cmapEncodingId = cmapTable.encodingId;
  16697. var cmapMappings = cmapTable.mappings;
  16698. var cmapMappingsLength = cmapMappings.length;
  16699. var hasEncoding = properties.differences.length ||
  16700. !!properties.baseEncodingName;
  16701. // The spec seems to imply that if the font is symbolic the encoding
  16702. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  16703. // where the the font is symbolic and it has an encoding.
  16704. if (hasEncoding &&
  16705. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  16706. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  16707. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  16708. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  16709. // When no preferred cmap table was found and |baseEncodingName| is
  16710. // one of the predefined encodings, we seem to obtain a better
  16711. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  16712. // TODO: Note that this is a hack which should be removed as soon as
  16713. // we have proper support for more exotic cmap tables.
  16714. var baseEncoding = [];
  16715. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  16716. properties.baseEncodingName === 'WinAnsiEncoding') {
  16717. baseEncoding = Encodings[properties.baseEncodingName];
  16718. }
  16719. for (charCode = 0; charCode < 256; charCode++) {
  16720. var glyphName;
  16721. if (this.differences && charCode in this.differences) {
  16722. glyphName = this.differences[charCode];
  16723. } else if (charCode in baseEncoding &&
  16724. baseEncoding[charCode] !== '') {
  16725. glyphName = baseEncoding[charCode];
  16726. } else {
  16727. glyphName = Encodings.StandardEncoding[charCode];
  16728. }
  16729. if (!glyphName) {
  16730. continue;
  16731. }
  16732. var unicodeOrCharCode;
  16733. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  16734. unicodeOrCharCode = GlyphsUnicode[glyphName];
  16735. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  16736. // TODO: the encoding needs to be updated with mac os table.
  16737. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  16738. }
  16739. var found = false;
  16740. for (i = 0; i < cmapMappingsLength; ++i) {
  16741. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  16742. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16743. found = true;
  16744. break;
  16745. }
  16746. }
  16747. if (!found && properties.glyphNames) {
  16748. // Try to map using the post table. There are currently no known
  16749. // pdfs that this fixes.
  16750. var glyphId = properties.glyphNames.indexOf(glyphName);
  16751. if (glyphId > 0) {
  16752. charCodeToGlyphId[charCode] = glyphId;
  16753. }
  16754. }
  16755. }
  16756. } else {
  16757. // For (3, 0) cmap tables:
  16758. // The charcode key being stored in charCodeToGlyphId is the lower
  16759. // byte of the two-byte charcodes of the cmap table since according to
  16760. // the spec: 'each byte from the string shall be prepended with the
  16761. // high byte of the range [of charcodes in the cmap table], to form
  16762. // a two-byte character, which shall be used to select the
  16763. // associated glyph description from the subtable'.
  16764. //
  16765. // For (1, 0) cmap tables:
  16766. // 'single bytes from the string shall be used to look up the
  16767. // associated glyph descriptions from the subtable'. This means
  16768. // charcodes in the cmap will be single bytes, so no-op since
  16769. // glyph.charCode & 0xFF === glyph.charCode
  16770. for (i = 0; i < cmapMappingsLength; ++i) {
  16771. charCode = cmapMappings[i].charCode & 0xFF;
  16772. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  16773. }
  16774. }
  16775. }
  16776. if (charCodeToGlyphId.length === 0) {
  16777. // defines at least one glyph
  16778. charCodeToGlyphId[0] = 0;
  16779. }
  16780. // Converting glyphs and ids into font's cmap table
  16781. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  16782. this.toFontChar = newMapping.toFontChar;
  16783. tables.cmap = {
  16784. tag: 'cmap',
  16785. data: createCmapTable(newMapping.charCodeToGlyphId)
  16786. };
  16787. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  16788. // extract some more font properties from the OpenType head and
  16789. // hhea tables; yMin and descent value are always negative
  16790. var override = {
  16791. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  16792. yMax: int16(tables.head.data[42], tables.head.data[43]),
  16793. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  16794. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  16795. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  16796. };
  16797. tables['OS/2'] = {
  16798. tag: 'OS/2',
  16799. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  16800. override)
  16801. };
  16802. }
  16803. // Rewrite the 'post' table if needed
  16804. if (!tables.post) {
  16805. tables.post = {
  16806. tag: 'post',
  16807. data: createPostTable(properties)
  16808. };
  16809. }
  16810. if (!isTrueType) {
  16811. try {
  16812. // Trying to repair CFF file
  16813. cffFile = new Stream(tables['CFF '].data);
  16814. var parser = new CFFParser(cffFile, properties);
  16815. cff = parser.parse();
  16816. var compiler = new CFFCompiler(cff);
  16817. tables['CFF '].data = compiler.compile();
  16818. } catch (e) {
  16819. warn('Failed to compile font ' + properties.loadedName);
  16820. }
  16821. }
  16822. // Re-creating 'name' table
  16823. if (!tables.name) {
  16824. tables.name = {
  16825. tag: 'name',
  16826. data: createNameTable(this.name)
  16827. };
  16828. } else {
  16829. // ... using existing 'name' table as prototype
  16830. var namePrototype = readNameTable(tables.name);
  16831. tables.name.data = createNameTable(name, namePrototype);
  16832. }
  16833. var builder = new OpenTypeFileBuilder(header.version);
  16834. for (var tableTag in tables) {
  16835. builder.addTable(tableTag, tables[tableTag].data);
  16836. }
  16837. return builder.toArray();
  16838. },
  16839. convert: function Font_convert(fontName, font, properties) {
  16840. // TODO: Check the charstring widths to determine this.
  16841. properties.fixedPitch = false;
  16842. var mapping = font.getGlyphMapping(properties);
  16843. var newMapping = adjustMapping(mapping, properties);
  16844. this.toFontChar = newMapping.toFontChar;
  16845. var numGlyphs = font.numGlyphs;
  16846. function getCharCodes(charCodeToGlyphId, glyphId) {
  16847. var charCodes = null;
  16848. for (var charCode in charCodeToGlyphId) {
  16849. if (glyphId === charCodeToGlyphId[charCode]) {
  16850. if (!charCodes) {
  16851. charCodes = [];
  16852. }
  16853. charCodes.push(charCode | 0);
  16854. }
  16855. }
  16856. return charCodes;
  16857. }
  16858. function createCharCode(charCodeToGlyphId, glyphId) {
  16859. for (var charCode in charCodeToGlyphId) {
  16860. if (glyphId === charCodeToGlyphId[charCode]) {
  16861. return charCode | 0;
  16862. }
  16863. }
  16864. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  16865. glyphId;
  16866. return newMapping.nextAvailableFontCharCode++;
  16867. }
  16868. var seacs = font.seacs;
  16869. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  16870. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  16871. var charset = font.getCharset();
  16872. var seacMap = Object.create(null);
  16873. for (var glyphId in seacs) {
  16874. glyphId |= 0;
  16875. var seac = seacs[glyphId];
  16876. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  16877. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  16878. var baseGlyphId = charset.indexOf(baseGlyphName);
  16879. var accentGlyphId = charset.indexOf(accentGlyphName);
  16880. if (baseGlyphId < 0 || accentGlyphId < 0) {
  16881. continue;
  16882. }
  16883. var accentOffset = {
  16884. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  16885. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  16886. };
  16887. var charCodes = getCharCodes(mapping, glyphId);
  16888. if (!charCodes) {
  16889. // There's no point in mapping it if the char code was never mapped
  16890. // to begin with.
  16891. continue;
  16892. }
  16893. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  16894. var charCode = charCodes[i];
  16895. // Find a fontCharCode that maps to the base and accent glyphs.
  16896. // If one doesn't exists, create it.
  16897. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  16898. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  16899. baseGlyphId);
  16900. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  16901. accentGlyphId);
  16902. seacMap[charCode] = {
  16903. baseFontCharCode: baseFontCharCode,
  16904. accentFontCharCode: accentFontCharCode,
  16905. accentOffset: accentOffset
  16906. };
  16907. }
  16908. }
  16909. properties.seacMap = seacMap;
  16910. }
  16911. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  16912. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  16913. // PostScript Font Program
  16914. builder.addTable('CFF ', font.data);
  16915. // OS/2 and Windows Specific metrics
  16916. builder.addTable('OS/2', createOS2Table(properties,
  16917. newMapping.charCodeToGlyphId));
  16918. // Character to glyphs mapping
  16919. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  16920. // Font header
  16921. builder.addTable('head',
  16922. '\x00\x01\x00\x00' + // Version number
  16923. '\x00\x00\x10\x00' + // fontRevision
  16924. '\x00\x00\x00\x00' + // checksumAdjustement
  16925. '\x5F\x0F\x3C\xF5' + // magicNumber
  16926. '\x00\x00' + // Flags
  16927. safeString16(unitsPerEm) + // unitsPerEM
  16928. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  16929. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  16930. '\x00\x00' + // xMin
  16931. safeString16(properties.descent) + // yMin
  16932. '\x0F\xFF' + // xMax
  16933. safeString16(properties.ascent) + // yMax
  16934. string16(properties.italicAngle ? 2 : 0) + // macStyle
  16935. '\x00\x11' + // lowestRecPPEM
  16936. '\x00\x00' + // fontDirectionHint
  16937. '\x00\x00' + // indexToLocFormat
  16938. '\x00\x00'); // glyphDataFormat
  16939. // Horizontal header
  16940. builder.addTable('hhea',
  16941. '\x00\x01\x00\x00' + // Version number
  16942. safeString16(properties.ascent) + // Typographic Ascent
  16943. safeString16(properties.descent) + // Typographic Descent
  16944. '\x00\x00' + // Line Gap
  16945. '\xFF\xFF' + // advanceWidthMax
  16946. '\x00\x00' + // minLeftSidebearing
  16947. '\x00\x00' + // minRightSidebearing
  16948. '\x00\x00' + // xMaxExtent
  16949. safeString16(properties.capHeight) + // caretSlopeRise
  16950. safeString16(Math.tan(properties.italicAngle) *
  16951. properties.xHeight) + // caretSlopeRun
  16952. '\x00\x00' + // caretOffset
  16953. '\x00\x00' + // -reserved-
  16954. '\x00\x00' + // -reserved-
  16955. '\x00\x00' + // -reserved-
  16956. '\x00\x00' + // -reserved-
  16957. '\x00\x00' + // metricDataFormat
  16958. string16(numGlyphs)); // Number of HMetrics
  16959. // Horizontal metrics
  16960. builder.addTable('hmtx', (function fontFieldsHmtx() {
  16961. var charstrings = font.charstrings;
  16962. var cffWidths = font.cff ? font.cff.widths : null;
  16963. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  16964. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  16965. var width = 0;
  16966. if (charstrings) {
  16967. var charstring = charstrings[i - 1];
  16968. width = 'width' in charstring ? charstring.width : 0;
  16969. } else if (cffWidths) {
  16970. width = Math.ceil(cffWidths[i] || 0);
  16971. }
  16972. hmtx += string16(width) + string16(0);
  16973. }
  16974. return hmtx;
  16975. })());
  16976. // Maximum profile
  16977. builder.addTable('maxp',
  16978. '\x00\x00\x50\x00' + // Version number
  16979. string16(numGlyphs)); // Num of glyphs
  16980. // Naming tables
  16981. builder.addTable('name', createNameTable(fontName));
  16982. // PostScript informations
  16983. builder.addTable('post', createPostTable(properties));
  16984. return builder.toArray();
  16985. },
  16986. /**
  16987. * Builds a char code to unicode map based on section 9.10 of the spec.
  16988. * @param {Object} properties Font properties object.
  16989. * @return {Object} A ToUnicodeMap object.
  16990. */
  16991. buildToUnicode: function Font_buildToUnicode(properties) {
  16992. // Section 9.10.2 Mapping Character Codes to Unicode Values
  16993. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  16994. return properties.toUnicode;
  16995. }
  16996. // According to the spec if the font is a simple font we should only map
  16997. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  16998. // the differences array only contains adobe standard or symbol set names,
  16999. // in pratice it seems better to always try to create a toUnicode
  17000. // map based of the default encoding.
  17001. var toUnicode, charcode;
  17002. if (!properties.composite /* is simple font */) {
  17003. toUnicode = [];
  17004. var encoding = properties.defaultEncoding.slice();
  17005. var baseEncodingName = properties.baseEncodingName;
  17006. // Merge in the differences array.
  17007. var differences = properties.differences;
  17008. for (charcode in differences) {
  17009. encoding[charcode] = differences[charcode];
  17010. }
  17011. for (charcode in encoding) {
  17012. // a) Map the character code to a character name.
  17013. var glyphName = encoding[charcode];
  17014. // b) Look up the character name in the Adobe Glyph List (see the
  17015. // Bibliography) to obtain the corresponding Unicode value.
  17016. if (glyphName === '') {
  17017. continue;
  17018. } else if (GlyphsUnicode[glyphName] === undefined) {
  17019. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17020. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17021. var code = 0;
  17022. switch (glyphName[0]) {
  17023. case 'G': // Gxx glyph
  17024. if (glyphName.length === 3) {
  17025. code = parseInt(glyphName.substr(1), 16);
  17026. }
  17027. break;
  17028. case 'g': // g00xx glyph
  17029. if (glyphName.length === 5) {
  17030. code = parseInt(glyphName.substr(1), 16);
  17031. }
  17032. break;
  17033. case 'C': // Cddd glyph
  17034. case 'c': // cddd glyph
  17035. if (glyphName.length >= 3) {
  17036. code = +glyphName.substr(1);
  17037. }
  17038. break;
  17039. }
  17040. if (code) {
  17041. // If |baseEncodingName| is one the predefined encodings,
  17042. // and |code| equals |charcode|, using the glyph defined in the
  17043. // baseEncoding seems to yield a better |toUnicode| mapping
  17044. // (fixes issue 5070).
  17045. if (baseEncodingName && code === +charcode) {
  17046. var baseEncoding = Encodings[baseEncodingName];
  17047. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17048. toUnicode[charcode] =
  17049. String.fromCharCode(GlyphsUnicode[glyphName]);
  17050. continue;
  17051. }
  17052. }
  17053. toUnicode[charcode] = String.fromCharCode(code);
  17054. }
  17055. continue;
  17056. }
  17057. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17058. }
  17059. return new ToUnicodeMap(toUnicode);
  17060. }
  17061. // If the font is a composite font that uses one of the predefined CMaps
  17062. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17063. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17064. // Adobe-Korea1 character collection:
  17065. if (properties.composite && (
  17066. (properties.cMap.builtInCMap &&
  17067. !(properties.cMap instanceof IdentityCMap)) ||
  17068. (properties.cidSystemInfo.registry === 'Adobe' &&
  17069. (properties.cidSystemInfo.ordering === 'GB1' ||
  17070. properties.cidSystemInfo.ordering === 'CNS1' ||
  17071. properties.cidSystemInfo.ordering === 'Japan1' ||
  17072. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17073. // Then:
  17074. // a) Map the character code to a character identifier (CID) according
  17075. // to the font’s CMap.
  17076. // b) Obtain the registry and ordering of the character collection used
  17077. // by the font’s CMap (for example, Adobe and Japan1) from its
  17078. // CIDSystemInfo dictionary.
  17079. var registry = properties.cidSystemInfo.registry;
  17080. var ordering = properties.cidSystemInfo.ordering;
  17081. // c) Construct a second CMap name by concatenating the registry and
  17082. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17083. // (for example, Adobe–Japan1–UCS2).
  17084. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17085. // d) Obtain the CMap with the name constructed in step (c) (available
  17086. // from the ASN Web site; see the Bibliography).
  17087. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17088. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17089. var cMap = properties.cMap;
  17090. toUnicode = [];
  17091. cMap.forEach(function(charcode, cid) {
  17092. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17093. // e) Map the CID obtained in step (a) according to the CMap obtained
  17094. // in step (d), producing a Unicode value.
  17095. var ucs2 = ucs2CMap.lookup(cid);
  17096. if (ucs2) {
  17097. toUnicode[charcode] =
  17098. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17099. ucs2.charCodeAt(1));
  17100. }
  17101. });
  17102. return new ToUnicodeMap(toUnicode);
  17103. }
  17104. // The viewer's choice, just use an identity map.
  17105. return new IdentityToUnicodeMap(properties.firstChar,
  17106. properties.lastChar);
  17107. },
  17108. get spaceWidth() {
  17109. if ('_shadowWidth' in this) {
  17110. return this._shadowWidth;
  17111. }
  17112. // trying to estimate space character width
  17113. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17114. var width;
  17115. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17116. var glyphName = possibleSpaceReplacements[i];
  17117. // if possible, getting width by glyph name
  17118. if (glyphName in this.widths) {
  17119. width = this.widths[glyphName];
  17120. break;
  17121. }
  17122. var glyphUnicode = GlyphsUnicode[glyphName];
  17123. // finding the charcode via unicodeToCID map
  17124. var charcode = 0;
  17125. if (this.composite) {
  17126. if (this.cMap.contains(glyphUnicode)) {
  17127. charcode = this.cMap.lookup(glyphUnicode);
  17128. }
  17129. }
  17130. // ... via toUnicode map
  17131. if (!charcode && 'toUnicode' in this) {
  17132. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17133. }
  17134. // setting it to unicode if negative or undefined
  17135. if (charcode <= 0) {
  17136. charcode = glyphUnicode;
  17137. }
  17138. // trying to get width via charcode
  17139. width = this.widths[charcode];
  17140. if (width) {
  17141. break; // the non-zero width found
  17142. }
  17143. }
  17144. width = width || this.defaultWidth;
  17145. // Do not shadow the property here. See discussion:
  17146. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17147. this._shadowWidth = width;
  17148. return width;
  17149. },
  17150. charToGlyph: function Font_charToGlyph(charcode) {
  17151. var fontCharCode, width, operatorListId;
  17152. var widthCode = charcode;
  17153. if (this.cMap && this.cMap.contains(charcode)) {
  17154. widthCode = this.cMap.lookup(charcode);
  17155. }
  17156. width = this.widths[widthCode];
  17157. width = isNum(width) ? width : this.defaultWidth;
  17158. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17159. var unicode = this.toUnicode.get(charcode) || charcode;
  17160. if (typeof unicode === 'number') {
  17161. unicode = String.fromCharCode(unicode);
  17162. }
  17163. // First try the toFontChar map, if it's not there then try falling
  17164. // back to the char code.
  17165. fontCharCode = this.toFontChar[charcode] || charcode;
  17166. if (this.missingFile) {
  17167. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17168. }
  17169. if (this.isType3Font) {
  17170. // Font char code in this case is actually a glyph name.
  17171. operatorListId = fontCharCode;
  17172. }
  17173. var accent = null;
  17174. if (this.seacMap && this.seacMap[charcode]) {
  17175. var seac = this.seacMap[charcode];
  17176. fontCharCode = seac.baseFontCharCode;
  17177. accent = {
  17178. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17179. offset: seac.accentOffset
  17180. };
  17181. }
  17182. var fontChar = String.fromCharCode(fontCharCode);
  17183. var glyph = this.glyphCache[charcode];
  17184. if (!glyph ||
  17185. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17186. operatorListId)) {
  17187. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17188. operatorListId);
  17189. this.glyphCache[charcode] = glyph;
  17190. }
  17191. return glyph;
  17192. },
  17193. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17194. var charsCache = this.charsCache;
  17195. var glyphs, glyph, charcode;
  17196. // if we translated this string before, just grab it from the cache
  17197. if (charsCache) {
  17198. glyphs = charsCache[chars];
  17199. if (glyphs) {
  17200. return glyphs;
  17201. }
  17202. }
  17203. // lazily create the translation cache
  17204. if (!charsCache) {
  17205. charsCache = this.charsCache = Object.create(null);
  17206. }
  17207. glyphs = [];
  17208. var charsCacheKey = chars;
  17209. var i = 0, ii;
  17210. if (this.cMap) {
  17211. // composite fonts have multi-byte strings convert the string from
  17212. // single-byte to multi-byte
  17213. var c = {};
  17214. while (i < chars.length) {
  17215. this.cMap.readCharCode(chars, i, c);
  17216. charcode = c.charcode;
  17217. var length = c.length;
  17218. i += length;
  17219. glyph = this.charToGlyph(charcode);
  17220. glyphs.push(glyph);
  17221. // placing null after each word break charcode (ASCII SPACE)
  17222. // Ignore occurences of 0x20 in multiple-byte codes.
  17223. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17224. glyphs.push(null);
  17225. }
  17226. }
  17227. } else {
  17228. for (i = 0, ii = chars.length; i < ii; ++i) {
  17229. charcode = chars.charCodeAt(i);
  17230. glyph = this.charToGlyph(charcode);
  17231. glyphs.push(glyph);
  17232. if (charcode === 0x20) {
  17233. glyphs.push(null);
  17234. }
  17235. }
  17236. }
  17237. // Enter the translated string into the cache
  17238. return (charsCache[charsCacheKey] = glyphs);
  17239. }
  17240. };
  17241. return Font;
  17242. })();
  17243. var ErrorFont = (function ErrorFontClosure() {
  17244. function ErrorFont(error) {
  17245. this.error = error;
  17246. this.loadedName = 'g_font_error';
  17247. this.loading = false;
  17248. }
  17249. ErrorFont.prototype = {
  17250. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17251. return [];
  17252. },
  17253. exportData: function ErrorFont_exportData() {
  17254. return {error: this.error};
  17255. }
  17256. };
  17257. return ErrorFont;
  17258. })();
  17259. /**
  17260. * Shared logic for building a char code to glyph id mapping for Type1 and
  17261. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17262. * @param {Object} properties Font properties object.
  17263. * @param {Object} builtInEncoding The encoding contained within the actual font
  17264. * data.
  17265. * @param {Array} Array of glyph names where the index is the glyph ID.
  17266. * @returns {Object} A char code to glyph ID map.
  17267. */
  17268. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17269. var charCodeToGlyphId = Object.create(null);
  17270. var glyphId, charCode, baseEncoding;
  17271. if (properties.baseEncodingName) {
  17272. // If a valid base encoding name was used, the mapping is initialized with
  17273. // that.
  17274. baseEncoding = Encodings[properties.baseEncodingName];
  17275. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17276. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17277. if (glyphId >= 0) {
  17278. charCodeToGlyphId[charCode] = glyphId;
  17279. } else {
  17280. charCodeToGlyphId[charCode] = 0; // notdef
  17281. }
  17282. }
  17283. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17284. // For a symbolic font the encoding should be the fonts built-in
  17285. // encoding.
  17286. for (charCode in builtInEncoding) {
  17287. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17288. }
  17289. } else {
  17290. // For non-symbolic fonts that don't have a base encoding the standard
  17291. // encoding should be used.
  17292. baseEncoding = Encodings.StandardEncoding;
  17293. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17294. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17295. if (glyphId >= 0) {
  17296. charCodeToGlyphId[charCode] = glyphId;
  17297. } else {
  17298. charCodeToGlyphId[charCode] = 0; // notdef
  17299. }
  17300. }
  17301. }
  17302. // Lastly, merge in the differences.
  17303. var differences = properties.differences;
  17304. if (differences) {
  17305. for (charCode in differences) {
  17306. var glyphName = differences[charCode];
  17307. glyphId = glyphNames.indexOf(glyphName);
  17308. if (glyphId >= 0) {
  17309. charCodeToGlyphId[charCode] = glyphId;
  17310. } else {
  17311. charCodeToGlyphId[charCode] = 0; // notdef
  17312. }
  17313. }
  17314. }
  17315. return charCodeToGlyphId;
  17316. }
  17317. /*
  17318. * CharStrings are encoded following the the CharString Encoding sequence
  17319. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17320. * The value in a byte indicates a command, a number, or subsequent bytes
  17321. * that are to be interpreted in a special way.
  17322. *
  17323. * CharString Number Encoding:
  17324. * A CharString byte containing the values from 32 through 255 inclusive
  17325. * indicate an integer. These values are decoded in four ranges.
  17326. *
  17327. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17328. * indicate the integer v - 139. Thus, the integer values from -107 through
  17329. * 107 inclusive may be encoded in single byte.
  17330. *
  17331. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17332. * indicates an integer involving the next byte, w, according to the formula:
  17333. * [(v - 247) x 256] + w + 108
  17334. *
  17335. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17336. * indicates an integer involving the next byte, w, according to the formula:
  17337. * -[(v - 251) * 256] - w - 108
  17338. *
  17339. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17340. * are a two complement signed integer. The first of these bytes contains the
  17341. * highest order bits, the second byte contains the next higher order bits
  17342. * and the fourth byte contain the lowest order bits.
  17343. *
  17344. *
  17345. * CharString Command Encoding:
  17346. * CharStrings commands are encoded in 1 or 2 bytes.
  17347. *
  17348. * Single byte commands are encoded in 1 byte that contains a value between
  17349. * 0 and 31 inclusive.
  17350. * If a command byte contains the value 12, then the value in the next byte
  17351. * indicates a command. This "escape" mechanism allows many extra commands
  17352. * to be encoded and this encoding technique helps to minimize the length of
  17353. * the charStrings.
  17354. */
  17355. var Type1CharString = (function Type1CharStringClosure() {
  17356. var COMMAND_MAP = {
  17357. 'hstem': [1],
  17358. 'vstem': [3],
  17359. 'vmoveto': [4],
  17360. 'rlineto': [5],
  17361. 'hlineto': [6],
  17362. 'vlineto': [7],
  17363. 'rrcurveto': [8],
  17364. 'callsubr': [10],
  17365. 'flex': [12, 35],
  17366. 'drop' : [12, 18],
  17367. 'endchar': [14],
  17368. 'rmoveto': [21],
  17369. 'hmoveto': [22],
  17370. 'vhcurveto': [30],
  17371. 'hvcurveto': [31]
  17372. };
  17373. function Type1CharString() {
  17374. this.width = 0;
  17375. this.lsb = 0;
  17376. this.flexing = false;
  17377. this.output = [];
  17378. this.stack = [];
  17379. }
  17380. Type1CharString.prototype = {
  17381. convert: function Type1CharString_convert(encoded, subrs) {
  17382. var count = encoded.length;
  17383. var error = false;
  17384. var wx, sbx, subrNumber;
  17385. for (var i = 0; i < count; i++) {
  17386. var value = encoded[i];
  17387. if (value < 32) {
  17388. if (value === 12) {
  17389. value = (value << 8) + encoded[++i];
  17390. }
  17391. switch (value) {
  17392. case 1: // hstem
  17393. if (!HINTING_ENABLED) {
  17394. this.stack = [];
  17395. break;
  17396. }
  17397. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17398. break;
  17399. case 3: // vstem
  17400. if (!HINTING_ENABLED) {
  17401. this.stack = [];
  17402. break;
  17403. }
  17404. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17405. break;
  17406. case 4: // vmoveto
  17407. if (this.flexing) {
  17408. if (this.stack.length < 1) {
  17409. error = true;
  17410. break;
  17411. }
  17412. // Add the dx for flex and but also swap the values so they are
  17413. // the right order.
  17414. var dy = this.stack.pop();
  17415. this.stack.push(0, dy);
  17416. break;
  17417. }
  17418. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17419. break;
  17420. case 5: // rlineto
  17421. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17422. break;
  17423. case 6: // hlineto
  17424. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17425. break;
  17426. case 7: // vlineto
  17427. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17428. break;
  17429. case 8: // rrcurveto
  17430. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17431. break;
  17432. case 9: // closepath
  17433. // closepath is a Type1 command that does not take argument and is
  17434. // useless in Type2 and it can simply be ignored.
  17435. this.stack = [];
  17436. break;
  17437. case 10: // callsubr
  17438. if (this.stack.length < 1) {
  17439. error = true;
  17440. break;
  17441. }
  17442. subrNumber = this.stack.pop();
  17443. error = this.convert(subrs[subrNumber], subrs);
  17444. break;
  17445. case 11: // return
  17446. return error;
  17447. case 13: // hsbw
  17448. if (this.stack.length < 2) {
  17449. error = true;
  17450. break;
  17451. }
  17452. // To convert to type2 we have to move the width value to the
  17453. // first part of the charstring and then use hmoveto with lsb.
  17454. wx = this.stack.pop();
  17455. sbx = this.stack.pop();
  17456. this.lsb = sbx;
  17457. this.width = wx;
  17458. this.stack.push(wx, sbx);
  17459. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17460. break;
  17461. case 14: // endchar
  17462. this.output.push(COMMAND_MAP.endchar[0]);
  17463. break;
  17464. case 21: // rmoveto
  17465. if (this.flexing) {
  17466. break;
  17467. }
  17468. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17469. break;
  17470. case 22: // hmoveto
  17471. if (this.flexing) {
  17472. // Add the dy for flex.
  17473. this.stack.push(0);
  17474. break;
  17475. }
  17476. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17477. break;
  17478. case 30: // vhcurveto
  17479. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17480. break;
  17481. case 31: // hvcurveto
  17482. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17483. break;
  17484. case (12 << 8) + 0: // dotsection
  17485. // dotsection is a Type1 command to specify some hinting feature
  17486. // for dots that do not take a parameter and it can safely be
  17487. // ignored for Type2.
  17488. this.stack = [];
  17489. break;
  17490. case (12 << 8) + 1: // vstem3
  17491. if (!HINTING_ENABLED) {
  17492. this.stack = [];
  17493. break;
  17494. }
  17495. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17496. // multiple parameters, so instead of returning [vh]stem3 take a
  17497. // shortcut and return [vhstem] instead.
  17498. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17499. break;
  17500. case (12 << 8) + 2: // hstem3
  17501. if (!HINTING_ENABLED) {
  17502. this.stack = [];
  17503. break;
  17504. }
  17505. // See vstem3.
  17506. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17507. break;
  17508. case (12 << 8) + 6: // seac
  17509. // seac is like type 2's special endchar but it doesn't use the
  17510. // first argument asb, so remove it.
  17511. if (SEAC_ANALYSIS_ENABLED) {
  17512. this.seac = this.stack.splice(-4, 4);
  17513. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17514. } else {
  17515. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17516. }
  17517. break;
  17518. case (12 << 8) + 7: // sbw
  17519. if (this.stack.length < 4) {
  17520. error = true;
  17521. break;
  17522. }
  17523. // To convert to type2 we have to move the width value to the
  17524. // first part of the charstring and then use rmoveto with
  17525. // (dx, dy). The height argument will not be used for vmtx and
  17526. // vhea tables reconstruction -- ignoring it.
  17527. var wy = this.stack.pop();
  17528. wx = this.stack.pop();
  17529. var sby = this.stack.pop();
  17530. sbx = this.stack.pop();
  17531. this.lsb = sbx;
  17532. this.width = wx;
  17533. this.stack.push(wx, sbx, sby);
  17534. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17535. break;
  17536. case (12 << 8) + 12: // div
  17537. if (this.stack.length < 2) {
  17538. error = true;
  17539. break;
  17540. }
  17541. var num2 = this.stack.pop();
  17542. var num1 = this.stack.pop();
  17543. this.stack.push(num1 / num2);
  17544. break;
  17545. case (12 << 8) + 16: // callothersubr
  17546. if (this.stack.length < 2) {
  17547. error = true;
  17548. break;
  17549. }
  17550. subrNumber = this.stack.pop();
  17551. var numArgs = this.stack.pop();
  17552. if (subrNumber === 0 && numArgs === 3) {
  17553. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17554. this.stack.push(
  17555. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17556. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17557. flexArgs[4], // bcp2x
  17558. flexArgs[5], // bcp2y
  17559. flexArgs[6], // p2x
  17560. flexArgs[7], // p2y
  17561. flexArgs[8], // bcp3x
  17562. flexArgs[9], // bcp3y
  17563. flexArgs[10], // bcp4x
  17564. flexArgs[11], // bcp4y
  17565. flexArgs[12], // p3x
  17566. flexArgs[13], // p3y
  17567. flexArgs[14] // flexDepth
  17568. // 15 = finalx unused by flex
  17569. // 16 = finaly unused by flex
  17570. );
  17571. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17572. this.flexing = false;
  17573. this.stack.push(flexArgs[15], flexArgs[16]);
  17574. } else if (subrNumber === 1 && numArgs === 0) {
  17575. this.flexing = true;
  17576. }
  17577. break;
  17578. case (12 << 8) + 17: // pop
  17579. // Ignore this since it is only used with othersubr.
  17580. break;
  17581. case (12 << 8) + 33: // setcurrentpoint
  17582. // Ignore for now.
  17583. this.stack = [];
  17584. break;
  17585. default:
  17586. warn('Unknown type 1 charstring command of "' + value + '"');
  17587. break;
  17588. }
  17589. if (error) {
  17590. break;
  17591. }
  17592. continue;
  17593. } else if (value <= 246) {
  17594. value = value - 139;
  17595. } else if (value <= 250) {
  17596. value = ((value - 247) * 256) + encoded[++i] + 108;
  17597. } else if (value <= 254) {
  17598. value = -((value - 251) * 256) - encoded[++i] - 108;
  17599. } else {
  17600. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17601. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17602. }
  17603. this.stack.push(value);
  17604. }
  17605. return error;
  17606. },
  17607. executeCommand: function(howManyArgs, command, keepStack) {
  17608. var stackLength = this.stack.length;
  17609. if (howManyArgs > stackLength) {
  17610. return true;
  17611. }
  17612. var start = stackLength - howManyArgs;
  17613. for (var i = start; i < stackLength; i++) {
  17614. var value = this.stack[i];
  17615. if (value === (value | 0)) { // int
  17616. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17617. } else { // fixed point
  17618. value = (65536 * value) | 0;
  17619. this.output.push(255,
  17620. (value >> 24) & 0xFF,
  17621. (value >> 16) & 0xFF,
  17622. (value >> 8) & 0xFF,
  17623. value & 0xFF);
  17624. }
  17625. }
  17626. this.output.push.apply(this.output, command);
  17627. if (keepStack) {
  17628. this.stack.splice(start, howManyArgs);
  17629. } else {
  17630. this.stack.length = 0;
  17631. }
  17632. return false;
  17633. }
  17634. };
  17635. return Type1CharString;
  17636. })();
  17637. /*
  17638. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17639. * program. Some of its logic depends on the Type2 charstrings
  17640. * structure.
  17641. * Note: this doesn't really parse the font since that would require evaluation
  17642. * of PostScript, but it is possible in most cases to extract what we need
  17643. * without a full parse.
  17644. */
  17645. var Type1Parser = (function Type1ParserClosure() {
  17646. /*
  17647. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  17648. * of Plaintext Bytes. The function took a key as a parameter which can be
  17649. * for decrypting the eexec block of for decoding charStrings.
  17650. */
  17651. var EEXEC_ENCRYPT_KEY = 55665;
  17652. var CHAR_STRS_ENCRYPT_KEY = 4330;
  17653. function isHexDigit(code) {
  17654. return code >= 48 && code <= 57 || // '0'-'9'
  17655. code >= 65 && code <= 70 || // 'A'-'F'
  17656. code >= 97 && code <= 102; // 'a'-'f'
  17657. }
  17658. function decrypt(data, key, discardNumber) {
  17659. var r = key | 0, c1 = 52845, c2 = 22719;
  17660. var count = data.length;
  17661. var decrypted = new Uint8Array(count);
  17662. for (var i = 0; i < count; i++) {
  17663. var value = data[i];
  17664. decrypted[i] = value ^ (r >> 8);
  17665. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17666. }
  17667. return Array.prototype.slice.call(decrypted, discardNumber);
  17668. }
  17669. function decryptAscii(data, key, discardNumber) {
  17670. var r = key | 0, c1 = 52845, c2 = 22719;
  17671. var count = data.length, maybeLength = count >>> 1;
  17672. var decrypted = new Uint8Array(maybeLength);
  17673. var i, j;
  17674. for (i = 0, j = 0; i < count; i++) {
  17675. var digit1 = data[i];
  17676. if (!isHexDigit(digit1)) {
  17677. continue;
  17678. }
  17679. i++;
  17680. var digit2;
  17681. while (i < count && !isHexDigit(digit2 = data[i])) {
  17682. i++;
  17683. }
  17684. if (i < count) {
  17685. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  17686. decrypted[j++] = value ^ (r >> 8);
  17687. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  17688. }
  17689. }
  17690. return Array.prototype.slice.call(decrypted, discardNumber, j);
  17691. }
  17692. function isSpecial(c) {
  17693. return c === 0x2F || // '/'
  17694. c === 0x5B || c === 0x5D || // '[', ']'
  17695. c === 0x7B || c === 0x7D || // '{', '}'
  17696. c === 0x28 || c === 0x29; // '(', ')'
  17697. }
  17698. function Type1Parser(stream, encrypted) {
  17699. if (encrypted) {
  17700. var data = stream.getBytes();
  17701. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  17702. isHexDigit(data[2]) && isHexDigit(data[3]));
  17703. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  17704. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  17705. }
  17706. this.stream = stream;
  17707. this.nextChar();
  17708. }
  17709. Type1Parser.prototype = {
  17710. readNumberArray: function Type1Parser_readNumberArray() {
  17711. this.getToken(); // read '[' or '{' (arrays can start with either)
  17712. var array = [];
  17713. while (true) {
  17714. var token = this.getToken();
  17715. if (token === null || token === ']' || token === '}') {
  17716. break;
  17717. }
  17718. array.push(parseFloat(token || 0));
  17719. }
  17720. return array;
  17721. },
  17722. readNumber: function Type1Parser_readNumber() {
  17723. var token = this.getToken();
  17724. return parseFloat(token || 0);
  17725. },
  17726. readInt: function Type1Parser_readInt() {
  17727. // Use '| 0' to prevent setting a double into length such as the double
  17728. // does not flow into the loop variable.
  17729. var token = this.getToken();
  17730. return parseInt(token || 0, 10) | 0;
  17731. },
  17732. readBoolean: function Type1Parser_readBoolean() {
  17733. var token = this.getToken();
  17734. // Use 1 and 0 since that's what type2 charstrings use.
  17735. return token === 'true' ? 1 : 0;
  17736. },
  17737. nextChar : function Type1_nextChar() {
  17738. return (this.currentChar = this.stream.getByte());
  17739. },
  17740. getToken: function Type1Parser_getToken() {
  17741. // Eat whitespace and comments.
  17742. var comment = false;
  17743. var ch = this.currentChar;
  17744. while (true) {
  17745. if (ch === -1) {
  17746. return null;
  17747. }
  17748. if (comment) {
  17749. if (ch === 0x0A || ch === 0x0D) {
  17750. comment = false;
  17751. }
  17752. } else if (ch === 0x25) { // '%'
  17753. comment = true;
  17754. } else if (!Lexer.isSpace(ch)) {
  17755. break;
  17756. }
  17757. ch = this.nextChar();
  17758. }
  17759. if (isSpecial(ch)) {
  17760. this.nextChar();
  17761. return String.fromCharCode(ch);
  17762. }
  17763. var token = '';
  17764. do {
  17765. token += String.fromCharCode(ch);
  17766. ch = this.nextChar();
  17767. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  17768. return token;
  17769. },
  17770. /*
  17771. * Returns an object containing a Subrs array and a CharStrings
  17772. * array extracted from and eexec encrypted block of data
  17773. */
  17774. extractFontProgram: function Type1Parser_extractFontProgram() {
  17775. var stream = this.stream;
  17776. var subrs = [], charstrings = [];
  17777. var program = {
  17778. subrs: [],
  17779. charstrings: [],
  17780. properties: {
  17781. 'privateData': {
  17782. 'lenIV': 4
  17783. }
  17784. }
  17785. };
  17786. var token, length, data, lenIV, encoded;
  17787. while ((token = this.getToken()) !== null) {
  17788. if (token !== '/') {
  17789. continue;
  17790. }
  17791. token = this.getToken();
  17792. switch (token) {
  17793. case 'CharStrings':
  17794. // The number immediately following CharStrings must be greater or
  17795. // equal to the number of CharStrings.
  17796. this.getToken();
  17797. this.getToken(); // read in 'dict'
  17798. this.getToken(); // read in 'dup'
  17799. this.getToken(); // read in 'begin'
  17800. while(true) {
  17801. token = this.getToken();
  17802. if (token === null || token === 'end') {
  17803. break;
  17804. }
  17805. if (token !== '/') {
  17806. continue;
  17807. }
  17808. var glyph = this.getToken();
  17809. length = this.readInt();
  17810. this.getToken(); // read in 'RD' or '-|'
  17811. data = stream.makeSubStream(stream.pos, length);
  17812. lenIV = program.properties.privateData['lenIV'];
  17813. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17814. // Skip past the required space and binary data.
  17815. stream.skip(length);
  17816. this.nextChar();
  17817. token = this.getToken(); // read in 'ND' or '|-'
  17818. if (token === 'noaccess') {
  17819. this.getToken(); // read in 'def'
  17820. }
  17821. charstrings.push({
  17822. glyph: glyph,
  17823. encoded: encoded
  17824. });
  17825. }
  17826. break;
  17827. case 'Subrs':
  17828. var num = this.readInt();
  17829. this.getToken(); // read in 'array'
  17830. while ((token = this.getToken()) === 'dup') {
  17831. var index = this.readInt();
  17832. length = this.readInt();
  17833. this.getToken(); // read in 'RD' or '-|'
  17834. data = stream.makeSubStream(stream.pos, length);
  17835. lenIV = program.properties.privateData['lenIV'];
  17836. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  17837. // Skip past the required space and binary data.
  17838. stream.skip(length);
  17839. this.nextChar();
  17840. token = this.getToken(); // read in 'NP' or '|'
  17841. if (token === 'noaccess') {
  17842. this.getToken(); // read in 'put'
  17843. }
  17844. subrs[index] = encoded;
  17845. }
  17846. break;
  17847. case 'BlueValues':
  17848. case 'OtherBlues':
  17849. case 'FamilyBlues':
  17850. case 'FamilyOtherBlues':
  17851. var blueArray = this.readNumberArray();
  17852. // *Blue* values may contain invalid data: disables reading of
  17853. // those values when hinting is disabled.
  17854. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  17855. HINTING_ENABLED) {
  17856. program.properties.privateData[token] = blueArray;
  17857. }
  17858. break;
  17859. case 'StemSnapH':
  17860. case 'StemSnapV':
  17861. program.properties.privateData[token] = this.readNumberArray();
  17862. break;
  17863. case 'StdHW':
  17864. case 'StdVW':
  17865. program.properties.privateData[token] =
  17866. this.readNumberArray()[0];
  17867. break;
  17868. case 'BlueShift':
  17869. case 'lenIV':
  17870. case 'BlueFuzz':
  17871. case 'BlueScale':
  17872. case 'LanguageGroup':
  17873. case 'ExpansionFactor':
  17874. program.properties.privateData[token] = this.readNumber();
  17875. break;
  17876. case 'ForceBold':
  17877. program.properties.privateData[token] = this.readBoolean();
  17878. break;
  17879. }
  17880. }
  17881. for (var i = 0; i < charstrings.length; i++) {
  17882. glyph = charstrings[i].glyph;
  17883. encoded = charstrings[i].encoded;
  17884. var charString = new Type1CharString();
  17885. var error = charString.convert(encoded, subrs);
  17886. var output = charString.output;
  17887. if (error) {
  17888. // It seems when FreeType encounters an error while evaluating a glyph
  17889. // that it completely ignores the glyph so we'll mimic that behaviour
  17890. // here and put an endchar to make the validator happy.
  17891. output = [14];
  17892. }
  17893. program.charstrings.push({
  17894. glyphName: glyph,
  17895. charstring: output,
  17896. width: charString.width,
  17897. lsb: charString.lsb,
  17898. seac: charString.seac
  17899. });
  17900. }
  17901. return program;
  17902. },
  17903. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  17904. var token;
  17905. while ((token = this.getToken()) !== null) {
  17906. if (token !== '/') {
  17907. continue;
  17908. }
  17909. token = this.getToken();
  17910. switch (token) {
  17911. case 'FontMatrix':
  17912. var matrix = this.readNumberArray();
  17913. properties.fontMatrix = matrix;
  17914. break;
  17915. case 'Encoding':
  17916. var encodingArg = this.getToken();
  17917. var encoding;
  17918. if (!/^\d+$/.test(encodingArg)) {
  17919. // encoding name is specified
  17920. encoding = Encodings[encodingArg];
  17921. } else {
  17922. encoding = [];
  17923. var size = parseInt(encodingArg, 10) | 0;
  17924. this.getToken(); // read in 'array'
  17925. for (var j = 0; j < size; j++) {
  17926. token = this.getToken();
  17927. // skipping till first dup or def (e.g. ignoring for statement)
  17928. while (token !== 'dup' && token !== 'def') {
  17929. token = this.getToken();
  17930. if (token === null) {
  17931. return; // invalid header
  17932. }
  17933. }
  17934. if (token === 'def') {
  17935. break; // read all array data
  17936. }
  17937. var index = this.readInt();
  17938. this.getToken(); // read in '/'
  17939. var glyph = this.getToken();
  17940. encoding[index] = glyph;
  17941. this.getToken(); // read the in 'put'
  17942. }
  17943. }
  17944. properties.builtInEncoding = encoding;
  17945. break;
  17946. case 'FontBBox':
  17947. var fontBBox = this.readNumberArray();
  17948. // adjusting ascent/descent
  17949. properties.ascent = fontBBox[3];
  17950. properties.descent = fontBBox[1];
  17951. properties.ascentScaled = true;
  17952. break;
  17953. }
  17954. }
  17955. }
  17956. };
  17957. return Type1Parser;
  17958. })();
  17959. /**
  17960. * The CFF class takes a Type1 file and wrap it into a
  17961. * 'Compact Font Format' which itself embed Type2 charstrings.
  17962. */
  17963. var CFFStandardStrings = [
  17964. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  17965. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  17966. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  17967. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  17968. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  17969. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  17970. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  17971. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  17972. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  17973. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  17974. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  17975. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  17976. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  17977. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  17978. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  17979. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  17980. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  17981. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  17982. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  17983. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  17984. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  17985. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  17986. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  17987. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  17988. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  17989. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  17990. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  17991. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  17992. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  17993. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  17994. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  17995. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  17996. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  17997. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  17998. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  17999. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18000. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18001. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18002. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18003. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18004. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18005. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18006. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18007. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18008. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18009. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18010. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18011. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18012. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18013. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18014. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18015. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18016. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18017. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18018. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18019. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18020. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18021. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18022. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18023. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18024. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18025. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18026. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18027. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18028. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18029. ];
  18030. // Type1Font is also a CIDFontType0.
  18031. var Type1Font = function Type1Font(name, file, properties) {
  18032. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18033. // Also, length1 and length2 might be off by 6 bytes as well.
  18034. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18035. var PFB_HEADER_SIZE = 6;
  18036. var headerBlockLength = properties.length1;
  18037. var eexecBlockLength = properties.length2;
  18038. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18039. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18040. if (pfbHeaderPresent) {
  18041. file.skip(PFB_HEADER_SIZE);
  18042. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18043. (pfbHeader[3] << 8) | pfbHeader[2];
  18044. }
  18045. // Get the data block containing glyphs and subrs informations
  18046. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18047. var headerBlockParser = new Type1Parser(headerBlock);
  18048. headerBlockParser.extractFontHeader(properties);
  18049. if (pfbHeaderPresent) {
  18050. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18051. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18052. (pfbHeader[3] << 8) | pfbHeader[2];
  18053. }
  18054. // Decrypt the data blocks and retrieve it's content
  18055. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18056. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18057. var data = eexecBlockParser.extractFontProgram();
  18058. for (var info in data.properties) {
  18059. properties[info] = data.properties[info];
  18060. }
  18061. var charstrings = data.charstrings;
  18062. var type2Charstrings = this.getType2Charstrings(charstrings);
  18063. var subrs = this.getType2Subrs(data.subrs);
  18064. this.charstrings = charstrings;
  18065. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18066. subrs, properties);
  18067. this.seacs = this.getSeacs(data.charstrings);
  18068. };
  18069. Type1Font.prototype = {
  18070. get numGlyphs() {
  18071. return this.charstrings.length + 1;
  18072. },
  18073. getCharset: function Type1Font_getCharset() {
  18074. var charset = ['.notdef'];
  18075. var charstrings = this.charstrings;
  18076. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18077. charset.push(charstrings[glyphId].glyphName);
  18078. }
  18079. return charset;
  18080. },
  18081. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18082. var charstrings = this.charstrings;
  18083. var glyphNames = ['.notdef'], glyphId;
  18084. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18085. glyphNames.push(charstrings[glyphId].glyphName);
  18086. }
  18087. var encoding = properties.builtInEncoding;
  18088. if (encoding) {
  18089. var builtInEncoding = {};
  18090. for (var charCode in encoding) {
  18091. glyphId = glyphNames.indexOf(encoding[charCode]);
  18092. if (glyphId >= 0) {
  18093. builtInEncoding[charCode] = glyphId;
  18094. }
  18095. }
  18096. }
  18097. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18098. },
  18099. getSeacs: function Type1Font_getSeacs(charstrings) {
  18100. var i, ii;
  18101. var seacMap = [];
  18102. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18103. var charstring = charstrings[i];
  18104. if (charstring.seac) {
  18105. // Offset by 1 for .notdef
  18106. seacMap[i + 1] = charstring.seac;
  18107. }
  18108. }
  18109. return seacMap;
  18110. },
  18111. getType2Charstrings: function Type1Font_getType2Charstrings(
  18112. type1Charstrings) {
  18113. var type2Charstrings = [];
  18114. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18115. type2Charstrings.push(type1Charstrings[i].charstring);
  18116. }
  18117. return type2Charstrings;
  18118. },
  18119. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18120. var bias = 0;
  18121. var count = type1Subrs.length;
  18122. if (count < 1133) {
  18123. bias = 107;
  18124. } else if (count < 33769) {
  18125. bias = 1131;
  18126. } else {
  18127. bias = 32768;
  18128. }
  18129. // Add a bunch of empty subrs to deal with the Type2 bias
  18130. var type2Subrs = [];
  18131. var i;
  18132. for (i = 0; i < bias; i++) {
  18133. type2Subrs.push([0x0B]);
  18134. }
  18135. for (i = 0; i < count; i++) {
  18136. type2Subrs.push(type1Subrs[i]);
  18137. }
  18138. return type2Subrs;
  18139. },
  18140. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18141. var cff = new CFF();
  18142. cff.header = new CFFHeader(1, 0, 4, 4);
  18143. cff.names = [name];
  18144. var topDict = new CFFTopDict();
  18145. // CFF strings IDs 0...390 are predefined names, so refering
  18146. // to entries in our own String INDEX starts at SID 391.
  18147. topDict.setByName('version', 391);
  18148. topDict.setByName('Notice', 392);
  18149. topDict.setByName('FullName', 393);
  18150. topDict.setByName('FamilyName', 394);
  18151. topDict.setByName('Weight', 395);
  18152. topDict.setByName('Encoding', null); // placeholder
  18153. topDict.setByName('FontMatrix', properties.fontMatrix);
  18154. topDict.setByName('FontBBox', properties.bbox);
  18155. topDict.setByName('charset', null); // placeholder
  18156. topDict.setByName('CharStrings', null); // placeholder
  18157. topDict.setByName('Private', null); // placeholder
  18158. cff.topDict = topDict;
  18159. var strings = new CFFStrings();
  18160. strings.add('Version 0.11'); // Version
  18161. strings.add('See original notice'); // Notice
  18162. strings.add(name); // FullName
  18163. strings.add(name); // FamilyName
  18164. strings.add('Medium'); // Weight
  18165. cff.strings = strings;
  18166. cff.globalSubrIndex = new CFFIndex();
  18167. var count = glyphs.length;
  18168. var charsetArray = [0];
  18169. var i, ii;
  18170. for (i = 0; i < count; i++) {
  18171. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18172. // TODO: Insert the string and correctly map it. Previously it was
  18173. // thought mapping names that aren't in the standard strings to .notdef
  18174. // was fine, however in issue818 when mapping them all to .notdef the
  18175. // adieresis glyph no longer worked.
  18176. if (index === -1) {
  18177. index = 0;
  18178. }
  18179. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18180. }
  18181. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18182. var charStringsIndex = new CFFIndex();
  18183. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18184. for (i = 0; i < count; i++) {
  18185. charStringsIndex.add(glyphs[i]);
  18186. }
  18187. cff.charStrings = charStringsIndex;
  18188. var privateDict = new CFFPrivateDict();
  18189. privateDict.setByName('Subrs', null); // placeholder
  18190. var fields = [
  18191. 'BlueValues',
  18192. 'OtherBlues',
  18193. 'FamilyBlues',
  18194. 'FamilyOtherBlues',
  18195. 'StemSnapH',
  18196. 'StemSnapV',
  18197. 'BlueShift',
  18198. 'BlueFuzz',
  18199. 'BlueScale',
  18200. 'LanguageGroup',
  18201. 'ExpansionFactor',
  18202. 'ForceBold',
  18203. 'StdHW',
  18204. 'StdVW'
  18205. ];
  18206. for (i = 0, ii = fields.length; i < ii; i++) {
  18207. var field = fields[i];
  18208. if (!properties.privateData.hasOwnProperty(field)) {
  18209. continue;
  18210. }
  18211. var value = properties.privateData[field];
  18212. if (isArray(value)) {
  18213. // All of the private dictionary array data in CFF must be stored as
  18214. // "delta-encoded" numbers.
  18215. for (var j = value.length - 1; j > 0; j--) {
  18216. value[j] -= value[j - 1]; // ... difference from previous value
  18217. }
  18218. }
  18219. privateDict.setByName(field, value);
  18220. }
  18221. cff.topDict.privateDict = privateDict;
  18222. var subrIndex = new CFFIndex();
  18223. for (i = 0, ii = subrs.length; i < ii; i++) {
  18224. subrIndex.add(subrs[i]);
  18225. }
  18226. privateDict.subrsIndex = subrIndex;
  18227. var compiler = new CFFCompiler(cff);
  18228. return compiler.compile();
  18229. }
  18230. };
  18231. var CFFFont = (function CFFFontClosure() {
  18232. function CFFFont(file, properties) {
  18233. this.properties = properties;
  18234. var parser = new CFFParser(file, properties);
  18235. this.cff = parser.parse();
  18236. var compiler = new CFFCompiler(this.cff);
  18237. this.seacs = this.cff.seacs;
  18238. try {
  18239. this.data = compiler.compile();
  18240. } catch (e) {
  18241. warn('Failed to compile font ' + properties.loadedName);
  18242. // There may have just been an issue with the compiler, set the data
  18243. // anyway and hope the font loaded.
  18244. this.data = file;
  18245. }
  18246. }
  18247. CFFFont.prototype = {
  18248. get numGlyphs() {
  18249. return this.cff.charStrings.count;
  18250. },
  18251. getCharset: function CFFFont_getCharset() {
  18252. return this.cff.charset.charset;
  18253. },
  18254. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18255. var cff = this.cff;
  18256. var properties = this.properties;
  18257. var charsets = cff.charset.charset;
  18258. var charCodeToGlyphId;
  18259. var glyphId;
  18260. if (properties.composite) {
  18261. charCodeToGlyphId = Object.create(null);
  18262. if (cff.isCIDFont) {
  18263. // If the font is actually a CID font then we should use the charset
  18264. // to map CIDs to GIDs.
  18265. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18266. var cid = charsets[glyphId];
  18267. var charCode = properties.cMap.charCodeOf(cid);
  18268. charCodeToGlyphId[charCode] = glyphId;
  18269. }
  18270. } else {
  18271. // If it is NOT actually a CID font then CIDs should be mapped
  18272. // directly to GIDs.
  18273. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18274. charCodeToGlyphId[glyphId] = glyphId;
  18275. }
  18276. }
  18277. return charCodeToGlyphId;
  18278. }
  18279. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18280. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18281. return charCodeToGlyphId;
  18282. }
  18283. };
  18284. return CFFFont;
  18285. })();
  18286. var CFFParser = (function CFFParserClosure() {
  18287. var CharstringValidationData = [
  18288. null,
  18289. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18290. null,
  18291. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18292. { id: 'vmoveto', min: 1, stackClearing: true },
  18293. { id: 'rlineto', min: 2, resetStack: true },
  18294. { id: 'hlineto', min: 1, resetStack: true },
  18295. { id: 'vlineto', min: 1, resetStack: true },
  18296. { id: 'rrcurveto', min: 6, resetStack: true },
  18297. null,
  18298. { id: 'callsubr', min: 1, undefStack: true },
  18299. { id: 'return', min: 0, undefStack: true },
  18300. null, // 12
  18301. null,
  18302. { id: 'endchar', min: 0, stackClearing: true },
  18303. null,
  18304. null,
  18305. null,
  18306. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18307. { id: 'hintmask', min: 0, stackClearing: true },
  18308. { id: 'cntrmask', min: 0, stackClearing: true },
  18309. { id: 'rmoveto', min: 2, stackClearing: true },
  18310. { id: 'hmoveto', min: 1, stackClearing: true },
  18311. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18312. { id: 'rcurveline', min: 8, resetStack: true },
  18313. { id: 'rlinecurve', min: 8, resetStack: true },
  18314. { id: 'vvcurveto', min: 4, resetStack: true },
  18315. { id: 'hhcurveto', min: 4, resetStack: true },
  18316. null, // shortint
  18317. { id: 'callgsubr', min: 1, undefStack: true },
  18318. { id: 'vhcurveto', min: 4, resetStack: true },
  18319. { id: 'hvcurveto', min: 4, resetStack: true }
  18320. ];
  18321. var CharstringValidationData12 = [
  18322. null,
  18323. null,
  18324. null,
  18325. { id: 'and', min: 2, stackDelta: -1 },
  18326. { id: 'or', min: 2, stackDelta: -1 },
  18327. { id: 'not', min: 1, stackDelta: 0 },
  18328. null,
  18329. null,
  18330. null,
  18331. { id: 'abs', min: 1, stackDelta: 0 },
  18332. { id: 'add', min: 2, stackDelta: -1,
  18333. stackFn: function stack_div(stack, index) {
  18334. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18335. }
  18336. },
  18337. { id: 'sub', min: 2, stackDelta: -1,
  18338. stackFn: function stack_div(stack, index) {
  18339. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18340. }
  18341. },
  18342. { id: 'div', min: 2, stackDelta: -1,
  18343. stackFn: function stack_div(stack, index) {
  18344. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18345. }
  18346. },
  18347. null,
  18348. { id: 'neg', min: 1, stackDelta: 0,
  18349. stackFn: function stack_div(stack, index) {
  18350. stack[index - 1] = -stack[index - 1];
  18351. }
  18352. },
  18353. { id: 'eq', min: 2, stackDelta: -1 },
  18354. null,
  18355. null,
  18356. { id: 'drop', min: 1, stackDelta: -1 },
  18357. null,
  18358. { id: 'put', min: 2, stackDelta: -2 },
  18359. { id: 'get', min: 1, stackDelta: 0 },
  18360. { id: 'ifelse', min: 4, stackDelta: -3 },
  18361. { id: 'random', min: 0, stackDelta: 1 },
  18362. { id: 'mul', min: 2, stackDelta: -1,
  18363. stackFn: function stack_div(stack, index) {
  18364. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18365. }
  18366. },
  18367. null,
  18368. { id: 'sqrt', min: 1, stackDelta: 0 },
  18369. { id: 'dup', min: 1, stackDelta: 1 },
  18370. { id: 'exch', min: 2, stackDelta: 0 },
  18371. { id: 'index', min: 2, stackDelta: 0 },
  18372. { id: 'roll', min: 3, stackDelta: -2 },
  18373. null,
  18374. null,
  18375. null,
  18376. { id: 'hflex', min: 7, resetStack: true },
  18377. { id: 'flex', min: 13, resetStack: true },
  18378. { id: 'hflex1', min: 9, resetStack: true },
  18379. { id: 'flex1', min: 11, resetStack: true }
  18380. ];
  18381. function CFFParser(file, properties) {
  18382. this.bytes = file.getBytes();
  18383. this.properties = properties;
  18384. }
  18385. CFFParser.prototype = {
  18386. parse: function CFFParser_parse() {
  18387. var properties = this.properties;
  18388. var cff = new CFF();
  18389. this.cff = cff;
  18390. // The first five sections must be in order, all the others are reached
  18391. // via offsets contained in one of the below.
  18392. var header = this.parseHeader();
  18393. var nameIndex = this.parseIndex(header.endPos);
  18394. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18395. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18396. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18397. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18398. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18399. cff.header = header.obj;
  18400. cff.names = this.parseNameIndex(nameIndex.obj);
  18401. cff.strings = this.parseStringIndex(stringIndex.obj);
  18402. cff.topDict = topDict;
  18403. cff.globalSubrIndex = globalSubrIndex.obj;
  18404. this.parsePrivateDict(cff.topDict);
  18405. cff.isCIDFont = topDict.hasName('ROS');
  18406. var charStringOffset = topDict.getByName('CharStrings');
  18407. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18408. cff.charStrings = charStringsAndSeacs.charStrings;
  18409. cff.seacs = charStringsAndSeacs.seacs;
  18410. cff.widths = charStringsAndSeacs.widths;
  18411. var fontMatrix = topDict.getByName('FontMatrix');
  18412. if (fontMatrix) {
  18413. properties.fontMatrix = fontMatrix;
  18414. }
  18415. var fontBBox = topDict.getByName('FontBBox');
  18416. if (fontBBox) {
  18417. // adjusting ascent/descent
  18418. properties.ascent = fontBBox[3];
  18419. properties.descent = fontBBox[1];
  18420. properties.ascentScaled = true;
  18421. }
  18422. var charset, encoding;
  18423. if (cff.isCIDFont) {
  18424. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18425. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18426. var dictRaw = fdArrayIndex.get(i);
  18427. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18428. cff.strings);
  18429. this.parsePrivateDict(fontDict);
  18430. cff.fdArray.push(fontDict);
  18431. }
  18432. // cid fonts don't have an encoding
  18433. encoding = null;
  18434. charset = this.parseCharsets(topDict.getByName('charset'),
  18435. cff.charStrings.count, cff.strings, true);
  18436. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18437. cff.charStrings.count);
  18438. } else {
  18439. charset = this.parseCharsets(topDict.getByName('charset'),
  18440. cff.charStrings.count, cff.strings, false);
  18441. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18442. properties,
  18443. cff.strings, charset.charset);
  18444. }
  18445. cff.charset = charset;
  18446. cff.encoding = encoding;
  18447. return cff;
  18448. },
  18449. parseHeader: function CFFParser_parseHeader() {
  18450. var bytes = this.bytes;
  18451. var bytesLength = bytes.length;
  18452. var offset = 0;
  18453. // Prevent an infinite loop, by checking that the offset is within the
  18454. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18455. while (offset < bytesLength && bytes[offset] !== 1) {
  18456. ++offset;
  18457. }
  18458. if (offset >= bytesLength) {
  18459. error('Invalid CFF header');
  18460. } else if (offset !== 0) {
  18461. info('cff data is shifted');
  18462. bytes = bytes.subarray(offset);
  18463. this.bytes = bytes;
  18464. }
  18465. var major = bytes[0];
  18466. var minor = bytes[1];
  18467. var hdrSize = bytes[2];
  18468. var offSize = bytes[3];
  18469. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18470. return { obj: header, endPos: hdrSize };
  18471. },
  18472. parseDict: function CFFParser_parseDict(dict) {
  18473. var pos = 0;
  18474. function parseOperand() {
  18475. var value = dict[pos++];
  18476. if (value === 30) {
  18477. return parseFloatOperand(pos);
  18478. } else if (value === 28) {
  18479. value = dict[pos++];
  18480. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18481. return value;
  18482. } else if (value === 29) {
  18483. value = dict[pos++];
  18484. value = (value << 8) | dict[pos++];
  18485. value = (value << 8) | dict[pos++];
  18486. value = (value << 8) | dict[pos++];
  18487. return value;
  18488. } else if (value >= 32 && value <= 246) {
  18489. return value - 139;
  18490. } else if (value >= 247 && value <= 250) {
  18491. return ((value - 247) * 256) + dict[pos++] + 108;
  18492. } else if (value >= 251 && value <= 254) {
  18493. return -((value - 251) * 256) - dict[pos++] - 108;
  18494. } else {
  18495. error('255 is not a valid DICT command');
  18496. }
  18497. return -1;
  18498. }
  18499. function parseFloatOperand() {
  18500. var str = '';
  18501. var eof = 15;
  18502. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18503. '9', '.', 'E', 'E-', null, '-'];
  18504. var length = dict.length;
  18505. while (pos < length) {
  18506. var b = dict[pos++];
  18507. var b1 = b >> 4;
  18508. var b2 = b & 15;
  18509. if (b1 === eof) {
  18510. break;
  18511. }
  18512. str += lookup[b1];
  18513. if (b2 === eof) {
  18514. break;
  18515. }
  18516. str += lookup[b2];
  18517. }
  18518. return parseFloat(str);
  18519. }
  18520. var operands = [];
  18521. var entries = [];
  18522. pos = 0;
  18523. var end = dict.length;
  18524. while (pos < end) {
  18525. var b = dict[pos];
  18526. if (b <= 21) {
  18527. if (b === 12) {
  18528. b = (b << 8) | dict[++pos];
  18529. }
  18530. entries.push([b, operands]);
  18531. operands = [];
  18532. ++pos;
  18533. } else {
  18534. operands.push(parseOperand());
  18535. }
  18536. }
  18537. return entries;
  18538. },
  18539. parseIndex: function CFFParser_parseIndex(pos) {
  18540. var cffIndex = new CFFIndex();
  18541. var bytes = this.bytes;
  18542. var count = (bytes[pos++] << 8) | bytes[pos++];
  18543. var offsets = [];
  18544. var end = pos;
  18545. var i, ii;
  18546. if (count !== 0) {
  18547. var offsetSize = bytes[pos++];
  18548. // add 1 for offset to determine size of last object
  18549. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18550. for (i = 0, ii = count + 1; i < ii; ++i) {
  18551. var offset = 0;
  18552. for (var j = 0; j < offsetSize; ++j) {
  18553. offset <<= 8;
  18554. offset += bytes[pos++];
  18555. }
  18556. offsets.push(startPos + offset);
  18557. }
  18558. end = offsets[count];
  18559. }
  18560. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18561. var offsetStart = offsets[i];
  18562. var offsetEnd = offsets[i + 1];
  18563. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18564. }
  18565. return {obj: cffIndex, endPos: end};
  18566. },
  18567. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18568. var names = [];
  18569. for (var i = 0, ii = index.count; i < ii; ++i) {
  18570. var name = index.get(i);
  18571. // OTS doesn't allow names to be over 127 characters.
  18572. var length = Math.min(name.length, 127);
  18573. var data = [];
  18574. // OTS also only permits certain characters in the name.
  18575. for (var j = 0; j < length; ++j) {
  18576. var c = name[j];
  18577. if (j === 0 && c === 0) {
  18578. data[j] = c;
  18579. continue;
  18580. }
  18581. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18582. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18583. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18584. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18585. data[j] = 95;
  18586. continue;
  18587. }
  18588. data[j] = c;
  18589. }
  18590. names.push(bytesToString(data));
  18591. }
  18592. return names;
  18593. },
  18594. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18595. var strings = new CFFStrings();
  18596. for (var i = 0, ii = index.count; i < ii; ++i) {
  18597. var data = index.get(i);
  18598. strings.add(bytesToString(data));
  18599. }
  18600. return strings;
  18601. },
  18602. createDict: function CFFParser_createDict(Type, dict, strings) {
  18603. var cffDict = new Type(strings);
  18604. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18605. var pair = dict[i];
  18606. var key = pair[0];
  18607. var value = pair[1];
  18608. cffDict.setByKey(key, value);
  18609. }
  18610. return cffDict;
  18611. },
  18612. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18613. var charStrings = this.parseIndex(charStringOffset).obj;
  18614. var seacs = [];
  18615. var widths = [];
  18616. var count = charStrings.count;
  18617. for (var i = 0; i < count; i++) {
  18618. var charstring = charStrings.get(i);
  18619. var stackSize = 0;
  18620. var stack = [];
  18621. var undefStack = true;
  18622. var hints = 0;
  18623. var valid = true;
  18624. var data = charstring;
  18625. var length = data.length;
  18626. var firstStackClearing = true;
  18627. for (var j = 0; j < length;) {
  18628. var value = data[j++];
  18629. var validationCommand = null;
  18630. if (value === 12) {
  18631. var q = data[j++];
  18632. if (q === 0) {
  18633. // The CFF specification state that the 'dotsection' command
  18634. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18635. // charstrings processors should support them. Unfortunately
  18636. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18637. // is replaced by a useless (0, hmoveto).
  18638. data[j - 2] = 139;
  18639. data[j - 1] = 22;
  18640. stackSize = 0;
  18641. } else {
  18642. validationCommand = CharstringValidationData12[q];
  18643. }
  18644. } else if (value === 28) { // number (16 bit)
  18645. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  18646. j += 2;
  18647. stackSize++;
  18648. } else if (value === 14) {
  18649. if (stackSize >= 4) {
  18650. stackSize -= 4;
  18651. if (SEAC_ANALYSIS_ENABLED) {
  18652. seacs[i] = stack.slice(stackSize, stackSize + 4);
  18653. valid = false;
  18654. }
  18655. }
  18656. validationCommand = CharstringValidationData[value];
  18657. } else if (value >= 32 && value <= 246) { // number
  18658. stack[stackSize] = value - 139;
  18659. stackSize++;
  18660. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  18661. stack[stackSize] = (value < 251 ?
  18662. ((value - 247) << 8) + data[j] + 108 :
  18663. -((value - 251) << 8) - data[j] - 108);
  18664. j++;
  18665. stackSize++;
  18666. } else if (value === 255) { // number (32 bit)
  18667. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  18668. (data[j + 2] << 8) | data[j + 3]) / 65536;
  18669. j += 4;
  18670. stackSize++;
  18671. } else if (value === 19 || value === 20) {
  18672. hints += stackSize >> 1;
  18673. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  18674. stackSize %= 2;
  18675. validationCommand = CharstringValidationData[value];
  18676. } else {
  18677. validationCommand = CharstringValidationData[value];
  18678. }
  18679. if (validationCommand) {
  18680. if (validationCommand.stem) {
  18681. hints += stackSize >> 1;
  18682. }
  18683. if ('min' in validationCommand) {
  18684. if (!undefStack && stackSize < validationCommand.min) {
  18685. warn('Not enough parameters for ' + validationCommand.id +
  18686. '; actual: ' + stackSize +
  18687. ', expected: ' + validationCommand.min);
  18688. valid = false;
  18689. break;
  18690. }
  18691. }
  18692. if (firstStackClearing && validationCommand.stackClearing) {
  18693. firstStackClearing = false;
  18694. // the optional character width can be found before the first
  18695. // stack-clearing command arguments
  18696. stackSize -= validationCommand.min;
  18697. if (stackSize >= 2 && validationCommand.stem) {
  18698. // there are even amount of arguments for stem commands
  18699. stackSize %= 2;
  18700. } else if (stackSize > 1) {
  18701. warn('Found too many parameters for stack-clearing command');
  18702. }
  18703. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  18704. widths[i] = stack[stackSize - 1];
  18705. }
  18706. }
  18707. if ('stackDelta' in validationCommand) {
  18708. if ('stackFn' in validationCommand) {
  18709. validationCommand.stackFn(stack, stackSize);
  18710. }
  18711. stackSize += validationCommand.stackDelta;
  18712. } else if (validationCommand.stackClearing) {
  18713. stackSize = 0;
  18714. } else if (validationCommand.resetStack) {
  18715. stackSize = 0;
  18716. undefStack = false;
  18717. } else if (validationCommand.undefStack) {
  18718. stackSize = 0;
  18719. undefStack = true;
  18720. firstStackClearing = false;
  18721. }
  18722. }
  18723. }
  18724. if (!valid) {
  18725. // resetting invalid charstring to single 'endchar'
  18726. charStrings.set(i, new Uint8Array([14]));
  18727. }
  18728. }
  18729. return { charStrings: charStrings, seacs: seacs, widths: widths };
  18730. },
  18731. emptyPrivateDictionary:
  18732. function CFFParser_emptyPrivateDictionary(parentDict) {
  18733. var privateDict = this.createDict(CFFPrivateDict, [],
  18734. parentDict.strings);
  18735. parentDict.setByKey(18, [0, 0]);
  18736. parentDict.privateDict = privateDict;
  18737. },
  18738. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  18739. // no private dict, do nothing
  18740. if (!parentDict.hasName('Private')) {
  18741. this.emptyPrivateDictionary(parentDict);
  18742. return;
  18743. }
  18744. var privateOffset = parentDict.getByName('Private');
  18745. // make sure the params are formatted correctly
  18746. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  18747. parentDict.removeByName('Private');
  18748. return;
  18749. }
  18750. var size = privateOffset[0];
  18751. var offset = privateOffset[1];
  18752. // remove empty dicts or ones that refer to invalid location
  18753. if (size === 0 || offset >= this.bytes.length) {
  18754. this.emptyPrivateDictionary(parentDict);
  18755. return;
  18756. }
  18757. var privateDictEnd = offset + size;
  18758. var dictData = this.bytes.subarray(offset, privateDictEnd);
  18759. var dict = this.parseDict(dictData);
  18760. var privateDict = this.createDict(CFFPrivateDict, dict,
  18761. parentDict.strings);
  18762. parentDict.privateDict = privateDict;
  18763. // Parse the Subrs index also since it's relative to the private dict.
  18764. if (!privateDict.getByName('Subrs')) {
  18765. return;
  18766. }
  18767. var subrsOffset = privateDict.getByName('Subrs');
  18768. var relativeOffset = offset + subrsOffset;
  18769. // Validate the offset.
  18770. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  18771. this.emptyPrivateDictionary(parentDict);
  18772. return;
  18773. }
  18774. var subrsIndex = this.parseIndex(relativeOffset);
  18775. privateDict.subrsIndex = subrsIndex.obj;
  18776. },
  18777. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  18778. if (pos === 0) {
  18779. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  18780. ISOAdobeCharset);
  18781. } else if (pos === 1) {
  18782. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  18783. ExpertCharset);
  18784. } else if (pos === 2) {
  18785. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  18786. ExpertSubsetCharset);
  18787. }
  18788. var bytes = this.bytes;
  18789. var start = pos;
  18790. var format = bytes[pos++];
  18791. var charset = ['.notdef'];
  18792. var id, count, i;
  18793. // subtract 1 for the .notdef glyph
  18794. length -= 1;
  18795. switch (format) {
  18796. case 0:
  18797. for (i = 0; i < length; i++) {
  18798. id = (bytes[pos++] << 8) | bytes[pos++];
  18799. charset.push(cid ? id : strings.get(id));
  18800. }
  18801. break;
  18802. case 1:
  18803. while (charset.length <= length) {
  18804. id = (bytes[pos++] << 8) | bytes[pos++];
  18805. count = bytes[pos++];
  18806. for (i = 0; i <= count; i++) {
  18807. charset.push(cid ? id++ : strings.get(id++));
  18808. }
  18809. }
  18810. break;
  18811. case 2:
  18812. while (charset.length <= length) {
  18813. id = (bytes[pos++] << 8) | bytes[pos++];
  18814. count = (bytes[pos++] << 8) | bytes[pos++];
  18815. for (i = 0; i <= count; i++) {
  18816. charset.push(cid ? id++ : strings.get(id++));
  18817. }
  18818. }
  18819. break;
  18820. default:
  18821. error('Unknown charset format');
  18822. }
  18823. // Raw won't be needed if we actually compile the charset.
  18824. var end = pos;
  18825. var raw = bytes.subarray(start, end);
  18826. return new CFFCharset(false, format, charset, raw);
  18827. },
  18828. parseEncoding: function CFFParser_parseEncoding(pos,
  18829. properties,
  18830. strings,
  18831. charset) {
  18832. var encoding = {};
  18833. var bytes = this.bytes;
  18834. var predefined = false;
  18835. var hasSupplement = false;
  18836. var format, i, ii;
  18837. var raw = null;
  18838. function readSupplement() {
  18839. var supplementsCount = bytes[pos++];
  18840. for (i = 0; i < supplementsCount; i++) {
  18841. var code = bytes[pos++];
  18842. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  18843. encoding[code] = charset.indexOf(strings.get(sid));
  18844. }
  18845. }
  18846. if (pos === 0 || pos === 1) {
  18847. predefined = true;
  18848. format = pos;
  18849. var baseEncoding = pos ? Encodings.ExpertEncoding :
  18850. Encodings.StandardEncoding;
  18851. for (i = 0, ii = charset.length; i < ii; i++) {
  18852. var index = baseEncoding.indexOf(charset[i]);
  18853. if (index !== -1) {
  18854. encoding[index] = i;
  18855. }
  18856. }
  18857. } else {
  18858. var dataStart = pos;
  18859. format = bytes[pos++];
  18860. switch (format & 0x7f) {
  18861. case 0:
  18862. var glyphsCount = bytes[pos++];
  18863. for (i = 1; i <= glyphsCount; i++) {
  18864. encoding[bytes[pos++]] = i;
  18865. }
  18866. break;
  18867. case 1:
  18868. var rangesCount = bytes[pos++];
  18869. var gid = 1;
  18870. for (i = 0; i < rangesCount; i++) {
  18871. var start = bytes[pos++];
  18872. var left = bytes[pos++];
  18873. for (var j = start; j <= start + left; j++) {
  18874. encoding[j] = gid++;
  18875. }
  18876. }
  18877. break;
  18878. default:
  18879. error('Unknow encoding format: ' + format + ' in CFF');
  18880. break;
  18881. }
  18882. var dataEnd = pos;
  18883. if (format & 0x80) {
  18884. // The font sanitizer does not support CFF encoding with a
  18885. // supplement, since the encoding is not really used to map
  18886. // between gid to glyph, let's overwrite what is declared in
  18887. // the top dictionary to let the sanitizer think the font use
  18888. // StandardEncoding, that's a lie but that's ok.
  18889. bytes[dataStart] &= 0x7f;
  18890. readSupplement();
  18891. hasSupplement = true;
  18892. }
  18893. raw = bytes.subarray(dataStart, dataEnd);
  18894. }
  18895. format = format & 0x7f;
  18896. return new CFFEncoding(predefined, format, encoding, raw);
  18897. },
  18898. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  18899. var start = pos;
  18900. var bytes = this.bytes;
  18901. var format = bytes[pos++];
  18902. var fdSelect = [];
  18903. var i;
  18904. switch (format) {
  18905. case 0:
  18906. for (i = 0; i < length; ++i) {
  18907. var id = bytes[pos++];
  18908. fdSelect.push(id);
  18909. }
  18910. break;
  18911. case 3:
  18912. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  18913. for (i = 0; i < rangesCount; ++i) {
  18914. var first = (bytes[pos++] << 8) | bytes[pos++];
  18915. var fdIndex = bytes[pos++];
  18916. var next = (bytes[pos] << 8) | bytes[pos + 1];
  18917. for (var j = first; j < next; ++j) {
  18918. fdSelect.push(fdIndex);
  18919. }
  18920. }
  18921. // Advance past the sentinel(next).
  18922. pos += 2;
  18923. break;
  18924. default:
  18925. error('Unknown fdselect format ' + format);
  18926. break;
  18927. }
  18928. var end = pos;
  18929. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  18930. }
  18931. };
  18932. return CFFParser;
  18933. })();
  18934. // Compact Font Format
  18935. var CFF = (function CFFClosure() {
  18936. function CFF() {
  18937. this.header = null;
  18938. this.names = [];
  18939. this.topDict = null;
  18940. this.strings = new CFFStrings();
  18941. this.globalSubrIndex = null;
  18942. // The following could really be per font, but since we only have one font
  18943. // store them here.
  18944. this.encoding = null;
  18945. this.charset = null;
  18946. this.charStrings = null;
  18947. this.fdArray = [];
  18948. this.fdSelect = null;
  18949. this.isCIDFont = false;
  18950. }
  18951. return CFF;
  18952. })();
  18953. var CFFHeader = (function CFFHeaderClosure() {
  18954. function CFFHeader(major, minor, hdrSize, offSize) {
  18955. this.major = major;
  18956. this.minor = minor;
  18957. this.hdrSize = hdrSize;
  18958. this.offSize = offSize;
  18959. }
  18960. return CFFHeader;
  18961. })();
  18962. var CFFStrings = (function CFFStringsClosure() {
  18963. function CFFStrings() {
  18964. this.strings = [];
  18965. }
  18966. CFFStrings.prototype = {
  18967. get: function CFFStrings_get(index) {
  18968. if (index >= 0 && index <= 390) {
  18969. return CFFStandardStrings[index];
  18970. }
  18971. if (index - 391 <= this.strings.length) {
  18972. return this.strings[index - 391];
  18973. }
  18974. return CFFStandardStrings[0];
  18975. },
  18976. add: function CFFStrings_add(value) {
  18977. this.strings.push(value);
  18978. },
  18979. get count() {
  18980. return this.strings.length;
  18981. }
  18982. };
  18983. return CFFStrings;
  18984. })();
  18985. var CFFIndex = (function CFFIndexClosure() {
  18986. function CFFIndex() {
  18987. this.objects = [];
  18988. this.length = 0;
  18989. }
  18990. CFFIndex.prototype = {
  18991. add: function CFFIndex_add(data) {
  18992. this.length += data.length;
  18993. this.objects.push(data);
  18994. },
  18995. set: function CFFIndex_set(index, data) {
  18996. this.length += data.length - this.objects[index].length;
  18997. this.objects[index] = data;
  18998. },
  18999. get: function CFFIndex_get(index) {
  19000. return this.objects[index];
  19001. },
  19002. get count() {
  19003. return this.objects.length;
  19004. }
  19005. };
  19006. return CFFIndex;
  19007. })();
  19008. var CFFDict = (function CFFDictClosure() {
  19009. function CFFDict(tables, strings) {
  19010. this.keyToNameMap = tables.keyToNameMap;
  19011. this.nameToKeyMap = tables.nameToKeyMap;
  19012. this.defaults = tables.defaults;
  19013. this.types = tables.types;
  19014. this.opcodes = tables.opcodes;
  19015. this.order = tables.order;
  19016. this.strings = strings;
  19017. this.values = {};
  19018. }
  19019. CFFDict.prototype = {
  19020. // value should always be an array
  19021. setByKey: function CFFDict_setByKey(key, value) {
  19022. if (!(key in this.keyToNameMap)) {
  19023. return false;
  19024. }
  19025. // ignore empty values
  19026. if (value.length === 0) {
  19027. return true;
  19028. }
  19029. var type = this.types[key];
  19030. // remove the array wrapping these types of values
  19031. if (type === 'num' || type === 'sid' || type === 'offset') {
  19032. value = value[0];
  19033. }
  19034. this.values[key] = value;
  19035. return true;
  19036. },
  19037. setByName: function CFFDict_setByName(name, value) {
  19038. if (!(name in this.nameToKeyMap)) {
  19039. error('Invalid dictionary name "' + name + '"');
  19040. }
  19041. this.values[this.nameToKeyMap[name]] = value;
  19042. },
  19043. hasName: function CFFDict_hasName(name) {
  19044. return this.nameToKeyMap[name] in this.values;
  19045. },
  19046. getByName: function CFFDict_getByName(name) {
  19047. if (!(name in this.nameToKeyMap)) {
  19048. error('Invalid dictionary name "' + name + '"');
  19049. }
  19050. var key = this.nameToKeyMap[name];
  19051. if (!(key in this.values)) {
  19052. return this.defaults[key];
  19053. }
  19054. return this.values[key];
  19055. },
  19056. removeByName: function CFFDict_removeByName(name) {
  19057. delete this.values[this.nameToKeyMap[name]];
  19058. }
  19059. };
  19060. CFFDict.createTables = function CFFDict_createTables(layout) {
  19061. var tables = {
  19062. keyToNameMap: {},
  19063. nameToKeyMap: {},
  19064. defaults: {},
  19065. types: {},
  19066. opcodes: {},
  19067. order: []
  19068. };
  19069. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19070. var entry = layout[i];
  19071. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19072. tables.keyToNameMap[key] = entry[1];
  19073. tables.nameToKeyMap[entry[1]] = key;
  19074. tables.types[key] = entry[2];
  19075. tables.defaults[key] = entry[3];
  19076. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19077. tables.order.push(key);
  19078. }
  19079. return tables;
  19080. };
  19081. return CFFDict;
  19082. })();
  19083. var CFFTopDict = (function CFFTopDictClosure() {
  19084. var layout = [
  19085. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19086. [[12, 20], 'SyntheticBase', 'num', null],
  19087. [0, 'version', 'sid', null],
  19088. [1, 'Notice', 'sid', null],
  19089. [[12, 0], 'Copyright', 'sid', null],
  19090. [2, 'FullName', 'sid', null],
  19091. [3, 'FamilyName', 'sid', null],
  19092. [4, 'Weight', 'sid', null],
  19093. [[12, 1], 'isFixedPitch', 'num', 0],
  19094. [[12, 2], 'ItalicAngle', 'num', 0],
  19095. [[12, 3], 'UnderlinePosition', 'num', -100],
  19096. [[12, 4], 'UnderlineThickness', 'num', 50],
  19097. [[12, 5], 'PaintType', 'num', 0],
  19098. [[12, 6], 'CharstringType', 'num', 2],
  19099. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19100. [0.001, 0, 0, 0.001, 0, 0]],
  19101. [13, 'UniqueID', 'num', null],
  19102. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19103. [[12, 8], 'StrokeWidth', 'num', 0],
  19104. [14, 'XUID', 'array', null],
  19105. [15, 'charset', 'offset', 0],
  19106. [16, 'Encoding', 'offset', 0],
  19107. [17, 'CharStrings', 'offset', 0],
  19108. [18, 'Private', ['offset', 'offset'], null],
  19109. [[12, 21], 'PostScript', 'sid', null],
  19110. [[12, 22], 'BaseFontName', 'sid', null],
  19111. [[12, 23], 'BaseFontBlend', 'delta', null],
  19112. [[12, 31], 'CIDFontVersion', 'num', 0],
  19113. [[12, 32], 'CIDFontRevision', 'num', 0],
  19114. [[12, 33], 'CIDFontType', 'num', 0],
  19115. [[12, 34], 'CIDCount', 'num', 8720],
  19116. [[12, 35], 'UIDBase', 'num', null],
  19117. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19118. // before FDArray.
  19119. [[12, 37], 'FDSelect', 'offset', null],
  19120. [[12, 36], 'FDArray', 'offset', null],
  19121. [[12, 38], 'FontName', 'sid', null]
  19122. ];
  19123. var tables = null;
  19124. function CFFTopDict(strings) {
  19125. if (tables === null) {
  19126. tables = CFFDict.createTables(layout);
  19127. }
  19128. CFFDict.call(this, tables, strings);
  19129. this.privateDict = null;
  19130. }
  19131. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19132. return CFFTopDict;
  19133. })();
  19134. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19135. var layout = [
  19136. [6, 'BlueValues', 'delta', null],
  19137. [7, 'OtherBlues', 'delta', null],
  19138. [8, 'FamilyBlues', 'delta', null],
  19139. [9, 'FamilyOtherBlues', 'delta', null],
  19140. [[12, 9], 'BlueScale', 'num', 0.039625],
  19141. [[12, 10], 'BlueShift', 'num', 7],
  19142. [[12, 11], 'BlueFuzz', 'num', 1],
  19143. [10, 'StdHW', 'num', null],
  19144. [11, 'StdVW', 'num', null],
  19145. [[12, 12], 'StemSnapH', 'delta', null],
  19146. [[12, 13], 'StemSnapV', 'delta', null],
  19147. [[12, 14], 'ForceBold', 'num', 0],
  19148. [[12, 17], 'LanguageGroup', 'num', 0],
  19149. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19150. [[12, 19], 'initialRandomSeed', 'num', 0],
  19151. [20, 'defaultWidthX', 'num', 0],
  19152. [21, 'nominalWidthX', 'num', 0],
  19153. [19, 'Subrs', 'offset', null]
  19154. ];
  19155. var tables = null;
  19156. function CFFPrivateDict(strings) {
  19157. if (tables === null) {
  19158. tables = CFFDict.createTables(layout);
  19159. }
  19160. CFFDict.call(this, tables, strings);
  19161. this.subrsIndex = null;
  19162. }
  19163. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19164. return CFFPrivateDict;
  19165. })();
  19166. var CFFCharsetPredefinedTypes = {
  19167. ISO_ADOBE: 0,
  19168. EXPERT: 1,
  19169. EXPERT_SUBSET: 2
  19170. };
  19171. var CFFCharset = (function CFFCharsetClosure() {
  19172. function CFFCharset(predefined, format, charset, raw) {
  19173. this.predefined = predefined;
  19174. this.format = format;
  19175. this.charset = charset;
  19176. this.raw = raw;
  19177. }
  19178. return CFFCharset;
  19179. })();
  19180. var CFFEncoding = (function CFFEncodingClosure() {
  19181. function CFFEncoding(predefined, format, encoding, raw) {
  19182. this.predefined = predefined;
  19183. this.format = format;
  19184. this.encoding = encoding;
  19185. this.raw = raw;
  19186. }
  19187. return CFFEncoding;
  19188. })();
  19189. var CFFFDSelect = (function CFFFDSelectClosure() {
  19190. function CFFFDSelect(fdSelect, raw) {
  19191. this.fdSelect = fdSelect;
  19192. this.raw = raw;
  19193. }
  19194. return CFFFDSelect;
  19195. })();
  19196. // Helper class to keep track of where an offset is within the data and helps
  19197. // filling in that offset once it's known.
  19198. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19199. function CFFOffsetTracker() {
  19200. this.offsets = {};
  19201. }
  19202. CFFOffsetTracker.prototype = {
  19203. isTracking: function CFFOffsetTracker_isTracking(key) {
  19204. return key in this.offsets;
  19205. },
  19206. track: function CFFOffsetTracker_track(key, location) {
  19207. if (key in this.offsets) {
  19208. error('Already tracking location of ' + key);
  19209. }
  19210. this.offsets[key] = location;
  19211. },
  19212. offset: function CFFOffsetTracker_offset(value) {
  19213. for (var key in this.offsets) {
  19214. this.offsets[key] += value;
  19215. }
  19216. },
  19217. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19218. values,
  19219. output) {
  19220. if (!(key in this.offsets)) {
  19221. error('Not tracking location of ' + key);
  19222. }
  19223. var data = output.data;
  19224. var dataOffset = this.offsets[key];
  19225. var size = 5;
  19226. for (var i = 0, ii = values.length; i < ii; ++i) {
  19227. var offset0 = i * size + dataOffset;
  19228. var offset1 = offset0 + 1;
  19229. var offset2 = offset0 + 2;
  19230. var offset3 = offset0 + 3;
  19231. var offset4 = offset0 + 4;
  19232. // It's easy to screw up offsets so perform this sanity check.
  19233. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19234. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19235. error('writing to an offset that is not empty');
  19236. }
  19237. var value = values[i];
  19238. data[offset0] = 0x1d;
  19239. data[offset1] = (value >> 24) & 0xFF;
  19240. data[offset2] = (value >> 16) & 0xFF;
  19241. data[offset3] = (value >> 8) & 0xFF;
  19242. data[offset4] = value & 0xFF;
  19243. }
  19244. }
  19245. };
  19246. return CFFOffsetTracker;
  19247. })();
  19248. // Takes a CFF and converts it to the binary representation.
  19249. var CFFCompiler = (function CFFCompilerClosure() {
  19250. function CFFCompiler(cff) {
  19251. this.cff = cff;
  19252. }
  19253. CFFCompiler.prototype = {
  19254. compile: function CFFCompiler_compile() {
  19255. var cff = this.cff;
  19256. var output = {
  19257. data: [],
  19258. length: 0,
  19259. add: function CFFCompiler_add(data) {
  19260. this.data = this.data.concat(data);
  19261. this.length = this.data.length;
  19262. }
  19263. };
  19264. // Compile the five entries that must be in order.
  19265. var header = this.compileHeader(cff.header);
  19266. output.add(header);
  19267. var nameIndex = this.compileNameIndex(cff.names);
  19268. output.add(nameIndex);
  19269. if (cff.isCIDFont) {
  19270. // The spec is unclear on how font matrices should relate to each other
  19271. // when there is one in the main top dict and the sub top dicts.
  19272. // Windows handles this differently than linux and osx so we have to
  19273. // normalize to work on all.
  19274. // Rules based off of some mailing list discussions:
  19275. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19276. // - If no main font matrix and there is a subfont matrix, use the
  19277. // subfont matrix.
  19278. // - If both have matrices, concat together.
  19279. // - If neither have matrices, use default.
  19280. // To make this work on all platforms we move the top matrix into each
  19281. // sub top dict and concat if necessary.
  19282. if (cff.topDict.hasName('FontMatrix')) {
  19283. var base = cff.topDict.getByName('FontMatrix');
  19284. cff.topDict.removeByName('FontMatrix');
  19285. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19286. var subDict = cff.fdArray[i];
  19287. var matrix = base.slice(0);
  19288. if (subDict.hasName('FontMatrix')) {
  19289. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19290. }
  19291. subDict.setByName('FontMatrix', matrix);
  19292. }
  19293. }
  19294. }
  19295. var compiled = this.compileTopDicts([cff.topDict],
  19296. output.length,
  19297. cff.isCIDFont);
  19298. output.add(compiled.output);
  19299. var topDictTracker = compiled.trackers[0];
  19300. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19301. output.add(stringIndex);
  19302. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19303. output.add(globalSubrIndex);
  19304. // Now start on the other entries that have no specfic order.
  19305. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19306. if (cff.encoding.predefined) {
  19307. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19308. output);
  19309. } else {
  19310. var encoding = this.compileEncoding(cff.encoding);
  19311. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19312. output.add(encoding);
  19313. }
  19314. }
  19315. if (cff.charset && cff.topDict.hasName('charset')) {
  19316. if (cff.charset.predefined) {
  19317. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19318. output);
  19319. } else {
  19320. var charset = this.compileCharset(cff.charset);
  19321. topDictTracker.setEntryLocation('charset', [output.length], output);
  19322. output.add(charset);
  19323. }
  19324. }
  19325. var charStrings = this.compileCharStrings(cff.charStrings);
  19326. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19327. output.add(charStrings);
  19328. if (cff.isCIDFont) {
  19329. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19330. // and linux don't seem to care.
  19331. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19332. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19333. output.add(fdSelect);
  19334. // It is unclear if the sub font dictionary can have CID related
  19335. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19336. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19337. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19338. output.add(compiled.output);
  19339. var fontDictTrackers = compiled.trackers;
  19340. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19341. }
  19342. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19343. // If the font data ends with INDEX whose object data is zero-length,
  19344. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19345. output.add([0]);
  19346. return output.data;
  19347. },
  19348. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19349. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19350. return this.encodeInteger(value);
  19351. } else {
  19352. return this.encodeFloat(value);
  19353. }
  19354. },
  19355. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19356. var value = num.toString();
  19357. // rounding inaccurate doubles
  19358. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19359. if (m) {
  19360. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19361. value = (Math.round(num * epsilon) / epsilon).toString();
  19362. }
  19363. var nibbles = '';
  19364. var i, ii;
  19365. for (i = 0, ii = value.length; i < ii; ++i) {
  19366. var a = value[i];
  19367. if (a === 'e') {
  19368. nibbles += value[++i] === '-' ? 'c' : 'b';
  19369. } else if (a === '.') {
  19370. nibbles += 'a';
  19371. } else if (a === '-') {
  19372. nibbles += 'e';
  19373. } else {
  19374. nibbles += a;
  19375. }
  19376. }
  19377. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19378. var out = [30];
  19379. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19380. out.push(parseInt(nibbles.substr(i, 2), 16));
  19381. }
  19382. return out;
  19383. },
  19384. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19385. var code;
  19386. if (value >= -107 && value <= 107) {
  19387. code = [value + 139];
  19388. } else if (value >= 108 && value <= 1131) {
  19389. value = [value - 108];
  19390. code = [(value >> 8) + 247, value & 0xFF];
  19391. } else if (value >= -1131 && value <= -108) {
  19392. value = -value - 108;
  19393. code = [(value >> 8) + 251, value & 0xFF];
  19394. } else if (value >= -32768 && value <= 32767) {
  19395. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19396. } else {
  19397. code = [0x1d,
  19398. (value >> 24) & 0xFF,
  19399. (value >> 16) & 0xFF,
  19400. (value >> 8) & 0xFF,
  19401. value & 0xFF];
  19402. }
  19403. return code;
  19404. },
  19405. compileHeader: function CFFCompiler_compileHeader(header) {
  19406. return [
  19407. header.major,
  19408. header.minor,
  19409. header.hdrSize,
  19410. header.offSize
  19411. ];
  19412. },
  19413. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19414. var nameIndex = new CFFIndex();
  19415. for (var i = 0, ii = names.length; i < ii; ++i) {
  19416. nameIndex.add(stringToBytes(names[i]));
  19417. }
  19418. return this.compileIndex(nameIndex);
  19419. },
  19420. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19421. length,
  19422. removeCidKeys) {
  19423. var fontDictTrackers = [];
  19424. var fdArrayIndex = new CFFIndex();
  19425. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19426. var fontDict = dicts[i];
  19427. if (removeCidKeys) {
  19428. fontDict.removeByName('CIDFontVersion');
  19429. fontDict.removeByName('CIDFontRevision');
  19430. fontDict.removeByName('CIDFontType');
  19431. fontDict.removeByName('CIDCount');
  19432. fontDict.removeByName('UIDBase');
  19433. }
  19434. var fontDictTracker = new CFFOffsetTracker();
  19435. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19436. fontDictTrackers.push(fontDictTracker);
  19437. fdArrayIndex.add(fontDictData);
  19438. fontDictTracker.offset(length);
  19439. }
  19440. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19441. return {
  19442. trackers: fontDictTrackers,
  19443. output: fdArrayIndex
  19444. };
  19445. },
  19446. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19447. trackers,
  19448. output) {
  19449. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19450. var fontDict = dicts[i];
  19451. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19452. 'There must be an private dictionary.');
  19453. var privateDict = fontDict.privateDict;
  19454. var privateDictTracker = new CFFOffsetTracker();
  19455. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19456. var outputLength = output.length;
  19457. privateDictTracker.offset(outputLength);
  19458. if (!privateDictData.length) {
  19459. // The private dictionary was empty, set the output length to zero to
  19460. // ensure the offset length isn't out of bounds in the eyes of the
  19461. // sanitizer.
  19462. outputLength = 0;
  19463. }
  19464. trackers[i].setEntryLocation('Private',
  19465. [privateDictData.length, outputLength],
  19466. output);
  19467. output.add(privateDictData);
  19468. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19469. var subrs = this.compileIndex(privateDict.subrsIndex);
  19470. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19471. output);
  19472. output.add(subrs);
  19473. }
  19474. }
  19475. },
  19476. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19477. var out = [];
  19478. // The dictionary keys must be in a certain order.
  19479. var order = dict.order;
  19480. for (var i = 0; i < order.length; ++i) {
  19481. var key = order[i];
  19482. if (!(key in dict.values)) {
  19483. continue;
  19484. }
  19485. var values = dict.values[key];
  19486. var types = dict.types[key];
  19487. if (!isArray(types)) {
  19488. types = [types];
  19489. }
  19490. if (!isArray(values)) {
  19491. values = [values];
  19492. }
  19493. // Remove any empty dict values.
  19494. if (values.length === 0) {
  19495. continue;
  19496. }
  19497. for (var j = 0, jj = types.length; j < jj; ++j) {
  19498. var type = types[j];
  19499. var value = values[j];
  19500. switch (type) {
  19501. case 'num':
  19502. case 'sid':
  19503. out = out.concat(this.encodeNumber(value));
  19504. break;
  19505. case 'offset':
  19506. // For offsets we just insert a 32bit integer so we don't have to
  19507. // deal with figuring out the length of the offset when it gets
  19508. // replaced later on by the compiler.
  19509. var name = dict.keyToNameMap[key];
  19510. // Some offsets have the offset and the length, so just record the
  19511. // position of the first one.
  19512. if (!offsetTracker.isTracking(name)) {
  19513. offsetTracker.track(name, out.length);
  19514. }
  19515. out = out.concat([0x1d, 0, 0, 0, 0]);
  19516. break;
  19517. case 'array':
  19518. case 'delta':
  19519. out = out.concat(this.encodeNumber(value));
  19520. for (var k = 1, kk = values.length; k < kk; ++k) {
  19521. out = out.concat(this.encodeNumber(values[k]));
  19522. }
  19523. break;
  19524. default:
  19525. error('Unknown data type of ' + type);
  19526. break;
  19527. }
  19528. }
  19529. out = out.concat(dict.opcodes[key]);
  19530. }
  19531. return out;
  19532. },
  19533. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19534. var stringIndex = new CFFIndex();
  19535. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19536. stringIndex.add(stringToBytes(strings[i]));
  19537. }
  19538. return this.compileIndex(stringIndex);
  19539. },
  19540. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19541. var globalSubrIndex = this.cff.globalSubrIndex;
  19542. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19543. },
  19544. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19545. return this.compileIndex(charStrings);
  19546. },
  19547. compileCharset: function CFFCompiler_compileCharset(charset) {
  19548. return this.compileTypedArray(charset.raw);
  19549. },
  19550. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19551. return this.compileTypedArray(encoding.raw);
  19552. },
  19553. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19554. return this.compileTypedArray(fdSelect);
  19555. },
  19556. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19557. var out = [];
  19558. for (var i = 0, ii = data.length; i < ii; ++i) {
  19559. out[i] = data[i];
  19560. }
  19561. return out;
  19562. },
  19563. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19564. trackers = trackers || [];
  19565. var objects = index.objects;
  19566. // First 2 bytes contains the number of objects contained into this index
  19567. var count = objects.length;
  19568. // If there is no object, just create an index. This technically
  19569. // should just be [0, 0] but OTS has an issue with that.
  19570. if (count === 0) {
  19571. return [0, 0, 0];
  19572. }
  19573. var data = [(count >> 8) & 0xFF, count & 0xff];
  19574. var lastOffset = 1, i;
  19575. for (i = 0; i < count; ++i) {
  19576. lastOffset += objects[i].length;
  19577. }
  19578. var offsetSize;
  19579. if (lastOffset < 0x100) {
  19580. offsetSize = 1;
  19581. } else if (lastOffset < 0x10000) {
  19582. offsetSize = 2;
  19583. } else if (lastOffset < 0x1000000) {
  19584. offsetSize = 3;
  19585. } else {
  19586. offsetSize = 4;
  19587. }
  19588. // Next byte contains the offset size use to reference object in the file
  19589. data.push(offsetSize);
  19590. // Add another offset after this one because we need a new offset
  19591. var relativeOffset = 1;
  19592. for (i = 0; i < count + 1; i++) {
  19593. if (offsetSize === 1) {
  19594. data.push(relativeOffset & 0xFF);
  19595. } else if (offsetSize === 2) {
  19596. data.push((relativeOffset >> 8) & 0xFF,
  19597. relativeOffset & 0xFF);
  19598. } else if (offsetSize === 3) {
  19599. data.push((relativeOffset >> 16) & 0xFF,
  19600. (relativeOffset >> 8) & 0xFF,
  19601. relativeOffset & 0xFF);
  19602. } else {
  19603. data.push((relativeOffset >>> 24) & 0xFF,
  19604. (relativeOffset >> 16) & 0xFF,
  19605. (relativeOffset >> 8) & 0xFF,
  19606. relativeOffset & 0xFF);
  19607. }
  19608. if (objects[i]) {
  19609. relativeOffset += objects[i].length;
  19610. }
  19611. }
  19612. for (i = 0; i < count; i++) {
  19613. // Notify the tracker where the object will be offset in the data.
  19614. if (trackers[i]) {
  19615. trackers[i].offset(data.length);
  19616. }
  19617. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19618. data.push(objects[i][j]);
  19619. }
  19620. }
  19621. return data;
  19622. }
  19623. };
  19624. return CFFCompiler;
  19625. })();
  19626. // Workaround for seac on Windows.
  19627. (function checkSeacSupport() {
  19628. if (/Windows/.test(navigator.userAgent)) {
  19629. SEAC_ANALYSIS_ENABLED = true;
  19630. }
  19631. })();
  19632. // Workaround for Private Use Area characters in Chrome on Windows
  19633. // http://code.google.com/p/chromium/issues/detail?id=122465
  19634. // https://github.com/mozilla/pdf.js/issues/1689
  19635. (function checkChromeWindows() {
  19636. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19637. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19638. }
  19639. })();
  19640. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19641. function getLong(data, offset) {
  19642. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19643. (data[offset + 2] << 8) | data[offset + 3];
  19644. }
  19645. function getUshort(data, offset) {
  19646. return (data[offset] << 8) | data[offset + 1];
  19647. }
  19648. function parseCmap(data, start, end) {
  19649. var offset = (getUshort(data, start + 2) === 1 ?
  19650. getLong(data, start + 8) : getLong(data, start + 16));
  19651. var format = getUshort(data, start + offset);
  19652. var length, ranges, p, i;
  19653. if (format === 4) {
  19654. length = getUshort(data, start + offset + 2);
  19655. var segCount = getUshort(data, start + offset + 6) >> 1;
  19656. p = start + offset + 14;
  19657. ranges = [];
  19658. for (i = 0; i < segCount; i++, p += 2) {
  19659. ranges[i] = {end: getUshort(data, p)};
  19660. }
  19661. p += 2;
  19662. for (i = 0; i < segCount; i++, p += 2) {
  19663. ranges[i].start = getUshort(data, p);
  19664. }
  19665. for (i = 0; i < segCount; i++, p += 2) {
  19666. ranges[i].idDelta = getUshort(data, p);
  19667. }
  19668. for (i = 0; i < segCount; i++, p += 2) {
  19669. var idOffset = getUshort(data, p);
  19670. if (idOffset === 0) {
  19671. continue;
  19672. }
  19673. ranges[i].ids = [];
  19674. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19675. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19676. idOffset += 2;
  19677. }
  19678. }
  19679. return ranges;
  19680. } else if (format === 12) {
  19681. length = getLong(data, start + offset + 4);
  19682. var groups = getLong(data, start + offset + 12);
  19683. p = start + offset + 16;
  19684. ranges = [];
  19685. for (i = 0; i < groups; i++) {
  19686. ranges.push({
  19687. start: getLong(data, p),
  19688. end: getLong(data, p + 4),
  19689. idDelta: getLong(data, p + 8) - getLong(data, p)
  19690. });
  19691. p += 12;
  19692. }
  19693. return ranges;
  19694. }
  19695. error('not supported cmap: ' + format);
  19696. }
  19697. function parseCff(data, start, end) {
  19698. var properties = {};
  19699. var parser = new CFFParser(new Stream(data, start, end - start),
  19700. properties);
  19701. var cff = parser.parse();
  19702. return {
  19703. glyphs: cff.charStrings.objects,
  19704. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19705. cff.topDict.privateDict.subrsIndex.objects),
  19706. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19707. };
  19708. }
  19709. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19710. var itemSize, itemDecode;
  19711. if (isGlyphLocationsLong) {
  19712. itemSize = 4;
  19713. itemDecode = function fontItemDecodeLong(data, offset) {
  19714. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19715. (data[offset + 2] << 8) | data[offset + 3];
  19716. };
  19717. } else {
  19718. itemSize = 2;
  19719. itemDecode = function fontItemDecode(data, offset) {
  19720. return (data[offset] << 9) | (data[offset + 1] << 1);
  19721. };
  19722. }
  19723. var glyphs = [];
  19724. var startOffset = itemDecode(loca, 0);
  19725. for (var j = itemSize; j < loca.length; j += itemSize) {
  19726. var endOffset = itemDecode(loca, j);
  19727. glyphs.push(glyf.subarray(startOffset, endOffset));
  19728. startOffset = endOffset;
  19729. }
  19730. return glyphs;
  19731. }
  19732. function lookupCmap(ranges, unicode) {
  19733. var code = unicode.charCodeAt(0);
  19734. var l = 0, r = ranges.length - 1;
  19735. while (l < r) {
  19736. var c = (l + r + 1) >> 1;
  19737. if (code < ranges[c].start) {
  19738. r = c - 1;
  19739. } else {
  19740. l = c;
  19741. }
  19742. }
  19743. if (ranges[l].start <= code && code <= ranges[l].end) {
  19744. return (ranges[l].idDelta + (ranges[l].ids ?
  19745. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19746. }
  19747. return 0;
  19748. }
  19749. function compileGlyf(code, js, font) {
  19750. function moveTo(x, y) {
  19751. js.push('c.moveTo(' + x + ',' + y + ');');
  19752. }
  19753. function lineTo(x, y) {
  19754. js.push('c.lineTo(' + x + ',' + y + ');');
  19755. }
  19756. function quadraticCurveTo(xa, ya, x, y) {
  19757. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  19758. x + ',' + y + ');');
  19759. }
  19760. var i = 0;
  19761. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19762. var flags;
  19763. var x = 0, y = 0;
  19764. i += 10;
  19765. if (numberOfContours < 0) {
  19766. // composite glyph
  19767. do {
  19768. flags = (code[i] << 8) | code[i + 1];
  19769. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19770. i += 4;
  19771. var arg1, arg2;
  19772. if ((flags & 0x01)) {
  19773. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19774. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19775. i += 4;
  19776. } else {
  19777. arg1 = code[i++]; arg2 = code[i++];
  19778. }
  19779. if ((flags & 0x02)) {
  19780. x = arg1;
  19781. y = arg2;
  19782. } else {
  19783. x = 0; y = 0; // TODO "they are points" ?
  19784. }
  19785. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19786. if ((flags & 0x08)) {
  19787. scaleX =
  19788. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19789. i += 2;
  19790. } else if ((flags & 0x40)) {
  19791. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19792. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19793. i += 4;
  19794. } else if ((flags & 0x80)) {
  19795. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19796. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19797. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19798. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19799. i += 8;
  19800. }
  19801. var subglyph = font.glyphs[glyphIndex];
  19802. if (subglyph) {
  19803. js.push('c.save();');
  19804. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  19805. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  19806. compileGlyf(subglyph, js, font);
  19807. js.push('c.restore();');
  19808. }
  19809. } while ((flags & 0x20));
  19810. } else {
  19811. // simple glyph
  19812. var endPtsOfContours = [];
  19813. var j, jj;
  19814. for (j = 0; j < numberOfContours; j++) {
  19815. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19816. i += 2;
  19817. }
  19818. var instructionLength = (code[i] << 8) | code[i + 1];
  19819. i += 2 + instructionLength; // skipping the instructions
  19820. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19821. var points = [];
  19822. while (points.length < numberOfPoints) {
  19823. flags = code[i++];
  19824. var repeat = 1;
  19825. if ((flags & 0x08)) {
  19826. repeat += code[i++];
  19827. }
  19828. while (repeat-- > 0) {
  19829. points.push({flags: flags});
  19830. }
  19831. }
  19832. for (j = 0; j < numberOfPoints; j++) {
  19833. switch (points[j].flags & 0x12) {
  19834. case 0x00:
  19835. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19836. i += 2;
  19837. break;
  19838. case 0x02:
  19839. x -= code[i++];
  19840. break;
  19841. case 0x12:
  19842. x += code[i++];
  19843. break;
  19844. }
  19845. points[j].x = x;
  19846. }
  19847. for (j = 0; j < numberOfPoints; j++) {
  19848. switch (points[j].flags & 0x24) {
  19849. case 0x00:
  19850. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19851. i += 2;
  19852. break;
  19853. case 0x04:
  19854. y -= code[i++];
  19855. break;
  19856. case 0x24:
  19857. y += code[i++];
  19858. break;
  19859. }
  19860. points[j].y = y;
  19861. }
  19862. var startPoint = 0;
  19863. for (i = 0; i < numberOfContours; i++) {
  19864. var endPoint = endPtsOfContours[i];
  19865. // contours might have implicit points, which is located in the middle
  19866. // between two neighboring off-curve points
  19867. var contour = points.slice(startPoint, endPoint + 1);
  19868. if ((contour[0].flags & 1)) {
  19869. contour.push(contour[0]); // using start point at the contour end
  19870. } else if ((contour[contour.length - 1].flags & 1)) {
  19871. // first is off-curve point, trying to use one from the end
  19872. contour.unshift(contour[contour.length - 1]);
  19873. } else {
  19874. // start and end are off-curve points, creating implicit one
  19875. var p = {
  19876. flags: 1,
  19877. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19878. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19879. };
  19880. contour.unshift(p);
  19881. contour.push(p);
  19882. }
  19883. moveTo(contour[0].x, contour[0].y);
  19884. for (j = 1, jj = contour.length; j < jj; j++) {
  19885. if ((contour[j].flags & 1)) {
  19886. lineTo(contour[j].x, contour[j].y);
  19887. } else if ((contour[j + 1].flags & 1)){
  19888. quadraticCurveTo(contour[j].x, contour[j].y,
  19889. contour[j + 1].x, contour[j + 1].y);
  19890. j++;
  19891. } else {
  19892. quadraticCurveTo(contour[j].x, contour[j].y,
  19893. (contour[j].x + contour[j + 1].x) / 2,
  19894. (contour[j].y + contour[j + 1].y) / 2);
  19895. }
  19896. }
  19897. startPoint = endPoint + 1;
  19898. }
  19899. }
  19900. }
  19901. function compileCharString(code, js, font) {
  19902. var stack = [];
  19903. var x = 0, y = 0;
  19904. var stems = 0;
  19905. function moveTo(x, y) {
  19906. js.push('c.moveTo(' + x + ',' + y + ');');
  19907. }
  19908. function lineTo(x, y) {
  19909. js.push('c.lineTo(' + x + ',' + y + ');');
  19910. }
  19911. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19912. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  19913. x + ',' + y + ');');
  19914. }
  19915. function parse(code) {
  19916. var i = 0;
  19917. while (i < code.length) {
  19918. var stackClean = false;
  19919. var v = code[i++];
  19920. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19921. switch (v) {
  19922. case 1: // hstem
  19923. stems += stack.length >> 1;
  19924. stackClean = true;
  19925. break;
  19926. case 3: // vstem
  19927. stems += stack.length >> 1;
  19928. stackClean = true;
  19929. break;
  19930. case 4: // vmoveto
  19931. y += stack.pop();
  19932. moveTo(x, y);
  19933. stackClean = true;
  19934. break;
  19935. case 5: // rlineto
  19936. while (stack.length > 0) {
  19937. x += stack.shift();
  19938. y += stack.shift();
  19939. lineTo(x, y);
  19940. }
  19941. break;
  19942. case 6: // hlineto
  19943. while (stack.length > 0) {
  19944. x += stack.shift();
  19945. lineTo(x, y);
  19946. if (stack.length === 0) {
  19947. break;
  19948. }
  19949. y += stack.shift();
  19950. lineTo(x, y);
  19951. }
  19952. break;
  19953. case 7: // vlineto
  19954. while (stack.length > 0) {
  19955. y += stack.shift();
  19956. lineTo(x, y);
  19957. if (stack.length === 0) {
  19958. break;
  19959. }
  19960. x += stack.shift();
  19961. lineTo(x, y);
  19962. }
  19963. break;
  19964. case 8: // rrcurveto
  19965. while (stack.length > 0) {
  19966. xa = x + stack.shift(); ya = y + stack.shift();
  19967. xb = xa + stack.shift(); yb = ya + stack.shift();
  19968. x = xb + stack.shift(); y = yb + stack.shift();
  19969. bezierCurveTo(xa, ya, xb, yb, x, y);
  19970. }
  19971. break;
  19972. case 10: // callsubr
  19973. n = stack.pop() + font.subrsBias;
  19974. subrCode = font.subrs[n];
  19975. if (subrCode) {
  19976. parse(subrCode);
  19977. }
  19978. break;
  19979. case 11: // return
  19980. return;
  19981. case 12:
  19982. v = code[i++];
  19983. switch (v) {
  19984. case 34: // flex
  19985. xa = x + stack.shift();
  19986. xb = xa + stack.shift(); y1 = y + stack.shift();
  19987. x = xb + stack.shift();
  19988. bezierCurveTo(xa, y, xb, y1, x, y1);
  19989. xa = x + stack.shift();
  19990. xb = xa + stack.shift();
  19991. x = xb + stack.shift();
  19992. bezierCurveTo(xa, y1, xb, y, x, y);
  19993. break;
  19994. case 35: // flex
  19995. xa = x + stack.shift(); ya = y + stack.shift();
  19996. xb = xa + stack.shift(); yb = ya + stack.shift();
  19997. x = xb + stack.shift(); y = yb + stack.shift();
  19998. bezierCurveTo(xa, ya, xb, yb, x, y);
  19999. xa = x + stack.shift(); ya = y + stack.shift();
  20000. xb = xa + stack.shift(); yb = ya + stack.shift();
  20001. x = xb + stack.shift(); y = yb + stack.shift();
  20002. bezierCurveTo(xa, ya, xb, yb, x, y);
  20003. stack.pop(); // fd
  20004. break;
  20005. case 36: // hflex1
  20006. xa = x + stack.shift(); y1 = y + stack.shift();
  20007. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20008. x = xb + stack.shift();
  20009. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20010. xa = x + stack.shift();
  20011. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20012. x = xb + stack.shift();
  20013. bezierCurveTo(xa, y2, xb, y3, x, y);
  20014. break;
  20015. case 37: // flex1
  20016. var x0 = x, y0 = y;
  20017. xa = x + stack.shift(); ya = y + stack.shift();
  20018. xb = xa + stack.shift(); yb = ya + stack.shift();
  20019. x = xb + stack.shift(); y = yb + stack.shift();
  20020. bezierCurveTo(xa, ya, xb, yb, x, y);
  20021. xa = x + stack.shift(); ya = y + stack.shift();
  20022. xb = xa + stack.shift(); yb = ya + stack.shift();
  20023. x = xb; y = yb;
  20024. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20025. x += stack.shift();
  20026. } else {
  20027. y += stack.shift();
  20028. }
  20029. bezierCurveTo(xa, ya, xb, yb, x, y);
  20030. break;
  20031. default:
  20032. error('unknown operator: 12 ' + v);
  20033. }
  20034. break;
  20035. case 14: // endchar
  20036. if (stack.length >= 4) {
  20037. var achar = stack.pop();
  20038. var bchar = stack.pop();
  20039. y = stack.pop();
  20040. x = stack.pop();
  20041. js.push('c.save();');
  20042. js.push('c.translate('+ x + ',' + y + ');');
  20043. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20044. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20045. compileCharString(font.glyphs[gid], js, font);
  20046. js.push('c.restore();');
  20047. gid = lookupCmap(font.cmap, String.fromCharCode(
  20048. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20049. compileCharString(font.glyphs[gid], js, font);
  20050. }
  20051. return;
  20052. case 18: // hstemhm
  20053. stems += stack.length >> 1;
  20054. stackClean = true;
  20055. break;
  20056. case 19: // hintmask
  20057. stems += stack.length >> 1;
  20058. i += (stems + 7) >> 3;
  20059. stackClean = true;
  20060. break;
  20061. case 20: // cntrmask
  20062. stems += stack.length >> 1;
  20063. i += (stems + 7) >> 3;
  20064. stackClean = true;
  20065. break;
  20066. case 21: // rmoveto
  20067. y += stack.pop();
  20068. x += stack.pop();
  20069. moveTo(x, y);
  20070. stackClean = true;
  20071. break;
  20072. case 22: // hmoveto
  20073. x += stack.pop();
  20074. moveTo(x, y);
  20075. stackClean = true;
  20076. break;
  20077. case 23: // vstemhm
  20078. stems += stack.length >> 1;
  20079. stackClean = true;
  20080. break;
  20081. case 24: // rcurveline
  20082. while (stack.length > 2) {
  20083. xa = x + stack.shift(); ya = y + stack.shift();
  20084. xb = xa + stack.shift(); yb = ya + stack.shift();
  20085. x = xb + stack.shift(); y = yb + stack.shift();
  20086. bezierCurveTo(xa, ya, xb, yb, x, y);
  20087. }
  20088. x += stack.shift();
  20089. y += stack.shift();
  20090. lineTo(x, y);
  20091. break;
  20092. case 25: // rlinecurve
  20093. while (stack.length > 6) {
  20094. x += stack.shift();
  20095. y += stack.shift();
  20096. lineTo(x, y);
  20097. }
  20098. xa = x + stack.shift(); ya = y + stack.shift();
  20099. xb = xa + stack.shift(); yb = ya + stack.shift();
  20100. x = xb + stack.shift(); y = yb + stack.shift();
  20101. bezierCurveTo(xa, ya, xb, yb, x, y);
  20102. break;
  20103. case 26: // vvcurveto
  20104. if (stack.length % 2) {
  20105. x += stack.shift();
  20106. }
  20107. while (stack.length > 0) {
  20108. xa = x; ya = y + stack.shift();
  20109. xb = xa + stack.shift(); yb = ya + stack.shift();
  20110. x = xb; y = yb + stack.shift();
  20111. bezierCurveTo(xa, ya, xb, yb, x, y);
  20112. }
  20113. break;
  20114. case 27: // hhcurveto
  20115. if (stack.length % 2) {
  20116. y += stack.shift();
  20117. }
  20118. while (stack.length > 0) {
  20119. xa = x + stack.shift(); ya = y;
  20120. xb = xa + stack.shift(); yb = ya + stack.shift();
  20121. x = xb + stack.shift(); y = yb;
  20122. bezierCurveTo(xa, ya, xb, yb, x, y);
  20123. }
  20124. break;
  20125. case 28:
  20126. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20127. i += 2;
  20128. break;
  20129. case 29: // callgsubr
  20130. n = stack.pop() + font.gsubrsBias;
  20131. subrCode = font.gsubrs[n];
  20132. if (subrCode) {
  20133. parse(subrCode);
  20134. }
  20135. break;
  20136. case 30: // vhcurveto
  20137. while (stack.length > 0) {
  20138. xa = x; ya = y + stack.shift();
  20139. xb = xa + stack.shift(); yb = ya + stack.shift();
  20140. x = xb + stack.shift();
  20141. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20142. bezierCurveTo(xa, ya, xb, yb, x, y);
  20143. if (stack.length === 0) {
  20144. break;
  20145. }
  20146. xa = x + stack.shift(); ya = y;
  20147. xb = xa + stack.shift(); yb = ya + stack.shift();
  20148. y = yb + stack.shift();
  20149. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20150. bezierCurveTo(xa, ya, xb, yb, x, y);
  20151. }
  20152. break;
  20153. case 31: // hvcurveto
  20154. while (stack.length > 0) {
  20155. xa = x + stack.shift(); ya = y;
  20156. xb = xa + stack.shift(); yb = ya + stack.shift();
  20157. y = yb + stack.shift();
  20158. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20159. bezierCurveTo(xa, ya, xb, yb, x, y);
  20160. if (stack.length === 0) {
  20161. break;
  20162. }
  20163. xa = x; ya = y + stack.shift();
  20164. xb = xa + stack.shift(); yb = ya + stack.shift();
  20165. x = xb + stack.shift();
  20166. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20167. bezierCurveTo(xa, ya, xb, yb, x, y);
  20168. }
  20169. break;
  20170. default:
  20171. if (v < 32) {
  20172. error('unknown operator: ' + v);
  20173. }
  20174. if (v < 247) {
  20175. stack.push(v - 139);
  20176. } else if (v < 251) {
  20177. stack.push((v - 247) * 256 + code[i++] + 108);
  20178. } else if (v < 255) {
  20179. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20180. } else {
  20181. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20182. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20183. i += 4;
  20184. }
  20185. break;
  20186. }
  20187. if (stackClean) {
  20188. stack.length = 0;
  20189. }
  20190. }
  20191. }
  20192. parse(code);
  20193. }
  20194. var noop = '';
  20195. function CompiledFont(fontMatrix) {
  20196. this.compiledGlyphs = {};
  20197. this.fontMatrix = fontMatrix;
  20198. }
  20199. CompiledFont.prototype = {
  20200. getPathJs: function (unicode) {
  20201. var gid = lookupCmap(this.cmap, unicode);
  20202. var fn = this.compiledGlyphs[gid];
  20203. if (!fn) {
  20204. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20205. }
  20206. return fn;
  20207. },
  20208. compileGlyph: function (code) {
  20209. if (!code || code.length === 0 || code[0] === 14) {
  20210. return noop;
  20211. }
  20212. var js = [];
  20213. js.push('c.save();');
  20214. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20215. js.push('c.scale(size, -size);');
  20216. this.compileGlyphImpl(code, js);
  20217. js.push('c.restore();');
  20218. return js.join('\n');
  20219. },
  20220. compileGlyphImpl: function () {
  20221. error('Children classes should implement this.');
  20222. },
  20223. hasBuiltPath: function (unicode) {
  20224. var gid = lookupCmap(this.cmap, unicode);
  20225. return gid in this.compiledGlyphs;
  20226. }
  20227. };
  20228. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20229. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20230. CompiledFont.call(this, fontMatrix);
  20231. this.glyphs = glyphs;
  20232. this.cmap = cmap;
  20233. this.compiledGlyphs = [];
  20234. }
  20235. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20236. compileGlyphImpl: function (code, js) {
  20237. compileGlyf(code, js, this);
  20238. }
  20239. });
  20240. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20241. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20242. CompiledFont.call(this, fontMatrix);
  20243. this.glyphs = cffInfo.glyphs;
  20244. this.gsubrs = cffInfo.gsubrs || [];
  20245. this.subrs = cffInfo.subrs || [];
  20246. this.cmap = cmap;
  20247. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20248. this.compiledGlyphs = [];
  20249. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20250. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20251. this.subrsBias = (this.subrs.length < 1240 ?
  20252. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20253. }
  20254. Util.inherit(Type2Compiled, CompiledFont, {
  20255. compileGlyphImpl: function (code, js) {
  20256. compileCharString(code, js, this);
  20257. }
  20258. });
  20259. return {
  20260. create: function FontRendererFactory_create(font) {
  20261. var data = new Uint8Array(font.data);
  20262. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20263. var numTables = getUshort(data, 4);
  20264. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20265. var tag = bytesToString(data.subarray(p, p + 4));
  20266. var offset = getLong(data, p + 8);
  20267. var length = getLong(data, p + 12);
  20268. switch (tag) {
  20269. case 'cmap':
  20270. cmap = parseCmap(data, offset, offset + length);
  20271. break;
  20272. case 'glyf':
  20273. glyf = data.subarray(offset, offset + length);
  20274. break;
  20275. case 'loca':
  20276. loca = data.subarray(offset, offset + length);
  20277. break;
  20278. case 'head':
  20279. unitsPerEm = getUshort(data, offset + 18);
  20280. indexToLocFormat = getUshort(data, offset + 50);
  20281. break;
  20282. case 'CFF ':
  20283. cff = parseCff(data, offset, offset + length);
  20284. break;
  20285. }
  20286. }
  20287. if (glyf) {
  20288. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20289. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20290. return new TrueTypeCompiled(
  20291. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20292. } else {
  20293. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20294. }
  20295. }
  20296. };
  20297. })();
  20298. var GlyphsUnicode = {
  20299. A: 0x0041,
  20300. AE: 0x00C6,
  20301. AEacute: 0x01FC,
  20302. AEmacron: 0x01E2,
  20303. AEsmall: 0xF7E6,
  20304. Aacute: 0x00C1,
  20305. Aacutesmall: 0xF7E1,
  20306. Abreve: 0x0102,
  20307. Abreveacute: 0x1EAE,
  20308. Abrevecyrillic: 0x04D0,
  20309. Abrevedotbelow: 0x1EB6,
  20310. Abrevegrave: 0x1EB0,
  20311. Abrevehookabove: 0x1EB2,
  20312. Abrevetilde: 0x1EB4,
  20313. Acaron: 0x01CD,
  20314. Acircle: 0x24B6,
  20315. Acircumflex: 0x00C2,
  20316. Acircumflexacute: 0x1EA4,
  20317. Acircumflexdotbelow: 0x1EAC,
  20318. Acircumflexgrave: 0x1EA6,
  20319. Acircumflexhookabove: 0x1EA8,
  20320. Acircumflexsmall: 0xF7E2,
  20321. Acircumflextilde: 0x1EAA,
  20322. Acute: 0xF6C9,
  20323. Acutesmall: 0xF7B4,
  20324. Acyrillic: 0x0410,
  20325. Adblgrave: 0x0200,
  20326. Adieresis: 0x00C4,
  20327. Adieresiscyrillic: 0x04D2,
  20328. Adieresismacron: 0x01DE,
  20329. Adieresissmall: 0xF7E4,
  20330. Adotbelow: 0x1EA0,
  20331. Adotmacron: 0x01E0,
  20332. Agrave: 0x00C0,
  20333. Agravesmall: 0xF7E0,
  20334. Ahookabove: 0x1EA2,
  20335. Aiecyrillic: 0x04D4,
  20336. Ainvertedbreve: 0x0202,
  20337. Alpha: 0x0391,
  20338. Alphatonos: 0x0386,
  20339. Amacron: 0x0100,
  20340. Amonospace: 0xFF21,
  20341. Aogonek: 0x0104,
  20342. Aring: 0x00C5,
  20343. Aringacute: 0x01FA,
  20344. Aringbelow: 0x1E00,
  20345. Aringsmall: 0xF7E5,
  20346. Asmall: 0xF761,
  20347. Atilde: 0x00C3,
  20348. Atildesmall: 0xF7E3,
  20349. Aybarmenian: 0x0531,
  20350. B: 0x0042,
  20351. Bcircle: 0x24B7,
  20352. Bdotaccent: 0x1E02,
  20353. Bdotbelow: 0x1E04,
  20354. Becyrillic: 0x0411,
  20355. Benarmenian: 0x0532,
  20356. Beta: 0x0392,
  20357. Bhook: 0x0181,
  20358. Blinebelow: 0x1E06,
  20359. Bmonospace: 0xFF22,
  20360. Brevesmall: 0xF6F4,
  20361. Bsmall: 0xF762,
  20362. Btopbar: 0x0182,
  20363. C: 0x0043,
  20364. Caarmenian: 0x053E,
  20365. Cacute: 0x0106,
  20366. Caron: 0xF6CA,
  20367. Caronsmall: 0xF6F5,
  20368. Ccaron: 0x010C,
  20369. Ccedilla: 0x00C7,
  20370. Ccedillaacute: 0x1E08,
  20371. Ccedillasmall: 0xF7E7,
  20372. Ccircle: 0x24B8,
  20373. Ccircumflex: 0x0108,
  20374. Cdot: 0x010A,
  20375. Cdotaccent: 0x010A,
  20376. Cedillasmall: 0xF7B8,
  20377. Chaarmenian: 0x0549,
  20378. Cheabkhasiancyrillic: 0x04BC,
  20379. Checyrillic: 0x0427,
  20380. Chedescenderabkhasiancyrillic: 0x04BE,
  20381. Chedescendercyrillic: 0x04B6,
  20382. Chedieresiscyrillic: 0x04F4,
  20383. Cheharmenian: 0x0543,
  20384. Chekhakassiancyrillic: 0x04CB,
  20385. Cheverticalstrokecyrillic: 0x04B8,
  20386. Chi: 0x03A7,
  20387. Chook: 0x0187,
  20388. Circumflexsmall: 0xF6F6,
  20389. Cmonospace: 0xFF23,
  20390. Coarmenian: 0x0551,
  20391. Csmall: 0xF763,
  20392. D: 0x0044,
  20393. DZ: 0x01F1,
  20394. DZcaron: 0x01C4,
  20395. Daarmenian: 0x0534,
  20396. Dafrican: 0x0189,
  20397. Dcaron: 0x010E,
  20398. Dcedilla: 0x1E10,
  20399. Dcircle: 0x24B9,
  20400. Dcircumflexbelow: 0x1E12,
  20401. Dcroat: 0x0110,
  20402. Ddotaccent: 0x1E0A,
  20403. Ddotbelow: 0x1E0C,
  20404. Decyrillic: 0x0414,
  20405. Deicoptic: 0x03EE,
  20406. Delta: 0x2206,
  20407. Deltagreek: 0x0394,
  20408. Dhook: 0x018A,
  20409. Dieresis: 0xF6CB,
  20410. DieresisAcute: 0xF6CC,
  20411. DieresisGrave: 0xF6CD,
  20412. Dieresissmall: 0xF7A8,
  20413. Digammagreek: 0x03DC,
  20414. Djecyrillic: 0x0402,
  20415. Dlinebelow: 0x1E0E,
  20416. Dmonospace: 0xFF24,
  20417. Dotaccentsmall: 0xF6F7,
  20418. Dslash: 0x0110,
  20419. Dsmall: 0xF764,
  20420. Dtopbar: 0x018B,
  20421. Dz: 0x01F2,
  20422. Dzcaron: 0x01C5,
  20423. Dzeabkhasiancyrillic: 0x04E0,
  20424. Dzecyrillic: 0x0405,
  20425. Dzhecyrillic: 0x040F,
  20426. E: 0x0045,
  20427. Eacute: 0x00C9,
  20428. Eacutesmall: 0xF7E9,
  20429. Ebreve: 0x0114,
  20430. Ecaron: 0x011A,
  20431. Ecedillabreve: 0x1E1C,
  20432. Echarmenian: 0x0535,
  20433. Ecircle: 0x24BA,
  20434. Ecircumflex: 0x00CA,
  20435. Ecircumflexacute: 0x1EBE,
  20436. Ecircumflexbelow: 0x1E18,
  20437. Ecircumflexdotbelow: 0x1EC6,
  20438. Ecircumflexgrave: 0x1EC0,
  20439. Ecircumflexhookabove: 0x1EC2,
  20440. Ecircumflexsmall: 0xF7EA,
  20441. Ecircumflextilde: 0x1EC4,
  20442. Ecyrillic: 0x0404,
  20443. Edblgrave: 0x0204,
  20444. Edieresis: 0x00CB,
  20445. Edieresissmall: 0xF7EB,
  20446. Edot: 0x0116,
  20447. Edotaccent: 0x0116,
  20448. Edotbelow: 0x1EB8,
  20449. Efcyrillic: 0x0424,
  20450. Egrave: 0x00C8,
  20451. Egravesmall: 0xF7E8,
  20452. Eharmenian: 0x0537,
  20453. Ehookabove: 0x1EBA,
  20454. Eightroman: 0x2167,
  20455. Einvertedbreve: 0x0206,
  20456. Eiotifiedcyrillic: 0x0464,
  20457. Elcyrillic: 0x041B,
  20458. Elevenroman: 0x216A,
  20459. Emacron: 0x0112,
  20460. Emacronacute: 0x1E16,
  20461. Emacrongrave: 0x1E14,
  20462. Emcyrillic: 0x041C,
  20463. Emonospace: 0xFF25,
  20464. Encyrillic: 0x041D,
  20465. Endescendercyrillic: 0x04A2,
  20466. Eng: 0x014A,
  20467. Enghecyrillic: 0x04A4,
  20468. Enhookcyrillic: 0x04C7,
  20469. Eogonek: 0x0118,
  20470. Eopen: 0x0190,
  20471. Epsilon: 0x0395,
  20472. Epsilontonos: 0x0388,
  20473. Ercyrillic: 0x0420,
  20474. Ereversed: 0x018E,
  20475. Ereversedcyrillic: 0x042D,
  20476. Escyrillic: 0x0421,
  20477. Esdescendercyrillic: 0x04AA,
  20478. Esh: 0x01A9,
  20479. Esmall: 0xF765,
  20480. Eta: 0x0397,
  20481. Etarmenian: 0x0538,
  20482. Etatonos: 0x0389,
  20483. Eth: 0x00D0,
  20484. Ethsmall: 0xF7F0,
  20485. Etilde: 0x1EBC,
  20486. Etildebelow: 0x1E1A,
  20487. Euro: 0x20AC,
  20488. Ezh: 0x01B7,
  20489. Ezhcaron: 0x01EE,
  20490. Ezhreversed: 0x01B8,
  20491. F: 0x0046,
  20492. Fcircle: 0x24BB,
  20493. Fdotaccent: 0x1E1E,
  20494. Feharmenian: 0x0556,
  20495. Feicoptic: 0x03E4,
  20496. Fhook: 0x0191,
  20497. Fitacyrillic: 0x0472,
  20498. Fiveroman: 0x2164,
  20499. Fmonospace: 0xFF26,
  20500. Fourroman: 0x2163,
  20501. Fsmall: 0xF766,
  20502. G: 0x0047,
  20503. GBsquare: 0x3387,
  20504. Gacute: 0x01F4,
  20505. Gamma: 0x0393,
  20506. Gammaafrican: 0x0194,
  20507. Gangiacoptic: 0x03EA,
  20508. Gbreve: 0x011E,
  20509. Gcaron: 0x01E6,
  20510. Gcedilla: 0x0122,
  20511. Gcircle: 0x24BC,
  20512. Gcircumflex: 0x011C,
  20513. Gcommaaccent: 0x0122,
  20514. Gdot: 0x0120,
  20515. Gdotaccent: 0x0120,
  20516. Gecyrillic: 0x0413,
  20517. Ghadarmenian: 0x0542,
  20518. Ghemiddlehookcyrillic: 0x0494,
  20519. Ghestrokecyrillic: 0x0492,
  20520. Gheupturncyrillic: 0x0490,
  20521. Ghook: 0x0193,
  20522. Gimarmenian: 0x0533,
  20523. Gjecyrillic: 0x0403,
  20524. Gmacron: 0x1E20,
  20525. Gmonospace: 0xFF27,
  20526. Grave: 0xF6CE,
  20527. Gravesmall: 0xF760,
  20528. Gsmall: 0xF767,
  20529. Gsmallhook: 0x029B,
  20530. Gstroke: 0x01E4,
  20531. H: 0x0048,
  20532. H18533: 0x25CF,
  20533. H18543: 0x25AA,
  20534. H18551: 0x25AB,
  20535. H22073: 0x25A1,
  20536. HPsquare: 0x33CB,
  20537. Haabkhasiancyrillic: 0x04A8,
  20538. Hadescendercyrillic: 0x04B2,
  20539. Hardsigncyrillic: 0x042A,
  20540. Hbar: 0x0126,
  20541. Hbrevebelow: 0x1E2A,
  20542. Hcedilla: 0x1E28,
  20543. Hcircle: 0x24BD,
  20544. Hcircumflex: 0x0124,
  20545. Hdieresis: 0x1E26,
  20546. Hdotaccent: 0x1E22,
  20547. Hdotbelow: 0x1E24,
  20548. Hmonospace: 0xFF28,
  20549. Hoarmenian: 0x0540,
  20550. Horicoptic: 0x03E8,
  20551. Hsmall: 0xF768,
  20552. Hungarumlaut: 0xF6CF,
  20553. Hungarumlautsmall: 0xF6F8,
  20554. Hzsquare: 0x3390,
  20555. I: 0x0049,
  20556. IAcyrillic: 0x042F,
  20557. IJ: 0x0132,
  20558. IUcyrillic: 0x042E,
  20559. Iacute: 0x00CD,
  20560. Iacutesmall: 0xF7ED,
  20561. Ibreve: 0x012C,
  20562. Icaron: 0x01CF,
  20563. Icircle: 0x24BE,
  20564. Icircumflex: 0x00CE,
  20565. Icircumflexsmall: 0xF7EE,
  20566. Icyrillic: 0x0406,
  20567. Idblgrave: 0x0208,
  20568. Idieresis: 0x00CF,
  20569. Idieresisacute: 0x1E2E,
  20570. Idieresiscyrillic: 0x04E4,
  20571. Idieresissmall: 0xF7EF,
  20572. Idot: 0x0130,
  20573. Idotaccent: 0x0130,
  20574. Idotbelow: 0x1ECA,
  20575. Iebrevecyrillic: 0x04D6,
  20576. Iecyrillic: 0x0415,
  20577. Ifraktur: 0x2111,
  20578. Igrave: 0x00CC,
  20579. Igravesmall: 0xF7EC,
  20580. Ihookabove: 0x1EC8,
  20581. Iicyrillic: 0x0418,
  20582. Iinvertedbreve: 0x020A,
  20583. Iishortcyrillic: 0x0419,
  20584. Imacron: 0x012A,
  20585. Imacroncyrillic: 0x04E2,
  20586. Imonospace: 0xFF29,
  20587. Iniarmenian: 0x053B,
  20588. Iocyrillic: 0x0401,
  20589. Iogonek: 0x012E,
  20590. Iota: 0x0399,
  20591. Iotaafrican: 0x0196,
  20592. Iotadieresis: 0x03AA,
  20593. Iotatonos: 0x038A,
  20594. Ismall: 0xF769,
  20595. Istroke: 0x0197,
  20596. Itilde: 0x0128,
  20597. Itildebelow: 0x1E2C,
  20598. Izhitsacyrillic: 0x0474,
  20599. Izhitsadblgravecyrillic: 0x0476,
  20600. J: 0x004A,
  20601. Jaarmenian: 0x0541,
  20602. Jcircle: 0x24BF,
  20603. Jcircumflex: 0x0134,
  20604. Jecyrillic: 0x0408,
  20605. Jheharmenian: 0x054B,
  20606. Jmonospace: 0xFF2A,
  20607. Jsmall: 0xF76A,
  20608. K: 0x004B,
  20609. KBsquare: 0x3385,
  20610. KKsquare: 0x33CD,
  20611. Kabashkircyrillic: 0x04A0,
  20612. Kacute: 0x1E30,
  20613. Kacyrillic: 0x041A,
  20614. Kadescendercyrillic: 0x049A,
  20615. Kahookcyrillic: 0x04C3,
  20616. Kappa: 0x039A,
  20617. Kastrokecyrillic: 0x049E,
  20618. Kaverticalstrokecyrillic: 0x049C,
  20619. Kcaron: 0x01E8,
  20620. Kcedilla: 0x0136,
  20621. Kcircle: 0x24C0,
  20622. Kcommaaccent: 0x0136,
  20623. Kdotbelow: 0x1E32,
  20624. Keharmenian: 0x0554,
  20625. Kenarmenian: 0x053F,
  20626. Khacyrillic: 0x0425,
  20627. Kheicoptic: 0x03E6,
  20628. Khook: 0x0198,
  20629. Kjecyrillic: 0x040C,
  20630. Klinebelow: 0x1E34,
  20631. Kmonospace: 0xFF2B,
  20632. Koppacyrillic: 0x0480,
  20633. Koppagreek: 0x03DE,
  20634. Ksicyrillic: 0x046E,
  20635. Ksmall: 0xF76B,
  20636. L: 0x004C,
  20637. LJ: 0x01C7,
  20638. LL: 0xF6BF,
  20639. Lacute: 0x0139,
  20640. Lambda: 0x039B,
  20641. Lcaron: 0x013D,
  20642. Lcedilla: 0x013B,
  20643. Lcircle: 0x24C1,
  20644. Lcircumflexbelow: 0x1E3C,
  20645. Lcommaaccent: 0x013B,
  20646. Ldot: 0x013F,
  20647. Ldotaccent: 0x013F,
  20648. Ldotbelow: 0x1E36,
  20649. Ldotbelowmacron: 0x1E38,
  20650. Liwnarmenian: 0x053C,
  20651. Lj: 0x01C8,
  20652. Ljecyrillic: 0x0409,
  20653. Llinebelow: 0x1E3A,
  20654. Lmonospace: 0xFF2C,
  20655. Lslash: 0x0141,
  20656. Lslashsmall: 0xF6F9,
  20657. Lsmall: 0xF76C,
  20658. M: 0x004D,
  20659. MBsquare: 0x3386,
  20660. Macron: 0xF6D0,
  20661. Macronsmall: 0xF7AF,
  20662. Macute: 0x1E3E,
  20663. Mcircle: 0x24C2,
  20664. Mdotaccent: 0x1E40,
  20665. Mdotbelow: 0x1E42,
  20666. Menarmenian: 0x0544,
  20667. Mmonospace: 0xFF2D,
  20668. Msmall: 0xF76D,
  20669. Mturned: 0x019C,
  20670. Mu: 0x039C,
  20671. N: 0x004E,
  20672. NJ: 0x01CA,
  20673. Nacute: 0x0143,
  20674. Ncaron: 0x0147,
  20675. Ncedilla: 0x0145,
  20676. Ncircle: 0x24C3,
  20677. Ncircumflexbelow: 0x1E4A,
  20678. Ncommaaccent: 0x0145,
  20679. Ndotaccent: 0x1E44,
  20680. Ndotbelow: 0x1E46,
  20681. Nhookleft: 0x019D,
  20682. Nineroman: 0x2168,
  20683. Nj: 0x01CB,
  20684. Njecyrillic: 0x040A,
  20685. Nlinebelow: 0x1E48,
  20686. Nmonospace: 0xFF2E,
  20687. Nowarmenian: 0x0546,
  20688. Nsmall: 0xF76E,
  20689. Ntilde: 0x00D1,
  20690. Ntildesmall: 0xF7F1,
  20691. Nu: 0x039D,
  20692. O: 0x004F,
  20693. OE: 0x0152,
  20694. OEsmall: 0xF6FA,
  20695. Oacute: 0x00D3,
  20696. Oacutesmall: 0xF7F3,
  20697. Obarredcyrillic: 0x04E8,
  20698. Obarreddieresiscyrillic: 0x04EA,
  20699. Obreve: 0x014E,
  20700. Ocaron: 0x01D1,
  20701. Ocenteredtilde: 0x019F,
  20702. Ocircle: 0x24C4,
  20703. Ocircumflex: 0x00D4,
  20704. Ocircumflexacute: 0x1ED0,
  20705. Ocircumflexdotbelow: 0x1ED8,
  20706. Ocircumflexgrave: 0x1ED2,
  20707. Ocircumflexhookabove: 0x1ED4,
  20708. Ocircumflexsmall: 0xF7F4,
  20709. Ocircumflextilde: 0x1ED6,
  20710. Ocyrillic: 0x041E,
  20711. Odblacute: 0x0150,
  20712. Odblgrave: 0x020C,
  20713. Odieresis: 0x00D6,
  20714. Odieresiscyrillic: 0x04E6,
  20715. Odieresissmall: 0xF7F6,
  20716. Odotbelow: 0x1ECC,
  20717. Ogoneksmall: 0xF6FB,
  20718. Ograve: 0x00D2,
  20719. Ogravesmall: 0xF7F2,
  20720. Oharmenian: 0x0555,
  20721. Ohm: 0x2126,
  20722. Ohookabove: 0x1ECE,
  20723. Ohorn: 0x01A0,
  20724. Ohornacute: 0x1EDA,
  20725. Ohorndotbelow: 0x1EE2,
  20726. Ohorngrave: 0x1EDC,
  20727. Ohornhookabove: 0x1EDE,
  20728. Ohorntilde: 0x1EE0,
  20729. Ohungarumlaut: 0x0150,
  20730. Oi: 0x01A2,
  20731. Oinvertedbreve: 0x020E,
  20732. Omacron: 0x014C,
  20733. Omacronacute: 0x1E52,
  20734. Omacrongrave: 0x1E50,
  20735. Omega: 0x2126,
  20736. Omegacyrillic: 0x0460,
  20737. Omegagreek: 0x03A9,
  20738. Omegaroundcyrillic: 0x047A,
  20739. Omegatitlocyrillic: 0x047C,
  20740. Omegatonos: 0x038F,
  20741. Omicron: 0x039F,
  20742. Omicrontonos: 0x038C,
  20743. Omonospace: 0xFF2F,
  20744. Oneroman: 0x2160,
  20745. Oogonek: 0x01EA,
  20746. Oogonekmacron: 0x01EC,
  20747. Oopen: 0x0186,
  20748. Oslash: 0x00D8,
  20749. Oslashacute: 0x01FE,
  20750. Oslashsmall: 0xF7F8,
  20751. Osmall: 0xF76F,
  20752. Ostrokeacute: 0x01FE,
  20753. Otcyrillic: 0x047E,
  20754. Otilde: 0x00D5,
  20755. Otildeacute: 0x1E4C,
  20756. Otildedieresis: 0x1E4E,
  20757. Otildesmall: 0xF7F5,
  20758. P: 0x0050,
  20759. Pacute: 0x1E54,
  20760. Pcircle: 0x24C5,
  20761. Pdotaccent: 0x1E56,
  20762. Pecyrillic: 0x041F,
  20763. Peharmenian: 0x054A,
  20764. Pemiddlehookcyrillic: 0x04A6,
  20765. Phi: 0x03A6,
  20766. Phook: 0x01A4,
  20767. Pi: 0x03A0,
  20768. Piwrarmenian: 0x0553,
  20769. Pmonospace: 0xFF30,
  20770. Psi: 0x03A8,
  20771. Psicyrillic: 0x0470,
  20772. Psmall: 0xF770,
  20773. Q: 0x0051,
  20774. Qcircle: 0x24C6,
  20775. Qmonospace: 0xFF31,
  20776. Qsmall: 0xF771,
  20777. R: 0x0052,
  20778. Raarmenian: 0x054C,
  20779. Racute: 0x0154,
  20780. Rcaron: 0x0158,
  20781. Rcedilla: 0x0156,
  20782. Rcircle: 0x24C7,
  20783. Rcommaaccent: 0x0156,
  20784. Rdblgrave: 0x0210,
  20785. Rdotaccent: 0x1E58,
  20786. Rdotbelow: 0x1E5A,
  20787. Rdotbelowmacron: 0x1E5C,
  20788. Reharmenian: 0x0550,
  20789. Rfraktur: 0x211C,
  20790. Rho: 0x03A1,
  20791. Ringsmall: 0xF6FC,
  20792. Rinvertedbreve: 0x0212,
  20793. Rlinebelow: 0x1E5E,
  20794. Rmonospace: 0xFF32,
  20795. Rsmall: 0xF772,
  20796. Rsmallinverted: 0x0281,
  20797. Rsmallinvertedsuperior: 0x02B6,
  20798. S: 0x0053,
  20799. SF010000: 0x250C,
  20800. SF020000: 0x2514,
  20801. SF030000: 0x2510,
  20802. SF040000: 0x2518,
  20803. SF050000: 0x253C,
  20804. SF060000: 0x252C,
  20805. SF070000: 0x2534,
  20806. SF080000: 0x251C,
  20807. SF090000: 0x2524,
  20808. SF100000: 0x2500,
  20809. SF110000: 0x2502,
  20810. SF190000: 0x2561,
  20811. SF200000: 0x2562,
  20812. SF210000: 0x2556,
  20813. SF220000: 0x2555,
  20814. SF230000: 0x2563,
  20815. SF240000: 0x2551,
  20816. SF250000: 0x2557,
  20817. SF260000: 0x255D,
  20818. SF270000: 0x255C,
  20819. SF280000: 0x255B,
  20820. SF360000: 0x255E,
  20821. SF370000: 0x255F,
  20822. SF380000: 0x255A,
  20823. SF390000: 0x2554,
  20824. SF400000: 0x2569,
  20825. SF410000: 0x2566,
  20826. SF420000: 0x2560,
  20827. SF430000: 0x2550,
  20828. SF440000: 0x256C,
  20829. SF450000: 0x2567,
  20830. SF460000: 0x2568,
  20831. SF470000: 0x2564,
  20832. SF480000: 0x2565,
  20833. SF490000: 0x2559,
  20834. SF500000: 0x2558,
  20835. SF510000: 0x2552,
  20836. SF520000: 0x2553,
  20837. SF530000: 0x256B,
  20838. SF540000: 0x256A,
  20839. Sacute: 0x015A,
  20840. Sacutedotaccent: 0x1E64,
  20841. Sampigreek: 0x03E0,
  20842. Scaron: 0x0160,
  20843. Scarondotaccent: 0x1E66,
  20844. Scaronsmall: 0xF6FD,
  20845. Scedilla: 0x015E,
  20846. Schwa: 0x018F,
  20847. Schwacyrillic: 0x04D8,
  20848. Schwadieresiscyrillic: 0x04DA,
  20849. Scircle: 0x24C8,
  20850. Scircumflex: 0x015C,
  20851. Scommaaccent: 0x0218,
  20852. Sdotaccent: 0x1E60,
  20853. Sdotbelow: 0x1E62,
  20854. Sdotbelowdotaccent: 0x1E68,
  20855. Seharmenian: 0x054D,
  20856. Sevenroman: 0x2166,
  20857. Shaarmenian: 0x0547,
  20858. Shacyrillic: 0x0428,
  20859. Shchacyrillic: 0x0429,
  20860. Sheicoptic: 0x03E2,
  20861. Shhacyrillic: 0x04BA,
  20862. Shimacoptic: 0x03EC,
  20863. Sigma: 0x03A3,
  20864. Sixroman: 0x2165,
  20865. Smonospace: 0xFF33,
  20866. Softsigncyrillic: 0x042C,
  20867. Ssmall: 0xF773,
  20868. Stigmagreek: 0x03DA,
  20869. T: 0x0054,
  20870. Tau: 0x03A4,
  20871. Tbar: 0x0166,
  20872. Tcaron: 0x0164,
  20873. Tcedilla: 0x0162,
  20874. Tcircle: 0x24C9,
  20875. Tcircumflexbelow: 0x1E70,
  20876. Tcommaaccent: 0x0162,
  20877. Tdotaccent: 0x1E6A,
  20878. Tdotbelow: 0x1E6C,
  20879. Tecyrillic: 0x0422,
  20880. Tedescendercyrillic: 0x04AC,
  20881. Tenroman: 0x2169,
  20882. Tetsecyrillic: 0x04B4,
  20883. Theta: 0x0398,
  20884. Thook: 0x01AC,
  20885. Thorn: 0x00DE,
  20886. Thornsmall: 0xF7FE,
  20887. Threeroman: 0x2162,
  20888. Tildesmall: 0xF6FE,
  20889. Tiwnarmenian: 0x054F,
  20890. Tlinebelow: 0x1E6E,
  20891. Tmonospace: 0xFF34,
  20892. Toarmenian: 0x0539,
  20893. Tonefive: 0x01BC,
  20894. Tonesix: 0x0184,
  20895. Tonetwo: 0x01A7,
  20896. Tretroflexhook: 0x01AE,
  20897. Tsecyrillic: 0x0426,
  20898. Tshecyrillic: 0x040B,
  20899. Tsmall: 0xF774,
  20900. Twelveroman: 0x216B,
  20901. Tworoman: 0x2161,
  20902. U: 0x0055,
  20903. Uacute: 0x00DA,
  20904. Uacutesmall: 0xF7FA,
  20905. Ubreve: 0x016C,
  20906. Ucaron: 0x01D3,
  20907. Ucircle: 0x24CA,
  20908. Ucircumflex: 0x00DB,
  20909. Ucircumflexbelow: 0x1E76,
  20910. Ucircumflexsmall: 0xF7FB,
  20911. Ucyrillic: 0x0423,
  20912. Udblacute: 0x0170,
  20913. Udblgrave: 0x0214,
  20914. Udieresis: 0x00DC,
  20915. Udieresisacute: 0x01D7,
  20916. Udieresisbelow: 0x1E72,
  20917. Udieresiscaron: 0x01D9,
  20918. Udieresiscyrillic: 0x04F0,
  20919. Udieresisgrave: 0x01DB,
  20920. Udieresismacron: 0x01D5,
  20921. Udieresissmall: 0xF7FC,
  20922. Udotbelow: 0x1EE4,
  20923. Ugrave: 0x00D9,
  20924. Ugravesmall: 0xF7F9,
  20925. Uhookabove: 0x1EE6,
  20926. Uhorn: 0x01AF,
  20927. Uhornacute: 0x1EE8,
  20928. Uhorndotbelow: 0x1EF0,
  20929. Uhorngrave: 0x1EEA,
  20930. Uhornhookabove: 0x1EEC,
  20931. Uhorntilde: 0x1EEE,
  20932. Uhungarumlaut: 0x0170,
  20933. Uhungarumlautcyrillic: 0x04F2,
  20934. Uinvertedbreve: 0x0216,
  20935. Ukcyrillic: 0x0478,
  20936. Umacron: 0x016A,
  20937. Umacroncyrillic: 0x04EE,
  20938. Umacrondieresis: 0x1E7A,
  20939. Umonospace: 0xFF35,
  20940. Uogonek: 0x0172,
  20941. Upsilon: 0x03A5,
  20942. Upsilon1: 0x03D2,
  20943. Upsilonacutehooksymbolgreek: 0x03D3,
  20944. Upsilonafrican: 0x01B1,
  20945. Upsilondieresis: 0x03AB,
  20946. Upsilondieresishooksymbolgreek: 0x03D4,
  20947. Upsilonhooksymbol: 0x03D2,
  20948. Upsilontonos: 0x038E,
  20949. Uring: 0x016E,
  20950. Ushortcyrillic: 0x040E,
  20951. Usmall: 0xF775,
  20952. Ustraightcyrillic: 0x04AE,
  20953. Ustraightstrokecyrillic: 0x04B0,
  20954. Utilde: 0x0168,
  20955. Utildeacute: 0x1E78,
  20956. Utildebelow: 0x1E74,
  20957. V: 0x0056,
  20958. Vcircle: 0x24CB,
  20959. Vdotbelow: 0x1E7E,
  20960. Vecyrillic: 0x0412,
  20961. Vewarmenian: 0x054E,
  20962. Vhook: 0x01B2,
  20963. Vmonospace: 0xFF36,
  20964. Voarmenian: 0x0548,
  20965. Vsmall: 0xF776,
  20966. Vtilde: 0x1E7C,
  20967. W: 0x0057,
  20968. Wacute: 0x1E82,
  20969. Wcircle: 0x24CC,
  20970. Wcircumflex: 0x0174,
  20971. Wdieresis: 0x1E84,
  20972. Wdotaccent: 0x1E86,
  20973. Wdotbelow: 0x1E88,
  20974. Wgrave: 0x1E80,
  20975. Wmonospace: 0xFF37,
  20976. Wsmall: 0xF777,
  20977. X: 0x0058,
  20978. Xcircle: 0x24CD,
  20979. Xdieresis: 0x1E8C,
  20980. Xdotaccent: 0x1E8A,
  20981. Xeharmenian: 0x053D,
  20982. Xi: 0x039E,
  20983. Xmonospace: 0xFF38,
  20984. Xsmall: 0xF778,
  20985. Y: 0x0059,
  20986. Yacute: 0x00DD,
  20987. Yacutesmall: 0xF7FD,
  20988. Yatcyrillic: 0x0462,
  20989. Ycircle: 0x24CE,
  20990. Ycircumflex: 0x0176,
  20991. Ydieresis: 0x0178,
  20992. Ydieresissmall: 0xF7FF,
  20993. Ydotaccent: 0x1E8E,
  20994. Ydotbelow: 0x1EF4,
  20995. Yericyrillic: 0x042B,
  20996. Yerudieresiscyrillic: 0x04F8,
  20997. Ygrave: 0x1EF2,
  20998. Yhook: 0x01B3,
  20999. Yhookabove: 0x1EF6,
  21000. Yiarmenian: 0x0545,
  21001. Yicyrillic: 0x0407,
  21002. Yiwnarmenian: 0x0552,
  21003. Ymonospace: 0xFF39,
  21004. Ysmall: 0xF779,
  21005. Ytilde: 0x1EF8,
  21006. Yusbigcyrillic: 0x046A,
  21007. Yusbigiotifiedcyrillic: 0x046C,
  21008. Yuslittlecyrillic: 0x0466,
  21009. Yuslittleiotifiedcyrillic: 0x0468,
  21010. Z: 0x005A,
  21011. Zaarmenian: 0x0536,
  21012. Zacute: 0x0179,
  21013. Zcaron: 0x017D,
  21014. Zcaronsmall: 0xF6FF,
  21015. Zcircle: 0x24CF,
  21016. Zcircumflex: 0x1E90,
  21017. Zdot: 0x017B,
  21018. Zdotaccent: 0x017B,
  21019. Zdotbelow: 0x1E92,
  21020. Zecyrillic: 0x0417,
  21021. Zedescendercyrillic: 0x0498,
  21022. Zedieresiscyrillic: 0x04DE,
  21023. Zeta: 0x0396,
  21024. Zhearmenian: 0x053A,
  21025. Zhebrevecyrillic: 0x04C1,
  21026. Zhecyrillic: 0x0416,
  21027. Zhedescendercyrillic: 0x0496,
  21028. Zhedieresiscyrillic: 0x04DC,
  21029. Zlinebelow: 0x1E94,
  21030. Zmonospace: 0xFF3A,
  21031. Zsmall: 0xF77A,
  21032. Zstroke: 0x01B5,
  21033. a: 0x0061,
  21034. aabengali: 0x0986,
  21035. aacute: 0x00E1,
  21036. aadeva: 0x0906,
  21037. aagujarati: 0x0A86,
  21038. aagurmukhi: 0x0A06,
  21039. aamatragurmukhi: 0x0A3E,
  21040. aarusquare: 0x3303,
  21041. aavowelsignbengali: 0x09BE,
  21042. aavowelsigndeva: 0x093E,
  21043. aavowelsigngujarati: 0x0ABE,
  21044. abbreviationmarkarmenian: 0x055F,
  21045. abbreviationsigndeva: 0x0970,
  21046. abengali: 0x0985,
  21047. abopomofo: 0x311A,
  21048. abreve: 0x0103,
  21049. abreveacute: 0x1EAF,
  21050. abrevecyrillic: 0x04D1,
  21051. abrevedotbelow: 0x1EB7,
  21052. abrevegrave: 0x1EB1,
  21053. abrevehookabove: 0x1EB3,
  21054. abrevetilde: 0x1EB5,
  21055. acaron: 0x01CE,
  21056. acircle: 0x24D0,
  21057. acircumflex: 0x00E2,
  21058. acircumflexacute: 0x1EA5,
  21059. acircumflexdotbelow: 0x1EAD,
  21060. acircumflexgrave: 0x1EA7,
  21061. acircumflexhookabove: 0x1EA9,
  21062. acircumflextilde: 0x1EAB,
  21063. acute: 0x00B4,
  21064. acutebelowcmb: 0x0317,
  21065. acutecmb: 0x0301,
  21066. acutecomb: 0x0301,
  21067. acutedeva: 0x0954,
  21068. acutelowmod: 0x02CF,
  21069. acutetonecmb: 0x0341,
  21070. acyrillic: 0x0430,
  21071. adblgrave: 0x0201,
  21072. addakgurmukhi: 0x0A71,
  21073. adeva: 0x0905,
  21074. adieresis: 0x00E4,
  21075. adieresiscyrillic: 0x04D3,
  21076. adieresismacron: 0x01DF,
  21077. adotbelow: 0x1EA1,
  21078. adotmacron: 0x01E1,
  21079. ae: 0x00E6,
  21080. aeacute: 0x01FD,
  21081. aekorean: 0x3150,
  21082. aemacron: 0x01E3,
  21083. afii00208: 0x2015,
  21084. afii08941: 0x20A4,
  21085. afii10017: 0x0410,
  21086. afii10018: 0x0411,
  21087. afii10019: 0x0412,
  21088. afii10020: 0x0413,
  21089. afii10021: 0x0414,
  21090. afii10022: 0x0415,
  21091. afii10023: 0x0401,
  21092. afii10024: 0x0416,
  21093. afii10025: 0x0417,
  21094. afii10026: 0x0418,
  21095. afii10027: 0x0419,
  21096. afii10028: 0x041A,
  21097. afii10029: 0x041B,
  21098. afii10030: 0x041C,
  21099. afii10031: 0x041D,
  21100. afii10032: 0x041E,
  21101. afii10033: 0x041F,
  21102. afii10034: 0x0420,
  21103. afii10035: 0x0421,
  21104. afii10036: 0x0422,
  21105. afii10037: 0x0423,
  21106. afii10038: 0x0424,
  21107. afii10039: 0x0425,
  21108. afii10040: 0x0426,
  21109. afii10041: 0x0427,
  21110. afii10042: 0x0428,
  21111. afii10043: 0x0429,
  21112. afii10044: 0x042A,
  21113. afii10045: 0x042B,
  21114. afii10046: 0x042C,
  21115. afii10047: 0x042D,
  21116. afii10048: 0x042E,
  21117. afii10049: 0x042F,
  21118. afii10050: 0x0490,
  21119. afii10051: 0x0402,
  21120. afii10052: 0x0403,
  21121. afii10053: 0x0404,
  21122. afii10054: 0x0405,
  21123. afii10055: 0x0406,
  21124. afii10056: 0x0407,
  21125. afii10057: 0x0408,
  21126. afii10058: 0x0409,
  21127. afii10059: 0x040A,
  21128. afii10060: 0x040B,
  21129. afii10061: 0x040C,
  21130. afii10062: 0x040E,
  21131. afii10063: 0xF6C4,
  21132. afii10064: 0xF6C5,
  21133. afii10065: 0x0430,
  21134. afii10066: 0x0431,
  21135. afii10067: 0x0432,
  21136. afii10068: 0x0433,
  21137. afii10069: 0x0434,
  21138. afii10070: 0x0435,
  21139. afii10071: 0x0451,
  21140. afii10072: 0x0436,
  21141. afii10073: 0x0437,
  21142. afii10074: 0x0438,
  21143. afii10075: 0x0439,
  21144. afii10076: 0x043A,
  21145. afii10077: 0x043B,
  21146. afii10078: 0x043C,
  21147. afii10079: 0x043D,
  21148. afii10080: 0x043E,
  21149. afii10081: 0x043F,
  21150. afii10082: 0x0440,
  21151. afii10083: 0x0441,
  21152. afii10084: 0x0442,
  21153. afii10085: 0x0443,
  21154. afii10086: 0x0444,
  21155. afii10087: 0x0445,
  21156. afii10088: 0x0446,
  21157. afii10089: 0x0447,
  21158. afii10090: 0x0448,
  21159. afii10091: 0x0449,
  21160. afii10092: 0x044A,
  21161. afii10093: 0x044B,
  21162. afii10094: 0x044C,
  21163. afii10095: 0x044D,
  21164. afii10096: 0x044E,
  21165. afii10097: 0x044F,
  21166. afii10098: 0x0491,
  21167. afii10099: 0x0452,
  21168. afii10100: 0x0453,
  21169. afii10101: 0x0454,
  21170. afii10102: 0x0455,
  21171. afii10103: 0x0456,
  21172. afii10104: 0x0457,
  21173. afii10105: 0x0458,
  21174. afii10106: 0x0459,
  21175. afii10107: 0x045A,
  21176. afii10108: 0x045B,
  21177. afii10109: 0x045C,
  21178. afii10110: 0x045E,
  21179. afii10145: 0x040F,
  21180. afii10146: 0x0462,
  21181. afii10147: 0x0472,
  21182. afii10148: 0x0474,
  21183. afii10192: 0xF6C6,
  21184. afii10193: 0x045F,
  21185. afii10194: 0x0463,
  21186. afii10195: 0x0473,
  21187. afii10196: 0x0475,
  21188. afii10831: 0xF6C7,
  21189. afii10832: 0xF6C8,
  21190. afii10846: 0x04D9,
  21191. afii299: 0x200E,
  21192. afii300: 0x200F,
  21193. afii301: 0x200D,
  21194. afii57381: 0x066A,
  21195. afii57388: 0x060C,
  21196. afii57392: 0x0660,
  21197. afii57393: 0x0661,
  21198. afii57394: 0x0662,
  21199. afii57395: 0x0663,
  21200. afii57396: 0x0664,
  21201. afii57397: 0x0665,
  21202. afii57398: 0x0666,
  21203. afii57399: 0x0667,
  21204. afii57400: 0x0668,
  21205. afii57401: 0x0669,
  21206. afii57403: 0x061B,
  21207. afii57407: 0x061F,
  21208. afii57409: 0x0621,
  21209. afii57410: 0x0622,
  21210. afii57411: 0x0623,
  21211. afii57412: 0x0624,
  21212. afii57413: 0x0625,
  21213. afii57414: 0x0626,
  21214. afii57415: 0x0627,
  21215. afii57416: 0x0628,
  21216. afii57417: 0x0629,
  21217. afii57418: 0x062A,
  21218. afii57419: 0x062B,
  21219. afii57420: 0x062C,
  21220. afii57421: 0x062D,
  21221. afii57422: 0x062E,
  21222. afii57423: 0x062F,
  21223. afii57424: 0x0630,
  21224. afii57425: 0x0631,
  21225. afii57426: 0x0632,
  21226. afii57427: 0x0633,
  21227. afii57428: 0x0634,
  21228. afii57429: 0x0635,
  21229. afii57430: 0x0636,
  21230. afii57431: 0x0637,
  21231. afii57432: 0x0638,
  21232. afii57433: 0x0639,
  21233. afii57434: 0x063A,
  21234. afii57440: 0x0640,
  21235. afii57441: 0x0641,
  21236. afii57442: 0x0642,
  21237. afii57443: 0x0643,
  21238. afii57444: 0x0644,
  21239. afii57445: 0x0645,
  21240. afii57446: 0x0646,
  21241. afii57448: 0x0648,
  21242. afii57449: 0x0649,
  21243. afii57450: 0x064A,
  21244. afii57451: 0x064B,
  21245. afii57452: 0x064C,
  21246. afii57453: 0x064D,
  21247. afii57454: 0x064E,
  21248. afii57455: 0x064F,
  21249. afii57456: 0x0650,
  21250. afii57457: 0x0651,
  21251. afii57458: 0x0652,
  21252. afii57470: 0x0647,
  21253. afii57505: 0x06A4,
  21254. afii57506: 0x067E,
  21255. afii57507: 0x0686,
  21256. afii57508: 0x0698,
  21257. afii57509: 0x06AF,
  21258. afii57511: 0x0679,
  21259. afii57512: 0x0688,
  21260. afii57513: 0x0691,
  21261. afii57514: 0x06BA,
  21262. afii57519: 0x06D2,
  21263. afii57534: 0x06D5,
  21264. afii57636: 0x20AA,
  21265. afii57645: 0x05BE,
  21266. afii57658: 0x05C3,
  21267. afii57664: 0x05D0,
  21268. afii57665: 0x05D1,
  21269. afii57666: 0x05D2,
  21270. afii57667: 0x05D3,
  21271. afii57668: 0x05D4,
  21272. afii57669: 0x05D5,
  21273. afii57670: 0x05D6,
  21274. afii57671: 0x05D7,
  21275. afii57672: 0x05D8,
  21276. afii57673: 0x05D9,
  21277. afii57674: 0x05DA,
  21278. afii57675: 0x05DB,
  21279. afii57676: 0x05DC,
  21280. afii57677: 0x05DD,
  21281. afii57678: 0x05DE,
  21282. afii57679: 0x05DF,
  21283. afii57680: 0x05E0,
  21284. afii57681: 0x05E1,
  21285. afii57682: 0x05E2,
  21286. afii57683: 0x05E3,
  21287. afii57684: 0x05E4,
  21288. afii57685: 0x05E5,
  21289. afii57686: 0x05E6,
  21290. afii57687: 0x05E7,
  21291. afii57688: 0x05E8,
  21292. afii57689: 0x05E9,
  21293. afii57690: 0x05EA,
  21294. afii57694: 0xFB2A,
  21295. afii57695: 0xFB2B,
  21296. afii57700: 0xFB4B,
  21297. afii57705: 0xFB1F,
  21298. afii57716: 0x05F0,
  21299. afii57717: 0x05F1,
  21300. afii57718: 0x05F2,
  21301. afii57723: 0xFB35,
  21302. afii57793: 0x05B4,
  21303. afii57794: 0x05B5,
  21304. afii57795: 0x05B6,
  21305. afii57796: 0x05BB,
  21306. afii57797: 0x05B8,
  21307. afii57798: 0x05B7,
  21308. afii57799: 0x05B0,
  21309. afii57800: 0x05B2,
  21310. afii57801: 0x05B1,
  21311. afii57802: 0x05B3,
  21312. afii57803: 0x05C2,
  21313. afii57804: 0x05C1,
  21314. afii57806: 0x05B9,
  21315. afii57807: 0x05BC,
  21316. afii57839: 0x05BD,
  21317. afii57841: 0x05BF,
  21318. afii57842: 0x05C0,
  21319. afii57929: 0x02BC,
  21320. afii61248: 0x2105,
  21321. afii61289: 0x2113,
  21322. afii61352: 0x2116,
  21323. afii61573: 0x202C,
  21324. afii61574: 0x202D,
  21325. afii61575: 0x202E,
  21326. afii61664: 0x200C,
  21327. afii63167: 0x066D,
  21328. afii64937: 0x02BD,
  21329. agrave: 0x00E0,
  21330. agujarati: 0x0A85,
  21331. agurmukhi: 0x0A05,
  21332. ahiragana: 0x3042,
  21333. ahookabove: 0x1EA3,
  21334. aibengali: 0x0990,
  21335. aibopomofo: 0x311E,
  21336. aideva: 0x0910,
  21337. aiecyrillic: 0x04D5,
  21338. aigujarati: 0x0A90,
  21339. aigurmukhi: 0x0A10,
  21340. aimatragurmukhi: 0x0A48,
  21341. ainarabic: 0x0639,
  21342. ainfinalarabic: 0xFECA,
  21343. aininitialarabic: 0xFECB,
  21344. ainmedialarabic: 0xFECC,
  21345. ainvertedbreve: 0x0203,
  21346. aivowelsignbengali: 0x09C8,
  21347. aivowelsigndeva: 0x0948,
  21348. aivowelsigngujarati: 0x0AC8,
  21349. akatakana: 0x30A2,
  21350. akatakanahalfwidth: 0xFF71,
  21351. akorean: 0x314F,
  21352. alef: 0x05D0,
  21353. alefarabic: 0x0627,
  21354. alefdageshhebrew: 0xFB30,
  21355. aleffinalarabic: 0xFE8E,
  21356. alefhamzaabovearabic: 0x0623,
  21357. alefhamzaabovefinalarabic: 0xFE84,
  21358. alefhamzabelowarabic: 0x0625,
  21359. alefhamzabelowfinalarabic: 0xFE88,
  21360. alefhebrew: 0x05D0,
  21361. aleflamedhebrew: 0xFB4F,
  21362. alefmaddaabovearabic: 0x0622,
  21363. alefmaddaabovefinalarabic: 0xFE82,
  21364. alefmaksuraarabic: 0x0649,
  21365. alefmaksurafinalarabic: 0xFEF0,
  21366. alefmaksurainitialarabic: 0xFEF3,
  21367. alefmaksuramedialarabic: 0xFEF4,
  21368. alefpatahhebrew: 0xFB2E,
  21369. alefqamatshebrew: 0xFB2F,
  21370. aleph: 0x2135,
  21371. allequal: 0x224C,
  21372. alpha: 0x03B1,
  21373. alphatonos: 0x03AC,
  21374. amacron: 0x0101,
  21375. amonospace: 0xFF41,
  21376. ampersand: 0x0026,
  21377. ampersandmonospace: 0xFF06,
  21378. ampersandsmall: 0xF726,
  21379. amsquare: 0x33C2,
  21380. anbopomofo: 0x3122,
  21381. angbopomofo: 0x3124,
  21382. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21383. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21384. angkhankhuthai: 0x0E5A,
  21385. angle: 0x2220,
  21386. anglebracketleft: 0x3008,
  21387. anglebracketleftvertical: 0xFE3F,
  21388. anglebracketright: 0x3009,
  21389. anglebracketrightvertical: 0xFE40,
  21390. angleleft: 0x2329,
  21391. angleright: 0x232A,
  21392. angstrom: 0x212B,
  21393. anoteleia: 0x0387,
  21394. anudattadeva: 0x0952,
  21395. anusvarabengali: 0x0982,
  21396. anusvaradeva: 0x0902,
  21397. anusvaragujarati: 0x0A82,
  21398. aogonek: 0x0105,
  21399. apaatosquare: 0x3300,
  21400. aparen: 0x249C,
  21401. apostrophearmenian: 0x055A,
  21402. apostrophemod: 0x02BC,
  21403. apple: 0xF8FF,
  21404. approaches: 0x2250,
  21405. approxequal: 0x2248,
  21406. approxequalorimage: 0x2252,
  21407. approximatelyequal: 0x2245,
  21408. araeaekorean: 0x318E,
  21409. araeakorean: 0x318D,
  21410. arc: 0x2312,
  21411. arighthalfring: 0x1E9A,
  21412. aring: 0x00E5,
  21413. aringacute: 0x01FB,
  21414. aringbelow: 0x1E01,
  21415. arrowboth: 0x2194,
  21416. arrowdashdown: 0x21E3,
  21417. arrowdashleft: 0x21E0,
  21418. arrowdashright: 0x21E2,
  21419. arrowdashup: 0x21E1,
  21420. arrowdblboth: 0x21D4,
  21421. arrowdbldown: 0x21D3,
  21422. arrowdblleft: 0x21D0,
  21423. arrowdblright: 0x21D2,
  21424. arrowdblup: 0x21D1,
  21425. arrowdown: 0x2193,
  21426. arrowdownleft: 0x2199,
  21427. arrowdownright: 0x2198,
  21428. arrowdownwhite: 0x21E9,
  21429. arrowheaddownmod: 0x02C5,
  21430. arrowheadleftmod: 0x02C2,
  21431. arrowheadrightmod: 0x02C3,
  21432. arrowheadupmod: 0x02C4,
  21433. arrowhorizex: 0xF8E7,
  21434. arrowleft: 0x2190,
  21435. arrowleftdbl: 0x21D0,
  21436. arrowleftdblstroke: 0x21CD,
  21437. arrowleftoverright: 0x21C6,
  21438. arrowleftwhite: 0x21E6,
  21439. arrowright: 0x2192,
  21440. arrowrightdblstroke: 0x21CF,
  21441. arrowrightheavy: 0x279E,
  21442. arrowrightoverleft: 0x21C4,
  21443. arrowrightwhite: 0x21E8,
  21444. arrowtableft: 0x21E4,
  21445. arrowtabright: 0x21E5,
  21446. arrowup: 0x2191,
  21447. arrowupdn: 0x2195,
  21448. arrowupdnbse: 0x21A8,
  21449. arrowupdownbase: 0x21A8,
  21450. arrowupleft: 0x2196,
  21451. arrowupleftofdown: 0x21C5,
  21452. arrowupright: 0x2197,
  21453. arrowupwhite: 0x21E7,
  21454. arrowvertex: 0xF8E6,
  21455. asciicircum: 0x005E,
  21456. asciicircummonospace: 0xFF3E,
  21457. asciitilde: 0x007E,
  21458. asciitildemonospace: 0xFF5E,
  21459. ascript: 0x0251,
  21460. ascriptturned: 0x0252,
  21461. asmallhiragana: 0x3041,
  21462. asmallkatakana: 0x30A1,
  21463. asmallkatakanahalfwidth: 0xFF67,
  21464. asterisk: 0x002A,
  21465. asteriskaltonearabic: 0x066D,
  21466. asteriskarabic: 0x066D,
  21467. asteriskmath: 0x2217,
  21468. asteriskmonospace: 0xFF0A,
  21469. asterisksmall: 0xFE61,
  21470. asterism: 0x2042,
  21471. asuperior: 0xF6E9,
  21472. asymptoticallyequal: 0x2243,
  21473. at: 0x0040,
  21474. atilde: 0x00E3,
  21475. atmonospace: 0xFF20,
  21476. atsmall: 0xFE6B,
  21477. aturned: 0x0250,
  21478. aubengali: 0x0994,
  21479. aubopomofo: 0x3120,
  21480. audeva: 0x0914,
  21481. augujarati: 0x0A94,
  21482. augurmukhi: 0x0A14,
  21483. aulengthmarkbengali: 0x09D7,
  21484. aumatragurmukhi: 0x0A4C,
  21485. auvowelsignbengali: 0x09CC,
  21486. auvowelsigndeva: 0x094C,
  21487. auvowelsigngujarati: 0x0ACC,
  21488. avagrahadeva: 0x093D,
  21489. aybarmenian: 0x0561,
  21490. ayin: 0x05E2,
  21491. ayinaltonehebrew: 0xFB20,
  21492. ayinhebrew: 0x05E2,
  21493. b: 0x0062,
  21494. babengali: 0x09AC,
  21495. backslash: 0x005C,
  21496. backslashmonospace: 0xFF3C,
  21497. badeva: 0x092C,
  21498. bagujarati: 0x0AAC,
  21499. bagurmukhi: 0x0A2C,
  21500. bahiragana: 0x3070,
  21501. bahtthai: 0x0E3F,
  21502. bakatakana: 0x30D0,
  21503. bar: 0x007C,
  21504. barmonospace: 0xFF5C,
  21505. bbopomofo: 0x3105,
  21506. bcircle: 0x24D1,
  21507. bdotaccent: 0x1E03,
  21508. bdotbelow: 0x1E05,
  21509. beamedsixteenthnotes: 0x266C,
  21510. because: 0x2235,
  21511. becyrillic: 0x0431,
  21512. beharabic: 0x0628,
  21513. behfinalarabic: 0xFE90,
  21514. behinitialarabic: 0xFE91,
  21515. behiragana: 0x3079,
  21516. behmedialarabic: 0xFE92,
  21517. behmeeminitialarabic: 0xFC9F,
  21518. behmeemisolatedarabic: 0xFC08,
  21519. behnoonfinalarabic: 0xFC6D,
  21520. bekatakana: 0x30D9,
  21521. benarmenian: 0x0562,
  21522. bet: 0x05D1,
  21523. beta: 0x03B2,
  21524. betasymbolgreek: 0x03D0,
  21525. betdagesh: 0xFB31,
  21526. betdageshhebrew: 0xFB31,
  21527. bethebrew: 0x05D1,
  21528. betrafehebrew: 0xFB4C,
  21529. bhabengali: 0x09AD,
  21530. bhadeva: 0x092D,
  21531. bhagujarati: 0x0AAD,
  21532. bhagurmukhi: 0x0A2D,
  21533. bhook: 0x0253,
  21534. bihiragana: 0x3073,
  21535. bikatakana: 0x30D3,
  21536. bilabialclick: 0x0298,
  21537. bindigurmukhi: 0x0A02,
  21538. birusquare: 0x3331,
  21539. blackcircle: 0x25CF,
  21540. blackdiamond: 0x25C6,
  21541. blackdownpointingtriangle: 0x25BC,
  21542. blackleftpointingpointer: 0x25C4,
  21543. blackleftpointingtriangle: 0x25C0,
  21544. blacklenticularbracketleft: 0x3010,
  21545. blacklenticularbracketleftvertical: 0xFE3B,
  21546. blacklenticularbracketright: 0x3011,
  21547. blacklenticularbracketrightvertical: 0xFE3C,
  21548. blacklowerlefttriangle: 0x25E3,
  21549. blacklowerrighttriangle: 0x25E2,
  21550. blackrectangle: 0x25AC,
  21551. blackrightpointingpointer: 0x25BA,
  21552. blackrightpointingtriangle: 0x25B6,
  21553. blacksmallsquare: 0x25AA,
  21554. blacksmilingface: 0x263B,
  21555. blacksquare: 0x25A0,
  21556. blackstar: 0x2605,
  21557. blackupperlefttriangle: 0x25E4,
  21558. blackupperrighttriangle: 0x25E5,
  21559. blackuppointingsmalltriangle: 0x25B4,
  21560. blackuppointingtriangle: 0x25B2,
  21561. blank: 0x2423,
  21562. blinebelow: 0x1E07,
  21563. block: 0x2588,
  21564. bmonospace: 0xFF42,
  21565. bobaimaithai: 0x0E1A,
  21566. bohiragana: 0x307C,
  21567. bokatakana: 0x30DC,
  21568. bparen: 0x249D,
  21569. bqsquare: 0x33C3,
  21570. braceex: 0xF8F4,
  21571. braceleft: 0x007B,
  21572. braceleftbt: 0xF8F3,
  21573. braceleftmid: 0xF8F2,
  21574. braceleftmonospace: 0xFF5B,
  21575. braceleftsmall: 0xFE5B,
  21576. bracelefttp: 0xF8F1,
  21577. braceleftvertical: 0xFE37,
  21578. braceright: 0x007D,
  21579. bracerightbt: 0xF8FE,
  21580. bracerightmid: 0xF8FD,
  21581. bracerightmonospace: 0xFF5D,
  21582. bracerightsmall: 0xFE5C,
  21583. bracerighttp: 0xF8FC,
  21584. bracerightvertical: 0xFE38,
  21585. bracketleft: 0x005B,
  21586. bracketleftbt: 0xF8F0,
  21587. bracketleftex: 0xF8EF,
  21588. bracketleftmonospace: 0xFF3B,
  21589. bracketlefttp: 0xF8EE,
  21590. bracketright: 0x005D,
  21591. bracketrightbt: 0xF8FB,
  21592. bracketrightex: 0xF8FA,
  21593. bracketrightmonospace: 0xFF3D,
  21594. bracketrighttp: 0xF8F9,
  21595. breve: 0x02D8,
  21596. brevebelowcmb: 0x032E,
  21597. brevecmb: 0x0306,
  21598. breveinvertedbelowcmb: 0x032F,
  21599. breveinvertedcmb: 0x0311,
  21600. breveinverteddoublecmb: 0x0361,
  21601. bridgebelowcmb: 0x032A,
  21602. bridgeinvertedbelowcmb: 0x033A,
  21603. brokenbar: 0x00A6,
  21604. bstroke: 0x0180,
  21605. bsuperior: 0xF6EA,
  21606. btopbar: 0x0183,
  21607. buhiragana: 0x3076,
  21608. bukatakana: 0x30D6,
  21609. bullet: 0x2022,
  21610. bulletinverse: 0x25D8,
  21611. bulletoperator: 0x2219,
  21612. bullseye: 0x25CE,
  21613. c: 0x0063,
  21614. caarmenian: 0x056E,
  21615. cabengali: 0x099A,
  21616. cacute: 0x0107,
  21617. cadeva: 0x091A,
  21618. cagujarati: 0x0A9A,
  21619. cagurmukhi: 0x0A1A,
  21620. calsquare: 0x3388,
  21621. candrabindubengali: 0x0981,
  21622. candrabinducmb: 0x0310,
  21623. candrabindudeva: 0x0901,
  21624. candrabindugujarati: 0x0A81,
  21625. capslock: 0x21EA,
  21626. careof: 0x2105,
  21627. caron: 0x02C7,
  21628. caronbelowcmb: 0x032C,
  21629. caroncmb: 0x030C,
  21630. carriagereturn: 0x21B5,
  21631. cbopomofo: 0x3118,
  21632. ccaron: 0x010D,
  21633. ccedilla: 0x00E7,
  21634. ccedillaacute: 0x1E09,
  21635. ccircle: 0x24D2,
  21636. ccircumflex: 0x0109,
  21637. ccurl: 0x0255,
  21638. cdot: 0x010B,
  21639. cdotaccent: 0x010B,
  21640. cdsquare: 0x33C5,
  21641. cedilla: 0x00B8,
  21642. cedillacmb: 0x0327,
  21643. cent: 0x00A2,
  21644. centigrade: 0x2103,
  21645. centinferior: 0xF6DF,
  21646. centmonospace: 0xFFE0,
  21647. centoldstyle: 0xF7A2,
  21648. centsuperior: 0xF6E0,
  21649. chaarmenian: 0x0579,
  21650. chabengali: 0x099B,
  21651. chadeva: 0x091B,
  21652. chagujarati: 0x0A9B,
  21653. chagurmukhi: 0x0A1B,
  21654. chbopomofo: 0x3114,
  21655. cheabkhasiancyrillic: 0x04BD,
  21656. checkmark: 0x2713,
  21657. checyrillic: 0x0447,
  21658. chedescenderabkhasiancyrillic: 0x04BF,
  21659. chedescendercyrillic: 0x04B7,
  21660. chedieresiscyrillic: 0x04F5,
  21661. cheharmenian: 0x0573,
  21662. chekhakassiancyrillic: 0x04CC,
  21663. cheverticalstrokecyrillic: 0x04B9,
  21664. chi: 0x03C7,
  21665. chieuchacirclekorean: 0x3277,
  21666. chieuchaparenkorean: 0x3217,
  21667. chieuchcirclekorean: 0x3269,
  21668. chieuchkorean: 0x314A,
  21669. chieuchparenkorean: 0x3209,
  21670. chochangthai: 0x0E0A,
  21671. chochanthai: 0x0E08,
  21672. chochingthai: 0x0E09,
  21673. chochoethai: 0x0E0C,
  21674. chook: 0x0188,
  21675. cieucacirclekorean: 0x3276,
  21676. cieucaparenkorean: 0x3216,
  21677. cieuccirclekorean: 0x3268,
  21678. cieuckorean: 0x3148,
  21679. cieucparenkorean: 0x3208,
  21680. cieucuparenkorean: 0x321C,
  21681. circle: 0x25CB,
  21682. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  21683. circlemultiply: 0x2297,
  21684. circleot: 0x2299,
  21685. circleplus: 0x2295,
  21686. circlepostalmark: 0x3036,
  21687. circlewithlefthalfblack: 0x25D0,
  21688. circlewithrighthalfblack: 0x25D1,
  21689. circumflex: 0x02C6,
  21690. circumflexbelowcmb: 0x032D,
  21691. circumflexcmb: 0x0302,
  21692. clear: 0x2327,
  21693. clickalveolar: 0x01C2,
  21694. clickdental: 0x01C0,
  21695. clicklateral: 0x01C1,
  21696. clickretroflex: 0x01C3,
  21697. club: 0x2663,
  21698. clubsuitblack: 0x2663,
  21699. clubsuitwhite: 0x2667,
  21700. cmcubedsquare: 0x33A4,
  21701. cmonospace: 0xFF43,
  21702. cmsquaredsquare: 0x33A0,
  21703. coarmenian: 0x0581,
  21704. colon: 0x003A,
  21705. colonmonetary: 0x20A1,
  21706. colonmonospace: 0xFF1A,
  21707. colonsign: 0x20A1,
  21708. colonsmall: 0xFE55,
  21709. colontriangularhalfmod: 0x02D1,
  21710. colontriangularmod: 0x02D0,
  21711. comma: 0x002C,
  21712. commaabovecmb: 0x0313,
  21713. commaaboverightcmb: 0x0315,
  21714. commaaccent: 0xF6C3,
  21715. commaarabic: 0x060C,
  21716. commaarmenian: 0x055D,
  21717. commainferior: 0xF6E1,
  21718. commamonospace: 0xFF0C,
  21719. commareversedabovecmb: 0x0314,
  21720. commareversedmod: 0x02BD,
  21721. commasmall: 0xFE50,
  21722. commasuperior: 0xF6E2,
  21723. commaturnedabovecmb: 0x0312,
  21724. commaturnedmod: 0x02BB,
  21725. compass: 0x263C,
  21726. congruent: 0x2245,
  21727. contourintegral: 0x222E,
  21728. control: 0x2303,
  21729. controlACK: 0x0006,
  21730. controlBEL: 0x0007,
  21731. controlBS: 0x0008,
  21732. controlCAN: 0x0018,
  21733. controlCR: 0x000D,
  21734. controlDC1: 0x0011,
  21735. controlDC2: 0x0012,
  21736. controlDC3: 0x0013,
  21737. controlDC4: 0x0014,
  21738. controlDEL: 0x007F,
  21739. controlDLE: 0x0010,
  21740. controlEM: 0x0019,
  21741. controlENQ: 0x0005,
  21742. controlEOT: 0x0004,
  21743. controlESC: 0x001B,
  21744. controlETB: 0x0017,
  21745. controlETX: 0x0003,
  21746. controlFF: 0x000C,
  21747. controlFS: 0x001C,
  21748. controlGS: 0x001D,
  21749. controlHT: 0x0009,
  21750. controlLF: 0x000A,
  21751. controlNAK: 0x0015,
  21752. controlRS: 0x001E,
  21753. controlSI: 0x000F,
  21754. controlSO: 0x000E,
  21755. controlSOT: 0x0002,
  21756. controlSTX: 0x0001,
  21757. controlSUB: 0x001A,
  21758. controlSYN: 0x0016,
  21759. controlUS: 0x001F,
  21760. controlVT: 0x000B,
  21761. copyright: 0x00A9,
  21762. copyrightsans: 0xF8E9,
  21763. copyrightserif: 0xF6D9,
  21764. cornerbracketleft: 0x300C,
  21765. cornerbracketlefthalfwidth: 0xFF62,
  21766. cornerbracketleftvertical: 0xFE41,
  21767. cornerbracketright: 0x300D,
  21768. cornerbracketrighthalfwidth: 0xFF63,
  21769. cornerbracketrightvertical: 0xFE42,
  21770. corporationsquare: 0x337F,
  21771. cosquare: 0x33C7,
  21772. coverkgsquare: 0x33C6,
  21773. cparen: 0x249E,
  21774. cruzeiro: 0x20A2,
  21775. cstretched: 0x0297,
  21776. curlyand: 0x22CF,
  21777. curlyor: 0x22CE,
  21778. currency: 0x00A4,
  21779. cyrBreve: 0xF6D1,
  21780. cyrFlex: 0xF6D2,
  21781. cyrbreve: 0xF6D4,
  21782. cyrflex: 0xF6D5,
  21783. d: 0x0064,
  21784. daarmenian: 0x0564,
  21785. dabengali: 0x09A6,
  21786. dadarabic: 0x0636,
  21787. dadeva: 0x0926,
  21788. dadfinalarabic: 0xFEBE,
  21789. dadinitialarabic: 0xFEBF,
  21790. dadmedialarabic: 0xFEC0,
  21791. dagesh: 0x05BC,
  21792. dageshhebrew: 0x05BC,
  21793. dagger: 0x2020,
  21794. daggerdbl: 0x2021,
  21795. dagujarati: 0x0AA6,
  21796. dagurmukhi: 0x0A26,
  21797. dahiragana: 0x3060,
  21798. dakatakana: 0x30C0,
  21799. dalarabic: 0x062F,
  21800. dalet: 0x05D3,
  21801. daletdagesh: 0xFB33,
  21802. daletdageshhebrew: 0xFB33,
  21803. dalethebrew: 0x05D3,
  21804. dalfinalarabic: 0xFEAA,
  21805. dammaarabic: 0x064F,
  21806. dammalowarabic: 0x064F,
  21807. dammatanaltonearabic: 0x064C,
  21808. dammatanarabic: 0x064C,
  21809. danda: 0x0964,
  21810. dargahebrew: 0x05A7,
  21811. dargalefthebrew: 0x05A7,
  21812. dasiapneumatacyrilliccmb: 0x0485,
  21813. dblGrave: 0xF6D3,
  21814. dblanglebracketleft: 0x300A,
  21815. dblanglebracketleftvertical: 0xFE3D,
  21816. dblanglebracketright: 0x300B,
  21817. dblanglebracketrightvertical: 0xFE3E,
  21818. dblarchinvertedbelowcmb: 0x032B,
  21819. dblarrowleft: 0x21D4,
  21820. dblarrowright: 0x21D2,
  21821. dbldanda: 0x0965,
  21822. dblgrave: 0xF6D6,
  21823. dblgravecmb: 0x030F,
  21824. dblintegral: 0x222C,
  21825. dbllowline: 0x2017,
  21826. dbllowlinecmb: 0x0333,
  21827. dbloverlinecmb: 0x033F,
  21828. dblprimemod: 0x02BA,
  21829. dblverticalbar: 0x2016,
  21830. dblverticallineabovecmb: 0x030E,
  21831. dbopomofo: 0x3109,
  21832. dbsquare: 0x33C8,
  21833. dcaron: 0x010F,
  21834. dcedilla: 0x1E11,
  21835. dcircle: 0x24D3,
  21836. dcircumflexbelow: 0x1E13,
  21837. dcroat: 0x0111,
  21838. ddabengali: 0x09A1,
  21839. ddadeva: 0x0921,
  21840. ddagujarati: 0x0AA1,
  21841. ddagurmukhi: 0x0A21,
  21842. ddalarabic: 0x0688,
  21843. ddalfinalarabic: 0xFB89,
  21844. dddhadeva: 0x095C,
  21845. ddhabengali: 0x09A2,
  21846. ddhadeva: 0x0922,
  21847. ddhagujarati: 0x0AA2,
  21848. ddhagurmukhi: 0x0A22,
  21849. ddotaccent: 0x1E0B,
  21850. ddotbelow: 0x1E0D,
  21851. decimalseparatorarabic: 0x066B,
  21852. decimalseparatorpersian: 0x066B,
  21853. decyrillic: 0x0434,
  21854. degree: 0x00B0,
  21855. dehihebrew: 0x05AD,
  21856. dehiragana: 0x3067,
  21857. deicoptic: 0x03EF,
  21858. dekatakana: 0x30C7,
  21859. deleteleft: 0x232B,
  21860. deleteright: 0x2326,
  21861. delta: 0x03B4,
  21862. deltaturned: 0x018D,
  21863. denominatorminusonenumeratorbengali: 0x09F8,
  21864. dezh: 0x02A4,
  21865. dhabengali: 0x09A7,
  21866. dhadeva: 0x0927,
  21867. dhagujarati: 0x0AA7,
  21868. dhagurmukhi: 0x0A27,
  21869. dhook: 0x0257,
  21870. dialytikatonos: 0x0385,
  21871. dialytikatonoscmb: 0x0344,
  21872. diamond: 0x2666,
  21873. diamondsuitwhite: 0x2662,
  21874. dieresis: 0x00A8,
  21875. dieresisacute: 0xF6D7,
  21876. dieresisbelowcmb: 0x0324,
  21877. dieresiscmb: 0x0308,
  21878. dieresisgrave: 0xF6D8,
  21879. dieresistonos: 0x0385,
  21880. dihiragana: 0x3062,
  21881. dikatakana: 0x30C2,
  21882. dittomark: 0x3003,
  21883. divide: 0x00F7,
  21884. divides: 0x2223,
  21885. divisionslash: 0x2215,
  21886. djecyrillic: 0x0452,
  21887. dkshade: 0x2593,
  21888. dlinebelow: 0x1E0F,
  21889. dlsquare: 0x3397,
  21890. dmacron: 0x0111,
  21891. dmonospace: 0xFF44,
  21892. dnblock: 0x2584,
  21893. dochadathai: 0x0E0E,
  21894. dodekthai: 0x0E14,
  21895. dohiragana: 0x3069,
  21896. dokatakana: 0x30C9,
  21897. dollar: 0x0024,
  21898. dollarinferior: 0xF6E3,
  21899. dollarmonospace: 0xFF04,
  21900. dollaroldstyle: 0xF724,
  21901. dollarsmall: 0xFE69,
  21902. dollarsuperior: 0xF6E4,
  21903. dong: 0x20AB,
  21904. dorusquare: 0x3326,
  21905. dotaccent: 0x02D9,
  21906. dotaccentcmb: 0x0307,
  21907. dotbelowcmb: 0x0323,
  21908. dotbelowcomb: 0x0323,
  21909. dotkatakana: 0x30FB,
  21910. dotlessi: 0x0131,
  21911. dotlessj: 0xF6BE,
  21912. dotlessjstrokehook: 0x0284,
  21913. dotmath: 0x22C5,
  21914. dottedcircle: 0x25CC,
  21915. doubleyodpatah: 0xFB1F,
  21916. doubleyodpatahhebrew: 0xFB1F,
  21917. downtackbelowcmb: 0x031E,
  21918. downtackmod: 0x02D5,
  21919. dparen: 0x249F,
  21920. dsuperior: 0xF6EB,
  21921. dtail: 0x0256,
  21922. dtopbar: 0x018C,
  21923. duhiragana: 0x3065,
  21924. dukatakana: 0x30C5,
  21925. dz: 0x01F3,
  21926. dzaltone: 0x02A3,
  21927. dzcaron: 0x01C6,
  21928. dzcurl: 0x02A5,
  21929. dzeabkhasiancyrillic: 0x04E1,
  21930. dzecyrillic: 0x0455,
  21931. dzhecyrillic: 0x045F,
  21932. e: 0x0065,
  21933. eacute: 0x00E9,
  21934. earth: 0x2641,
  21935. ebengali: 0x098F,
  21936. ebopomofo: 0x311C,
  21937. ebreve: 0x0115,
  21938. ecandradeva: 0x090D,
  21939. ecandragujarati: 0x0A8D,
  21940. ecandravowelsigndeva: 0x0945,
  21941. ecandravowelsigngujarati: 0x0AC5,
  21942. ecaron: 0x011B,
  21943. ecedillabreve: 0x1E1D,
  21944. echarmenian: 0x0565,
  21945. echyiwnarmenian: 0x0587,
  21946. ecircle: 0x24D4,
  21947. ecircumflex: 0x00EA,
  21948. ecircumflexacute: 0x1EBF,
  21949. ecircumflexbelow: 0x1E19,
  21950. ecircumflexdotbelow: 0x1EC7,
  21951. ecircumflexgrave: 0x1EC1,
  21952. ecircumflexhookabove: 0x1EC3,
  21953. ecircumflextilde: 0x1EC5,
  21954. ecyrillic: 0x0454,
  21955. edblgrave: 0x0205,
  21956. edeva: 0x090F,
  21957. edieresis: 0x00EB,
  21958. edot: 0x0117,
  21959. edotaccent: 0x0117,
  21960. edotbelow: 0x1EB9,
  21961. eegurmukhi: 0x0A0F,
  21962. eematragurmukhi: 0x0A47,
  21963. efcyrillic: 0x0444,
  21964. egrave: 0x00E8,
  21965. egujarati: 0x0A8F,
  21966. eharmenian: 0x0567,
  21967. ehbopomofo: 0x311D,
  21968. ehiragana: 0x3048,
  21969. ehookabove: 0x1EBB,
  21970. eibopomofo: 0x311F,
  21971. eight: 0x0038,
  21972. eightarabic: 0x0668,
  21973. eightbengali: 0x09EE,
  21974. eightcircle: 0x2467,
  21975. eightcircleinversesansserif: 0x2791,
  21976. eightdeva: 0x096E,
  21977. eighteencircle: 0x2471,
  21978. eighteenparen: 0x2485,
  21979. eighteenperiod: 0x2499,
  21980. eightgujarati: 0x0AEE,
  21981. eightgurmukhi: 0x0A6E,
  21982. eighthackarabic: 0x0668,
  21983. eighthangzhou: 0x3028,
  21984. eighthnotebeamed: 0x266B,
  21985. eightideographicparen: 0x3227,
  21986. eightinferior: 0x2088,
  21987. eightmonospace: 0xFF18,
  21988. eightoldstyle: 0xF738,
  21989. eightparen: 0x247B,
  21990. eightperiod: 0x248F,
  21991. eightpersian: 0x06F8,
  21992. eightroman: 0x2177,
  21993. eightsuperior: 0x2078,
  21994. eightthai: 0x0E58,
  21995. einvertedbreve: 0x0207,
  21996. eiotifiedcyrillic: 0x0465,
  21997. ekatakana: 0x30A8,
  21998. ekatakanahalfwidth: 0xFF74,
  21999. ekonkargurmukhi: 0x0A74,
  22000. ekorean: 0x3154,
  22001. elcyrillic: 0x043B,
  22002. element: 0x2208,
  22003. elevencircle: 0x246A,
  22004. elevenparen: 0x247E,
  22005. elevenperiod: 0x2492,
  22006. elevenroman: 0x217A,
  22007. ellipsis: 0x2026,
  22008. ellipsisvertical: 0x22EE,
  22009. emacron: 0x0113,
  22010. emacronacute: 0x1E17,
  22011. emacrongrave: 0x1E15,
  22012. emcyrillic: 0x043C,
  22013. emdash: 0x2014,
  22014. emdashvertical: 0xFE31,
  22015. emonospace: 0xFF45,
  22016. emphasismarkarmenian: 0x055B,
  22017. emptyset: 0x2205,
  22018. enbopomofo: 0x3123,
  22019. encyrillic: 0x043D,
  22020. endash: 0x2013,
  22021. endashvertical: 0xFE32,
  22022. endescendercyrillic: 0x04A3,
  22023. eng: 0x014B,
  22024. engbopomofo: 0x3125,
  22025. enghecyrillic: 0x04A5,
  22026. enhookcyrillic: 0x04C8,
  22027. enspace: 0x2002,
  22028. eogonek: 0x0119,
  22029. eokorean: 0x3153,
  22030. eopen: 0x025B,
  22031. eopenclosed: 0x029A,
  22032. eopenreversed: 0x025C,
  22033. eopenreversedclosed: 0x025E,
  22034. eopenreversedhook: 0x025D,
  22035. eparen: 0x24A0,
  22036. epsilon: 0x03B5,
  22037. epsilontonos: 0x03AD,
  22038. equal: 0x003D,
  22039. equalmonospace: 0xFF1D,
  22040. equalsmall: 0xFE66,
  22041. equalsuperior: 0x207C,
  22042. equivalence: 0x2261,
  22043. erbopomofo: 0x3126,
  22044. ercyrillic: 0x0440,
  22045. ereversed: 0x0258,
  22046. ereversedcyrillic: 0x044D,
  22047. escyrillic: 0x0441,
  22048. esdescendercyrillic: 0x04AB,
  22049. esh: 0x0283,
  22050. eshcurl: 0x0286,
  22051. eshortdeva: 0x090E,
  22052. eshortvowelsigndeva: 0x0946,
  22053. eshreversedloop: 0x01AA,
  22054. eshsquatreversed: 0x0285,
  22055. esmallhiragana: 0x3047,
  22056. esmallkatakana: 0x30A7,
  22057. esmallkatakanahalfwidth: 0xFF6A,
  22058. estimated: 0x212E,
  22059. esuperior: 0xF6EC,
  22060. eta: 0x03B7,
  22061. etarmenian: 0x0568,
  22062. etatonos: 0x03AE,
  22063. eth: 0x00F0,
  22064. etilde: 0x1EBD,
  22065. etildebelow: 0x1E1B,
  22066. etnahtafoukhhebrew: 0x0591,
  22067. etnahtafoukhlefthebrew: 0x0591,
  22068. etnahtahebrew: 0x0591,
  22069. etnahtalefthebrew: 0x0591,
  22070. eturned: 0x01DD,
  22071. eukorean: 0x3161,
  22072. euro: 0x20AC,
  22073. evowelsignbengali: 0x09C7,
  22074. evowelsigndeva: 0x0947,
  22075. evowelsigngujarati: 0x0AC7,
  22076. exclam: 0x0021,
  22077. exclamarmenian: 0x055C,
  22078. exclamdbl: 0x203C,
  22079. exclamdown: 0x00A1,
  22080. exclamdownsmall: 0xF7A1,
  22081. exclammonospace: 0xFF01,
  22082. exclamsmall: 0xF721,
  22083. existential: 0x2203,
  22084. ezh: 0x0292,
  22085. ezhcaron: 0x01EF,
  22086. ezhcurl: 0x0293,
  22087. ezhreversed: 0x01B9,
  22088. ezhtail: 0x01BA,
  22089. f: 0x0066,
  22090. fadeva: 0x095E,
  22091. fagurmukhi: 0x0A5E,
  22092. fahrenheit: 0x2109,
  22093. fathaarabic: 0x064E,
  22094. fathalowarabic: 0x064E,
  22095. fathatanarabic: 0x064B,
  22096. fbopomofo: 0x3108,
  22097. fcircle: 0x24D5,
  22098. fdotaccent: 0x1E1F,
  22099. feharabic: 0x0641,
  22100. feharmenian: 0x0586,
  22101. fehfinalarabic: 0xFED2,
  22102. fehinitialarabic: 0xFED3,
  22103. fehmedialarabic: 0xFED4,
  22104. feicoptic: 0x03E5,
  22105. female: 0x2640,
  22106. ff: 0xFB00,
  22107. ffi: 0xFB03,
  22108. ffl: 0xFB04,
  22109. fi: 0xFB01,
  22110. fifteencircle: 0x246E,
  22111. fifteenparen: 0x2482,
  22112. fifteenperiod: 0x2496,
  22113. figuredash: 0x2012,
  22114. filledbox: 0x25A0,
  22115. filledrect: 0x25AC,
  22116. finalkaf: 0x05DA,
  22117. finalkafdagesh: 0xFB3A,
  22118. finalkafdageshhebrew: 0xFB3A,
  22119. finalkafhebrew: 0x05DA,
  22120. finalmem: 0x05DD,
  22121. finalmemhebrew: 0x05DD,
  22122. finalnun: 0x05DF,
  22123. finalnunhebrew: 0x05DF,
  22124. finalpe: 0x05E3,
  22125. finalpehebrew: 0x05E3,
  22126. finaltsadi: 0x05E5,
  22127. finaltsadihebrew: 0x05E5,
  22128. firsttonechinese: 0x02C9,
  22129. fisheye: 0x25C9,
  22130. fitacyrillic: 0x0473,
  22131. five: 0x0035,
  22132. fivearabic: 0x0665,
  22133. fivebengali: 0x09EB,
  22134. fivecircle: 0x2464,
  22135. fivecircleinversesansserif: 0x278E,
  22136. fivedeva: 0x096B,
  22137. fiveeighths: 0x215D,
  22138. fivegujarati: 0x0AEB,
  22139. fivegurmukhi: 0x0A6B,
  22140. fivehackarabic: 0x0665,
  22141. fivehangzhou: 0x3025,
  22142. fiveideographicparen: 0x3224,
  22143. fiveinferior: 0x2085,
  22144. fivemonospace: 0xFF15,
  22145. fiveoldstyle: 0xF735,
  22146. fiveparen: 0x2478,
  22147. fiveperiod: 0x248C,
  22148. fivepersian: 0x06F5,
  22149. fiveroman: 0x2174,
  22150. fivesuperior: 0x2075,
  22151. fivethai: 0x0E55,
  22152. fl: 0xFB02,
  22153. florin: 0x0192,
  22154. fmonospace: 0xFF46,
  22155. fmsquare: 0x3399,
  22156. fofanthai: 0x0E1F,
  22157. fofathai: 0x0E1D,
  22158. fongmanthai: 0x0E4F,
  22159. forall: 0x2200,
  22160. four: 0x0034,
  22161. fourarabic: 0x0664,
  22162. fourbengali: 0x09EA,
  22163. fourcircle: 0x2463,
  22164. fourcircleinversesansserif: 0x278D,
  22165. fourdeva: 0x096A,
  22166. fourgujarati: 0x0AEA,
  22167. fourgurmukhi: 0x0A6A,
  22168. fourhackarabic: 0x0664,
  22169. fourhangzhou: 0x3024,
  22170. fourideographicparen: 0x3223,
  22171. fourinferior: 0x2084,
  22172. fourmonospace: 0xFF14,
  22173. fournumeratorbengali: 0x09F7,
  22174. fouroldstyle: 0xF734,
  22175. fourparen: 0x2477,
  22176. fourperiod: 0x248B,
  22177. fourpersian: 0x06F4,
  22178. fourroman: 0x2173,
  22179. foursuperior: 0x2074,
  22180. fourteencircle: 0x246D,
  22181. fourteenparen: 0x2481,
  22182. fourteenperiod: 0x2495,
  22183. fourthai: 0x0E54,
  22184. fourthtonechinese: 0x02CB,
  22185. fparen: 0x24A1,
  22186. fraction: 0x2044,
  22187. franc: 0x20A3,
  22188. g: 0x0067,
  22189. gabengali: 0x0997,
  22190. gacute: 0x01F5,
  22191. gadeva: 0x0917,
  22192. gafarabic: 0x06AF,
  22193. gaffinalarabic: 0xFB93,
  22194. gafinitialarabic: 0xFB94,
  22195. gafmedialarabic: 0xFB95,
  22196. gagujarati: 0x0A97,
  22197. gagurmukhi: 0x0A17,
  22198. gahiragana: 0x304C,
  22199. gakatakana: 0x30AC,
  22200. gamma: 0x03B3,
  22201. gammalatinsmall: 0x0263,
  22202. gammasuperior: 0x02E0,
  22203. gangiacoptic: 0x03EB,
  22204. gbopomofo: 0x310D,
  22205. gbreve: 0x011F,
  22206. gcaron: 0x01E7,
  22207. gcedilla: 0x0123,
  22208. gcircle: 0x24D6,
  22209. gcircumflex: 0x011D,
  22210. gcommaaccent: 0x0123,
  22211. gdot: 0x0121,
  22212. gdotaccent: 0x0121,
  22213. gecyrillic: 0x0433,
  22214. gehiragana: 0x3052,
  22215. gekatakana: 0x30B2,
  22216. geometricallyequal: 0x2251,
  22217. gereshaccenthebrew: 0x059C,
  22218. gereshhebrew: 0x05F3,
  22219. gereshmuqdamhebrew: 0x059D,
  22220. germandbls: 0x00DF,
  22221. gershayimaccenthebrew: 0x059E,
  22222. gershayimhebrew: 0x05F4,
  22223. getamark: 0x3013,
  22224. ghabengali: 0x0998,
  22225. ghadarmenian: 0x0572,
  22226. ghadeva: 0x0918,
  22227. ghagujarati: 0x0A98,
  22228. ghagurmukhi: 0x0A18,
  22229. ghainarabic: 0x063A,
  22230. ghainfinalarabic: 0xFECE,
  22231. ghaininitialarabic: 0xFECF,
  22232. ghainmedialarabic: 0xFED0,
  22233. ghemiddlehookcyrillic: 0x0495,
  22234. ghestrokecyrillic: 0x0493,
  22235. gheupturncyrillic: 0x0491,
  22236. ghhadeva: 0x095A,
  22237. ghhagurmukhi: 0x0A5A,
  22238. ghook: 0x0260,
  22239. ghzsquare: 0x3393,
  22240. gihiragana: 0x304E,
  22241. gikatakana: 0x30AE,
  22242. gimarmenian: 0x0563,
  22243. gimel: 0x05D2,
  22244. gimeldagesh: 0xFB32,
  22245. gimeldageshhebrew: 0xFB32,
  22246. gimelhebrew: 0x05D2,
  22247. gjecyrillic: 0x0453,
  22248. glottalinvertedstroke: 0x01BE,
  22249. glottalstop: 0x0294,
  22250. glottalstopinverted: 0x0296,
  22251. glottalstopmod: 0x02C0,
  22252. glottalstopreversed: 0x0295,
  22253. glottalstopreversedmod: 0x02C1,
  22254. glottalstopreversedsuperior: 0x02E4,
  22255. glottalstopstroke: 0x02A1,
  22256. glottalstopstrokereversed: 0x02A2,
  22257. gmacron: 0x1E21,
  22258. gmonospace: 0xFF47,
  22259. gohiragana: 0x3054,
  22260. gokatakana: 0x30B4,
  22261. gparen: 0x24A2,
  22262. gpasquare: 0x33AC,
  22263. gradient: 0x2207,
  22264. grave: 0x0060,
  22265. gravebelowcmb: 0x0316,
  22266. gravecmb: 0x0300,
  22267. gravecomb: 0x0300,
  22268. gravedeva: 0x0953,
  22269. gravelowmod: 0x02CE,
  22270. gravemonospace: 0xFF40,
  22271. gravetonecmb: 0x0340,
  22272. greater: 0x003E,
  22273. greaterequal: 0x2265,
  22274. greaterequalorless: 0x22DB,
  22275. greatermonospace: 0xFF1E,
  22276. greaterorequivalent: 0x2273,
  22277. greaterorless: 0x2277,
  22278. greateroverequal: 0x2267,
  22279. greatersmall: 0xFE65,
  22280. gscript: 0x0261,
  22281. gstroke: 0x01E5,
  22282. guhiragana: 0x3050,
  22283. guillemotleft: 0x00AB,
  22284. guillemotright: 0x00BB,
  22285. guilsinglleft: 0x2039,
  22286. guilsinglright: 0x203A,
  22287. gukatakana: 0x30B0,
  22288. guramusquare: 0x3318,
  22289. gysquare: 0x33C9,
  22290. h: 0x0068,
  22291. haabkhasiancyrillic: 0x04A9,
  22292. haaltonearabic: 0x06C1,
  22293. habengali: 0x09B9,
  22294. hadescendercyrillic: 0x04B3,
  22295. hadeva: 0x0939,
  22296. hagujarati: 0x0AB9,
  22297. hagurmukhi: 0x0A39,
  22298. haharabic: 0x062D,
  22299. hahfinalarabic: 0xFEA2,
  22300. hahinitialarabic: 0xFEA3,
  22301. hahiragana: 0x306F,
  22302. hahmedialarabic: 0xFEA4,
  22303. haitusquare: 0x332A,
  22304. hakatakana: 0x30CF,
  22305. hakatakanahalfwidth: 0xFF8A,
  22306. halantgurmukhi: 0x0A4D,
  22307. hamzaarabic: 0x0621,
  22308. hamzalowarabic: 0x0621,
  22309. hangulfiller: 0x3164,
  22310. hardsigncyrillic: 0x044A,
  22311. harpoonleftbarbup: 0x21BC,
  22312. harpoonrightbarbup: 0x21C0,
  22313. hasquare: 0x33CA,
  22314. hatafpatah: 0x05B2,
  22315. hatafpatah16: 0x05B2,
  22316. hatafpatah23: 0x05B2,
  22317. hatafpatah2f: 0x05B2,
  22318. hatafpatahhebrew: 0x05B2,
  22319. hatafpatahnarrowhebrew: 0x05B2,
  22320. hatafpatahquarterhebrew: 0x05B2,
  22321. hatafpatahwidehebrew: 0x05B2,
  22322. hatafqamats: 0x05B3,
  22323. hatafqamats1b: 0x05B3,
  22324. hatafqamats28: 0x05B3,
  22325. hatafqamats34: 0x05B3,
  22326. hatafqamatshebrew: 0x05B3,
  22327. hatafqamatsnarrowhebrew: 0x05B3,
  22328. hatafqamatsquarterhebrew: 0x05B3,
  22329. hatafqamatswidehebrew: 0x05B3,
  22330. hatafsegol: 0x05B1,
  22331. hatafsegol17: 0x05B1,
  22332. hatafsegol24: 0x05B1,
  22333. hatafsegol30: 0x05B1,
  22334. hatafsegolhebrew: 0x05B1,
  22335. hatafsegolnarrowhebrew: 0x05B1,
  22336. hatafsegolquarterhebrew: 0x05B1,
  22337. hatafsegolwidehebrew: 0x05B1,
  22338. hbar: 0x0127,
  22339. hbopomofo: 0x310F,
  22340. hbrevebelow: 0x1E2B,
  22341. hcedilla: 0x1E29,
  22342. hcircle: 0x24D7,
  22343. hcircumflex: 0x0125,
  22344. hdieresis: 0x1E27,
  22345. hdotaccent: 0x1E23,
  22346. hdotbelow: 0x1E25,
  22347. he: 0x05D4,
  22348. heart: 0x2665,
  22349. heartsuitblack: 0x2665,
  22350. heartsuitwhite: 0x2661,
  22351. hedagesh: 0xFB34,
  22352. hedageshhebrew: 0xFB34,
  22353. hehaltonearabic: 0x06C1,
  22354. heharabic: 0x0647,
  22355. hehebrew: 0x05D4,
  22356. hehfinalaltonearabic: 0xFBA7,
  22357. hehfinalalttwoarabic: 0xFEEA,
  22358. hehfinalarabic: 0xFEEA,
  22359. hehhamzaabovefinalarabic: 0xFBA5,
  22360. hehhamzaaboveisolatedarabic: 0xFBA4,
  22361. hehinitialaltonearabic: 0xFBA8,
  22362. hehinitialarabic: 0xFEEB,
  22363. hehiragana: 0x3078,
  22364. hehmedialaltonearabic: 0xFBA9,
  22365. hehmedialarabic: 0xFEEC,
  22366. heiseierasquare: 0x337B,
  22367. hekatakana: 0x30D8,
  22368. hekatakanahalfwidth: 0xFF8D,
  22369. hekutaarusquare: 0x3336,
  22370. henghook: 0x0267,
  22371. herutusquare: 0x3339,
  22372. het: 0x05D7,
  22373. hethebrew: 0x05D7,
  22374. hhook: 0x0266,
  22375. hhooksuperior: 0x02B1,
  22376. hieuhacirclekorean: 0x327B,
  22377. hieuhaparenkorean: 0x321B,
  22378. hieuhcirclekorean: 0x326D,
  22379. hieuhkorean: 0x314E,
  22380. hieuhparenkorean: 0x320D,
  22381. hihiragana: 0x3072,
  22382. hikatakana: 0x30D2,
  22383. hikatakanahalfwidth: 0xFF8B,
  22384. hiriq: 0x05B4,
  22385. hiriq14: 0x05B4,
  22386. hiriq21: 0x05B4,
  22387. hiriq2d: 0x05B4,
  22388. hiriqhebrew: 0x05B4,
  22389. hiriqnarrowhebrew: 0x05B4,
  22390. hiriqquarterhebrew: 0x05B4,
  22391. hiriqwidehebrew: 0x05B4,
  22392. hlinebelow: 0x1E96,
  22393. hmonospace: 0xFF48,
  22394. hoarmenian: 0x0570,
  22395. hohipthai: 0x0E2B,
  22396. hohiragana: 0x307B,
  22397. hokatakana: 0x30DB,
  22398. hokatakanahalfwidth: 0xFF8E,
  22399. holam: 0x05B9,
  22400. holam19: 0x05B9,
  22401. holam26: 0x05B9,
  22402. holam32: 0x05B9,
  22403. holamhebrew: 0x05B9,
  22404. holamnarrowhebrew: 0x05B9,
  22405. holamquarterhebrew: 0x05B9,
  22406. holamwidehebrew: 0x05B9,
  22407. honokhukthai: 0x0E2E,
  22408. hookabovecomb: 0x0309,
  22409. hookcmb: 0x0309,
  22410. hookpalatalizedbelowcmb: 0x0321,
  22411. hookretroflexbelowcmb: 0x0322,
  22412. hoonsquare: 0x3342,
  22413. horicoptic: 0x03E9,
  22414. horizontalbar: 0x2015,
  22415. horncmb: 0x031B,
  22416. hotsprings: 0x2668,
  22417. house: 0x2302,
  22418. hparen: 0x24A3,
  22419. hsuperior: 0x02B0,
  22420. hturned: 0x0265,
  22421. huhiragana: 0x3075,
  22422. huiitosquare: 0x3333,
  22423. hukatakana: 0x30D5,
  22424. hukatakanahalfwidth: 0xFF8C,
  22425. hungarumlaut: 0x02DD,
  22426. hungarumlautcmb: 0x030B,
  22427. hv: 0x0195,
  22428. hyphen: 0x002D,
  22429. hypheninferior: 0xF6E5,
  22430. hyphenmonospace: 0xFF0D,
  22431. hyphensmall: 0xFE63,
  22432. hyphensuperior: 0xF6E6,
  22433. hyphentwo: 0x2010,
  22434. i: 0x0069,
  22435. iacute: 0x00ED,
  22436. iacyrillic: 0x044F,
  22437. ibengali: 0x0987,
  22438. ibopomofo: 0x3127,
  22439. ibreve: 0x012D,
  22440. icaron: 0x01D0,
  22441. icircle: 0x24D8,
  22442. icircumflex: 0x00EE,
  22443. icyrillic: 0x0456,
  22444. idblgrave: 0x0209,
  22445. ideographearthcircle: 0x328F,
  22446. ideographfirecircle: 0x328B,
  22447. ideographicallianceparen: 0x323F,
  22448. ideographiccallparen: 0x323A,
  22449. ideographiccentrecircle: 0x32A5,
  22450. ideographicclose: 0x3006,
  22451. ideographiccomma: 0x3001,
  22452. ideographiccommaleft: 0xFF64,
  22453. ideographiccongratulationparen: 0x3237,
  22454. ideographiccorrectcircle: 0x32A3,
  22455. ideographicearthparen: 0x322F,
  22456. ideographicenterpriseparen: 0x323D,
  22457. ideographicexcellentcircle: 0x329D,
  22458. ideographicfestivalparen: 0x3240,
  22459. ideographicfinancialcircle: 0x3296,
  22460. ideographicfinancialparen: 0x3236,
  22461. ideographicfireparen: 0x322B,
  22462. ideographichaveparen: 0x3232,
  22463. ideographichighcircle: 0x32A4,
  22464. ideographiciterationmark: 0x3005,
  22465. ideographiclaborcircle: 0x3298,
  22466. ideographiclaborparen: 0x3238,
  22467. ideographicleftcircle: 0x32A7,
  22468. ideographiclowcircle: 0x32A6,
  22469. ideographicmedicinecircle: 0x32A9,
  22470. ideographicmetalparen: 0x322E,
  22471. ideographicmoonparen: 0x322A,
  22472. ideographicnameparen: 0x3234,
  22473. ideographicperiod: 0x3002,
  22474. ideographicprintcircle: 0x329E,
  22475. ideographicreachparen: 0x3243,
  22476. ideographicrepresentparen: 0x3239,
  22477. ideographicresourceparen: 0x323E,
  22478. ideographicrightcircle: 0x32A8,
  22479. ideographicsecretcircle: 0x3299,
  22480. ideographicselfparen: 0x3242,
  22481. ideographicsocietyparen: 0x3233,
  22482. ideographicspace: 0x3000,
  22483. ideographicspecialparen: 0x3235,
  22484. ideographicstockparen: 0x3231,
  22485. ideographicstudyparen: 0x323B,
  22486. ideographicsunparen: 0x3230,
  22487. ideographicsuperviseparen: 0x323C,
  22488. ideographicwaterparen: 0x322C,
  22489. ideographicwoodparen: 0x322D,
  22490. ideographiczero: 0x3007,
  22491. ideographmetalcircle: 0x328E,
  22492. ideographmooncircle: 0x328A,
  22493. ideographnamecircle: 0x3294,
  22494. ideographsuncircle: 0x3290,
  22495. ideographwatercircle: 0x328C,
  22496. ideographwoodcircle: 0x328D,
  22497. ideva: 0x0907,
  22498. idieresis: 0x00EF,
  22499. idieresisacute: 0x1E2F,
  22500. idieresiscyrillic: 0x04E5,
  22501. idotbelow: 0x1ECB,
  22502. iebrevecyrillic: 0x04D7,
  22503. iecyrillic: 0x0435,
  22504. ieungacirclekorean: 0x3275,
  22505. ieungaparenkorean: 0x3215,
  22506. ieungcirclekorean: 0x3267,
  22507. ieungkorean: 0x3147,
  22508. ieungparenkorean: 0x3207,
  22509. igrave: 0x00EC,
  22510. igujarati: 0x0A87,
  22511. igurmukhi: 0x0A07,
  22512. ihiragana: 0x3044,
  22513. ihookabove: 0x1EC9,
  22514. iibengali: 0x0988,
  22515. iicyrillic: 0x0438,
  22516. iideva: 0x0908,
  22517. iigujarati: 0x0A88,
  22518. iigurmukhi: 0x0A08,
  22519. iimatragurmukhi: 0x0A40,
  22520. iinvertedbreve: 0x020B,
  22521. iishortcyrillic: 0x0439,
  22522. iivowelsignbengali: 0x09C0,
  22523. iivowelsigndeva: 0x0940,
  22524. iivowelsigngujarati: 0x0AC0,
  22525. ij: 0x0133,
  22526. ikatakana: 0x30A4,
  22527. ikatakanahalfwidth: 0xFF72,
  22528. ikorean: 0x3163,
  22529. ilde: 0x02DC,
  22530. iluyhebrew: 0x05AC,
  22531. imacron: 0x012B,
  22532. imacroncyrillic: 0x04E3,
  22533. imageorapproximatelyequal: 0x2253,
  22534. imatragurmukhi: 0x0A3F,
  22535. imonospace: 0xFF49,
  22536. increment: 0x2206,
  22537. infinity: 0x221E,
  22538. iniarmenian: 0x056B,
  22539. integral: 0x222B,
  22540. integralbottom: 0x2321,
  22541. integralbt: 0x2321,
  22542. integralex: 0xF8F5,
  22543. integraltop: 0x2320,
  22544. integraltp: 0x2320,
  22545. intersection: 0x2229,
  22546. intisquare: 0x3305,
  22547. invbullet: 0x25D8,
  22548. invcircle: 0x25D9,
  22549. invsmileface: 0x263B,
  22550. iocyrillic: 0x0451,
  22551. iogonek: 0x012F,
  22552. iota: 0x03B9,
  22553. iotadieresis: 0x03CA,
  22554. iotadieresistonos: 0x0390,
  22555. iotalatin: 0x0269,
  22556. iotatonos: 0x03AF,
  22557. iparen: 0x24A4,
  22558. irigurmukhi: 0x0A72,
  22559. ismallhiragana: 0x3043,
  22560. ismallkatakana: 0x30A3,
  22561. ismallkatakanahalfwidth: 0xFF68,
  22562. issharbengali: 0x09FA,
  22563. istroke: 0x0268,
  22564. isuperior: 0xF6ED,
  22565. iterationhiragana: 0x309D,
  22566. iterationkatakana: 0x30FD,
  22567. itilde: 0x0129,
  22568. itildebelow: 0x1E2D,
  22569. iubopomofo: 0x3129,
  22570. iucyrillic: 0x044E,
  22571. ivowelsignbengali: 0x09BF,
  22572. ivowelsigndeva: 0x093F,
  22573. ivowelsigngujarati: 0x0ABF,
  22574. izhitsacyrillic: 0x0475,
  22575. izhitsadblgravecyrillic: 0x0477,
  22576. j: 0x006A,
  22577. jaarmenian: 0x0571,
  22578. jabengali: 0x099C,
  22579. jadeva: 0x091C,
  22580. jagujarati: 0x0A9C,
  22581. jagurmukhi: 0x0A1C,
  22582. jbopomofo: 0x3110,
  22583. jcaron: 0x01F0,
  22584. jcircle: 0x24D9,
  22585. jcircumflex: 0x0135,
  22586. jcrossedtail: 0x029D,
  22587. jdotlessstroke: 0x025F,
  22588. jecyrillic: 0x0458,
  22589. jeemarabic: 0x062C,
  22590. jeemfinalarabic: 0xFE9E,
  22591. jeeminitialarabic: 0xFE9F,
  22592. jeemmedialarabic: 0xFEA0,
  22593. jeharabic: 0x0698,
  22594. jehfinalarabic: 0xFB8B,
  22595. jhabengali: 0x099D,
  22596. jhadeva: 0x091D,
  22597. jhagujarati: 0x0A9D,
  22598. jhagurmukhi: 0x0A1D,
  22599. jheharmenian: 0x057B,
  22600. jis: 0x3004,
  22601. jmonospace: 0xFF4A,
  22602. jparen: 0x24A5,
  22603. jsuperior: 0x02B2,
  22604. k: 0x006B,
  22605. kabashkircyrillic: 0x04A1,
  22606. kabengali: 0x0995,
  22607. kacute: 0x1E31,
  22608. kacyrillic: 0x043A,
  22609. kadescendercyrillic: 0x049B,
  22610. kadeva: 0x0915,
  22611. kaf: 0x05DB,
  22612. kafarabic: 0x0643,
  22613. kafdagesh: 0xFB3B,
  22614. kafdageshhebrew: 0xFB3B,
  22615. kaffinalarabic: 0xFEDA,
  22616. kafhebrew: 0x05DB,
  22617. kafinitialarabic: 0xFEDB,
  22618. kafmedialarabic: 0xFEDC,
  22619. kafrafehebrew: 0xFB4D,
  22620. kagujarati: 0x0A95,
  22621. kagurmukhi: 0x0A15,
  22622. kahiragana: 0x304B,
  22623. kahookcyrillic: 0x04C4,
  22624. kakatakana: 0x30AB,
  22625. kakatakanahalfwidth: 0xFF76,
  22626. kappa: 0x03BA,
  22627. kappasymbolgreek: 0x03F0,
  22628. kapyeounmieumkorean: 0x3171,
  22629. kapyeounphieuphkorean: 0x3184,
  22630. kapyeounpieupkorean: 0x3178,
  22631. kapyeounssangpieupkorean: 0x3179,
  22632. karoriisquare: 0x330D,
  22633. kashidaautoarabic: 0x0640,
  22634. kashidaautonosidebearingarabic: 0x0640,
  22635. kasmallkatakana: 0x30F5,
  22636. kasquare: 0x3384,
  22637. kasraarabic: 0x0650,
  22638. kasratanarabic: 0x064D,
  22639. kastrokecyrillic: 0x049F,
  22640. katahiraprolongmarkhalfwidth: 0xFF70,
  22641. kaverticalstrokecyrillic: 0x049D,
  22642. kbopomofo: 0x310E,
  22643. kcalsquare: 0x3389,
  22644. kcaron: 0x01E9,
  22645. kcedilla: 0x0137,
  22646. kcircle: 0x24DA,
  22647. kcommaaccent: 0x0137,
  22648. kdotbelow: 0x1E33,
  22649. keharmenian: 0x0584,
  22650. kehiragana: 0x3051,
  22651. kekatakana: 0x30B1,
  22652. kekatakanahalfwidth: 0xFF79,
  22653. kenarmenian: 0x056F,
  22654. kesmallkatakana: 0x30F6,
  22655. kgreenlandic: 0x0138,
  22656. khabengali: 0x0996,
  22657. khacyrillic: 0x0445,
  22658. khadeva: 0x0916,
  22659. khagujarati: 0x0A96,
  22660. khagurmukhi: 0x0A16,
  22661. khaharabic: 0x062E,
  22662. khahfinalarabic: 0xFEA6,
  22663. khahinitialarabic: 0xFEA7,
  22664. khahmedialarabic: 0xFEA8,
  22665. kheicoptic: 0x03E7,
  22666. khhadeva: 0x0959,
  22667. khhagurmukhi: 0x0A59,
  22668. khieukhacirclekorean: 0x3278,
  22669. khieukhaparenkorean: 0x3218,
  22670. khieukhcirclekorean: 0x326A,
  22671. khieukhkorean: 0x314B,
  22672. khieukhparenkorean: 0x320A,
  22673. khokhaithai: 0x0E02,
  22674. khokhonthai: 0x0E05,
  22675. khokhuatthai: 0x0E03,
  22676. khokhwaithai: 0x0E04,
  22677. khomutthai: 0x0E5B,
  22678. khook: 0x0199,
  22679. khorakhangthai: 0x0E06,
  22680. khzsquare: 0x3391,
  22681. kihiragana: 0x304D,
  22682. kikatakana: 0x30AD,
  22683. kikatakanahalfwidth: 0xFF77,
  22684. kiroguramusquare: 0x3315,
  22685. kiromeetorusquare: 0x3316,
  22686. kirosquare: 0x3314,
  22687. kiyeokacirclekorean: 0x326E,
  22688. kiyeokaparenkorean: 0x320E,
  22689. kiyeokcirclekorean: 0x3260,
  22690. kiyeokkorean: 0x3131,
  22691. kiyeokparenkorean: 0x3200,
  22692. kiyeoksioskorean: 0x3133,
  22693. kjecyrillic: 0x045C,
  22694. klinebelow: 0x1E35,
  22695. klsquare: 0x3398,
  22696. kmcubedsquare: 0x33A6,
  22697. kmonospace: 0xFF4B,
  22698. kmsquaredsquare: 0x33A2,
  22699. kohiragana: 0x3053,
  22700. kohmsquare: 0x33C0,
  22701. kokaithai: 0x0E01,
  22702. kokatakana: 0x30B3,
  22703. kokatakanahalfwidth: 0xFF7A,
  22704. kooposquare: 0x331E,
  22705. koppacyrillic: 0x0481,
  22706. koreanstandardsymbol: 0x327F,
  22707. koroniscmb: 0x0343,
  22708. kparen: 0x24A6,
  22709. kpasquare: 0x33AA,
  22710. ksicyrillic: 0x046F,
  22711. ktsquare: 0x33CF,
  22712. kturned: 0x029E,
  22713. kuhiragana: 0x304F,
  22714. kukatakana: 0x30AF,
  22715. kukatakanahalfwidth: 0xFF78,
  22716. kvsquare: 0x33B8,
  22717. kwsquare: 0x33BE,
  22718. l: 0x006C,
  22719. labengali: 0x09B2,
  22720. lacute: 0x013A,
  22721. ladeva: 0x0932,
  22722. lagujarati: 0x0AB2,
  22723. lagurmukhi: 0x0A32,
  22724. lakkhangyaothai: 0x0E45,
  22725. lamaleffinalarabic: 0xFEFC,
  22726. lamalefhamzaabovefinalarabic: 0xFEF8,
  22727. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  22728. lamalefhamzabelowfinalarabic: 0xFEFA,
  22729. lamalefhamzabelowisolatedarabic: 0xFEF9,
  22730. lamalefisolatedarabic: 0xFEFB,
  22731. lamalefmaddaabovefinalarabic: 0xFEF6,
  22732. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  22733. lamarabic: 0x0644,
  22734. lambda: 0x03BB,
  22735. lambdastroke: 0x019B,
  22736. lamed: 0x05DC,
  22737. lameddagesh: 0xFB3C,
  22738. lameddageshhebrew: 0xFB3C,
  22739. lamedhebrew: 0x05DC,
  22740. lamfinalarabic: 0xFEDE,
  22741. lamhahinitialarabic: 0xFCCA,
  22742. laminitialarabic: 0xFEDF,
  22743. lamjeeminitialarabic: 0xFCC9,
  22744. lamkhahinitialarabic: 0xFCCB,
  22745. lamlamhehisolatedarabic: 0xFDF2,
  22746. lammedialarabic: 0xFEE0,
  22747. lammeemhahinitialarabic: 0xFD88,
  22748. lammeeminitialarabic: 0xFCCC,
  22749. largecircle: 0x25EF,
  22750. lbar: 0x019A,
  22751. lbelt: 0x026C,
  22752. lbopomofo: 0x310C,
  22753. lcaron: 0x013E,
  22754. lcedilla: 0x013C,
  22755. lcircle: 0x24DB,
  22756. lcircumflexbelow: 0x1E3D,
  22757. lcommaaccent: 0x013C,
  22758. ldot: 0x0140,
  22759. ldotaccent: 0x0140,
  22760. ldotbelow: 0x1E37,
  22761. ldotbelowmacron: 0x1E39,
  22762. leftangleabovecmb: 0x031A,
  22763. lefttackbelowcmb: 0x0318,
  22764. less: 0x003C,
  22765. lessequal: 0x2264,
  22766. lessequalorgreater: 0x22DA,
  22767. lessmonospace: 0xFF1C,
  22768. lessorequivalent: 0x2272,
  22769. lessorgreater: 0x2276,
  22770. lessoverequal: 0x2266,
  22771. lesssmall: 0xFE64,
  22772. lezh: 0x026E,
  22773. lfblock: 0x258C,
  22774. lhookretroflex: 0x026D,
  22775. lira: 0x20A4,
  22776. liwnarmenian: 0x056C,
  22777. lj: 0x01C9,
  22778. ljecyrillic: 0x0459,
  22779. ll: 0xF6C0,
  22780. lladeva: 0x0933,
  22781. llagujarati: 0x0AB3,
  22782. llinebelow: 0x1E3B,
  22783. llladeva: 0x0934,
  22784. llvocalicbengali: 0x09E1,
  22785. llvocalicdeva: 0x0961,
  22786. llvocalicvowelsignbengali: 0x09E3,
  22787. llvocalicvowelsigndeva: 0x0963,
  22788. lmiddletilde: 0x026B,
  22789. lmonospace: 0xFF4C,
  22790. lmsquare: 0x33D0,
  22791. lochulathai: 0x0E2C,
  22792. logicaland: 0x2227,
  22793. logicalnot: 0x00AC,
  22794. logicalnotreversed: 0x2310,
  22795. logicalor: 0x2228,
  22796. lolingthai: 0x0E25,
  22797. longs: 0x017F,
  22798. lowlinecenterline: 0xFE4E,
  22799. lowlinecmb: 0x0332,
  22800. lowlinedashed: 0xFE4D,
  22801. lozenge: 0x25CA,
  22802. lparen: 0x24A7,
  22803. lslash: 0x0142,
  22804. lsquare: 0x2113,
  22805. lsuperior: 0xF6EE,
  22806. ltshade: 0x2591,
  22807. luthai: 0x0E26,
  22808. lvocalicbengali: 0x098C,
  22809. lvocalicdeva: 0x090C,
  22810. lvocalicvowelsignbengali: 0x09E2,
  22811. lvocalicvowelsigndeva: 0x0962,
  22812. lxsquare: 0x33D3,
  22813. m: 0x006D,
  22814. mabengali: 0x09AE,
  22815. macron: 0x00AF,
  22816. macronbelowcmb: 0x0331,
  22817. macroncmb: 0x0304,
  22818. macronlowmod: 0x02CD,
  22819. macronmonospace: 0xFFE3,
  22820. macute: 0x1E3F,
  22821. madeva: 0x092E,
  22822. magujarati: 0x0AAE,
  22823. magurmukhi: 0x0A2E,
  22824. mahapakhhebrew: 0x05A4,
  22825. mahapakhlefthebrew: 0x05A4,
  22826. mahiragana: 0x307E,
  22827. maichattawalowleftthai: 0xF895,
  22828. maichattawalowrightthai: 0xF894,
  22829. maichattawathai: 0x0E4B,
  22830. maichattawaupperleftthai: 0xF893,
  22831. maieklowleftthai: 0xF88C,
  22832. maieklowrightthai: 0xF88B,
  22833. maiekthai: 0x0E48,
  22834. maiekupperleftthai: 0xF88A,
  22835. maihanakatleftthai: 0xF884,
  22836. maihanakatthai: 0x0E31,
  22837. maitaikhuleftthai: 0xF889,
  22838. maitaikhuthai: 0x0E47,
  22839. maitholowleftthai: 0xF88F,
  22840. maitholowrightthai: 0xF88E,
  22841. maithothai: 0x0E49,
  22842. maithoupperleftthai: 0xF88D,
  22843. maitrilowleftthai: 0xF892,
  22844. maitrilowrightthai: 0xF891,
  22845. maitrithai: 0x0E4A,
  22846. maitriupperleftthai: 0xF890,
  22847. maiyamokthai: 0x0E46,
  22848. makatakana: 0x30DE,
  22849. makatakanahalfwidth: 0xFF8F,
  22850. male: 0x2642,
  22851. mansyonsquare: 0x3347,
  22852. maqafhebrew: 0x05BE,
  22853. mars: 0x2642,
  22854. masoracirclehebrew: 0x05AF,
  22855. masquare: 0x3383,
  22856. mbopomofo: 0x3107,
  22857. mbsquare: 0x33D4,
  22858. mcircle: 0x24DC,
  22859. mcubedsquare: 0x33A5,
  22860. mdotaccent: 0x1E41,
  22861. mdotbelow: 0x1E43,
  22862. meemarabic: 0x0645,
  22863. meemfinalarabic: 0xFEE2,
  22864. meeminitialarabic: 0xFEE3,
  22865. meemmedialarabic: 0xFEE4,
  22866. meemmeeminitialarabic: 0xFCD1,
  22867. meemmeemisolatedarabic: 0xFC48,
  22868. meetorusquare: 0x334D,
  22869. mehiragana: 0x3081,
  22870. meizierasquare: 0x337E,
  22871. mekatakana: 0x30E1,
  22872. mekatakanahalfwidth: 0xFF92,
  22873. mem: 0x05DE,
  22874. memdagesh: 0xFB3E,
  22875. memdageshhebrew: 0xFB3E,
  22876. memhebrew: 0x05DE,
  22877. menarmenian: 0x0574,
  22878. merkhahebrew: 0x05A5,
  22879. merkhakefulahebrew: 0x05A6,
  22880. merkhakefulalefthebrew: 0x05A6,
  22881. merkhalefthebrew: 0x05A5,
  22882. mhook: 0x0271,
  22883. mhzsquare: 0x3392,
  22884. middledotkatakanahalfwidth: 0xFF65,
  22885. middot: 0x00B7,
  22886. mieumacirclekorean: 0x3272,
  22887. mieumaparenkorean: 0x3212,
  22888. mieumcirclekorean: 0x3264,
  22889. mieumkorean: 0x3141,
  22890. mieumpansioskorean: 0x3170,
  22891. mieumparenkorean: 0x3204,
  22892. mieumpieupkorean: 0x316E,
  22893. mieumsioskorean: 0x316F,
  22894. mihiragana: 0x307F,
  22895. mikatakana: 0x30DF,
  22896. mikatakanahalfwidth: 0xFF90,
  22897. minus: 0x2212,
  22898. minusbelowcmb: 0x0320,
  22899. minuscircle: 0x2296,
  22900. minusmod: 0x02D7,
  22901. minusplus: 0x2213,
  22902. minute: 0x2032,
  22903. miribaarusquare: 0x334A,
  22904. mirisquare: 0x3349,
  22905. mlonglegturned: 0x0270,
  22906. mlsquare: 0x3396,
  22907. mmcubedsquare: 0x33A3,
  22908. mmonospace: 0xFF4D,
  22909. mmsquaredsquare: 0x339F,
  22910. mohiragana: 0x3082,
  22911. mohmsquare: 0x33C1,
  22912. mokatakana: 0x30E2,
  22913. mokatakanahalfwidth: 0xFF93,
  22914. molsquare: 0x33D6,
  22915. momathai: 0x0E21,
  22916. moverssquare: 0x33A7,
  22917. moverssquaredsquare: 0x33A8,
  22918. mparen: 0x24A8,
  22919. mpasquare: 0x33AB,
  22920. mssquare: 0x33B3,
  22921. msuperior: 0xF6EF,
  22922. mturned: 0x026F,
  22923. mu: 0x00B5,
  22924. mu1: 0x00B5,
  22925. muasquare: 0x3382,
  22926. muchgreater: 0x226B,
  22927. muchless: 0x226A,
  22928. mufsquare: 0x338C,
  22929. mugreek: 0x03BC,
  22930. mugsquare: 0x338D,
  22931. muhiragana: 0x3080,
  22932. mukatakana: 0x30E0,
  22933. mukatakanahalfwidth: 0xFF91,
  22934. mulsquare: 0x3395,
  22935. multiply: 0x00D7,
  22936. mumsquare: 0x339B,
  22937. munahhebrew: 0x05A3,
  22938. munahlefthebrew: 0x05A3,
  22939. musicalnote: 0x266A,
  22940. musicalnotedbl: 0x266B,
  22941. musicflatsign: 0x266D,
  22942. musicsharpsign: 0x266F,
  22943. mussquare: 0x33B2,
  22944. muvsquare: 0x33B6,
  22945. muwsquare: 0x33BC,
  22946. mvmegasquare: 0x33B9,
  22947. mvsquare: 0x33B7,
  22948. mwmegasquare: 0x33BF,
  22949. mwsquare: 0x33BD,
  22950. n: 0x006E,
  22951. nabengali: 0x09A8,
  22952. nabla: 0x2207,
  22953. nacute: 0x0144,
  22954. nadeva: 0x0928,
  22955. nagujarati: 0x0AA8,
  22956. nagurmukhi: 0x0A28,
  22957. nahiragana: 0x306A,
  22958. nakatakana: 0x30CA,
  22959. nakatakanahalfwidth: 0xFF85,
  22960. napostrophe: 0x0149,
  22961. nasquare: 0x3381,
  22962. nbopomofo: 0x310B,
  22963. nbspace: 0x00A0,
  22964. ncaron: 0x0148,
  22965. ncedilla: 0x0146,
  22966. ncircle: 0x24DD,
  22967. ncircumflexbelow: 0x1E4B,
  22968. ncommaaccent: 0x0146,
  22969. ndotaccent: 0x1E45,
  22970. ndotbelow: 0x1E47,
  22971. nehiragana: 0x306D,
  22972. nekatakana: 0x30CD,
  22973. nekatakanahalfwidth: 0xFF88,
  22974. newsheqelsign: 0x20AA,
  22975. nfsquare: 0x338B,
  22976. ngabengali: 0x0999,
  22977. ngadeva: 0x0919,
  22978. ngagujarati: 0x0A99,
  22979. ngagurmukhi: 0x0A19,
  22980. ngonguthai: 0x0E07,
  22981. nhiragana: 0x3093,
  22982. nhookleft: 0x0272,
  22983. nhookretroflex: 0x0273,
  22984. nieunacirclekorean: 0x326F,
  22985. nieunaparenkorean: 0x320F,
  22986. nieuncieuckorean: 0x3135,
  22987. nieuncirclekorean: 0x3261,
  22988. nieunhieuhkorean: 0x3136,
  22989. nieunkorean: 0x3134,
  22990. nieunpansioskorean: 0x3168,
  22991. nieunparenkorean: 0x3201,
  22992. nieunsioskorean: 0x3167,
  22993. nieuntikeutkorean: 0x3166,
  22994. nihiragana: 0x306B,
  22995. nikatakana: 0x30CB,
  22996. nikatakanahalfwidth: 0xFF86,
  22997. nikhahitleftthai: 0xF899,
  22998. nikhahitthai: 0x0E4D,
  22999. nine: 0x0039,
  23000. ninearabic: 0x0669,
  23001. ninebengali: 0x09EF,
  23002. ninecircle: 0x2468,
  23003. ninecircleinversesansserif: 0x2792,
  23004. ninedeva: 0x096F,
  23005. ninegujarati: 0x0AEF,
  23006. ninegurmukhi: 0x0A6F,
  23007. ninehackarabic: 0x0669,
  23008. ninehangzhou: 0x3029,
  23009. nineideographicparen: 0x3228,
  23010. nineinferior: 0x2089,
  23011. ninemonospace: 0xFF19,
  23012. nineoldstyle: 0xF739,
  23013. nineparen: 0x247C,
  23014. nineperiod: 0x2490,
  23015. ninepersian: 0x06F9,
  23016. nineroman: 0x2178,
  23017. ninesuperior: 0x2079,
  23018. nineteencircle: 0x2472,
  23019. nineteenparen: 0x2486,
  23020. nineteenperiod: 0x249A,
  23021. ninethai: 0x0E59,
  23022. nj: 0x01CC,
  23023. njecyrillic: 0x045A,
  23024. nkatakana: 0x30F3,
  23025. nkatakanahalfwidth: 0xFF9D,
  23026. nlegrightlong: 0x019E,
  23027. nlinebelow: 0x1E49,
  23028. nmonospace: 0xFF4E,
  23029. nmsquare: 0x339A,
  23030. nnabengali: 0x09A3,
  23031. nnadeva: 0x0923,
  23032. nnagujarati: 0x0AA3,
  23033. nnagurmukhi: 0x0A23,
  23034. nnnadeva: 0x0929,
  23035. nohiragana: 0x306E,
  23036. nokatakana: 0x30CE,
  23037. nokatakanahalfwidth: 0xFF89,
  23038. nonbreakingspace: 0x00A0,
  23039. nonenthai: 0x0E13,
  23040. nonuthai: 0x0E19,
  23041. noonarabic: 0x0646,
  23042. noonfinalarabic: 0xFEE6,
  23043. noonghunnaarabic: 0x06BA,
  23044. noonghunnafinalarabic: 0xFB9F,
  23045. nooninitialarabic: 0xFEE7,
  23046. noonjeeminitialarabic: 0xFCD2,
  23047. noonjeemisolatedarabic: 0xFC4B,
  23048. noonmedialarabic: 0xFEE8,
  23049. noonmeeminitialarabic: 0xFCD5,
  23050. noonmeemisolatedarabic: 0xFC4E,
  23051. noonnoonfinalarabic: 0xFC8D,
  23052. notcontains: 0x220C,
  23053. notelement: 0x2209,
  23054. notelementof: 0x2209,
  23055. notequal: 0x2260,
  23056. notgreater: 0x226F,
  23057. notgreaternorequal: 0x2271,
  23058. notgreaternorless: 0x2279,
  23059. notidentical: 0x2262,
  23060. notless: 0x226E,
  23061. notlessnorequal: 0x2270,
  23062. notparallel: 0x2226,
  23063. notprecedes: 0x2280,
  23064. notsubset: 0x2284,
  23065. notsucceeds: 0x2281,
  23066. notsuperset: 0x2285,
  23067. nowarmenian: 0x0576,
  23068. nparen: 0x24A9,
  23069. nssquare: 0x33B1,
  23070. nsuperior: 0x207F,
  23071. ntilde: 0x00F1,
  23072. nu: 0x03BD,
  23073. nuhiragana: 0x306C,
  23074. nukatakana: 0x30CC,
  23075. nukatakanahalfwidth: 0xFF87,
  23076. nuktabengali: 0x09BC,
  23077. nuktadeva: 0x093C,
  23078. nuktagujarati: 0x0ABC,
  23079. nuktagurmukhi: 0x0A3C,
  23080. numbersign: 0x0023,
  23081. numbersignmonospace: 0xFF03,
  23082. numbersignsmall: 0xFE5F,
  23083. numeralsigngreek: 0x0374,
  23084. numeralsignlowergreek: 0x0375,
  23085. numero: 0x2116,
  23086. nun: 0x05E0,
  23087. nundagesh: 0xFB40,
  23088. nundageshhebrew: 0xFB40,
  23089. nunhebrew: 0x05E0,
  23090. nvsquare: 0x33B5,
  23091. nwsquare: 0x33BB,
  23092. nyabengali: 0x099E,
  23093. nyadeva: 0x091E,
  23094. nyagujarati: 0x0A9E,
  23095. nyagurmukhi: 0x0A1E,
  23096. o: 0x006F,
  23097. oacute: 0x00F3,
  23098. oangthai: 0x0E2D,
  23099. obarred: 0x0275,
  23100. obarredcyrillic: 0x04E9,
  23101. obarreddieresiscyrillic: 0x04EB,
  23102. obengali: 0x0993,
  23103. obopomofo: 0x311B,
  23104. obreve: 0x014F,
  23105. ocandradeva: 0x0911,
  23106. ocandragujarati: 0x0A91,
  23107. ocandravowelsigndeva: 0x0949,
  23108. ocandravowelsigngujarati: 0x0AC9,
  23109. ocaron: 0x01D2,
  23110. ocircle: 0x24DE,
  23111. ocircumflex: 0x00F4,
  23112. ocircumflexacute: 0x1ED1,
  23113. ocircumflexdotbelow: 0x1ED9,
  23114. ocircumflexgrave: 0x1ED3,
  23115. ocircumflexhookabove: 0x1ED5,
  23116. ocircumflextilde: 0x1ED7,
  23117. ocyrillic: 0x043E,
  23118. odblacute: 0x0151,
  23119. odblgrave: 0x020D,
  23120. odeva: 0x0913,
  23121. odieresis: 0x00F6,
  23122. odieresiscyrillic: 0x04E7,
  23123. odotbelow: 0x1ECD,
  23124. oe: 0x0153,
  23125. oekorean: 0x315A,
  23126. ogonek: 0x02DB,
  23127. ogonekcmb: 0x0328,
  23128. ograve: 0x00F2,
  23129. ogujarati: 0x0A93,
  23130. oharmenian: 0x0585,
  23131. ohiragana: 0x304A,
  23132. ohookabove: 0x1ECF,
  23133. ohorn: 0x01A1,
  23134. ohornacute: 0x1EDB,
  23135. ohorndotbelow: 0x1EE3,
  23136. ohorngrave: 0x1EDD,
  23137. ohornhookabove: 0x1EDF,
  23138. ohorntilde: 0x1EE1,
  23139. ohungarumlaut: 0x0151,
  23140. oi: 0x01A3,
  23141. oinvertedbreve: 0x020F,
  23142. okatakana: 0x30AA,
  23143. okatakanahalfwidth: 0xFF75,
  23144. okorean: 0x3157,
  23145. olehebrew: 0x05AB,
  23146. omacron: 0x014D,
  23147. omacronacute: 0x1E53,
  23148. omacrongrave: 0x1E51,
  23149. omdeva: 0x0950,
  23150. omega: 0x03C9,
  23151. omega1: 0x03D6,
  23152. omegacyrillic: 0x0461,
  23153. omegalatinclosed: 0x0277,
  23154. omegaroundcyrillic: 0x047B,
  23155. omegatitlocyrillic: 0x047D,
  23156. omegatonos: 0x03CE,
  23157. omgujarati: 0x0AD0,
  23158. omicron: 0x03BF,
  23159. omicrontonos: 0x03CC,
  23160. omonospace: 0xFF4F,
  23161. one: 0x0031,
  23162. onearabic: 0x0661,
  23163. onebengali: 0x09E7,
  23164. onecircle: 0x2460,
  23165. onecircleinversesansserif: 0x278A,
  23166. onedeva: 0x0967,
  23167. onedotenleader: 0x2024,
  23168. oneeighth: 0x215B,
  23169. onefitted: 0xF6DC,
  23170. onegujarati: 0x0AE7,
  23171. onegurmukhi: 0x0A67,
  23172. onehackarabic: 0x0661,
  23173. onehalf: 0x00BD,
  23174. onehangzhou: 0x3021,
  23175. oneideographicparen: 0x3220,
  23176. oneinferior: 0x2081,
  23177. onemonospace: 0xFF11,
  23178. onenumeratorbengali: 0x09F4,
  23179. oneoldstyle: 0xF731,
  23180. oneparen: 0x2474,
  23181. oneperiod: 0x2488,
  23182. onepersian: 0x06F1,
  23183. onequarter: 0x00BC,
  23184. oneroman: 0x2170,
  23185. onesuperior: 0x00B9,
  23186. onethai: 0x0E51,
  23187. onethird: 0x2153,
  23188. oogonek: 0x01EB,
  23189. oogonekmacron: 0x01ED,
  23190. oogurmukhi: 0x0A13,
  23191. oomatragurmukhi: 0x0A4B,
  23192. oopen: 0x0254,
  23193. oparen: 0x24AA,
  23194. openbullet: 0x25E6,
  23195. option: 0x2325,
  23196. ordfeminine: 0x00AA,
  23197. ordmasculine: 0x00BA,
  23198. orthogonal: 0x221F,
  23199. oshortdeva: 0x0912,
  23200. oshortvowelsigndeva: 0x094A,
  23201. oslash: 0x00F8,
  23202. oslashacute: 0x01FF,
  23203. osmallhiragana: 0x3049,
  23204. osmallkatakana: 0x30A9,
  23205. osmallkatakanahalfwidth: 0xFF6B,
  23206. ostrokeacute: 0x01FF,
  23207. osuperior: 0xF6F0,
  23208. otcyrillic: 0x047F,
  23209. otilde: 0x00F5,
  23210. otildeacute: 0x1E4D,
  23211. otildedieresis: 0x1E4F,
  23212. oubopomofo: 0x3121,
  23213. overline: 0x203E,
  23214. overlinecenterline: 0xFE4A,
  23215. overlinecmb: 0x0305,
  23216. overlinedashed: 0xFE49,
  23217. overlinedblwavy: 0xFE4C,
  23218. overlinewavy: 0xFE4B,
  23219. overscore: 0x00AF,
  23220. ovowelsignbengali: 0x09CB,
  23221. ovowelsigndeva: 0x094B,
  23222. ovowelsigngujarati: 0x0ACB,
  23223. p: 0x0070,
  23224. paampssquare: 0x3380,
  23225. paasentosquare: 0x332B,
  23226. pabengali: 0x09AA,
  23227. pacute: 0x1E55,
  23228. padeva: 0x092A,
  23229. pagedown: 0x21DF,
  23230. pageup: 0x21DE,
  23231. pagujarati: 0x0AAA,
  23232. pagurmukhi: 0x0A2A,
  23233. pahiragana: 0x3071,
  23234. paiyannoithai: 0x0E2F,
  23235. pakatakana: 0x30D1,
  23236. palatalizationcyrilliccmb: 0x0484,
  23237. palochkacyrillic: 0x04C0,
  23238. pansioskorean: 0x317F,
  23239. paragraph: 0x00B6,
  23240. parallel: 0x2225,
  23241. parenleft: 0x0028,
  23242. parenleftaltonearabic: 0xFD3E,
  23243. parenleftbt: 0xF8ED,
  23244. parenleftex: 0xF8EC,
  23245. parenleftinferior: 0x208D,
  23246. parenleftmonospace: 0xFF08,
  23247. parenleftsmall: 0xFE59,
  23248. parenleftsuperior: 0x207D,
  23249. parenlefttp: 0xF8EB,
  23250. parenleftvertical: 0xFE35,
  23251. parenright: 0x0029,
  23252. parenrightaltonearabic: 0xFD3F,
  23253. parenrightbt: 0xF8F8,
  23254. parenrightex: 0xF8F7,
  23255. parenrightinferior: 0x208E,
  23256. parenrightmonospace: 0xFF09,
  23257. parenrightsmall: 0xFE5A,
  23258. parenrightsuperior: 0x207E,
  23259. parenrighttp: 0xF8F6,
  23260. parenrightvertical: 0xFE36,
  23261. partialdiff: 0x2202,
  23262. paseqhebrew: 0x05C0,
  23263. pashtahebrew: 0x0599,
  23264. pasquare: 0x33A9,
  23265. patah: 0x05B7,
  23266. patah11: 0x05B7,
  23267. patah1d: 0x05B7,
  23268. patah2a: 0x05B7,
  23269. patahhebrew: 0x05B7,
  23270. patahnarrowhebrew: 0x05B7,
  23271. patahquarterhebrew: 0x05B7,
  23272. patahwidehebrew: 0x05B7,
  23273. pazerhebrew: 0x05A1,
  23274. pbopomofo: 0x3106,
  23275. pcircle: 0x24DF,
  23276. pdotaccent: 0x1E57,
  23277. pe: 0x05E4,
  23278. pecyrillic: 0x043F,
  23279. pedagesh: 0xFB44,
  23280. pedageshhebrew: 0xFB44,
  23281. peezisquare: 0x333B,
  23282. pefinaldageshhebrew: 0xFB43,
  23283. peharabic: 0x067E,
  23284. peharmenian: 0x057A,
  23285. pehebrew: 0x05E4,
  23286. pehfinalarabic: 0xFB57,
  23287. pehinitialarabic: 0xFB58,
  23288. pehiragana: 0x307A,
  23289. pehmedialarabic: 0xFB59,
  23290. pekatakana: 0x30DA,
  23291. pemiddlehookcyrillic: 0x04A7,
  23292. perafehebrew: 0xFB4E,
  23293. percent: 0x0025,
  23294. percentarabic: 0x066A,
  23295. percentmonospace: 0xFF05,
  23296. percentsmall: 0xFE6A,
  23297. period: 0x002E,
  23298. periodarmenian: 0x0589,
  23299. periodcentered: 0x00B7,
  23300. periodhalfwidth: 0xFF61,
  23301. periodinferior: 0xF6E7,
  23302. periodmonospace: 0xFF0E,
  23303. periodsmall: 0xFE52,
  23304. periodsuperior: 0xF6E8,
  23305. perispomenigreekcmb: 0x0342,
  23306. perpendicular: 0x22A5,
  23307. perthousand: 0x2030,
  23308. peseta: 0x20A7,
  23309. pfsquare: 0x338A,
  23310. phabengali: 0x09AB,
  23311. phadeva: 0x092B,
  23312. phagujarati: 0x0AAB,
  23313. phagurmukhi: 0x0A2B,
  23314. phi: 0x03C6,
  23315. phi1: 0x03D5,
  23316. phieuphacirclekorean: 0x327A,
  23317. phieuphaparenkorean: 0x321A,
  23318. phieuphcirclekorean: 0x326C,
  23319. phieuphkorean: 0x314D,
  23320. phieuphparenkorean: 0x320C,
  23321. philatin: 0x0278,
  23322. phinthuthai: 0x0E3A,
  23323. phisymbolgreek: 0x03D5,
  23324. phook: 0x01A5,
  23325. phophanthai: 0x0E1E,
  23326. phophungthai: 0x0E1C,
  23327. phosamphaothai: 0x0E20,
  23328. pi: 0x03C0,
  23329. pieupacirclekorean: 0x3273,
  23330. pieupaparenkorean: 0x3213,
  23331. pieupcieuckorean: 0x3176,
  23332. pieupcirclekorean: 0x3265,
  23333. pieupkiyeokkorean: 0x3172,
  23334. pieupkorean: 0x3142,
  23335. pieupparenkorean: 0x3205,
  23336. pieupsioskiyeokkorean: 0x3174,
  23337. pieupsioskorean: 0x3144,
  23338. pieupsiostikeutkorean: 0x3175,
  23339. pieupthieuthkorean: 0x3177,
  23340. pieuptikeutkorean: 0x3173,
  23341. pihiragana: 0x3074,
  23342. pikatakana: 0x30D4,
  23343. pisymbolgreek: 0x03D6,
  23344. piwrarmenian: 0x0583,
  23345. plus: 0x002B,
  23346. plusbelowcmb: 0x031F,
  23347. pluscircle: 0x2295,
  23348. plusminus: 0x00B1,
  23349. plusmod: 0x02D6,
  23350. plusmonospace: 0xFF0B,
  23351. plussmall: 0xFE62,
  23352. plussuperior: 0x207A,
  23353. pmonospace: 0xFF50,
  23354. pmsquare: 0x33D8,
  23355. pohiragana: 0x307D,
  23356. pointingindexdownwhite: 0x261F,
  23357. pointingindexleftwhite: 0x261C,
  23358. pointingindexrightwhite: 0x261E,
  23359. pointingindexupwhite: 0x261D,
  23360. pokatakana: 0x30DD,
  23361. poplathai: 0x0E1B,
  23362. postalmark: 0x3012,
  23363. postalmarkface: 0x3020,
  23364. pparen: 0x24AB,
  23365. precedes: 0x227A,
  23366. prescription: 0x211E,
  23367. primemod: 0x02B9,
  23368. primereversed: 0x2035,
  23369. product: 0x220F,
  23370. projective: 0x2305,
  23371. prolongedkana: 0x30FC,
  23372. propellor: 0x2318,
  23373. propersubset: 0x2282,
  23374. propersuperset: 0x2283,
  23375. proportion: 0x2237,
  23376. proportional: 0x221D,
  23377. psi: 0x03C8,
  23378. psicyrillic: 0x0471,
  23379. psilipneumatacyrilliccmb: 0x0486,
  23380. pssquare: 0x33B0,
  23381. puhiragana: 0x3077,
  23382. pukatakana: 0x30D7,
  23383. pvsquare: 0x33B4,
  23384. pwsquare: 0x33BA,
  23385. q: 0x0071,
  23386. qadeva: 0x0958,
  23387. qadmahebrew: 0x05A8,
  23388. qafarabic: 0x0642,
  23389. qaffinalarabic: 0xFED6,
  23390. qafinitialarabic: 0xFED7,
  23391. qafmedialarabic: 0xFED8,
  23392. qamats: 0x05B8,
  23393. qamats10: 0x05B8,
  23394. qamats1a: 0x05B8,
  23395. qamats1c: 0x05B8,
  23396. qamats27: 0x05B8,
  23397. qamats29: 0x05B8,
  23398. qamats33: 0x05B8,
  23399. qamatsde: 0x05B8,
  23400. qamatshebrew: 0x05B8,
  23401. qamatsnarrowhebrew: 0x05B8,
  23402. qamatsqatanhebrew: 0x05B8,
  23403. qamatsqatannarrowhebrew: 0x05B8,
  23404. qamatsqatanquarterhebrew: 0x05B8,
  23405. qamatsqatanwidehebrew: 0x05B8,
  23406. qamatsquarterhebrew: 0x05B8,
  23407. qamatswidehebrew: 0x05B8,
  23408. qarneyparahebrew: 0x059F,
  23409. qbopomofo: 0x3111,
  23410. qcircle: 0x24E0,
  23411. qhook: 0x02A0,
  23412. qmonospace: 0xFF51,
  23413. qof: 0x05E7,
  23414. qofdagesh: 0xFB47,
  23415. qofdageshhebrew: 0xFB47,
  23416. qofhebrew: 0x05E7,
  23417. qparen: 0x24AC,
  23418. quarternote: 0x2669,
  23419. qubuts: 0x05BB,
  23420. qubuts18: 0x05BB,
  23421. qubuts25: 0x05BB,
  23422. qubuts31: 0x05BB,
  23423. qubutshebrew: 0x05BB,
  23424. qubutsnarrowhebrew: 0x05BB,
  23425. qubutsquarterhebrew: 0x05BB,
  23426. qubutswidehebrew: 0x05BB,
  23427. question: 0x003F,
  23428. questionarabic: 0x061F,
  23429. questionarmenian: 0x055E,
  23430. questiondown: 0x00BF,
  23431. questiondownsmall: 0xF7BF,
  23432. questiongreek: 0x037E,
  23433. questionmonospace: 0xFF1F,
  23434. questionsmall: 0xF73F,
  23435. quotedbl: 0x0022,
  23436. quotedblbase: 0x201E,
  23437. quotedblleft: 0x201C,
  23438. quotedblmonospace: 0xFF02,
  23439. quotedblprime: 0x301E,
  23440. quotedblprimereversed: 0x301D,
  23441. quotedblright: 0x201D,
  23442. quoteleft: 0x2018,
  23443. quoteleftreversed: 0x201B,
  23444. quotereversed: 0x201B,
  23445. quoteright: 0x2019,
  23446. quoterightn: 0x0149,
  23447. quotesinglbase: 0x201A,
  23448. quotesingle: 0x0027,
  23449. quotesinglemonospace: 0xFF07,
  23450. r: 0x0072,
  23451. raarmenian: 0x057C,
  23452. rabengali: 0x09B0,
  23453. racute: 0x0155,
  23454. radeva: 0x0930,
  23455. radical: 0x221A,
  23456. radicalex: 0xF8E5,
  23457. radoverssquare: 0x33AE,
  23458. radoverssquaredsquare: 0x33AF,
  23459. radsquare: 0x33AD,
  23460. rafe: 0x05BF,
  23461. rafehebrew: 0x05BF,
  23462. ragujarati: 0x0AB0,
  23463. ragurmukhi: 0x0A30,
  23464. rahiragana: 0x3089,
  23465. rakatakana: 0x30E9,
  23466. rakatakanahalfwidth: 0xFF97,
  23467. ralowerdiagonalbengali: 0x09F1,
  23468. ramiddlediagonalbengali: 0x09F0,
  23469. ramshorn: 0x0264,
  23470. ratio: 0x2236,
  23471. rbopomofo: 0x3116,
  23472. rcaron: 0x0159,
  23473. rcedilla: 0x0157,
  23474. rcircle: 0x24E1,
  23475. rcommaaccent: 0x0157,
  23476. rdblgrave: 0x0211,
  23477. rdotaccent: 0x1E59,
  23478. rdotbelow: 0x1E5B,
  23479. rdotbelowmacron: 0x1E5D,
  23480. referencemark: 0x203B,
  23481. reflexsubset: 0x2286,
  23482. reflexsuperset: 0x2287,
  23483. registered: 0x00AE,
  23484. registersans: 0xF8E8,
  23485. registerserif: 0xF6DA,
  23486. reharabic: 0x0631,
  23487. reharmenian: 0x0580,
  23488. rehfinalarabic: 0xFEAE,
  23489. rehiragana: 0x308C,
  23490. rekatakana: 0x30EC,
  23491. rekatakanahalfwidth: 0xFF9A,
  23492. resh: 0x05E8,
  23493. reshdageshhebrew: 0xFB48,
  23494. reshhebrew: 0x05E8,
  23495. reversedtilde: 0x223D,
  23496. reviahebrew: 0x0597,
  23497. reviamugrashhebrew: 0x0597,
  23498. revlogicalnot: 0x2310,
  23499. rfishhook: 0x027E,
  23500. rfishhookreversed: 0x027F,
  23501. rhabengali: 0x09DD,
  23502. rhadeva: 0x095D,
  23503. rho: 0x03C1,
  23504. rhook: 0x027D,
  23505. rhookturned: 0x027B,
  23506. rhookturnedsuperior: 0x02B5,
  23507. rhosymbolgreek: 0x03F1,
  23508. rhotichookmod: 0x02DE,
  23509. rieulacirclekorean: 0x3271,
  23510. rieulaparenkorean: 0x3211,
  23511. rieulcirclekorean: 0x3263,
  23512. rieulhieuhkorean: 0x3140,
  23513. rieulkiyeokkorean: 0x313A,
  23514. rieulkiyeoksioskorean: 0x3169,
  23515. rieulkorean: 0x3139,
  23516. rieulmieumkorean: 0x313B,
  23517. rieulpansioskorean: 0x316C,
  23518. rieulparenkorean: 0x3203,
  23519. rieulphieuphkorean: 0x313F,
  23520. rieulpieupkorean: 0x313C,
  23521. rieulpieupsioskorean: 0x316B,
  23522. rieulsioskorean: 0x313D,
  23523. rieulthieuthkorean: 0x313E,
  23524. rieultikeutkorean: 0x316A,
  23525. rieulyeorinhieuhkorean: 0x316D,
  23526. rightangle: 0x221F,
  23527. righttackbelowcmb: 0x0319,
  23528. righttriangle: 0x22BF,
  23529. rihiragana: 0x308A,
  23530. rikatakana: 0x30EA,
  23531. rikatakanahalfwidth: 0xFF98,
  23532. ring: 0x02DA,
  23533. ringbelowcmb: 0x0325,
  23534. ringcmb: 0x030A,
  23535. ringhalfleft: 0x02BF,
  23536. ringhalfleftarmenian: 0x0559,
  23537. ringhalfleftbelowcmb: 0x031C,
  23538. ringhalfleftcentered: 0x02D3,
  23539. ringhalfright: 0x02BE,
  23540. ringhalfrightbelowcmb: 0x0339,
  23541. ringhalfrightcentered: 0x02D2,
  23542. rinvertedbreve: 0x0213,
  23543. rittorusquare: 0x3351,
  23544. rlinebelow: 0x1E5F,
  23545. rlongleg: 0x027C,
  23546. rlonglegturned: 0x027A,
  23547. rmonospace: 0xFF52,
  23548. rohiragana: 0x308D,
  23549. rokatakana: 0x30ED,
  23550. rokatakanahalfwidth: 0xFF9B,
  23551. roruathai: 0x0E23,
  23552. rparen: 0x24AD,
  23553. rrabengali: 0x09DC,
  23554. rradeva: 0x0931,
  23555. rragurmukhi: 0x0A5C,
  23556. rreharabic: 0x0691,
  23557. rrehfinalarabic: 0xFB8D,
  23558. rrvocalicbengali: 0x09E0,
  23559. rrvocalicdeva: 0x0960,
  23560. rrvocalicgujarati: 0x0AE0,
  23561. rrvocalicvowelsignbengali: 0x09C4,
  23562. rrvocalicvowelsigndeva: 0x0944,
  23563. rrvocalicvowelsigngujarati: 0x0AC4,
  23564. rsuperior: 0xF6F1,
  23565. rtblock: 0x2590,
  23566. rturned: 0x0279,
  23567. rturnedsuperior: 0x02B4,
  23568. ruhiragana: 0x308B,
  23569. rukatakana: 0x30EB,
  23570. rukatakanahalfwidth: 0xFF99,
  23571. rupeemarkbengali: 0x09F2,
  23572. rupeesignbengali: 0x09F3,
  23573. rupiah: 0xF6DD,
  23574. ruthai: 0x0E24,
  23575. rvocalicbengali: 0x098B,
  23576. rvocalicdeva: 0x090B,
  23577. rvocalicgujarati: 0x0A8B,
  23578. rvocalicvowelsignbengali: 0x09C3,
  23579. rvocalicvowelsigndeva: 0x0943,
  23580. rvocalicvowelsigngujarati: 0x0AC3,
  23581. s: 0x0073,
  23582. sabengali: 0x09B8,
  23583. sacute: 0x015B,
  23584. sacutedotaccent: 0x1E65,
  23585. sadarabic: 0x0635,
  23586. sadeva: 0x0938,
  23587. sadfinalarabic: 0xFEBA,
  23588. sadinitialarabic: 0xFEBB,
  23589. sadmedialarabic: 0xFEBC,
  23590. sagujarati: 0x0AB8,
  23591. sagurmukhi: 0x0A38,
  23592. sahiragana: 0x3055,
  23593. sakatakana: 0x30B5,
  23594. sakatakanahalfwidth: 0xFF7B,
  23595. sallallahoualayhewasallamarabic: 0xFDFA,
  23596. samekh: 0x05E1,
  23597. samekhdagesh: 0xFB41,
  23598. samekhdageshhebrew: 0xFB41,
  23599. samekhhebrew: 0x05E1,
  23600. saraaathai: 0x0E32,
  23601. saraaethai: 0x0E41,
  23602. saraaimaimalaithai: 0x0E44,
  23603. saraaimaimuanthai: 0x0E43,
  23604. saraamthai: 0x0E33,
  23605. saraathai: 0x0E30,
  23606. saraethai: 0x0E40,
  23607. saraiileftthai: 0xF886,
  23608. saraiithai: 0x0E35,
  23609. saraileftthai: 0xF885,
  23610. saraithai: 0x0E34,
  23611. saraothai: 0x0E42,
  23612. saraueeleftthai: 0xF888,
  23613. saraueethai: 0x0E37,
  23614. saraueleftthai: 0xF887,
  23615. sarauethai: 0x0E36,
  23616. sarauthai: 0x0E38,
  23617. sarauuthai: 0x0E39,
  23618. sbopomofo: 0x3119,
  23619. scaron: 0x0161,
  23620. scarondotaccent: 0x1E67,
  23621. scedilla: 0x015F,
  23622. schwa: 0x0259,
  23623. schwacyrillic: 0x04D9,
  23624. schwadieresiscyrillic: 0x04DB,
  23625. schwahook: 0x025A,
  23626. scircle: 0x24E2,
  23627. scircumflex: 0x015D,
  23628. scommaaccent: 0x0219,
  23629. sdotaccent: 0x1E61,
  23630. sdotbelow: 0x1E63,
  23631. sdotbelowdotaccent: 0x1E69,
  23632. seagullbelowcmb: 0x033C,
  23633. second: 0x2033,
  23634. secondtonechinese: 0x02CA,
  23635. section: 0x00A7,
  23636. seenarabic: 0x0633,
  23637. seenfinalarabic: 0xFEB2,
  23638. seeninitialarabic: 0xFEB3,
  23639. seenmedialarabic: 0xFEB4,
  23640. segol: 0x05B6,
  23641. segol13: 0x05B6,
  23642. segol1f: 0x05B6,
  23643. segol2c: 0x05B6,
  23644. segolhebrew: 0x05B6,
  23645. segolnarrowhebrew: 0x05B6,
  23646. segolquarterhebrew: 0x05B6,
  23647. segoltahebrew: 0x0592,
  23648. segolwidehebrew: 0x05B6,
  23649. seharmenian: 0x057D,
  23650. sehiragana: 0x305B,
  23651. sekatakana: 0x30BB,
  23652. sekatakanahalfwidth: 0xFF7E,
  23653. semicolon: 0x003B,
  23654. semicolonarabic: 0x061B,
  23655. semicolonmonospace: 0xFF1B,
  23656. semicolonsmall: 0xFE54,
  23657. semivoicedmarkkana: 0x309C,
  23658. semivoicedmarkkanahalfwidth: 0xFF9F,
  23659. sentisquare: 0x3322,
  23660. sentosquare: 0x3323,
  23661. seven: 0x0037,
  23662. sevenarabic: 0x0667,
  23663. sevenbengali: 0x09ED,
  23664. sevencircle: 0x2466,
  23665. sevencircleinversesansserif: 0x2790,
  23666. sevendeva: 0x096D,
  23667. seveneighths: 0x215E,
  23668. sevengujarati: 0x0AED,
  23669. sevengurmukhi: 0x0A6D,
  23670. sevenhackarabic: 0x0667,
  23671. sevenhangzhou: 0x3027,
  23672. sevenideographicparen: 0x3226,
  23673. seveninferior: 0x2087,
  23674. sevenmonospace: 0xFF17,
  23675. sevenoldstyle: 0xF737,
  23676. sevenparen: 0x247A,
  23677. sevenperiod: 0x248E,
  23678. sevenpersian: 0x06F7,
  23679. sevenroman: 0x2176,
  23680. sevensuperior: 0x2077,
  23681. seventeencircle: 0x2470,
  23682. seventeenparen: 0x2484,
  23683. seventeenperiod: 0x2498,
  23684. seventhai: 0x0E57,
  23685. sfthyphen: 0x00AD,
  23686. shaarmenian: 0x0577,
  23687. shabengali: 0x09B6,
  23688. shacyrillic: 0x0448,
  23689. shaddaarabic: 0x0651,
  23690. shaddadammaarabic: 0xFC61,
  23691. shaddadammatanarabic: 0xFC5E,
  23692. shaddafathaarabic: 0xFC60,
  23693. shaddakasraarabic: 0xFC62,
  23694. shaddakasratanarabic: 0xFC5F,
  23695. shade: 0x2592,
  23696. shadedark: 0x2593,
  23697. shadelight: 0x2591,
  23698. shademedium: 0x2592,
  23699. shadeva: 0x0936,
  23700. shagujarati: 0x0AB6,
  23701. shagurmukhi: 0x0A36,
  23702. shalshelethebrew: 0x0593,
  23703. shbopomofo: 0x3115,
  23704. shchacyrillic: 0x0449,
  23705. sheenarabic: 0x0634,
  23706. sheenfinalarabic: 0xFEB6,
  23707. sheeninitialarabic: 0xFEB7,
  23708. sheenmedialarabic: 0xFEB8,
  23709. sheicoptic: 0x03E3,
  23710. sheqel: 0x20AA,
  23711. sheqelhebrew: 0x20AA,
  23712. sheva: 0x05B0,
  23713. sheva115: 0x05B0,
  23714. sheva15: 0x05B0,
  23715. sheva22: 0x05B0,
  23716. sheva2e: 0x05B0,
  23717. shevahebrew: 0x05B0,
  23718. shevanarrowhebrew: 0x05B0,
  23719. shevaquarterhebrew: 0x05B0,
  23720. shevawidehebrew: 0x05B0,
  23721. shhacyrillic: 0x04BB,
  23722. shimacoptic: 0x03ED,
  23723. shin: 0x05E9,
  23724. shindagesh: 0xFB49,
  23725. shindageshhebrew: 0xFB49,
  23726. shindageshshindot: 0xFB2C,
  23727. shindageshshindothebrew: 0xFB2C,
  23728. shindageshsindot: 0xFB2D,
  23729. shindageshsindothebrew: 0xFB2D,
  23730. shindothebrew: 0x05C1,
  23731. shinhebrew: 0x05E9,
  23732. shinshindot: 0xFB2A,
  23733. shinshindothebrew: 0xFB2A,
  23734. shinsindot: 0xFB2B,
  23735. shinsindothebrew: 0xFB2B,
  23736. shook: 0x0282,
  23737. sigma: 0x03C3,
  23738. sigma1: 0x03C2,
  23739. sigmafinal: 0x03C2,
  23740. sigmalunatesymbolgreek: 0x03F2,
  23741. sihiragana: 0x3057,
  23742. sikatakana: 0x30B7,
  23743. sikatakanahalfwidth: 0xFF7C,
  23744. siluqhebrew: 0x05BD,
  23745. siluqlefthebrew: 0x05BD,
  23746. similar: 0x223C,
  23747. sindothebrew: 0x05C2,
  23748. siosacirclekorean: 0x3274,
  23749. siosaparenkorean: 0x3214,
  23750. sioscieuckorean: 0x317E,
  23751. sioscirclekorean: 0x3266,
  23752. sioskiyeokkorean: 0x317A,
  23753. sioskorean: 0x3145,
  23754. siosnieunkorean: 0x317B,
  23755. siosparenkorean: 0x3206,
  23756. siospieupkorean: 0x317D,
  23757. siostikeutkorean: 0x317C,
  23758. six: 0x0036,
  23759. sixarabic: 0x0666,
  23760. sixbengali: 0x09EC,
  23761. sixcircle: 0x2465,
  23762. sixcircleinversesansserif: 0x278F,
  23763. sixdeva: 0x096C,
  23764. sixgujarati: 0x0AEC,
  23765. sixgurmukhi: 0x0A6C,
  23766. sixhackarabic: 0x0666,
  23767. sixhangzhou: 0x3026,
  23768. sixideographicparen: 0x3225,
  23769. sixinferior: 0x2086,
  23770. sixmonospace: 0xFF16,
  23771. sixoldstyle: 0xF736,
  23772. sixparen: 0x2479,
  23773. sixperiod: 0x248D,
  23774. sixpersian: 0x06F6,
  23775. sixroman: 0x2175,
  23776. sixsuperior: 0x2076,
  23777. sixteencircle: 0x246F,
  23778. sixteencurrencydenominatorbengali: 0x09F9,
  23779. sixteenparen: 0x2483,
  23780. sixteenperiod: 0x2497,
  23781. sixthai: 0x0E56,
  23782. slash: 0x002F,
  23783. slashmonospace: 0xFF0F,
  23784. slong: 0x017F,
  23785. slongdotaccent: 0x1E9B,
  23786. smileface: 0x263A,
  23787. smonospace: 0xFF53,
  23788. sofpasuqhebrew: 0x05C3,
  23789. softhyphen: 0x00AD,
  23790. softsigncyrillic: 0x044C,
  23791. sohiragana: 0x305D,
  23792. sokatakana: 0x30BD,
  23793. sokatakanahalfwidth: 0xFF7F,
  23794. soliduslongoverlaycmb: 0x0338,
  23795. solidusshortoverlaycmb: 0x0337,
  23796. sorusithai: 0x0E29,
  23797. sosalathai: 0x0E28,
  23798. sosothai: 0x0E0B,
  23799. sosuathai: 0x0E2A,
  23800. space: 0x0020,
  23801. spacehackarabic: 0x0020,
  23802. spade: 0x2660,
  23803. spadesuitblack: 0x2660,
  23804. spadesuitwhite: 0x2664,
  23805. sparen: 0x24AE,
  23806. squarebelowcmb: 0x033B,
  23807. squarecc: 0x33C4,
  23808. squarecm: 0x339D,
  23809. squarediagonalcrosshatchfill: 0x25A9,
  23810. squarehorizontalfill: 0x25A4,
  23811. squarekg: 0x338F,
  23812. squarekm: 0x339E,
  23813. squarekmcapital: 0x33CE,
  23814. squareln: 0x33D1,
  23815. squarelog: 0x33D2,
  23816. squaremg: 0x338E,
  23817. squaremil: 0x33D5,
  23818. squaremm: 0x339C,
  23819. squaremsquared: 0x33A1,
  23820. squareorthogonalcrosshatchfill: 0x25A6,
  23821. squareupperlefttolowerrightfill: 0x25A7,
  23822. squareupperrighttolowerleftfill: 0x25A8,
  23823. squareverticalfill: 0x25A5,
  23824. squarewhitewithsmallblack: 0x25A3,
  23825. srsquare: 0x33DB,
  23826. ssabengali: 0x09B7,
  23827. ssadeva: 0x0937,
  23828. ssagujarati: 0x0AB7,
  23829. ssangcieuckorean: 0x3149,
  23830. ssanghieuhkorean: 0x3185,
  23831. ssangieungkorean: 0x3180,
  23832. ssangkiyeokkorean: 0x3132,
  23833. ssangnieunkorean: 0x3165,
  23834. ssangpieupkorean: 0x3143,
  23835. ssangsioskorean: 0x3146,
  23836. ssangtikeutkorean: 0x3138,
  23837. ssuperior: 0xF6F2,
  23838. sterling: 0x00A3,
  23839. sterlingmonospace: 0xFFE1,
  23840. strokelongoverlaycmb: 0x0336,
  23841. strokeshortoverlaycmb: 0x0335,
  23842. subset: 0x2282,
  23843. subsetnotequal: 0x228A,
  23844. subsetorequal: 0x2286,
  23845. succeeds: 0x227B,
  23846. suchthat: 0x220B,
  23847. suhiragana: 0x3059,
  23848. sukatakana: 0x30B9,
  23849. sukatakanahalfwidth: 0xFF7D,
  23850. sukunarabic: 0x0652,
  23851. summation: 0x2211,
  23852. sun: 0x263C,
  23853. superset: 0x2283,
  23854. supersetnotequal: 0x228B,
  23855. supersetorequal: 0x2287,
  23856. svsquare: 0x33DC,
  23857. syouwaerasquare: 0x337C,
  23858. t: 0x0074,
  23859. tabengali: 0x09A4,
  23860. tackdown: 0x22A4,
  23861. tackleft: 0x22A3,
  23862. tadeva: 0x0924,
  23863. tagujarati: 0x0AA4,
  23864. tagurmukhi: 0x0A24,
  23865. taharabic: 0x0637,
  23866. tahfinalarabic: 0xFEC2,
  23867. tahinitialarabic: 0xFEC3,
  23868. tahiragana: 0x305F,
  23869. tahmedialarabic: 0xFEC4,
  23870. taisyouerasquare: 0x337D,
  23871. takatakana: 0x30BF,
  23872. takatakanahalfwidth: 0xFF80,
  23873. tatweelarabic: 0x0640,
  23874. tau: 0x03C4,
  23875. tav: 0x05EA,
  23876. tavdages: 0xFB4A,
  23877. tavdagesh: 0xFB4A,
  23878. tavdageshhebrew: 0xFB4A,
  23879. tavhebrew: 0x05EA,
  23880. tbar: 0x0167,
  23881. tbopomofo: 0x310A,
  23882. tcaron: 0x0165,
  23883. tccurl: 0x02A8,
  23884. tcedilla: 0x0163,
  23885. tcheharabic: 0x0686,
  23886. tchehfinalarabic: 0xFB7B,
  23887. tchehinitialarabic: 0xFB7C,
  23888. tchehmedialarabic: 0xFB7D,
  23889. tcircle: 0x24E3,
  23890. tcircumflexbelow: 0x1E71,
  23891. tcommaaccent: 0x0163,
  23892. tdieresis: 0x1E97,
  23893. tdotaccent: 0x1E6B,
  23894. tdotbelow: 0x1E6D,
  23895. tecyrillic: 0x0442,
  23896. tedescendercyrillic: 0x04AD,
  23897. teharabic: 0x062A,
  23898. tehfinalarabic: 0xFE96,
  23899. tehhahinitialarabic: 0xFCA2,
  23900. tehhahisolatedarabic: 0xFC0C,
  23901. tehinitialarabic: 0xFE97,
  23902. tehiragana: 0x3066,
  23903. tehjeeminitialarabic: 0xFCA1,
  23904. tehjeemisolatedarabic: 0xFC0B,
  23905. tehmarbutaarabic: 0x0629,
  23906. tehmarbutafinalarabic: 0xFE94,
  23907. tehmedialarabic: 0xFE98,
  23908. tehmeeminitialarabic: 0xFCA4,
  23909. tehmeemisolatedarabic: 0xFC0E,
  23910. tehnoonfinalarabic: 0xFC73,
  23911. tekatakana: 0x30C6,
  23912. tekatakanahalfwidth: 0xFF83,
  23913. telephone: 0x2121,
  23914. telephoneblack: 0x260E,
  23915. telishagedolahebrew: 0x05A0,
  23916. telishaqetanahebrew: 0x05A9,
  23917. tencircle: 0x2469,
  23918. tenideographicparen: 0x3229,
  23919. tenparen: 0x247D,
  23920. tenperiod: 0x2491,
  23921. tenroman: 0x2179,
  23922. tesh: 0x02A7,
  23923. tet: 0x05D8,
  23924. tetdagesh: 0xFB38,
  23925. tetdageshhebrew: 0xFB38,
  23926. tethebrew: 0x05D8,
  23927. tetsecyrillic: 0x04B5,
  23928. tevirhebrew: 0x059B,
  23929. tevirlefthebrew: 0x059B,
  23930. thabengali: 0x09A5,
  23931. thadeva: 0x0925,
  23932. thagujarati: 0x0AA5,
  23933. thagurmukhi: 0x0A25,
  23934. thalarabic: 0x0630,
  23935. thalfinalarabic: 0xFEAC,
  23936. thanthakhatlowleftthai: 0xF898,
  23937. thanthakhatlowrightthai: 0xF897,
  23938. thanthakhatthai: 0x0E4C,
  23939. thanthakhatupperleftthai: 0xF896,
  23940. theharabic: 0x062B,
  23941. thehfinalarabic: 0xFE9A,
  23942. thehinitialarabic: 0xFE9B,
  23943. thehmedialarabic: 0xFE9C,
  23944. thereexists: 0x2203,
  23945. therefore: 0x2234,
  23946. theta: 0x03B8,
  23947. theta1: 0x03D1,
  23948. thetasymbolgreek: 0x03D1,
  23949. thieuthacirclekorean: 0x3279,
  23950. thieuthaparenkorean: 0x3219,
  23951. thieuthcirclekorean: 0x326B,
  23952. thieuthkorean: 0x314C,
  23953. thieuthparenkorean: 0x320B,
  23954. thirteencircle: 0x246C,
  23955. thirteenparen: 0x2480,
  23956. thirteenperiod: 0x2494,
  23957. thonangmonthothai: 0x0E11,
  23958. thook: 0x01AD,
  23959. thophuthaothai: 0x0E12,
  23960. thorn: 0x00FE,
  23961. thothahanthai: 0x0E17,
  23962. thothanthai: 0x0E10,
  23963. thothongthai: 0x0E18,
  23964. thothungthai: 0x0E16,
  23965. thousandcyrillic: 0x0482,
  23966. thousandsseparatorarabic: 0x066C,
  23967. thousandsseparatorpersian: 0x066C,
  23968. three: 0x0033,
  23969. threearabic: 0x0663,
  23970. threebengali: 0x09E9,
  23971. threecircle: 0x2462,
  23972. threecircleinversesansserif: 0x278C,
  23973. threedeva: 0x0969,
  23974. threeeighths: 0x215C,
  23975. threegujarati: 0x0AE9,
  23976. threegurmukhi: 0x0A69,
  23977. threehackarabic: 0x0663,
  23978. threehangzhou: 0x3023,
  23979. threeideographicparen: 0x3222,
  23980. threeinferior: 0x2083,
  23981. threemonospace: 0xFF13,
  23982. threenumeratorbengali: 0x09F6,
  23983. threeoldstyle: 0xF733,
  23984. threeparen: 0x2476,
  23985. threeperiod: 0x248A,
  23986. threepersian: 0x06F3,
  23987. threequarters: 0x00BE,
  23988. threequartersemdash: 0xF6DE,
  23989. threeroman: 0x2172,
  23990. threesuperior: 0x00B3,
  23991. threethai: 0x0E53,
  23992. thzsquare: 0x3394,
  23993. tihiragana: 0x3061,
  23994. tikatakana: 0x30C1,
  23995. tikatakanahalfwidth: 0xFF81,
  23996. tikeutacirclekorean: 0x3270,
  23997. tikeutaparenkorean: 0x3210,
  23998. tikeutcirclekorean: 0x3262,
  23999. tikeutkorean: 0x3137,
  24000. tikeutparenkorean: 0x3202,
  24001. tilde: 0x02DC,
  24002. tildebelowcmb: 0x0330,
  24003. tildecmb: 0x0303,
  24004. tildecomb: 0x0303,
  24005. tildedoublecmb: 0x0360,
  24006. tildeoperator: 0x223C,
  24007. tildeoverlaycmb: 0x0334,
  24008. tildeverticalcmb: 0x033E,
  24009. timescircle: 0x2297,
  24010. tipehahebrew: 0x0596,
  24011. tipehalefthebrew: 0x0596,
  24012. tippigurmukhi: 0x0A70,
  24013. titlocyrilliccmb: 0x0483,
  24014. tiwnarmenian: 0x057F,
  24015. tlinebelow: 0x1E6F,
  24016. tmonospace: 0xFF54,
  24017. toarmenian: 0x0569,
  24018. tohiragana: 0x3068,
  24019. tokatakana: 0x30C8,
  24020. tokatakanahalfwidth: 0xFF84,
  24021. tonebarextrahighmod: 0x02E5,
  24022. tonebarextralowmod: 0x02E9,
  24023. tonebarhighmod: 0x02E6,
  24024. tonebarlowmod: 0x02E8,
  24025. tonebarmidmod: 0x02E7,
  24026. tonefive: 0x01BD,
  24027. tonesix: 0x0185,
  24028. tonetwo: 0x01A8,
  24029. tonos: 0x0384,
  24030. tonsquare: 0x3327,
  24031. topatakthai: 0x0E0F,
  24032. tortoiseshellbracketleft: 0x3014,
  24033. tortoiseshellbracketleftsmall: 0xFE5D,
  24034. tortoiseshellbracketleftvertical: 0xFE39,
  24035. tortoiseshellbracketright: 0x3015,
  24036. tortoiseshellbracketrightsmall: 0xFE5E,
  24037. tortoiseshellbracketrightvertical: 0xFE3A,
  24038. totaothai: 0x0E15,
  24039. tpalatalhook: 0x01AB,
  24040. tparen: 0x24AF,
  24041. trademark: 0x2122,
  24042. trademarksans: 0xF8EA,
  24043. trademarkserif: 0xF6DB,
  24044. tretroflexhook: 0x0288,
  24045. triagdn: 0x25BC,
  24046. triaglf: 0x25C4,
  24047. triagrt: 0x25BA,
  24048. triagup: 0x25B2,
  24049. ts: 0x02A6,
  24050. tsadi: 0x05E6,
  24051. tsadidagesh: 0xFB46,
  24052. tsadidageshhebrew: 0xFB46,
  24053. tsadihebrew: 0x05E6,
  24054. tsecyrillic: 0x0446,
  24055. tsere: 0x05B5,
  24056. tsere12: 0x05B5,
  24057. tsere1e: 0x05B5,
  24058. tsere2b: 0x05B5,
  24059. tserehebrew: 0x05B5,
  24060. tserenarrowhebrew: 0x05B5,
  24061. tserequarterhebrew: 0x05B5,
  24062. tserewidehebrew: 0x05B5,
  24063. tshecyrillic: 0x045B,
  24064. tsuperior: 0xF6F3,
  24065. ttabengali: 0x099F,
  24066. ttadeva: 0x091F,
  24067. ttagujarati: 0x0A9F,
  24068. ttagurmukhi: 0x0A1F,
  24069. tteharabic: 0x0679,
  24070. ttehfinalarabic: 0xFB67,
  24071. ttehinitialarabic: 0xFB68,
  24072. ttehmedialarabic: 0xFB69,
  24073. tthabengali: 0x09A0,
  24074. tthadeva: 0x0920,
  24075. tthagujarati: 0x0AA0,
  24076. tthagurmukhi: 0x0A20,
  24077. tturned: 0x0287,
  24078. tuhiragana: 0x3064,
  24079. tukatakana: 0x30C4,
  24080. tukatakanahalfwidth: 0xFF82,
  24081. tusmallhiragana: 0x3063,
  24082. tusmallkatakana: 0x30C3,
  24083. tusmallkatakanahalfwidth: 0xFF6F,
  24084. twelvecircle: 0x246B,
  24085. twelveparen: 0x247F,
  24086. twelveperiod: 0x2493,
  24087. twelveroman: 0x217B,
  24088. twentycircle: 0x2473,
  24089. twentyhangzhou: 0x5344,
  24090. twentyparen: 0x2487,
  24091. twentyperiod: 0x249B,
  24092. two: 0x0032,
  24093. twoarabic: 0x0662,
  24094. twobengali: 0x09E8,
  24095. twocircle: 0x2461,
  24096. twocircleinversesansserif: 0x278B,
  24097. twodeva: 0x0968,
  24098. twodotenleader: 0x2025,
  24099. twodotleader: 0x2025,
  24100. twodotleadervertical: 0xFE30,
  24101. twogujarati: 0x0AE8,
  24102. twogurmukhi: 0x0A68,
  24103. twohackarabic: 0x0662,
  24104. twohangzhou: 0x3022,
  24105. twoideographicparen: 0x3221,
  24106. twoinferior: 0x2082,
  24107. twomonospace: 0xFF12,
  24108. twonumeratorbengali: 0x09F5,
  24109. twooldstyle: 0xF732,
  24110. twoparen: 0x2475,
  24111. twoperiod: 0x2489,
  24112. twopersian: 0x06F2,
  24113. tworoman: 0x2171,
  24114. twostroke: 0x01BB,
  24115. twosuperior: 0x00B2,
  24116. twothai: 0x0E52,
  24117. twothirds: 0x2154,
  24118. u: 0x0075,
  24119. uacute: 0x00FA,
  24120. ubar: 0x0289,
  24121. ubengali: 0x0989,
  24122. ubopomofo: 0x3128,
  24123. ubreve: 0x016D,
  24124. ucaron: 0x01D4,
  24125. ucircle: 0x24E4,
  24126. ucircumflex: 0x00FB,
  24127. ucircumflexbelow: 0x1E77,
  24128. ucyrillic: 0x0443,
  24129. udattadeva: 0x0951,
  24130. udblacute: 0x0171,
  24131. udblgrave: 0x0215,
  24132. udeva: 0x0909,
  24133. udieresis: 0x00FC,
  24134. udieresisacute: 0x01D8,
  24135. udieresisbelow: 0x1E73,
  24136. udieresiscaron: 0x01DA,
  24137. udieresiscyrillic: 0x04F1,
  24138. udieresisgrave: 0x01DC,
  24139. udieresismacron: 0x01D6,
  24140. udotbelow: 0x1EE5,
  24141. ugrave: 0x00F9,
  24142. ugujarati: 0x0A89,
  24143. ugurmukhi: 0x0A09,
  24144. uhiragana: 0x3046,
  24145. uhookabove: 0x1EE7,
  24146. uhorn: 0x01B0,
  24147. uhornacute: 0x1EE9,
  24148. uhorndotbelow: 0x1EF1,
  24149. uhorngrave: 0x1EEB,
  24150. uhornhookabove: 0x1EED,
  24151. uhorntilde: 0x1EEF,
  24152. uhungarumlaut: 0x0171,
  24153. uhungarumlautcyrillic: 0x04F3,
  24154. uinvertedbreve: 0x0217,
  24155. ukatakana: 0x30A6,
  24156. ukatakanahalfwidth: 0xFF73,
  24157. ukcyrillic: 0x0479,
  24158. ukorean: 0x315C,
  24159. umacron: 0x016B,
  24160. umacroncyrillic: 0x04EF,
  24161. umacrondieresis: 0x1E7B,
  24162. umatragurmukhi: 0x0A41,
  24163. umonospace: 0xFF55,
  24164. underscore: 0x005F,
  24165. underscoredbl: 0x2017,
  24166. underscoremonospace: 0xFF3F,
  24167. underscorevertical: 0xFE33,
  24168. underscorewavy: 0xFE4F,
  24169. union: 0x222A,
  24170. universal: 0x2200,
  24171. uogonek: 0x0173,
  24172. uparen: 0x24B0,
  24173. upblock: 0x2580,
  24174. upperdothebrew: 0x05C4,
  24175. upsilon: 0x03C5,
  24176. upsilondieresis: 0x03CB,
  24177. upsilondieresistonos: 0x03B0,
  24178. upsilonlatin: 0x028A,
  24179. upsilontonos: 0x03CD,
  24180. uptackbelowcmb: 0x031D,
  24181. uptackmod: 0x02D4,
  24182. uragurmukhi: 0x0A73,
  24183. uring: 0x016F,
  24184. ushortcyrillic: 0x045E,
  24185. usmallhiragana: 0x3045,
  24186. usmallkatakana: 0x30A5,
  24187. usmallkatakanahalfwidth: 0xFF69,
  24188. ustraightcyrillic: 0x04AF,
  24189. ustraightstrokecyrillic: 0x04B1,
  24190. utilde: 0x0169,
  24191. utildeacute: 0x1E79,
  24192. utildebelow: 0x1E75,
  24193. uubengali: 0x098A,
  24194. uudeva: 0x090A,
  24195. uugujarati: 0x0A8A,
  24196. uugurmukhi: 0x0A0A,
  24197. uumatragurmukhi: 0x0A42,
  24198. uuvowelsignbengali: 0x09C2,
  24199. uuvowelsigndeva: 0x0942,
  24200. uuvowelsigngujarati: 0x0AC2,
  24201. uvowelsignbengali: 0x09C1,
  24202. uvowelsigndeva: 0x0941,
  24203. uvowelsigngujarati: 0x0AC1,
  24204. v: 0x0076,
  24205. vadeva: 0x0935,
  24206. vagujarati: 0x0AB5,
  24207. vagurmukhi: 0x0A35,
  24208. vakatakana: 0x30F7,
  24209. vav: 0x05D5,
  24210. vavdagesh: 0xFB35,
  24211. vavdagesh65: 0xFB35,
  24212. vavdageshhebrew: 0xFB35,
  24213. vavhebrew: 0x05D5,
  24214. vavholam: 0xFB4B,
  24215. vavholamhebrew: 0xFB4B,
  24216. vavvavhebrew: 0x05F0,
  24217. vavyodhebrew: 0x05F1,
  24218. vcircle: 0x24E5,
  24219. vdotbelow: 0x1E7F,
  24220. vecyrillic: 0x0432,
  24221. veharabic: 0x06A4,
  24222. vehfinalarabic: 0xFB6B,
  24223. vehinitialarabic: 0xFB6C,
  24224. vehmedialarabic: 0xFB6D,
  24225. vekatakana: 0x30F9,
  24226. venus: 0x2640,
  24227. verticalbar: 0x007C,
  24228. verticallineabovecmb: 0x030D,
  24229. verticallinebelowcmb: 0x0329,
  24230. verticallinelowmod: 0x02CC,
  24231. verticallinemod: 0x02C8,
  24232. vewarmenian: 0x057E,
  24233. vhook: 0x028B,
  24234. vikatakana: 0x30F8,
  24235. viramabengali: 0x09CD,
  24236. viramadeva: 0x094D,
  24237. viramagujarati: 0x0ACD,
  24238. visargabengali: 0x0983,
  24239. visargadeva: 0x0903,
  24240. visargagujarati: 0x0A83,
  24241. vmonospace: 0xFF56,
  24242. voarmenian: 0x0578,
  24243. voicediterationhiragana: 0x309E,
  24244. voicediterationkatakana: 0x30FE,
  24245. voicedmarkkana: 0x309B,
  24246. voicedmarkkanahalfwidth: 0xFF9E,
  24247. vokatakana: 0x30FA,
  24248. vparen: 0x24B1,
  24249. vtilde: 0x1E7D,
  24250. vturned: 0x028C,
  24251. vuhiragana: 0x3094,
  24252. vukatakana: 0x30F4,
  24253. w: 0x0077,
  24254. wacute: 0x1E83,
  24255. waekorean: 0x3159,
  24256. wahiragana: 0x308F,
  24257. wakatakana: 0x30EF,
  24258. wakatakanahalfwidth: 0xFF9C,
  24259. wakorean: 0x3158,
  24260. wasmallhiragana: 0x308E,
  24261. wasmallkatakana: 0x30EE,
  24262. wattosquare: 0x3357,
  24263. wavedash: 0x301C,
  24264. wavyunderscorevertical: 0xFE34,
  24265. wawarabic: 0x0648,
  24266. wawfinalarabic: 0xFEEE,
  24267. wawhamzaabovearabic: 0x0624,
  24268. wawhamzaabovefinalarabic: 0xFE86,
  24269. wbsquare: 0x33DD,
  24270. wcircle: 0x24E6,
  24271. wcircumflex: 0x0175,
  24272. wdieresis: 0x1E85,
  24273. wdotaccent: 0x1E87,
  24274. wdotbelow: 0x1E89,
  24275. wehiragana: 0x3091,
  24276. weierstrass: 0x2118,
  24277. wekatakana: 0x30F1,
  24278. wekorean: 0x315E,
  24279. weokorean: 0x315D,
  24280. wgrave: 0x1E81,
  24281. whitebullet: 0x25E6,
  24282. whitecircle: 0x25CB,
  24283. whitecircleinverse: 0x25D9,
  24284. whitecornerbracketleft: 0x300E,
  24285. whitecornerbracketleftvertical: 0xFE43,
  24286. whitecornerbracketright: 0x300F,
  24287. whitecornerbracketrightvertical: 0xFE44,
  24288. whitediamond: 0x25C7,
  24289. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24290. whitedownpointingsmalltriangle: 0x25BF,
  24291. whitedownpointingtriangle: 0x25BD,
  24292. whiteleftpointingsmalltriangle: 0x25C3,
  24293. whiteleftpointingtriangle: 0x25C1,
  24294. whitelenticularbracketleft: 0x3016,
  24295. whitelenticularbracketright: 0x3017,
  24296. whiterightpointingsmalltriangle: 0x25B9,
  24297. whiterightpointingtriangle: 0x25B7,
  24298. whitesmallsquare: 0x25AB,
  24299. whitesmilingface: 0x263A,
  24300. whitesquare: 0x25A1,
  24301. whitestar: 0x2606,
  24302. whitetelephone: 0x260F,
  24303. whitetortoiseshellbracketleft: 0x3018,
  24304. whitetortoiseshellbracketright: 0x3019,
  24305. whiteuppointingsmalltriangle: 0x25B5,
  24306. whiteuppointingtriangle: 0x25B3,
  24307. wihiragana: 0x3090,
  24308. wikatakana: 0x30F0,
  24309. wikorean: 0x315F,
  24310. wmonospace: 0xFF57,
  24311. wohiragana: 0x3092,
  24312. wokatakana: 0x30F2,
  24313. wokatakanahalfwidth: 0xFF66,
  24314. won: 0x20A9,
  24315. wonmonospace: 0xFFE6,
  24316. wowaenthai: 0x0E27,
  24317. wparen: 0x24B2,
  24318. wring: 0x1E98,
  24319. wsuperior: 0x02B7,
  24320. wturned: 0x028D,
  24321. wynn: 0x01BF,
  24322. x: 0x0078,
  24323. xabovecmb: 0x033D,
  24324. xbopomofo: 0x3112,
  24325. xcircle: 0x24E7,
  24326. xdieresis: 0x1E8D,
  24327. xdotaccent: 0x1E8B,
  24328. xeharmenian: 0x056D,
  24329. xi: 0x03BE,
  24330. xmonospace: 0xFF58,
  24331. xparen: 0x24B3,
  24332. xsuperior: 0x02E3,
  24333. y: 0x0079,
  24334. yaadosquare: 0x334E,
  24335. yabengali: 0x09AF,
  24336. yacute: 0x00FD,
  24337. yadeva: 0x092F,
  24338. yaekorean: 0x3152,
  24339. yagujarati: 0x0AAF,
  24340. yagurmukhi: 0x0A2F,
  24341. yahiragana: 0x3084,
  24342. yakatakana: 0x30E4,
  24343. yakatakanahalfwidth: 0xFF94,
  24344. yakorean: 0x3151,
  24345. yamakkanthai: 0x0E4E,
  24346. yasmallhiragana: 0x3083,
  24347. yasmallkatakana: 0x30E3,
  24348. yasmallkatakanahalfwidth: 0xFF6C,
  24349. yatcyrillic: 0x0463,
  24350. ycircle: 0x24E8,
  24351. ycircumflex: 0x0177,
  24352. ydieresis: 0x00FF,
  24353. ydotaccent: 0x1E8F,
  24354. ydotbelow: 0x1EF5,
  24355. yeharabic: 0x064A,
  24356. yehbarreearabic: 0x06D2,
  24357. yehbarreefinalarabic: 0xFBAF,
  24358. yehfinalarabic: 0xFEF2,
  24359. yehhamzaabovearabic: 0x0626,
  24360. yehhamzaabovefinalarabic: 0xFE8A,
  24361. yehhamzaaboveinitialarabic: 0xFE8B,
  24362. yehhamzaabovemedialarabic: 0xFE8C,
  24363. yehinitialarabic: 0xFEF3,
  24364. yehmedialarabic: 0xFEF4,
  24365. yehmeeminitialarabic: 0xFCDD,
  24366. yehmeemisolatedarabic: 0xFC58,
  24367. yehnoonfinalarabic: 0xFC94,
  24368. yehthreedotsbelowarabic: 0x06D1,
  24369. yekorean: 0x3156,
  24370. yen: 0x00A5,
  24371. yenmonospace: 0xFFE5,
  24372. yeokorean: 0x3155,
  24373. yeorinhieuhkorean: 0x3186,
  24374. yerahbenyomohebrew: 0x05AA,
  24375. yerahbenyomolefthebrew: 0x05AA,
  24376. yericyrillic: 0x044B,
  24377. yerudieresiscyrillic: 0x04F9,
  24378. yesieungkorean: 0x3181,
  24379. yesieungpansioskorean: 0x3183,
  24380. yesieungsioskorean: 0x3182,
  24381. yetivhebrew: 0x059A,
  24382. ygrave: 0x1EF3,
  24383. yhook: 0x01B4,
  24384. yhookabove: 0x1EF7,
  24385. yiarmenian: 0x0575,
  24386. yicyrillic: 0x0457,
  24387. yikorean: 0x3162,
  24388. yinyang: 0x262F,
  24389. yiwnarmenian: 0x0582,
  24390. ymonospace: 0xFF59,
  24391. yod: 0x05D9,
  24392. yoddagesh: 0xFB39,
  24393. yoddageshhebrew: 0xFB39,
  24394. yodhebrew: 0x05D9,
  24395. yodyodhebrew: 0x05F2,
  24396. yodyodpatahhebrew: 0xFB1F,
  24397. yohiragana: 0x3088,
  24398. yoikorean: 0x3189,
  24399. yokatakana: 0x30E8,
  24400. yokatakanahalfwidth: 0xFF96,
  24401. yokorean: 0x315B,
  24402. yosmallhiragana: 0x3087,
  24403. yosmallkatakana: 0x30E7,
  24404. yosmallkatakanahalfwidth: 0xFF6E,
  24405. yotgreek: 0x03F3,
  24406. yoyaekorean: 0x3188,
  24407. yoyakorean: 0x3187,
  24408. yoyakthai: 0x0E22,
  24409. yoyingthai: 0x0E0D,
  24410. yparen: 0x24B4,
  24411. ypogegrammeni: 0x037A,
  24412. ypogegrammenigreekcmb: 0x0345,
  24413. yr: 0x01A6,
  24414. yring: 0x1E99,
  24415. ysuperior: 0x02B8,
  24416. ytilde: 0x1EF9,
  24417. yturned: 0x028E,
  24418. yuhiragana: 0x3086,
  24419. yuikorean: 0x318C,
  24420. yukatakana: 0x30E6,
  24421. yukatakanahalfwidth: 0xFF95,
  24422. yukorean: 0x3160,
  24423. yusbigcyrillic: 0x046B,
  24424. yusbigiotifiedcyrillic: 0x046D,
  24425. yuslittlecyrillic: 0x0467,
  24426. yuslittleiotifiedcyrillic: 0x0469,
  24427. yusmallhiragana: 0x3085,
  24428. yusmallkatakana: 0x30E5,
  24429. yusmallkatakanahalfwidth: 0xFF6D,
  24430. yuyekorean: 0x318B,
  24431. yuyeokorean: 0x318A,
  24432. yyabengali: 0x09DF,
  24433. yyadeva: 0x095F,
  24434. z: 0x007A,
  24435. zaarmenian: 0x0566,
  24436. zacute: 0x017A,
  24437. zadeva: 0x095B,
  24438. zagurmukhi: 0x0A5B,
  24439. zaharabic: 0x0638,
  24440. zahfinalarabic: 0xFEC6,
  24441. zahinitialarabic: 0xFEC7,
  24442. zahiragana: 0x3056,
  24443. zahmedialarabic: 0xFEC8,
  24444. zainarabic: 0x0632,
  24445. zainfinalarabic: 0xFEB0,
  24446. zakatakana: 0x30B6,
  24447. zaqefgadolhebrew: 0x0595,
  24448. zaqefqatanhebrew: 0x0594,
  24449. zarqahebrew: 0x0598,
  24450. zayin: 0x05D6,
  24451. zayindagesh: 0xFB36,
  24452. zayindageshhebrew: 0xFB36,
  24453. zayinhebrew: 0x05D6,
  24454. zbopomofo: 0x3117,
  24455. zcaron: 0x017E,
  24456. zcircle: 0x24E9,
  24457. zcircumflex: 0x1E91,
  24458. zcurl: 0x0291,
  24459. zdot: 0x017C,
  24460. zdotaccent: 0x017C,
  24461. zdotbelow: 0x1E93,
  24462. zecyrillic: 0x0437,
  24463. zedescendercyrillic: 0x0499,
  24464. zedieresiscyrillic: 0x04DF,
  24465. zehiragana: 0x305C,
  24466. zekatakana: 0x30BC,
  24467. zero: 0x0030,
  24468. zeroarabic: 0x0660,
  24469. zerobengali: 0x09E6,
  24470. zerodeva: 0x0966,
  24471. zerogujarati: 0x0AE6,
  24472. zerogurmukhi: 0x0A66,
  24473. zerohackarabic: 0x0660,
  24474. zeroinferior: 0x2080,
  24475. zeromonospace: 0xFF10,
  24476. zerooldstyle: 0xF730,
  24477. zeropersian: 0x06F0,
  24478. zerosuperior: 0x2070,
  24479. zerothai: 0x0E50,
  24480. zerowidthjoiner: 0xFEFF,
  24481. zerowidthnonjoiner: 0x200C,
  24482. zerowidthspace: 0x200B,
  24483. zeta: 0x03B6,
  24484. zhbopomofo: 0x3113,
  24485. zhearmenian: 0x056A,
  24486. zhebrevecyrillic: 0x04C2,
  24487. zhecyrillic: 0x0436,
  24488. zhedescendercyrillic: 0x0497,
  24489. zhedieresiscyrillic: 0x04DD,
  24490. zihiragana: 0x3058,
  24491. zikatakana: 0x30B8,
  24492. zinorhebrew: 0x05AE,
  24493. zlinebelow: 0x1E95,
  24494. zmonospace: 0xFF5A,
  24495. zohiragana: 0x305E,
  24496. zokatakana: 0x30BE,
  24497. zparen: 0x24B5,
  24498. zretroflexhook: 0x0290,
  24499. zstroke: 0x01B6,
  24500. zuhiragana: 0x305A,
  24501. zukatakana: 0x30BA,
  24502. '.notdef': 0x0000
  24503. };
  24504. var DingbatsGlyphsUnicode = {
  24505. space: 0x0020,
  24506. a1: 0x2701,
  24507. a2: 0x2702,
  24508. a202: 0x2703,
  24509. a3: 0x2704,
  24510. a4: 0x260E,
  24511. a5: 0x2706,
  24512. a119: 0x2707,
  24513. a118: 0x2708,
  24514. a117: 0x2709,
  24515. a11: 0x261B,
  24516. a12: 0x261E,
  24517. a13: 0x270C,
  24518. a14: 0x270D,
  24519. a15: 0x270E,
  24520. a16: 0x270F,
  24521. a105: 0x2710,
  24522. a17: 0x2711,
  24523. a18: 0x2712,
  24524. a19: 0x2713,
  24525. a20: 0x2714,
  24526. a21: 0x2715,
  24527. a22: 0x2716,
  24528. a23: 0x2717,
  24529. a24: 0x2718,
  24530. a25: 0x2719,
  24531. a26: 0x271A,
  24532. a27: 0x271B,
  24533. a28: 0x271C,
  24534. a6: 0x271D,
  24535. a7: 0x271E,
  24536. a8: 0x271F,
  24537. a9: 0x2720,
  24538. a10: 0x2721,
  24539. a29: 0x2722,
  24540. a30: 0x2723,
  24541. a31: 0x2724,
  24542. a32: 0x2725,
  24543. a33: 0x2726,
  24544. a34: 0x2727,
  24545. a35: 0x2605,
  24546. a36: 0x2729,
  24547. a37: 0x272A,
  24548. a38: 0x272B,
  24549. a39: 0x272C,
  24550. a40: 0x272D,
  24551. a41: 0x272E,
  24552. a42: 0x272F,
  24553. a43: 0x2730,
  24554. a44: 0x2731,
  24555. a45: 0x2732,
  24556. a46: 0x2733,
  24557. a47: 0x2734,
  24558. a48: 0x2735,
  24559. a49: 0x2736,
  24560. a50: 0x2737,
  24561. a51: 0x2738,
  24562. a52: 0x2739,
  24563. a53: 0x273A,
  24564. a54: 0x273B,
  24565. a55: 0x273C,
  24566. a56: 0x273D,
  24567. a57: 0x273E,
  24568. a58: 0x273F,
  24569. a59: 0x2740,
  24570. a60: 0x2741,
  24571. a61: 0x2742,
  24572. a62: 0x2743,
  24573. a63: 0x2744,
  24574. a64: 0x2745,
  24575. a65: 0x2746,
  24576. a66: 0x2747,
  24577. a67: 0x2748,
  24578. a68: 0x2749,
  24579. a69: 0x274A,
  24580. a70: 0x274B,
  24581. a71: 0x25CF,
  24582. a72: 0x274D,
  24583. a73: 0x25A0,
  24584. a74: 0x274F,
  24585. a203: 0x2750,
  24586. a75: 0x2751,
  24587. a204: 0x2752,
  24588. a76: 0x25B2,
  24589. a77: 0x25BC,
  24590. a78: 0x25C6,
  24591. a79: 0x2756,
  24592. a81: 0x25D7,
  24593. a82: 0x2758,
  24594. a83: 0x2759,
  24595. a84: 0x275A,
  24596. a97: 0x275B,
  24597. a98: 0x275C,
  24598. a99: 0x275D,
  24599. a100: 0x275E,
  24600. a101: 0x2761,
  24601. a102: 0x2762,
  24602. a103: 0x2763,
  24603. a104: 0x2764,
  24604. a106: 0x2765,
  24605. a107: 0x2766,
  24606. a108: 0x2767,
  24607. a112: 0x2663,
  24608. a111: 0x2666,
  24609. a110: 0x2665,
  24610. a109: 0x2660,
  24611. a120: 0x2460,
  24612. a121: 0x2461,
  24613. a122: 0x2462,
  24614. a123: 0x2463,
  24615. a124: 0x2464,
  24616. a125: 0x2465,
  24617. a126: 0x2466,
  24618. a127: 0x2467,
  24619. a128: 0x2468,
  24620. a129: 0x2469,
  24621. a130: 0x2776,
  24622. a131: 0x2777,
  24623. a132: 0x2778,
  24624. a133: 0x2779,
  24625. a134: 0x277A,
  24626. a135: 0x277B,
  24627. a136: 0x277C,
  24628. a137: 0x277D,
  24629. a138: 0x277E,
  24630. a139: 0x277F,
  24631. a140: 0x2780,
  24632. a141: 0x2781,
  24633. a142: 0x2782,
  24634. a143: 0x2783,
  24635. a144: 0x2784,
  24636. a145: 0x2785,
  24637. a146: 0x2786,
  24638. a147: 0x2787,
  24639. a148: 0x2788,
  24640. a149: 0x2789,
  24641. a150: 0x278A,
  24642. a151: 0x278B,
  24643. a152: 0x278C,
  24644. a153: 0x278D,
  24645. a154: 0x278E,
  24646. a155: 0x278F,
  24647. a156: 0x2790,
  24648. a157: 0x2791,
  24649. a158: 0x2792,
  24650. a159: 0x2793,
  24651. a160: 0x2794,
  24652. a161: 0x2192,
  24653. a163: 0x2194,
  24654. a164: 0x2195,
  24655. a196: 0x2798,
  24656. a165: 0x2799,
  24657. a192: 0x279A,
  24658. a166: 0x279B,
  24659. a167: 0x279C,
  24660. a168: 0x279D,
  24661. a169: 0x279E,
  24662. a170: 0x279F,
  24663. a171: 0x27A0,
  24664. a172: 0x27A1,
  24665. a173: 0x27A2,
  24666. a162: 0x27A3,
  24667. a174: 0x27A4,
  24668. a175: 0x27A5,
  24669. a176: 0x27A6,
  24670. a177: 0x27A7,
  24671. a178: 0x27A8,
  24672. a179: 0x27A9,
  24673. a193: 0x27AA,
  24674. a180: 0x27AB,
  24675. a199: 0x27AC,
  24676. a181: 0x27AD,
  24677. a200: 0x27AE,
  24678. a182: 0x27AF,
  24679. a201: 0x27B1,
  24680. a183: 0x27B2,
  24681. a184: 0x27B3,
  24682. a197: 0x27B4,
  24683. a185: 0x27B5,
  24684. a194: 0x27B6,
  24685. a198: 0x27B7,
  24686. a186: 0x27B8,
  24687. a195: 0x27B9,
  24688. a187: 0x27BA,
  24689. a188: 0x27BB,
  24690. a189: 0x27BC,
  24691. a190: 0x27BD,
  24692. a191: 0x27BE,
  24693. a89: 0x2768, // 0xF8D7
  24694. a90: 0x2769, // 0xF8D8
  24695. a93: 0x276A, // 0xF8D9
  24696. a94: 0x276B, // 0xF8DA
  24697. a91: 0x276C, // 0xF8DB
  24698. a92: 0x276D, // 0xF8DC
  24699. a205: 0x276E, // 0xF8DD
  24700. a85: 0x276F, // 0xF8DE
  24701. a206: 0x2770, // 0xF8DF
  24702. a86: 0x2771, // 0xF8E0
  24703. a87: 0x2772, // 0xF8E1
  24704. a88: 0x2773, // 0xF8E2
  24705. a95: 0x2774, // 0xF8E3
  24706. a96: 0x2775, // 0xF8E4
  24707. '.notdef': 0x0000
  24708. };
  24709. var PDFImage = (function PDFImageClosure() {
  24710. /**
  24711. * Decode the image in the main thread if it supported. Resovles the promise
  24712. * when the image data is ready.
  24713. */
  24714. function handleImageData(handler, xref, res, image) {
  24715. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  24716. // For natively supported jpegs send them to the main thread for decoding.
  24717. var dict = image.dict;
  24718. var colorSpace = dict.get('ColorSpace', 'CS');
  24719. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24720. var numComps = colorSpace.numComps;
  24721. var decodePromise = handler.sendWithPromise('JpegDecode',
  24722. [image.getIR(), numComps]);
  24723. return decodePromise.then(function (message) {
  24724. var data = message.data;
  24725. return new Stream(data, 0, data.length, image.dict);
  24726. });
  24727. } else {
  24728. return Promise.resolve(image);
  24729. }
  24730. }
  24731. /**
  24732. * Decode and clamp a value. The formula is different from the spec because we
  24733. * don't decode to float range [0,1], we decode it in the [0,max] range.
  24734. */
  24735. function decodeAndClamp(value, addend, coefficient, max) {
  24736. value = addend + value * coefficient;
  24737. // Clamp the value to the range
  24738. return (value < 0 ? 0 : (value > max ? max : value));
  24739. }
  24740. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  24741. this.image = image;
  24742. var dict = image.dict;
  24743. if (dict.has('Filter')) {
  24744. var filter = dict.get('Filter').name;
  24745. if (filter === 'JPXDecode') {
  24746. var jpxImage = new JpxImage();
  24747. jpxImage.parseImageProperties(image.stream);
  24748. image.stream.reset();
  24749. image.bitsPerComponent = jpxImage.bitsPerComponent;
  24750. image.numComps = jpxImage.componentsCount;
  24751. } else if (filter === 'JBIG2Decode') {
  24752. image.bitsPerComponent = 1;
  24753. image.numComps = 1;
  24754. }
  24755. }
  24756. // TODO cache rendered images?
  24757. this.width = dict.get('Width', 'W');
  24758. this.height = dict.get('Height', 'H');
  24759. if (this.width < 1 || this.height < 1) {
  24760. error('Invalid image width: ' + this.width + ' or height: ' +
  24761. this.height);
  24762. }
  24763. this.interpolate = dict.get('Interpolate', 'I') || false;
  24764. this.imageMask = dict.get('ImageMask', 'IM') || false;
  24765. this.matte = dict.get('Matte') || false;
  24766. var bitsPerComponent = image.bitsPerComponent;
  24767. if (!bitsPerComponent) {
  24768. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  24769. if (!bitsPerComponent) {
  24770. if (this.imageMask) {
  24771. bitsPerComponent = 1;
  24772. } else {
  24773. error('Bits per component missing in image: ' + this.imageMask);
  24774. }
  24775. }
  24776. }
  24777. this.bpc = bitsPerComponent;
  24778. if (!this.imageMask) {
  24779. var colorSpace = dict.get('ColorSpace', 'CS');
  24780. if (!colorSpace) {
  24781. info('JPX images (which do not require color spaces)');
  24782. switch (image.numComps) {
  24783. case 1:
  24784. colorSpace = Name.get('DeviceGray');
  24785. break;
  24786. case 3:
  24787. colorSpace = Name.get('DeviceRGB');
  24788. break;
  24789. case 4:
  24790. colorSpace = Name.get('DeviceCMYK');
  24791. break;
  24792. default:
  24793. error('JPX images with ' + this.numComps +
  24794. ' color components not supported.');
  24795. }
  24796. }
  24797. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  24798. this.numComps = this.colorSpace.numComps;
  24799. }
  24800. this.decode = dict.get('Decode', 'D');
  24801. this.needsDecode = false;
  24802. if (this.decode &&
  24803. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  24804. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  24805. this.needsDecode = true;
  24806. // Do some preprocessing to avoid more math.
  24807. var max = (1 << bitsPerComponent) - 1;
  24808. this.decodeCoefficients = [];
  24809. this.decodeAddends = [];
  24810. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  24811. var dmin = this.decode[i];
  24812. var dmax = this.decode[i + 1];
  24813. this.decodeCoefficients[j] = dmax - dmin;
  24814. this.decodeAddends[j] = max * dmin;
  24815. }
  24816. }
  24817. if (smask) {
  24818. this.smask = new PDFImage(xref, res, smask, false);
  24819. } else if (mask) {
  24820. if (isStream(mask)) {
  24821. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  24822. } else {
  24823. // Color key mask (just an array).
  24824. this.mask = mask;
  24825. }
  24826. }
  24827. }
  24828. /**
  24829. * Handles processing of image data and returns the Promise that is resolved
  24830. * with a PDFImage when the image is ready to be used.
  24831. */
  24832. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  24833. res, image, inline) {
  24834. var imagePromise = handleImageData(handler, xref, res, image);
  24835. var smaskPromise;
  24836. var maskPromise;
  24837. var smask = image.dict.get('SMask');
  24838. var mask = image.dict.get('Mask');
  24839. if (smask) {
  24840. smaskPromise = handleImageData(handler, xref, res, smask);
  24841. maskPromise = Promise.resolve(null);
  24842. } else {
  24843. smaskPromise = Promise.resolve(null);
  24844. if (mask) {
  24845. if (isStream(mask)) {
  24846. maskPromise = handleImageData(handler, xref, res, mask);
  24847. } else if (isArray(mask)) {
  24848. maskPromise = Promise.resolve(mask);
  24849. } else {
  24850. warn('Unsupported mask format.');
  24851. maskPromise = Promise.resolve(null);
  24852. }
  24853. } else {
  24854. maskPromise = Promise.resolve(null);
  24855. }
  24856. }
  24857. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  24858. function(results) {
  24859. var imageData = results[0];
  24860. var smaskData = results[1];
  24861. var maskData = results[2];
  24862. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  24863. });
  24864. };
  24865. /**
  24866. * Resize an image using the nearest neighbor algorithm. Currently only
  24867. * supports one and three component images.
  24868. * @param {TypedArray} pixels The original image with one component.
  24869. * @param {Number} bpc Number of bits per component.
  24870. * @param {Number} components Number of color components, 1 or 3 is supported.
  24871. * @param {Number} w1 Original width.
  24872. * @param {Number} h1 Original height.
  24873. * @param {Number} w2 New width.
  24874. * @param {Number} h2 New height.
  24875. * @param {TypedArray} dest (Optional) The destination buffer.
  24876. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  24877. * @return {TypedArray} Resized image data.
  24878. */
  24879. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  24880. w1, h1, w2, h2, dest, alpha01) {
  24881. if (components !== 1 && components !== 3) {
  24882. error('Unsupported component count for resizing.');
  24883. }
  24884. var length = w2 * h2 * components;
  24885. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  24886. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  24887. var xRatio = w1 / w2;
  24888. var yRatio = h1 / h2;
  24889. var i, j, py, newIndex = 0, oldIndex;
  24890. var xScaled = new Uint16Array(w2);
  24891. var w1Scanline = w1 * components;
  24892. if (alpha01 !== 1) {
  24893. alpha01 = 0;
  24894. }
  24895. for (j = 0; j < w2; j++) {
  24896. xScaled[j] = Math.floor(j * xRatio) * components;
  24897. }
  24898. if (components === 1) {
  24899. for (i = 0; i < h2; i++) {
  24900. py = Math.floor(i * yRatio) * w1Scanline;
  24901. for (j = 0; j < w2; j++) {
  24902. oldIndex = py + xScaled[j];
  24903. temp[newIndex++] = pixels[oldIndex];
  24904. }
  24905. }
  24906. } else if (components === 3) {
  24907. for (i = 0; i < h2; i++) {
  24908. py = Math.floor(i * yRatio) * w1Scanline;
  24909. for (j = 0; j < w2; j++) {
  24910. oldIndex = py + xScaled[j];
  24911. temp[newIndex++] = pixels[oldIndex++];
  24912. temp[newIndex++] = pixels[oldIndex++];
  24913. temp[newIndex++] = pixels[oldIndex++];
  24914. newIndex += alpha01;
  24915. }
  24916. }
  24917. }
  24918. return temp;
  24919. };
  24920. PDFImage.createMask =
  24921. function PDFImage_createMask(imgArray, width, height,
  24922. imageIsFromDecodeStream, inverseDecode) {
  24923. // |imgArray| might not contain full data for every pixel of the mask, so
  24924. // we need to distinguish between |computedLength| and |actualLength|.
  24925. // In particular, if inverseDecode is true, then the array we return must
  24926. // have a length of |computedLength|.
  24927. var computedLength = ((width + 7) >> 3) * height;
  24928. var actualLength = imgArray.byteLength;
  24929. var haveFullData = computedLength === actualLength;
  24930. var data, i;
  24931. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  24932. // imgArray came from a DecodeStream and its data is in an appropriate
  24933. // form, so we can just transfer it.
  24934. data = imgArray;
  24935. } else if (!inverseDecode) {
  24936. data = new Uint8Array(actualLength);
  24937. data.set(imgArray);
  24938. } else {
  24939. data = new Uint8Array(computedLength);
  24940. data.set(imgArray);
  24941. for (i = actualLength; i < computedLength; i++) {
  24942. data[i] = 0xff;
  24943. }
  24944. }
  24945. // If necessary, invert the original mask data (but not any extra we might
  24946. // have added above). It's safe to modify the array -- whether it's the
  24947. // original or a copy, we're about to transfer it anyway, so nothing else
  24948. // in this thread can be relying on its contents.
  24949. if (inverseDecode) {
  24950. for (i = 0; i < actualLength; i++) {
  24951. data[i] = ~data[i];
  24952. }
  24953. }
  24954. return {data: data, width: width, height: height};
  24955. };
  24956. PDFImage.prototype = {
  24957. get drawWidth() {
  24958. return Math.max(this.width,
  24959. this.smask && this.smask.width || 0,
  24960. this.mask && this.mask.width || 0);
  24961. },
  24962. get drawHeight() {
  24963. return Math.max(this.height,
  24964. this.smask && this.smask.height || 0,
  24965. this.mask && this.mask.height || 0);
  24966. },
  24967. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  24968. var bpc = this.bpc;
  24969. var numComps = this.numComps;
  24970. var decodeAddends = this.decodeAddends;
  24971. var decodeCoefficients = this.decodeCoefficients;
  24972. var max = (1 << bpc) - 1;
  24973. var i, ii;
  24974. if (bpc === 1) {
  24975. // If the buffer needed decode that means it just needs to be inverted.
  24976. for (i = 0, ii = buffer.length; i < ii; i++) {
  24977. buffer[i] = +!(buffer[i]);
  24978. }
  24979. return;
  24980. }
  24981. var index = 0;
  24982. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  24983. for (var j = 0; j < numComps; j++) {
  24984. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  24985. decodeCoefficients[j], max);
  24986. index++;
  24987. }
  24988. }
  24989. },
  24990. getComponents: function PDFImage_getComponents(buffer) {
  24991. var bpc = this.bpc;
  24992. // This image doesn't require any extra work.
  24993. if (bpc === 8) {
  24994. return buffer;
  24995. }
  24996. var width = this.width;
  24997. var height = this.height;
  24998. var numComps = this.numComps;
  24999. var length = width * height * numComps;
  25000. var bufferPos = 0;
  25001. var output = (bpc <= 8 ? new Uint8Array(length) :
  25002. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25003. var rowComps = width * numComps;
  25004. var max = (1 << bpc) - 1;
  25005. var i = 0, ii, buf;
  25006. if (bpc === 1) {
  25007. // Optimization for reading 1 bpc images.
  25008. var mask, loop1End, loop2End;
  25009. for (var j = 0; j < height; j++) {
  25010. loop1End = i + (rowComps & ~7);
  25011. loop2End = i + rowComps;
  25012. // unroll loop for all full bytes
  25013. while (i < loop1End) {
  25014. buf = buffer[bufferPos++];
  25015. output[i] = (buf >> 7) & 1;
  25016. output[i + 1] = (buf >> 6) & 1;
  25017. output[i + 2] = (buf >> 5) & 1;
  25018. output[i + 3] = (buf >> 4) & 1;
  25019. output[i + 4] = (buf >> 3) & 1;
  25020. output[i + 5] = (buf >> 2) & 1;
  25021. output[i + 6] = (buf >> 1) & 1;
  25022. output[i + 7] = buf & 1;
  25023. i += 8;
  25024. }
  25025. // handle remaing bits
  25026. if (i < loop2End) {
  25027. buf = buffer[bufferPos++];
  25028. mask = 128;
  25029. while (i < loop2End) {
  25030. output[i++] = +!!(buf & mask);
  25031. mask >>= 1;
  25032. }
  25033. }
  25034. }
  25035. } else {
  25036. // The general case that handles all other bpc values.
  25037. var bits = 0;
  25038. buf = 0;
  25039. for (i = 0, ii = length; i < ii; ++i) {
  25040. if (i % rowComps === 0) {
  25041. buf = 0;
  25042. bits = 0;
  25043. }
  25044. while (bits < bpc) {
  25045. buf = (buf << 8) | buffer[bufferPos++];
  25046. bits += 8;
  25047. }
  25048. var remainingBits = bits - bpc;
  25049. var value = buf >> remainingBits;
  25050. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25051. buf = buf & ((1 << remainingBits) - 1);
  25052. bits = remainingBits;
  25053. }
  25054. }
  25055. return output;
  25056. },
  25057. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25058. actualHeight, image) {
  25059. var smask = this.smask;
  25060. var mask = this.mask;
  25061. var alphaBuf, sw, sh, i, ii, j;
  25062. if (smask) {
  25063. sw = smask.width;
  25064. sh = smask.height;
  25065. alphaBuf = new Uint8Array(sw * sh);
  25066. smask.fillGrayBuffer(alphaBuf);
  25067. if (sw !== width || sh !== height) {
  25068. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25069. height);
  25070. }
  25071. } else if (mask) {
  25072. if (mask instanceof PDFImage) {
  25073. sw = mask.width;
  25074. sh = mask.height;
  25075. alphaBuf = new Uint8Array(sw * sh);
  25076. mask.numComps = 1;
  25077. mask.fillGrayBuffer(alphaBuf);
  25078. // Need to invert values in rgbaBuf
  25079. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25080. alphaBuf[i] = 255 - alphaBuf[i];
  25081. }
  25082. if (sw !== width || sh !== height) {
  25083. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25084. height);
  25085. }
  25086. } else if (isArray(mask)) {
  25087. // Color key mask: if any of the compontents are outside the range
  25088. // then they should be painted.
  25089. alphaBuf = new Uint8Array(width * height);
  25090. var numComps = this.numComps;
  25091. for (i = 0, ii = width * height; i < ii; ++i) {
  25092. var opacity = 0;
  25093. var imageOffset = i * numComps;
  25094. for (j = 0; j < numComps; ++j) {
  25095. var color = image[imageOffset + j];
  25096. var maskOffset = j * 2;
  25097. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25098. opacity = 255;
  25099. break;
  25100. }
  25101. }
  25102. alphaBuf[i] = opacity;
  25103. }
  25104. } else {
  25105. error('Unknown mask format.');
  25106. }
  25107. }
  25108. if (alphaBuf) {
  25109. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25110. rgbaBuf[j] = alphaBuf[i];
  25111. }
  25112. } else {
  25113. // No mask.
  25114. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25115. rgbaBuf[j] = 255;
  25116. }
  25117. }
  25118. },
  25119. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25120. var matte = this.smask && this.smask.matte;
  25121. if (!matte) {
  25122. return;
  25123. }
  25124. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25125. var matteR = matteRgb[0];
  25126. var matteG = matteRgb[1];
  25127. var matteB = matteRgb[2];
  25128. var length = width * height * 4;
  25129. var r, g, b;
  25130. for (var i = 0; i < length; i += 4) {
  25131. var alpha = buffer[i + 3];
  25132. if (alpha === 0) {
  25133. // according formula we have to get Infinity in all components
  25134. // making it white (typical paper color) should be okay
  25135. buffer[i] = 255;
  25136. buffer[i + 1] = 255;
  25137. buffer[i + 2] = 255;
  25138. continue;
  25139. }
  25140. var k = 255 / alpha;
  25141. r = (buffer[i] - matteR) * k + matteR;
  25142. g = (buffer[i + 1] - matteG) * k + matteG;
  25143. b = (buffer[i + 2] - matteB) * k + matteB;
  25144. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25145. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25146. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25147. }
  25148. },
  25149. createImageData: function PDFImage_createImageData(forceRGBA) {
  25150. var drawWidth = this.drawWidth;
  25151. var drawHeight = this.drawHeight;
  25152. var imgData = { // other fields are filled in below
  25153. width: drawWidth,
  25154. height: drawHeight
  25155. };
  25156. var numComps = this.numComps;
  25157. var originalWidth = this.width;
  25158. var originalHeight = this.height;
  25159. var bpc = this.bpc;
  25160. // Rows start at byte boundary.
  25161. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25162. var imgArray;
  25163. if (!forceRGBA) {
  25164. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25165. // without any complications, we pass a same-sized copy to the main
  25166. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25167. // of memory for many scanned documents. It's also much faster.
  25168. //
  25169. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25170. // complications, we avoid expanding by 1.333x to RGBA form.
  25171. var kind;
  25172. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25173. kind = ImageKind.GRAYSCALE_1BPP;
  25174. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25175. !this.needsDecode) {
  25176. kind = ImageKind.RGB_24BPP;
  25177. }
  25178. if (kind && !this.smask && !this.mask &&
  25179. drawWidth === originalWidth && drawHeight === originalHeight) {
  25180. imgData.kind = kind;
  25181. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25182. // If imgArray came from a DecodeStream, we're safe to transfer it
  25183. // (and thus neuter it) because it will constitute the entire
  25184. // DecodeStream's data. But if it came from a Stream, we need to
  25185. // copy it because it'll only be a portion of the Stream's data, and
  25186. // the rest will be read later on.
  25187. if (this.image instanceof DecodeStream) {
  25188. imgData.data = imgArray;
  25189. } else {
  25190. var newArray = new Uint8Array(imgArray.length);
  25191. newArray.set(imgArray);
  25192. imgData.data = newArray;
  25193. }
  25194. if (this.needsDecode) {
  25195. // Invert the buffer (which must be grayscale if we reached here).
  25196. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25197. var buffer = imgData.data;
  25198. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25199. buffer[i] ^= 0xff;
  25200. }
  25201. }
  25202. return imgData;
  25203. }
  25204. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25205. imgData.kind = ImageKind.RGB_24BPP;
  25206. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25207. drawWidth, drawHeight, true);
  25208. return imgData;
  25209. }
  25210. }
  25211. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25212. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25213. var actualHeight = 0 | (imgArray.length / rowBytes *
  25214. drawHeight / originalHeight);
  25215. var comps = this.getComponents(imgArray);
  25216. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25217. // more compact RGB_24BPP form if allowable.
  25218. var alpha01, maybeUndoPreblend;
  25219. if (!forceRGBA && !this.smask && !this.mask) {
  25220. imgData.kind = ImageKind.RGB_24BPP;
  25221. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25222. alpha01 = 0;
  25223. maybeUndoPreblend = false;
  25224. } else {
  25225. imgData.kind = ImageKind.RGBA_32BPP;
  25226. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25227. alpha01 = 1;
  25228. maybeUndoPreblend = true;
  25229. // Color key masking (opacity) must be performed before decoding.
  25230. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25231. comps);
  25232. }
  25233. if (this.needsDecode) {
  25234. this.decodeBuffer(comps);
  25235. }
  25236. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25237. drawWidth, drawHeight, actualHeight, bpc, comps,
  25238. alpha01);
  25239. if (maybeUndoPreblend) {
  25240. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25241. }
  25242. return imgData;
  25243. },
  25244. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25245. var numComps = this.numComps;
  25246. if (numComps !== 1) {
  25247. error('Reading gray scale from a color image: ' + numComps);
  25248. }
  25249. var width = this.width;
  25250. var height = this.height;
  25251. var bpc = this.bpc;
  25252. // rows start at byte boundary
  25253. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25254. var imgArray = this.getImageBytes(height * rowBytes);
  25255. var comps = this.getComponents(imgArray);
  25256. var i, length;
  25257. if (bpc === 1) {
  25258. // inline decoding (= inversion) for 1 bpc images
  25259. length = width * height;
  25260. if (this.needsDecode) {
  25261. // invert and scale to {0, 255}
  25262. for (i = 0; i < length; ++i) {
  25263. buffer[i] = (comps[i] - 1) & 255;
  25264. }
  25265. } else {
  25266. // scale to {0, 255}
  25267. for (i = 0; i < length; ++i) {
  25268. buffer[i] = (-comps[i]) & 255;
  25269. }
  25270. }
  25271. return;
  25272. }
  25273. if (this.needsDecode) {
  25274. this.decodeBuffer(comps);
  25275. }
  25276. length = width * height;
  25277. // we aren't using a colorspace so we need to scale the value
  25278. var scale = 255 / ((1 << bpc) - 1);
  25279. for (i = 0; i < length; ++i) {
  25280. buffer[i] = (scale * comps[i]) | 0;
  25281. }
  25282. },
  25283. getImageBytes: function PDFImage_getImageBytes(length,
  25284. drawWidth, drawHeight,
  25285. forceRGB) {
  25286. this.image.reset();
  25287. this.image.drawWidth = drawWidth || this.width;
  25288. this.image.drawHeight = drawHeight || this.height;
  25289. this.image.forceRGB = !!forceRGB;
  25290. return this.image.getBytes(length);
  25291. }
  25292. };
  25293. return PDFImage;
  25294. })();
  25295. // The Metrics object contains glyph widths (in glyph space units).
  25296. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25297. // space unit corresponds to 1/1000th of text space unit.
  25298. var Metrics = {
  25299. 'Courier': 600,
  25300. 'Courier-Bold': 600,
  25301. 'Courier-BoldOblique': 600,
  25302. 'Courier-Oblique': 600,
  25303. 'Helvetica' : {
  25304. 'space': 278,
  25305. 'exclam': 278,
  25306. 'quotedbl': 355,
  25307. 'numbersign': 556,
  25308. 'dollar': 556,
  25309. 'percent': 889,
  25310. 'ampersand': 667,
  25311. 'quoteright': 222,
  25312. 'parenleft': 333,
  25313. 'parenright': 333,
  25314. 'asterisk': 389,
  25315. 'plus': 584,
  25316. 'comma': 278,
  25317. 'hyphen': 333,
  25318. 'period': 278,
  25319. 'slash': 278,
  25320. 'zero': 556,
  25321. 'one': 556,
  25322. 'two': 556,
  25323. 'three': 556,
  25324. 'four': 556,
  25325. 'five': 556,
  25326. 'six': 556,
  25327. 'seven': 556,
  25328. 'eight': 556,
  25329. 'nine': 556,
  25330. 'colon': 278,
  25331. 'semicolon': 278,
  25332. 'less': 584,
  25333. 'equal': 584,
  25334. 'greater': 584,
  25335. 'question': 556,
  25336. 'at': 1015,
  25337. 'A': 667,
  25338. 'B': 667,
  25339. 'C': 722,
  25340. 'D': 722,
  25341. 'E': 667,
  25342. 'F': 611,
  25343. 'G': 778,
  25344. 'H': 722,
  25345. 'I': 278,
  25346. 'J': 500,
  25347. 'K': 667,
  25348. 'L': 556,
  25349. 'M': 833,
  25350. 'N': 722,
  25351. 'O': 778,
  25352. 'P': 667,
  25353. 'Q': 778,
  25354. 'R': 722,
  25355. 'S': 667,
  25356. 'T': 611,
  25357. 'U': 722,
  25358. 'V': 667,
  25359. 'W': 944,
  25360. 'X': 667,
  25361. 'Y': 667,
  25362. 'Z': 611,
  25363. 'bracketleft': 278,
  25364. 'backslash': 278,
  25365. 'bracketright': 278,
  25366. 'asciicircum': 469,
  25367. 'underscore': 556,
  25368. 'quoteleft': 222,
  25369. 'a': 556,
  25370. 'b': 556,
  25371. 'c': 500,
  25372. 'd': 556,
  25373. 'e': 556,
  25374. 'f': 278,
  25375. 'g': 556,
  25376. 'h': 556,
  25377. 'i': 222,
  25378. 'j': 222,
  25379. 'k': 500,
  25380. 'l': 222,
  25381. 'm': 833,
  25382. 'n': 556,
  25383. 'o': 556,
  25384. 'p': 556,
  25385. 'q': 556,
  25386. 'r': 333,
  25387. 's': 500,
  25388. 't': 278,
  25389. 'u': 556,
  25390. 'v': 500,
  25391. 'w': 722,
  25392. 'x': 500,
  25393. 'y': 500,
  25394. 'z': 500,
  25395. 'braceleft': 334,
  25396. 'bar': 260,
  25397. 'braceright': 334,
  25398. 'asciitilde': 584,
  25399. 'exclamdown': 333,
  25400. 'cent': 556,
  25401. 'sterling': 556,
  25402. 'fraction': 167,
  25403. 'yen': 556,
  25404. 'florin': 556,
  25405. 'section': 556,
  25406. 'currency': 556,
  25407. 'quotesingle': 191,
  25408. 'quotedblleft': 333,
  25409. 'guillemotleft': 556,
  25410. 'guilsinglleft': 333,
  25411. 'guilsinglright': 333,
  25412. 'fi': 500,
  25413. 'fl': 500,
  25414. 'endash': 556,
  25415. 'dagger': 556,
  25416. 'daggerdbl': 556,
  25417. 'periodcentered': 278,
  25418. 'paragraph': 537,
  25419. 'bullet': 350,
  25420. 'quotesinglbase': 222,
  25421. 'quotedblbase': 333,
  25422. 'quotedblright': 333,
  25423. 'guillemotright': 556,
  25424. 'ellipsis': 1000,
  25425. 'perthousand': 1000,
  25426. 'questiondown': 611,
  25427. 'grave': 333,
  25428. 'acute': 333,
  25429. 'circumflex': 333,
  25430. 'tilde': 333,
  25431. 'macron': 333,
  25432. 'breve': 333,
  25433. 'dotaccent': 333,
  25434. 'dieresis': 333,
  25435. 'ring': 333,
  25436. 'cedilla': 333,
  25437. 'hungarumlaut': 333,
  25438. 'ogonek': 333,
  25439. 'caron': 333,
  25440. 'emdash': 1000,
  25441. 'AE': 1000,
  25442. 'ordfeminine': 370,
  25443. 'Lslash': 556,
  25444. 'Oslash': 778,
  25445. 'OE': 1000,
  25446. 'ordmasculine': 365,
  25447. 'ae': 889,
  25448. 'dotlessi': 278,
  25449. 'lslash': 222,
  25450. 'oslash': 611,
  25451. 'oe': 944,
  25452. 'germandbls': 611,
  25453. 'Idieresis': 278,
  25454. 'eacute': 556,
  25455. 'abreve': 556,
  25456. 'uhungarumlaut': 556,
  25457. 'ecaron': 556,
  25458. 'Ydieresis': 667,
  25459. 'divide': 584,
  25460. 'Yacute': 667,
  25461. 'Acircumflex': 667,
  25462. 'aacute': 556,
  25463. 'Ucircumflex': 722,
  25464. 'yacute': 500,
  25465. 'scommaaccent': 500,
  25466. 'ecircumflex': 556,
  25467. 'Uring': 722,
  25468. 'Udieresis': 722,
  25469. 'aogonek': 556,
  25470. 'Uacute': 722,
  25471. 'uogonek': 556,
  25472. 'Edieresis': 667,
  25473. 'Dcroat': 722,
  25474. 'commaaccent': 250,
  25475. 'copyright': 737,
  25476. 'Emacron': 667,
  25477. 'ccaron': 500,
  25478. 'aring': 556,
  25479. 'Ncommaaccent': 722,
  25480. 'lacute': 222,
  25481. 'agrave': 556,
  25482. 'Tcommaaccent': 611,
  25483. 'Cacute': 722,
  25484. 'atilde': 556,
  25485. 'Edotaccent': 667,
  25486. 'scaron': 500,
  25487. 'scedilla': 500,
  25488. 'iacute': 278,
  25489. 'lozenge': 471,
  25490. 'Rcaron': 722,
  25491. 'Gcommaaccent': 778,
  25492. 'ucircumflex': 556,
  25493. 'acircumflex': 556,
  25494. 'Amacron': 667,
  25495. 'rcaron': 333,
  25496. 'ccedilla': 500,
  25497. 'Zdotaccent': 611,
  25498. 'Thorn': 667,
  25499. 'Omacron': 778,
  25500. 'Racute': 722,
  25501. 'Sacute': 667,
  25502. 'dcaron': 643,
  25503. 'Umacron': 722,
  25504. 'uring': 556,
  25505. 'threesuperior': 333,
  25506. 'Ograve': 778,
  25507. 'Agrave': 667,
  25508. 'Abreve': 667,
  25509. 'multiply': 584,
  25510. 'uacute': 556,
  25511. 'Tcaron': 611,
  25512. 'partialdiff': 476,
  25513. 'ydieresis': 500,
  25514. 'Nacute': 722,
  25515. 'icircumflex': 278,
  25516. 'Ecircumflex': 667,
  25517. 'adieresis': 556,
  25518. 'edieresis': 556,
  25519. 'cacute': 500,
  25520. 'nacute': 556,
  25521. 'umacron': 556,
  25522. 'Ncaron': 722,
  25523. 'Iacute': 278,
  25524. 'plusminus': 584,
  25525. 'brokenbar': 260,
  25526. 'registered': 737,
  25527. 'Gbreve': 778,
  25528. 'Idotaccent': 278,
  25529. 'summation': 600,
  25530. 'Egrave': 667,
  25531. 'racute': 333,
  25532. 'omacron': 556,
  25533. 'Zacute': 611,
  25534. 'Zcaron': 611,
  25535. 'greaterequal': 549,
  25536. 'Eth': 722,
  25537. 'Ccedilla': 722,
  25538. 'lcommaaccent': 222,
  25539. 'tcaron': 317,
  25540. 'eogonek': 556,
  25541. 'Uogonek': 722,
  25542. 'Aacute': 667,
  25543. 'Adieresis': 667,
  25544. 'egrave': 556,
  25545. 'zacute': 500,
  25546. 'iogonek': 222,
  25547. 'Oacute': 778,
  25548. 'oacute': 556,
  25549. 'amacron': 556,
  25550. 'sacute': 500,
  25551. 'idieresis': 278,
  25552. 'Ocircumflex': 778,
  25553. 'Ugrave': 722,
  25554. 'Delta': 612,
  25555. 'thorn': 556,
  25556. 'twosuperior': 333,
  25557. 'Odieresis': 778,
  25558. 'mu': 556,
  25559. 'igrave': 278,
  25560. 'ohungarumlaut': 556,
  25561. 'Eogonek': 667,
  25562. 'dcroat': 556,
  25563. 'threequarters': 834,
  25564. 'Scedilla': 667,
  25565. 'lcaron': 299,
  25566. 'Kcommaaccent': 667,
  25567. 'Lacute': 556,
  25568. 'trademark': 1000,
  25569. 'edotaccent': 556,
  25570. 'Igrave': 278,
  25571. 'Imacron': 278,
  25572. 'Lcaron': 556,
  25573. 'onehalf': 834,
  25574. 'lessequal': 549,
  25575. 'ocircumflex': 556,
  25576. 'ntilde': 556,
  25577. 'Uhungarumlaut': 722,
  25578. 'Eacute': 667,
  25579. 'emacron': 556,
  25580. 'gbreve': 556,
  25581. 'onequarter': 834,
  25582. 'Scaron': 667,
  25583. 'Scommaaccent': 667,
  25584. 'Ohungarumlaut': 778,
  25585. 'degree': 400,
  25586. 'ograve': 556,
  25587. 'Ccaron': 722,
  25588. 'ugrave': 556,
  25589. 'radical': 453,
  25590. 'Dcaron': 722,
  25591. 'rcommaaccent': 333,
  25592. 'Ntilde': 722,
  25593. 'otilde': 556,
  25594. 'Rcommaaccent': 722,
  25595. 'Lcommaaccent': 556,
  25596. 'Atilde': 667,
  25597. 'Aogonek': 667,
  25598. 'Aring': 667,
  25599. 'Otilde': 778,
  25600. 'zdotaccent': 500,
  25601. 'Ecaron': 667,
  25602. 'Iogonek': 278,
  25603. 'kcommaaccent': 500,
  25604. 'minus': 584,
  25605. 'Icircumflex': 278,
  25606. 'ncaron': 556,
  25607. 'tcommaaccent': 278,
  25608. 'logicalnot': 584,
  25609. 'odieresis': 556,
  25610. 'udieresis': 556,
  25611. 'notequal': 549,
  25612. 'gcommaaccent': 556,
  25613. 'eth': 556,
  25614. 'zcaron': 500,
  25615. 'ncommaaccent': 556,
  25616. 'onesuperior': 333,
  25617. 'imacron': 278,
  25618. 'Euro': 556
  25619. },
  25620. 'Helvetica-Bold': {
  25621. 'space': 278,
  25622. 'exclam': 333,
  25623. 'quotedbl': 474,
  25624. 'numbersign': 556,
  25625. 'dollar': 556,
  25626. 'percent': 889,
  25627. 'ampersand': 722,
  25628. 'quoteright': 278,
  25629. 'parenleft': 333,
  25630. 'parenright': 333,
  25631. 'asterisk': 389,
  25632. 'plus': 584,
  25633. 'comma': 278,
  25634. 'hyphen': 333,
  25635. 'period': 278,
  25636. 'slash': 278,
  25637. 'zero': 556,
  25638. 'one': 556,
  25639. 'two': 556,
  25640. 'three': 556,
  25641. 'four': 556,
  25642. 'five': 556,
  25643. 'six': 556,
  25644. 'seven': 556,
  25645. 'eight': 556,
  25646. 'nine': 556,
  25647. 'colon': 333,
  25648. 'semicolon': 333,
  25649. 'less': 584,
  25650. 'equal': 584,
  25651. 'greater': 584,
  25652. 'question': 611,
  25653. 'at': 975,
  25654. 'A': 722,
  25655. 'B': 722,
  25656. 'C': 722,
  25657. 'D': 722,
  25658. 'E': 667,
  25659. 'F': 611,
  25660. 'G': 778,
  25661. 'H': 722,
  25662. 'I': 278,
  25663. 'J': 556,
  25664. 'K': 722,
  25665. 'L': 611,
  25666. 'M': 833,
  25667. 'N': 722,
  25668. 'O': 778,
  25669. 'P': 667,
  25670. 'Q': 778,
  25671. 'R': 722,
  25672. 'S': 667,
  25673. 'T': 611,
  25674. 'U': 722,
  25675. 'V': 667,
  25676. 'W': 944,
  25677. 'X': 667,
  25678. 'Y': 667,
  25679. 'Z': 611,
  25680. 'bracketleft': 333,
  25681. 'backslash': 278,
  25682. 'bracketright': 333,
  25683. 'asciicircum': 584,
  25684. 'underscore': 556,
  25685. 'quoteleft': 278,
  25686. 'a': 556,
  25687. 'b': 611,
  25688. 'c': 556,
  25689. 'd': 611,
  25690. 'e': 556,
  25691. 'f': 333,
  25692. 'g': 611,
  25693. 'h': 611,
  25694. 'i': 278,
  25695. 'j': 278,
  25696. 'k': 556,
  25697. 'l': 278,
  25698. 'm': 889,
  25699. 'n': 611,
  25700. 'o': 611,
  25701. 'p': 611,
  25702. 'q': 611,
  25703. 'r': 389,
  25704. 's': 556,
  25705. 't': 333,
  25706. 'u': 611,
  25707. 'v': 556,
  25708. 'w': 778,
  25709. 'x': 556,
  25710. 'y': 556,
  25711. 'z': 500,
  25712. 'braceleft': 389,
  25713. 'bar': 280,
  25714. 'braceright': 389,
  25715. 'asciitilde': 584,
  25716. 'exclamdown': 333,
  25717. 'cent': 556,
  25718. 'sterling': 556,
  25719. 'fraction': 167,
  25720. 'yen': 556,
  25721. 'florin': 556,
  25722. 'section': 556,
  25723. 'currency': 556,
  25724. 'quotesingle': 238,
  25725. 'quotedblleft': 500,
  25726. 'guillemotleft': 556,
  25727. 'guilsinglleft': 333,
  25728. 'guilsinglright': 333,
  25729. 'fi': 611,
  25730. 'fl': 611,
  25731. 'endash': 556,
  25732. 'dagger': 556,
  25733. 'daggerdbl': 556,
  25734. 'periodcentered': 278,
  25735. 'paragraph': 556,
  25736. 'bullet': 350,
  25737. 'quotesinglbase': 278,
  25738. 'quotedblbase': 500,
  25739. 'quotedblright': 500,
  25740. 'guillemotright': 556,
  25741. 'ellipsis': 1000,
  25742. 'perthousand': 1000,
  25743. 'questiondown': 611,
  25744. 'grave': 333,
  25745. 'acute': 333,
  25746. 'circumflex': 333,
  25747. 'tilde': 333,
  25748. 'macron': 333,
  25749. 'breve': 333,
  25750. 'dotaccent': 333,
  25751. 'dieresis': 333,
  25752. 'ring': 333,
  25753. 'cedilla': 333,
  25754. 'hungarumlaut': 333,
  25755. 'ogonek': 333,
  25756. 'caron': 333,
  25757. 'emdash': 1000,
  25758. 'AE': 1000,
  25759. 'ordfeminine': 370,
  25760. 'Lslash': 611,
  25761. 'Oslash': 778,
  25762. 'OE': 1000,
  25763. 'ordmasculine': 365,
  25764. 'ae': 889,
  25765. 'dotlessi': 278,
  25766. 'lslash': 278,
  25767. 'oslash': 611,
  25768. 'oe': 944,
  25769. 'germandbls': 611,
  25770. 'Idieresis': 278,
  25771. 'eacute': 556,
  25772. 'abreve': 556,
  25773. 'uhungarumlaut': 611,
  25774. 'ecaron': 556,
  25775. 'Ydieresis': 667,
  25776. 'divide': 584,
  25777. 'Yacute': 667,
  25778. 'Acircumflex': 722,
  25779. 'aacute': 556,
  25780. 'Ucircumflex': 722,
  25781. 'yacute': 556,
  25782. 'scommaaccent': 556,
  25783. 'ecircumflex': 556,
  25784. 'Uring': 722,
  25785. 'Udieresis': 722,
  25786. 'aogonek': 556,
  25787. 'Uacute': 722,
  25788. 'uogonek': 611,
  25789. 'Edieresis': 667,
  25790. 'Dcroat': 722,
  25791. 'commaaccent': 250,
  25792. 'copyright': 737,
  25793. 'Emacron': 667,
  25794. 'ccaron': 556,
  25795. 'aring': 556,
  25796. 'Ncommaaccent': 722,
  25797. 'lacute': 278,
  25798. 'agrave': 556,
  25799. 'Tcommaaccent': 611,
  25800. 'Cacute': 722,
  25801. 'atilde': 556,
  25802. 'Edotaccent': 667,
  25803. 'scaron': 556,
  25804. 'scedilla': 556,
  25805. 'iacute': 278,
  25806. 'lozenge': 494,
  25807. 'Rcaron': 722,
  25808. 'Gcommaaccent': 778,
  25809. 'ucircumflex': 611,
  25810. 'acircumflex': 556,
  25811. 'Amacron': 722,
  25812. 'rcaron': 389,
  25813. 'ccedilla': 556,
  25814. 'Zdotaccent': 611,
  25815. 'Thorn': 667,
  25816. 'Omacron': 778,
  25817. 'Racute': 722,
  25818. 'Sacute': 667,
  25819. 'dcaron': 743,
  25820. 'Umacron': 722,
  25821. 'uring': 611,
  25822. 'threesuperior': 333,
  25823. 'Ograve': 778,
  25824. 'Agrave': 722,
  25825. 'Abreve': 722,
  25826. 'multiply': 584,
  25827. 'uacute': 611,
  25828. 'Tcaron': 611,
  25829. 'partialdiff': 494,
  25830. 'ydieresis': 556,
  25831. 'Nacute': 722,
  25832. 'icircumflex': 278,
  25833. 'Ecircumflex': 667,
  25834. 'adieresis': 556,
  25835. 'edieresis': 556,
  25836. 'cacute': 556,
  25837. 'nacute': 611,
  25838. 'umacron': 611,
  25839. 'Ncaron': 722,
  25840. 'Iacute': 278,
  25841. 'plusminus': 584,
  25842. 'brokenbar': 280,
  25843. 'registered': 737,
  25844. 'Gbreve': 778,
  25845. 'Idotaccent': 278,
  25846. 'summation': 600,
  25847. 'Egrave': 667,
  25848. 'racute': 389,
  25849. 'omacron': 611,
  25850. 'Zacute': 611,
  25851. 'Zcaron': 611,
  25852. 'greaterequal': 549,
  25853. 'Eth': 722,
  25854. 'Ccedilla': 722,
  25855. 'lcommaaccent': 278,
  25856. 'tcaron': 389,
  25857. 'eogonek': 556,
  25858. 'Uogonek': 722,
  25859. 'Aacute': 722,
  25860. 'Adieresis': 722,
  25861. 'egrave': 556,
  25862. 'zacute': 500,
  25863. 'iogonek': 278,
  25864. 'Oacute': 778,
  25865. 'oacute': 611,
  25866. 'amacron': 556,
  25867. 'sacute': 556,
  25868. 'idieresis': 278,
  25869. 'Ocircumflex': 778,
  25870. 'Ugrave': 722,
  25871. 'Delta': 612,
  25872. 'thorn': 611,
  25873. 'twosuperior': 333,
  25874. 'Odieresis': 778,
  25875. 'mu': 611,
  25876. 'igrave': 278,
  25877. 'ohungarumlaut': 611,
  25878. 'Eogonek': 667,
  25879. 'dcroat': 611,
  25880. 'threequarters': 834,
  25881. 'Scedilla': 667,
  25882. 'lcaron': 400,
  25883. 'Kcommaaccent': 722,
  25884. 'Lacute': 611,
  25885. 'trademark': 1000,
  25886. 'edotaccent': 556,
  25887. 'Igrave': 278,
  25888. 'Imacron': 278,
  25889. 'Lcaron': 611,
  25890. 'onehalf': 834,
  25891. 'lessequal': 549,
  25892. 'ocircumflex': 611,
  25893. 'ntilde': 611,
  25894. 'Uhungarumlaut': 722,
  25895. 'Eacute': 667,
  25896. 'emacron': 556,
  25897. 'gbreve': 611,
  25898. 'onequarter': 834,
  25899. 'Scaron': 667,
  25900. 'Scommaaccent': 667,
  25901. 'Ohungarumlaut': 778,
  25902. 'degree': 400,
  25903. 'ograve': 611,
  25904. 'Ccaron': 722,
  25905. 'ugrave': 611,
  25906. 'radical': 549,
  25907. 'Dcaron': 722,
  25908. 'rcommaaccent': 389,
  25909. 'Ntilde': 722,
  25910. 'otilde': 611,
  25911. 'Rcommaaccent': 722,
  25912. 'Lcommaaccent': 611,
  25913. 'Atilde': 722,
  25914. 'Aogonek': 722,
  25915. 'Aring': 722,
  25916. 'Otilde': 778,
  25917. 'zdotaccent': 500,
  25918. 'Ecaron': 667,
  25919. 'Iogonek': 278,
  25920. 'kcommaaccent': 556,
  25921. 'minus': 584,
  25922. 'Icircumflex': 278,
  25923. 'ncaron': 611,
  25924. 'tcommaaccent': 333,
  25925. 'logicalnot': 584,
  25926. 'odieresis': 611,
  25927. 'udieresis': 611,
  25928. 'notequal': 549,
  25929. 'gcommaaccent': 611,
  25930. 'eth': 611,
  25931. 'zcaron': 500,
  25932. 'ncommaaccent': 611,
  25933. 'onesuperior': 333,
  25934. 'imacron': 278,
  25935. 'Euro': 556
  25936. },
  25937. 'Helvetica-BoldOblique': {
  25938. 'space': 278,
  25939. 'exclam': 333,
  25940. 'quotedbl': 474,
  25941. 'numbersign': 556,
  25942. 'dollar': 556,
  25943. 'percent': 889,
  25944. 'ampersand': 722,
  25945. 'quoteright': 278,
  25946. 'parenleft': 333,
  25947. 'parenright': 333,
  25948. 'asterisk': 389,
  25949. 'plus': 584,
  25950. 'comma': 278,
  25951. 'hyphen': 333,
  25952. 'period': 278,
  25953. 'slash': 278,
  25954. 'zero': 556,
  25955. 'one': 556,
  25956. 'two': 556,
  25957. 'three': 556,
  25958. 'four': 556,
  25959. 'five': 556,
  25960. 'six': 556,
  25961. 'seven': 556,
  25962. 'eight': 556,
  25963. 'nine': 556,
  25964. 'colon': 333,
  25965. 'semicolon': 333,
  25966. 'less': 584,
  25967. 'equal': 584,
  25968. 'greater': 584,
  25969. 'question': 611,
  25970. 'at': 975,
  25971. 'A': 722,
  25972. 'B': 722,
  25973. 'C': 722,
  25974. 'D': 722,
  25975. 'E': 667,
  25976. 'F': 611,
  25977. 'G': 778,
  25978. 'H': 722,
  25979. 'I': 278,
  25980. 'J': 556,
  25981. 'K': 722,
  25982. 'L': 611,
  25983. 'M': 833,
  25984. 'N': 722,
  25985. 'O': 778,
  25986. 'P': 667,
  25987. 'Q': 778,
  25988. 'R': 722,
  25989. 'S': 667,
  25990. 'T': 611,
  25991. 'U': 722,
  25992. 'V': 667,
  25993. 'W': 944,
  25994. 'X': 667,
  25995. 'Y': 667,
  25996. 'Z': 611,
  25997. 'bracketleft': 333,
  25998. 'backslash': 278,
  25999. 'bracketright': 333,
  26000. 'asciicircum': 584,
  26001. 'underscore': 556,
  26002. 'quoteleft': 278,
  26003. 'a': 556,
  26004. 'b': 611,
  26005. 'c': 556,
  26006. 'd': 611,
  26007. 'e': 556,
  26008. 'f': 333,
  26009. 'g': 611,
  26010. 'h': 611,
  26011. 'i': 278,
  26012. 'j': 278,
  26013. 'k': 556,
  26014. 'l': 278,
  26015. 'm': 889,
  26016. 'n': 611,
  26017. 'o': 611,
  26018. 'p': 611,
  26019. 'q': 611,
  26020. 'r': 389,
  26021. 's': 556,
  26022. 't': 333,
  26023. 'u': 611,
  26024. 'v': 556,
  26025. 'w': 778,
  26026. 'x': 556,
  26027. 'y': 556,
  26028. 'z': 500,
  26029. 'braceleft': 389,
  26030. 'bar': 280,
  26031. 'braceright': 389,
  26032. 'asciitilde': 584,
  26033. 'exclamdown': 333,
  26034. 'cent': 556,
  26035. 'sterling': 556,
  26036. 'fraction': 167,
  26037. 'yen': 556,
  26038. 'florin': 556,
  26039. 'section': 556,
  26040. 'currency': 556,
  26041. 'quotesingle': 238,
  26042. 'quotedblleft': 500,
  26043. 'guillemotleft': 556,
  26044. 'guilsinglleft': 333,
  26045. 'guilsinglright': 333,
  26046. 'fi': 611,
  26047. 'fl': 611,
  26048. 'endash': 556,
  26049. 'dagger': 556,
  26050. 'daggerdbl': 556,
  26051. 'periodcentered': 278,
  26052. 'paragraph': 556,
  26053. 'bullet': 350,
  26054. 'quotesinglbase': 278,
  26055. 'quotedblbase': 500,
  26056. 'quotedblright': 500,
  26057. 'guillemotright': 556,
  26058. 'ellipsis': 1000,
  26059. 'perthousand': 1000,
  26060. 'questiondown': 611,
  26061. 'grave': 333,
  26062. 'acute': 333,
  26063. 'circumflex': 333,
  26064. 'tilde': 333,
  26065. 'macron': 333,
  26066. 'breve': 333,
  26067. 'dotaccent': 333,
  26068. 'dieresis': 333,
  26069. 'ring': 333,
  26070. 'cedilla': 333,
  26071. 'hungarumlaut': 333,
  26072. 'ogonek': 333,
  26073. 'caron': 333,
  26074. 'emdash': 1000,
  26075. 'AE': 1000,
  26076. 'ordfeminine': 370,
  26077. 'Lslash': 611,
  26078. 'Oslash': 778,
  26079. 'OE': 1000,
  26080. 'ordmasculine': 365,
  26081. 'ae': 889,
  26082. 'dotlessi': 278,
  26083. 'lslash': 278,
  26084. 'oslash': 611,
  26085. 'oe': 944,
  26086. 'germandbls': 611,
  26087. 'Idieresis': 278,
  26088. 'eacute': 556,
  26089. 'abreve': 556,
  26090. 'uhungarumlaut': 611,
  26091. 'ecaron': 556,
  26092. 'Ydieresis': 667,
  26093. 'divide': 584,
  26094. 'Yacute': 667,
  26095. 'Acircumflex': 722,
  26096. 'aacute': 556,
  26097. 'Ucircumflex': 722,
  26098. 'yacute': 556,
  26099. 'scommaaccent': 556,
  26100. 'ecircumflex': 556,
  26101. 'Uring': 722,
  26102. 'Udieresis': 722,
  26103. 'aogonek': 556,
  26104. 'Uacute': 722,
  26105. 'uogonek': 611,
  26106. 'Edieresis': 667,
  26107. 'Dcroat': 722,
  26108. 'commaaccent': 250,
  26109. 'copyright': 737,
  26110. 'Emacron': 667,
  26111. 'ccaron': 556,
  26112. 'aring': 556,
  26113. 'Ncommaaccent': 722,
  26114. 'lacute': 278,
  26115. 'agrave': 556,
  26116. 'Tcommaaccent': 611,
  26117. 'Cacute': 722,
  26118. 'atilde': 556,
  26119. 'Edotaccent': 667,
  26120. 'scaron': 556,
  26121. 'scedilla': 556,
  26122. 'iacute': 278,
  26123. 'lozenge': 494,
  26124. 'Rcaron': 722,
  26125. 'Gcommaaccent': 778,
  26126. 'ucircumflex': 611,
  26127. 'acircumflex': 556,
  26128. 'Amacron': 722,
  26129. 'rcaron': 389,
  26130. 'ccedilla': 556,
  26131. 'Zdotaccent': 611,
  26132. 'Thorn': 667,
  26133. 'Omacron': 778,
  26134. 'Racute': 722,
  26135. 'Sacute': 667,
  26136. 'dcaron': 743,
  26137. 'Umacron': 722,
  26138. 'uring': 611,
  26139. 'threesuperior': 333,
  26140. 'Ograve': 778,
  26141. 'Agrave': 722,
  26142. 'Abreve': 722,
  26143. 'multiply': 584,
  26144. 'uacute': 611,
  26145. 'Tcaron': 611,
  26146. 'partialdiff': 494,
  26147. 'ydieresis': 556,
  26148. 'Nacute': 722,
  26149. 'icircumflex': 278,
  26150. 'Ecircumflex': 667,
  26151. 'adieresis': 556,
  26152. 'edieresis': 556,
  26153. 'cacute': 556,
  26154. 'nacute': 611,
  26155. 'umacron': 611,
  26156. 'Ncaron': 722,
  26157. 'Iacute': 278,
  26158. 'plusminus': 584,
  26159. 'brokenbar': 280,
  26160. 'registered': 737,
  26161. 'Gbreve': 778,
  26162. 'Idotaccent': 278,
  26163. 'summation': 600,
  26164. 'Egrave': 667,
  26165. 'racute': 389,
  26166. 'omacron': 611,
  26167. 'Zacute': 611,
  26168. 'Zcaron': 611,
  26169. 'greaterequal': 549,
  26170. 'Eth': 722,
  26171. 'Ccedilla': 722,
  26172. 'lcommaaccent': 278,
  26173. 'tcaron': 389,
  26174. 'eogonek': 556,
  26175. 'Uogonek': 722,
  26176. 'Aacute': 722,
  26177. 'Adieresis': 722,
  26178. 'egrave': 556,
  26179. 'zacute': 500,
  26180. 'iogonek': 278,
  26181. 'Oacute': 778,
  26182. 'oacute': 611,
  26183. 'amacron': 556,
  26184. 'sacute': 556,
  26185. 'idieresis': 278,
  26186. 'Ocircumflex': 778,
  26187. 'Ugrave': 722,
  26188. 'Delta': 612,
  26189. 'thorn': 611,
  26190. 'twosuperior': 333,
  26191. 'Odieresis': 778,
  26192. 'mu': 611,
  26193. 'igrave': 278,
  26194. 'ohungarumlaut': 611,
  26195. 'Eogonek': 667,
  26196. 'dcroat': 611,
  26197. 'threequarters': 834,
  26198. 'Scedilla': 667,
  26199. 'lcaron': 400,
  26200. 'Kcommaaccent': 722,
  26201. 'Lacute': 611,
  26202. 'trademark': 1000,
  26203. 'edotaccent': 556,
  26204. 'Igrave': 278,
  26205. 'Imacron': 278,
  26206. 'Lcaron': 611,
  26207. 'onehalf': 834,
  26208. 'lessequal': 549,
  26209. 'ocircumflex': 611,
  26210. 'ntilde': 611,
  26211. 'Uhungarumlaut': 722,
  26212. 'Eacute': 667,
  26213. 'emacron': 556,
  26214. 'gbreve': 611,
  26215. 'onequarter': 834,
  26216. 'Scaron': 667,
  26217. 'Scommaaccent': 667,
  26218. 'Ohungarumlaut': 778,
  26219. 'degree': 400,
  26220. 'ograve': 611,
  26221. 'Ccaron': 722,
  26222. 'ugrave': 611,
  26223. 'radical': 549,
  26224. 'Dcaron': 722,
  26225. 'rcommaaccent': 389,
  26226. 'Ntilde': 722,
  26227. 'otilde': 611,
  26228. 'Rcommaaccent': 722,
  26229. 'Lcommaaccent': 611,
  26230. 'Atilde': 722,
  26231. 'Aogonek': 722,
  26232. 'Aring': 722,
  26233. 'Otilde': 778,
  26234. 'zdotaccent': 500,
  26235. 'Ecaron': 667,
  26236. 'Iogonek': 278,
  26237. 'kcommaaccent': 556,
  26238. 'minus': 584,
  26239. 'Icircumflex': 278,
  26240. 'ncaron': 611,
  26241. 'tcommaaccent': 333,
  26242. 'logicalnot': 584,
  26243. 'odieresis': 611,
  26244. 'udieresis': 611,
  26245. 'notequal': 549,
  26246. 'gcommaaccent': 611,
  26247. 'eth': 611,
  26248. 'zcaron': 500,
  26249. 'ncommaaccent': 611,
  26250. 'onesuperior': 333,
  26251. 'imacron': 278,
  26252. 'Euro': 556
  26253. },
  26254. 'Helvetica-Oblique' : {
  26255. 'space': 278,
  26256. 'exclam': 278,
  26257. 'quotedbl': 355,
  26258. 'numbersign': 556,
  26259. 'dollar': 556,
  26260. 'percent': 889,
  26261. 'ampersand': 667,
  26262. 'quoteright': 222,
  26263. 'parenleft': 333,
  26264. 'parenright': 333,
  26265. 'asterisk': 389,
  26266. 'plus': 584,
  26267. 'comma': 278,
  26268. 'hyphen': 333,
  26269. 'period': 278,
  26270. 'slash': 278,
  26271. 'zero': 556,
  26272. 'one': 556,
  26273. 'two': 556,
  26274. 'three': 556,
  26275. 'four': 556,
  26276. 'five': 556,
  26277. 'six': 556,
  26278. 'seven': 556,
  26279. 'eight': 556,
  26280. 'nine': 556,
  26281. 'colon': 278,
  26282. 'semicolon': 278,
  26283. 'less': 584,
  26284. 'equal': 584,
  26285. 'greater': 584,
  26286. 'question': 556,
  26287. 'at': 1015,
  26288. 'A': 667,
  26289. 'B': 667,
  26290. 'C': 722,
  26291. 'D': 722,
  26292. 'E': 667,
  26293. 'F': 611,
  26294. 'G': 778,
  26295. 'H': 722,
  26296. 'I': 278,
  26297. 'J': 500,
  26298. 'K': 667,
  26299. 'L': 556,
  26300. 'M': 833,
  26301. 'N': 722,
  26302. 'O': 778,
  26303. 'P': 667,
  26304. 'Q': 778,
  26305. 'R': 722,
  26306. 'S': 667,
  26307. 'T': 611,
  26308. 'U': 722,
  26309. 'V': 667,
  26310. 'W': 944,
  26311. 'X': 667,
  26312. 'Y': 667,
  26313. 'Z': 611,
  26314. 'bracketleft': 278,
  26315. 'backslash': 278,
  26316. 'bracketright': 278,
  26317. 'asciicircum': 469,
  26318. 'underscore': 556,
  26319. 'quoteleft': 222,
  26320. 'a': 556,
  26321. 'b': 556,
  26322. 'c': 500,
  26323. 'd': 556,
  26324. 'e': 556,
  26325. 'f': 278,
  26326. 'g': 556,
  26327. 'h': 556,
  26328. 'i': 222,
  26329. 'j': 222,
  26330. 'k': 500,
  26331. 'l': 222,
  26332. 'm': 833,
  26333. 'n': 556,
  26334. 'o': 556,
  26335. 'p': 556,
  26336. 'q': 556,
  26337. 'r': 333,
  26338. 's': 500,
  26339. 't': 278,
  26340. 'u': 556,
  26341. 'v': 500,
  26342. 'w': 722,
  26343. 'x': 500,
  26344. 'y': 500,
  26345. 'z': 500,
  26346. 'braceleft': 334,
  26347. 'bar': 260,
  26348. 'braceright': 334,
  26349. 'asciitilde': 584,
  26350. 'exclamdown': 333,
  26351. 'cent': 556,
  26352. 'sterling': 556,
  26353. 'fraction': 167,
  26354. 'yen': 556,
  26355. 'florin': 556,
  26356. 'section': 556,
  26357. 'currency': 556,
  26358. 'quotesingle': 191,
  26359. 'quotedblleft': 333,
  26360. 'guillemotleft': 556,
  26361. 'guilsinglleft': 333,
  26362. 'guilsinglright': 333,
  26363. 'fi': 500,
  26364. 'fl': 500,
  26365. 'endash': 556,
  26366. 'dagger': 556,
  26367. 'daggerdbl': 556,
  26368. 'periodcentered': 278,
  26369. 'paragraph': 537,
  26370. 'bullet': 350,
  26371. 'quotesinglbase': 222,
  26372. 'quotedblbase': 333,
  26373. 'quotedblright': 333,
  26374. 'guillemotright': 556,
  26375. 'ellipsis': 1000,
  26376. 'perthousand': 1000,
  26377. 'questiondown': 611,
  26378. 'grave': 333,
  26379. 'acute': 333,
  26380. 'circumflex': 333,
  26381. 'tilde': 333,
  26382. 'macron': 333,
  26383. 'breve': 333,
  26384. 'dotaccent': 333,
  26385. 'dieresis': 333,
  26386. 'ring': 333,
  26387. 'cedilla': 333,
  26388. 'hungarumlaut': 333,
  26389. 'ogonek': 333,
  26390. 'caron': 333,
  26391. 'emdash': 1000,
  26392. 'AE': 1000,
  26393. 'ordfeminine': 370,
  26394. 'Lslash': 556,
  26395. 'Oslash': 778,
  26396. 'OE': 1000,
  26397. 'ordmasculine': 365,
  26398. 'ae': 889,
  26399. 'dotlessi': 278,
  26400. 'lslash': 222,
  26401. 'oslash': 611,
  26402. 'oe': 944,
  26403. 'germandbls': 611,
  26404. 'Idieresis': 278,
  26405. 'eacute': 556,
  26406. 'abreve': 556,
  26407. 'uhungarumlaut': 556,
  26408. 'ecaron': 556,
  26409. 'Ydieresis': 667,
  26410. 'divide': 584,
  26411. 'Yacute': 667,
  26412. 'Acircumflex': 667,
  26413. 'aacute': 556,
  26414. 'Ucircumflex': 722,
  26415. 'yacute': 500,
  26416. 'scommaaccent': 500,
  26417. 'ecircumflex': 556,
  26418. 'Uring': 722,
  26419. 'Udieresis': 722,
  26420. 'aogonek': 556,
  26421. 'Uacute': 722,
  26422. 'uogonek': 556,
  26423. 'Edieresis': 667,
  26424. 'Dcroat': 722,
  26425. 'commaaccent': 250,
  26426. 'copyright': 737,
  26427. 'Emacron': 667,
  26428. 'ccaron': 500,
  26429. 'aring': 556,
  26430. 'Ncommaaccent': 722,
  26431. 'lacute': 222,
  26432. 'agrave': 556,
  26433. 'Tcommaaccent': 611,
  26434. 'Cacute': 722,
  26435. 'atilde': 556,
  26436. 'Edotaccent': 667,
  26437. 'scaron': 500,
  26438. 'scedilla': 500,
  26439. 'iacute': 278,
  26440. 'lozenge': 471,
  26441. 'Rcaron': 722,
  26442. 'Gcommaaccent': 778,
  26443. 'ucircumflex': 556,
  26444. 'acircumflex': 556,
  26445. 'Amacron': 667,
  26446. 'rcaron': 333,
  26447. 'ccedilla': 500,
  26448. 'Zdotaccent': 611,
  26449. 'Thorn': 667,
  26450. 'Omacron': 778,
  26451. 'Racute': 722,
  26452. 'Sacute': 667,
  26453. 'dcaron': 643,
  26454. 'Umacron': 722,
  26455. 'uring': 556,
  26456. 'threesuperior': 333,
  26457. 'Ograve': 778,
  26458. 'Agrave': 667,
  26459. 'Abreve': 667,
  26460. 'multiply': 584,
  26461. 'uacute': 556,
  26462. 'Tcaron': 611,
  26463. 'partialdiff': 476,
  26464. 'ydieresis': 500,
  26465. 'Nacute': 722,
  26466. 'icircumflex': 278,
  26467. 'Ecircumflex': 667,
  26468. 'adieresis': 556,
  26469. 'edieresis': 556,
  26470. 'cacute': 500,
  26471. 'nacute': 556,
  26472. 'umacron': 556,
  26473. 'Ncaron': 722,
  26474. 'Iacute': 278,
  26475. 'plusminus': 584,
  26476. 'brokenbar': 260,
  26477. 'registered': 737,
  26478. 'Gbreve': 778,
  26479. 'Idotaccent': 278,
  26480. 'summation': 600,
  26481. 'Egrave': 667,
  26482. 'racute': 333,
  26483. 'omacron': 556,
  26484. 'Zacute': 611,
  26485. 'Zcaron': 611,
  26486. 'greaterequal': 549,
  26487. 'Eth': 722,
  26488. 'Ccedilla': 722,
  26489. 'lcommaaccent': 222,
  26490. 'tcaron': 317,
  26491. 'eogonek': 556,
  26492. 'Uogonek': 722,
  26493. 'Aacute': 667,
  26494. 'Adieresis': 667,
  26495. 'egrave': 556,
  26496. 'zacute': 500,
  26497. 'iogonek': 222,
  26498. 'Oacute': 778,
  26499. 'oacute': 556,
  26500. 'amacron': 556,
  26501. 'sacute': 500,
  26502. 'idieresis': 278,
  26503. 'Ocircumflex': 778,
  26504. 'Ugrave': 722,
  26505. 'Delta': 612,
  26506. 'thorn': 556,
  26507. 'twosuperior': 333,
  26508. 'Odieresis': 778,
  26509. 'mu': 556,
  26510. 'igrave': 278,
  26511. 'ohungarumlaut': 556,
  26512. 'Eogonek': 667,
  26513. 'dcroat': 556,
  26514. 'threequarters': 834,
  26515. 'Scedilla': 667,
  26516. 'lcaron': 299,
  26517. 'Kcommaaccent': 667,
  26518. 'Lacute': 556,
  26519. 'trademark': 1000,
  26520. 'edotaccent': 556,
  26521. 'Igrave': 278,
  26522. 'Imacron': 278,
  26523. 'Lcaron': 556,
  26524. 'onehalf': 834,
  26525. 'lessequal': 549,
  26526. 'ocircumflex': 556,
  26527. 'ntilde': 556,
  26528. 'Uhungarumlaut': 722,
  26529. 'Eacute': 667,
  26530. 'emacron': 556,
  26531. 'gbreve': 556,
  26532. 'onequarter': 834,
  26533. 'Scaron': 667,
  26534. 'Scommaaccent': 667,
  26535. 'Ohungarumlaut': 778,
  26536. 'degree': 400,
  26537. 'ograve': 556,
  26538. 'Ccaron': 722,
  26539. 'ugrave': 556,
  26540. 'radical': 453,
  26541. 'Dcaron': 722,
  26542. 'rcommaaccent': 333,
  26543. 'Ntilde': 722,
  26544. 'otilde': 556,
  26545. 'Rcommaaccent': 722,
  26546. 'Lcommaaccent': 556,
  26547. 'Atilde': 667,
  26548. 'Aogonek': 667,
  26549. 'Aring': 667,
  26550. 'Otilde': 778,
  26551. 'zdotaccent': 500,
  26552. 'Ecaron': 667,
  26553. 'Iogonek': 278,
  26554. 'kcommaaccent': 500,
  26555. 'minus': 584,
  26556. 'Icircumflex': 278,
  26557. 'ncaron': 556,
  26558. 'tcommaaccent': 278,
  26559. 'logicalnot': 584,
  26560. 'odieresis': 556,
  26561. 'udieresis': 556,
  26562. 'notequal': 549,
  26563. 'gcommaaccent': 556,
  26564. 'eth': 556,
  26565. 'zcaron': 500,
  26566. 'ncommaaccent': 556,
  26567. 'onesuperior': 333,
  26568. 'imacron': 278,
  26569. 'Euro': 556
  26570. },
  26571. 'Symbol': {
  26572. 'space': 250,
  26573. 'exclam': 333,
  26574. 'universal': 713,
  26575. 'numbersign': 500,
  26576. 'existential': 549,
  26577. 'percent': 833,
  26578. 'ampersand': 778,
  26579. 'suchthat': 439,
  26580. 'parenleft': 333,
  26581. 'parenright': 333,
  26582. 'asteriskmath': 500,
  26583. 'plus': 549,
  26584. 'comma': 250,
  26585. 'minus': 549,
  26586. 'period': 250,
  26587. 'slash': 278,
  26588. 'zero': 500,
  26589. 'one': 500,
  26590. 'two': 500,
  26591. 'three': 500,
  26592. 'four': 500,
  26593. 'five': 500,
  26594. 'six': 500,
  26595. 'seven': 500,
  26596. 'eight': 500,
  26597. 'nine': 500,
  26598. 'colon': 278,
  26599. 'semicolon': 278,
  26600. 'less': 549,
  26601. 'equal': 549,
  26602. 'greater': 549,
  26603. 'question': 444,
  26604. 'congruent': 549,
  26605. 'Alpha': 722,
  26606. 'Beta': 667,
  26607. 'Chi': 722,
  26608. 'Delta': 612,
  26609. 'Epsilon': 611,
  26610. 'Phi': 763,
  26611. 'Gamma': 603,
  26612. 'Eta': 722,
  26613. 'Iota': 333,
  26614. 'theta1': 631,
  26615. 'Kappa': 722,
  26616. 'Lambda': 686,
  26617. 'Mu': 889,
  26618. 'Nu': 722,
  26619. 'Omicron': 722,
  26620. 'Pi': 768,
  26621. 'Theta': 741,
  26622. 'Rho': 556,
  26623. 'Sigma': 592,
  26624. 'Tau': 611,
  26625. 'Upsilon': 690,
  26626. 'sigma1': 439,
  26627. 'Omega': 768,
  26628. 'Xi': 645,
  26629. 'Psi': 795,
  26630. 'Zeta': 611,
  26631. 'bracketleft': 333,
  26632. 'therefore': 863,
  26633. 'bracketright': 333,
  26634. 'perpendicular': 658,
  26635. 'underscore': 500,
  26636. 'radicalex': 500,
  26637. 'alpha': 631,
  26638. 'beta': 549,
  26639. 'chi': 549,
  26640. 'delta': 494,
  26641. 'epsilon': 439,
  26642. 'phi': 521,
  26643. 'gamma': 411,
  26644. 'eta': 603,
  26645. 'iota': 329,
  26646. 'phi1': 603,
  26647. 'kappa': 549,
  26648. 'lambda': 549,
  26649. 'mu': 576,
  26650. 'nu': 521,
  26651. 'omicron': 549,
  26652. 'pi': 549,
  26653. 'theta': 521,
  26654. 'rho': 549,
  26655. 'sigma': 603,
  26656. 'tau': 439,
  26657. 'upsilon': 576,
  26658. 'omega1': 713,
  26659. 'omega': 686,
  26660. 'xi': 493,
  26661. 'psi': 686,
  26662. 'zeta': 494,
  26663. 'braceleft': 480,
  26664. 'bar': 200,
  26665. 'braceright': 480,
  26666. 'similar': 549,
  26667. 'Euro': 750,
  26668. 'Upsilon1': 620,
  26669. 'minute': 247,
  26670. 'lessequal': 549,
  26671. 'fraction': 167,
  26672. 'infinity': 713,
  26673. 'florin': 500,
  26674. 'club': 753,
  26675. 'diamond': 753,
  26676. 'heart': 753,
  26677. 'spade': 753,
  26678. 'arrowboth': 1042,
  26679. 'arrowleft': 987,
  26680. 'arrowup': 603,
  26681. 'arrowright': 987,
  26682. 'arrowdown': 603,
  26683. 'degree': 400,
  26684. 'plusminus': 549,
  26685. 'second': 411,
  26686. 'greaterequal': 549,
  26687. 'multiply': 549,
  26688. 'proportional': 713,
  26689. 'partialdiff': 494,
  26690. 'bullet': 460,
  26691. 'divide': 549,
  26692. 'notequal': 549,
  26693. 'equivalence': 549,
  26694. 'approxequal': 549,
  26695. 'ellipsis': 1000,
  26696. 'arrowvertex': 603,
  26697. 'arrowhorizex': 1000,
  26698. 'carriagereturn': 658,
  26699. 'aleph': 823,
  26700. 'Ifraktur': 686,
  26701. 'Rfraktur': 795,
  26702. 'weierstrass': 987,
  26703. 'circlemultiply': 768,
  26704. 'circleplus': 768,
  26705. 'emptyset': 823,
  26706. 'intersection': 768,
  26707. 'union': 768,
  26708. 'propersuperset': 713,
  26709. 'reflexsuperset': 713,
  26710. 'notsubset': 713,
  26711. 'propersubset': 713,
  26712. 'reflexsubset': 713,
  26713. 'element': 713,
  26714. 'notelement': 713,
  26715. 'angle': 768,
  26716. 'gradient': 713,
  26717. 'registerserif': 790,
  26718. 'copyrightserif': 790,
  26719. 'trademarkserif': 890,
  26720. 'product': 823,
  26721. 'radical': 549,
  26722. 'dotmath': 250,
  26723. 'logicalnot': 713,
  26724. 'logicaland': 603,
  26725. 'logicalor': 603,
  26726. 'arrowdblboth': 1042,
  26727. 'arrowdblleft': 987,
  26728. 'arrowdblup': 603,
  26729. 'arrowdblright': 987,
  26730. 'arrowdbldown': 603,
  26731. 'lozenge': 494,
  26732. 'angleleft': 329,
  26733. 'registersans': 790,
  26734. 'copyrightsans': 790,
  26735. 'trademarksans': 786,
  26736. 'summation': 713,
  26737. 'parenlefttp': 384,
  26738. 'parenleftex': 384,
  26739. 'parenleftbt': 384,
  26740. 'bracketlefttp': 384,
  26741. 'bracketleftex': 384,
  26742. 'bracketleftbt': 384,
  26743. 'bracelefttp': 494,
  26744. 'braceleftmid': 494,
  26745. 'braceleftbt': 494,
  26746. 'braceex': 494,
  26747. 'angleright': 329,
  26748. 'integral': 274,
  26749. 'integraltp': 686,
  26750. 'integralex': 686,
  26751. 'integralbt': 686,
  26752. 'parenrighttp': 384,
  26753. 'parenrightex': 384,
  26754. 'parenrightbt': 384,
  26755. 'bracketrighttp': 384,
  26756. 'bracketrightex': 384,
  26757. 'bracketrightbt': 384,
  26758. 'bracerighttp': 494,
  26759. 'bracerightmid': 494,
  26760. 'bracerightbt': 494,
  26761. 'apple': 790
  26762. },
  26763. 'Times-Roman': {
  26764. 'space': 250,
  26765. 'exclam': 333,
  26766. 'quotedbl': 408,
  26767. 'numbersign': 500,
  26768. 'dollar': 500,
  26769. 'percent': 833,
  26770. 'ampersand': 778,
  26771. 'quoteright': 333,
  26772. 'parenleft': 333,
  26773. 'parenright': 333,
  26774. 'asterisk': 500,
  26775. 'plus': 564,
  26776. 'comma': 250,
  26777. 'hyphen': 333,
  26778. 'period': 250,
  26779. 'slash': 278,
  26780. 'zero': 500,
  26781. 'one': 500,
  26782. 'two': 500,
  26783. 'three': 500,
  26784. 'four': 500,
  26785. 'five': 500,
  26786. 'six': 500,
  26787. 'seven': 500,
  26788. 'eight': 500,
  26789. 'nine': 500,
  26790. 'colon': 278,
  26791. 'semicolon': 278,
  26792. 'less': 564,
  26793. 'equal': 564,
  26794. 'greater': 564,
  26795. 'question': 444,
  26796. 'at': 921,
  26797. 'A': 722,
  26798. 'B': 667,
  26799. 'C': 667,
  26800. 'D': 722,
  26801. 'E': 611,
  26802. 'F': 556,
  26803. 'G': 722,
  26804. 'H': 722,
  26805. 'I': 333,
  26806. 'J': 389,
  26807. 'K': 722,
  26808. 'L': 611,
  26809. 'M': 889,
  26810. 'N': 722,
  26811. 'O': 722,
  26812. 'P': 556,
  26813. 'Q': 722,
  26814. 'R': 667,
  26815. 'S': 556,
  26816. 'T': 611,
  26817. 'U': 722,
  26818. 'V': 722,
  26819. 'W': 944,
  26820. 'X': 722,
  26821. 'Y': 722,
  26822. 'Z': 611,
  26823. 'bracketleft': 333,
  26824. 'backslash': 278,
  26825. 'bracketright': 333,
  26826. 'asciicircum': 469,
  26827. 'underscore': 500,
  26828. 'quoteleft': 333,
  26829. 'a': 444,
  26830. 'b': 500,
  26831. 'c': 444,
  26832. 'd': 500,
  26833. 'e': 444,
  26834. 'f': 333,
  26835. 'g': 500,
  26836. 'h': 500,
  26837. 'i': 278,
  26838. 'j': 278,
  26839. 'k': 500,
  26840. 'l': 278,
  26841. 'm': 778,
  26842. 'n': 500,
  26843. 'o': 500,
  26844. 'p': 500,
  26845. 'q': 500,
  26846. 'r': 333,
  26847. 's': 389,
  26848. 't': 278,
  26849. 'u': 500,
  26850. 'v': 500,
  26851. 'w': 722,
  26852. 'x': 500,
  26853. 'y': 500,
  26854. 'z': 444,
  26855. 'braceleft': 480,
  26856. 'bar': 200,
  26857. 'braceright': 480,
  26858. 'asciitilde': 541,
  26859. 'exclamdown': 333,
  26860. 'cent': 500,
  26861. 'sterling': 500,
  26862. 'fraction': 167,
  26863. 'yen': 500,
  26864. 'florin': 500,
  26865. 'section': 500,
  26866. 'currency': 500,
  26867. 'quotesingle': 180,
  26868. 'quotedblleft': 444,
  26869. 'guillemotleft': 500,
  26870. 'guilsinglleft': 333,
  26871. 'guilsinglright': 333,
  26872. 'fi': 556,
  26873. 'fl': 556,
  26874. 'endash': 500,
  26875. 'dagger': 500,
  26876. 'daggerdbl': 500,
  26877. 'periodcentered': 250,
  26878. 'paragraph': 453,
  26879. 'bullet': 350,
  26880. 'quotesinglbase': 333,
  26881. 'quotedblbase': 444,
  26882. 'quotedblright': 444,
  26883. 'guillemotright': 500,
  26884. 'ellipsis': 1000,
  26885. 'perthousand': 1000,
  26886. 'questiondown': 444,
  26887. 'grave': 333,
  26888. 'acute': 333,
  26889. 'circumflex': 333,
  26890. 'tilde': 333,
  26891. 'macron': 333,
  26892. 'breve': 333,
  26893. 'dotaccent': 333,
  26894. 'dieresis': 333,
  26895. 'ring': 333,
  26896. 'cedilla': 333,
  26897. 'hungarumlaut': 333,
  26898. 'ogonek': 333,
  26899. 'caron': 333,
  26900. 'emdash': 1000,
  26901. 'AE': 889,
  26902. 'ordfeminine': 276,
  26903. 'Lslash': 611,
  26904. 'Oslash': 722,
  26905. 'OE': 889,
  26906. 'ordmasculine': 310,
  26907. 'ae': 667,
  26908. 'dotlessi': 278,
  26909. 'lslash': 278,
  26910. 'oslash': 500,
  26911. 'oe': 722,
  26912. 'germandbls': 500,
  26913. 'Idieresis': 333,
  26914. 'eacute': 444,
  26915. 'abreve': 444,
  26916. 'uhungarumlaut': 500,
  26917. 'ecaron': 444,
  26918. 'Ydieresis': 722,
  26919. 'divide': 564,
  26920. 'Yacute': 722,
  26921. 'Acircumflex': 722,
  26922. 'aacute': 444,
  26923. 'Ucircumflex': 722,
  26924. 'yacute': 500,
  26925. 'scommaaccent': 389,
  26926. 'ecircumflex': 444,
  26927. 'Uring': 722,
  26928. 'Udieresis': 722,
  26929. 'aogonek': 444,
  26930. 'Uacute': 722,
  26931. 'uogonek': 500,
  26932. 'Edieresis': 611,
  26933. 'Dcroat': 722,
  26934. 'commaaccent': 250,
  26935. 'copyright': 760,
  26936. 'Emacron': 611,
  26937. 'ccaron': 444,
  26938. 'aring': 444,
  26939. 'Ncommaaccent': 722,
  26940. 'lacute': 278,
  26941. 'agrave': 444,
  26942. 'Tcommaaccent': 611,
  26943. 'Cacute': 667,
  26944. 'atilde': 444,
  26945. 'Edotaccent': 611,
  26946. 'scaron': 389,
  26947. 'scedilla': 389,
  26948. 'iacute': 278,
  26949. 'lozenge': 471,
  26950. 'Rcaron': 667,
  26951. 'Gcommaaccent': 722,
  26952. 'ucircumflex': 500,
  26953. 'acircumflex': 444,
  26954. 'Amacron': 722,
  26955. 'rcaron': 333,
  26956. 'ccedilla': 444,
  26957. 'Zdotaccent': 611,
  26958. 'Thorn': 556,
  26959. 'Omacron': 722,
  26960. 'Racute': 667,
  26961. 'Sacute': 556,
  26962. 'dcaron': 588,
  26963. 'Umacron': 722,
  26964. 'uring': 500,
  26965. 'threesuperior': 300,
  26966. 'Ograve': 722,
  26967. 'Agrave': 722,
  26968. 'Abreve': 722,
  26969. 'multiply': 564,
  26970. 'uacute': 500,
  26971. 'Tcaron': 611,
  26972. 'partialdiff': 476,
  26973. 'ydieresis': 500,
  26974. 'Nacute': 722,
  26975. 'icircumflex': 278,
  26976. 'Ecircumflex': 611,
  26977. 'adieresis': 444,
  26978. 'edieresis': 444,
  26979. 'cacute': 444,
  26980. 'nacute': 500,
  26981. 'umacron': 500,
  26982. 'Ncaron': 722,
  26983. 'Iacute': 333,
  26984. 'plusminus': 564,
  26985. 'brokenbar': 200,
  26986. 'registered': 760,
  26987. 'Gbreve': 722,
  26988. 'Idotaccent': 333,
  26989. 'summation': 600,
  26990. 'Egrave': 611,
  26991. 'racute': 333,
  26992. 'omacron': 500,
  26993. 'Zacute': 611,
  26994. 'Zcaron': 611,
  26995. 'greaterequal': 549,
  26996. 'Eth': 722,
  26997. 'Ccedilla': 667,
  26998. 'lcommaaccent': 278,
  26999. 'tcaron': 326,
  27000. 'eogonek': 444,
  27001. 'Uogonek': 722,
  27002. 'Aacute': 722,
  27003. 'Adieresis': 722,
  27004. 'egrave': 444,
  27005. 'zacute': 444,
  27006. 'iogonek': 278,
  27007. 'Oacute': 722,
  27008. 'oacute': 500,
  27009. 'amacron': 444,
  27010. 'sacute': 389,
  27011. 'idieresis': 278,
  27012. 'Ocircumflex': 722,
  27013. 'Ugrave': 722,
  27014. 'Delta': 612,
  27015. 'thorn': 500,
  27016. 'twosuperior': 300,
  27017. 'Odieresis': 722,
  27018. 'mu': 500,
  27019. 'igrave': 278,
  27020. 'ohungarumlaut': 500,
  27021. 'Eogonek': 611,
  27022. 'dcroat': 500,
  27023. 'threequarters': 750,
  27024. 'Scedilla': 556,
  27025. 'lcaron': 344,
  27026. 'Kcommaaccent': 722,
  27027. 'Lacute': 611,
  27028. 'trademark': 980,
  27029. 'edotaccent': 444,
  27030. 'Igrave': 333,
  27031. 'Imacron': 333,
  27032. 'Lcaron': 611,
  27033. 'onehalf': 750,
  27034. 'lessequal': 549,
  27035. 'ocircumflex': 500,
  27036. 'ntilde': 500,
  27037. 'Uhungarumlaut': 722,
  27038. 'Eacute': 611,
  27039. 'emacron': 444,
  27040. 'gbreve': 500,
  27041. 'onequarter': 750,
  27042. 'Scaron': 556,
  27043. 'Scommaaccent': 556,
  27044. 'Ohungarumlaut': 722,
  27045. 'degree': 400,
  27046. 'ograve': 500,
  27047. 'Ccaron': 667,
  27048. 'ugrave': 500,
  27049. 'radical': 453,
  27050. 'Dcaron': 722,
  27051. 'rcommaaccent': 333,
  27052. 'Ntilde': 722,
  27053. 'otilde': 500,
  27054. 'Rcommaaccent': 667,
  27055. 'Lcommaaccent': 611,
  27056. 'Atilde': 722,
  27057. 'Aogonek': 722,
  27058. 'Aring': 722,
  27059. 'Otilde': 722,
  27060. 'zdotaccent': 444,
  27061. 'Ecaron': 611,
  27062. 'Iogonek': 333,
  27063. 'kcommaaccent': 500,
  27064. 'minus': 564,
  27065. 'Icircumflex': 333,
  27066. 'ncaron': 500,
  27067. 'tcommaaccent': 278,
  27068. 'logicalnot': 564,
  27069. 'odieresis': 500,
  27070. 'udieresis': 500,
  27071. 'notequal': 549,
  27072. 'gcommaaccent': 500,
  27073. 'eth': 500,
  27074. 'zcaron': 444,
  27075. 'ncommaaccent': 500,
  27076. 'onesuperior': 300,
  27077. 'imacron': 278,
  27078. 'Euro': 500
  27079. },
  27080. 'Times-Bold': {
  27081. 'space': 250,
  27082. 'exclam': 333,
  27083. 'quotedbl': 555,
  27084. 'numbersign': 500,
  27085. 'dollar': 500,
  27086. 'percent': 1000,
  27087. 'ampersand': 833,
  27088. 'quoteright': 333,
  27089. 'parenleft': 333,
  27090. 'parenright': 333,
  27091. 'asterisk': 500,
  27092. 'plus': 570,
  27093. 'comma': 250,
  27094. 'hyphen': 333,
  27095. 'period': 250,
  27096. 'slash': 278,
  27097. 'zero': 500,
  27098. 'one': 500,
  27099. 'two': 500,
  27100. 'three': 500,
  27101. 'four': 500,
  27102. 'five': 500,
  27103. 'six': 500,
  27104. 'seven': 500,
  27105. 'eight': 500,
  27106. 'nine': 500,
  27107. 'colon': 333,
  27108. 'semicolon': 333,
  27109. 'less': 570,
  27110. 'equal': 570,
  27111. 'greater': 570,
  27112. 'question': 500,
  27113. 'at': 930,
  27114. 'A': 722,
  27115. 'B': 667,
  27116. 'C': 722,
  27117. 'D': 722,
  27118. 'E': 667,
  27119. 'F': 611,
  27120. 'G': 778,
  27121. 'H': 778,
  27122. 'I': 389,
  27123. 'J': 500,
  27124. 'K': 778,
  27125. 'L': 667,
  27126. 'M': 944,
  27127. 'N': 722,
  27128. 'O': 778,
  27129. 'P': 611,
  27130. 'Q': 778,
  27131. 'R': 722,
  27132. 'S': 556,
  27133. 'T': 667,
  27134. 'U': 722,
  27135. 'V': 722,
  27136. 'W': 1000,
  27137. 'X': 722,
  27138. 'Y': 722,
  27139. 'Z': 667,
  27140. 'bracketleft': 333,
  27141. 'backslash': 278,
  27142. 'bracketright': 333,
  27143. 'asciicircum': 581,
  27144. 'underscore': 500,
  27145. 'quoteleft': 333,
  27146. 'a': 500,
  27147. 'b': 556,
  27148. 'c': 444,
  27149. 'd': 556,
  27150. 'e': 444,
  27151. 'f': 333,
  27152. 'g': 500,
  27153. 'h': 556,
  27154. 'i': 278,
  27155. 'j': 333,
  27156. 'k': 556,
  27157. 'l': 278,
  27158. 'm': 833,
  27159. 'n': 556,
  27160. 'o': 500,
  27161. 'p': 556,
  27162. 'q': 556,
  27163. 'r': 444,
  27164. 's': 389,
  27165. 't': 333,
  27166. 'u': 556,
  27167. 'v': 500,
  27168. 'w': 722,
  27169. 'x': 500,
  27170. 'y': 500,
  27171. 'z': 444,
  27172. 'braceleft': 394,
  27173. 'bar': 220,
  27174. 'braceright': 394,
  27175. 'asciitilde': 520,
  27176. 'exclamdown': 333,
  27177. 'cent': 500,
  27178. 'sterling': 500,
  27179. 'fraction': 167,
  27180. 'yen': 500,
  27181. 'florin': 500,
  27182. 'section': 500,
  27183. 'currency': 500,
  27184. 'quotesingle': 278,
  27185. 'quotedblleft': 500,
  27186. 'guillemotleft': 500,
  27187. 'guilsinglleft': 333,
  27188. 'guilsinglright': 333,
  27189. 'fi': 556,
  27190. 'fl': 556,
  27191. 'endash': 500,
  27192. 'dagger': 500,
  27193. 'daggerdbl': 500,
  27194. 'periodcentered': 250,
  27195. 'paragraph': 540,
  27196. 'bullet': 350,
  27197. 'quotesinglbase': 333,
  27198. 'quotedblbase': 500,
  27199. 'quotedblright': 500,
  27200. 'guillemotright': 500,
  27201. 'ellipsis': 1000,
  27202. 'perthousand': 1000,
  27203. 'questiondown': 500,
  27204. 'grave': 333,
  27205. 'acute': 333,
  27206. 'circumflex': 333,
  27207. 'tilde': 333,
  27208. 'macron': 333,
  27209. 'breve': 333,
  27210. 'dotaccent': 333,
  27211. 'dieresis': 333,
  27212. 'ring': 333,
  27213. 'cedilla': 333,
  27214. 'hungarumlaut': 333,
  27215. 'ogonek': 333,
  27216. 'caron': 333,
  27217. 'emdash': 1000,
  27218. 'AE': 1000,
  27219. 'ordfeminine': 300,
  27220. 'Lslash': 667,
  27221. 'Oslash': 778,
  27222. 'OE': 1000,
  27223. 'ordmasculine': 330,
  27224. 'ae': 722,
  27225. 'dotlessi': 278,
  27226. 'lslash': 278,
  27227. 'oslash': 500,
  27228. 'oe': 722,
  27229. 'germandbls': 556,
  27230. 'Idieresis': 389,
  27231. 'eacute': 444,
  27232. 'abreve': 500,
  27233. 'uhungarumlaut': 556,
  27234. 'ecaron': 444,
  27235. 'Ydieresis': 722,
  27236. 'divide': 570,
  27237. 'Yacute': 722,
  27238. 'Acircumflex': 722,
  27239. 'aacute': 500,
  27240. 'Ucircumflex': 722,
  27241. 'yacute': 500,
  27242. 'scommaaccent': 389,
  27243. 'ecircumflex': 444,
  27244. 'Uring': 722,
  27245. 'Udieresis': 722,
  27246. 'aogonek': 500,
  27247. 'Uacute': 722,
  27248. 'uogonek': 556,
  27249. 'Edieresis': 667,
  27250. 'Dcroat': 722,
  27251. 'commaaccent': 250,
  27252. 'copyright': 747,
  27253. 'Emacron': 667,
  27254. 'ccaron': 444,
  27255. 'aring': 500,
  27256. 'Ncommaaccent': 722,
  27257. 'lacute': 278,
  27258. 'agrave': 500,
  27259. 'Tcommaaccent': 667,
  27260. 'Cacute': 722,
  27261. 'atilde': 500,
  27262. 'Edotaccent': 667,
  27263. 'scaron': 389,
  27264. 'scedilla': 389,
  27265. 'iacute': 278,
  27266. 'lozenge': 494,
  27267. 'Rcaron': 722,
  27268. 'Gcommaaccent': 778,
  27269. 'ucircumflex': 556,
  27270. 'acircumflex': 500,
  27271. 'Amacron': 722,
  27272. 'rcaron': 444,
  27273. 'ccedilla': 444,
  27274. 'Zdotaccent': 667,
  27275. 'Thorn': 611,
  27276. 'Omacron': 778,
  27277. 'Racute': 722,
  27278. 'Sacute': 556,
  27279. 'dcaron': 672,
  27280. 'Umacron': 722,
  27281. 'uring': 556,
  27282. 'threesuperior': 300,
  27283. 'Ograve': 778,
  27284. 'Agrave': 722,
  27285. 'Abreve': 722,
  27286. 'multiply': 570,
  27287. 'uacute': 556,
  27288. 'Tcaron': 667,
  27289. 'partialdiff': 494,
  27290. 'ydieresis': 500,
  27291. 'Nacute': 722,
  27292. 'icircumflex': 278,
  27293. 'Ecircumflex': 667,
  27294. 'adieresis': 500,
  27295. 'edieresis': 444,
  27296. 'cacute': 444,
  27297. 'nacute': 556,
  27298. 'umacron': 556,
  27299. 'Ncaron': 722,
  27300. 'Iacute': 389,
  27301. 'plusminus': 570,
  27302. 'brokenbar': 220,
  27303. 'registered': 747,
  27304. 'Gbreve': 778,
  27305. 'Idotaccent': 389,
  27306. 'summation': 600,
  27307. 'Egrave': 667,
  27308. 'racute': 444,
  27309. 'omacron': 500,
  27310. 'Zacute': 667,
  27311. 'Zcaron': 667,
  27312. 'greaterequal': 549,
  27313. 'Eth': 722,
  27314. 'Ccedilla': 722,
  27315. 'lcommaaccent': 278,
  27316. 'tcaron': 416,
  27317. 'eogonek': 444,
  27318. 'Uogonek': 722,
  27319. 'Aacute': 722,
  27320. 'Adieresis': 722,
  27321. 'egrave': 444,
  27322. 'zacute': 444,
  27323. 'iogonek': 278,
  27324. 'Oacute': 778,
  27325. 'oacute': 500,
  27326. 'amacron': 500,
  27327. 'sacute': 389,
  27328. 'idieresis': 278,
  27329. 'Ocircumflex': 778,
  27330. 'Ugrave': 722,
  27331. 'Delta': 612,
  27332. 'thorn': 556,
  27333. 'twosuperior': 300,
  27334. 'Odieresis': 778,
  27335. 'mu': 556,
  27336. 'igrave': 278,
  27337. 'ohungarumlaut': 500,
  27338. 'Eogonek': 667,
  27339. 'dcroat': 556,
  27340. 'threequarters': 750,
  27341. 'Scedilla': 556,
  27342. 'lcaron': 394,
  27343. 'Kcommaaccent': 778,
  27344. 'Lacute': 667,
  27345. 'trademark': 1000,
  27346. 'edotaccent': 444,
  27347. 'Igrave': 389,
  27348. 'Imacron': 389,
  27349. 'Lcaron': 667,
  27350. 'onehalf': 750,
  27351. 'lessequal': 549,
  27352. 'ocircumflex': 500,
  27353. 'ntilde': 556,
  27354. 'Uhungarumlaut': 722,
  27355. 'Eacute': 667,
  27356. 'emacron': 444,
  27357. 'gbreve': 500,
  27358. 'onequarter': 750,
  27359. 'Scaron': 556,
  27360. 'Scommaaccent': 556,
  27361. 'Ohungarumlaut': 778,
  27362. 'degree': 400,
  27363. 'ograve': 500,
  27364. 'Ccaron': 722,
  27365. 'ugrave': 556,
  27366. 'radical': 549,
  27367. 'Dcaron': 722,
  27368. 'rcommaaccent': 444,
  27369. 'Ntilde': 722,
  27370. 'otilde': 500,
  27371. 'Rcommaaccent': 722,
  27372. 'Lcommaaccent': 667,
  27373. 'Atilde': 722,
  27374. 'Aogonek': 722,
  27375. 'Aring': 722,
  27376. 'Otilde': 778,
  27377. 'zdotaccent': 444,
  27378. 'Ecaron': 667,
  27379. 'Iogonek': 389,
  27380. 'kcommaaccent': 556,
  27381. 'minus': 570,
  27382. 'Icircumflex': 389,
  27383. 'ncaron': 556,
  27384. 'tcommaaccent': 333,
  27385. 'logicalnot': 570,
  27386. 'odieresis': 500,
  27387. 'udieresis': 556,
  27388. 'notequal': 549,
  27389. 'gcommaaccent': 500,
  27390. 'eth': 500,
  27391. 'zcaron': 444,
  27392. 'ncommaaccent': 556,
  27393. 'onesuperior': 300,
  27394. 'imacron': 278,
  27395. 'Euro': 500
  27396. },
  27397. 'Times-BoldItalic': {
  27398. 'space': 250,
  27399. 'exclam': 389,
  27400. 'quotedbl': 555,
  27401. 'numbersign': 500,
  27402. 'dollar': 500,
  27403. 'percent': 833,
  27404. 'ampersand': 778,
  27405. 'quoteright': 333,
  27406. 'parenleft': 333,
  27407. 'parenright': 333,
  27408. 'asterisk': 500,
  27409. 'plus': 570,
  27410. 'comma': 250,
  27411. 'hyphen': 333,
  27412. 'period': 250,
  27413. 'slash': 278,
  27414. 'zero': 500,
  27415. 'one': 500,
  27416. 'two': 500,
  27417. 'three': 500,
  27418. 'four': 500,
  27419. 'five': 500,
  27420. 'six': 500,
  27421. 'seven': 500,
  27422. 'eight': 500,
  27423. 'nine': 500,
  27424. 'colon': 333,
  27425. 'semicolon': 333,
  27426. 'less': 570,
  27427. 'equal': 570,
  27428. 'greater': 570,
  27429. 'question': 500,
  27430. 'at': 832,
  27431. 'A': 667,
  27432. 'B': 667,
  27433. 'C': 667,
  27434. 'D': 722,
  27435. 'E': 667,
  27436. 'F': 667,
  27437. 'G': 722,
  27438. 'H': 778,
  27439. 'I': 389,
  27440. 'J': 500,
  27441. 'K': 667,
  27442. 'L': 611,
  27443. 'M': 889,
  27444. 'N': 722,
  27445. 'O': 722,
  27446. 'P': 611,
  27447. 'Q': 722,
  27448. 'R': 667,
  27449. 'S': 556,
  27450. 'T': 611,
  27451. 'U': 722,
  27452. 'V': 667,
  27453. 'W': 889,
  27454. 'X': 667,
  27455. 'Y': 611,
  27456. 'Z': 611,
  27457. 'bracketleft': 333,
  27458. 'backslash': 278,
  27459. 'bracketright': 333,
  27460. 'asciicircum': 570,
  27461. 'underscore': 500,
  27462. 'quoteleft': 333,
  27463. 'a': 500,
  27464. 'b': 500,
  27465. 'c': 444,
  27466. 'd': 500,
  27467. 'e': 444,
  27468. 'f': 333,
  27469. 'g': 500,
  27470. 'h': 556,
  27471. 'i': 278,
  27472. 'j': 278,
  27473. 'k': 500,
  27474. 'l': 278,
  27475. 'm': 778,
  27476. 'n': 556,
  27477. 'o': 500,
  27478. 'p': 500,
  27479. 'q': 500,
  27480. 'r': 389,
  27481. 's': 389,
  27482. 't': 278,
  27483. 'u': 556,
  27484. 'v': 444,
  27485. 'w': 667,
  27486. 'x': 500,
  27487. 'y': 444,
  27488. 'z': 389,
  27489. 'braceleft': 348,
  27490. 'bar': 220,
  27491. 'braceright': 348,
  27492. 'asciitilde': 570,
  27493. 'exclamdown': 389,
  27494. 'cent': 500,
  27495. 'sterling': 500,
  27496. 'fraction': 167,
  27497. 'yen': 500,
  27498. 'florin': 500,
  27499. 'section': 500,
  27500. 'currency': 500,
  27501. 'quotesingle': 278,
  27502. 'quotedblleft': 500,
  27503. 'guillemotleft': 500,
  27504. 'guilsinglleft': 333,
  27505. 'guilsinglright': 333,
  27506. 'fi': 556,
  27507. 'fl': 556,
  27508. 'endash': 500,
  27509. 'dagger': 500,
  27510. 'daggerdbl': 500,
  27511. 'periodcentered': 250,
  27512. 'paragraph': 500,
  27513. 'bullet': 350,
  27514. 'quotesinglbase': 333,
  27515. 'quotedblbase': 500,
  27516. 'quotedblright': 500,
  27517. 'guillemotright': 500,
  27518. 'ellipsis': 1000,
  27519. 'perthousand': 1000,
  27520. 'questiondown': 500,
  27521. 'grave': 333,
  27522. 'acute': 333,
  27523. 'circumflex': 333,
  27524. 'tilde': 333,
  27525. 'macron': 333,
  27526. 'breve': 333,
  27527. 'dotaccent': 333,
  27528. 'dieresis': 333,
  27529. 'ring': 333,
  27530. 'cedilla': 333,
  27531. 'hungarumlaut': 333,
  27532. 'ogonek': 333,
  27533. 'caron': 333,
  27534. 'emdash': 1000,
  27535. 'AE': 944,
  27536. 'ordfeminine': 266,
  27537. 'Lslash': 611,
  27538. 'Oslash': 722,
  27539. 'OE': 944,
  27540. 'ordmasculine': 300,
  27541. 'ae': 722,
  27542. 'dotlessi': 278,
  27543. 'lslash': 278,
  27544. 'oslash': 500,
  27545. 'oe': 722,
  27546. 'germandbls': 500,
  27547. 'Idieresis': 389,
  27548. 'eacute': 444,
  27549. 'abreve': 500,
  27550. 'uhungarumlaut': 556,
  27551. 'ecaron': 444,
  27552. 'Ydieresis': 611,
  27553. 'divide': 570,
  27554. 'Yacute': 611,
  27555. 'Acircumflex': 667,
  27556. 'aacute': 500,
  27557. 'Ucircumflex': 722,
  27558. 'yacute': 444,
  27559. 'scommaaccent': 389,
  27560. 'ecircumflex': 444,
  27561. 'Uring': 722,
  27562. 'Udieresis': 722,
  27563. 'aogonek': 500,
  27564. 'Uacute': 722,
  27565. 'uogonek': 556,
  27566. 'Edieresis': 667,
  27567. 'Dcroat': 722,
  27568. 'commaaccent': 250,
  27569. 'copyright': 747,
  27570. 'Emacron': 667,
  27571. 'ccaron': 444,
  27572. 'aring': 500,
  27573. 'Ncommaaccent': 722,
  27574. 'lacute': 278,
  27575. 'agrave': 500,
  27576. 'Tcommaaccent': 611,
  27577. 'Cacute': 667,
  27578. 'atilde': 500,
  27579. 'Edotaccent': 667,
  27580. 'scaron': 389,
  27581. 'scedilla': 389,
  27582. 'iacute': 278,
  27583. 'lozenge': 494,
  27584. 'Rcaron': 667,
  27585. 'Gcommaaccent': 722,
  27586. 'ucircumflex': 556,
  27587. 'acircumflex': 500,
  27588. 'Amacron': 667,
  27589. 'rcaron': 389,
  27590. 'ccedilla': 444,
  27591. 'Zdotaccent': 611,
  27592. 'Thorn': 611,
  27593. 'Omacron': 722,
  27594. 'Racute': 667,
  27595. 'Sacute': 556,
  27596. 'dcaron': 608,
  27597. 'Umacron': 722,
  27598. 'uring': 556,
  27599. 'threesuperior': 300,
  27600. 'Ograve': 722,
  27601. 'Agrave': 667,
  27602. 'Abreve': 667,
  27603. 'multiply': 570,
  27604. 'uacute': 556,
  27605. 'Tcaron': 611,
  27606. 'partialdiff': 494,
  27607. 'ydieresis': 444,
  27608. 'Nacute': 722,
  27609. 'icircumflex': 278,
  27610. 'Ecircumflex': 667,
  27611. 'adieresis': 500,
  27612. 'edieresis': 444,
  27613. 'cacute': 444,
  27614. 'nacute': 556,
  27615. 'umacron': 556,
  27616. 'Ncaron': 722,
  27617. 'Iacute': 389,
  27618. 'plusminus': 570,
  27619. 'brokenbar': 220,
  27620. 'registered': 747,
  27621. 'Gbreve': 722,
  27622. 'Idotaccent': 389,
  27623. 'summation': 600,
  27624. 'Egrave': 667,
  27625. 'racute': 389,
  27626. 'omacron': 500,
  27627. 'Zacute': 611,
  27628. 'Zcaron': 611,
  27629. 'greaterequal': 549,
  27630. 'Eth': 722,
  27631. 'Ccedilla': 667,
  27632. 'lcommaaccent': 278,
  27633. 'tcaron': 366,
  27634. 'eogonek': 444,
  27635. 'Uogonek': 722,
  27636. 'Aacute': 667,
  27637. 'Adieresis': 667,
  27638. 'egrave': 444,
  27639. 'zacute': 389,
  27640. 'iogonek': 278,
  27641. 'Oacute': 722,
  27642. 'oacute': 500,
  27643. 'amacron': 500,
  27644. 'sacute': 389,
  27645. 'idieresis': 278,
  27646. 'Ocircumflex': 722,
  27647. 'Ugrave': 722,
  27648. 'Delta': 612,
  27649. 'thorn': 500,
  27650. 'twosuperior': 300,
  27651. 'Odieresis': 722,
  27652. 'mu': 576,
  27653. 'igrave': 278,
  27654. 'ohungarumlaut': 500,
  27655. 'Eogonek': 667,
  27656. 'dcroat': 500,
  27657. 'threequarters': 750,
  27658. 'Scedilla': 556,
  27659. 'lcaron': 382,
  27660. 'Kcommaaccent': 667,
  27661. 'Lacute': 611,
  27662. 'trademark': 1000,
  27663. 'edotaccent': 444,
  27664. 'Igrave': 389,
  27665. 'Imacron': 389,
  27666. 'Lcaron': 611,
  27667. 'onehalf': 750,
  27668. 'lessequal': 549,
  27669. 'ocircumflex': 500,
  27670. 'ntilde': 556,
  27671. 'Uhungarumlaut': 722,
  27672. 'Eacute': 667,
  27673. 'emacron': 444,
  27674. 'gbreve': 500,
  27675. 'onequarter': 750,
  27676. 'Scaron': 556,
  27677. 'Scommaaccent': 556,
  27678. 'Ohungarumlaut': 722,
  27679. 'degree': 400,
  27680. 'ograve': 500,
  27681. 'Ccaron': 667,
  27682. 'ugrave': 556,
  27683. 'radical': 549,
  27684. 'Dcaron': 722,
  27685. 'rcommaaccent': 389,
  27686. 'Ntilde': 722,
  27687. 'otilde': 500,
  27688. 'Rcommaaccent': 667,
  27689. 'Lcommaaccent': 611,
  27690. 'Atilde': 667,
  27691. 'Aogonek': 667,
  27692. 'Aring': 667,
  27693. 'Otilde': 722,
  27694. 'zdotaccent': 389,
  27695. 'Ecaron': 667,
  27696. 'Iogonek': 389,
  27697. 'kcommaaccent': 500,
  27698. 'minus': 606,
  27699. 'Icircumflex': 389,
  27700. 'ncaron': 556,
  27701. 'tcommaaccent': 278,
  27702. 'logicalnot': 606,
  27703. 'odieresis': 500,
  27704. 'udieresis': 556,
  27705. 'notequal': 549,
  27706. 'gcommaaccent': 500,
  27707. 'eth': 500,
  27708. 'zcaron': 389,
  27709. 'ncommaaccent': 556,
  27710. 'onesuperior': 300,
  27711. 'imacron': 278,
  27712. 'Euro': 500
  27713. },
  27714. 'Times-Italic': {
  27715. 'space': 250,
  27716. 'exclam': 333,
  27717. 'quotedbl': 420,
  27718. 'numbersign': 500,
  27719. 'dollar': 500,
  27720. 'percent': 833,
  27721. 'ampersand': 778,
  27722. 'quoteright': 333,
  27723. 'parenleft': 333,
  27724. 'parenright': 333,
  27725. 'asterisk': 500,
  27726. 'plus': 675,
  27727. 'comma': 250,
  27728. 'hyphen': 333,
  27729. 'period': 250,
  27730. 'slash': 278,
  27731. 'zero': 500,
  27732. 'one': 500,
  27733. 'two': 500,
  27734. 'three': 500,
  27735. 'four': 500,
  27736. 'five': 500,
  27737. 'six': 500,
  27738. 'seven': 500,
  27739. 'eight': 500,
  27740. 'nine': 500,
  27741. 'colon': 333,
  27742. 'semicolon': 333,
  27743. 'less': 675,
  27744. 'equal': 675,
  27745. 'greater': 675,
  27746. 'question': 500,
  27747. 'at': 920,
  27748. 'A': 611,
  27749. 'B': 611,
  27750. 'C': 667,
  27751. 'D': 722,
  27752. 'E': 611,
  27753. 'F': 611,
  27754. 'G': 722,
  27755. 'H': 722,
  27756. 'I': 333,
  27757. 'J': 444,
  27758. 'K': 667,
  27759. 'L': 556,
  27760. 'M': 833,
  27761. 'N': 667,
  27762. 'O': 722,
  27763. 'P': 611,
  27764. 'Q': 722,
  27765. 'R': 611,
  27766. 'S': 500,
  27767. 'T': 556,
  27768. 'U': 722,
  27769. 'V': 611,
  27770. 'W': 833,
  27771. 'X': 611,
  27772. 'Y': 556,
  27773. 'Z': 556,
  27774. 'bracketleft': 389,
  27775. 'backslash': 278,
  27776. 'bracketright': 389,
  27777. 'asciicircum': 422,
  27778. 'underscore': 500,
  27779. 'quoteleft': 333,
  27780. 'a': 500,
  27781. 'b': 500,
  27782. 'c': 444,
  27783. 'd': 500,
  27784. 'e': 444,
  27785. 'f': 278,
  27786. 'g': 500,
  27787. 'h': 500,
  27788. 'i': 278,
  27789. 'j': 278,
  27790. 'k': 444,
  27791. 'l': 278,
  27792. 'm': 722,
  27793. 'n': 500,
  27794. 'o': 500,
  27795. 'p': 500,
  27796. 'q': 500,
  27797. 'r': 389,
  27798. 's': 389,
  27799. 't': 278,
  27800. 'u': 500,
  27801. 'v': 444,
  27802. 'w': 667,
  27803. 'x': 444,
  27804. 'y': 444,
  27805. 'z': 389,
  27806. 'braceleft': 400,
  27807. 'bar': 275,
  27808. 'braceright': 400,
  27809. 'asciitilde': 541,
  27810. 'exclamdown': 389,
  27811. 'cent': 500,
  27812. 'sterling': 500,
  27813. 'fraction': 167,
  27814. 'yen': 500,
  27815. 'florin': 500,
  27816. 'section': 500,
  27817. 'currency': 500,
  27818. 'quotesingle': 214,
  27819. 'quotedblleft': 556,
  27820. 'guillemotleft': 500,
  27821. 'guilsinglleft': 333,
  27822. 'guilsinglright': 333,
  27823. 'fi': 500,
  27824. 'fl': 500,
  27825. 'endash': 500,
  27826. 'dagger': 500,
  27827. 'daggerdbl': 500,
  27828. 'periodcentered': 250,
  27829. 'paragraph': 523,
  27830. 'bullet': 350,
  27831. 'quotesinglbase': 333,
  27832. 'quotedblbase': 556,
  27833. 'quotedblright': 556,
  27834. 'guillemotright': 500,
  27835. 'ellipsis': 889,
  27836. 'perthousand': 1000,
  27837. 'questiondown': 500,
  27838. 'grave': 333,
  27839. 'acute': 333,
  27840. 'circumflex': 333,
  27841. 'tilde': 333,
  27842. 'macron': 333,
  27843. 'breve': 333,
  27844. 'dotaccent': 333,
  27845. 'dieresis': 333,
  27846. 'ring': 333,
  27847. 'cedilla': 333,
  27848. 'hungarumlaut': 333,
  27849. 'ogonek': 333,
  27850. 'caron': 333,
  27851. 'emdash': 889,
  27852. 'AE': 889,
  27853. 'ordfeminine': 276,
  27854. 'Lslash': 556,
  27855. 'Oslash': 722,
  27856. 'OE': 944,
  27857. 'ordmasculine': 310,
  27858. 'ae': 667,
  27859. 'dotlessi': 278,
  27860. 'lslash': 278,
  27861. 'oslash': 500,
  27862. 'oe': 667,
  27863. 'germandbls': 500,
  27864. 'Idieresis': 333,
  27865. 'eacute': 444,
  27866. 'abreve': 500,
  27867. 'uhungarumlaut': 500,
  27868. 'ecaron': 444,
  27869. 'Ydieresis': 556,
  27870. 'divide': 675,
  27871. 'Yacute': 556,
  27872. 'Acircumflex': 611,
  27873. 'aacute': 500,
  27874. 'Ucircumflex': 722,
  27875. 'yacute': 444,
  27876. 'scommaaccent': 389,
  27877. 'ecircumflex': 444,
  27878. 'Uring': 722,
  27879. 'Udieresis': 722,
  27880. 'aogonek': 500,
  27881. 'Uacute': 722,
  27882. 'uogonek': 500,
  27883. 'Edieresis': 611,
  27884. 'Dcroat': 722,
  27885. 'commaaccent': 250,
  27886. 'copyright': 760,
  27887. 'Emacron': 611,
  27888. 'ccaron': 444,
  27889. 'aring': 500,
  27890. 'Ncommaaccent': 667,
  27891. 'lacute': 278,
  27892. 'agrave': 500,
  27893. 'Tcommaaccent': 556,
  27894. 'Cacute': 667,
  27895. 'atilde': 500,
  27896. 'Edotaccent': 611,
  27897. 'scaron': 389,
  27898. 'scedilla': 389,
  27899. 'iacute': 278,
  27900. 'lozenge': 471,
  27901. 'Rcaron': 611,
  27902. 'Gcommaaccent': 722,
  27903. 'ucircumflex': 500,
  27904. 'acircumflex': 500,
  27905. 'Amacron': 611,
  27906. 'rcaron': 389,
  27907. 'ccedilla': 444,
  27908. 'Zdotaccent': 556,
  27909. 'Thorn': 611,
  27910. 'Omacron': 722,
  27911. 'Racute': 611,
  27912. 'Sacute': 500,
  27913. 'dcaron': 544,
  27914. 'Umacron': 722,
  27915. 'uring': 500,
  27916. 'threesuperior': 300,
  27917. 'Ograve': 722,
  27918. 'Agrave': 611,
  27919. 'Abreve': 611,
  27920. 'multiply': 675,
  27921. 'uacute': 500,
  27922. 'Tcaron': 556,
  27923. 'partialdiff': 476,
  27924. 'ydieresis': 444,
  27925. 'Nacute': 667,
  27926. 'icircumflex': 278,
  27927. 'Ecircumflex': 611,
  27928. 'adieresis': 500,
  27929. 'edieresis': 444,
  27930. 'cacute': 444,
  27931. 'nacute': 500,
  27932. 'umacron': 500,
  27933. 'Ncaron': 667,
  27934. 'Iacute': 333,
  27935. 'plusminus': 675,
  27936. 'brokenbar': 275,
  27937. 'registered': 760,
  27938. 'Gbreve': 722,
  27939. 'Idotaccent': 333,
  27940. 'summation': 600,
  27941. 'Egrave': 611,
  27942. 'racute': 389,
  27943. 'omacron': 500,
  27944. 'Zacute': 556,
  27945. 'Zcaron': 556,
  27946. 'greaterequal': 549,
  27947. 'Eth': 722,
  27948. 'Ccedilla': 667,
  27949. 'lcommaaccent': 278,
  27950. 'tcaron': 300,
  27951. 'eogonek': 444,
  27952. 'Uogonek': 722,
  27953. 'Aacute': 611,
  27954. 'Adieresis': 611,
  27955. 'egrave': 444,
  27956. 'zacute': 389,
  27957. 'iogonek': 278,
  27958. 'Oacute': 722,
  27959. 'oacute': 500,
  27960. 'amacron': 500,
  27961. 'sacute': 389,
  27962. 'idieresis': 278,
  27963. 'Ocircumflex': 722,
  27964. 'Ugrave': 722,
  27965. 'Delta': 612,
  27966. 'thorn': 500,
  27967. 'twosuperior': 300,
  27968. 'Odieresis': 722,
  27969. 'mu': 500,
  27970. 'igrave': 278,
  27971. 'ohungarumlaut': 500,
  27972. 'Eogonek': 611,
  27973. 'dcroat': 500,
  27974. 'threequarters': 750,
  27975. 'Scedilla': 500,
  27976. 'lcaron': 300,
  27977. 'Kcommaaccent': 667,
  27978. 'Lacute': 556,
  27979. 'trademark': 980,
  27980. 'edotaccent': 444,
  27981. 'Igrave': 333,
  27982. 'Imacron': 333,
  27983. 'Lcaron': 611,
  27984. 'onehalf': 750,
  27985. 'lessequal': 549,
  27986. 'ocircumflex': 500,
  27987. 'ntilde': 500,
  27988. 'Uhungarumlaut': 722,
  27989. 'Eacute': 611,
  27990. 'emacron': 444,
  27991. 'gbreve': 500,
  27992. 'onequarter': 750,
  27993. 'Scaron': 500,
  27994. 'Scommaaccent': 500,
  27995. 'Ohungarumlaut': 722,
  27996. 'degree': 400,
  27997. 'ograve': 500,
  27998. 'Ccaron': 667,
  27999. 'ugrave': 500,
  28000. 'radical': 453,
  28001. 'Dcaron': 722,
  28002. 'rcommaaccent': 389,
  28003. 'Ntilde': 667,
  28004. 'otilde': 500,
  28005. 'Rcommaaccent': 611,
  28006. 'Lcommaaccent': 556,
  28007. 'Atilde': 611,
  28008. 'Aogonek': 611,
  28009. 'Aring': 611,
  28010. 'Otilde': 722,
  28011. 'zdotaccent': 389,
  28012. 'Ecaron': 611,
  28013. 'Iogonek': 333,
  28014. 'kcommaaccent': 444,
  28015. 'minus': 675,
  28016. 'Icircumflex': 333,
  28017. 'ncaron': 500,
  28018. 'tcommaaccent': 278,
  28019. 'logicalnot': 675,
  28020. 'odieresis': 500,
  28021. 'udieresis': 500,
  28022. 'notequal': 549,
  28023. 'gcommaaccent': 500,
  28024. 'eth': 500,
  28025. 'zcaron': 389,
  28026. 'ncommaaccent': 500,
  28027. 'onesuperior': 300,
  28028. 'imacron': 278,
  28029. 'Euro': 500
  28030. },
  28031. 'ZapfDingbats': {
  28032. 'space': 278,
  28033. 'a1': 974,
  28034. 'a2': 961,
  28035. 'a202': 974,
  28036. 'a3': 980,
  28037. 'a4': 719,
  28038. 'a5': 789,
  28039. 'a119': 790,
  28040. 'a118': 791,
  28041. 'a117': 690,
  28042. 'a11': 960,
  28043. 'a12': 939,
  28044. 'a13': 549,
  28045. 'a14': 855,
  28046. 'a15': 911,
  28047. 'a16': 933,
  28048. 'a105': 911,
  28049. 'a17': 945,
  28050. 'a18': 974,
  28051. 'a19': 755,
  28052. 'a20': 846,
  28053. 'a21': 762,
  28054. 'a22': 761,
  28055. 'a23': 571,
  28056. 'a24': 677,
  28057. 'a25': 763,
  28058. 'a26': 760,
  28059. 'a27': 759,
  28060. 'a28': 754,
  28061. 'a6': 494,
  28062. 'a7': 552,
  28063. 'a8': 537,
  28064. 'a9': 577,
  28065. 'a10': 692,
  28066. 'a29': 786,
  28067. 'a30': 788,
  28068. 'a31': 788,
  28069. 'a32': 790,
  28070. 'a33': 793,
  28071. 'a34': 794,
  28072. 'a35': 816,
  28073. 'a36': 823,
  28074. 'a37': 789,
  28075. 'a38': 841,
  28076. 'a39': 823,
  28077. 'a40': 833,
  28078. 'a41': 816,
  28079. 'a42': 831,
  28080. 'a43': 923,
  28081. 'a44': 744,
  28082. 'a45': 723,
  28083. 'a46': 749,
  28084. 'a47': 790,
  28085. 'a48': 792,
  28086. 'a49': 695,
  28087. 'a50': 776,
  28088. 'a51': 768,
  28089. 'a52': 792,
  28090. 'a53': 759,
  28091. 'a54': 707,
  28092. 'a55': 708,
  28093. 'a56': 682,
  28094. 'a57': 701,
  28095. 'a58': 826,
  28096. 'a59': 815,
  28097. 'a60': 789,
  28098. 'a61': 789,
  28099. 'a62': 707,
  28100. 'a63': 687,
  28101. 'a64': 696,
  28102. 'a65': 689,
  28103. 'a66': 786,
  28104. 'a67': 787,
  28105. 'a68': 713,
  28106. 'a69': 791,
  28107. 'a70': 785,
  28108. 'a71': 791,
  28109. 'a72': 873,
  28110. 'a73': 761,
  28111. 'a74': 762,
  28112. 'a203': 762,
  28113. 'a75': 759,
  28114. 'a204': 759,
  28115. 'a76': 892,
  28116. 'a77': 892,
  28117. 'a78': 788,
  28118. 'a79': 784,
  28119. 'a81': 438,
  28120. 'a82': 138,
  28121. 'a83': 277,
  28122. 'a84': 415,
  28123. 'a97': 392,
  28124. 'a98': 392,
  28125. 'a99': 668,
  28126. 'a100': 668,
  28127. 'a89': 390,
  28128. 'a90': 390,
  28129. 'a93': 317,
  28130. 'a94': 317,
  28131. 'a91': 276,
  28132. 'a92': 276,
  28133. 'a205': 509,
  28134. 'a85': 509,
  28135. 'a206': 410,
  28136. 'a86': 410,
  28137. 'a87': 234,
  28138. 'a88': 234,
  28139. 'a95': 334,
  28140. 'a96': 334,
  28141. 'a101': 732,
  28142. 'a102': 544,
  28143. 'a103': 544,
  28144. 'a104': 910,
  28145. 'a106': 667,
  28146. 'a107': 760,
  28147. 'a108': 760,
  28148. 'a112': 776,
  28149. 'a111': 595,
  28150. 'a110': 694,
  28151. 'a109': 626,
  28152. 'a120': 788,
  28153. 'a121': 788,
  28154. 'a122': 788,
  28155. 'a123': 788,
  28156. 'a124': 788,
  28157. 'a125': 788,
  28158. 'a126': 788,
  28159. 'a127': 788,
  28160. 'a128': 788,
  28161. 'a129': 788,
  28162. 'a130': 788,
  28163. 'a131': 788,
  28164. 'a132': 788,
  28165. 'a133': 788,
  28166. 'a134': 788,
  28167. 'a135': 788,
  28168. 'a136': 788,
  28169. 'a137': 788,
  28170. 'a138': 788,
  28171. 'a139': 788,
  28172. 'a140': 788,
  28173. 'a141': 788,
  28174. 'a142': 788,
  28175. 'a143': 788,
  28176. 'a144': 788,
  28177. 'a145': 788,
  28178. 'a146': 788,
  28179. 'a147': 788,
  28180. 'a148': 788,
  28181. 'a149': 788,
  28182. 'a150': 788,
  28183. 'a151': 788,
  28184. 'a152': 788,
  28185. 'a153': 788,
  28186. 'a154': 788,
  28187. 'a155': 788,
  28188. 'a156': 788,
  28189. 'a157': 788,
  28190. 'a158': 788,
  28191. 'a159': 788,
  28192. 'a160': 894,
  28193. 'a161': 838,
  28194. 'a163': 1016,
  28195. 'a164': 458,
  28196. 'a196': 748,
  28197. 'a165': 924,
  28198. 'a192': 748,
  28199. 'a166': 918,
  28200. 'a167': 927,
  28201. 'a168': 928,
  28202. 'a169': 928,
  28203. 'a170': 834,
  28204. 'a171': 873,
  28205. 'a172': 828,
  28206. 'a173': 924,
  28207. 'a162': 924,
  28208. 'a174': 917,
  28209. 'a175': 930,
  28210. 'a176': 931,
  28211. 'a177': 463,
  28212. 'a178': 883,
  28213. 'a179': 836,
  28214. 'a193': 836,
  28215. 'a180': 867,
  28216. 'a199': 867,
  28217. 'a181': 696,
  28218. 'a200': 696,
  28219. 'a182': 874,
  28220. 'a201': 874,
  28221. 'a183': 760,
  28222. 'a184': 946,
  28223. 'a197': 771,
  28224. 'a185': 865,
  28225. 'a194': 771,
  28226. 'a198': 888,
  28227. 'a186': 967,
  28228. 'a195': 888,
  28229. 'a187': 831,
  28230. 'a188': 873,
  28231. 'a189': 927,
  28232. 'a190': 970,
  28233. 'a191': 918
  28234. }
  28235. };
  28236. var EOF = {};
  28237. function isEOF(v) {
  28238. return (v === EOF);
  28239. }
  28240. var MAX_LENGTH_TO_CACHE = 1000;
  28241. var Parser = (function ParserClosure() {
  28242. function Parser(lexer, allowStreams, xref) {
  28243. this.lexer = lexer;
  28244. this.allowStreams = allowStreams;
  28245. this.xref = xref;
  28246. this.imageCache = {};
  28247. this.refill();
  28248. }
  28249. Parser.prototype = {
  28250. refill: function Parser_refill() {
  28251. this.buf1 = this.lexer.getObj();
  28252. this.buf2 = this.lexer.getObj();
  28253. },
  28254. shift: function Parser_shift() {
  28255. if (isCmd(this.buf2, 'ID')) {
  28256. this.buf1 = this.buf2;
  28257. this.buf2 = null;
  28258. } else {
  28259. this.buf1 = this.buf2;
  28260. this.buf2 = this.lexer.getObj();
  28261. }
  28262. },
  28263. getObj: function Parser_getObj(cipherTransform) {
  28264. var buf1 = this.buf1;
  28265. this.shift();
  28266. if (buf1 instanceof Cmd) {
  28267. switch (buf1.cmd) {
  28268. case 'BI': // inline image
  28269. return this.makeInlineImage(cipherTransform);
  28270. case '[': // array
  28271. var array = [];
  28272. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28273. array.push(this.getObj(cipherTransform));
  28274. }
  28275. if (isEOF(this.buf1)) {
  28276. error('End of file inside array');
  28277. }
  28278. this.shift();
  28279. return array;
  28280. case '<<': // dictionary or stream
  28281. var dict = new Dict(this.xref);
  28282. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28283. if (!isName(this.buf1)) {
  28284. info('Malformed dictionary: key must be a name object');
  28285. this.shift();
  28286. continue;
  28287. }
  28288. var key = this.buf1.name;
  28289. this.shift();
  28290. if (isEOF(this.buf1)) {
  28291. break;
  28292. }
  28293. dict.set(key, this.getObj(cipherTransform));
  28294. }
  28295. if (isEOF(this.buf1)) {
  28296. error('End of file inside dictionary');
  28297. }
  28298. // Stream objects are not allowed inside content streams or
  28299. // object streams.
  28300. if (isCmd(this.buf2, 'stream')) {
  28301. return (this.allowStreams ?
  28302. this.makeStream(dict, cipherTransform) : dict);
  28303. }
  28304. this.shift();
  28305. return dict;
  28306. default: // simple object
  28307. return buf1;
  28308. }
  28309. }
  28310. if (isInt(buf1)) { // indirect reference or integer
  28311. var num = buf1;
  28312. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28313. var ref = new Ref(num, this.buf1);
  28314. this.shift();
  28315. this.shift();
  28316. return ref;
  28317. }
  28318. return num;
  28319. }
  28320. if (isString(buf1)) { // string
  28321. var str = buf1;
  28322. if (cipherTransform) {
  28323. str = cipherTransform.decryptString(str);
  28324. }
  28325. return str;
  28326. }
  28327. // simple object
  28328. return buf1;
  28329. },
  28330. /**
  28331. * Find the end of the stream by searching for the /EI\s/.
  28332. * @returns {number} The inline stream length.
  28333. */
  28334. findDefaultInlineStreamEnd:
  28335. function Parser_findDefaultInlineStreamEnd(stream) {
  28336. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28337. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28338. while ((ch = stream.getByte()) !== -1) {
  28339. if (state === 0) {
  28340. state = (ch === E) ? 1 : 0;
  28341. } else if (state === 1) {
  28342. state = (ch === I) ? 2 : 0;
  28343. } else {
  28344. assert(state === 2);
  28345. if (ch === SPACE || ch === LF || ch === CR) {
  28346. // Let's check the next five bytes are ASCII... just be sure.
  28347. n = 5;
  28348. followingBytes = stream.peekBytes(n);
  28349. for (i = 0; i < n; i++) {
  28350. ch = followingBytes[i];
  28351. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28352. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28353. // it's binary stuff. Resetting the state.
  28354. state = 0;
  28355. break;
  28356. }
  28357. }
  28358. if (state === 2) {
  28359. break; // Finished!
  28360. }
  28361. } else {
  28362. state = 0;
  28363. }
  28364. }
  28365. }
  28366. return ((stream.pos - 4) - startPos);
  28367. },
  28368. /**
  28369. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28370. * @returns {number} The inline stream length.
  28371. */
  28372. findDCTDecodeInlineStreamEnd:
  28373. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28374. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28375. while ((b = stream.getByte()) !== -1) {
  28376. if (b !== 0xFF) { // Not a valid marker.
  28377. continue;
  28378. }
  28379. switch (stream.getByte()) {
  28380. case 0x00: // Byte stuffing.
  28381. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28382. break;
  28383. case 0xFF: // Fill byte.
  28384. // Avoid skipping a valid marker, resetting the stream position.
  28385. stream.skip(-1);
  28386. break;
  28387. case 0xD9: // EOI
  28388. foundEOI = true;
  28389. break;
  28390. case 0xC0: // SOF0
  28391. case 0xC1: // SOF1
  28392. case 0xC2: // SOF2
  28393. case 0xC3: // SOF3
  28394. case 0xC5: // SOF5
  28395. case 0xC6: // SOF6
  28396. case 0xC7: // SOF7
  28397. case 0xC9: // SOF9
  28398. case 0xCA: // SOF10
  28399. case 0xCB: // SOF11
  28400. case 0xCD: // SOF13
  28401. case 0xCE: // SOF14
  28402. case 0xCF: // SOF15
  28403. case 0xC4: // DHT
  28404. case 0xCC: // DAC
  28405. case 0xDA: // SOS
  28406. case 0xDB: // DQT
  28407. case 0xDC: // DNL
  28408. case 0xDD: // DRI
  28409. case 0xDE: // DHP
  28410. case 0xDF: // EXP
  28411. case 0xE0: // APP0
  28412. case 0xE1: // APP1
  28413. case 0xE2: // APP2
  28414. case 0xE3: // APP3
  28415. case 0xE4: // APP4
  28416. case 0xE5: // APP5
  28417. case 0xE6: // APP6
  28418. case 0xE7: // APP7
  28419. case 0xE8: // APP8
  28420. case 0xE9: // APP9
  28421. case 0xEA: // APP10
  28422. case 0xEB: // APP11
  28423. case 0xEC: // APP12
  28424. case 0xED: // APP13
  28425. case 0xEE: // APP14
  28426. case 0xEF: // APP15
  28427. case 0xFE: // COM
  28428. // The marker should be followed by the length of the segment.
  28429. markerLength = stream.getUint16();
  28430. if (markerLength > 2) {
  28431. // |markerLength| contains the byte length of the marker segment,
  28432. // including its own length (2 bytes) and excluding the marker.
  28433. stream.skip(markerLength - 2); // Jump to the next marker.
  28434. } else {
  28435. // The marker length is invalid, resetting the stream position.
  28436. stream.skip(-2);
  28437. }
  28438. break;
  28439. }
  28440. if (foundEOI) {
  28441. break;
  28442. }
  28443. }
  28444. length = stream.pos - startPos;
  28445. if (b === -1) {
  28446. warn('Inline DCTDecode image stream: ' +
  28447. 'EOI marker not found, searching for /EI/ instead.');
  28448. stream.skip(-length); // Reset the stream position.
  28449. return this.findDefaultInlineStreamEnd(stream);
  28450. }
  28451. this.inlineStreamSkipEI(stream);
  28452. return length;
  28453. },
  28454. /**
  28455. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28456. * @returns {number} The inline stream length.
  28457. */
  28458. findASCII85DecodeInlineStreamEnd:
  28459. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28460. var TILDE = 0x7E, GT = 0x3E;
  28461. var startPos = stream.pos, ch, length;
  28462. while ((ch = stream.getByte()) !== -1) {
  28463. if (ch === TILDE && stream.peekByte() === GT) {
  28464. stream.skip();
  28465. break;
  28466. }
  28467. }
  28468. length = stream.pos - startPos;
  28469. if (ch === -1) {
  28470. warn('Inline ASCII85Decode image stream: ' +
  28471. 'EOD marker not found, searching for /EI/ instead.');
  28472. stream.skip(-length); // Reset the stream position.
  28473. return this.findDefaultInlineStreamEnd(stream);
  28474. }
  28475. this.inlineStreamSkipEI(stream);
  28476. return length;
  28477. },
  28478. /**
  28479. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28480. * @returns {number} The inline stream length.
  28481. */
  28482. findASCIIHexDecodeInlineStreamEnd:
  28483. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28484. var GT = 0x3E;
  28485. var startPos = stream.pos, ch, length;
  28486. while ((ch = stream.getByte()) !== -1) {
  28487. if (ch === GT) {
  28488. break;
  28489. }
  28490. }
  28491. length = stream.pos - startPos;
  28492. if (ch === -1) {
  28493. warn('Inline ASCIIHexDecode image stream: ' +
  28494. 'EOD marker not found, searching for /EI/ instead.');
  28495. stream.skip(-length); // Reset the stream position.
  28496. return this.findDefaultInlineStreamEnd(stream);
  28497. }
  28498. this.inlineStreamSkipEI(stream);
  28499. return length;
  28500. },
  28501. /**
  28502. * Skip over the /EI/ for streams where we search for an EOD marker.
  28503. */
  28504. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28505. var E = 0x45, I = 0x49;
  28506. var state = 0, ch;
  28507. while ((ch = stream.getByte()) !== -1) {
  28508. if (state === 0) {
  28509. state = (ch === E) ? 1 : 0;
  28510. } else if (state === 1) {
  28511. state = (ch === I) ? 2 : 0;
  28512. } else if (state === 2) {
  28513. break;
  28514. }
  28515. }
  28516. },
  28517. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28518. var lexer = this.lexer;
  28519. var stream = lexer.stream;
  28520. // Parse dictionary.
  28521. var dict = new Dict(null);
  28522. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28523. if (!isName(this.buf1)) {
  28524. error('Dictionary key must be a name object');
  28525. }
  28526. var key = this.buf1.name;
  28527. this.shift();
  28528. if (isEOF(this.buf1)) {
  28529. break;
  28530. }
  28531. dict.set(key, this.getObj(cipherTransform));
  28532. }
  28533. // Extract the name of the first (i.e. the current) image filter.
  28534. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28535. if (isName(filter)) {
  28536. filterName = filter.name;
  28537. } else if (isArray(filter) && isName(filter[0])) {
  28538. filterName = filter[0].name;
  28539. }
  28540. // Parse image stream.
  28541. var startPos = stream.pos, length, i, ii;
  28542. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28543. length = this.findDCTDecodeInlineStreamEnd(stream);
  28544. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28545. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28546. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28547. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28548. } else {
  28549. length = this.findDefaultInlineStreamEnd(stream);
  28550. }
  28551. var imageStream = stream.makeSubStream(startPos, length, dict);
  28552. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28553. // adler32 checksum.
  28554. var adler32;
  28555. if (length < MAX_LENGTH_TO_CACHE) {
  28556. var imageBytes = imageStream.getBytes();
  28557. imageStream.reset();
  28558. var a = 1;
  28559. var b = 0;
  28560. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28561. // No modulo required in the loop if imageBytes.length < 5552.
  28562. a += imageBytes[i] & 0xff;
  28563. b += a;
  28564. }
  28565. adler32 = ((b % 65521) << 16) | (a % 65521);
  28566. if (this.imageCache.adler32 === adler32) {
  28567. this.buf2 = Cmd.get('EI');
  28568. this.shift();
  28569. this.imageCache[adler32].reset();
  28570. return this.imageCache[adler32];
  28571. }
  28572. }
  28573. if (cipherTransform) {
  28574. imageStream = cipherTransform.createStream(imageStream, length);
  28575. }
  28576. imageStream = this.filter(imageStream, dict, length);
  28577. imageStream.dict = dict;
  28578. if (adler32 !== undefined) {
  28579. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28580. this.imageCache[adler32] = imageStream;
  28581. }
  28582. this.buf2 = Cmd.get('EI');
  28583. this.shift();
  28584. return imageStream;
  28585. },
  28586. fetchIfRef: function Parser_fetchIfRef(obj) {
  28587. // not relying on the xref.fetchIfRef -- xref might not be set
  28588. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28589. },
  28590. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28591. var lexer = this.lexer;
  28592. var stream = lexer.stream;
  28593. // get stream start position
  28594. lexer.skipToNextLine();
  28595. var pos = stream.pos - 1;
  28596. // get length
  28597. var length = this.fetchIfRef(dict.get('Length'));
  28598. if (!isInt(length)) {
  28599. info('Bad ' + length + ' attribute in stream');
  28600. length = 0;
  28601. }
  28602. // skip over the stream data
  28603. stream.pos = pos + length;
  28604. lexer.nextChar();
  28605. this.shift(); // '>>'
  28606. this.shift(); // 'stream'
  28607. if (!isCmd(this.buf1, 'endstream')) {
  28608. // bad stream length, scanning for endstream
  28609. stream.pos = pos;
  28610. var SCAN_BLOCK_SIZE = 2048;
  28611. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28612. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28613. 0x61, 0x6D];
  28614. var skipped = 0, found = false, i, j;
  28615. while (stream.pos < stream.end) {
  28616. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28617. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28618. if (scanLength <= 0) {
  28619. break;
  28620. }
  28621. found = false;
  28622. for (i = 0, j = 0; i < scanLength; i++) {
  28623. var b = scanBytes[i];
  28624. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28625. i -= j;
  28626. j = 0;
  28627. } else {
  28628. j++;
  28629. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28630. i++;
  28631. found = true;
  28632. break;
  28633. }
  28634. }
  28635. }
  28636. if (found) {
  28637. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28638. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28639. break;
  28640. }
  28641. skipped += scanLength;
  28642. stream.pos += scanLength;
  28643. }
  28644. if (!found) {
  28645. error('Missing endstream');
  28646. }
  28647. length = skipped;
  28648. lexer.nextChar();
  28649. this.shift();
  28650. this.shift();
  28651. }
  28652. this.shift(); // 'endstream'
  28653. stream = stream.makeSubStream(pos, length, dict);
  28654. if (cipherTransform) {
  28655. stream = cipherTransform.createStream(stream, length);
  28656. }
  28657. stream = this.filter(stream, dict, length);
  28658. stream.dict = dict;
  28659. return stream;
  28660. },
  28661. filter: function Parser_filter(stream, dict, length) {
  28662. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  28663. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  28664. if (isName(filter)) {
  28665. return this.makeFilter(stream, filter.name, length, params);
  28666. }
  28667. var maybeLength = length;
  28668. if (isArray(filter)) {
  28669. var filterArray = filter;
  28670. var paramsArray = params;
  28671. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  28672. filter = filterArray[i];
  28673. if (!isName(filter)) {
  28674. error('Bad filter name: ' + filter);
  28675. }
  28676. params = null;
  28677. if (isArray(paramsArray) && (i in paramsArray)) {
  28678. params = paramsArray[i];
  28679. }
  28680. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  28681. // after the first stream the length variable is invalid
  28682. maybeLength = null;
  28683. }
  28684. }
  28685. return stream;
  28686. },
  28687. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  28688. if (stream.dict.get('Length') === 0) {
  28689. return new NullStream(stream);
  28690. }
  28691. try {
  28692. if (params) {
  28693. params = this.fetchIfRef(params);
  28694. }
  28695. var xrefStreamStats = this.xref.stats.streamTypes;
  28696. if (name === 'FlateDecode' || name === 'Fl') {
  28697. xrefStreamStats[StreamType.FLATE] = true;
  28698. if (params) {
  28699. return new PredictorStream(new FlateStream(stream, maybeLength),
  28700. maybeLength, params);
  28701. }
  28702. return new FlateStream(stream, maybeLength);
  28703. }
  28704. if (name === 'LZWDecode' || name === 'LZW') {
  28705. xrefStreamStats[StreamType.LZW] = true;
  28706. var earlyChange = 1;
  28707. if (params) {
  28708. if (params.has('EarlyChange')) {
  28709. earlyChange = params.get('EarlyChange');
  28710. }
  28711. return new PredictorStream(
  28712. new LZWStream(stream, maybeLength, earlyChange),
  28713. maybeLength, params);
  28714. }
  28715. return new LZWStream(stream, maybeLength, earlyChange);
  28716. }
  28717. if (name === 'DCTDecode' || name === 'DCT') {
  28718. xrefStreamStats[StreamType.DCT] = true;
  28719. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  28720. }
  28721. if (name === 'JPXDecode' || name === 'JPX') {
  28722. xrefStreamStats[StreamType.JPX] = true;
  28723. return new JpxStream(stream, maybeLength, stream.dict);
  28724. }
  28725. if (name === 'ASCII85Decode' || name === 'A85') {
  28726. xrefStreamStats[StreamType.A85] = true;
  28727. return new Ascii85Stream(stream, maybeLength);
  28728. }
  28729. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  28730. xrefStreamStats[StreamType.AHX] = true;
  28731. return new AsciiHexStream(stream, maybeLength);
  28732. }
  28733. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  28734. xrefStreamStats[StreamType.CCF] = true;
  28735. return new CCITTFaxStream(stream, maybeLength, params);
  28736. }
  28737. if (name === 'RunLengthDecode' || name === 'RL') {
  28738. xrefStreamStats[StreamType.RL] = true;
  28739. return new RunLengthStream(stream, maybeLength);
  28740. }
  28741. if (name === 'JBIG2Decode') {
  28742. xrefStreamStats[StreamType.JBIG] = true;
  28743. return new Jbig2Stream(stream, maybeLength, stream.dict);
  28744. }
  28745. warn('filter "' + name + '" not supported yet');
  28746. return stream;
  28747. } catch (ex) {
  28748. if (ex instanceof MissingDataException) {
  28749. throw ex;
  28750. }
  28751. warn('Invalid stream: \"' + ex + '\"');
  28752. return new NullStream(stream);
  28753. }
  28754. }
  28755. };
  28756. return Parser;
  28757. })();
  28758. var Lexer = (function LexerClosure() {
  28759. function Lexer(stream, knownCommands) {
  28760. this.stream = stream;
  28761. this.nextChar();
  28762. // While lexing, we build up many strings one char at a time. Using += for
  28763. // this can result in lots of garbage strings. It's better to build an
  28764. // array of single-char strings and then join() them together at the end.
  28765. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  28766. // purpose uses less memory than using a new array for each string.
  28767. this.strBuf = [];
  28768. // The PDFs might have "glued" commands with other commands, operands or
  28769. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  28770. // commands and their prefixes. The prefixes are built the following way:
  28771. // if there a command that is a prefix of the other valid command or
  28772. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  28773. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  28774. // other commands or literals as a prefix. The knowCommands is optional.
  28775. this.knownCommands = knownCommands;
  28776. }
  28777. Lexer.isSpace = function Lexer_isSpace(ch) {
  28778. // Space is one of the following characters: SPACE, TAB, CR or LF.
  28779. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  28780. };
  28781. // A '1' in this array means the character is white space. A '1' or
  28782. // '2' means the character ends a name or command.
  28783. var specialChars = [
  28784. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  28785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  28786. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  28787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  28788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  28789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  28790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  28791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  28792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  28793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  28794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  28795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  28796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  28797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  28798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  28799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  28800. ];
  28801. function toHexDigit(ch) {
  28802. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28803. return ch & 0x0F;
  28804. }
  28805. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28806. // 'A'-'F', 'a'-'f'
  28807. return (ch & 0x0F) + 9;
  28808. }
  28809. return -1;
  28810. }
  28811. Lexer.prototype = {
  28812. nextChar: function Lexer_nextChar() {
  28813. return (this.currentChar = this.stream.getByte());
  28814. },
  28815. peekChar: function Lexer_peekChar() {
  28816. return this.stream.peekByte();
  28817. },
  28818. getNumber: function Lexer_getNumber() {
  28819. var ch = this.currentChar;
  28820. var eNotation = false;
  28821. var divideBy = 0; // different from 0 if it's a floating point value
  28822. var sign = 1;
  28823. if (ch === 0x2D) { // '-'
  28824. sign = -1;
  28825. ch = this.nextChar();
  28826. } else if (ch === 0x2B) { // '+'
  28827. ch = this.nextChar();
  28828. }
  28829. if (ch === 0x2E) { // '.'
  28830. divideBy = 10;
  28831. ch = this.nextChar();
  28832. }
  28833. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28834. error('Invalid number: ' + String.fromCharCode(ch));
  28835. return 0;
  28836. }
  28837. var baseValue = ch - 0x30; // '0'
  28838. var powerValue = 0;
  28839. var powerValueSign = 1;
  28840. while ((ch = this.nextChar()) >= 0) {
  28841. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  28842. var currentDigit = ch - 0x30; // '0'
  28843. if (eNotation) { // We are after an 'e' or 'E'
  28844. powerValue = powerValue * 10 + currentDigit;
  28845. } else {
  28846. if (divideBy !== 0) { // We are after a point
  28847. divideBy *= 10;
  28848. }
  28849. baseValue = baseValue * 10 + currentDigit;
  28850. }
  28851. } else if (ch === 0x2E) { // '.'
  28852. if (divideBy === 0) {
  28853. divideBy = 1;
  28854. } else {
  28855. // A number can have only one '.'
  28856. break;
  28857. }
  28858. } else if (ch === 0x2D) { // '-'
  28859. // ignore minus signs in the middle of numbers to match
  28860. // Adobe's behavior
  28861. warn('Badly formated number');
  28862. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  28863. // 'E' can be either a scientific notation or the beginning of a new
  28864. // operator
  28865. ch = this.peekChar();
  28866. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  28867. powerValueSign = (ch === 0x2D) ? -1 : 1;
  28868. this.nextChar(); // Consume the sign character
  28869. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  28870. // The 'E' must be the beginning of a new operator
  28871. break;
  28872. }
  28873. eNotation = true;
  28874. } else {
  28875. // the last character doesn't belong to us
  28876. break;
  28877. }
  28878. }
  28879. if (divideBy !== 0) {
  28880. baseValue /= divideBy;
  28881. }
  28882. if (eNotation) {
  28883. baseValue *= Math.pow(10, powerValueSign * powerValue);
  28884. }
  28885. return sign * baseValue;
  28886. },
  28887. getString: function Lexer_getString() {
  28888. var numParen = 1;
  28889. var done = false;
  28890. var strBuf = this.strBuf;
  28891. strBuf.length = 0;
  28892. var ch = this.nextChar();
  28893. while (true) {
  28894. var charBuffered = false;
  28895. switch (ch | 0) {
  28896. case -1:
  28897. warn('Unterminated string');
  28898. done = true;
  28899. break;
  28900. case 0x28: // '('
  28901. ++numParen;
  28902. strBuf.push('(');
  28903. break;
  28904. case 0x29: // ')'
  28905. if (--numParen === 0) {
  28906. this.nextChar(); // consume strings ')'
  28907. done = true;
  28908. } else {
  28909. strBuf.push(')');
  28910. }
  28911. break;
  28912. case 0x5C: // '\\'
  28913. ch = this.nextChar();
  28914. switch (ch) {
  28915. case -1:
  28916. warn('Unterminated string');
  28917. done = true;
  28918. break;
  28919. case 0x6E: // 'n'
  28920. strBuf.push('\n');
  28921. break;
  28922. case 0x72: // 'r'
  28923. strBuf.push('\r');
  28924. break;
  28925. case 0x74: // 't'
  28926. strBuf.push('\t');
  28927. break;
  28928. case 0x62: // 'b'
  28929. strBuf.push('\b');
  28930. break;
  28931. case 0x66: // 'f'
  28932. strBuf.push('\f');
  28933. break;
  28934. case 0x5C: // '\'
  28935. case 0x28: // '('
  28936. case 0x29: // ')'
  28937. strBuf.push(String.fromCharCode(ch));
  28938. break;
  28939. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  28940. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  28941. var x = ch & 0x0F;
  28942. ch = this.nextChar();
  28943. charBuffered = true;
  28944. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28945. x = (x << 3) + (ch & 0x0F);
  28946. ch = this.nextChar();
  28947. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  28948. charBuffered = false;
  28949. x = (x << 3) + (ch & 0x0F);
  28950. }
  28951. }
  28952. strBuf.push(String.fromCharCode(x));
  28953. break;
  28954. case 0x0D: // CR
  28955. if (this.peekChar() === 0x0A) { // LF
  28956. this.nextChar();
  28957. }
  28958. break;
  28959. case 0x0A: // LF
  28960. break;
  28961. default:
  28962. strBuf.push(String.fromCharCode(ch));
  28963. break;
  28964. }
  28965. break;
  28966. default:
  28967. strBuf.push(String.fromCharCode(ch));
  28968. break;
  28969. }
  28970. if (done) {
  28971. break;
  28972. }
  28973. if (!charBuffered) {
  28974. ch = this.nextChar();
  28975. }
  28976. }
  28977. return strBuf.join('');
  28978. },
  28979. getName: function Lexer_getName() {
  28980. var ch;
  28981. var strBuf = this.strBuf;
  28982. strBuf.length = 0;
  28983. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  28984. if (ch === 0x23) { // '#'
  28985. ch = this.nextChar();
  28986. var x = toHexDigit(ch);
  28987. if (x !== -1) {
  28988. var x2 = toHexDigit(this.nextChar());
  28989. if (x2 === -1) {
  28990. error('Illegal digit in hex char in name: ' + x2);
  28991. }
  28992. strBuf.push(String.fromCharCode((x << 4) | x2));
  28993. } else {
  28994. strBuf.push('#', String.fromCharCode(ch));
  28995. }
  28996. } else {
  28997. strBuf.push(String.fromCharCode(ch));
  28998. }
  28999. }
  29000. if (strBuf.length > 128) {
  29001. error('Warning: name token is longer than allowed by the spec: ' +
  29002. strBuf.length);
  29003. }
  29004. return Name.get(strBuf.join(''));
  29005. },
  29006. getHexString: function Lexer_getHexString() {
  29007. var strBuf = this.strBuf;
  29008. strBuf.length = 0;
  29009. var ch = this.currentChar;
  29010. var isFirstHex = true;
  29011. var firstDigit;
  29012. var secondDigit;
  29013. while (true) {
  29014. if (ch < 0) {
  29015. warn('Unterminated hex string');
  29016. break;
  29017. } else if (ch === 0x3E) { // '>'
  29018. this.nextChar();
  29019. break;
  29020. } else if (specialChars[ch] === 1) {
  29021. ch = this.nextChar();
  29022. continue;
  29023. } else {
  29024. if (isFirstHex) {
  29025. firstDigit = toHexDigit(ch);
  29026. if (firstDigit === -1) {
  29027. warn('Ignoring invalid character "' + ch + '" in hex string');
  29028. ch = this.nextChar();
  29029. continue;
  29030. }
  29031. } else {
  29032. secondDigit = toHexDigit(ch);
  29033. if (secondDigit === -1) {
  29034. warn('Ignoring invalid character "' + ch + '" in hex string');
  29035. ch = this.nextChar();
  29036. continue;
  29037. }
  29038. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29039. }
  29040. isFirstHex = !isFirstHex;
  29041. ch = this.nextChar();
  29042. }
  29043. }
  29044. return strBuf.join('');
  29045. },
  29046. getObj: function Lexer_getObj() {
  29047. // skip whitespace and comments
  29048. var comment = false;
  29049. var ch = this.currentChar;
  29050. while (true) {
  29051. if (ch < 0) {
  29052. return EOF;
  29053. }
  29054. if (comment) {
  29055. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29056. comment = false;
  29057. }
  29058. } else if (ch === 0x25) { // '%'
  29059. comment = true;
  29060. } else if (specialChars[ch] !== 1) {
  29061. break;
  29062. }
  29063. ch = this.nextChar();
  29064. }
  29065. // start reading token
  29066. switch (ch | 0) {
  29067. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29068. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29069. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29070. return this.getNumber();
  29071. case 0x28: // '('
  29072. return this.getString();
  29073. case 0x2F: // '/'
  29074. return this.getName();
  29075. // array punctuation
  29076. case 0x5B: // '['
  29077. this.nextChar();
  29078. return Cmd.get('[');
  29079. case 0x5D: // ']'
  29080. this.nextChar();
  29081. return Cmd.get(']');
  29082. // hex string or dict punctuation
  29083. case 0x3C: // '<'
  29084. ch = this.nextChar();
  29085. if (ch === 0x3C) {
  29086. // dict punctuation
  29087. this.nextChar();
  29088. return Cmd.get('<<');
  29089. }
  29090. return this.getHexString();
  29091. // dict punctuation
  29092. case 0x3E: // '>'
  29093. ch = this.nextChar();
  29094. if (ch === 0x3E) {
  29095. this.nextChar();
  29096. return Cmd.get('>>');
  29097. }
  29098. return Cmd.get('>');
  29099. case 0x7B: // '{'
  29100. this.nextChar();
  29101. return Cmd.get('{');
  29102. case 0x7D: // '}'
  29103. this.nextChar();
  29104. return Cmd.get('}');
  29105. case 0x29: // ')'
  29106. error('Illegal character: ' + ch);
  29107. break;
  29108. }
  29109. // command
  29110. var str = String.fromCharCode(ch);
  29111. var knownCommands = this.knownCommands;
  29112. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29113. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29114. // stop if known command is found and next character does not make
  29115. // the str a command
  29116. var possibleCommand = str + String.fromCharCode(ch);
  29117. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29118. break;
  29119. }
  29120. if (str.length === 128) {
  29121. error('Command token too long: ' + str.length);
  29122. }
  29123. str = possibleCommand;
  29124. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29125. }
  29126. if (str === 'true') {
  29127. return true;
  29128. }
  29129. if (str === 'false') {
  29130. return false;
  29131. }
  29132. if (str === 'null') {
  29133. return null;
  29134. }
  29135. return Cmd.get(str);
  29136. },
  29137. skipToNextLine: function Lexer_skipToNextLine() {
  29138. var ch = this.currentChar;
  29139. while (ch >= 0) {
  29140. if (ch === 0x0D) { // CR
  29141. ch = this.nextChar();
  29142. if (ch === 0x0A) { // LF
  29143. this.nextChar();
  29144. }
  29145. break;
  29146. } else if (ch === 0x0A) { // LF
  29147. this.nextChar();
  29148. break;
  29149. }
  29150. ch = this.nextChar();
  29151. }
  29152. }
  29153. };
  29154. return Lexer;
  29155. })();
  29156. var Linearization = {
  29157. create: function LinearizationCreate(stream) {
  29158. function getInt(name, allowZeroValue) {
  29159. var obj = linDict.get(name);
  29160. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29161. return obj;
  29162. }
  29163. throw new Error('The "' + name + '" parameter in the linearization ' +
  29164. 'dictionary is invalid.');
  29165. }
  29166. function getHints() {
  29167. var hints = linDict.get('H'), hintsLength, item;
  29168. if (isArray(hints) &&
  29169. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29170. for (var index = 0; index < hintsLength; index++) {
  29171. if (!(isInt(item = hints[index]) && item > 0)) {
  29172. throw new Error('Hint (' + index +
  29173. ') in the linearization dictionary is invalid.');
  29174. }
  29175. }
  29176. return hints;
  29177. }
  29178. throw new Error('Hint array in the linearization dictionary is invalid.');
  29179. }
  29180. var parser = new Parser(new Lexer(stream), false, null);
  29181. var obj1 = parser.getObj();
  29182. var obj2 = parser.getObj();
  29183. var obj3 = parser.getObj();
  29184. var linDict = parser.getObj();
  29185. var obj, length;
  29186. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29187. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29188. return null; // No valid linearization dictionary found.
  29189. } else if ((length = getInt('L')) !== stream.length) {
  29190. throw new Error('The "L" parameter in the linearization dictionary ' +
  29191. 'does not equal the stream length.');
  29192. }
  29193. return {
  29194. length: length,
  29195. hints: getHints(),
  29196. objectNumberFirst: getInt('O'),
  29197. endFirst: getInt('E'),
  29198. numPages: getInt('N'),
  29199. mainXRefEntriesOffset: getInt('T'),
  29200. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29201. };
  29202. }
  29203. };
  29204. var PostScriptParser = (function PostScriptParserClosure() {
  29205. function PostScriptParser(lexer) {
  29206. this.lexer = lexer;
  29207. this.operators = [];
  29208. this.token = null;
  29209. this.prev = null;
  29210. }
  29211. PostScriptParser.prototype = {
  29212. nextToken: function PostScriptParser_nextToken() {
  29213. this.prev = this.token;
  29214. this.token = this.lexer.getToken();
  29215. },
  29216. accept: function PostScriptParser_accept(type) {
  29217. if (this.token.type === type) {
  29218. this.nextToken();
  29219. return true;
  29220. }
  29221. return false;
  29222. },
  29223. expect: function PostScriptParser_expect(type) {
  29224. if (this.accept(type)) {
  29225. return true;
  29226. }
  29227. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29228. type + '.');
  29229. },
  29230. parse: function PostScriptParser_parse() {
  29231. this.nextToken();
  29232. this.expect(PostScriptTokenTypes.LBRACE);
  29233. this.parseBlock();
  29234. this.expect(PostScriptTokenTypes.RBRACE);
  29235. return this.operators;
  29236. },
  29237. parseBlock: function PostScriptParser_parseBlock() {
  29238. while (true) {
  29239. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29240. this.operators.push(this.prev.value);
  29241. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29242. this.operators.push(this.prev.value);
  29243. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29244. this.parseCondition();
  29245. } else {
  29246. return;
  29247. }
  29248. }
  29249. },
  29250. parseCondition: function PostScriptParser_parseCondition() {
  29251. // Add two place holders that will be updated later
  29252. var conditionLocation = this.operators.length;
  29253. this.operators.push(null, null);
  29254. this.parseBlock();
  29255. this.expect(PostScriptTokenTypes.RBRACE);
  29256. if (this.accept(PostScriptTokenTypes.IF)) {
  29257. // The true block is right after the 'if' so it just falls through on
  29258. // true else it jumps and skips the true block.
  29259. this.operators[conditionLocation] = this.operators.length;
  29260. this.operators[conditionLocation + 1] = 'jz';
  29261. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29262. var jumpLocation = this.operators.length;
  29263. this.operators.push(null, null);
  29264. var endOfTrue = this.operators.length;
  29265. this.parseBlock();
  29266. this.expect(PostScriptTokenTypes.RBRACE);
  29267. this.expect(PostScriptTokenTypes.IFELSE);
  29268. // The jump is added at the end of the true block to skip the false
  29269. // block.
  29270. this.operators[jumpLocation] = this.operators.length;
  29271. this.operators[jumpLocation + 1] = 'j';
  29272. this.operators[conditionLocation] = endOfTrue;
  29273. this.operators[conditionLocation + 1] = 'jz';
  29274. } else {
  29275. error('PS Function: error parsing conditional.');
  29276. }
  29277. }
  29278. };
  29279. return PostScriptParser;
  29280. })();
  29281. var PostScriptTokenTypes = {
  29282. LBRACE: 0,
  29283. RBRACE: 1,
  29284. NUMBER: 2,
  29285. OPERATOR: 3,
  29286. IF: 4,
  29287. IFELSE: 5
  29288. };
  29289. var PostScriptToken = (function PostScriptTokenClosure() {
  29290. function PostScriptToken(type, value) {
  29291. this.type = type;
  29292. this.value = value;
  29293. }
  29294. var opCache = {};
  29295. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29296. var opValue = opCache[op];
  29297. if (opValue) {
  29298. return opValue;
  29299. }
  29300. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29301. };
  29302. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29303. '{');
  29304. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29305. '}');
  29306. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29307. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29308. 'IFELSE');
  29309. return PostScriptToken;
  29310. })();
  29311. var PostScriptLexer = (function PostScriptLexerClosure() {
  29312. function PostScriptLexer(stream) {
  29313. this.stream = stream;
  29314. this.nextChar();
  29315. this.strBuf = [];
  29316. }
  29317. PostScriptLexer.prototype = {
  29318. nextChar: function PostScriptLexer_nextChar() {
  29319. return (this.currentChar = this.stream.getByte());
  29320. },
  29321. getToken: function PostScriptLexer_getToken() {
  29322. var comment = false;
  29323. var ch = this.currentChar;
  29324. // skip comments
  29325. while (true) {
  29326. if (ch < 0) {
  29327. return EOF;
  29328. }
  29329. if (comment) {
  29330. if (ch === 0x0A || ch === 0x0D) {
  29331. comment = false;
  29332. }
  29333. } else if (ch === 0x25) { // '%'
  29334. comment = true;
  29335. } else if (!Lexer.isSpace(ch)) {
  29336. break;
  29337. }
  29338. ch = this.nextChar();
  29339. }
  29340. switch (ch | 0) {
  29341. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29342. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29343. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29344. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29345. this.getNumber());
  29346. case 0x7B: // '{'
  29347. this.nextChar();
  29348. return PostScriptToken.LBRACE;
  29349. case 0x7D: // '}'
  29350. this.nextChar();
  29351. return PostScriptToken.RBRACE;
  29352. }
  29353. // operator
  29354. var strBuf = this.strBuf;
  29355. strBuf.length = 0;
  29356. strBuf[0] = String.fromCharCode(ch);
  29357. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29358. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29359. strBuf.push(String.fromCharCode(ch));
  29360. }
  29361. var str = strBuf.join('');
  29362. switch (str.toLowerCase()) {
  29363. case 'if':
  29364. return PostScriptToken.IF;
  29365. case 'ifelse':
  29366. return PostScriptToken.IFELSE;
  29367. default:
  29368. return PostScriptToken.getOperator(str);
  29369. }
  29370. },
  29371. getNumber: function PostScriptLexer_getNumber() {
  29372. var ch = this.currentChar;
  29373. var strBuf = this.strBuf;
  29374. strBuf.length = 0;
  29375. strBuf[0] = String.fromCharCode(ch);
  29376. while ((ch = this.nextChar()) >= 0) {
  29377. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29378. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29379. strBuf.push(String.fromCharCode(ch));
  29380. } else {
  29381. break;
  29382. }
  29383. }
  29384. var value = parseFloat(strBuf.join(''));
  29385. if (isNaN(value)) {
  29386. error('Invalid floating point number: ' + value);
  29387. }
  29388. return value;
  29389. }
  29390. };
  29391. return PostScriptLexer;
  29392. })();
  29393. var Stream = (function StreamClosure() {
  29394. function Stream(arrayBuffer, start, length, dict) {
  29395. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29396. arrayBuffer : new Uint8Array(arrayBuffer));
  29397. this.start = start || 0;
  29398. this.pos = this.start;
  29399. this.end = (start + length) || this.bytes.length;
  29400. this.dict = dict;
  29401. }
  29402. // required methods for a stream. if a particular stream does not
  29403. // implement these, an error should be thrown
  29404. Stream.prototype = {
  29405. get length() {
  29406. return this.end - this.start;
  29407. },
  29408. get isEmpty() {
  29409. return this.length === 0;
  29410. },
  29411. getByte: function Stream_getByte() {
  29412. if (this.pos >= this.end) {
  29413. return -1;
  29414. }
  29415. return this.bytes[this.pos++];
  29416. },
  29417. getUint16: function Stream_getUint16() {
  29418. var b0 = this.getByte();
  29419. var b1 = this.getByte();
  29420. if (b0 === -1 || b1 === -1) {
  29421. return -1;
  29422. }
  29423. return (b0 << 8) + b1;
  29424. },
  29425. getInt32: function Stream_getInt32() {
  29426. var b0 = this.getByte();
  29427. var b1 = this.getByte();
  29428. var b2 = this.getByte();
  29429. var b3 = this.getByte();
  29430. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29431. },
  29432. // returns subarray of original buffer
  29433. // should only be read
  29434. getBytes: function Stream_getBytes(length) {
  29435. var bytes = this.bytes;
  29436. var pos = this.pos;
  29437. var strEnd = this.end;
  29438. if (!length) {
  29439. return bytes.subarray(pos, strEnd);
  29440. }
  29441. var end = pos + length;
  29442. if (end > strEnd) {
  29443. end = strEnd;
  29444. }
  29445. this.pos = end;
  29446. return bytes.subarray(pos, end);
  29447. },
  29448. peekByte: function Stream_peekByte() {
  29449. var peekedByte = this.getByte();
  29450. this.pos--;
  29451. return peekedByte;
  29452. },
  29453. peekBytes: function Stream_peekBytes(length) {
  29454. var bytes = this.getBytes(length);
  29455. this.pos -= bytes.length;
  29456. return bytes;
  29457. },
  29458. skip: function Stream_skip(n) {
  29459. if (!n) {
  29460. n = 1;
  29461. }
  29462. this.pos += n;
  29463. },
  29464. reset: function Stream_reset() {
  29465. this.pos = this.start;
  29466. },
  29467. moveStart: function Stream_moveStart() {
  29468. this.start = this.pos;
  29469. },
  29470. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29471. return new Stream(this.bytes.buffer, start, length, dict);
  29472. },
  29473. isStream: true
  29474. };
  29475. return Stream;
  29476. })();
  29477. var StringStream = (function StringStreamClosure() {
  29478. function StringStream(str) {
  29479. var length = str.length;
  29480. var bytes = new Uint8Array(length);
  29481. for (var n = 0; n < length; ++n) {
  29482. bytes[n] = str.charCodeAt(n);
  29483. }
  29484. Stream.call(this, bytes);
  29485. }
  29486. StringStream.prototype = Stream.prototype;
  29487. return StringStream;
  29488. })();
  29489. // super class for the decoding streams
  29490. var DecodeStream = (function DecodeStreamClosure() {
  29491. // Lots of DecodeStreams are created whose buffers are never used. For these
  29492. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29493. // having special cases that would be required if we used |null| for an empty
  29494. // buffer.
  29495. var emptyBuffer = new Uint8Array(0);
  29496. function DecodeStream(maybeMinBufferLength) {
  29497. this.pos = 0;
  29498. this.bufferLength = 0;
  29499. this.eof = false;
  29500. this.buffer = emptyBuffer;
  29501. this.minBufferLength = 512;
  29502. if (maybeMinBufferLength) {
  29503. // Compute the first power of two that is as big as maybeMinBufferLength.
  29504. while (this.minBufferLength < maybeMinBufferLength) {
  29505. this.minBufferLength *= 2;
  29506. }
  29507. }
  29508. }
  29509. DecodeStream.prototype = {
  29510. get isEmpty() {
  29511. while (!this.eof && this.bufferLength === 0) {
  29512. this.readBlock();
  29513. }
  29514. return this.bufferLength === 0;
  29515. },
  29516. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29517. var buffer = this.buffer;
  29518. if (requested <= buffer.byteLength) {
  29519. return buffer;
  29520. }
  29521. var size = this.minBufferLength;
  29522. while (size < requested) {
  29523. size *= 2;
  29524. }
  29525. var buffer2 = new Uint8Array(size);
  29526. buffer2.set(buffer);
  29527. return (this.buffer = buffer2);
  29528. },
  29529. getByte: function DecodeStream_getByte() {
  29530. var pos = this.pos;
  29531. while (this.bufferLength <= pos) {
  29532. if (this.eof) {
  29533. return -1;
  29534. }
  29535. this.readBlock();
  29536. }
  29537. return this.buffer[this.pos++];
  29538. },
  29539. getUint16: function DecodeStream_getUint16() {
  29540. var b0 = this.getByte();
  29541. var b1 = this.getByte();
  29542. if (b0 === -1 || b1 === -1) {
  29543. return -1;
  29544. }
  29545. return (b0 << 8) + b1;
  29546. },
  29547. getInt32: function DecodeStream_getInt32() {
  29548. var b0 = this.getByte();
  29549. var b1 = this.getByte();
  29550. var b2 = this.getByte();
  29551. var b3 = this.getByte();
  29552. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29553. },
  29554. getBytes: function DecodeStream_getBytes(length) {
  29555. var end, pos = this.pos;
  29556. if (length) {
  29557. this.ensureBuffer(pos + length);
  29558. end = pos + length;
  29559. while (!this.eof && this.bufferLength < end) {
  29560. this.readBlock();
  29561. }
  29562. var bufEnd = this.bufferLength;
  29563. if (end > bufEnd) {
  29564. end = bufEnd;
  29565. }
  29566. } else {
  29567. while (!this.eof) {
  29568. this.readBlock();
  29569. }
  29570. end = this.bufferLength;
  29571. }
  29572. this.pos = end;
  29573. return this.buffer.subarray(pos, end);
  29574. },
  29575. peekByte: function DecodeStream_peekByte() {
  29576. var peekedByte = this.getByte();
  29577. this.pos--;
  29578. return peekedByte;
  29579. },
  29580. peekBytes: function DecodeStream_peekBytes(length) {
  29581. var bytes = this.getBytes(length);
  29582. this.pos -= bytes.length;
  29583. return bytes;
  29584. },
  29585. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29586. var end = start + length;
  29587. while (this.bufferLength <= end && !this.eof) {
  29588. this.readBlock();
  29589. }
  29590. return new Stream(this.buffer, start, length, dict);
  29591. },
  29592. skip: function DecodeStream_skip(n) {
  29593. if (!n) {
  29594. n = 1;
  29595. }
  29596. this.pos += n;
  29597. },
  29598. reset: function DecodeStream_reset() {
  29599. this.pos = 0;
  29600. },
  29601. getBaseStreams: function DecodeStream_getBaseStreams() {
  29602. if (this.str && this.str.getBaseStreams) {
  29603. return this.str.getBaseStreams();
  29604. }
  29605. return [];
  29606. }
  29607. };
  29608. return DecodeStream;
  29609. })();
  29610. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29611. function StreamsSequenceStream(streams) {
  29612. this.streams = streams;
  29613. DecodeStream.call(this, /* maybeLength = */ null);
  29614. }
  29615. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29616. StreamsSequenceStream.prototype.readBlock =
  29617. function streamSequenceStreamReadBlock() {
  29618. var streams = this.streams;
  29619. if (streams.length === 0) {
  29620. this.eof = true;
  29621. return;
  29622. }
  29623. var stream = streams.shift();
  29624. var chunk = stream.getBytes();
  29625. var bufferLength = this.bufferLength;
  29626. var newLength = bufferLength + chunk.length;
  29627. var buffer = this.ensureBuffer(newLength);
  29628. buffer.set(chunk, bufferLength);
  29629. this.bufferLength = newLength;
  29630. };
  29631. StreamsSequenceStream.prototype.getBaseStreams =
  29632. function StreamsSequenceStream_getBaseStreams() {
  29633. var baseStreams = [];
  29634. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29635. var stream = this.streams[i];
  29636. if (stream.getBaseStreams) {
  29637. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29638. }
  29639. }
  29640. return baseStreams;
  29641. };
  29642. return StreamsSequenceStream;
  29643. })();
  29644. var FlateStream = (function FlateStreamClosure() {
  29645. var codeLenCodeMap = new Uint32Array([
  29646. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  29647. ]);
  29648. var lengthDecode = new Uint32Array([
  29649. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  29650. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  29651. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  29652. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  29653. ]);
  29654. var distDecode = new Uint32Array([
  29655. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  29656. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  29657. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  29658. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  29659. ]);
  29660. var fixedLitCodeTab = [new Uint32Array([
  29661. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  29662. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  29663. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  29664. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  29665. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  29666. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  29667. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  29668. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  29669. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  29670. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  29671. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  29672. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  29673. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  29674. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  29675. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  29676. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  29677. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  29678. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  29679. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  29680. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  29681. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  29682. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  29683. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  29684. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  29685. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  29686. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  29687. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  29688. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  29689. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  29690. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  29691. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  29692. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  29693. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  29694. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  29695. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  29696. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  29697. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  29698. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  29699. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  29700. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  29701. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  29702. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  29703. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  29704. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  29705. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  29706. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  29707. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  29708. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  29709. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  29710. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  29711. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  29712. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  29713. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  29714. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  29715. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  29716. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  29717. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  29718. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  29719. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  29720. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  29721. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  29722. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  29723. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  29724. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  29725. ]), 9];
  29726. var fixedDistCodeTab = [new Uint32Array([
  29727. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  29728. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  29729. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  29730. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  29731. ]), 5];
  29732. function FlateStream(str, maybeLength) {
  29733. this.str = str;
  29734. this.dict = str.dict;
  29735. var cmf = str.getByte();
  29736. var flg = str.getByte();
  29737. if (cmf === -1 || flg === -1) {
  29738. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  29739. }
  29740. if ((cmf & 0x0f) !== 0x08) {
  29741. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  29742. }
  29743. if ((((cmf << 8) + flg) % 31) !== 0) {
  29744. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  29745. }
  29746. if (flg & 0x20) {
  29747. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  29748. }
  29749. this.codeSize = 0;
  29750. this.codeBuf = 0;
  29751. DecodeStream.call(this, maybeLength);
  29752. }
  29753. FlateStream.prototype = Object.create(DecodeStream.prototype);
  29754. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  29755. var str = this.str;
  29756. var codeSize = this.codeSize;
  29757. var codeBuf = this.codeBuf;
  29758. var b;
  29759. while (codeSize < bits) {
  29760. if ((b = str.getByte()) === -1) {
  29761. error('Bad encoding in flate stream');
  29762. }
  29763. codeBuf |= b << codeSize;
  29764. codeSize += 8;
  29765. }
  29766. b = codeBuf & ((1 << bits) - 1);
  29767. this.codeBuf = codeBuf >> bits;
  29768. this.codeSize = codeSize -= bits;
  29769. return b;
  29770. };
  29771. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  29772. var str = this.str;
  29773. var codes = table[0];
  29774. var maxLen = table[1];
  29775. var codeSize = this.codeSize;
  29776. var codeBuf = this.codeBuf;
  29777. var b;
  29778. while (codeSize < maxLen) {
  29779. if ((b = str.getByte()) === -1) {
  29780. // premature end of stream. code might however still be valid.
  29781. // codeSize < codeLen check below guards against incomplete codeVal.
  29782. break;
  29783. }
  29784. codeBuf |= (b << codeSize);
  29785. codeSize += 8;
  29786. }
  29787. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  29788. var codeLen = code >> 16;
  29789. var codeVal = code & 0xffff;
  29790. if (codeLen < 1 || codeSize < codeLen) {
  29791. error('Bad encoding in flate stream');
  29792. }
  29793. this.codeBuf = (codeBuf >> codeLen);
  29794. this.codeSize = (codeSize - codeLen);
  29795. return codeVal;
  29796. };
  29797. FlateStream.prototype.generateHuffmanTable =
  29798. function flateStreamGenerateHuffmanTable(lengths) {
  29799. var n = lengths.length;
  29800. // find max code length
  29801. var maxLen = 0;
  29802. var i;
  29803. for (i = 0; i < n; ++i) {
  29804. if (lengths[i] > maxLen) {
  29805. maxLen = lengths[i];
  29806. }
  29807. }
  29808. // build the table
  29809. var size = 1 << maxLen;
  29810. var codes = new Uint32Array(size);
  29811. for (var len = 1, code = 0, skip = 2;
  29812. len <= maxLen;
  29813. ++len, code <<= 1, skip <<= 1) {
  29814. for (var val = 0; val < n; ++val) {
  29815. if (lengths[val] === len) {
  29816. // bit-reverse the code
  29817. var code2 = 0;
  29818. var t = code;
  29819. for (i = 0; i < len; ++i) {
  29820. code2 = (code2 << 1) | (t & 1);
  29821. t >>= 1;
  29822. }
  29823. // fill the table entries
  29824. for (i = code2; i < size; i += skip) {
  29825. codes[i] = (len << 16) | val;
  29826. }
  29827. ++code;
  29828. }
  29829. }
  29830. }
  29831. return [codes, maxLen];
  29832. };
  29833. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  29834. var buffer, len;
  29835. var str = this.str;
  29836. // read block header
  29837. var hdr = this.getBits(3);
  29838. if (hdr & 1) {
  29839. this.eof = true;
  29840. }
  29841. hdr >>= 1;
  29842. if (hdr === 0) { // uncompressed block
  29843. var b;
  29844. if ((b = str.getByte()) === -1) {
  29845. error('Bad block header in flate stream');
  29846. }
  29847. var blockLen = b;
  29848. if ((b = str.getByte()) === -1) {
  29849. error('Bad block header in flate stream');
  29850. }
  29851. blockLen |= (b << 8);
  29852. if ((b = str.getByte()) === -1) {
  29853. error('Bad block header in flate stream');
  29854. }
  29855. var check = b;
  29856. if ((b = str.getByte()) === -1) {
  29857. error('Bad block header in flate stream');
  29858. }
  29859. check |= (b << 8);
  29860. if (check !== (~blockLen & 0xffff) &&
  29861. (blockLen !== 0 || check !== 0)) {
  29862. // Ignoring error for bad "empty" block (see issue 1277)
  29863. error('Bad uncompressed block length in flate stream');
  29864. }
  29865. this.codeBuf = 0;
  29866. this.codeSize = 0;
  29867. var bufferLength = this.bufferLength;
  29868. buffer = this.ensureBuffer(bufferLength + blockLen);
  29869. var end = bufferLength + blockLen;
  29870. this.bufferLength = end;
  29871. if (blockLen === 0) {
  29872. if (str.peekByte() === -1) {
  29873. this.eof = true;
  29874. }
  29875. } else {
  29876. for (var n = bufferLength; n < end; ++n) {
  29877. if ((b = str.getByte()) === -1) {
  29878. this.eof = true;
  29879. break;
  29880. }
  29881. buffer[n] = b;
  29882. }
  29883. }
  29884. return;
  29885. }
  29886. var litCodeTable;
  29887. var distCodeTable;
  29888. if (hdr === 1) { // compressed block, fixed codes
  29889. litCodeTable = fixedLitCodeTab;
  29890. distCodeTable = fixedDistCodeTab;
  29891. } else if (hdr === 2) { // compressed block, dynamic codes
  29892. var numLitCodes = this.getBits(5) + 257;
  29893. var numDistCodes = this.getBits(5) + 1;
  29894. var numCodeLenCodes = this.getBits(4) + 4;
  29895. // build the code lengths code table
  29896. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  29897. var i;
  29898. for (i = 0; i < numCodeLenCodes; ++i) {
  29899. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  29900. }
  29901. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  29902. // build the literal and distance code tables
  29903. len = 0;
  29904. i = 0;
  29905. var codes = numLitCodes + numDistCodes;
  29906. var codeLengths = new Uint8Array(codes);
  29907. var bitsLength, bitsOffset, what;
  29908. while (i < codes) {
  29909. var code = this.getCode(codeLenCodeTab);
  29910. if (code === 16) {
  29911. bitsLength = 2; bitsOffset = 3; what = len;
  29912. } else if (code === 17) {
  29913. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  29914. } else if (code === 18) {
  29915. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  29916. } else {
  29917. codeLengths[i++] = len = code;
  29918. continue;
  29919. }
  29920. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  29921. while (repeatLength-- > 0) {
  29922. codeLengths[i++] = what;
  29923. }
  29924. }
  29925. litCodeTable =
  29926. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  29927. distCodeTable =
  29928. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  29929. } else {
  29930. error('Unknown block type in flate stream');
  29931. }
  29932. buffer = this.buffer;
  29933. var limit = buffer ? buffer.length : 0;
  29934. var pos = this.bufferLength;
  29935. while (true) {
  29936. var code1 = this.getCode(litCodeTable);
  29937. if (code1 < 256) {
  29938. if (pos + 1 >= limit) {
  29939. buffer = this.ensureBuffer(pos + 1);
  29940. limit = buffer.length;
  29941. }
  29942. buffer[pos++] = code1;
  29943. continue;
  29944. }
  29945. if (code1 === 256) {
  29946. this.bufferLength = pos;
  29947. return;
  29948. }
  29949. code1 -= 257;
  29950. code1 = lengthDecode[code1];
  29951. var code2 = code1 >> 16;
  29952. if (code2 > 0) {
  29953. code2 = this.getBits(code2);
  29954. }
  29955. len = (code1 & 0xffff) + code2;
  29956. code1 = this.getCode(distCodeTable);
  29957. code1 = distDecode[code1];
  29958. code2 = code1 >> 16;
  29959. if (code2 > 0) {
  29960. code2 = this.getBits(code2);
  29961. }
  29962. var dist = (code1 & 0xffff) + code2;
  29963. if (pos + len >= limit) {
  29964. buffer = this.ensureBuffer(pos + len);
  29965. limit = buffer.length;
  29966. }
  29967. for (var k = 0; k < len; ++k, ++pos) {
  29968. buffer[pos] = buffer[pos - dist];
  29969. }
  29970. }
  29971. };
  29972. return FlateStream;
  29973. })();
  29974. var PredictorStream = (function PredictorStreamClosure() {
  29975. function PredictorStream(str, maybeLength, params) {
  29976. var predictor = this.predictor = params.get('Predictor') || 1;
  29977. if (predictor <= 1) {
  29978. return str; // no prediction
  29979. }
  29980. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  29981. error('Unsupported predictor: ' + predictor);
  29982. }
  29983. if (predictor === 2) {
  29984. this.readBlock = this.readBlockTiff;
  29985. } else {
  29986. this.readBlock = this.readBlockPng;
  29987. }
  29988. this.str = str;
  29989. this.dict = str.dict;
  29990. var colors = this.colors = params.get('Colors') || 1;
  29991. var bits = this.bits = params.get('BitsPerComponent') || 8;
  29992. var columns = this.columns = params.get('Columns') || 1;
  29993. this.pixBytes = (colors * bits + 7) >> 3;
  29994. this.rowBytes = (columns * colors * bits + 7) >> 3;
  29995. DecodeStream.call(this, maybeLength);
  29996. return this;
  29997. }
  29998. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  29999. PredictorStream.prototype.readBlockTiff =
  30000. function predictorStreamReadBlockTiff() {
  30001. var rowBytes = this.rowBytes;
  30002. var bufferLength = this.bufferLength;
  30003. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30004. var bits = this.bits;
  30005. var colors = this.colors;
  30006. var rawBytes = this.str.getBytes(rowBytes);
  30007. this.eof = !rawBytes.length;
  30008. if (this.eof) {
  30009. return;
  30010. }
  30011. var inbuf = 0, outbuf = 0;
  30012. var inbits = 0, outbits = 0;
  30013. var pos = bufferLength;
  30014. var i;
  30015. if (bits === 1) {
  30016. for (i = 0; i < rowBytes; ++i) {
  30017. var c = rawBytes[i];
  30018. inbuf = (inbuf << 8) | c;
  30019. // bitwise addition is exclusive or
  30020. // first shift inbuf and then add
  30021. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30022. // truncate inbuf (assumes colors < 16)
  30023. inbuf &= 0xFFFF;
  30024. }
  30025. } else if (bits === 8) {
  30026. for (i = 0; i < colors; ++i) {
  30027. buffer[pos++] = rawBytes[i];
  30028. }
  30029. for (; i < rowBytes; ++i) {
  30030. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30031. pos++;
  30032. }
  30033. } else {
  30034. var compArray = new Uint8Array(colors + 1);
  30035. var bitMask = (1 << bits) - 1;
  30036. var j = 0, k = bufferLength;
  30037. var columns = this.columns;
  30038. for (i = 0; i < columns; ++i) {
  30039. for (var kk = 0; kk < colors; ++kk) {
  30040. if (inbits < bits) {
  30041. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30042. inbits += 8;
  30043. }
  30044. compArray[kk] = (compArray[kk] +
  30045. (inbuf >> (inbits - bits))) & bitMask;
  30046. inbits -= bits;
  30047. outbuf = (outbuf << bits) | compArray[kk];
  30048. outbits += bits;
  30049. if (outbits >= 8) {
  30050. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30051. outbits -= 8;
  30052. }
  30053. }
  30054. }
  30055. if (outbits > 0) {
  30056. buffer[k++] = (outbuf << (8 - outbits)) +
  30057. (inbuf & ((1 << (8 - outbits)) - 1));
  30058. }
  30059. }
  30060. this.bufferLength += rowBytes;
  30061. };
  30062. PredictorStream.prototype.readBlockPng =
  30063. function predictorStreamReadBlockPng() {
  30064. var rowBytes = this.rowBytes;
  30065. var pixBytes = this.pixBytes;
  30066. var predictor = this.str.getByte();
  30067. var rawBytes = this.str.getBytes(rowBytes);
  30068. this.eof = !rawBytes.length;
  30069. if (this.eof) {
  30070. return;
  30071. }
  30072. var bufferLength = this.bufferLength;
  30073. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30074. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30075. if (prevRow.length === 0) {
  30076. prevRow = new Uint8Array(rowBytes);
  30077. }
  30078. var i, j = bufferLength, up, c;
  30079. switch (predictor) {
  30080. case 0:
  30081. for (i = 0; i < rowBytes; ++i) {
  30082. buffer[j++] = rawBytes[i];
  30083. }
  30084. break;
  30085. case 1:
  30086. for (i = 0; i < pixBytes; ++i) {
  30087. buffer[j++] = rawBytes[i];
  30088. }
  30089. for (; i < rowBytes; ++i) {
  30090. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30091. j++;
  30092. }
  30093. break;
  30094. case 2:
  30095. for (i = 0; i < rowBytes; ++i) {
  30096. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30097. }
  30098. break;
  30099. case 3:
  30100. for (i = 0; i < pixBytes; ++i) {
  30101. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30102. }
  30103. for (; i < rowBytes; ++i) {
  30104. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30105. rawBytes[i]) & 0xFF;
  30106. j++;
  30107. }
  30108. break;
  30109. case 4:
  30110. // we need to save the up left pixels values. the simplest way
  30111. // is to create a new buffer
  30112. for (i = 0; i < pixBytes; ++i) {
  30113. up = prevRow[i];
  30114. c = rawBytes[i];
  30115. buffer[j++] = up + c;
  30116. }
  30117. for (; i < rowBytes; ++i) {
  30118. up = prevRow[i];
  30119. var upLeft = prevRow[i - pixBytes];
  30120. var left = buffer[j - pixBytes];
  30121. var p = left + up - upLeft;
  30122. var pa = p - left;
  30123. if (pa < 0) {
  30124. pa = -pa;
  30125. }
  30126. var pb = p - up;
  30127. if (pb < 0) {
  30128. pb = -pb;
  30129. }
  30130. var pc = p - upLeft;
  30131. if (pc < 0) {
  30132. pc = -pc;
  30133. }
  30134. c = rawBytes[i];
  30135. if (pa <= pb && pa <= pc) {
  30136. buffer[j++] = left + c;
  30137. } else if (pb <= pc) {
  30138. buffer[j++] = up + c;
  30139. } else {
  30140. buffer[j++] = upLeft + c;
  30141. }
  30142. }
  30143. break;
  30144. default:
  30145. error('Unsupported predictor: ' + predictor);
  30146. }
  30147. this.bufferLength += rowBytes;
  30148. };
  30149. return PredictorStream;
  30150. })();
  30151. /**
  30152. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30153. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30154. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30155. * a library to decode these images and the stream behaves like all the other
  30156. * DecodeStreams.
  30157. */
  30158. var JpegStream = (function JpegStreamClosure() {
  30159. function JpegStream(stream, maybeLength, dict, xref) {
  30160. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30161. // Note: this seems to mainly affect inline images.
  30162. var ch;
  30163. while ((ch = stream.getByte()) !== -1) {
  30164. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30165. stream.skip(-1); // Reset the stream position to the SOI.
  30166. break;
  30167. }
  30168. }
  30169. this.stream = stream;
  30170. this.maybeLength = maybeLength;
  30171. this.dict = dict;
  30172. DecodeStream.call(this, maybeLength);
  30173. }
  30174. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30175. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30176. get: function JpegStream_bytes() {
  30177. // If this.maybeLength is null, we'll get the entire stream.
  30178. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30179. },
  30180. configurable: true
  30181. });
  30182. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30183. if (this.bufferLength) {
  30184. return;
  30185. }
  30186. try {
  30187. var jpegImage = new JpegImage();
  30188. // checking if values needs to be transformed before conversion
  30189. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30190. var decodeArr = this.dict.get('Decode');
  30191. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30192. var decodeArrLength = decodeArr.length;
  30193. var transform = new Int32Array(decodeArrLength);
  30194. var transformNeeded = false;
  30195. var maxValue = (1 << bitsPerComponent) - 1;
  30196. for (var i = 0; i < decodeArrLength; i += 2) {
  30197. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30198. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30199. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30200. transformNeeded = true;
  30201. }
  30202. }
  30203. if (transformNeeded) {
  30204. jpegImage.decodeTransform = transform;
  30205. }
  30206. }
  30207. jpegImage.parse(this.bytes);
  30208. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30209. this.forceRGB);
  30210. this.buffer = data;
  30211. this.bufferLength = data.length;
  30212. this.eof = true;
  30213. } catch (e) {
  30214. error('JPEG error: ' + e);
  30215. }
  30216. };
  30217. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30218. this.ensureBuffer();
  30219. return this.buffer;
  30220. };
  30221. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30222. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30223. };
  30224. /**
  30225. * Checks if the image can be decoded and displayed by the browser without any
  30226. * further processing such as color space conversions.
  30227. */
  30228. JpegStream.prototype.isNativelySupported =
  30229. function JpegStream_isNativelySupported(xref, res) {
  30230. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30231. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30232. };
  30233. /**
  30234. * Checks if the image can be decoded by the browser.
  30235. */
  30236. JpegStream.prototype.isNativelyDecodable =
  30237. function JpegStream_isNativelyDecodable(xref, res) {
  30238. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30239. var numComps = cs.numComps;
  30240. return numComps === 1 || numComps === 3;
  30241. };
  30242. return JpegStream;
  30243. })();
  30244. /**
  30245. * For JPEG 2000's we use a library to decode these images and
  30246. * the stream behaves like all the other DecodeStreams.
  30247. */
  30248. var JpxStream = (function JpxStreamClosure() {
  30249. function JpxStream(stream, maybeLength, dict) {
  30250. this.stream = stream;
  30251. this.maybeLength = maybeLength;
  30252. this.dict = dict;
  30253. DecodeStream.call(this, maybeLength);
  30254. }
  30255. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30256. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30257. get: function JpxStream_bytes() {
  30258. // If this.maybeLength is null, we'll get the entire stream.
  30259. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30260. },
  30261. configurable: true
  30262. });
  30263. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30264. if (this.bufferLength) {
  30265. return;
  30266. }
  30267. var jpxImage = new JpxImage();
  30268. jpxImage.parse(this.bytes);
  30269. var width = jpxImage.width;
  30270. var height = jpxImage.height;
  30271. var componentsCount = jpxImage.componentsCount;
  30272. var tileCount = jpxImage.tiles.length;
  30273. if (tileCount === 1) {
  30274. this.buffer = jpxImage.tiles[0].items;
  30275. } else {
  30276. var data = new Uint8Array(width * height * componentsCount);
  30277. for (var k = 0; k < tileCount; k++) {
  30278. var tileComponents = jpxImage.tiles[k];
  30279. var tileWidth = tileComponents.width;
  30280. var tileHeight = tileComponents.height;
  30281. var tileLeft = tileComponents.left;
  30282. var tileTop = tileComponents.top;
  30283. var src = tileComponents.items;
  30284. var srcPosition = 0;
  30285. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30286. var imgRowSize = width * componentsCount;
  30287. var tileRowSize = tileWidth * componentsCount;
  30288. for (var j = 0; j < tileHeight; j++) {
  30289. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30290. data.set(rowBytes, dataPosition);
  30291. srcPosition += tileRowSize;
  30292. dataPosition += imgRowSize;
  30293. }
  30294. }
  30295. this.buffer = data;
  30296. }
  30297. this.bufferLength = this.buffer.length;
  30298. this.eof = true;
  30299. };
  30300. return JpxStream;
  30301. })();
  30302. /**
  30303. * For JBIG2's we use a library to decode these images and
  30304. * the stream behaves like all the other DecodeStreams.
  30305. */
  30306. var Jbig2Stream = (function Jbig2StreamClosure() {
  30307. function Jbig2Stream(stream, maybeLength, dict) {
  30308. this.stream = stream;
  30309. this.maybeLength = maybeLength;
  30310. this.dict = dict;
  30311. DecodeStream.call(this, maybeLength);
  30312. }
  30313. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30314. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30315. get: function Jbig2Stream_bytes() {
  30316. // If this.maybeLength is null, we'll get the entire stream.
  30317. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30318. },
  30319. configurable: true
  30320. });
  30321. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30322. if (this.bufferLength) {
  30323. return;
  30324. }
  30325. var jbig2Image = new Jbig2Image();
  30326. var chunks = [], xref = this.dict.xref;
  30327. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30328. // According to the PDF specification, DecodeParms can be either
  30329. // a dictionary, or an array whose elements are dictionaries.
  30330. if (isArray(decodeParams)) {
  30331. if (decodeParams.length > 1) {
  30332. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30333. 'not supported.');
  30334. }
  30335. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30336. }
  30337. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30338. var globalsStream = decodeParams.get('JBIG2Globals');
  30339. var globals = globalsStream.getBytes();
  30340. chunks.push({data: globals, start: 0, end: globals.length});
  30341. }
  30342. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30343. var data = jbig2Image.parseChunks(chunks);
  30344. var dataLength = data.length;
  30345. // JBIG2 had black as 1 and white as 0, inverting the colors
  30346. for (var i = 0; i < dataLength; i++) {
  30347. data[i] ^= 0xFF;
  30348. }
  30349. this.buffer = data;
  30350. this.bufferLength = dataLength;
  30351. this.eof = true;
  30352. };
  30353. return Jbig2Stream;
  30354. })();
  30355. var DecryptStream = (function DecryptStreamClosure() {
  30356. function DecryptStream(str, maybeLength, decrypt) {
  30357. this.str = str;
  30358. this.dict = str.dict;
  30359. this.decrypt = decrypt;
  30360. this.nextChunk = null;
  30361. this.initialized = false;
  30362. DecodeStream.call(this, maybeLength);
  30363. }
  30364. var chunkSize = 512;
  30365. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30366. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30367. var chunk;
  30368. if (this.initialized) {
  30369. chunk = this.nextChunk;
  30370. } else {
  30371. chunk = this.str.getBytes(chunkSize);
  30372. this.initialized = true;
  30373. }
  30374. if (!chunk || chunk.length === 0) {
  30375. this.eof = true;
  30376. return;
  30377. }
  30378. this.nextChunk = this.str.getBytes(chunkSize);
  30379. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30380. var decrypt = this.decrypt;
  30381. chunk = decrypt(chunk, !hasMoreData);
  30382. var bufferLength = this.bufferLength;
  30383. var i, n = chunk.length;
  30384. var buffer = this.ensureBuffer(bufferLength + n);
  30385. for (i = 0; i < n; i++) {
  30386. buffer[bufferLength++] = chunk[i];
  30387. }
  30388. this.bufferLength = bufferLength;
  30389. };
  30390. return DecryptStream;
  30391. })();
  30392. var Ascii85Stream = (function Ascii85StreamClosure() {
  30393. function Ascii85Stream(str, maybeLength) {
  30394. this.str = str;
  30395. this.dict = str.dict;
  30396. this.input = new Uint8Array(5);
  30397. // Most streams increase in size when decoded, but Ascii85 streams
  30398. // typically shrink by ~20%.
  30399. if (maybeLength) {
  30400. maybeLength = 0.8 * maybeLength;
  30401. }
  30402. DecodeStream.call(this, maybeLength);
  30403. }
  30404. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30405. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30406. var TILDA_CHAR = 0x7E; // '~'
  30407. var Z_LOWER_CHAR = 0x7A; // 'z'
  30408. var EOF = -1;
  30409. var str = this.str;
  30410. var c = str.getByte();
  30411. while (Lexer.isSpace(c)) {
  30412. c = str.getByte();
  30413. }
  30414. if (c === EOF || c === TILDA_CHAR) {
  30415. this.eof = true;
  30416. return;
  30417. }
  30418. var bufferLength = this.bufferLength, buffer;
  30419. var i;
  30420. // special code for z
  30421. if (c === Z_LOWER_CHAR) {
  30422. buffer = this.ensureBuffer(bufferLength + 4);
  30423. for (i = 0; i < 4; ++i) {
  30424. buffer[bufferLength + i] = 0;
  30425. }
  30426. this.bufferLength += 4;
  30427. } else {
  30428. var input = this.input;
  30429. input[0] = c;
  30430. for (i = 1; i < 5; ++i) {
  30431. c = str.getByte();
  30432. while (Lexer.isSpace(c)) {
  30433. c = str.getByte();
  30434. }
  30435. input[i] = c;
  30436. if (c === EOF || c === TILDA_CHAR) {
  30437. break;
  30438. }
  30439. }
  30440. buffer = this.ensureBuffer(bufferLength + i - 1);
  30441. this.bufferLength += i - 1;
  30442. // partial ending;
  30443. if (i < 5) {
  30444. for (; i < 5; ++i) {
  30445. input[i] = 0x21 + 84;
  30446. }
  30447. this.eof = true;
  30448. }
  30449. var t = 0;
  30450. for (i = 0; i < 5; ++i) {
  30451. t = t * 85 + (input[i] - 0x21);
  30452. }
  30453. for (i = 3; i >= 0; --i) {
  30454. buffer[bufferLength + i] = t & 0xFF;
  30455. t >>= 8;
  30456. }
  30457. }
  30458. };
  30459. return Ascii85Stream;
  30460. })();
  30461. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30462. function AsciiHexStream(str, maybeLength) {
  30463. this.str = str;
  30464. this.dict = str.dict;
  30465. this.firstDigit = -1;
  30466. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30467. // by 50%.
  30468. if (maybeLength) {
  30469. maybeLength = 0.5 * maybeLength;
  30470. }
  30471. DecodeStream.call(this, maybeLength);
  30472. }
  30473. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30474. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30475. var UPSTREAM_BLOCK_SIZE = 8000;
  30476. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30477. if (!bytes.length) {
  30478. this.eof = true;
  30479. return;
  30480. }
  30481. var maxDecodeLength = (bytes.length + 1) >> 1;
  30482. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30483. var bufferLength = this.bufferLength;
  30484. var firstDigit = this.firstDigit;
  30485. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30486. var ch = bytes[i], digit;
  30487. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30488. digit = ch & 0x0F;
  30489. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30490. // 'A'-'Z', 'a'-'z'
  30491. digit = (ch & 0x0F) + 9;
  30492. } else if (ch === 0x3E) { // '>'
  30493. this.eof = true;
  30494. break;
  30495. } else { // probably whitespace
  30496. continue; // ignoring
  30497. }
  30498. if (firstDigit < 0) {
  30499. firstDigit = digit;
  30500. } else {
  30501. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30502. firstDigit = -1;
  30503. }
  30504. }
  30505. if (firstDigit >= 0 && this.eof) {
  30506. // incomplete byte
  30507. buffer[bufferLength++] = (firstDigit << 4);
  30508. firstDigit = -1;
  30509. }
  30510. this.firstDigit = firstDigit;
  30511. this.bufferLength = bufferLength;
  30512. };
  30513. return AsciiHexStream;
  30514. })();
  30515. var RunLengthStream = (function RunLengthStreamClosure() {
  30516. function RunLengthStream(str, maybeLength) {
  30517. this.str = str;
  30518. this.dict = str.dict;
  30519. DecodeStream.call(this, maybeLength);
  30520. }
  30521. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30522. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30523. // The repeatHeader has following format. The first byte defines type of run
  30524. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30525. // (in addition to the second byte from the header), n = 129 through 255 -
  30526. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30527. var repeatHeader = this.str.getBytes(2);
  30528. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30529. this.eof = true;
  30530. return;
  30531. }
  30532. var buffer;
  30533. var bufferLength = this.bufferLength;
  30534. var n = repeatHeader[0];
  30535. if (n < 128) {
  30536. // copy n bytes
  30537. buffer = this.ensureBuffer(bufferLength + n + 1);
  30538. buffer[bufferLength++] = repeatHeader[1];
  30539. if (n > 0) {
  30540. var source = this.str.getBytes(n);
  30541. buffer.set(source, bufferLength);
  30542. bufferLength += n;
  30543. }
  30544. } else {
  30545. n = 257 - n;
  30546. var b = repeatHeader[1];
  30547. buffer = this.ensureBuffer(bufferLength + n + 1);
  30548. for (var i = 0; i < n; i++) {
  30549. buffer[bufferLength++] = b;
  30550. }
  30551. }
  30552. this.bufferLength = bufferLength;
  30553. };
  30554. return RunLengthStream;
  30555. })();
  30556. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30557. var ccittEOL = -2;
  30558. var twoDimPass = 0;
  30559. var twoDimHoriz = 1;
  30560. var twoDimVert0 = 2;
  30561. var twoDimVertR1 = 3;
  30562. var twoDimVertL1 = 4;
  30563. var twoDimVertR2 = 5;
  30564. var twoDimVertL2 = 6;
  30565. var twoDimVertR3 = 7;
  30566. var twoDimVertL3 = 8;
  30567. var twoDimTable = [
  30568. [-1, -1], [-1, -1], // 000000x
  30569. [7, twoDimVertL3], // 0000010
  30570. [7, twoDimVertR3], // 0000011
  30571. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30572. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30573. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30574. [4, twoDimPass], [4, twoDimPass],
  30575. [4, twoDimPass], [4, twoDimPass],
  30576. [4, twoDimPass], [4, twoDimPass],
  30577. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30578. [3, twoDimHoriz], [3, twoDimHoriz],
  30579. [3, twoDimHoriz], [3, twoDimHoriz],
  30580. [3, twoDimHoriz], [3, twoDimHoriz],
  30581. [3, twoDimHoriz], [3, twoDimHoriz],
  30582. [3, twoDimHoriz], [3, twoDimHoriz],
  30583. [3, twoDimHoriz], [3, twoDimHoriz],
  30584. [3, twoDimHoriz], [3, twoDimHoriz],
  30585. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30586. [3, twoDimVertL1], [3, twoDimVertL1],
  30587. [3, twoDimVertL1], [3, twoDimVertL1],
  30588. [3, twoDimVertL1], [3, twoDimVertL1],
  30589. [3, twoDimVertL1], [3, twoDimVertL1],
  30590. [3, twoDimVertL1], [3, twoDimVertL1],
  30591. [3, twoDimVertL1], [3, twoDimVertL1],
  30592. [3, twoDimVertL1], [3, twoDimVertL1],
  30593. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30594. [3, twoDimVertR1], [3, twoDimVertR1],
  30595. [3, twoDimVertR1], [3, twoDimVertR1],
  30596. [3, twoDimVertR1], [3, twoDimVertR1],
  30597. [3, twoDimVertR1], [3, twoDimVertR1],
  30598. [3, twoDimVertR1], [3, twoDimVertR1],
  30599. [3, twoDimVertR1], [3, twoDimVertR1],
  30600. [3, twoDimVertR1], [3, twoDimVertR1],
  30601. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30602. [1, twoDimVert0], [1, twoDimVert0],
  30603. [1, twoDimVert0], [1, twoDimVert0],
  30604. [1, twoDimVert0], [1, twoDimVert0],
  30605. [1, twoDimVert0], [1, twoDimVert0],
  30606. [1, twoDimVert0], [1, twoDimVert0],
  30607. [1, twoDimVert0], [1, twoDimVert0],
  30608. [1, twoDimVert0], [1, twoDimVert0],
  30609. [1, twoDimVert0], [1, twoDimVert0],
  30610. [1, twoDimVert0], [1, twoDimVert0],
  30611. [1, twoDimVert0], [1, twoDimVert0],
  30612. [1, twoDimVert0], [1, twoDimVert0],
  30613. [1, twoDimVert0], [1, twoDimVert0],
  30614. [1, twoDimVert0], [1, twoDimVert0],
  30615. [1, twoDimVert0], [1, twoDimVert0],
  30616. [1, twoDimVert0], [1, twoDimVert0],
  30617. [1, twoDimVert0], [1, twoDimVert0],
  30618. [1, twoDimVert0], [1, twoDimVert0],
  30619. [1, twoDimVert0], [1, twoDimVert0],
  30620. [1, twoDimVert0], [1, twoDimVert0],
  30621. [1, twoDimVert0], [1, twoDimVert0],
  30622. [1, twoDimVert0], [1, twoDimVert0],
  30623. [1, twoDimVert0], [1, twoDimVert0],
  30624. [1, twoDimVert0], [1, twoDimVert0],
  30625. [1, twoDimVert0], [1, twoDimVert0],
  30626. [1, twoDimVert0], [1, twoDimVert0],
  30627. [1, twoDimVert0], [1, twoDimVert0],
  30628. [1, twoDimVert0], [1, twoDimVert0],
  30629. [1, twoDimVert0], [1, twoDimVert0],
  30630. [1, twoDimVert0], [1, twoDimVert0],
  30631. [1, twoDimVert0], [1, twoDimVert0],
  30632. [1, twoDimVert0], [1, twoDimVert0]
  30633. ];
  30634. var whiteTable1 = [
  30635. [-1, -1], // 00000
  30636. [12, ccittEOL], // 00001
  30637. [-1, -1], [-1, -1], // 0001x
  30638. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30639. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  30640. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  30641. [11, 1792], [11, 1792], // 1000x
  30642. [12, 1984], // 10010
  30643. [12, 2048], // 10011
  30644. [12, 2112], // 10100
  30645. [12, 2176], // 10101
  30646. [12, 2240], // 10110
  30647. [12, 2304], // 10111
  30648. [11, 1856], [11, 1856], // 1100x
  30649. [11, 1920], [11, 1920], // 1101x
  30650. [12, 2368], // 11100
  30651. [12, 2432], // 11101
  30652. [12, 2496], // 11110
  30653. [12, 2560] // 11111
  30654. ];
  30655. var whiteTable2 = [
  30656. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  30657. [8, 29], [8, 29], // 00000010x
  30658. [8, 30], [8, 30], // 00000011x
  30659. [8, 45], [8, 45], // 00000100x
  30660. [8, 46], [8, 46], // 00000101x
  30661. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  30662. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  30663. [8, 47], [8, 47], // 00001010x
  30664. [8, 48], [8, 48], // 00001011x
  30665. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  30666. [6, 13], [6, 13], [6, 13], [6, 13],
  30667. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  30668. [8, 33], [8, 33], // 00010010x
  30669. [8, 34], [8, 34], // 00010011x
  30670. [8, 35], [8, 35], // 00010100x
  30671. [8, 36], [8, 36], // 00010101x
  30672. [8, 37], [8, 37], // 00010110x
  30673. [8, 38], [8, 38], // 00010111x
  30674. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  30675. [8, 31], [8, 31], // 00011010x
  30676. [8, 32], [8, 32], // 00011011x
  30677. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  30678. [6, 1], [6, 1], [6, 1], [6, 1],
  30679. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  30680. [6, 12], [6, 12], [6, 12], [6, 12],
  30681. [8, 53], [8, 53], // 00100100x
  30682. [8, 54], [8, 54], // 00100101x
  30683. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  30684. [8, 39], [8, 39], // 00101000x
  30685. [8, 40], [8, 40], // 00101001x
  30686. [8, 41], [8, 41], // 00101010x
  30687. [8, 42], [8, 42], // 00101011x
  30688. [8, 43], [8, 43], // 00101100x
  30689. [8, 44], [8, 44], // 00101101x
  30690. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  30691. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  30692. [8, 61], [8, 61], // 00110010x
  30693. [8, 62], [8, 62], // 00110011x
  30694. [8, 63], [8, 63], // 00110100x
  30695. [8, 0], [8, 0], // 00110101x
  30696. [8, 320], [8, 320], // 00110110x
  30697. [8, 384], [8, 384], // 00110111x
  30698. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  30699. [5, 10], [5, 10], [5, 10], [5, 10],
  30700. [5, 10], [5, 10], [5, 10], [5, 10],
  30701. [5, 10], [5, 10], [5, 10], [5, 10],
  30702. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  30703. [5, 11], [5, 11], [5, 11], [5, 11],
  30704. [5, 11], [5, 11], [5, 11], [5, 11],
  30705. [5, 11], [5, 11], [5, 11], [5, 11],
  30706. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  30707. [8, 59], [8, 59], // 01001010x
  30708. [8, 60], [8, 60], // 01001011x
  30709. [9, 1472], // 010011000
  30710. [9, 1536], // 010011001
  30711. [9, 1600], // 010011010
  30712. [9, 1728], // 010011011
  30713. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  30714. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  30715. [8, 49], [8, 49], // 01010010x
  30716. [8, 50], [8, 50], // 01010011x
  30717. [8, 51], [8, 51], // 01010100x
  30718. [8, 52], [8, 52], // 01010101x
  30719. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  30720. [8, 55], [8, 55], // 01011000x
  30721. [8, 56], [8, 56], // 01011001x
  30722. [8, 57], [8, 57], // 01011010x
  30723. [8, 58], [8, 58], // 01011011x
  30724. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  30725. [6, 192], [6, 192], [6, 192], [6, 192],
  30726. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  30727. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  30728. [8, 448], [8, 448], // 01100100x
  30729. [8, 512], [8, 512], // 01100101x
  30730. [9, 704], // 011001100
  30731. [9, 768], // 011001101
  30732. [8, 640], [8, 640], // 01100111x
  30733. [8, 576], [8, 576], // 01101000x
  30734. [9, 832], // 011010010
  30735. [9, 896], // 011010011
  30736. [9, 960], // 011010100
  30737. [9, 1024], // 011010101
  30738. [9, 1088], // 011010110
  30739. [9, 1152], // 011010111
  30740. [9, 1216], // 011011000
  30741. [9, 1280], // 011011001
  30742. [9, 1344], // 011011010
  30743. [9, 1408], // 011011011
  30744. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  30745. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  30746. [4, 2], [4, 2], [4, 2], [4, 2],
  30747. [4, 2], [4, 2], [4, 2], [4, 2],
  30748. [4, 2], [4, 2], [4, 2], [4, 2],
  30749. [4, 2], [4, 2], [4, 2], [4, 2],
  30750. [4, 2], [4, 2], [4, 2], [4, 2],
  30751. [4, 2], [4, 2], [4, 2], [4, 2],
  30752. [4, 2], [4, 2], [4, 2], [4, 2],
  30753. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  30754. [4, 3], [4, 3], [4, 3], [4, 3],
  30755. [4, 3], [4, 3], [4, 3], [4, 3],
  30756. [4, 3], [4, 3], [4, 3], [4, 3],
  30757. [4, 3], [4, 3], [4, 3], [4, 3],
  30758. [4, 3], [4, 3], [4, 3], [4, 3],
  30759. [4, 3], [4, 3], [4, 3], [4, 3],
  30760. [4, 3], [4, 3], [4, 3], [4, 3],
  30761. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  30762. [5, 128], [5, 128], [5, 128], [5, 128],
  30763. [5, 128], [5, 128], [5, 128], [5, 128],
  30764. [5, 128], [5, 128], [5, 128], [5, 128],
  30765. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  30766. [5, 8], [5, 8], [5, 8], [5, 8],
  30767. [5, 8], [5, 8], [5, 8], [5, 8],
  30768. [5, 8], [5, 8], [5, 8], [5, 8],
  30769. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  30770. [5, 9], [5, 9], [5, 9], [5, 9],
  30771. [5, 9], [5, 9], [5, 9], [5, 9],
  30772. [5, 9], [5, 9], [5, 9], [5, 9],
  30773. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  30774. [6, 16], [6, 16], [6, 16], [6, 16],
  30775. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  30776. [6, 17], [6, 17], [6, 17], [6, 17],
  30777. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  30778. [4, 4], [4, 4], [4, 4], [4, 4],
  30779. [4, 4], [4, 4], [4, 4], [4, 4],
  30780. [4, 4], [4, 4], [4, 4], [4, 4],
  30781. [4, 4], [4, 4], [4, 4], [4, 4],
  30782. [4, 4], [4, 4], [4, 4], [4, 4],
  30783. [4, 4], [4, 4], [4, 4], [4, 4],
  30784. [4, 4], [4, 4], [4, 4], [4, 4],
  30785. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  30786. [4, 5], [4, 5], [4, 5], [4, 5],
  30787. [4, 5], [4, 5], [4, 5], [4, 5],
  30788. [4, 5], [4, 5], [4, 5], [4, 5],
  30789. [4, 5], [4, 5], [4, 5], [4, 5],
  30790. [4, 5], [4, 5], [4, 5], [4, 5],
  30791. [4, 5], [4, 5], [4, 5], [4, 5],
  30792. [4, 5], [4, 5], [4, 5], [4, 5],
  30793. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  30794. [6, 14], [6, 14], [6, 14], [6, 14],
  30795. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  30796. [6, 15], [6, 15], [6, 15], [6, 15],
  30797. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  30798. [5, 64], [5, 64], [5, 64], [5, 64],
  30799. [5, 64], [5, 64], [5, 64], [5, 64],
  30800. [5, 64], [5, 64], [5, 64], [5, 64],
  30801. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  30802. [4, 6], [4, 6], [4, 6], [4, 6],
  30803. [4, 6], [4, 6], [4, 6], [4, 6],
  30804. [4, 6], [4, 6], [4, 6], [4, 6],
  30805. [4, 6], [4, 6], [4, 6], [4, 6],
  30806. [4, 6], [4, 6], [4, 6], [4, 6],
  30807. [4, 6], [4, 6], [4, 6], [4, 6],
  30808. [4, 6], [4, 6], [4, 6], [4, 6],
  30809. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  30810. [4, 7], [4, 7], [4, 7], [4, 7],
  30811. [4, 7], [4, 7], [4, 7], [4, 7],
  30812. [4, 7], [4, 7], [4, 7], [4, 7],
  30813. [4, 7], [4, 7], [4, 7], [4, 7],
  30814. [4, 7], [4, 7], [4, 7], [4, 7],
  30815. [4, 7], [4, 7], [4, 7], [4, 7],
  30816. [4, 7], [4, 7], [4, 7], [4, 7]
  30817. ];
  30818. var blackTable1 = [
  30819. [-1, -1], [-1, -1], // 000000000000x
  30820. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  30821. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  30822. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  30823. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  30824. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  30825. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  30826. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  30827. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  30828. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  30829. [12, 1984], [12, 1984], // 000000010010x
  30830. [12, 2048], [12, 2048], // 000000010011x
  30831. [12, 2112], [12, 2112], // 000000010100x
  30832. [12, 2176], [12, 2176], // 000000010101x
  30833. [12, 2240], [12, 2240], // 000000010110x
  30834. [12, 2304], [12, 2304], // 000000010111x
  30835. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  30836. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  30837. [12, 2368], [12, 2368], // 000000011100x
  30838. [12, 2432], [12, 2432], // 000000011101x
  30839. [12, 2496], [12, 2496], // 000000011110x
  30840. [12, 2560], [12, 2560], // 000000011111x
  30841. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  30842. [10, 18], [10, 18], [10, 18], [10, 18],
  30843. [12, 52], [12, 52], // 000000100100x
  30844. [13, 640], // 0000001001010
  30845. [13, 704], // 0000001001011
  30846. [13, 768], // 0000001001100
  30847. [13, 832], // 0000001001101
  30848. [12, 55], [12, 55], // 000000100111x
  30849. [12, 56], [12, 56], // 000000101000x
  30850. [13, 1280], // 0000001010010
  30851. [13, 1344], // 0000001010011
  30852. [13, 1408], // 0000001010100
  30853. [13, 1472], // 0000001010101
  30854. [12, 59], [12, 59], // 000000101011x
  30855. [12, 60], [12, 60], // 000000101100x
  30856. [13, 1536], // 0000001011010
  30857. [13, 1600], // 0000001011011
  30858. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  30859. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  30860. [13, 1664], // 0000001100100
  30861. [13, 1728], // 0000001100101
  30862. [12, 320], [12, 320], // 000000110011x
  30863. [12, 384], [12, 384], // 000000110100x
  30864. [12, 448], [12, 448], // 000000110101x
  30865. [13, 512], // 0000001101100
  30866. [13, 576], // 0000001101101
  30867. [12, 53], [12, 53], // 000000110111x
  30868. [12, 54], [12, 54], // 000000111000x
  30869. [13, 896], // 0000001110010
  30870. [13, 960], // 0000001110011
  30871. [13, 1024], // 0000001110100
  30872. [13, 1088], // 0000001110101
  30873. [13, 1152], // 0000001110110
  30874. [13, 1216], // 0000001110111
  30875. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  30876. [10, 64], [10, 64], [10, 64], [10, 64]
  30877. ];
  30878. var blackTable2 = [
  30879. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  30880. [8, 13], [8, 13], [8, 13], [8, 13],
  30881. [8, 13], [8, 13], [8, 13], [8, 13],
  30882. [8, 13], [8, 13], [8, 13], [8, 13],
  30883. [11, 23], [11, 23], // 00000101000x
  30884. [12, 50], // 000001010010
  30885. [12, 51], // 000001010011
  30886. [12, 44], // 000001010100
  30887. [12, 45], // 000001010101
  30888. [12, 46], // 000001010110
  30889. [12, 47], // 000001010111
  30890. [12, 57], // 000001011000
  30891. [12, 58], // 000001011001
  30892. [12, 61], // 000001011010
  30893. [12, 256], // 000001011011
  30894. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  30895. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  30896. [12, 48], // 000001100100
  30897. [12, 49], // 000001100101
  30898. [12, 62], // 000001100110
  30899. [12, 63], // 000001100111
  30900. [12, 30], // 000001101000
  30901. [12, 31], // 000001101001
  30902. [12, 32], // 000001101010
  30903. [12, 33], // 000001101011
  30904. [12, 40], // 000001101100
  30905. [12, 41], // 000001101101
  30906. [11, 22], [11, 22], // 00000110111x
  30907. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  30908. [8, 14], [8, 14], [8, 14], [8, 14],
  30909. [8, 14], [8, 14], [8, 14], [8, 14],
  30910. [8, 14], [8, 14], [8, 14], [8, 14],
  30911. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  30912. [7, 10], [7, 10], [7, 10], [7, 10],
  30913. [7, 10], [7, 10], [7, 10], [7, 10],
  30914. [7, 10], [7, 10], [7, 10], [7, 10],
  30915. [7, 10], [7, 10], [7, 10], [7, 10],
  30916. [7, 10], [7, 10], [7, 10], [7, 10],
  30917. [7, 10], [7, 10], [7, 10], [7, 10],
  30918. [7, 10], [7, 10], [7, 10], [7, 10],
  30919. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  30920. [7, 11], [7, 11], [7, 11], [7, 11],
  30921. [7, 11], [7, 11], [7, 11], [7, 11],
  30922. [7, 11], [7, 11], [7, 11], [7, 11],
  30923. [7, 11], [7, 11], [7, 11], [7, 11],
  30924. [7, 11], [7, 11], [7, 11], [7, 11],
  30925. [7, 11], [7, 11], [7, 11], [7, 11],
  30926. [7, 11], [7, 11], [7, 11], [7, 11],
  30927. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  30928. [9, 15], [9, 15], [9, 15], [9, 15],
  30929. [12, 128], // 000011001000
  30930. [12, 192], // 000011001001
  30931. [12, 26], // 000011001010
  30932. [12, 27], // 000011001011
  30933. [12, 28], // 000011001100
  30934. [12, 29], // 000011001101
  30935. [11, 19], [11, 19], // 00001100111x
  30936. [11, 20], [11, 20], // 00001101000x
  30937. [12, 34], // 000011010010
  30938. [12, 35], // 000011010011
  30939. [12, 36], // 000011010100
  30940. [12, 37], // 000011010101
  30941. [12, 38], // 000011010110
  30942. [12, 39], // 000011010111
  30943. [11, 21], [11, 21], // 00001101100x
  30944. [12, 42], // 000011011010
  30945. [12, 43], // 000011011011
  30946. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  30947. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  30948. [7, 12], [7, 12], [7, 12], [7, 12],
  30949. [7, 12], [7, 12], [7, 12], [7, 12],
  30950. [7, 12], [7, 12], [7, 12], [7, 12],
  30951. [7, 12], [7, 12], [7, 12], [7, 12],
  30952. [7, 12], [7, 12], [7, 12], [7, 12],
  30953. [7, 12], [7, 12], [7, 12], [7, 12],
  30954. [7, 12], [7, 12], [7, 12], [7, 12]
  30955. ];
  30956. var blackTable3 = [
  30957. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  30958. [6, 9], // 000100
  30959. [6, 8], // 000101
  30960. [5, 7], [5, 7], // 00011x
  30961. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  30962. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  30963. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  30964. [3, 1], [3, 1], [3, 1], [3, 1],
  30965. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  30966. [3, 4], [3, 4], [3, 4], [3, 4],
  30967. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  30968. [2, 3], [2, 3], [2, 3], [2, 3],
  30969. [2, 3], [2, 3], [2, 3], [2, 3],
  30970. [2, 3], [2, 3], [2, 3], [2, 3],
  30971. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  30972. [2, 2], [2, 2], [2, 2], [2, 2],
  30973. [2, 2], [2, 2], [2, 2], [2, 2],
  30974. [2, 2], [2, 2], [2, 2], [2, 2]
  30975. ];
  30976. function CCITTFaxStream(str, maybeLength, params) {
  30977. this.str = str;
  30978. this.dict = str.dict;
  30979. params = params || Dict.empty;
  30980. this.encoding = params.get('K') || 0;
  30981. this.eoline = params.get('EndOfLine') || false;
  30982. this.byteAlign = params.get('EncodedByteAlign') || false;
  30983. this.columns = params.get('Columns') || 1728;
  30984. this.rows = params.get('Rows') || 0;
  30985. var eoblock = params.get('EndOfBlock');
  30986. if (eoblock === null || eoblock === undefined) {
  30987. eoblock = true;
  30988. }
  30989. this.eoblock = eoblock;
  30990. this.black = params.get('BlackIs1') || false;
  30991. this.codingLine = new Uint32Array(this.columns + 1);
  30992. this.refLine = new Uint32Array(this.columns + 2);
  30993. this.codingLine[0] = this.columns;
  30994. this.codingPos = 0;
  30995. this.row = 0;
  30996. this.nextLine2D = this.encoding < 0;
  30997. this.inputBits = 0;
  30998. this.inputBuf = 0;
  30999. this.outputBits = 0;
  31000. var code1;
  31001. while ((code1 = this.lookBits(12)) === 0) {
  31002. this.eatBits(1);
  31003. }
  31004. if (code1 === 1) {
  31005. this.eatBits(12);
  31006. }
  31007. if (this.encoding > 0) {
  31008. this.nextLine2D = !this.lookBits(1);
  31009. this.eatBits(1);
  31010. }
  31011. DecodeStream.call(this, maybeLength);
  31012. }
  31013. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31014. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31015. while (!this.eof) {
  31016. var c = this.lookChar();
  31017. this.ensureBuffer(this.bufferLength + 1);
  31018. this.buffer[this.bufferLength++] = c;
  31019. }
  31020. };
  31021. CCITTFaxStream.prototype.addPixels =
  31022. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31023. var codingLine = this.codingLine;
  31024. var codingPos = this.codingPos;
  31025. if (a1 > codingLine[codingPos]) {
  31026. if (a1 > this.columns) {
  31027. info('row is wrong length');
  31028. this.err = true;
  31029. a1 = this.columns;
  31030. }
  31031. if ((codingPos & 1) ^ blackPixels) {
  31032. ++codingPos;
  31033. }
  31034. codingLine[codingPos] = a1;
  31035. }
  31036. this.codingPos = codingPos;
  31037. };
  31038. CCITTFaxStream.prototype.addPixelsNeg =
  31039. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31040. var codingLine = this.codingLine;
  31041. var codingPos = this.codingPos;
  31042. if (a1 > codingLine[codingPos]) {
  31043. if (a1 > this.columns) {
  31044. info('row is wrong length');
  31045. this.err = true;
  31046. a1 = this.columns;
  31047. }
  31048. if ((codingPos & 1) ^ blackPixels) {
  31049. ++codingPos;
  31050. }
  31051. codingLine[codingPos] = a1;
  31052. } else if (a1 < codingLine[codingPos]) {
  31053. if (a1 < 0) {
  31054. info('invalid code');
  31055. this.err = true;
  31056. a1 = 0;
  31057. }
  31058. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31059. --codingPos;
  31060. }
  31061. codingLine[codingPos] = a1;
  31062. }
  31063. this.codingPos = codingPos;
  31064. };
  31065. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31066. var refLine = this.refLine;
  31067. var codingLine = this.codingLine;
  31068. var columns = this.columns;
  31069. var refPos, blackPixels, bits, i;
  31070. if (this.outputBits === 0) {
  31071. if (this.eof) {
  31072. return null;
  31073. }
  31074. this.err = false;
  31075. var code1, code2, code3;
  31076. if (this.nextLine2D) {
  31077. for (i = 0; codingLine[i] < columns; ++i) {
  31078. refLine[i] = codingLine[i];
  31079. }
  31080. refLine[i++] = columns;
  31081. refLine[i] = columns;
  31082. codingLine[0] = 0;
  31083. this.codingPos = 0;
  31084. refPos = 0;
  31085. blackPixels = 0;
  31086. while (codingLine[this.codingPos] < columns) {
  31087. code1 = this.getTwoDimCode();
  31088. switch (code1) {
  31089. case twoDimPass:
  31090. this.addPixels(refLine[refPos + 1], blackPixels);
  31091. if (refLine[refPos + 1] < columns) {
  31092. refPos += 2;
  31093. }
  31094. break;
  31095. case twoDimHoriz:
  31096. code1 = code2 = 0;
  31097. if (blackPixels) {
  31098. do {
  31099. code1 += (code3 = this.getBlackCode());
  31100. } while (code3 >= 64);
  31101. do {
  31102. code2 += (code3 = this.getWhiteCode());
  31103. } while (code3 >= 64);
  31104. } else {
  31105. do {
  31106. code1 += (code3 = this.getWhiteCode());
  31107. } while (code3 >= 64);
  31108. do {
  31109. code2 += (code3 = this.getBlackCode());
  31110. } while (code3 >= 64);
  31111. }
  31112. this.addPixels(codingLine[this.codingPos] +
  31113. code1, blackPixels);
  31114. if (codingLine[this.codingPos] < columns) {
  31115. this.addPixels(codingLine[this.codingPos] + code2,
  31116. blackPixels ^ 1);
  31117. }
  31118. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31119. refLine[refPos] < columns) {
  31120. refPos += 2;
  31121. }
  31122. break;
  31123. case twoDimVertR3:
  31124. this.addPixels(refLine[refPos] + 3, blackPixels);
  31125. blackPixels ^= 1;
  31126. if (codingLine[this.codingPos] < columns) {
  31127. ++refPos;
  31128. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31129. refLine[refPos] < columns) {
  31130. refPos += 2;
  31131. }
  31132. }
  31133. break;
  31134. case twoDimVertR2:
  31135. this.addPixels(refLine[refPos] + 2, blackPixels);
  31136. blackPixels ^= 1;
  31137. if (codingLine[this.codingPos] < columns) {
  31138. ++refPos;
  31139. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31140. refLine[refPos] < columns) {
  31141. refPos += 2;
  31142. }
  31143. }
  31144. break;
  31145. case twoDimVertR1:
  31146. this.addPixels(refLine[refPos] + 1, blackPixels);
  31147. blackPixels ^= 1;
  31148. if (codingLine[this.codingPos] < columns) {
  31149. ++refPos;
  31150. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31151. refLine[refPos] < columns) {
  31152. refPos += 2;
  31153. }
  31154. }
  31155. break;
  31156. case twoDimVert0:
  31157. this.addPixels(refLine[refPos], blackPixels);
  31158. blackPixels ^= 1;
  31159. if (codingLine[this.codingPos] < columns) {
  31160. ++refPos;
  31161. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31162. refLine[refPos] < columns) {
  31163. refPos += 2;
  31164. }
  31165. }
  31166. break;
  31167. case twoDimVertL3:
  31168. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31169. blackPixels ^= 1;
  31170. if (codingLine[this.codingPos] < columns) {
  31171. if (refPos > 0) {
  31172. --refPos;
  31173. } else {
  31174. ++refPos;
  31175. }
  31176. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31177. refLine[refPos] < columns) {
  31178. refPos += 2;
  31179. }
  31180. }
  31181. break;
  31182. case twoDimVertL2:
  31183. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31184. blackPixels ^= 1;
  31185. if (codingLine[this.codingPos] < columns) {
  31186. if (refPos > 0) {
  31187. --refPos;
  31188. } else {
  31189. ++refPos;
  31190. }
  31191. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31192. refLine[refPos] < columns) {
  31193. refPos += 2;
  31194. }
  31195. }
  31196. break;
  31197. case twoDimVertL1:
  31198. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31199. blackPixels ^= 1;
  31200. if (codingLine[this.codingPos] < columns) {
  31201. if (refPos > 0) {
  31202. --refPos;
  31203. } else {
  31204. ++refPos;
  31205. }
  31206. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31207. refLine[refPos] < columns) {
  31208. refPos += 2;
  31209. }
  31210. }
  31211. break;
  31212. case EOF:
  31213. this.addPixels(columns, 0);
  31214. this.eof = true;
  31215. break;
  31216. default:
  31217. info('bad 2d code');
  31218. this.addPixels(columns, 0);
  31219. this.err = true;
  31220. }
  31221. }
  31222. } else {
  31223. codingLine[0] = 0;
  31224. this.codingPos = 0;
  31225. blackPixels = 0;
  31226. while (codingLine[this.codingPos] < columns) {
  31227. code1 = 0;
  31228. if (blackPixels) {
  31229. do {
  31230. code1 += (code3 = this.getBlackCode());
  31231. } while (code3 >= 64);
  31232. } else {
  31233. do {
  31234. code1 += (code3 = this.getWhiteCode());
  31235. } while (code3 >= 64);
  31236. }
  31237. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31238. blackPixels ^= 1;
  31239. }
  31240. }
  31241. var gotEOL = false;
  31242. if (!this.eoblock && this.row === this.rows - 1) {
  31243. this.eof = true;
  31244. } else {
  31245. code1 = this.lookBits(12);
  31246. if (this.eoline) {
  31247. while (code1 !== EOF && code1 !== 1) {
  31248. this.eatBits(1);
  31249. code1 = this.lookBits(12);
  31250. }
  31251. } else {
  31252. while (code1 === 0) {
  31253. this.eatBits(1);
  31254. code1 = this.lookBits(12);
  31255. }
  31256. }
  31257. if (code1 === 1) {
  31258. this.eatBits(12);
  31259. gotEOL = true;
  31260. } else if (code1 === EOF) {
  31261. this.eof = true;
  31262. }
  31263. }
  31264. if (this.byteAlign && !gotEOL) {
  31265. this.inputBits &= ~7;
  31266. }
  31267. if (!this.eof && this.encoding > 0) {
  31268. this.nextLine2D = !this.lookBits(1);
  31269. this.eatBits(1);
  31270. }
  31271. if (this.eoblock && gotEOL && this.byteAlign) {
  31272. code1 = this.lookBits(12);
  31273. if (code1 === 1) {
  31274. this.eatBits(12);
  31275. if (this.encoding > 0) {
  31276. this.lookBits(1);
  31277. this.eatBits(1);
  31278. }
  31279. if (this.encoding >= 0) {
  31280. for (i = 0; i < 4; ++i) {
  31281. code1 = this.lookBits(12);
  31282. if (code1 !== 1) {
  31283. info('bad rtc code: ' + code1);
  31284. }
  31285. this.eatBits(12);
  31286. if (this.encoding > 0) {
  31287. this.lookBits(1);
  31288. this.eatBits(1);
  31289. }
  31290. }
  31291. }
  31292. this.eof = true;
  31293. }
  31294. } else if (this.err && this.eoline) {
  31295. while (true) {
  31296. code1 = this.lookBits(13);
  31297. if (code1 === EOF) {
  31298. this.eof = true;
  31299. return null;
  31300. }
  31301. if ((code1 >> 1) === 1) {
  31302. break;
  31303. }
  31304. this.eatBits(1);
  31305. }
  31306. this.eatBits(12);
  31307. if (this.encoding > 0) {
  31308. this.eatBits(1);
  31309. this.nextLine2D = !(code1 & 1);
  31310. }
  31311. }
  31312. if (codingLine[0] > 0) {
  31313. this.outputBits = codingLine[this.codingPos = 0];
  31314. } else {
  31315. this.outputBits = codingLine[this.codingPos = 1];
  31316. }
  31317. this.row++;
  31318. }
  31319. var c;
  31320. if (this.outputBits >= 8) {
  31321. c = (this.codingPos & 1) ? 0 : 0xFF;
  31322. this.outputBits -= 8;
  31323. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31324. this.codingPos++;
  31325. this.outputBits = (codingLine[this.codingPos] -
  31326. codingLine[this.codingPos - 1]);
  31327. }
  31328. } else {
  31329. bits = 8;
  31330. c = 0;
  31331. do {
  31332. if (this.outputBits > bits) {
  31333. c <<= bits;
  31334. if (!(this.codingPos & 1)) {
  31335. c |= 0xFF >> (8 - bits);
  31336. }
  31337. this.outputBits -= bits;
  31338. bits = 0;
  31339. } else {
  31340. c <<= this.outputBits;
  31341. if (!(this.codingPos & 1)) {
  31342. c |= 0xFF >> (8 - this.outputBits);
  31343. }
  31344. bits -= this.outputBits;
  31345. this.outputBits = 0;
  31346. if (codingLine[this.codingPos] < columns) {
  31347. this.codingPos++;
  31348. this.outputBits = (codingLine[this.codingPos] -
  31349. codingLine[this.codingPos - 1]);
  31350. } else if (bits > 0) {
  31351. c <<= bits;
  31352. bits = 0;
  31353. }
  31354. }
  31355. } while (bits);
  31356. }
  31357. if (this.black) {
  31358. c ^= 0xFF;
  31359. }
  31360. return c;
  31361. };
  31362. // This functions returns the code found from the table.
  31363. // The start and end parameters set the boundaries for searching the table.
  31364. // The limit parameter is optional. Function returns an array with three
  31365. // values. The first array element indicates whether a valid code is being
  31366. // returned. The second array element is the actual code. The third array
  31367. // element indicates whether EOF was reached.
  31368. CCITTFaxStream.prototype.findTableCode =
  31369. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31370. var limitValue = limit || 0;
  31371. for (var i = start; i <= end; ++i) {
  31372. var code = this.lookBits(i);
  31373. if (code === EOF) {
  31374. return [true, 1, false];
  31375. }
  31376. if (i < end) {
  31377. code <<= end - i;
  31378. }
  31379. if (!limitValue || code >= limitValue) {
  31380. var p = table[code - limitValue];
  31381. if (p[0] === i) {
  31382. this.eatBits(i);
  31383. return [true, p[1], true];
  31384. }
  31385. }
  31386. }
  31387. return [false, 0, false];
  31388. };
  31389. CCITTFaxStream.prototype.getTwoDimCode =
  31390. function ccittFaxStreamGetTwoDimCode() {
  31391. var code = 0;
  31392. var p;
  31393. if (this.eoblock) {
  31394. code = this.lookBits(7);
  31395. p = twoDimTable[code];
  31396. if (p && p[0] > 0) {
  31397. this.eatBits(p[0]);
  31398. return p[1];
  31399. }
  31400. } else {
  31401. var result = this.findTableCode(1, 7, twoDimTable);
  31402. if (result[0] && result[2]) {
  31403. return result[1];
  31404. }
  31405. }
  31406. info('Bad two dim code');
  31407. return EOF;
  31408. };
  31409. CCITTFaxStream.prototype.getWhiteCode =
  31410. function ccittFaxStreamGetWhiteCode() {
  31411. var code = 0;
  31412. var p;
  31413. if (this.eoblock) {
  31414. code = this.lookBits(12);
  31415. if (code === EOF) {
  31416. return 1;
  31417. }
  31418. if ((code >> 5) === 0) {
  31419. p = whiteTable1[code];
  31420. } else {
  31421. p = whiteTable2[code >> 3];
  31422. }
  31423. if (p[0] > 0) {
  31424. this.eatBits(p[0]);
  31425. return p[1];
  31426. }
  31427. } else {
  31428. var result = this.findTableCode(1, 9, whiteTable2);
  31429. if (result[0]) {
  31430. return result[1];
  31431. }
  31432. result = this.findTableCode(11, 12, whiteTable1);
  31433. if (result[0]) {
  31434. return result[1];
  31435. }
  31436. }
  31437. info('bad white code');
  31438. this.eatBits(1);
  31439. return 1;
  31440. };
  31441. CCITTFaxStream.prototype.getBlackCode =
  31442. function ccittFaxStreamGetBlackCode() {
  31443. var code, p;
  31444. if (this.eoblock) {
  31445. code = this.lookBits(13);
  31446. if (code === EOF) {
  31447. return 1;
  31448. }
  31449. if ((code >> 7) === 0) {
  31450. p = blackTable1[code];
  31451. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31452. p = blackTable2[(code >> 1) - 64];
  31453. } else {
  31454. p = blackTable3[code >> 7];
  31455. }
  31456. if (p[0] > 0) {
  31457. this.eatBits(p[0]);
  31458. return p[1];
  31459. }
  31460. } else {
  31461. var result = this.findTableCode(2, 6, blackTable3);
  31462. if (result[0]) {
  31463. return result[1];
  31464. }
  31465. result = this.findTableCode(7, 12, blackTable2, 64);
  31466. if (result[0]) {
  31467. return result[1];
  31468. }
  31469. result = this.findTableCode(10, 13, blackTable1);
  31470. if (result[0]) {
  31471. return result[1];
  31472. }
  31473. }
  31474. info('bad black code');
  31475. this.eatBits(1);
  31476. return 1;
  31477. };
  31478. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31479. var c;
  31480. while (this.inputBits < n) {
  31481. if ((c = this.str.getByte()) === -1) {
  31482. if (this.inputBits === 0) {
  31483. return EOF;
  31484. }
  31485. return ((this.inputBuf << (n - this.inputBits)) &
  31486. (0xFFFF >> (16 - n)));
  31487. }
  31488. this.inputBuf = (this.inputBuf << 8) + c;
  31489. this.inputBits += 8;
  31490. }
  31491. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31492. };
  31493. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31494. if ((this.inputBits -= n) < 0) {
  31495. this.inputBits = 0;
  31496. }
  31497. };
  31498. return CCITTFaxStream;
  31499. })();
  31500. var LZWStream = (function LZWStreamClosure() {
  31501. function LZWStream(str, maybeLength, earlyChange) {
  31502. this.str = str;
  31503. this.dict = str.dict;
  31504. this.cachedData = 0;
  31505. this.bitsCached = 0;
  31506. var maxLzwDictionarySize = 4096;
  31507. var lzwState = {
  31508. earlyChange: earlyChange,
  31509. codeLength: 9,
  31510. nextCode: 258,
  31511. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31512. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31513. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31514. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31515. currentSequenceLength: 0
  31516. };
  31517. for (var i = 0; i < 256; ++i) {
  31518. lzwState.dictionaryValues[i] = i;
  31519. lzwState.dictionaryLengths[i] = 1;
  31520. }
  31521. this.lzwState = lzwState;
  31522. DecodeStream.call(this, maybeLength);
  31523. }
  31524. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31525. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31526. var bitsCached = this.bitsCached;
  31527. var cachedData = this.cachedData;
  31528. while (bitsCached < n) {
  31529. var c = this.str.getByte();
  31530. if (c === -1) {
  31531. this.eof = true;
  31532. return null;
  31533. }
  31534. cachedData = (cachedData << 8) | c;
  31535. bitsCached += 8;
  31536. }
  31537. this.bitsCached = (bitsCached -= n);
  31538. this.cachedData = cachedData;
  31539. this.lastCode = null;
  31540. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31541. };
  31542. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31543. var blockSize = 512;
  31544. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31545. var i, j, q;
  31546. var lzwState = this.lzwState;
  31547. if (!lzwState) {
  31548. return; // eof was found
  31549. }
  31550. var earlyChange = lzwState.earlyChange;
  31551. var nextCode = lzwState.nextCode;
  31552. var dictionaryValues = lzwState.dictionaryValues;
  31553. var dictionaryLengths = lzwState.dictionaryLengths;
  31554. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31555. var codeLength = lzwState.codeLength;
  31556. var prevCode = lzwState.prevCode;
  31557. var currentSequence = lzwState.currentSequence;
  31558. var currentSequenceLength = lzwState.currentSequenceLength;
  31559. var decodedLength = 0;
  31560. var currentBufferLength = this.bufferLength;
  31561. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31562. for (i = 0; i < blockSize; i++) {
  31563. var code = this.readBits(codeLength);
  31564. var hasPrev = currentSequenceLength > 0;
  31565. if (code < 256) {
  31566. currentSequence[0] = code;
  31567. currentSequenceLength = 1;
  31568. } else if (code >= 258) {
  31569. if (code < nextCode) {
  31570. currentSequenceLength = dictionaryLengths[code];
  31571. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31572. currentSequence[j] = dictionaryValues[q];
  31573. q = dictionaryPrevCodes[q];
  31574. }
  31575. } else {
  31576. currentSequence[currentSequenceLength++] = currentSequence[0];
  31577. }
  31578. } else if (code === 256) {
  31579. codeLength = 9;
  31580. nextCode = 258;
  31581. currentSequenceLength = 0;
  31582. continue;
  31583. } else {
  31584. this.eof = true;
  31585. delete this.lzwState;
  31586. break;
  31587. }
  31588. if (hasPrev) {
  31589. dictionaryPrevCodes[nextCode] = prevCode;
  31590. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31591. dictionaryValues[nextCode] = currentSequence[0];
  31592. nextCode++;
  31593. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31594. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31595. 0.6931471805599453 + 1, 12) | 0;
  31596. }
  31597. prevCode = code;
  31598. decodedLength += currentSequenceLength;
  31599. if (estimatedDecodedSize < decodedLength) {
  31600. do {
  31601. estimatedDecodedSize += decodedSizeDelta;
  31602. } while (estimatedDecodedSize < decodedLength);
  31603. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31604. }
  31605. for (j = 0; j < currentSequenceLength; j++) {
  31606. buffer[currentBufferLength++] = currentSequence[j];
  31607. }
  31608. }
  31609. lzwState.nextCode = nextCode;
  31610. lzwState.codeLength = codeLength;
  31611. lzwState.prevCode = prevCode;
  31612. lzwState.currentSequenceLength = currentSequenceLength;
  31613. this.bufferLength = currentBufferLength;
  31614. };
  31615. return LZWStream;
  31616. })();
  31617. var NullStream = (function NullStreamClosure() {
  31618. function NullStream() {
  31619. Stream.call(this, new Uint8Array(0));
  31620. }
  31621. NullStream.prototype = Stream.prototype;
  31622. return NullStream;
  31623. })();
  31624. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31625. setup: function wphSetup(handler) {
  31626. var pdfManager;
  31627. function loadDocument(recoveryMode) {
  31628. var loadDocumentCapability = createPromiseCapability();
  31629. var parseSuccess = function parseSuccess() {
  31630. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31631. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31632. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31633. Promise.all([numPagesPromise, fingerprintPromise,
  31634. encryptedPromise]).then(function onDocReady(results) {
  31635. var doc = {
  31636. numPages: results[0],
  31637. fingerprint: results[1],
  31638. encrypted: !!results[2],
  31639. };
  31640. loadDocumentCapability.resolve(doc);
  31641. },
  31642. parseFailure);
  31643. };
  31644. var parseFailure = function parseFailure(e) {
  31645. loadDocumentCapability.reject(e);
  31646. };
  31647. pdfManager.ensureDoc('checkHeader', []).then(function() {
  31648. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  31649. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  31650. parseSuccess, parseFailure);
  31651. }, parseFailure);
  31652. }, parseFailure);
  31653. return loadDocumentCapability.promise;
  31654. }
  31655. function getPdfManager(data) {
  31656. var pdfManagerCapability = createPromiseCapability();
  31657. var source = data.source;
  31658. var disableRange = data.disableRange;
  31659. if (source.data) {
  31660. try {
  31661. pdfManager = new LocalPdfManager(source.data, source.password);
  31662. pdfManagerCapability.resolve();
  31663. } catch (ex) {
  31664. pdfManagerCapability.reject(ex);
  31665. }
  31666. return pdfManagerCapability.promise;
  31667. } else if (source.chunkedViewerLoading) {
  31668. try {
  31669. pdfManager = new NetworkPdfManager(source, handler);
  31670. pdfManagerCapability.resolve();
  31671. } catch (ex) {
  31672. pdfManagerCapability.reject(ex);
  31673. }
  31674. return pdfManagerCapability.promise;
  31675. }
  31676. var networkManager = new NetworkManager(source.url, {
  31677. httpHeaders: source.httpHeaders,
  31678. withCredentials: source.withCredentials
  31679. });
  31680. var cachedChunks = [];
  31681. var fullRequestXhrId = networkManager.requestFull({
  31682. onHeadersReceived: function onHeadersReceived() {
  31683. if (disableRange) {
  31684. return;
  31685. }
  31686. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  31687. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  31688. return;
  31689. }
  31690. var contentEncoding =
  31691. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  31692. if (contentEncoding !== 'identity') {
  31693. return;
  31694. }
  31695. var length = fullRequestXhr.getResponseHeader('Content-Length');
  31696. length = parseInt(length, 10);
  31697. if (fullRequestXhr.status === 206) {
  31698. // Since Chrome 39, there exists a bug where cached responses are
  31699. // served with status code 206 for non-range requests.
  31700. // Content-Length does not specify the total size of the resource
  31701. // when the status code is 206 (see RFC 2616, section 14.16).
  31702. // In this case, extract the file size from the Content-Range
  31703. // header, which is defined to be "bytes start-end/length" for
  31704. // byte range requests.
  31705. // See https://github.com/mozilla/pdf.js/issues/5512 and
  31706. // https://code.google.com/p/chromium/issues/detail?id=442318
  31707. length = fullRequestXhr.getResponseHeader('Content-Range');
  31708. length = length && /bytes \d+-\d+\/(\d+)/.exec(length);
  31709. length = length && parseInt(length[1], 10);
  31710. }
  31711. if (!isInt(length)) {
  31712. return;
  31713. }
  31714. source.length = length;
  31715. if (length <= 2 * RANGE_CHUNK_SIZE) {
  31716. // The file size is smaller than the size of two chunks, so it does
  31717. // not make any sense to abort the request and retry with a range
  31718. // request.
  31719. return;
  31720. }
  31721. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  31722. // We can continue fetching when progressive loading is enabled,
  31723. // and we don't need the autoFetch feature.
  31724. source.disableAutoFetch = true;
  31725. } else {
  31726. // NOTE: by cancelling the full request, and then issuing range
  31727. // requests, there will be an issue for sites where you can only
  31728. // request the pdf once. However, if this is the case, then the
  31729. // server should not be returning that it can support range
  31730. // requests.
  31731. networkManager.abortRequest(fullRequestXhrId);
  31732. }
  31733. try {
  31734. pdfManager = new NetworkPdfManager(source, handler);
  31735. pdfManagerCapability.resolve(pdfManager);
  31736. } catch (ex) {
  31737. pdfManagerCapability.reject(ex);
  31738. }
  31739. },
  31740. onProgressiveData: source.disableStream ? null :
  31741. function onProgressiveData(chunk) {
  31742. if (!pdfManager) {
  31743. cachedChunks.push(chunk);
  31744. return;
  31745. }
  31746. pdfManager.sendProgressiveData(chunk);
  31747. },
  31748. onDone: function onDone(args) {
  31749. if (pdfManager) {
  31750. return; // already processed
  31751. }
  31752. var pdfFile;
  31753. if (args === null) {
  31754. // TODO add some streaming manager, e.g. for unknown length files.
  31755. // The data was returned in the onProgressiveData, combining...
  31756. var pdfFileLength = 0, pos = 0;
  31757. cachedChunks.forEach(function (chunk) {
  31758. pdfFileLength += chunk.byteLength;
  31759. });
  31760. if (source.length && pdfFileLength !== source.length) {
  31761. warn('reported HTTP length is different from actual');
  31762. }
  31763. var pdfFileArray = new Uint8Array(pdfFileLength);
  31764. cachedChunks.forEach(function (chunk) {
  31765. pdfFileArray.set(new Uint8Array(chunk), pos);
  31766. pos += chunk.byteLength;
  31767. });
  31768. pdfFile = pdfFileArray.buffer;
  31769. } else {
  31770. pdfFile = args.chunk;
  31771. }
  31772. // the data is array, instantiating directly from it
  31773. try {
  31774. pdfManager = new LocalPdfManager(pdfFile, source.password);
  31775. pdfManagerCapability.resolve();
  31776. } catch (ex) {
  31777. pdfManagerCapability.reject(ex);
  31778. }
  31779. },
  31780. onError: function onError(status) {
  31781. var exception;
  31782. if (status === 404) {
  31783. exception = new MissingPDFException('Missing PDF "' +
  31784. source.url + '".');
  31785. handler.send('MissingPDF', exception);
  31786. } else {
  31787. exception = new UnexpectedResponseException(
  31788. 'Unexpected server response (' + status +
  31789. ') while retrieving PDF "' + source.url + '".', status);
  31790. handler.send('UnexpectedResponse', exception);
  31791. }
  31792. },
  31793. onProgress: function onProgress(evt) {
  31794. handler.send('DocProgress', {
  31795. loaded: evt.loaded,
  31796. total: evt.lengthComputable ? evt.total : source.length
  31797. });
  31798. }
  31799. });
  31800. return pdfManagerCapability.promise;
  31801. }
  31802. handler.on('test', function wphSetupTest(data) {
  31803. // check if Uint8Array can be sent to worker
  31804. if (!(data instanceof Uint8Array)) {
  31805. handler.send('test', false);
  31806. return;
  31807. }
  31808. // making sure postMessage transfers are working
  31809. var supportTransfers = data[0] === 255;
  31810. handler.postMessageTransfers = supportTransfers;
  31811. // check if the response property is supported by xhr
  31812. var xhr = new XMLHttpRequest();
  31813. var responseExists = 'response' in xhr;
  31814. // check if the property is actually implemented
  31815. try {
  31816. var dummy = xhr.responseType;
  31817. } catch (e) {
  31818. responseExists = false;
  31819. }
  31820. if (!responseExists) {
  31821. handler.send('test', false);
  31822. return;
  31823. }
  31824. handler.send('test', {
  31825. supportTypedArray: true,
  31826. supportTransfers: supportTransfers
  31827. });
  31828. });
  31829. handler.on('GetDocRequest', function wphSetupDoc(data) {
  31830. var onSuccess = function(doc) {
  31831. handler.send('GetDoc', { pdfInfo: doc });
  31832. };
  31833. var onFailure = function(e) {
  31834. if (e instanceof PasswordException) {
  31835. if (e.code === PasswordResponses.NEED_PASSWORD) {
  31836. handler.send('NeedPassword', e);
  31837. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  31838. handler.send('IncorrectPassword', e);
  31839. }
  31840. } else if (e instanceof InvalidPDFException) {
  31841. handler.send('InvalidPDF', e);
  31842. } else if (e instanceof MissingPDFException) {
  31843. handler.send('MissingPDF', e);
  31844. } else if (e instanceof UnexpectedResponseException) {
  31845. handler.send('UnexpectedResponse', e);
  31846. } else {
  31847. handler.send('UnknownError',
  31848. new UnknownErrorException(e.message, e.toString()));
  31849. }
  31850. };
  31851. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  31852. -1 : data.maxImageSize;
  31853. PDFJS.disableFontFace = data.disableFontFace;
  31854. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  31855. PDFJS.verbosity = data.verbosity;
  31856. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  31857. null : data.cMapUrl;
  31858. PDFJS.cMapPacked = data.cMapPacked === true;
  31859. getPdfManager(data).then(function () {
  31860. handler.send('PDFManagerReady', null);
  31861. pdfManager.onLoadedStream().then(function(stream) {
  31862. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  31863. });
  31864. }).then(function pdfManagerReady() {
  31865. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  31866. // Try again with recoveryMode == true
  31867. if (!(ex instanceof XRefParseException)) {
  31868. if (ex instanceof PasswordException) {
  31869. // after password exception prepare to receive a new password
  31870. // to repeat loading
  31871. pdfManager.passwordChanged().then(pdfManagerReady);
  31872. }
  31873. onFailure(ex);
  31874. return;
  31875. }
  31876. pdfManager.requestLoadedStream();
  31877. pdfManager.onLoadedStream().then(function() {
  31878. loadDocument(true).then(onSuccess, onFailure);
  31879. });
  31880. }, onFailure);
  31881. }, onFailure);
  31882. });
  31883. handler.on('GetPage', function wphSetupGetPage(data) {
  31884. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31885. var rotatePromise = pdfManager.ensure(page, 'rotate');
  31886. var refPromise = pdfManager.ensure(page, 'ref');
  31887. var viewPromise = pdfManager.ensure(page, 'view');
  31888. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  31889. function(results) {
  31890. return {
  31891. rotate: results[0],
  31892. ref: results[1],
  31893. view: results[2]
  31894. };
  31895. });
  31896. });
  31897. });
  31898. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  31899. var ref = new Ref(data.ref.num, data.ref.gen);
  31900. var catalog = pdfManager.pdfDocument.catalog;
  31901. return catalog.getPageIndex(ref);
  31902. });
  31903. handler.on('GetDestinations',
  31904. function wphSetupGetDestinations(data) {
  31905. return pdfManager.ensureCatalog('destinations');
  31906. }
  31907. );
  31908. handler.on('GetDestination',
  31909. function wphSetupGetDestination(data) {
  31910. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  31911. }
  31912. );
  31913. handler.on('GetAttachments',
  31914. function wphSetupGetAttachments(data) {
  31915. return pdfManager.ensureCatalog('attachments');
  31916. }
  31917. );
  31918. handler.on('GetJavaScript',
  31919. function wphSetupGetJavaScript(data) {
  31920. return pdfManager.ensureCatalog('javaScript');
  31921. }
  31922. );
  31923. handler.on('GetOutline',
  31924. function wphSetupGetOutline(data) {
  31925. return pdfManager.ensureCatalog('documentOutline');
  31926. }
  31927. );
  31928. handler.on('GetMetadata',
  31929. function wphSetupGetMetadata(data) {
  31930. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  31931. pdfManager.ensureCatalog('metadata')]);
  31932. }
  31933. );
  31934. handler.on('GetData', function wphSetupGetData(data) {
  31935. pdfManager.requestLoadedStream();
  31936. return pdfManager.onLoadedStream().then(function(stream) {
  31937. return stream.bytes;
  31938. });
  31939. });
  31940. handler.on('GetStats',
  31941. function wphSetupGetStats(data) {
  31942. return pdfManager.pdfDocument.xref.stats;
  31943. }
  31944. );
  31945. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  31946. pdfManager.updatePassword(data);
  31947. });
  31948. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  31949. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31950. return pdfManager.ensure(page, 'getAnnotationsData', []);
  31951. });
  31952. });
  31953. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  31954. pdfManager.getPage(data.pageIndex).then(function(page) {
  31955. var pageNum = data.pageIndex + 1;
  31956. var start = Date.now();
  31957. // Pre compile the pdf page and fetch the fonts/images.
  31958. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  31959. info('page=' + pageNum + ' - getOperatorList: time=' +
  31960. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  31961. }, function(e) {
  31962. var minimumStackMessage =
  31963. 'worker.js: while trying to getPage() and getOperatorList()';
  31964. var wrappedException;
  31965. // Turn the error into an obj that can be serialized
  31966. if (typeof e === 'string') {
  31967. wrappedException = {
  31968. message: e,
  31969. stack: minimumStackMessage
  31970. };
  31971. } else if (typeof e === 'object') {
  31972. wrappedException = {
  31973. message: e.message || e.toString(),
  31974. stack: e.stack || minimumStackMessage
  31975. };
  31976. } else {
  31977. wrappedException = {
  31978. message: 'Unknown exception type: ' + (typeof e),
  31979. stack: minimumStackMessage
  31980. };
  31981. }
  31982. handler.send('PageError', {
  31983. pageNum: pageNum,
  31984. error: wrappedException,
  31985. intent: data.intent
  31986. });
  31987. });
  31988. });
  31989. }, this);
  31990. handler.on('GetTextContent', function wphExtractText(data) {
  31991. return pdfManager.getPage(data.pageIndex).then(function(page) {
  31992. var pageNum = data.pageIndex + 1;
  31993. var start = Date.now();
  31994. return page.extractTextContent().then(function(textContent) {
  31995. info('text indexing: page=' + pageNum + ' - time=' +
  31996. (Date.now() - start) + 'ms');
  31997. return textContent;
  31998. });
  31999. });
  32000. });
  32001. handler.on('Cleanup', function wphCleanup(data) {
  32002. return pdfManager.cleanup();
  32003. });
  32004. handler.on('Terminate', function wphTerminate(data) {
  32005. pdfManager.terminate();
  32006. });
  32007. }
  32008. };
  32009. var consoleTimer = {};
  32010. var workerConsole = {
  32011. log: function log() {
  32012. var args = Array.prototype.slice.call(arguments);
  32013. globalScope.postMessage({
  32014. action: 'console_log',
  32015. data: args
  32016. });
  32017. },
  32018. error: function error() {
  32019. var args = Array.prototype.slice.call(arguments);
  32020. globalScope.postMessage({
  32021. action: 'console_error',
  32022. data: args
  32023. });
  32024. throw 'pdf.js execution error';
  32025. },
  32026. time: function time(name) {
  32027. consoleTimer[name] = Date.now();
  32028. },
  32029. timeEnd: function timeEnd(name) {
  32030. var time = consoleTimer[name];
  32031. if (!time) {
  32032. error('Unknown timer name ' + name);
  32033. }
  32034. this.log('Timer:', name, Date.now() - time);
  32035. }
  32036. };
  32037. // Worker thread?
  32038. if (typeof window === 'undefined') {
  32039. if (!('console' in globalScope)) {
  32040. globalScope.console = workerConsole;
  32041. }
  32042. // Listen for unsupported features so we can pass them on to the main thread.
  32043. PDFJS.UnsupportedManager.listen(function (msg) {
  32044. globalScope.postMessage({
  32045. action: '_unsupported_feature',
  32046. data: msg
  32047. });
  32048. });
  32049. var handler = new MessageHandler('worker_processor', this);
  32050. WorkerMessageHandler.setup(handler);
  32051. }
  32052. /* This class implements the QM Coder decoding as defined in
  32053. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32054. * Annex C.3 Arithmetic decoding procedure
  32055. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32056. *
  32057. * The arithmetic decoder is used in conjunction with context models to decode
  32058. * JPEG2000 and JBIG2 streams.
  32059. */
  32060. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32061. // Table C-2
  32062. var QeTable = [
  32063. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32064. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32065. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32066. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32067. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32068. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32069. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32070. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32071. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32072. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32073. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32074. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32075. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32076. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32077. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32078. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32079. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32080. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32081. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32082. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32083. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32084. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32085. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32086. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32087. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32088. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32089. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32090. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32091. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32092. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32093. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32094. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32095. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32096. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32097. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32098. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32099. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32100. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32101. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32102. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32103. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32104. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32105. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32106. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32107. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32108. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32109. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32110. ];
  32111. // C.3.5 Initialisation of the decoder (INITDEC)
  32112. function ArithmeticDecoder(data, start, end) {
  32113. this.data = data;
  32114. this.bp = start;
  32115. this.dataEnd = end;
  32116. this.chigh = data[start];
  32117. this.clow = 0;
  32118. this.byteIn();
  32119. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32120. this.clow = (this.clow << 7) & 0xFFFF;
  32121. this.ct -= 7;
  32122. this.a = 0x8000;
  32123. }
  32124. ArithmeticDecoder.prototype = {
  32125. // C.3.4 Compressed data input (BYTEIN)
  32126. byteIn: function ArithmeticDecoder_byteIn() {
  32127. var data = this.data;
  32128. var bp = this.bp;
  32129. if (data[bp] === 0xFF) {
  32130. var b1 = data[bp + 1];
  32131. if (b1 > 0x8F) {
  32132. this.clow += 0xFF00;
  32133. this.ct = 8;
  32134. } else {
  32135. bp++;
  32136. this.clow += (data[bp] << 9);
  32137. this.ct = 7;
  32138. this.bp = bp;
  32139. }
  32140. } else {
  32141. bp++;
  32142. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32143. this.ct = 8;
  32144. this.bp = bp;
  32145. }
  32146. if (this.clow > 0xFFFF) {
  32147. this.chigh += (this.clow >> 16);
  32148. this.clow &= 0xFFFF;
  32149. }
  32150. },
  32151. // C.3.2 Decoding a decision (DECODE)
  32152. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32153. // contexts are packed into 1 byte:
  32154. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32155. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32156. var qeTableIcx = QeTable[cx_index];
  32157. var qeIcx = qeTableIcx.qe;
  32158. var d;
  32159. var a = this.a - qeIcx;
  32160. if (this.chigh < qeIcx) {
  32161. // exchangeLps
  32162. if (a < qeIcx) {
  32163. a = qeIcx;
  32164. d = cx_mps;
  32165. cx_index = qeTableIcx.nmps;
  32166. } else {
  32167. a = qeIcx;
  32168. d = 1 ^ cx_mps;
  32169. if (qeTableIcx.switchFlag === 1) {
  32170. cx_mps = d;
  32171. }
  32172. cx_index = qeTableIcx.nlps;
  32173. }
  32174. } else {
  32175. this.chigh -= qeIcx;
  32176. if ((a & 0x8000) !== 0) {
  32177. this.a = a;
  32178. return cx_mps;
  32179. }
  32180. // exchangeMps
  32181. if (a < qeIcx) {
  32182. d = 1 ^ cx_mps;
  32183. if (qeTableIcx.switchFlag === 1) {
  32184. cx_mps = d;
  32185. }
  32186. cx_index = qeTableIcx.nlps;
  32187. } else {
  32188. d = cx_mps;
  32189. cx_index = qeTableIcx.nmps;
  32190. }
  32191. }
  32192. // C.3.3 renormD;
  32193. do {
  32194. if (this.ct === 0) {
  32195. this.byteIn();
  32196. }
  32197. a <<= 1;
  32198. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32199. this.clow = (this.clow << 1) & 0xFFFF;
  32200. this.ct--;
  32201. } while ((a & 0x8000) === 0);
  32202. this.a = a;
  32203. contexts[pos] = cx_index << 1 | cx_mps;
  32204. return d;
  32205. }
  32206. };
  32207. return ArithmeticDecoder;
  32208. })();
  32209. var JpegImage = (function jpegImage() {
  32210. var dctZigZag = new Uint8Array([
  32211. 0,
  32212. 1, 8,
  32213. 16, 9, 2,
  32214. 3, 10, 17, 24,
  32215. 32, 25, 18, 11, 4,
  32216. 5, 12, 19, 26, 33, 40,
  32217. 48, 41, 34, 27, 20, 13, 6,
  32218. 7, 14, 21, 28, 35, 42, 49, 56,
  32219. 57, 50, 43, 36, 29, 22, 15,
  32220. 23, 30, 37, 44, 51, 58,
  32221. 59, 52, 45, 38, 31,
  32222. 39, 46, 53, 60,
  32223. 61, 54, 47,
  32224. 55, 62,
  32225. 63
  32226. ]);
  32227. var dctCos1 = 4017; // cos(pi/16)
  32228. var dctSin1 = 799; // sin(pi/16)
  32229. var dctCos3 = 3406; // cos(3*pi/16)
  32230. var dctSin3 = 2276; // sin(3*pi/16)
  32231. var dctCos6 = 1567; // cos(6*pi/16)
  32232. var dctSin6 = 3784; // sin(6*pi/16)
  32233. var dctSqrt2 = 5793; // sqrt(2)
  32234. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32235. function constructor() {
  32236. }
  32237. function buildHuffmanTable(codeLengths, values) {
  32238. var k = 0, code = [], i, j, length = 16;
  32239. while (length > 0 && !codeLengths[length - 1]) {
  32240. length--;
  32241. }
  32242. code.push({children: [], index: 0});
  32243. var p = code[0], q;
  32244. for (i = 0; i < length; i++) {
  32245. for (j = 0; j < codeLengths[i]; j++) {
  32246. p = code.pop();
  32247. p.children[p.index] = values[k];
  32248. while (p.index > 0) {
  32249. p = code.pop();
  32250. }
  32251. p.index++;
  32252. code.push(p);
  32253. while (code.length <= i) {
  32254. code.push(q = {children: [], index: 0});
  32255. p.children[p.index] = q.children;
  32256. p = q;
  32257. }
  32258. k++;
  32259. }
  32260. if (i + 1 < length) {
  32261. // p here points to last code
  32262. code.push(q = {children: [], index: 0});
  32263. p.children[p.index] = q.children;
  32264. p = q;
  32265. }
  32266. }
  32267. return code[0].children;
  32268. }
  32269. function getBlockBufferOffset(component, row, col) {
  32270. return 64 * ((component.blocksPerLine + 1) * row + col);
  32271. }
  32272. function decodeScan(data, offset, frame, components, resetInterval,
  32273. spectralStart, spectralEnd, successivePrev, successive) {
  32274. var precision = frame.precision;
  32275. var samplesPerLine = frame.samplesPerLine;
  32276. var scanLines = frame.scanLines;
  32277. var mcusPerLine = frame.mcusPerLine;
  32278. var progressive = frame.progressive;
  32279. var maxH = frame.maxH, maxV = frame.maxV;
  32280. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32281. function readBit() {
  32282. if (bitsCount > 0) {
  32283. bitsCount--;
  32284. return (bitsData >> bitsCount) & 1;
  32285. }
  32286. bitsData = data[offset++];
  32287. if (bitsData === 0xFF) {
  32288. var nextByte = data[offset++];
  32289. if (nextByte) {
  32290. throw 'unexpected marker: ' +
  32291. ((bitsData << 8) | nextByte).toString(16);
  32292. }
  32293. // unstuff 0
  32294. }
  32295. bitsCount = 7;
  32296. return bitsData >>> 7;
  32297. }
  32298. function decodeHuffman(tree) {
  32299. var node = tree;
  32300. while (true) {
  32301. node = node[readBit()];
  32302. if (typeof node === 'number') {
  32303. return node;
  32304. }
  32305. if (typeof node !== 'object') {
  32306. throw 'invalid huffman sequence';
  32307. }
  32308. }
  32309. }
  32310. function receive(length) {
  32311. var n = 0;
  32312. while (length > 0) {
  32313. n = (n << 1) | readBit();
  32314. length--;
  32315. }
  32316. return n;
  32317. }
  32318. function receiveAndExtend(length) {
  32319. if (length === 1) {
  32320. return readBit() === 1 ? 1 : -1;
  32321. }
  32322. var n = receive(length);
  32323. if (n >= 1 << (length - 1)) {
  32324. return n;
  32325. }
  32326. return n + (-1 << length) + 1;
  32327. }
  32328. function decodeBaseline(component, offset) {
  32329. var t = decodeHuffman(component.huffmanTableDC);
  32330. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32331. component.blockData[offset] = (component.pred += diff);
  32332. var k = 1;
  32333. while (k < 64) {
  32334. var rs = decodeHuffman(component.huffmanTableAC);
  32335. var s = rs & 15, r = rs >> 4;
  32336. if (s === 0) {
  32337. if (r < 15) {
  32338. break;
  32339. }
  32340. k += 16;
  32341. continue;
  32342. }
  32343. k += r;
  32344. var z = dctZigZag[k];
  32345. component.blockData[offset + z] = receiveAndExtend(s);
  32346. k++;
  32347. }
  32348. }
  32349. function decodeDCFirst(component, offset) {
  32350. var t = decodeHuffman(component.huffmanTableDC);
  32351. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32352. component.blockData[offset] = (component.pred += diff);
  32353. }
  32354. function decodeDCSuccessive(component, offset) {
  32355. component.blockData[offset] |= readBit() << successive;
  32356. }
  32357. var eobrun = 0;
  32358. function decodeACFirst(component, offset) {
  32359. if (eobrun > 0) {
  32360. eobrun--;
  32361. return;
  32362. }
  32363. var k = spectralStart, e = spectralEnd;
  32364. while (k <= e) {
  32365. var rs = decodeHuffman(component.huffmanTableAC);
  32366. var s = rs & 15, r = rs >> 4;
  32367. if (s === 0) {
  32368. if (r < 15) {
  32369. eobrun = receive(r) + (1 << r) - 1;
  32370. break;
  32371. }
  32372. k += 16;
  32373. continue;
  32374. }
  32375. k += r;
  32376. var z = dctZigZag[k];
  32377. component.blockData[offset + z] =
  32378. receiveAndExtend(s) * (1 << successive);
  32379. k++;
  32380. }
  32381. }
  32382. var successiveACState = 0, successiveACNextValue;
  32383. function decodeACSuccessive(component, offset) {
  32384. var k = spectralStart;
  32385. var e = spectralEnd;
  32386. var r = 0;
  32387. var s;
  32388. var rs;
  32389. while (k <= e) {
  32390. var z = dctZigZag[k];
  32391. switch (successiveACState) {
  32392. case 0: // initial state
  32393. rs = decodeHuffman(component.huffmanTableAC);
  32394. s = rs & 15;
  32395. r = rs >> 4;
  32396. if (s === 0) {
  32397. if (r < 15) {
  32398. eobrun = receive(r) + (1 << r);
  32399. successiveACState = 4;
  32400. } else {
  32401. r = 16;
  32402. successiveACState = 1;
  32403. }
  32404. } else {
  32405. if (s !== 1) {
  32406. throw 'invalid ACn encoding';
  32407. }
  32408. successiveACNextValue = receiveAndExtend(s);
  32409. successiveACState = r ? 2 : 3;
  32410. }
  32411. continue;
  32412. case 1: // skipping r zero items
  32413. case 2:
  32414. if (component.blockData[offset + z]) {
  32415. component.blockData[offset + z] += (readBit() << successive);
  32416. } else {
  32417. r--;
  32418. if (r === 0) {
  32419. successiveACState = successiveACState === 2 ? 3 : 0;
  32420. }
  32421. }
  32422. break;
  32423. case 3: // set value for a zero item
  32424. if (component.blockData[offset + z]) {
  32425. component.blockData[offset + z] += (readBit() << successive);
  32426. } else {
  32427. component.blockData[offset + z] =
  32428. successiveACNextValue << successive;
  32429. successiveACState = 0;
  32430. }
  32431. break;
  32432. case 4: // eob
  32433. if (component.blockData[offset + z]) {
  32434. component.blockData[offset + z] += (readBit() << successive);
  32435. }
  32436. break;
  32437. }
  32438. k++;
  32439. }
  32440. if (successiveACState === 4) {
  32441. eobrun--;
  32442. if (eobrun === 0) {
  32443. successiveACState = 0;
  32444. }
  32445. }
  32446. }
  32447. function decodeMcu(component, decode, mcu, row, col) {
  32448. var mcuRow = (mcu / mcusPerLine) | 0;
  32449. var mcuCol = mcu % mcusPerLine;
  32450. var blockRow = mcuRow * component.v + row;
  32451. var blockCol = mcuCol * component.h + col;
  32452. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32453. decode(component, offset);
  32454. }
  32455. function decodeBlock(component, decode, mcu) {
  32456. var blockRow = (mcu / component.blocksPerLine) | 0;
  32457. var blockCol = mcu % component.blocksPerLine;
  32458. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32459. decode(component, offset);
  32460. }
  32461. var componentsLength = components.length;
  32462. var component, i, j, k, n;
  32463. var decodeFn;
  32464. if (progressive) {
  32465. if (spectralStart === 0) {
  32466. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32467. } else {
  32468. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32469. }
  32470. } else {
  32471. decodeFn = decodeBaseline;
  32472. }
  32473. var mcu = 0, marker;
  32474. var mcuExpected;
  32475. if (componentsLength === 1) {
  32476. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32477. } else {
  32478. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32479. }
  32480. if (!resetInterval) {
  32481. resetInterval = mcuExpected;
  32482. }
  32483. var h, v;
  32484. while (mcu < mcuExpected) {
  32485. // reset interval stuff
  32486. for (i = 0; i < componentsLength; i++) {
  32487. components[i].pred = 0;
  32488. }
  32489. eobrun = 0;
  32490. if (componentsLength === 1) {
  32491. component = components[0];
  32492. for (n = 0; n < resetInterval; n++) {
  32493. decodeBlock(component, decodeFn, mcu);
  32494. mcu++;
  32495. }
  32496. } else {
  32497. for (n = 0; n < resetInterval; n++) {
  32498. for (i = 0; i < componentsLength; i++) {
  32499. component = components[i];
  32500. h = component.h;
  32501. v = component.v;
  32502. for (j = 0; j < v; j++) {
  32503. for (k = 0; k < h; k++) {
  32504. decodeMcu(component, decodeFn, mcu, j, k);
  32505. }
  32506. }
  32507. }
  32508. mcu++;
  32509. }
  32510. }
  32511. // find marker
  32512. bitsCount = 0;
  32513. marker = (data[offset] << 8) | data[offset + 1];
  32514. if (marker <= 0xFF00) {
  32515. throw 'marker was not found';
  32516. }
  32517. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32518. offset += 2;
  32519. } else {
  32520. break;
  32521. }
  32522. }
  32523. return offset - startOffset;
  32524. }
  32525. // A port of poppler's IDCT method which in turn is taken from:
  32526. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32527. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32528. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32529. // 988-991.
  32530. function quantizeAndInverse(component, blockBufferOffset, p) {
  32531. var qt = component.quantizationTable, blockData = component.blockData;
  32532. var v0, v1, v2, v3, v4, v5, v6, v7;
  32533. var p0, p1, p2, p3, p4, p5, p6, p7;
  32534. var t;
  32535. // inverse DCT on rows
  32536. for (var row = 0; row < 64; row += 8) {
  32537. // gather block data
  32538. p0 = blockData[blockBufferOffset + row];
  32539. p1 = blockData[blockBufferOffset + row + 1];
  32540. p2 = blockData[blockBufferOffset + row + 2];
  32541. p3 = blockData[blockBufferOffset + row + 3];
  32542. p4 = blockData[blockBufferOffset + row + 4];
  32543. p5 = blockData[blockBufferOffset + row + 5];
  32544. p6 = blockData[blockBufferOffset + row + 6];
  32545. p7 = blockData[blockBufferOffset + row + 7];
  32546. // dequant p0
  32547. p0 *= qt[row];
  32548. // check for all-zero AC coefficients
  32549. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32550. t = (dctSqrt2 * p0 + 512) >> 10;
  32551. p[row] = t;
  32552. p[row + 1] = t;
  32553. p[row + 2] = t;
  32554. p[row + 3] = t;
  32555. p[row + 4] = t;
  32556. p[row + 5] = t;
  32557. p[row + 6] = t;
  32558. p[row + 7] = t;
  32559. continue;
  32560. }
  32561. // dequant p1 ... p7
  32562. p1 *= qt[row + 1];
  32563. p2 *= qt[row + 2];
  32564. p3 *= qt[row + 3];
  32565. p4 *= qt[row + 4];
  32566. p5 *= qt[row + 5];
  32567. p6 *= qt[row + 6];
  32568. p7 *= qt[row + 7];
  32569. // stage 4
  32570. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32571. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32572. v2 = p2;
  32573. v3 = p6;
  32574. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32575. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32576. v5 = p3 << 4;
  32577. v6 = p5 << 4;
  32578. // stage 3
  32579. v0 = (v0 + v1 + 1) >> 1;
  32580. v1 = v0 - v1;
  32581. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32582. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32583. v3 = t;
  32584. v4 = (v4 + v6 + 1) >> 1;
  32585. v6 = v4 - v6;
  32586. v7 = (v7 + v5 + 1) >> 1;
  32587. v5 = v7 - v5;
  32588. // stage 2
  32589. v0 = (v0 + v3 + 1) >> 1;
  32590. v3 = v0 - v3;
  32591. v1 = (v1 + v2 + 1) >> 1;
  32592. v2 = v1 - v2;
  32593. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32594. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32595. v7 = t;
  32596. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32597. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32598. v6 = t;
  32599. // stage 1
  32600. p[row] = v0 + v7;
  32601. p[row + 7] = v0 - v7;
  32602. p[row + 1] = v1 + v6;
  32603. p[row + 6] = v1 - v6;
  32604. p[row + 2] = v2 + v5;
  32605. p[row + 5] = v2 - v5;
  32606. p[row + 3] = v3 + v4;
  32607. p[row + 4] = v3 - v4;
  32608. }
  32609. // inverse DCT on columns
  32610. for (var col = 0; col < 8; ++col) {
  32611. p0 = p[col];
  32612. p1 = p[col + 8];
  32613. p2 = p[col + 16];
  32614. p3 = p[col + 24];
  32615. p4 = p[col + 32];
  32616. p5 = p[col + 40];
  32617. p6 = p[col + 48];
  32618. p7 = p[col + 56];
  32619. // check for all-zero AC coefficients
  32620. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32621. t = (dctSqrt2 * p0 + 8192) >> 14;
  32622. // convert to 8 bit
  32623. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32624. blockData[blockBufferOffset + col] = t;
  32625. blockData[blockBufferOffset + col + 8] = t;
  32626. blockData[blockBufferOffset + col + 16] = t;
  32627. blockData[blockBufferOffset + col + 24] = t;
  32628. blockData[blockBufferOffset + col + 32] = t;
  32629. blockData[blockBufferOffset + col + 40] = t;
  32630. blockData[blockBufferOffset + col + 48] = t;
  32631. blockData[blockBufferOffset + col + 56] = t;
  32632. continue;
  32633. }
  32634. // stage 4
  32635. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32636. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32637. v2 = p2;
  32638. v3 = p6;
  32639. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32640. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32641. v5 = p3;
  32642. v6 = p5;
  32643. // stage 3
  32644. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32645. // converting to UInt8 range later.
  32646. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32647. v1 = v0 - v1;
  32648. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32649. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32650. v3 = t;
  32651. v4 = (v4 + v6 + 1) >> 1;
  32652. v6 = v4 - v6;
  32653. v7 = (v7 + v5 + 1) >> 1;
  32654. v5 = v7 - v5;
  32655. // stage 2
  32656. v0 = (v0 + v3 + 1) >> 1;
  32657. v3 = v0 - v3;
  32658. v1 = (v1 + v2 + 1) >> 1;
  32659. v2 = v1 - v2;
  32660. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32661. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32662. v7 = t;
  32663. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32664. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32665. v6 = t;
  32666. // stage 1
  32667. p0 = v0 + v7;
  32668. p7 = v0 - v7;
  32669. p1 = v1 + v6;
  32670. p6 = v1 - v6;
  32671. p2 = v2 + v5;
  32672. p5 = v2 - v5;
  32673. p3 = v3 + v4;
  32674. p4 = v3 - v4;
  32675. // convert to 8-bit integers
  32676. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  32677. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  32678. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  32679. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  32680. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  32681. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  32682. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  32683. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  32684. // store block data
  32685. blockData[blockBufferOffset + col] = p0;
  32686. blockData[blockBufferOffset + col + 8] = p1;
  32687. blockData[blockBufferOffset + col + 16] = p2;
  32688. blockData[blockBufferOffset + col + 24] = p3;
  32689. blockData[blockBufferOffset + col + 32] = p4;
  32690. blockData[blockBufferOffset + col + 40] = p5;
  32691. blockData[blockBufferOffset + col + 48] = p6;
  32692. blockData[blockBufferOffset + col + 56] = p7;
  32693. }
  32694. }
  32695. function buildComponentData(frame, component) {
  32696. var blocksPerLine = component.blocksPerLine;
  32697. var blocksPerColumn = component.blocksPerColumn;
  32698. var computationBuffer = new Int16Array(64);
  32699. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  32700. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  32701. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32702. quantizeAndInverse(component, offset, computationBuffer);
  32703. }
  32704. }
  32705. return component.blockData;
  32706. }
  32707. function clamp0to255(a) {
  32708. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  32709. }
  32710. constructor.prototype = {
  32711. parse: function parse(data) {
  32712. function readUint16() {
  32713. var value = (data[offset] << 8) | data[offset + 1];
  32714. offset += 2;
  32715. return value;
  32716. }
  32717. function readDataBlock() {
  32718. var length = readUint16();
  32719. var array = data.subarray(offset, offset + length - 2);
  32720. offset += array.length;
  32721. return array;
  32722. }
  32723. function prepareComponents(frame) {
  32724. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  32725. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  32726. for (var i = 0; i < frame.components.length; i++) {
  32727. component = frame.components[i];
  32728. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  32729. component.h / frame.maxH);
  32730. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  32731. component.v / frame.maxV);
  32732. var blocksPerLineForMcu = mcusPerLine * component.h;
  32733. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  32734. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  32735. (blocksPerLineForMcu + 1);
  32736. component.blockData = new Int16Array(blocksBufferSize);
  32737. component.blocksPerLine = blocksPerLine;
  32738. component.blocksPerColumn = blocksPerColumn;
  32739. }
  32740. frame.mcusPerLine = mcusPerLine;
  32741. frame.mcusPerColumn = mcusPerColumn;
  32742. }
  32743. var offset = 0, length = data.length;
  32744. var jfif = null;
  32745. var adobe = null;
  32746. var pixels = null;
  32747. var frame, resetInterval;
  32748. var quantizationTables = [];
  32749. var huffmanTablesAC = [], huffmanTablesDC = [];
  32750. var fileMarker = readUint16();
  32751. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  32752. throw 'SOI not found';
  32753. }
  32754. fileMarker = readUint16();
  32755. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  32756. var i, j, l;
  32757. switch(fileMarker) {
  32758. case 0xFFE0: // APP0 (Application Specific)
  32759. case 0xFFE1: // APP1
  32760. case 0xFFE2: // APP2
  32761. case 0xFFE3: // APP3
  32762. case 0xFFE4: // APP4
  32763. case 0xFFE5: // APP5
  32764. case 0xFFE6: // APP6
  32765. case 0xFFE7: // APP7
  32766. case 0xFFE8: // APP8
  32767. case 0xFFE9: // APP9
  32768. case 0xFFEA: // APP10
  32769. case 0xFFEB: // APP11
  32770. case 0xFFEC: // APP12
  32771. case 0xFFED: // APP13
  32772. case 0xFFEE: // APP14
  32773. case 0xFFEF: // APP15
  32774. case 0xFFFE: // COM (Comment)
  32775. var appData = readDataBlock();
  32776. if (fileMarker === 0xFFE0) {
  32777. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  32778. appData[2] === 0x49 && appData[3] === 0x46 &&
  32779. appData[4] === 0) { // 'JFIF\x00'
  32780. jfif = {
  32781. version: { major: appData[5], minor: appData[6] },
  32782. densityUnits: appData[7],
  32783. xDensity: (appData[8] << 8) | appData[9],
  32784. yDensity: (appData[10] << 8) | appData[11],
  32785. thumbWidth: appData[12],
  32786. thumbHeight: appData[13],
  32787. thumbData: appData.subarray(14, 14 +
  32788. 3 * appData[12] * appData[13])
  32789. };
  32790. }
  32791. }
  32792. // TODO APP1 - Exif
  32793. if (fileMarker === 0xFFEE) {
  32794. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  32795. appData[2] === 0x6F && appData[3] === 0x62 &&
  32796. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  32797. adobe = {
  32798. version: appData[6],
  32799. flags0: (appData[7] << 8) | appData[8],
  32800. flags1: (appData[9] << 8) | appData[10],
  32801. transformCode: appData[11]
  32802. };
  32803. }
  32804. }
  32805. break;
  32806. case 0xFFDB: // DQT (Define Quantization Tables)
  32807. var quantizationTablesLength = readUint16();
  32808. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  32809. var z;
  32810. while (offset < quantizationTablesEnd) {
  32811. var quantizationTableSpec = data[offset++];
  32812. var tableData = new Uint16Array(64);
  32813. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  32814. for (j = 0; j < 64; j++) {
  32815. z = dctZigZag[j];
  32816. tableData[z] = data[offset++];
  32817. }
  32818. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  32819. for (j = 0; j < 64; j++) {
  32820. z = dctZigZag[j];
  32821. tableData[z] = readUint16();
  32822. }
  32823. } else {
  32824. throw 'DQT: invalid table spec';
  32825. }
  32826. quantizationTables[quantizationTableSpec & 15] = tableData;
  32827. }
  32828. break;
  32829. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  32830. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  32831. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  32832. if (frame) {
  32833. throw 'Only single frame JPEGs supported';
  32834. }
  32835. readUint16(); // skip data length
  32836. frame = {};
  32837. frame.extended = (fileMarker === 0xFFC1);
  32838. frame.progressive = (fileMarker === 0xFFC2);
  32839. frame.precision = data[offset++];
  32840. frame.scanLines = readUint16();
  32841. frame.samplesPerLine = readUint16();
  32842. frame.components = [];
  32843. frame.componentIds = {};
  32844. var componentsCount = data[offset++], componentId;
  32845. var maxH = 0, maxV = 0;
  32846. for (i = 0; i < componentsCount; i++) {
  32847. componentId = data[offset];
  32848. var h = data[offset + 1] >> 4;
  32849. var v = data[offset + 1] & 15;
  32850. if (maxH < h) {
  32851. maxH = h;
  32852. }
  32853. if (maxV < v) {
  32854. maxV = v;
  32855. }
  32856. var qId = data[offset + 2];
  32857. l = frame.components.push({
  32858. h: h,
  32859. v: v,
  32860. quantizationTable: quantizationTables[qId]
  32861. });
  32862. frame.componentIds[componentId] = l - 1;
  32863. offset += 3;
  32864. }
  32865. frame.maxH = maxH;
  32866. frame.maxV = maxV;
  32867. prepareComponents(frame);
  32868. break;
  32869. case 0xFFC4: // DHT (Define Huffman Tables)
  32870. var huffmanLength = readUint16();
  32871. for (i = 2; i < huffmanLength;) {
  32872. var huffmanTableSpec = data[offset++];
  32873. var codeLengths = new Uint8Array(16);
  32874. var codeLengthSum = 0;
  32875. for (j = 0; j < 16; j++, offset++) {
  32876. codeLengthSum += (codeLengths[j] = data[offset]);
  32877. }
  32878. var huffmanValues = new Uint8Array(codeLengthSum);
  32879. for (j = 0; j < codeLengthSum; j++, offset++) {
  32880. huffmanValues[j] = data[offset];
  32881. }
  32882. i += 17 + codeLengthSum;
  32883. ((huffmanTableSpec >> 4) === 0 ?
  32884. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  32885. buildHuffmanTable(codeLengths, huffmanValues);
  32886. }
  32887. break;
  32888. case 0xFFDD: // DRI (Define Restart Interval)
  32889. readUint16(); // skip data length
  32890. resetInterval = readUint16();
  32891. break;
  32892. case 0xFFDA: // SOS (Start of Scan)
  32893. var scanLength = readUint16();
  32894. var selectorsCount = data[offset++];
  32895. var components = [], component;
  32896. for (i = 0; i < selectorsCount; i++) {
  32897. var componentIndex = frame.componentIds[data[offset++]];
  32898. component = frame.components[componentIndex];
  32899. var tableSpec = data[offset++];
  32900. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  32901. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  32902. components.push(component);
  32903. }
  32904. var spectralStart = data[offset++];
  32905. var spectralEnd = data[offset++];
  32906. var successiveApproximation = data[offset++];
  32907. var processed = decodeScan(data, offset,
  32908. frame, components, resetInterval,
  32909. spectralStart, spectralEnd,
  32910. successiveApproximation >> 4, successiveApproximation & 15);
  32911. offset += processed;
  32912. break;
  32913. default:
  32914. if (data[offset - 3] === 0xFF &&
  32915. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  32916. // could be incorrect encoding -- last 0xFF byte of the previous
  32917. // block was eaten by the encoder
  32918. offset -= 3;
  32919. break;
  32920. }
  32921. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  32922. }
  32923. fileMarker = readUint16();
  32924. }
  32925. this.width = frame.samplesPerLine;
  32926. this.height = frame.scanLines;
  32927. this.jfif = jfif;
  32928. this.adobe = adobe;
  32929. this.components = [];
  32930. for (i = 0; i < frame.components.length; i++) {
  32931. component = frame.components[i];
  32932. this.components.push({
  32933. output: buildComponentData(frame, component),
  32934. scaleX: component.h / frame.maxH,
  32935. scaleY: component.v / frame.maxV,
  32936. blocksPerLine: component.blocksPerLine,
  32937. blocksPerColumn: component.blocksPerColumn
  32938. });
  32939. }
  32940. this.numComponents = this.components.length;
  32941. },
  32942. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  32943. var scaleX = this.width / width, scaleY = this.height / height;
  32944. var component, componentScaleX, componentScaleY, blocksPerScanline;
  32945. var x, y, i, j, k;
  32946. var index;
  32947. var offset = 0;
  32948. var output;
  32949. var numComponents = this.components.length;
  32950. var dataLength = width * height * numComponents;
  32951. var data = new Uint8Array(dataLength);
  32952. var xScaleBlockOffset = new Uint32Array(width);
  32953. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  32954. for (i = 0; i < numComponents; i++) {
  32955. component = this.components[i];
  32956. componentScaleX = component.scaleX * scaleX;
  32957. componentScaleY = component.scaleY * scaleY;
  32958. offset = i;
  32959. output = component.output;
  32960. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  32961. // precalculate the xScaleBlockOffset
  32962. for (x = 0; x < width; x++) {
  32963. j = 0 | (x * componentScaleX);
  32964. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  32965. }
  32966. // linearize the blocks of the component
  32967. for (y = 0; y < height; y++) {
  32968. j = 0 | (y * componentScaleY);
  32969. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  32970. for (x = 0; x < width; x++) {
  32971. data[offset] = output[index + xScaleBlockOffset[x]];
  32972. offset += numComponents;
  32973. }
  32974. }
  32975. }
  32976. // decodeTransform contains pairs of multiplier (-256..256) and additive
  32977. var transform = this.decodeTransform;
  32978. if (transform) {
  32979. for (i = 0; i < dataLength;) {
  32980. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  32981. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  32982. }
  32983. }
  32984. }
  32985. return data;
  32986. },
  32987. _isColorConversionNeeded: function isColorConversionNeeded() {
  32988. if (this.adobe && this.adobe.transformCode) {
  32989. // The adobe transform marker overrides any previous setting
  32990. return true;
  32991. } else if (this.numComponents === 3) {
  32992. return true;
  32993. } else {
  32994. return false;
  32995. }
  32996. },
  32997. _convertYccToRgb: function convertYccToRgb(data) {
  32998. var Y, Cb, Cr;
  32999. for (var i = 0, length = data.length; i < length; i += 3) {
  33000. Y = data[i ];
  33001. Cb = data[i + 1];
  33002. Cr = data[i + 2];
  33003. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33004. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33005. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33006. }
  33007. return data;
  33008. },
  33009. _convertYcckToRgb: function convertYcckToRgb(data) {
  33010. var Y, Cb, Cr, k;
  33011. var offset = 0;
  33012. for (var i = 0, length = data.length; i < length; i += 4) {
  33013. Y = data[i];
  33014. Cb = data[i + 1];
  33015. Cr = data[i + 2];
  33016. k = data[i + 3];
  33017. var r = -122.67195406894 +
  33018. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33019. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33020. 0.154362151871126) +
  33021. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33022. 0.00477271405408747 * k + 1.53380253221734) +
  33023. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33024. 0.48357088451265) +
  33025. k * (-0.000336197177618394 * k + 0.484791561490776);
  33026. var g = 107.268039397724 +
  33027. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33028. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33029. 0.176491792462875) +
  33030. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33031. 0.000770482631801132 * k - 0.151051492775562) +
  33032. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33033. 0.25802910206845) +
  33034. k * (-0.000318913117588328 * k - 0.213742400323665);
  33035. var b = -20.810012546947 +
  33036. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33037. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33038. 0.814272968359295) +
  33039. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33040. 0.000560833691242812 * k - 0.195152027534049) +
  33041. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33042. 0.116935020465145) +
  33043. k * (-0.000343531996510555 * k + 0.24165260232407);
  33044. data[offset++] = clamp0to255(r);
  33045. data[offset++] = clamp0to255(g);
  33046. data[offset++] = clamp0to255(b);
  33047. }
  33048. return data;
  33049. },
  33050. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33051. var Y, Cb, Cr;
  33052. for (var i = 0, length = data.length; i < length; i += 4) {
  33053. Y = data[i];
  33054. Cb = data[i + 1];
  33055. Cr = data[i + 2];
  33056. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33057. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33058. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33059. // K in data[i + 3] is unchanged
  33060. }
  33061. return data;
  33062. },
  33063. _convertCmykToRgb: function convertCmykToRgb(data) {
  33064. var c, m, y, k;
  33065. var offset = 0;
  33066. var min = -255 * 255 * 255;
  33067. var scale = 1 / 255 / 255;
  33068. for (var i = 0, length = data.length; i < length; i += 4) {
  33069. c = data[i];
  33070. m = data[i + 1];
  33071. y = data[i + 2];
  33072. k = data[i + 3];
  33073. var r =
  33074. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33075. 18.82290502165302 * y + 212.25662451639585 * k -
  33076. 72734.4411664936) +
  33077. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33078. 17.873870861415444 * k - 1401.7366389350734) +
  33079. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33080. 4465.541406466231) -
  33081. k * (21.86122147463605 * k + 48317.86113160301);
  33082. var g =
  33083. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33084. 6.871425592049007 * y + 31.159100130055922 * k -
  33085. 20220.756542821975) +
  33086. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33087. 131.35250912493976 * k - 48691.05921601825) +
  33088. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33089. 6341.191035517494) -
  33090. k * (20.737325471181034 * k + 47890.15695978492);
  33091. var b =
  33092. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33093. 30.89978309703729 * y - 0.23883238689178934 * k -
  33094. 3616.812083916688) +
  33095. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33096. 50.606957656360734 * k - 28620.90484698408) +
  33097. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33098. 49363.43385999684) -
  33099. k * (22.33816807309886 * k + 45932.16563550634);
  33100. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33101. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33102. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33103. }
  33104. return data;
  33105. },
  33106. getData: function getData(width, height, forceRGBoutput) {
  33107. if (this.numComponents > 4) {
  33108. throw 'Unsupported color mode';
  33109. }
  33110. // type of data: Uint8Array(width * height * numComponents)
  33111. var data = this._getLinearizedBlockData(width, height);
  33112. if (this.numComponents === 3) {
  33113. return this._convertYccToRgb(data);
  33114. } else if (this.numComponents === 4) {
  33115. if (this._isColorConversionNeeded()) {
  33116. if (forceRGBoutput) {
  33117. return this._convertYcckToRgb(data);
  33118. } else {
  33119. return this._convertYcckToCmyk(data);
  33120. }
  33121. } else if (forceRGBoutput) {
  33122. return this._convertCmykToRgb(data);
  33123. }
  33124. }
  33125. return data;
  33126. }
  33127. };
  33128. return constructor;
  33129. })();
  33130. var JpxImage = (function JpxImageClosure() {
  33131. // Table E.1
  33132. var SubbandsGainLog2 = {
  33133. 'LL': 0,
  33134. 'LH': 1,
  33135. 'HL': 1,
  33136. 'HH': 2
  33137. };
  33138. function JpxImage() {
  33139. this.failOnCorruptedImage = false;
  33140. }
  33141. JpxImage.prototype = {
  33142. parse: function JpxImage_parse(data) {
  33143. var head = readUint16(data, 0);
  33144. // No box header, immediate start of codestream (SOC)
  33145. if (head === 0xFF4F) {
  33146. this.parseCodestream(data, 0, data.length);
  33147. return;
  33148. }
  33149. var position = 0, length = data.length;
  33150. while (position < length) {
  33151. var headerSize = 8;
  33152. var lbox = readUint32(data, position);
  33153. var tbox = readUint32(data, position + 4);
  33154. position += headerSize;
  33155. if (lbox === 1) {
  33156. // XLBox: read UInt64 according to spec.
  33157. // JavaScript's int precision of 53 bit should be sufficient here.
  33158. lbox = readUint32(data, position) * 4294967296 +
  33159. readUint32(data, position + 4);
  33160. position += 8;
  33161. headerSize += 8;
  33162. }
  33163. if (lbox === 0) {
  33164. lbox = length - position + headerSize;
  33165. }
  33166. if (lbox < headerSize) {
  33167. throw new Error('JPX Error: Invalid box field size');
  33168. }
  33169. var dataLength = lbox - headerSize;
  33170. var jumpDataLength = true;
  33171. switch (tbox) {
  33172. case 0x6A703268: // 'jp2h'
  33173. jumpDataLength = false; // parsing child boxes
  33174. break;
  33175. case 0x636F6C72: // 'colr'
  33176. // Colorspaces are not used, the CS from the PDF is used.
  33177. var method = data[position];
  33178. var precedence = data[position + 1];
  33179. var approximation = data[position + 2];
  33180. if (method === 1) {
  33181. // enumerated colorspace
  33182. var colorspace = readUint32(data, position + 3);
  33183. switch (colorspace) {
  33184. case 16: // this indicates a sRGB colorspace
  33185. case 17: // this indicates a grayscale colorspace
  33186. case 18: // this indicates a YUV colorspace
  33187. break;
  33188. default:
  33189. warn('Unknown colorspace ' + colorspace);
  33190. break;
  33191. }
  33192. } else if (method === 2) {
  33193. info('ICC profile not supported');
  33194. }
  33195. break;
  33196. case 0x6A703263: // 'jp2c'
  33197. this.parseCodestream(data, position, position + dataLength);
  33198. break;
  33199. case 0x6A502020: // 'jP\024\024'
  33200. if (0x0d0a870a !== readUint32(data, position)) {
  33201. warn('Invalid JP2 signature');
  33202. }
  33203. break;
  33204. // The following header types are valid but currently not used:
  33205. case 0x6A501A1A: // 'jP\032\032'
  33206. case 0x66747970: // 'ftyp'
  33207. case 0x72726571: // 'rreq'
  33208. case 0x72657320: // 'res '
  33209. case 0x69686472: // 'ihdr'
  33210. break;
  33211. default:
  33212. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33213. (tbox >> 16) & 0xFF,
  33214. (tbox >> 8) & 0xFF,
  33215. tbox & 0xFF);
  33216. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33217. break;
  33218. }
  33219. if (jumpDataLength) {
  33220. position += dataLength;
  33221. }
  33222. }
  33223. },
  33224. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33225. var newByte = stream.getByte();
  33226. while (newByte >= 0) {
  33227. var oldByte = newByte;
  33228. newByte = stream.getByte();
  33229. var code = (oldByte << 8) | newByte;
  33230. // Image and tile size (SIZ)
  33231. if (code === 0xFF51) {
  33232. stream.skip(4);
  33233. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33234. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33235. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33236. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33237. stream.skip(16);
  33238. var Csiz = stream.getUint16(); // Byte 36
  33239. this.width = Xsiz - XOsiz;
  33240. this.height = Ysiz - YOsiz;
  33241. this.componentsCount = Csiz;
  33242. // Results are always returned as Uint8Arrays
  33243. this.bitsPerComponent = 8;
  33244. return;
  33245. }
  33246. }
  33247. throw new Error('JPX Error: No size marker found in JPX stream');
  33248. },
  33249. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33250. var context = {};
  33251. try {
  33252. var doNotRecover = false;
  33253. var position = start;
  33254. while (position + 1 < end) {
  33255. var code = readUint16(data, position);
  33256. position += 2;
  33257. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33258. switch (code) {
  33259. case 0xFF4F: // Start of codestream (SOC)
  33260. context.mainHeader = true;
  33261. break;
  33262. case 0xFFD9: // End of codestream (EOC)
  33263. break;
  33264. case 0xFF51: // Image and tile size (SIZ)
  33265. length = readUint16(data, position);
  33266. var siz = {};
  33267. siz.Xsiz = readUint32(data, position + 4);
  33268. siz.Ysiz = readUint32(data, position + 8);
  33269. siz.XOsiz = readUint32(data, position + 12);
  33270. siz.YOsiz = readUint32(data, position + 16);
  33271. siz.XTsiz = readUint32(data, position + 20);
  33272. siz.YTsiz = readUint32(data, position + 24);
  33273. siz.XTOsiz = readUint32(data, position + 28);
  33274. siz.YTOsiz = readUint32(data, position + 32);
  33275. var componentsCount = readUint16(data, position + 36);
  33276. siz.Csiz = componentsCount;
  33277. var components = [];
  33278. j = position + 38;
  33279. for (var i = 0; i < componentsCount; i++) {
  33280. var component = {
  33281. precision: (data[j] & 0x7F) + 1,
  33282. isSigned: !!(data[j] & 0x80),
  33283. XRsiz: data[j + 1],
  33284. YRsiz: data[j + 1]
  33285. };
  33286. calculateComponentDimensions(component, siz);
  33287. components.push(component);
  33288. }
  33289. context.SIZ = siz;
  33290. context.components = components;
  33291. calculateTileGrids(context, components);
  33292. context.QCC = [];
  33293. context.COC = [];
  33294. break;
  33295. case 0xFF5C: // Quantization default (QCD)
  33296. length = readUint16(data, position);
  33297. var qcd = {};
  33298. j = position + 2;
  33299. sqcd = data[j++];
  33300. switch (sqcd & 0x1F) {
  33301. case 0:
  33302. spqcdSize = 8;
  33303. scalarExpounded = true;
  33304. break;
  33305. case 1:
  33306. spqcdSize = 16;
  33307. scalarExpounded = false;
  33308. break;
  33309. case 2:
  33310. spqcdSize = 16;
  33311. scalarExpounded = true;
  33312. break;
  33313. default:
  33314. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33315. }
  33316. qcd.noQuantization = (spqcdSize === 8);
  33317. qcd.scalarExpounded = scalarExpounded;
  33318. qcd.guardBits = sqcd >> 5;
  33319. spqcds = [];
  33320. while (j < length + position) {
  33321. var spqcd = {};
  33322. if (spqcdSize === 8) {
  33323. spqcd.epsilon = data[j++] >> 3;
  33324. spqcd.mu = 0;
  33325. } else {
  33326. spqcd.epsilon = data[j] >> 3;
  33327. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33328. j += 2;
  33329. }
  33330. spqcds.push(spqcd);
  33331. }
  33332. qcd.SPqcds = spqcds;
  33333. if (context.mainHeader) {
  33334. context.QCD = qcd;
  33335. } else {
  33336. context.currentTile.QCD = qcd;
  33337. context.currentTile.QCC = [];
  33338. }
  33339. break;
  33340. case 0xFF5D: // Quantization component (QCC)
  33341. length = readUint16(data, position);
  33342. var qcc = {};
  33343. j = position + 2;
  33344. var cqcc;
  33345. if (context.SIZ.Csiz < 257) {
  33346. cqcc = data[j++];
  33347. } else {
  33348. cqcc = readUint16(data, j);
  33349. j += 2;
  33350. }
  33351. sqcd = data[j++];
  33352. switch (sqcd & 0x1F) {
  33353. case 0:
  33354. spqcdSize = 8;
  33355. scalarExpounded = true;
  33356. break;
  33357. case 1:
  33358. spqcdSize = 16;
  33359. scalarExpounded = false;
  33360. break;
  33361. case 2:
  33362. spqcdSize = 16;
  33363. scalarExpounded = true;
  33364. break;
  33365. default:
  33366. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33367. }
  33368. qcc.noQuantization = (spqcdSize === 8);
  33369. qcc.scalarExpounded = scalarExpounded;
  33370. qcc.guardBits = sqcd >> 5;
  33371. spqcds = [];
  33372. while (j < (length + position)) {
  33373. spqcd = {};
  33374. if (spqcdSize === 8) {
  33375. spqcd.epsilon = data[j++] >> 3;
  33376. spqcd.mu = 0;
  33377. } else {
  33378. spqcd.epsilon = data[j] >> 3;
  33379. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33380. j += 2;
  33381. }
  33382. spqcds.push(spqcd);
  33383. }
  33384. qcc.SPqcds = spqcds;
  33385. if (context.mainHeader) {
  33386. context.QCC[cqcc] = qcc;
  33387. } else {
  33388. context.currentTile.QCC[cqcc] = qcc;
  33389. }
  33390. break;
  33391. case 0xFF52: // Coding style default (COD)
  33392. length = readUint16(data, position);
  33393. var cod = {};
  33394. j = position + 2;
  33395. var scod = data[j++];
  33396. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33397. cod.sopMarkerUsed = !!(scod & 2);
  33398. cod.ephMarkerUsed = !!(scod & 4);
  33399. cod.progressionOrder = data[j++];
  33400. cod.layersCount = readUint16(data, j);
  33401. j += 2;
  33402. cod.multipleComponentTransform = data[j++];
  33403. cod.decompositionLevelsCount = data[j++];
  33404. cod.xcb = (data[j++] & 0xF) + 2;
  33405. cod.ycb = (data[j++] & 0xF) + 2;
  33406. var blockStyle = data[j++];
  33407. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33408. cod.resetContextProbabilities = !!(blockStyle & 2);
  33409. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33410. cod.verticalyStripe = !!(blockStyle & 8);
  33411. cod.predictableTermination = !!(blockStyle & 16);
  33412. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33413. cod.reversibleTransformation = data[j++];
  33414. if (cod.entropyCoderWithCustomPrecincts) {
  33415. var precinctsSizes = [];
  33416. while (j < length + position) {
  33417. var precinctsSize = data[j++];
  33418. precinctsSizes.push({
  33419. PPx: precinctsSize & 0xF,
  33420. PPy: precinctsSize >> 4
  33421. });
  33422. }
  33423. cod.precinctsSizes = precinctsSizes;
  33424. }
  33425. var unsupported = [];
  33426. if (cod.selectiveArithmeticCodingBypass) {
  33427. unsupported.push('selectiveArithmeticCodingBypass');
  33428. }
  33429. if (cod.resetContextProbabilities) {
  33430. unsupported.push('resetContextProbabilities');
  33431. }
  33432. if (cod.terminationOnEachCodingPass) {
  33433. unsupported.push('terminationOnEachCodingPass');
  33434. }
  33435. if (cod.verticalyStripe) {
  33436. unsupported.push('verticalyStripe');
  33437. }
  33438. if (cod.predictableTermination) {
  33439. unsupported.push('predictableTermination');
  33440. }
  33441. if (unsupported.length > 0) {
  33442. doNotRecover = true;
  33443. throw new Error('JPX Error: Unsupported COD options (' +
  33444. unsupported.join(', ') + ')');
  33445. }
  33446. if (context.mainHeader) {
  33447. context.COD = cod;
  33448. } else {
  33449. context.currentTile.COD = cod;
  33450. context.currentTile.COC = [];
  33451. }
  33452. break;
  33453. case 0xFF90: // Start of tile-part (SOT)
  33454. length = readUint16(data, position);
  33455. tile = {};
  33456. tile.index = readUint16(data, position + 2);
  33457. tile.length = readUint32(data, position + 4);
  33458. tile.dataEnd = tile.length + position - 2;
  33459. tile.partIndex = data[position + 8];
  33460. tile.partsCount = data[position + 9];
  33461. context.mainHeader = false;
  33462. if (tile.partIndex === 0) {
  33463. // reset component specific settings
  33464. tile.COD = context.COD;
  33465. tile.COC = context.COC.slice(0); // clone of the global COC
  33466. tile.QCD = context.QCD;
  33467. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33468. }
  33469. context.currentTile = tile;
  33470. break;
  33471. case 0xFF93: // Start of data (SOD)
  33472. tile = context.currentTile;
  33473. if (tile.partIndex === 0) {
  33474. initializeTile(context, tile.index);
  33475. buildPackets(context);
  33476. }
  33477. // moving to the end of the data
  33478. length = tile.dataEnd - position;
  33479. parseTilePackets(context, data, position, length);
  33480. break;
  33481. case 0xFF55: // Tile-part lengths, main header (TLM)
  33482. case 0xFF57: // Packet length, main header (PLM)
  33483. case 0xFF58: // Packet length, tile-part header (PLT)
  33484. case 0xFF64: // Comment (COM)
  33485. length = readUint16(data, position);
  33486. // skipping content
  33487. break;
  33488. case 0xFF53: // Coding style component (COC)
  33489. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33490. 'not implemented');
  33491. default:
  33492. throw new Error('JPX Error: Unknown codestream code: ' +
  33493. code.toString(16));
  33494. }
  33495. position += length;
  33496. }
  33497. } catch (e) {
  33498. if (doNotRecover || this.failOnCorruptedImage) {
  33499. throw e;
  33500. } else {
  33501. warn('Trying to recover from ' + e.message);
  33502. }
  33503. }
  33504. this.tiles = transformComponents(context);
  33505. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33506. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33507. this.componentsCount = context.SIZ.Csiz;
  33508. }
  33509. };
  33510. function calculateComponentDimensions(component, siz) {
  33511. // Section B.2 Component mapping
  33512. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33513. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33514. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33515. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33516. component.width = component.x1 - component.x0;
  33517. component.height = component.y1 - component.y0;
  33518. }
  33519. function calculateTileGrids(context, components) {
  33520. var siz = context.SIZ;
  33521. // Section B.3 Division into tile and tile-components
  33522. var tile, tiles = [];
  33523. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33524. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33525. for (var q = 0; q < numYtiles; q++) {
  33526. for (var p = 0; p < numXtiles; p++) {
  33527. tile = {};
  33528. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33529. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33530. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33531. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33532. tile.width = tile.tx1 - tile.tx0;
  33533. tile.height = tile.ty1 - tile.ty0;
  33534. tile.components = [];
  33535. tiles.push(tile);
  33536. }
  33537. }
  33538. context.tiles = tiles;
  33539. var componentsCount = siz.Csiz;
  33540. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33541. var component = components[i];
  33542. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33543. var tileComponent = {};
  33544. tile = tiles[j];
  33545. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33546. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33547. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33548. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33549. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33550. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33551. tile.components[i] = tileComponent;
  33552. }
  33553. }
  33554. }
  33555. function getBlocksDimensions(context, component, r) {
  33556. var codOrCoc = component.codingStyleParameters;
  33557. var result = {};
  33558. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33559. result.PPx = 15;
  33560. result.PPy = 15;
  33561. } else {
  33562. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33563. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33564. }
  33565. // calculate codeblock size as described in section B.7
  33566. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33567. Math.min(codOrCoc.xcb, result.PPx));
  33568. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33569. Math.min(codOrCoc.ycb, result.PPy));
  33570. return result;
  33571. }
  33572. function buildPrecincts(context, resolution, dimensions) {
  33573. // Section B.6 Division resolution to precincts
  33574. var precinctWidth = 1 << dimensions.PPx;
  33575. var precinctHeight = 1 << dimensions.PPy;
  33576. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33577. // to precincts. Precinct partition divides a resolution according to width
  33578. // and height parameters. The subband that belongs to the resolution level
  33579. // has a different size than the level, unless it is the zero resolution.
  33580. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33581. // The precinct partitioning for a particular subband is derived from a
  33582. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33583. // resolution level)... The LL band associated with each resolution level is
  33584. // divided into precincts... Each of the resulting precinct regions is then
  33585. // mapped into its child subbands (if any) at the next lower resolution
  33586. // level. This is accomplished by using the coordinate transformation
  33587. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33588. // coordinates of a point in the LL band and child subband, respectively.
  33589. var isZeroRes = resolution.resLevel === 0;
  33590. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33591. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33592. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33593. Math.ceil(resolution.trx1 / precinctWidth) -
  33594. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33595. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33596. Math.ceil(resolution.try1 / precinctHeight) -
  33597. Math.floor(resolution.try0 / precinctHeight) : 0);
  33598. var numprecincts = numprecinctswide * numprecinctshigh;
  33599. resolution.precinctParameters = {
  33600. precinctWidth: precinctWidth,
  33601. precinctHeight: precinctHeight,
  33602. numprecinctswide: numprecinctswide,
  33603. numprecinctshigh: numprecinctshigh,
  33604. numprecincts: numprecincts,
  33605. precinctWidthInSubband: precinctWidthInSubband,
  33606. precinctHeightInSubband: precinctHeightInSubband
  33607. };
  33608. }
  33609. function buildCodeblocks(context, subband, dimensions) {
  33610. // Section B.7 Division sub-band into code-blocks
  33611. var xcb_ = dimensions.xcb_;
  33612. var ycb_ = dimensions.ycb_;
  33613. var codeblockWidth = 1 << xcb_;
  33614. var codeblockHeight = 1 << ycb_;
  33615. var cbx0 = subband.tbx0 >> xcb_;
  33616. var cby0 = subband.tby0 >> ycb_;
  33617. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33618. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33619. var precinctParameters = subband.resolution.precinctParameters;
  33620. var codeblocks = [];
  33621. var precincts = [];
  33622. var i, j, codeblock, precinctNumber;
  33623. for (j = cby0; j < cby1; j++) {
  33624. for (i = cbx0; i < cbx1; i++) {
  33625. codeblock = {
  33626. cbx: i,
  33627. cby: j,
  33628. tbx0: codeblockWidth * i,
  33629. tby0: codeblockHeight * j,
  33630. tbx1: codeblockWidth * (i + 1),
  33631. tby1: codeblockHeight * (j + 1)
  33632. };
  33633. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33634. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33635. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33636. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33637. // Calculate precinct number for this codeblock, codeblock position
  33638. // should be relative to its subband, use actual dimension and position
  33639. // See comment about codeblock group width and height
  33640. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33641. precinctParameters.precinctWidthInSubband);
  33642. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33643. precinctParameters.precinctHeightInSubband);
  33644. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33645. codeblock.precinctNumber = precinctNumber;
  33646. codeblock.subbandType = subband.type;
  33647. codeblock.Lblock = 3;
  33648. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  33649. codeblock.tby1_ <= codeblock.tby0_) {
  33650. continue;
  33651. }
  33652. codeblocks.push(codeblock);
  33653. // building precinct for the sub-band
  33654. var precinct = precincts[precinctNumber];
  33655. if (precinct !== undefined) {
  33656. if (i < precinct.cbxMin) {
  33657. precinct.cbxMin = i;
  33658. } else if (i > precinct.cbxMax) {
  33659. precinct.cbxMax = i;
  33660. }
  33661. if (j < precinct.cbyMin) {
  33662. precinct.cbxMin = j;
  33663. } else if (j > precinct.cbyMax) {
  33664. precinct.cbyMax = j;
  33665. }
  33666. } else {
  33667. precincts[precinctNumber] = precinct = {
  33668. cbxMin: i,
  33669. cbyMin: j,
  33670. cbxMax: i,
  33671. cbyMax: j
  33672. };
  33673. }
  33674. codeblock.precinct = precinct;
  33675. }
  33676. }
  33677. subband.codeblockParameters = {
  33678. codeblockWidth: xcb_,
  33679. codeblockHeight: ycb_,
  33680. numcodeblockwide: cbx1 - cbx0 + 1,
  33681. numcodeblockhigh: cby1 - cby0 + 1
  33682. };
  33683. subband.codeblocks = codeblocks;
  33684. subband.precincts = precincts;
  33685. }
  33686. function createPacket(resolution, precinctNumber, layerNumber) {
  33687. var precinctCodeblocks = [];
  33688. // Section B.10.8 Order of info in packet
  33689. var subbands = resolution.subbands;
  33690. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  33691. for (var i = 0, ii = subbands.length; i < ii; i++) {
  33692. var subband = subbands[i];
  33693. var codeblocks = subband.codeblocks;
  33694. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  33695. var codeblock = codeblocks[j];
  33696. if (codeblock.precinctNumber !== precinctNumber) {
  33697. continue;
  33698. }
  33699. precinctCodeblocks.push(codeblock);
  33700. }
  33701. }
  33702. return {
  33703. layerNumber: layerNumber,
  33704. codeblocks: precinctCodeblocks
  33705. };
  33706. }
  33707. function LayerResolutionComponentPositionIterator(context) {
  33708. var siz = context.SIZ;
  33709. var tileIndex = context.currentTile.index;
  33710. var tile = context.tiles[tileIndex];
  33711. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33712. var componentsCount = siz.Csiz;
  33713. var maxDecompositionLevelsCount = 0;
  33714. for (var q = 0; q < componentsCount; q++) {
  33715. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33716. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33717. }
  33718. var l = 0, r = 0, i = 0, k = 0;
  33719. this.nextPacket = function JpxImage_nextPacket() {
  33720. // Section B.12.1.1 Layer-resolution-component-position
  33721. for (; l < layersCount; l++) {
  33722. for (; r <= maxDecompositionLevelsCount; r++) {
  33723. for (; i < componentsCount; i++) {
  33724. var component = tile.components[i];
  33725. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33726. continue;
  33727. }
  33728. var resolution = component.resolutions[r];
  33729. var numprecincts = resolution.precinctParameters.numprecincts;
  33730. for (; k < numprecincts;) {
  33731. var packet = createPacket(resolution, k, l);
  33732. k++;
  33733. return packet;
  33734. }
  33735. k = 0;
  33736. }
  33737. i = 0;
  33738. }
  33739. r = 0;
  33740. }
  33741. throw new Error('JPX Error: Out of packets');
  33742. };
  33743. }
  33744. function ResolutionLayerComponentPositionIterator(context) {
  33745. var siz = context.SIZ;
  33746. var tileIndex = context.currentTile.index;
  33747. var tile = context.tiles[tileIndex];
  33748. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33749. var componentsCount = siz.Csiz;
  33750. var maxDecompositionLevelsCount = 0;
  33751. for (var q = 0; q < componentsCount; q++) {
  33752. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33753. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  33754. }
  33755. var r = 0, l = 0, i = 0, k = 0;
  33756. this.nextPacket = function JpxImage_nextPacket() {
  33757. // Section B.12.1.2 Resolution-layer-component-position
  33758. for (; r <= maxDecompositionLevelsCount; r++) {
  33759. for (; l < layersCount; l++) {
  33760. for (; i < componentsCount; i++) {
  33761. var component = tile.components[i];
  33762. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33763. continue;
  33764. }
  33765. var resolution = component.resolutions[r];
  33766. var numprecincts = resolution.precinctParameters.numprecincts;
  33767. for (; k < numprecincts;) {
  33768. var packet = createPacket(resolution, k, l);
  33769. k++;
  33770. return packet;
  33771. }
  33772. k = 0;
  33773. }
  33774. i = 0;
  33775. }
  33776. l = 0;
  33777. }
  33778. throw new Error('JPX Error: Out of packets');
  33779. };
  33780. }
  33781. function ResolutionPositionComponentLayerIterator(context) {
  33782. var siz = context.SIZ;
  33783. var tileIndex = context.currentTile.index;
  33784. var tile = context.tiles[tileIndex];
  33785. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33786. var componentsCount = siz.Csiz;
  33787. var l, r, c, p;
  33788. var maxDecompositionLevelsCount = 0;
  33789. for (c = 0; c < componentsCount; c++) {
  33790. var component = tile.components[c];
  33791. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  33792. component.codingStyleParameters.decompositionLevelsCount);
  33793. }
  33794. var maxNumPrecinctsInLevel = new Int32Array(
  33795. maxDecompositionLevelsCount + 1);
  33796. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  33797. var maxNumPrecincts = 0;
  33798. for (c = 0; c < componentsCount; ++c) {
  33799. var resolutions = tile.components[c].resolutions;
  33800. if (r < resolutions.length) {
  33801. maxNumPrecincts = Math.max(maxNumPrecincts,
  33802. resolutions[r].precinctParameters.numprecincts);
  33803. }
  33804. }
  33805. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  33806. }
  33807. l = 0;
  33808. r = 0;
  33809. c = 0;
  33810. p = 0;
  33811. this.nextPacket = function JpxImage_nextPacket() {
  33812. // Section B.12.1.3 Resolution-position-component-layer
  33813. for (; r <= maxDecompositionLevelsCount; r++) {
  33814. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  33815. for (; c < componentsCount; c++) {
  33816. var component = tile.components[c];
  33817. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  33818. continue;
  33819. }
  33820. var resolution = component.resolutions[r];
  33821. var numprecincts = resolution.precinctParameters.numprecincts;
  33822. if (p >= numprecincts) {
  33823. continue;
  33824. }
  33825. for (; l < layersCount;) {
  33826. var packet = createPacket(resolution, p, l);
  33827. l++;
  33828. return packet;
  33829. }
  33830. l = 0;
  33831. }
  33832. c = 0;
  33833. }
  33834. p = 0;
  33835. }
  33836. throw new Error('JPX Error: Out of packets');
  33837. };
  33838. }
  33839. function PositionComponentResolutionLayerIterator(context) {
  33840. var siz = context.SIZ;
  33841. var tileIndex = context.currentTile.index;
  33842. var tile = context.tiles[tileIndex];
  33843. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33844. var componentsCount = siz.Csiz;
  33845. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33846. var precinctsIterationSizes = precinctsSizes;
  33847. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33848. this.nextPacket = function JpxImage_nextPacket() {
  33849. // Section B.12.1.4 Position-component-resolution-layer
  33850. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33851. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33852. for (; c < componentsCount; c++) {
  33853. var component = tile.components[c];
  33854. var decompositionLevelsCount =
  33855. component.codingStyleParameters.decompositionLevelsCount;
  33856. for (; r <= decompositionLevelsCount; r++) {
  33857. var resolution = component.resolutions[r];
  33858. var sizeInImageScale =
  33859. precinctsSizes.components[c].resolutions[r];
  33860. var k = getPrecinctIndexIfExist(
  33861. px,
  33862. py,
  33863. sizeInImageScale,
  33864. precinctsIterationSizes,
  33865. resolution);
  33866. if (k === null) {
  33867. continue;
  33868. }
  33869. for (; l < layersCount;) {
  33870. var packet = createPacket(resolution, k, l);
  33871. l++;
  33872. return packet;
  33873. }
  33874. l = 0;
  33875. }
  33876. r = 0;
  33877. }
  33878. c = 0;
  33879. }
  33880. px = 0;
  33881. }
  33882. throw new Error('JPX Error: Out of packets');
  33883. };
  33884. }
  33885. function ComponentPositionResolutionLayerIterator(context) {
  33886. var siz = context.SIZ;
  33887. var tileIndex = context.currentTile.index;
  33888. var tile = context.tiles[tileIndex];
  33889. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  33890. var componentsCount = siz.Csiz;
  33891. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  33892. var l = 0, r = 0, c = 0, px = 0, py = 0;
  33893. this.nextPacket = function JpxImage_nextPacket() {
  33894. // Section B.12.1.5 Component-position-resolution-layer
  33895. for (; c < componentsCount; ++c) {
  33896. var component = tile.components[c];
  33897. var precinctsIterationSizes = precinctsSizes.components[c];
  33898. var decompositionLevelsCount =
  33899. component.codingStyleParameters.decompositionLevelsCount;
  33900. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  33901. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  33902. for (; r <= decompositionLevelsCount; r++) {
  33903. var resolution = component.resolutions[r];
  33904. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  33905. var k = getPrecinctIndexIfExist(
  33906. px,
  33907. py,
  33908. sizeInImageScale,
  33909. precinctsIterationSizes,
  33910. resolution);
  33911. if (k === null) {
  33912. continue;
  33913. }
  33914. for (; l < layersCount;) {
  33915. var packet = createPacket(resolution, k, l);
  33916. l++;
  33917. return packet;
  33918. }
  33919. l = 0;
  33920. }
  33921. r = 0;
  33922. }
  33923. px = 0;
  33924. }
  33925. py = 0;
  33926. }
  33927. throw new Error('JPX Error: Out of packets');
  33928. };
  33929. }
  33930. function getPrecinctIndexIfExist(
  33931. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  33932. var posX = pxIndex * precinctIterationSizes.minWidth;
  33933. var posY = pyIndex * precinctIterationSizes.minHeight;
  33934. if (posX % sizeInImageScale.width !== 0 ||
  33935. posY % sizeInImageScale.height !== 0) {
  33936. return null;
  33937. }
  33938. var startPrecinctRowIndex =
  33939. (posY / sizeInImageScale.width) *
  33940. resolution.precinctParameters.numprecinctswide;
  33941. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  33942. }
  33943. function getPrecinctSizesInImageScale(tile) {
  33944. var componentsCount = tile.components.length;
  33945. var minWidth = Number.MAX_VALUE;
  33946. var minHeight = Number.MAX_VALUE;
  33947. var maxNumWide = 0;
  33948. var maxNumHigh = 0;
  33949. var sizePerComponent = new Array(componentsCount);
  33950. for (var c = 0; c < componentsCount; c++) {
  33951. var component = tile.components[c];
  33952. var decompositionLevelsCount =
  33953. component.codingStyleParameters.decompositionLevelsCount;
  33954. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  33955. var minWidthCurrentComponent = Number.MAX_VALUE;
  33956. var minHeightCurrentComponent = Number.MAX_VALUE;
  33957. var maxNumWideCurrentComponent = 0;
  33958. var maxNumHighCurrentComponent = 0;
  33959. var scale = 1;
  33960. for (var r = decompositionLevelsCount; r >= 0; --r) {
  33961. var resolution = component.resolutions[r];
  33962. var widthCurrentResolution =
  33963. scale * resolution.precinctParameters.precinctWidth;
  33964. var heightCurrentResolution =
  33965. scale * resolution.precinctParameters.precinctHeight;
  33966. minWidthCurrentComponent = Math.min(
  33967. minWidthCurrentComponent,
  33968. widthCurrentResolution);
  33969. minHeightCurrentComponent = Math.min(
  33970. minHeightCurrentComponent,
  33971. heightCurrentResolution);
  33972. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  33973. resolution.precinctParameters.numprecinctswide);
  33974. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  33975. resolution.precinctParameters.numprecinctshigh);
  33976. sizePerResolution[r] = {
  33977. width: widthCurrentResolution,
  33978. height: heightCurrentResolution
  33979. };
  33980. scale <<= 1;
  33981. }
  33982. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  33983. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  33984. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  33985. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  33986. sizePerComponent[c] = {
  33987. resolutions: sizePerResolution,
  33988. minWidth: minWidthCurrentComponent,
  33989. minHeight: minHeightCurrentComponent,
  33990. maxNumWide: maxNumWideCurrentComponent,
  33991. maxNumHigh: maxNumHighCurrentComponent
  33992. };
  33993. }
  33994. return {
  33995. components: sizePerComponent,
  33996. minWidth: minWidth,
  33997. minHeight: minHeight,
  33998. maxNumWide: maxNumWide,
  33999. maxNumHigh: maxNumHigh
  34000. };
  34001. }
  34002. function buildPackets(context) {
  34003. var siz = context.SIZ;
  34004. var tileIndex = context.currentTile.index;
  34005. var tile = context.tiles[tileIndex];
  34006. var componentsCount = siz.Csiz;
  34007. // Creating resolutions and sub-bands for each component
  34008. for (var c = 0; c < componentsCount; c++) {
  34009. var component = tile.components[c];
  34010. var decompositionLevelsCount =
  34011. component.codingStyleParameters.decompositionLevelsCount;
  34012. // Section B.5 Resolution levels and sub-bands
  34013. var resolutions = [];
  34014. var subbands = [];
  34015. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34016. var blocksDimensions = getBlocksDimensions(context, component, r);
  34017. var resolution = {};
  34018. var scale = 1 << (decompositionLevelsCount - r);
  34019. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34020. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34021. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34022. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34023. resolution.resLevel = r;
  34024. buildPrecincts(context, resolution, blocksDimensions);
  34025. resolutions.push(resolution);
  34026. var subband;
  34027. if (r === 0) {
  34028. // one sub-band (LL) with last decomposition
  34029. subband = {};
  34030. subband.type = 'LL';
  34031. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34032. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34033. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34034. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34035. subband.resolution = resolution;
  34036. buildCodeblocks(context, subband, blocksDimensions);
  34037. subbands.push(subband);
  34038. resolution.subbands = [subband];
  34039. } else {
  34040. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34041. var resolutionSubbands = [];
  34042. // three sub-bands (HL, LH and HH) with rest of decompositions
  34043. subband = {};
  34044. subband.type = 'HL';
  34045. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34046. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34047. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34048. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34049. subband.resolution = resolution;
  34050. buildCodeblocks(context, subband, blocksDimensions);
  34051. subbands.push(subband);
  34052. resolutionSubbands.push(subband);
  34053. subband = {};
  34054. subband.type = 'LH';
  34055. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34056. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34057. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34058. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34059. subband.resolution = resolution;
  34060. buildCodeblocks(context, subband, blocksDimensions);
  34061. subbands.push(subband);
  34062. resolutionSubbands.push(subband);
  34063. subband = {};
  34064. subband.type = 'HH';
  34065. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34066. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34067. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34068. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34069. subband.resolution = resolution;
  34070. buildCodeblocks(context, subband, blocksDimensions);
  34071. subbands.push(subband);
  34072. resolutionSubbands.push(subband);
  34073. resolution.subbands = resolutionSubbands;
  34074. }
  34075. }
  34076. component.resolutions = resolutions;
  34077. component.subbands = subbands;
  34078. }
  34079. // Generate the packets sequence
  34080. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34081. switch (progressionOrder) {
  34082. case 0:
  34083. tile.packetsIterator =
  34084. new LayerResolutionComponentPositionIterator(context);
  34085. break;
  34086. case 1:
  34087. tile.packetsIterator =
  34088. new ResolutionLayerComponentPositionIterator(context);
  34089. break;
  34090. case 2:
  34091. tile.packetsIterator =
  34092. new ResolutionPositionComponentLayerIterator(context);
  34093. break;
  34094. case 3:
  34095. tile.packetsIterator =
  34096. new PositionComponentResolutionLayerIterator(context);
  34097. break;
  34098. case 4:
  34099. tile.packetsIterator =
  34100. new ComponentPositionResolutionLayerIterator(context);
  34101. break;
  34102. default:
  34103. throw new Error('JPX Error: Unsupported progression order ' +
  34104. progressionOrder);
  34105. }
  34106. }
  34107. function parseTilePackets(context, data, offset, dataLength) {
  34108. var position = 0;
  34109. var buffer, bufferSize = 0, skipNextBit = false;
  34110. function readBits(count) {
  34111. while (bufferSize < count) {
  34112. var b = data[offset + position];
  34113. position++;
  34114. if (skipNextBit) {
  34115. buffer = (buffer << 7) | b;
  34116. bufferSize += 7;
  34117. skipNextBit = false;
  34118. } else {
  34119. buffer = (buffer << 8) | b;
  34120. bufferSize += 8;
  34121. }
  34122. if (b === 0xFF) {
  34123. skipNextBit = true;
  34124. }
  34125. }
  34126. bufferSize -= count;
  34127. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34128. }
  34129. function skipMarkerIfEqual(value) {
  34130. if (data[offset + position - 1] === 0xFF &&
  34131. data[offset + position] === value) {
  34132. skipBytes(1);
  34133. return true;
  34134. } else if (data[offset + position] === 0xFF &&
  34135. data[offset + position + 1] === value) {
  34136. skipBytes(2);
  34137. return true;
  34138. }
  34139. return false;
  34140. }
  34141. function skipBytes(count) {
  34142. position += count;
  34143. }
  34144. function alignToByte() {
  34145. bufferSize = 0;
  34146. if (skipNextBit) {
  34147. position++;
  34148. skipNextBit = false;
  34149. }
  34150. }
  34151. function readCodingpasses() {
  34152. if (readBits(1) === 0) {
  34153. return 1;
  34154. }
  34155. if (readBits(1) === 0) {
  34156. return 2;
  34157. }
  34158. var value = readBits(2);
  34159. if (value < 3) {
  34160. return value + 3;
  34161. }
  34162. value = readBits(5);
  34163. if (value < 31) {
  34164. return value + 6;
  34165. }
  34166. value = readBits(7);
  34167. return value + 37;
  34168. }
  34169. var tileIndex = context.currentTile.index;
  34170. var tile = context.tiles[tileIndex];
  34171. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34172. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34173. var packetsIterator = tile.packetsIterator;
  34174. while (position < dataLength) {
  34175. alignToByte();
  34176. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34177. // Skip also marker segment length and packet sequence ID
  34178. skipBytes(4);
  34179. }
  34180. var packet = packetsIterator.nextPacket();
  34181. if (!readBits(1)) {
  34182. continue;
  34183. }
  34184. var layerNumber = packet.layerNumber;
  34185. var queue = [], codeblock;
  34186. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34187. codeblock = packet.codeblocks[i];
  34188. var precinct = codeblock.precinct;
  34189. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34190. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34191. var codeblockIncluded = false;
  34192. var firstTimeInclusion = false;
  34193. var valueReady;
  34194. if (codeblock['included'] !== undefined) {
  34195. codeblockIncluded = !!readBits(1);
  34196. } else {
  34197. // reading inclusion tree
  34198. precinct = codeblock.precinct;
  34199. var inclusionTree, zeroBitPlanesTree;
  34200. if (precinct['inclusionTree'] !== undefined) {
  34201. inclusionTree = precinct.inclusionTree;
  34202. } else {
  34203. // building inclusion and zero bit-planes trees
  34204. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34205. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34206. inclusionTree = new InclusionTree(width, height, layerNumber);
  34207. zeroBitPlanesTree = new TagTree(width, height);
  34208. precinct.inclusionTree = inclusionTree;
  34209. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34210. }
  34211. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34212. while (true) {
  34213. if (readBits(1)) {
  34214. valueReady = !inclusionTree.nextLevel();
  34215. if (valueReady) {
  34216. codeblock.included = true;
  34217. codeblockIncluded = firstTimeInclusion = true;
  34218. break;
  34219. }
  34220. } else {
  34221. inclusionTree.incrementValue(layerNumber);
  34222. break;
  34223. }
  34224. }
  34225. }
  34226. }
  34227. if (!codeblockIncluded) {
  34228. continue;
  34229. }
  34230. if (firstTimeInclusion) {
  34231. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34232. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34233. while (true) {
  34234. if (readBits(1)) {
  34235. valueReady = !zeroBitPlanesTree.nextLevel();
  34236. if (valueReady) {
  34237. break;
  34238. }
  34239. } else {
  34240. zeroBitPlanesTree.incrementValue();
  34241. }
  34242. }
  34243. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34244. }
  34245. var codingpasses = readCodingpasses();
  34246. while (readBits(1)) {
  34247. codeblock.Lblock++;
  34248. }
  34249. var codingpassesLog2 = log2(codingpasses);
  34250. // rounding down log2
  34251. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34252. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34253. var codedDataLength = readBits(bits);
  34254. queue.push({
  34255. codeblock: codeblock,
  34256. codingpasses: codingpasses,
  34257. dataLength: codedDataLength
  34258. });
  34259. }
  34260. alignToByte();
  34261. if (ephMarkerUsed) {
  34262. skipMarkerIfEqual(0x92);
  34263. }
  34264. while (queue.length > 0) {
  34265. var packetItem = queue.shift();
  34266. codeblock = packetItem.codeblock;
  34267. if (codeblock['data'] === undefined) {
  34268. codeblock.data = [];
  34269. }
  34270. codeblock.data.push({
  34271. data: data,
  34272. start: offset + position,
  34273. end: offset + position + packetItem.dataLength,
  34274. codingpasses: packetItem.codingpasses
  34275. });
  34276. position += packetItem.dataLength;
  34277. }
  34278. }
  34279. return position;
  34280. }
  34281. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34282. delta, mb, reversible, segmentationSymbolUsed) {
  34283. var x0 = subband.tbx0;
  34284. var y0 = subband.tby0;
  34285. var width = subband.tbx1 - subband.tbx0;
  34286. var codeblocks = subband.codeblocks;
  34287. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34288. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34289. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34290. var codeblock = codeblocks[i];
  34291. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34292. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34293. if (blockWidth === 0 || blockHeight === 0) {
  34294. continue;
  34295. }
  34296. if (codeblock['data'] === undefined) {
  34297. continue;
  34298. }
  34299. var bitModel, currentCodingpassType;
  34300. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34301. codeblock.zeroBitPlanes, mb);
  34302. currentCodingpassType = 2; // first bit plane starts from cleanup
  34303. // collect data
  34304. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34305. var j, jj, dataItem;
  34306. for (j = 0, jj = data.length; j < jj; j++) {
  34307. dataItem = data[j];
  34308. totalLength += dataItem.end - dataItem.start;
  34309. codingpasses += dataItem.codingpasses;
  34310. }
  34311. var encodedData = new Uint8Array(totalLength);
  34312. var position = 0;
  34313. for (j = 0, jj = data.length; j < jj; j++) {
  34314. dataItem = data[j];
  34315. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34316. encodedData.set(chunk, position);
  34317. position += chunk.length;
  34318. }
  34319. // decoding the item
  34320. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34321. bitModel.setDecoder(decoder);
  34322. for (j = 0; j < codingpasses; j++) {
  34323. switch (currentCodingpassType) {
  34324. case 0:
  34325. bitModel.runSignificancePropogationPass();
  34326. break;
  34327. case 1:
  34328. bitModel.runMagnitudeRefinementPass();
  34329. break;
  34330. case 2:
  34331. bitModel.runCleanupPass();
  34332. if (segmentationSymbolUsed) {
  34333. bitModel.checkSegmentationSymbol();
  34334. }
  34335. break;
  34336. }
  34337. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34338. }
  34339. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34340. var sign = bitModel.coefficentsSign;
  34341. var magnitude = bitModel.coefficentsMagnitude;
  34342. var bitsDecoded = bitModel.bitsDecoded;
  34343. var magnitudeCorrection = reversible ? 0 : 0.5;
  34344. var k, n, nb;
  34345. position = 0;
  34346. // Do the interleaving of Section F.3.3 here, so we do not need
  34347. // to copy later. LL level is not interleaved, just copied.
  34348. var interleave = (subband.type !== 'LL');
  34349. for (j = 0; j < blockHeight; j++) {
  34350. var row = (offset / width) | 0; // row in the non-interleaved subband
  34351. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34352. for (k = 0; k < blockWidth; k++) {
  34353. n = magnitude[position];
  34354. if (n !== 0) {
  34355. n = (n + magnitudeCorrection) * delta;
  34356. if (sign[position] !== 0) {
  34357. n = -n;
  34358. }
  34359. nb = bitsDecoded[position];
  34360. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34361. if (reversible && (nb >= mb)) {
  34362. coefficients[pos] = n;
  34363. } else {
  34364. coefficients[pos] = n * (1 << (mb - nb));
  34365. }
  34366. }
  34367. offset++;
  34368. position++;
  34369. }
  34370. offset += width - blockWidth;
  34371. }
  34372. }
  34373. }
  34374. function transformTile(context, tile, c) {
  34375. var component = tile.components[c];
  34376. var codingStyleParameters = component.codingStyleParameters;
  34377. var quantizationParameters = component.quantizationParameters;
  34378. var decompositionLevelsCount =
  34379. codingStyleParameters.decompositionLevelsCount;
  34380. var spqcds = quantizationParameters.SPqcds;
  34381. var scalarExpounded = quantizationParameters.scalarExpounded;
  34382. var guardBits = quantizationParameters.guardBits;
  34383. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34384. var precision = context.components[c].precision;
  34385. var reversible = codingStyleParameters.reversibleTransformation;
  34386. var transform = (reversible ? new ReversibleTransform() :
  34387. new IrreversibleTransform());
  34388. var subbandCoefficients = [];
  34389. var b = 0;
  34390. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34391. var resolution = component.resolutions[i];
  34392. var width = resolution.trx1 - resolution.trx0;
  34393. var height = resolution.try1 - resolution.try0;
  34394. // Allocate space for the whole sublevel.
  34395. var coefficients = new Float32Array(width * height);
  34396. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34397. var mu, epsilon;
  34398. if (!scalarExpounded) {
  34399. // formula E-5
  34400. mu = spqcds[0].mu;
  34401. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34402. } else {
  34403. mu = spqcds[b].mu;
  34404. epsilon = spqcds[b].epsilon;
  34405. b++;
  34406. }
  34407. var subband = resolution.subbands[j];
  34408. var gainLog2 = SubbandsGainLog2[subband.type];
  34409. // calulate quantization coefficient (Section E.1.1.1)
  34410. var delta = (reversible ? 1 :
  34411. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34412. var mb = (guardBits + epsilon - 1);
  34413. // In the first resolution level, copyCoefficients will fill the
  34414. // whole array with coefficients. In the succeding passes,
  34415. // copyCoefficients will consecutively fill in the values that belong
  34416. // to the interleaved positions of the HL, LH, and HH coefficients.
  34417. // The LL coefficients will then be interleaved in Transform.iterate().
  34418. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34419. reversible, segmentationSymbolUsed);
  34420. }
  34421. subbandCoefficients.push({
  34422. width: width,
  34423. height: height,
  34424. items: coefficients
  34425. });
  34426. }
  34427. var result = transform.calculate(subbandCoefficients,
  34428. component.tcx0, component.tcy0);
  34429. return {
  34430. left: component.tcx0,
  34431. top: component.tcy0,
  34432. width: result.width,
  34433. height: result.height,
  34434. items: result.items
  34435. };
  34436. }
  34437. function transformComponents(context) {
  34438. var siz = context.SIZ;
  34439. var components = context.components;
  34440. var componentsCount = siz.Csiz;
  34441. var resultImages = [];
  34442. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34443. var tile = context.tiles[i];
  34444. var transformedTiles = [];
  34445. var c;
  34446. for (c = 0; c < componentsCount; c++) {
  34447. transformedTiles[c] = transformTile(context, tile, c);
  34448. }
  34449. var tile0 = transformedTiles[0];
  34450. var out = new Uint8Array(tile0.items.length * componentsCount);
  34451. var result = {
  34452. left: tile0.left,
  34453. top: tile0.top,
  34454. width: tile0.width,
  34455. height: tile0.height,
  34456. items: out
  34457. };
  34458. // Section G.2.2 Inverse multi component transform
  34459. var shift, offset, max, min, maxK;
  34460. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34461. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34462. var fourComponents = componentsCount === 4;
  34463. var y0items = transformedTiles[0].items;
  34464. var y1items = transformedTiles[1].items;
  34465. var y2items = transformedTiles[2].items;
  34466. var y3items = fourComponents ? transformedTiles[3].items : null;
  34467. // HACK: The multiple component transform formulas below assume that
  34468. // all components have the same precision. With this in mind, we
  34469. // compute shift and offset only once.
  34470. shift = components[0].precision - 8;
  34471. offset = (128 << shift) + 0.5;
  34472. max = 255 * (1 << shift);
  34473. maxK = max * 0.5;
  34474. min = -maxK;
  34475. var component0 = tile.components[0];
  34476. var alpha01 = componentsCount - 3;
  34477. jj = y0items.length;
  34478. if (!component0.codingStyleParameters.reversibleTransformation) {
  34479. // inverse irreversible multiple component transform
  34480. for (j = 0; j < jj; j++, pos += alpha01) {
  34481. y0 = y0items[j] + offset;
  34482. y1 = y1items[j];
  34483. y2 = y2items[j];
  34484. r = y0 + 1.402 * y2;
  34485. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34486. b = y0 + 1.772 * y1;
  34487. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34488. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34489. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34490. }
  34491. } else {
  34492. // inverse reversible multiple component transform
  34493. for (j = 0; j < jj; j++, pos += alpha01) {
  34494. y0 = y0items[j] + offset;
  34495. y1 = y1items[j];
  34496. y2 = y2items[j];
  34497. g = y0 - ((y2 + y1) >> 2);
  34498. r = g + y2;
  34499. b = g + y1;
  34500. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34501. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34502. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34503. }
  34504. }
  34505. if (fourComponents) {
  34506. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34507. k = y3items[j];
  34508. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34509. }
  34510. }
  34511. } else { // no multi-component transform
  34512. for (c = 0; c < componentsCount; c++) {
  34513. var items = transformedTiles[c].items;
  34514. shift = components[c].precision - 8;
  34515. offset = (128 << shift) + 0.5;
  34516. max = (127.5 * (1 << shift));
  34517. min = -max;
  34518. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34519. val = items[j];
  34520. out[pos] = val <= min ? 0 :
  34521. val >= max ? 255 : (val + offset) >> shift;
  34522. pos += componentsCount;
  34523. }
  34524. }
  34525. }
  34526. resultImages.push(result);
  34527. }
  34528. return resultImages;
  34529. }
  34530. function initializeTile(context, tileIndex) {
  34531. var siz = context.SIZ;
  34532. var componentsCount = siz.Csiz;
  34533. var tile = context.tiles[tileIndex];
  34534. for (var c = 0; c < componentsCount; c++) {
  34535. var component = tile.components[c];
  34536. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34537. context.currentTile.QCC[c] : context.currentTile.QCD);
  34538. component.quantizationParameters = qcdOrQcc;
  34539. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34540. context.currentTile.COC[c] : context.currentTile.COD);
  34541. component.codingStyleParameters = codOrCoc;
  34542. }
  34543. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34544. }
  34545. // Section B.10.2 Tag trees
  34546. var TagTree = (function TagTreeClosure() {
  34547. function TagTree(width, height) {
  34548. var levelsLength = log2(Math.max(width, height)) + 1;
  34549. this.levels = [];
  34550. for (var i = 0; i < levelsLength; i++) {
  34551. var level = {
  34552. width: width,
  34553. height: height,
  34554. items: []
  34555. };
  34556. this.levels.push(level);
  34557. width = Math.ceil(width / 2);
  34558. height = Math.ceil(height / 2);
  34559. }
  34560. }
  34561. TagTree.prototype = {
  34562. reset: function TagTree_reset(i, j) {
  34563. var currentLevel = 0, value = 0, level;
  34564. while (currentLevel < this.levels.length) {
  34565. level = this.levels[currentLevel];
  34566. var index = i + j * level.width;
  34567. if (level.items[index] !== undefined) {
  34568. value = level.items[index];
  34569. break;
  34570. }
  34571. level.index = index;
  34572. i >>= 1;
  34573. j >>= 1;
  34574. currentLevel++;
  34575. }
  34576. currentLevel--;
  34577. level = this.levels[currentLevel];
  34578. level.items[level.index] = value;
  34579. this.currentLevel = currentLevel;
  34580. delete this.value;
  34581. },
  34582. incrementValue: function TagTree_incrementValue() {
  34583. var level = this.levels[this.currentLevel];
  34584. level.items[level.index]++;
  34585. },
  34586. nextLevel: function TagTree_nextLevel() {
  34587. var currentLevel = this.currentLevel;
  34588. var level = this.levels[currentLevel];
  34589. var value = level.items[level.index];
  34590. currentLevel--;
  34591. if (currentLevel < 0) {
  34592. this.value = value;
  34593. return false;
  34594. }
  34595. this.currentLevel = currentLevel;
  34596. level = this.levels[currentLevel];
  34597. level.items[level.index] = value;
  34598. return true;
  34599. }
  34600. };
  34601. return TagTree;
  34602. })();
  34603. var InclusionTree = (function InclusionTreeClosure() {
  34604. function InclusionTree(width, height, defaultValue) {
  34605. var levelsLength = log2(Math.max(width, height)) + 1;
  34606. this.levels = [];
  34607. for (var i = 0; i < levelsLength; i++) {
  34608. var items = new Uint8Array(width * height);
  34609. for (var j = 0, jj = items.length; j < jj; j++) {
  34610. items[j] = defaultValue;
  34611. }
  34612. var level = {
  34613. width: width,
  34614. height: height,
  34615. items: items
  34616. };
  34617. this.levels.push(level);
  34618. width = Math.ceil(width / 2);
  34619. height = Math.ceil(height / 2);
  34620. }
  34621. }
  34622. InclusionTree.prototype = {
  34623. reset: function InclusionTree_reset(i, j, stopValue) {
  34624. var currentLevel = 0;
  34625. while (currentLevel < this.levels.length) {
  34626. var level = this.levels[currentLevel];
  34627. var index = i + j * level.width;
  34628. level.index = index;
  34629. var value = level.items[index];
  34630. if (value === 0xFF) {
  34631. break;
  34632. }
  34633. if (value > stopValue) {
  34634. this.currentLevel = currentLevel;
  34635. // already know about this one, propagating the value to top levels
  34636. this.propagateValues();
  34637. return false;
  34638. }
  34639. i >>= 1;
  34640. j >>= 1;
  34641. currentLevel++;
  34642. }
  34643. this.currentLevel = currentLevel - 1;
  34644. return true;
  34645. },
  34646. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34647. var level = this.levels[this.currentLevel];
  34648. level.items[level.index] = stopValue + 1;
  34649. this.propagateValues();
  34650. },
  34651. propagateValues: function InclusionTree_propagateValues() {
  34652. var levelIndex = this.currentLevel;
  34653. var level = this.levels[levelIndex];
  34654. var currentValue = level.items[level.index];
  34655. while (--levelIndex >= 0) {
  34656. level = this.levels[levelIndex];
  34657. level.items[level.index] = currentValue;
  34658. }
  34659. },
  34660. nextLevel: function InclusionTree_nextLevel() {
  34661. var currentLevel = this.currentLevel;
  34662. var level = this.levels[currentLevel];
  34663. var value = level.items[level.index];
  34664. level.items[level.index] = 0xFF;
  34665. currentLevel--;
  34666. if (currentLevel < 0) {
  34667. return false;
  34668. }
  34669. this.currentLevel = currentLevel;
  34670. level = this.levels[currentLevel];
  34671. level.items[level.index] = value;
  34672. return true;
  34673. }
  34674. };
  34675. return InclusionTree;
  34676. })();
  34677. // Section D. Coefficient bit modeling
  34678. var BitModel = (function BitModelClosure() {
  34679. var UNIFORM_CONTEXT = 17;
  34680. var RUNLENGTH_CONTEXT = 18;
  34681. // Table D-1
  34682. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  34683. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  34684. var LLAndLHContextsLabel = new Uint8Array([
  34685. 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,
  34686. 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,
  34687. 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
  34688. ]);
  34689. var HLContextLabel = new Uint8Array([
  34690. 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,
  34691. 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,
  34692. 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
  34693. ]);
  34694. var HHContextLabel = new Uint8Array([
  34695. 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,
  34696. 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,
  34697. 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
  34698. ]);
  34699. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  34700. this.width = width;
  34701. this.height = height;
  34702. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  34703. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  34704. var coefficientCount = width * height;
  34705. // coefficients outside the encoding region treated as insignificant
  34706. // add border state cells for significanceState
  34707. this.neighborsSignificance = new Uint8Array(coefficientCount);
  34708. this.coefficentsSign = new Uint8Array(coefficientCount);
  34709. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  34710. mb > 6 ? new Uint16Array(coefficientCount) :
  34711. new Uint8Array(coefficientCount);
  34712. this.processingFlags = new Uint8Array(coefficientCount);
  34713. var bitsDecoded = new Uint8Array(coefficientCount);
  34714. if (zeroBitPlanes !== 0) {
  34715. for (var i = 0; i < coefficientCount; i++) {
  34716. bitsDecoded[i] = zeroBitPlanes;
  34717. }
  34718. }
  34719. this.bitsDecoded = bitsDecoded;
  34720. this.reset();
  34721. }
  34722. BitModel.prototype = {
  34723. setDecoder: function BitModel_setDecoder(decoder) {
  34724. this.decoder = decoder;
  34725. },
  34726. reset: function BitModel_reset() {
  34727. // We have 17 contexts that are accessed via context labels,
  34728. // plus the uniform and runlength context.
  34729. this.contexts = new Int8Array(19);
  34730. // Contexts are packed into 1 byte:
  34731. // highest 7 bits carry the index, lowest bit carries mps
  34732. this.contexts[0] = (4 << 1) | 0;
  34733. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  34734. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  34735. },
  34736. setNeighborsSignificance:
  34737. function BitModel_setNeighborsSignificance(row, column, index) {
  34738. var neighborsSignificance = this.neighborsSignificance;
  34739. var width = this.width, height = this.height;
  34740. var left = (column > 0);
  34741. var right = (column + 1 < width);
  34742. var i;
  34743. if (row > 0) {
  34744. i = index - width;
  34745. if (left) {
  34746. neighborsSignificance[i - 1] += 0x10;
  34747. }
  34748. if (right) {
  34749. neighborsSignificance[i + 1] += 0x10;
  34750. }
  34751. neighborsSignificance[i] += 0x04;
  34752. }
  34753. if (row + 1 < height) {
  34754. i = index + width;
  34755. if (left) {
  34756. neighborsSignificance[i - 1] += 0x10;
  34757. }
  34758. if (right) {
  34759. neighborsSignificance[i + 1] += 0x10;
  34760. }
  34761. neighborsSignificance[i] += 0x04;
  34762. }
  34763. if (left) {
  34764. neighborsSignificance[index - 1] += 0x01;
  34765. }
  34766. if (right) {
  34767. neighborsSignificance[index + 1] += 0x01;
  34768. }
  34769. neighborsSignificance[index] |= 0x80;
  34770. },
  34771. runSignificancePropogationPass:
  34772. function BitModel_runSignificancePropogationPass() {
  34773. var decoder = this.decoder;
  34774. var width = this.width, height = this.height;
  34775. var coefficentsMagnitude = this.coefficentsMagnitude;
  34776. var coefficentsSign = this.coefficentsSign;
  34777. var neighborsSignificance = this.neighborsSignificance;
  34778. var processingFlags = this.processingFlags;
  34779. var contexts = this.contexts;
  34780. var labels = this.contextLabelTable;
  34781. var bitsDecoded = this.bitsDecoded;
  34782. var processedInverseMask = ~1;
  34783. var processedMask = 1;
  34784. var firstMagnitudeBitMask = 2;
  34785. for (var i0 = 0; i0 < height; i0 += 4) {
  34786. for (var j = 0; j < width; j++) {
  34787. var index = i0 * width + j;
  34788. for (var i1 = 0; i1 < 4; i1++, index += width) {
  34789. var i = i0 + i1;
  34790. if (i >= height) {
  34791. break;
  34792. }
  34793. // clear processed flag first
  34794. processingFlags[index] &= processedInverseMask;
  34795. if (coefficentsMagnitude[index] ||
  34796. !neighborsSignificance[index]) {
  34797. continue;
  34798. }
  34799. var contextLabel = labels[neighborsSignificance[index]];
  34800. var decision = decoder.readBit(contexts, contextLabel);
  34801. if (decision) {
  34802. var sign = this.decodeSignBit(i, j, index);
  34803. coefficentsSign[index] = sign;
  34804. coefficentsMagnitude[index] = 1;
  34805. this.setNeighborsSignificance(i, j, index);
  34806. processingFlags[index] |= firstMagnitudeBitMask;
  34807. }
  34808. bitsDecoded[index]++;
  34809. processingFlags[index] |= processedMask;
  34810. }
  34811. }
  34812. }
  34813. },
  34814. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  34815. var width = this.width, height = this.height;
  34816. var coefficentsMagnitude = this.coefficentsMagnitude;
  34817. var coefficentsSign = this.coefficentsSign;
  34818. var contribution, sign0, sign1, significance1;
  34819. var contextLabel, decoded;
  34820. // calculate horizontal contribution
  34821. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  34822. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  34823. sign1 = coefficentsSign[index + 1];
  34824. if (significance1) {
  34825. sign0 = coefficentsSign[index - 1];
  34826. contribution = 1 - sign1 - sign0;
  34827. } else {
  34828. contribution = 1 - sign1 - sign1;
  34829. }
  34830. } else if (significance1) {
  34831. sign0 = coefficentsSign[index - 1];
  34832. contribution = 1 - sign0 - sign0;
  34833. } else {
  34834. contribution = 0;
  34835. }
  34836. var horizontalContribution = 3 * contribution;
  34837. // calculate vertical contribution and combine with the horizontal
  34838. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  34839. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  34840. sign1 = coefficentsSign[index + width];
  34841. if (significance1) {
  34842. sign0 = coefficentsSign[index - width];
  34843. contribution = 1 - sign1 - sign0 + horizontalContribution;
  34844. } else {
  34845. contribution = 1 - sign1 - sign1 + horizontalContribution;
  34846. }
  34847. } else if (significance1) {
  34848. sign0 = coefficentsSign[index - width];
  34849. contribution = 1 - sign0 - sign0 + horizontalContribution;
  34850. } else {
  34851. contribution = horizontalContribution;
  34852. }
  34853. if (contribution >= 0) {
  34854. contextLabel = 9 + contribution;
  34855. decoded = this.decoder.readBit(this.contexts, contextLabel);
  34856. } else {
  34857. contextLabel = 9 - contribution;
  34858. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  34859. }
  34860. return decoded;
  34861. },
  34862. runMagnitudeRefinementPass:
  34863. function BitModel_runMagnitudeRefinementPass() {
  34864. var decoder = this.decoder;
  34865. var width = this.width, height = this.height;
  34866. var coefficentsMagnitude = this.coefficentsMagnitude;
  34867. var neighborsSignificance = this.neighborsSignificance;
  34868. var contexts = this.contexts;
  34869. var bitsDecoded = this.bitsDecoded;
  34870. var processingFlags = this.processingFlags;
  34871. var processedMask = 1;
  34872. var firstMagnitudeBitMask = 2;
  34873. var length = width * height;
  34874. var width4 = width * 4;
  34875. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  34876. indexNext = Math.min(length, index0 + width4);
  34877. for (var j = 0; j < width; j++) {
  34878. for (var index = index0 + j; index < indexNext; index += width) {
  34879. // significant but not those that have just become
  34880. if (!coefficentsMagnitude[index] ||
  34881. (processingFlags[index] & processedMask) !== 0) {
  34882. continue;
  34883. }
  34884. var contextLabel = 16;
  34885. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  34886. processingFlags[index] ^= firstMagnitudeBitMask;
  34887. // first refinement
  34888. var significance = neighborsSignificance[index] & 127;
  34889. contextLabel = significance === 0 ? 15 : 14;
  34890. }
  34891. var bit = decoder.readBit(contexts, contextLabel);
  34892. coefficentsMagnitude[index] =
  34893. (coefficentsMagnitude[index] << 1) | bit;
  34894. bitsDecoded[index]++;
  34895. processingFlags[index] |= processedMask;
  34896. }
  34897. }
  34898. }
  34899. },
  34900. runCleanupPass: function BitModel_runCleanupPass() {
  34901. var decoder = this.decoder;
  34902. var width = this.width, height = this.height;
  34903. var neighborsSignificance = this.neighborsSignificance;
  34904. var coefficentsMagnitude = this.coefficentsMagnitude;
  34905. var coefficentsSign = this.coefficentsSign;
  34906. var contexts = this.contexts;
  34907. var labels = this.contextLabelTable;
  34908. var bitsDecoded = this.bitsDecoded;
  34909. var processingFlags = this.processingFlags;
  34910. var processedMask = 1;
  34911. var firstMagnitudeBitMask = 2;
  34912. var oneRowDown = width;
  34913. var twoRowsDown = width * 2;
  34914. var threeRowsDown = width * 3;
  34915. var iNext;
  34916. for (var i0 = 0; i0 < height; i0 = iNext) {
  34917. iNext = Math.min(i0 + 4, height);
  34918. var indexBase = i0 * width;
  34919. var checkAllEmpty = i0 + 3 < height;
  34920. for (var j = 0; j < width; j++) {
  34921. var index0 = indexBase + j;
  34922. // using the property: labels[neighborsSignificance[index]] === 0
  34923. // when neighborsSignificance[index] === 0
  34924. var allEmpty = (checkAllEmpty &&
  34925. processingFlags[index0] === 0 &&
  34926. processingFlags[index0 + oneRowDown] === 0 &&
  34927. processingFlags[index0 + twoRowsDown] === 0 &&
  34928. processingFlags[index0 + threeRowsDown] === 0 &&
  34929. neighborsSignificance[index0] === 0 &&
  34930. neighborsSignificance[index0 + oneRowDown] === 0 &&
  34931. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  34932. neighborsSignificance[index0 + threeRowsDown] === 0);
  34933. var i1 = 0, index = index0;
  34934. var i = i0, sign;
  34935. if (allEmpty) {
  34936. var hasSignificantCoefficent =
  34937. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  34938. if (!hasSignificantCoefficent) {
  34939. bitsDecoded[index0]++;
  34940. bitsDecoded[index0 + oneRowDown]++;
  34941. bitsDecoded[index0 + twoRowsDown]++;
  34942. bitsDecoded[index0 + threeRowsDown]++;
  34943. continue; // next column
  34944. }
  34945. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34946. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34947. if (i1 !== 0) {
  34948. i = i0 + i1;
  34949. index += i1 * width;
  34950. }
  34951. sign = this.decodeSignBit(i, j, index);
  34952. coefficentsSign[index] = sign;
  34953. coefficentsMagnitude[index] = 1;
  34954. this.setNeighborsSignificance(i, j, index);
  34955. processingFlags[index] |= firstMagnitudeBitMask;
  34956. index = index0;
  34957. for (var i2 = i0; i2 <= i; i2++, index += width) {
  34958. bitsDecoded[index]++;
  34959. }
  34960. i1++;
  34961. }
  34962. for (i = i0 + i1; i < iNext; i++, index += width) {
  34963. if (coefficentsMagnitude[index] ||
  34964. (processingFlags[index] & processedMask) !== 0) {
  34965. continue;
  34966. }
  34967. var contextLabel = labels[neighborsSignificance[index]];
  34968. var decision = decoder.readBit(contexts, contextLabel);
  34969. if (decision === 1) {
  34970. sign = this.decodeSignBit(i, j, index);
  34971. coefficentsSign[index] = sign;
  34972. coefficentsMagnitude[index] = 1;
  34973. this.setNeighborsSignificance(i, j, index);
  34974. processingFlags[index] |= firstMagnitudeBitMask;
  34975. }
  34976. bitsDecoded[index]++;
  34977. }
  34978. }
  34979. }
  34980. },
  34981. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  34982. var decoder = this.decoder;
  34983. var contexts = this.contexts;
  34984. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  34985. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  34986. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  34987. decoder.readBit(contexts, UNIFORM_CONTEXT);
  34988. if (symbol !== 0xA) {
  34989. throw new Error('JPX Error: Invalid segmentation symbol');
  34990. }
  34991. }
  34992. };
  34993. return BitModel;
  34994. })();
  34995. // Section F, Discrete wavelet transformation
  34996. var Transform = (function TransformClosure() {
  34997. function Transform() {}
  34998. Transform.prototype.calculate =
  34999. function transformCalculate(subbands, u0, v0) {
  35000. var ll = subbands[0];
  35001. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35002. ll = this.iterate(ll, subbands[i], u0, v0);
  35003. }
  35004. return ll;
  35005. };
  35006. Transform.prototype.extend = function extend(buffer, offset, size) {
  35007. // Section F.3.7 extending... using max extension of 4
  35008. var i1 = offset - 1, j1 = offset + 1;
  35009. var i2 = offset + size - 2, j2 = offset + size;
  35010. buffer[i1--] = buffer[j1++];
  35011. buffer[j2++] = buffer[i2--];
  35012. buffer[i1--] = buffer[j1++];
  35013. buffer[j2++] = buffer[i2--];
  35014. buffer[i1--] = buffer[j1++];
  35015. buffer[j2++] = buffer[i2--];
  35016. buffer[i1] = buffer[j1];
  35017. buffer[j2] = buffer[i2];
  35018. };
  35019. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35020. u0, v0) {
  35021. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35022. var width = hl_lh_hh.width;
  35023. var height = hl_lh_hh.height;
  35024. var items = hl_lh_hh.items;
  35025. var i, j, k, l, u, v;
  35026. // Interleave LL according to Section F.3.3
  35027. for (k = 0, i = 0; i < llHeight; i++) {
  35028. l = i * 2 * width;
  35029. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35030. items[l] = llItems[k];
  35031. }
  35032. }
  35033. // The LL band is not needed anymore.
  35034. llItems = ll.items = null;
  35035. var bufferPadding = 4;
  35036. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35037. // Section F.3.4 HOR_SR
  35038. if (width === 1) {
  35039. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35040. if ((u0 & 1) !== 0) {
  35041. for (v = 0, k = 0; v < height; v++, k += width) {
  35042. items[k] *= 0.5;
  35043. }
  35044. }
  35045. } else {
  35046. for (v = 0, k = 0; v < height; v++, k += width) {
  35047. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35048. this.extend(rowBuffer, bufferPadding, width);
  35049. this.filter(rowBuffer, bufferPadding, width);
  35050. items.set(
  35051. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35052. k);
  35053. }
  35054. }
  35055. // Accesses to the items array can take long, because it may not fit into
  35056. // CPU cache and has to be fetched from main memory. Since subsequent
  35057. // accesses to the items array are not local when reading columns, we
  35058. // have a cache miss every time. To reduce cache misses, get up to
  35059. // 'numBuffers' items at a time and store them into the individual
  35060. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35061. var numBuffers = 16;
  35062. var colBuffers = [];
  35063. for (i = 0; i < numBuffers; i++) {
  35064. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35065. }
  35066. var b, currentBuffer = 0;
  35067. ll = bufferPadding + height;
  35068. // Section F.3.5 VER_SR
  35069. if (height === 1) {
  35070. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35071. if ((v0 & 1) !== 0) {
  35072. for (u = 0; u < width; u++) {
  35073. items[u] *= 0.5;
  35074. }
  35075. }
  35076. } else {
  35077. for (u = 0; u < width; u++) {
  35078. // if we ran out of buffers, copy several image columns at once
  35079. if (currentBuffer === 0) {
  35080. numBuffers = Math.min(width - u, numBuffers);
  35081. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35082. for (b = 0; b < numBuffers; b++) {
  35083. colBuffers[b][l] = items[k + b];
  35084. }
  35085. }
  35086. currentBuffer = numBuffers;
  35087. }
  35088. currentBuffer--;
  35089. var buffer = colBuffers[currentBuffer];
  35090. this.extend(buffer, bufferPadding, height);
  35091. this.filter(buffer, bufferPadding, height);
  35092. // If this is last buffer in this group of buffers, flush all buffers.
  35093. if (currentBuffer === 0) {
  35094. k = u - numBuffers + 1;
  35095. for (l = bufferPadding; l < ll; k += width, l++) {
  35096. for (b = 0; b < numBuffers; b++) {
  35097. items[k + b] = colBuffers[b][l];
  35098. }
  35099. }
  35100. }
  35101. }
  35102. }
  35103. return {
  35104. width: width,
  35105. height: height,
  35106. items: items
  35107. };
  35108. };
  35109. return Transform;
  35110. })();
  35111. // Section 3.8.2 Irreversible 9-7 filter
  35112. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35113. function IrreversibleTransform() {
  35114. Transform.call(this);
  35115. }
  35116. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35117. IrreversibleTransform.prototype.filter =
  35118. function irreversibleTransformFilter(x, offset, length) {
  35119. var len = length >> 1;
  35120. offset = offset | 0;
  35121. var j, n, current, next;
  35122. var alpha = -1.586134342059924;
  35123. var beta = -0.052980118572961;
  35124. var gamma = 0.882911075530934;
  35125. var delta = 0.443506852043971;
  35126. var K = 1.230174104914001;
  35127. var K_ = 1 / K;
  35128. // step 1 is combined with step 3
  35129. // step 2
  35130. j = offset - 3;
  35131. for (n = len + 4; n--; j += 2) {
  35132. x[j] *= K_;
  35133. }
  35134. // step 1 & 3
  35135. j = offset - 2;
  35136. current = delta * x[j -1];
  35137. for (n = len + 3; n--; j += 2) {
  35138. next = delta * x[j + 1];
  35139. x[j] = K * x[j] - current - next;
  35140. if (n--) {
  35141. j += 2;
  35142. current = delta * x[j + 1];
  35143. x[j] = K * x[j] - current - next;
  35144. } else {
  35145. break;
  35146. }
  35147. }
  35148. // step 4
  35149. j = offset - 1;
  35150. current = gamma * x[j - 1];
  35151. for (n = len + 2; n--; j += 2) {
  35152. next = gamma * x[j + 1];
  35153. x[j] -= current + next;
  35154. if (n--) {
  35155. j += 2;
  35156. current = gamma * x[j + 1];
  35157. x[j] -= current + next;
  35158. } else {
  35159. break;
  35160. }
  35161. }
  35162. // step 5
  35163. j = offset;
  35164. current = beta * x[j - 1];
  35165. for (n = len + 1; n--; j += 2) {
  35166. next = beta * x[j + 1];
  35167. x[j] -= current + next;
  35168. if (n--) {
  35169. j += 2;
  35170. current = beta * x[j + 1];
  35171. x[j] -= current + next;
  35172. } else {
  35173. break;
  35174. }
  35175. }
  35176. // step 6
  35177. if (len !== 0) {
  35178. j = offset + 1;
  35179. current = alpha * x[j - 1];
  35180. for (n = len; n--; j += 2) {
  35181. next = alpha * x[j + 1];
  35182. x[j] -= current + next;
  35183. if (n--) {
  35184. j += 2;
  35185. current = alpha * x[j + 1];
  35186. x[j] -= current + next;
  35187. } else {
  35188. break;
  35189. }
  35190. }
  35191. }
  35192. };
  35193. return IrreversibleTransform;
  35194. })();
  35195. // Section 3.8.1 Reversible 5-3 filter
  35196. var ReversibleTransform = (function ReversibleTransformClosure() {
  35197. function ReversibleTransform() {
  35198. Transform.call(this);
  35199. }
  35200. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35201. ReversibleTransform.prototype.filter =
  35202. function reversibleTransformFilter(x, offset, length) {
  35203. var len = length >> 1;
  35204. offset = offset | 0;
  35205. var j, n;
  35206. for (j = offset, n = len + 1; n--; j += 2) {
  35207. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35208. }
  35209. for (j = offset + 1, n = len; n--; j += 2) {
  35210. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35211. }
  35212. };
  35213. return ReversibleTransform;
  35214. })();
  35215. return JpxImage;
  35216. })();
  35217. var Jbig2Image = (function Jbig2ImageClosure() {
  35218. // Utility data structures
  35219. function ContextCache() {}
  35220. ContextCache.prototype = {
  35221. getContexts: function(id) {
  35222. if (id in this) {
  35223. return this[id];
  35224. }
  35225. return (this[id] = new Int8Array(1 << 16));
  35226. }
  35227. };
  35228. function DecodingContext(data, start, end) {
  35229. this.data = data;
  35230. this.start = start;
  35231. this.end = end;
  35232. }
  35233. DecodingContext.prototype = {
  35234. get decoder() {
  35235. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35236. return shadow(this, 'decoder', decoder);
  35237. },
  35238. get contextCache() {
  35239. var cache = new ContextCache();
  35240. return shadow(this, 'contextCache', cache);
  35241. }
  35242. };
  35243. // Annex A. Arithmetic Integer Decoding Procedure
  35244. // A.2 Procedure for decoding values
  35245. function decodeInteger(contextCache, procedure, decoder) {
  35246. var contexts = contextCache.getContexts(procedure);
  35247. var prev = 1;
  35248. function readBits(length) {
  35249. var v = 0;
  35250. for (var i = 0; i < length; i++) {
  35251. var bit = decoder.readBit(contexts, prev);
  35252. prev = (prev < 256 ? (prev << 1) | bit :
  35253. (((prev << 1) | bit) & 511) | 256);
  35254. v = (v << 1) | bit;
  35255. }
  35256. return v >>> 0;
  35257. }
  35258. var sign = readBits(1);
  35259. var value = readBits(1) ?
  35260. (readBits(1) ?
  35261. (readBits(1) ?
  35262. (readBits(1) ?
  35263. (readBits(1) ?
  35264. (readBits(32) + 4436) :
  35265. readBits(12) + 340) :
  35266. readBits(8) + 84) :
  35267. readBits(6) + 20) :
  35268. readBits(4) + 4) :
  35269. readBits(2);
  35270. return (sign === 0 ? value : (value > 0 ? -value : null));
  35271. }
  35272. // A.3 The IAID decoding procedure
  35273. function decodeIAID(contextCache, decoder, codeLength) {
  35274. var contexts = contextCache.getContexts('IAID');
  35275. var prev = 1;
  35276. for (var i = 0; i < codeLength; i++) {
  35277. var bit = decoder.readBit(contexts, prev);
  35278. prev = (prev << 1) | bit;
  35279. }
  35280. if (codeLength < 31) {
  35281. return prev & ((1 << codeLength) - 1);
  35282. }
  35283. return prev & 0x7FFFFFFF;
  35284. }
  35285. // 7.3 Segment types
  35286. var SegmentTypes = [
  35287. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35288. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35289. null, null, null, null, null, 'patternDictionary', null, null, null,
  35290. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35291. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35292. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35293. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35294. 'IntermediateGenericRefinementRegion', null,
  35295. 'ImmediateGenericRefinementRegion',
  35296. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35297. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35298. 'Tables', null, null, null, null, null, null, null, null,
  35299. 'Extension'
  35300. ];
  35301. var CodingTemplates = [
  35302. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35303. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35304. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35305. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35306. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35307. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35308. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35309. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35310. {x: -1, y: 0}],
  35311. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35312. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35313. ];
  35314. var RefinementTemplates = [
  35315. {
  35316. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35317. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35318. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35319. },
  35320. {
  35321. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35322. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35323. {x: 0, y: 1}, {x: 1, y: 1}]
  35324. }
  35325. ];
  35326. // See 6.2.5.7 Decoding the bitmap.
  35327. var ReusedContexts = [
  35328. 0x9B25, // 10011 0110010 0101
  35329. 0x0795, // 0011 110010 101
  35330. 0x00E5, // 001 11001 01
  35331. 0x0195 // 011001 0101
  35332. ];
  35333. var RefinementReusedContexts = [
  35334. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35335. 0x0008 // '0000' + '001000'
  35336. ];
  35337. function decodeBitmapTemplate0(width, height, decodingContext) {
  35338. var decoder = decodingContext.decoder;
  35339. var contexts = decodingContext.contextCache.getContexts('GB');
  35340. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35341. // ...ooooo....
  35342. // ..ooooooo... Context template for current pixel (X)
  35343. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35344. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35345. for (i = 0; i < height; i++) {
  35346. row = bitmap[i] = new Uint8Array(width);
  35347. row1 = (i < 1) ? row : bitmap[i - 1];
  35348. row2 = (i < 2) ? row : bitmap[i - 2];
  35349. // At the beginning of each row:
  35350. // Fill contextLabel with pixels that are above/right of (X)
  35351. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35352. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35353. (row1[3] << 4);
  35354. for (j = 0; j < width; j++) {
  35355. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35356. // At each pixel: Clear contextLabel pixels that are shifted
  35357. // out of the context, then add new ones.
  35358. // If j + n is out of range at the right image border, then
  35359. // the undefined value of bitmap[i - 2][j + n] is shifted to 0
  35360. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35361. (row2[j + 3] << 11) | (row1[j + 4] << 4) | pixel;
  35362. }
  35363. }
  35364. return bitmap;
  35365. }
  35366. // 6.2 Generic Region Decoding Procedure
  35367. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35368. decodingContext) {
  35369. if (mmr) {
  35370. error('JBIG2 error: MMR encoding is not supported');
  35371. }
  35372. // Use optimized version for the most common case
  35373. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35374. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35375. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35376. return decodeBitmapTemplate0(width, height, decodingContext);
  35377. }
  35378. var useskip = !!skip;
  35379. var template = CodingTemplates[templateIndex].concat(at);
  35380. // Sorting is non-standard, and it is not required. But sorting increases
  35381. // the number of template bits that can be reused from the previous
  35382. // contextLabel in the main loop.
  35383. template.sort(function (a, b) {
  35384. return (a.y - b.y) || (a.x - b.x);
  35385. });
  35386. var templateLength = template.length;
  35387. var templateX = new Int8Array(templateLength);
  35388. var templateY = new Int8Array(templateLength);
  35389. var changingTemplateEntries = [];
  35390. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35391. var c, k;
  35392. for (k = 0; k < templateLength; k++) {
  35393. templateX[k] = template[k].x;
  35394. templateY[k] = template[k].y;
  35395. minX = Math.min(minX, template[k].x);
  35396. maxX = Math.max(maxX, template[k].x);
  35397. minY = Math.min(minY, template[k].y);
  35398. // Check if the template pixel appears in two consecutive context labels,
  35399. // so it can be reused. Otherwise, we add it to the list of changing
  35400. // template entries.
  35401. if (k < templateLength - 1 &&
  35402. template[k].y === template[k + 1].y &&
  35403. template[k].x === template[k + 1].x - 1) {
  35404. reuseMask |= 1 << (templateLength - 1 - k);
  35405. } else {
  35406. changingTemplateEntries.push(k);
  35407. }
  35408. }
  35409. var changingEntriesLength = changingTemplateEntries.length;
  35410. var changingTemplateX = new Int8Array(changingEntriesLength);
  35411. var changingTemplateY = new Int8Array(changingEntriesLength);
  35412. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35413. for (c = 0; c < changingEntriesLength; c++) {
  35414. k = changingTemplateEntries[c];
  35415. changingTemplateX[c] = template[k].x;
  35416. changingTemplateY[c] = template[k].y;
  35417. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35418. }
  35419. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35420. var sbb_left = -minX;
  35421. var sbb_top = -minY;
  35422. var sbb_right = width - maxX;
  35423. var pseudoPixelContext = ReusedContexts[templateIndex];
  35424. var row = new Uint8Array(width);
  35425. var bitmap = [];
  35426. var decoder = decodingContext.decoder;
  35427. var contexts = decodingContext.contextCache.getContexts('GB');
  35428. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35429. for (var i = 0; i < height; i++) {
  35430. if (prediction) {
  35431. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35432. ltp ^= sltp;
  35433. if (ltp) {
  35434. bitmap.push(row); // duplicate previous row
  35435. continue;
  35436. }
  35437. }
  35438. row = new Uint8Array(row);
  35439. bitmap.push(row);
  35440. for (j = 0; j < width; j++) {
  35441. if (useskip && skip[i][j]) {
  35442. row[j] = 0;
  35443. continue;
  35444. }
  35445. // Are we in the middle of a scanline, so we can reuse contextLabel
  35446. // bits?
  35447. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35448. // If yes, we can just shift the bits that are reusable and only
  35449. // fetch the remaining ones.
  35450. contextLabel = (contextLabel << 1) & reuseMask;
  35451. for (k = 0; k < changingEntriesLength; k++) {
  35452. i0 = i + changingTemplateY[k];
  35453. j0 = j + changingTemplateX[k];
  35454. bit = bitmap[i0][j0];
  35455. if (bit) {
  35456. bit = changingTemplateBit[k];
  35457. contextLabel |= bit;
  35458. }
  35459. }
  35460. } else {
  35461. // compute the contextLabel from scratch
  35462. contextLabel = 0;
  35463. shift = templateLength - 1;
  35464. for (k = 0; k < templateLength; k++, shift--) {
  35465. j0 = j + templateX[k];
  35466. if (j0 >= 0 && j0 < width) {
  35467. i0 = i + templateY[k];
  35468. if (i0 >= 0) {
  35469. bit = bitmap[i0][j0];
  35470. if (bit) {
  35471. contextLabel |= bit << shift;
  35472. }
  35473. }
  35474. }
  35475. }
  35476. }
  35477. var pixel = decoder.readBit(contexts, contextLabel);
  35478. row[j] = pixel;
  35479. }
  35480. }
  35481. return bitmap;
  35482. }
  35483. // 6.3.2 Generic Refinement Region Decoding Procedure
  35484. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35485. offsetX, offsetY, prediction, at,
  35486. decodingContext) {
  35487. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35488. if (templateIndex === 0) {
  35489. codingTemplate = codingTemplate.concat([at[0]]);
  35490. }
  35491. var codingTemplateLength = codingTemplate.length;
  35492. var codingTemplateX = new Int32Array(codingTemplateLength);
  35493. var codingTemplateY = new Int32Array(codingTemplateLength);
  35494. var k;
  35495. for (k = 0; k < codingTemplateLength; k++) {
  35496. codingTemplateX[k] = codingTemplate[k].x;
  35497. codingTemplateY[k] = codingTemplate[k].y;
  35498. }
  35499. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35500. if (templateIndex === 0) {
  35501. referenceTemplate = referenceTemplate.concat([at[1]]);
  35502. }
  35503. var referenceTemplateLength = referenceTemplate.length;
  35504. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35505. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35506. for (k = 0; k < referenceTemplateLength; k++) {
  35507. referenceTemplateX[k] = referenceTemplate[k].x;
  35508. referenceTemplateY[k] = referenceTemplate[k].y;
  35509. }
  35510. var referenceWidth = referenceBitmap[0].length;
  35511. var referenceHeight = referenceBitmap.length;
  35512. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35513. var bitmap = [];
  35514. var decoder = decodingContext.decoder;
  35515. var contexts = decodingContext.contextCache.getContexts('GR');
  35516. var ltp = 0;
  35517. for (var i = 0; i < height; i++) {
  35518. if (prediction) {
  35519. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35520. ltp ^= sltp;
  35521. if (ltp) {
  35522. error('JBIG2 error: prediction is not supported');
  35523. }
  35524. }
  35525. var row = new Uint8Array(width);
  35526. bitmap.push(row);
  35527. for (var j = 0; j < width; j++) {
  35528. var i0, j0;
  35529. var contextLabel = 0;
  35530. for (k = 0; k < codingTemplateLength; k++) {
  35531. i0 = i + codingTemplateY[k];
  35532. j0 = j + codingTemplateX[k];
  35533. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35534. contextLabel <<= 1; // out of bound pixel
  35535. } else {
  35536. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35537. }
  35538. }
  35539. for (k = 0; k < referenceTemplateLength; k++) {
  35540. i0 = i + referenceTemplateY[k] + offsetY;
  35541. j0 = j + referenceTemplateX[k] + offsetX;
  35542. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35543. j0 >= referenceWidth) {
  35544. contextLabel <<= 1; // out of bound pixel
  35545. } else {
  35546. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35547. }
  35548. }
  35549. var pixel = decoder.readBit(contexts, contextLabel);
  35550. row[j] = pixel;
  35551. }
  35552. }
  35553. return bitmap;
  35554. }
  35555. // 6.5.5 Decoding the symbol dictionary
  35556. function decodeSymbolDictionary(huffman, refinement, symbols,
  35557. numberOfNewSymbols, numberOfExportedSymbols,
  35558. huffmanTables, templateIndex, at,
  35559. refinementTemplateIndex, refinementAt,
  35560. decodingContext) {
  35561. if (huffman) {
  35562. error('JBIG2 error: huffman is not supported');
  35563. }
  35564. var newSymbols = [];
  35565. var currentHeight = 0;
  35566. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35567. var decoder = decodingContext.decoder;
  35568. var contextCache = decodingContext.contextCache;
  35569. while (newSymbols.length < numberOfNewSymbols) {
  35570. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35571. currentHeight += deltaHeight;
  35572. var currentWidth = 0;
  35573. var totalWidth = 0;
  35574. while (true) {
  35575. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35576. if (deltaWidth === null) {
  35577. break; // OOB
  35578. }
  35579. currentWidth += deltaWidth;
  35580. totalWidth += currentWidth;
  35581. var bitmap;
  35582. if (refinement) {
  35583. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35584. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35585. if (numberOfInstances > 1) {
  35586. bitmap = decodeTextRegion(huffman, refinement,
  35587. currentWidth, currentHeight, 0,
  35588. numberOfInstances, 1, //strip size
  35589. symbols.concat(newSymbols),
  35590. symbolCodeLength,
  35591. 0, //transposed
  35592. 0, //ds offset
  35593. 1, //top left 7.4.3.1.1
  35594. 0, //OR operator
  35595. huffmanTables,
  35596. refinementTemplateIndex, refinementAt,
  35597. decodingContext);
  35598. } else {
  35599. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35600. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35601. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35602. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35603. newSymbols[symbolId - symbols.length]);
  35604. bitmap = decodeRefinement(currentWidth, currentHeight,
  35605. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35606. decodingContext);
  35607. }
  35608. } else {
  35609. // 6.5.8.1 Direct-coded symbol bitmap
  35610. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35611. templateIndex, false, null, at, decodingContext);
  35612. }
  35613. newSymbols.push(bitmap);
  35614. }
  35615. }
  35616. // 6.5.10 Exported symbols
  35617. var exportedSymbols = [];
  35618. var flags = [], currentFlag = false;
  35619. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35620. while (flags.length < totalSymbolsLength) {
  35621. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35622. while (runLength--) {
  35623. flags.push(currentFlag);
  35624. }
  35625. currentFlag = !currentFlag;
  35626. }
  35627. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35628. if (flags[i]) {
  35629. exportedSymbols.push(symbols[i]);
  35630. }
  35631. }
  35632. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35633. if (flags[i]) {
  35634. exportedSymbols.push(newSymbols[j]);
  35635. }
  35636. }
  35637. return exportedSymbols;
  35638. }
  35639. function decodeTextRegion(huffman, refinement, width, height,
  35640. defaultPixelValue, numberOfSymbolInstances,
  35641. stripSize, inputSymbols, symbolCodeLength,
  35642. transposed, dsOffset, referenceCorner,
  35643. combinationOperator, huffmanTables,
  35644. refinementTemplateIndex, refinementAt,
  35645. decodingContext) {
  35646. if (huffman) {
  35647. error('JBIG2 error: huffman is not supported');
  35648. }
  35649. // Prepare bitmap
  35650. var bitmap = [];
  35651. var i, row;
  35652. for (i = 0; i < height; i++) {
  35653. row = new Uint8Array(width);
  35654. if (defaultPixelValue) {
  35655. for (var j = 0; j < width; j++) {
  35656. row[j] = defaultPixelValue;
  35657. }
  35658. }
  35659. bitmap.push(row);
  35660. }
  35661. var decoder = decodingContext.decoder;
  35662. var contextCache = decodingContext.contextCache;
  35663. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35664. var firstS = 0;
  35665. i = 0;
  35666. while (i < numberOfSymbolInstances) {
  35667. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  35668. stripT += deltaT;
  35669. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  35670. firstS += deltaFirstS;
  35671. var currentS = firstS;
  35672. do {
  35673. var currentT = (stripSize === 1 ? 0 :
  35674. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  35675. var t = stripSize * stripT + currentT;
  35676. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35677. var applyRefinement = (refinement &&
  35678. decodeInteger(contextCache, 'IARI', decoder));
  35679. var symbolBitmap = inputSymbols[symbolId];
  35680. var symbolWidth = symbolBitmap[0].length;
  35681. var symbolHeight = symbolBitmap.length;
  35682. if (applyRefinement) {
  35683. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  35684. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  35685. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35686. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35687. symbolWidth += rdw;
  35688. symbolHeight += rdh;
  35689. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  35690. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  35691. (rdh >> 1) + rdy, false, refinementAt,
  35692. decodingContext);
  35693. }
  35694. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  35695. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  35696. var s2, t2, symbolRow;
  35697. if (transposed) {
  35698. // Place Symbol Bitmap from T1,S1
  35699. for (s2 = 0; s2 < symbolHeight; s2++) {
  35700. row = bitmap[offsetS + s2];
  35701. if (!row) {
  35702. continue;
  35703. }
  35704. symbolRow = symbolBitmap[s2];
  35705. // To ignore Parts of Symbol bitmap which goes
  35706. // outside bitmap region
  35707. var maxWidth = Math.min(width - offsetT, symbolWidth);
  35708. switch (combinationOperator) {
  35709. case 0: // OR
  35710. for (t2 = 0; t2 < maxWidth; t2++) {
  35711. row[offsetT + t2] |= symbolRow[t2];
  35712. }
  35713. break;
  35714. case 2: // XOR
  35715. for (t2 = 0; t2 < maxWidth; t2++) {
  35716. row[offsetT + t2] ^= symbolRow[t2];
  35717. }
  35718. break;
  35719. default:
  35720. error('JBIG2 error: operator ' + combinationOperator +
  35721. ' is not supported');
  35722. }
  35723. }
  35724. currentS += symbolHeight - 1;
  35725. } else {
  35726. for (t2 = 0; t2 < symbolHeight; t2++) {
  35727. row = bitmap[offsetT + t2];
  35728. if (!row) {
  35729. continue;
  35730. }
  35731. symbolRow = symbolBitmap[t2];
  35732. switch (combinationOperator) {
  35733. case 0: // OR
  35734. for (s2 = 0; s2 < symbolWidth; s2++) {
  35735. row[offsetS + s2] |= symbolRow[s2];
  35736. }
  35737. break;
  35738. case 2: // XOR
  35739. for (s2 = 0; s2 < symbolWidth; s2++) {
  35740. row[offsetS + s2] ^= symbolRow[s2];
  35741. }
  35742. break;
  35743. default:
  35744. error('JBIG2 error: operator ' + combinationOperator +
  35745. ' is not supported');
  35746. }
  35747. }
  35748. currentS += symbolWidth - 1;
  35749. }
  35750. i++;
  35751. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  35752. if (deltaS === null) {
  35753. break; // OOB
  35754. }
  35755. currentS += deltaS + dsOffset;
  35756. } while (true);
  35757. }
  35758. return bitmap;
  35759. }
  35760. function readSegmentHeader(data, start) {
  35761. var segmentHeader = {};
  35762. segmentHeader.number = readUint32(data, start);
  35763. var flags = data[start + 4];
  35764. var segmentType = flags & 0x3F;
  35765. if (!SegmentTypes[segmentType]) {
  35766. error('JBIG2 error: invalid segment type: ' + segmentType);
  35767. }
  35768. segmentHeader.type = segmentType;
  35769. segmentHeader.typeName = SegmentTypes[segmentType];
  35770. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  35771. var pageAssociationFieldSize = !!(flags & 0x40);
  35772. var referredFlags = data[start + 5];
  35773. var referredToCount = (referredFlags >> 5) & 7;
  35774. var retainBits = [referredFlags & 31];
  35775. var position = start + 6;
  35776. if (referredFlags === 7) {
  35777. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  35778. position += 3;
  35779. var bytes = (referredToCount + 7) >> 3;
  35780. retainBits[0] = data[position++];
  35781. while (--bytes > 0) {
  35782. retainBits.push(data[position++]);
  35783. }
  35784. } else if (referredFlags === 5 || referredFlags === 6) {
  35785. error('JBIG2 error: invalid referred-to flags');
  35786. }
  35787. segmentHeader.retainBits = retainBits;
  35788. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  35789. (segmentHeader.number <= 65536 ? 2 : 4));
  35790. var referredTo = [];
  35791. var i, ii;
  35792. for (i = 0; i < referredToCount; i++) {
  35793. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  35794. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  35795. readUint32(data, position)));
  35796. referredTo.push(number);
  35797. position += referredToSegmentNumberSize;
  35798. }
  35799. segmentHeader.referredTo = referredTo;
  35800. if (!pageAssociationFieldSize) {
  35801. segmentHeader.pageAssociation = data[position++];
  35802. } else {
  35803. segmentHeader.pageAssociation = readUint32(data, position);
  35804. position += 4;
  35805. }
  35806. segmentHeader.length = readUint32(data, position);
  35807. position += 4;
  35808. if (segmentHeader.length === 0xFFFFFFFF) {
  35809. // 7.2.7 Segment data length, unknown segment length
  35810. if (segmentType === 38) { // ImmediateGenericRegion
  35811. var genericRegionInfo = readRegionSegmentInformation(data, position);
  35812. var genericRegionSegmentFlags = data[position +
  35813. RegionSegmentInformationFieldLength];
  35814. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  35815. // searching for the segment end
  35816. var searchPatternLength = 6;
  35817. var searchPattern = new Uint8Array(searchPatternLength);
  35818. if (!genericRegionMmr) {
  35819. searchPattern[0] = 0xFF;
  35820. searchPattern[1] = 0xAC;
  35821. }
  35822. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  35823. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  35824. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  35825. searchPattern[5] = genericRegionInfo.height & 0xFF;
  35826. for (i = position, ii = data.length; i < ii; i++) {
  35827. var j = 0;
  35828. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  35829. j++;
  35830. }
  35831. if (j === searchPatternLength) {
  35832. segmentHeader.length = i + searchPatternLength;
  35833. break;
  35834. }
  35835. }
  35836. if (segmentHeader.length === 0xFFFFFFFF) {
  35837. error('JBIG2 error: segment end was not found');
  35838. }
  35839. } else {
  35840. error('JBIG2 error: invalid unknown segment length');
  35841. }
  35842. }
  35843. segmentHeader.headerEnd = position;
  35844. return segmentHeader;
  35845. }
  35846. function readSegments(header, data, start, end) {
  35847. var segments = [];
  35848. var position = start;
  35849. while (position < end) {
  35850. var segmentHeader = readSegmentHeader(data, position);
  35851. position = segmentHeader.headerEnd;
  35852. var segment = {
  35853. header: segmentHeader,
  35854. data: data
  35855. };
  35856. if (!header.randomAccess) {
  35857. segment.start = position;
  35858. position += segmentHeader.length;
  35859. segment.end = position;
  35860. }
  35861. segments.push(segment);
  35862. if (segmentHeader.type === 51) {
  35863. break; // end of file is found
  35864. }
  35865. }
  35866. if (header.randomAccess) {
  35867. for (var i = 0, ii = segments.length; i < ii; i++) {
  35868. segments[i].start = position;
  35869. position += segments[i].header.length;
  35870. segments[i].end = position;
  35871. }
  35872. }
  35873. return segments;
  35874. }
  35875. // 7.4.1 Region segment information field
  35876. function readRegionSegmentInformation(data, start) {
  35877. return {
  35878. width: readUint32(data, start),
  35879. height: readUint32(data, start + 4),
  35880. x: readUint32(data, start + 8),
  35881. y: readUint32(data, start + 12),
  35882. combinationOperator: data[start + 16] & 7
  35883. };
  35884. }
  35885. var RegionSegmentInformationFieldLength = 17;
  35886. function processSegment(segment, visitor) {
  35887. var header = segment.header;
  35888. var data = segment.data, position = segment.start, end = segment.end;
  35889. var args, at, i, atLength;
  35890. switch (header.type) {
  35891. case 0: // SymbolDictionary
  35892. // 7.4.2 Symbol dictionary segment syntax
  35893. var dictionary = {};
  35894. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  35895. dictionary.huffman = !!(dictionaryFlags & 1);
  35896. dictionary.refinement = !!(dictionaryFlags & 2);
  35897. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  35898. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  35899. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  35900. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  35901. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  35902. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  35903. dictionary.template = (dictionaryFlags >> 10) & 3;
  35904. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  35905. position += 2;
  35906. if (!dictionary.huffman) {
  35907. atLength = dictionary.template === 0 ? 4 : 1;
  35908. at = [];
  35909. for (i = 0; i < atLength; i++) {
  35910. at.push({
  35911. x: readInt8(data, position),
  35912. y: readInt8(data, position + 1)
  35913. });
  35914. position += 2;
  35915. }
  35916. dictionary.at = at;
  35917. }
  35918. if (dictionary.refinement && !dictionary.refinementTemplate) {
  35919. at = [];
  35920. for (i = 0; i < 2; i++) {
  35921. at.push({
  35922. x: readInt8(data, position),
  35923. y: readInt8(data, position + 1)
  35924. });
  35925. position += 2;
  35926. }
  35927. dictionary.refinementAt = at;
  35928. }
  35929. dictionary.numberOfExportedSymbols = readUint32(data, position);
  35930. position += 4;
  35931. dictionary.numberOfNewSymbols = readUint32(data, position);
  35932. position += 4;
  35933. args = [dictionary, header.number, header.referredTo,
  35934. data, position, end];
  35935. break;
  35936. case 6: // ImmediateTextRegion
  35937. case 7: // ImmediateLosslessTextRegion
  35938. var textRegion = {};
  35939. textRegion.info = readRegionSegmentInformation(data, position);
  35940. position += RegionSegmentInformationFieldLength;
  35941. var textRegionSegmentFlags = readUint16(data, position);
  35942. position += 2;
  35943. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  35944. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  35945. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  35946. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  35947. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  35948. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  35949. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  35950. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  35951. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  35952. if (textRegion.huffman) {
  35953. var textRegionHuffmanFlags = readUint16(data, position);
  35954. position += 2;
  35955. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  35956. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  35957. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  35958. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  35959. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  35960. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  35961. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  35962. textRegion.huffmanRefinementSizeSelector =
  35963. !!(textRegionHuffmanFlags & 14);
  35964. }
  35965. if (textRegion.refinement && !textRegion.refinementTemplate) {
  35966. at = [];
  35967. for (i = 0; i < 2; i++) {
  35968. at.push({
  35969. x: readInt8(data, position),
  35970. y: readInt8(data, position + 1)
  35971. });
  35972. position += 2;
  35973. }
  35974. textRegion.refinementAt = at;
  35975. }
  35976. textRegion.numberOfSymbolInstances = readUint32(data, position);
  35977. position += 4;
  35978. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  35979. if (textRegion.huffman) {
  35980. error('JBIG2 error: huffman is not supported');
  35981. }
  35982. args = [textRegion, header.referredTo, data, position, end];
  35983. break;
  35984. case 38: // ImmediateGenericRegion
  35985. case 39: // ImmediateLosslessGenericRegion
  35986. var genericRegion = {};
  35987. genericRegion.info = readRegionSegmentInformation(data, position);
  35988. position += RegionSegmentInformationFieldLength;
  35989. var genericRegionSegmentFlags = data[position++];
  35990. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  35991. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  35992. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  35993. if (!genericRegion.mmr) {
  35994. atLength = genericRegion.template === 0 ? 4 : 1;
  35995. at = [];
  35996. for (i = 0; i < atLength; i++) {
  35997. at.push({
  35998. x: readInt8(data, position),
  35999. y: readInt8(data, position + 1)
  36000. });
  36001. position += 2;
  36002. }
  36003. genericRegion.at = at;
  36004. }
  36005. args = [genericRegion, data, position, end];
  36006. break;
  36007. case 48: // PageInformation
  36008. var pageInfo = {
  36009. width: readUint32(data, position),
  36010. height: readUint32(data, position + 4),
  36011. resolutionX: readUint32(data, position + 8),
  36012. resolutionY: readUint32(data, position + 12)
  36013. };
  36014. if (pageInfo.height === 0xFFFFFFFF) {
  36015. delete pageInfo.height;
  36016. }
  36017. var pageSegmentFlags = data[position + 16];
  36018. var pageStripingInformatiom = readUint16(data, position + 17);
  36019. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36020. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36021. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36022. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36023. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36024. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36025. args = [pageInfo];
  36026. break;
  36027. case 49: // EndOfPage
  36028. break;
  36029. case 50: // EndOfStripe
  36030. break;
  36031. case 51: // EndOfFile
  36032. break;
  36033. case 62: // 7.4.15 defines 2 extension types which
  36034. // are comments and can be ignored.
  36035. break;
  36036. default:
  36037. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36038. header.type + ') is not implemented');
  36039. }
  36040. var callbackName = 'on' + header.typeName;
  36041. if (callbackName in visitor) {
  36042. visitor[callbackName].apply(visitor, args);
  36043. }
  36044. }
  36045. function processSegments(segments, visitor) {
  36046. for (var i = 0, ii = segments.length; i < ii; i++) {
  36047. processSegment(segments[i], visitor);
  36048. }
  36049. }
  36050. function parseJbig2(data, start, end) {
  36051. var position = start;
  36052. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36053. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36054. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36055. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36056. error('JBIG2 error: invalid header');
  36057. }
  36058. var header = {};
  36059. position += 8;
  36060. var flags = data[position++];
  36061. header.randomAccess = !(flags & 1);
  36062. if (!(flags & 2)) {
  36063. header.numberOfPages = readUint32(data, position);
  36064. position += 4;
  36065. }
  36066. var segments = readSegments(header, data, position, end);
  36067. error('Not implemented');
  36068. // processSegments(segments, new SimpleSegmentVisitor());
  36069. }
  36070. function parseJbig2Chunks(chunks) {
  36071. var visitor = new SimpleSegmentVisitor();
  36072. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36073. var chunk = chunks[i];
  36074. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36075. processSegments(segments, visitor);
  36076. }
  36077. return visitor.buffer;
  36078. }
  36079. function SimpleSegmentVisitor() {}
  36080. SimpleSegmentVisitor.prototype = {
  36081. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36082. this.currentPageInfo = info;
  36083. var rowSize = (info.width + 7) >> 3;
  36084. var buffer = new Uint8Array(rowSize * info.height);
  36085. // The contents of ArrayBuffers are initialized to 0.
  36086. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36087. if (info.defaultPixelValue) {
  36088. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36089. buffer[i] = 0xFF;
  36090. }
  36091. }
  36092. this.buffer = buffer;
  36093. },
  36094. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36095. var pageInfo = this.currentPageInfo;
  36096. var width = regionInfo.width, height = regionInfo.height;
  36097. var rowSize = (pageInfo.width + 7) >> 3;
  36098. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36099. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36100. var buffer = this.buffer;
  36101. var mask0 = 128 >> (regionInfo.x & 7);
  36102. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36103. var i, j, mask, offset;
  36104. switch (combinationOperator) {
  36105. case 0: // OR
  36106. for (i = 0; i < height; i++) {
  36107. mask = mask0;
  36108. offset = offset0;
  36109. for (j = 0; j < width; j++) {
  36110. if (bitmap[i][j]) {
  36111. buffer[offset] |= mask;
  36112. }
  36113. mask >>= 1;
  36114. if (!mask) {
  36115. mask = 128;
  36116. offset++;
  36117. }
  36118. }
  36119. offset0 += rowSize;
  36120. }
  36121. break;
  36122. case 2: // XOR
  36123. for (i = 0; i < height; i++) {
  36124. mask = mask0;
  36125. offset = offset0;
  36126. for (j = 0; j < width; j++) {
  36127. if (bitmap[i][j]) {
  36128. buffer[offset] ^= mask;
  36129. }
  36130. mask >>= 1;
  36131. if (!mask) {
  36132. mask = 128;
  36133. offset++;
  36134. }
  36135. }
  36136. offset0 += rowSize;
  36137. }
  36138. break;
  36139. default:
  36140. error('JBIG2 error: operator ' + combinationOperator +
  36141. ' is not supported');
  36142. }
  36143. },
  36144. onImmediateGenericRegion:
  36145. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36146. start, end) {
  36147. var regionInfo = region.info;
  36148. var decodingContext = new DecodingContext(data, start, end);
  36149. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36150. region.template, region.prediction, null,
  36151. region.at, decodingContext);
  36152. this.drawBitmap(regionInfo, bitmap);
  36153. },
  36154. onImmediateLosslessGenericRegion:
  36155. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36156. this.onImmediateGenericRegion.apply(this, arguments);
  36157. },
  36158. onSymbolDictionary:
  36159. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36160. currentSegment,
  36161. referredSegments,
  36162. data, start, end) {
  36163. var huffmanTables;
  36164. if (dictionary.huffman) {
  36165. error('JBIG2 error: huffman is not supported');
  36166. }
  36167. // Combines exported symbols from all referred segments
  36168. var symbols = this.symbols;
  36169. if (!symbols) {
  36170. this.symbols = symbols = {};
  36171. }
  36172. var inputSymbols = [];
  36173. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36174. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36175. }
  36176. var decodingContext = new DecodingContext(data, start, end);
  36177. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36178. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36179. dictionary.numberOfExportedSymbols, huffmanTables,
  36180. dictionary.template, dictionary.at,
  36181. dictionary.refinementTemplate, dictionary.refinementAt,
  36182. decodingContext);
  36183. },
  36184. onImmediateTextRegion:
  36185. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36186. referredSegments,
  36187. data, start, end) {
  36188. var regionInfo = region.info;
  36189. var huffmanTables;
  36190. // Combines exported symbols from all referred segments
  36191. var symbols = this.symbols;
  36192. var inputSymbols = [];
  36193. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36194. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36195. }
  36196. var symbolCodeLength = log2(inputSymbols.length);
  36197. var decodingContext = new DecodingContext(data, start, end);
  36198. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36199. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36200. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36201. symbolCodeLength, region.transposed, region.dsOffset,
  36202. region.referenceCorner, region.combinationOperator, huffmanTables,
  36203. region.refinementTemplate, region.refinementAt, decodingContext);
  36204. this.drawBitmap(regionInfo, bitmap);
  36205. },
  36206. onImmediateLosslessTextRegion:
  36207. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36208. this.onImmediateTextRegion.apply(this, arguments);
  36209. }
  36210. };
  36211. function Jbig2Image() {}
  36212. Jbig2Image.prototype = {
  36213. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36214. return parseJbig2Chunks(chunks);
  36215. }
  36216. };
  36217. return Jbig2Image;
  36218. })();
  36219. var bidi = PDFJS.bidi = (function bidiClosure() {
  36220. // Character types for symbols from 0000 to 00FF.
  36221. var baseTypes = [
  36222. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36223. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36224. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36225. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36226. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36227. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36228. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36229. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36230. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36231. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36232. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36233. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36234. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36235. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36236. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36237. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36238. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36239. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36240. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36241. ];
  36242. // Character types for symbols from 0600 to 06FF
  36243. var arabicTypes = [
  36244. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36245. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36247. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36248. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36249. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36250. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36251. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36252. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36253. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36254. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36255. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36256. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36257. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36258. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36259. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36260. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36261. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36262. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36263. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36264. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36265. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36266. ];
  36267. function isOdd(i) {
  36268. return (i & 1) !== 0;
  36269. }
  36270. function isEven(i) {
  36271. return (i & 1) === 0;
  36272. }
  36273. function findUnequal(arr, start, value) {
  36274. for (var j = start, jj = arr.length; j < jj; ++j) {
  36275. if (arr[j] !== value) {
  36276. return j;
  36277. }
  36278. }
  36279. return j;
  36280. }
  36281. function setValues(arr, start, end, value) {
  36282. for (var j = start; j < end; ++j) {
  36283. arr[j] = value;
  36284. }
  36285. }
  36286. function reverseValues(arr, start, end) {
  36287. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36288. var temp = arr[i];
  36289. arr[i] = arr[j];
  36290. arr[j] = temp;
  36291. }
  36292. }
  36293. function createBidiText(str, isLTR, vertical) {
  36294. return {
  36295. str: str,
  36296. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36297. };
  36298. }
  36299. // These are used in bidi(), which is called frequently. We re-use them on
  36300. // each call to avoid unnecessary allocations.
  36301. var chars = [];
  36302. var types = [];
  36303. function bidi(str, startLevel, vertical) {
  36304. var isLTR = true;
  36305. var strLength = str.length;
  36306. if (strLength === 0 || vertical) {
  36307. return createBidiText(str, isLTR, vertical);
  36308. }
  36309. // Get types and fill arrays
  36310. chars.length = strLength;
  36311. types.length = strLength;
  36312. var numBidi = 0;
  36313. var i, ii;
  36314. for (i = 0; i < strLength; ++i) {
  36315. chars[i] = str.charAt(i);
  36316. var charCode = str.charCodeAt(i);
  36317. var charType = 'L';
  36318. if (charCode <= 0x00ff) {
  36319. charType = baseTypes[charCode];
  36320. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36321. charType = 'R';
  36322. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36323. charType = arabicTypes[charCode & 0xff];
  36324. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36325. charType = 'AL';
  36326. }
  36327. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36328. numBidi++;
  36329. }
  36330. types[i] = charType;
  36331. }
  36332. // Detect the bidi method
  36333. // - If there are no rtl characters then no bidi needed
  36334. // - If less than 30% chars are rtl then string is primarily ltr
  36335. // - If more than 30% chars are rtl then string is primarily rtl
  36336. if (numBidi === 0) {
  36337. isLTR = true;
  36338. return createBidiText(str, isLTR);
  36339. }
  36340. if (startLevel === -1) {
  36341. if ((strLength / numBidi) < 0.3) {
  36342. isLTR = true;
  36343. startLevel = 0;
  36344. } else {
  36345. isLTR = false;
  36346. startLevel = 1;
  36347. }
  36348. }
  36349. var levels = [];
  36350. for (i = 0; i < strLength; ++i) {
  36351. levels[i] = startLevel;
  36352. }
  36353. /*
  36354. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36355. */
  36356. var e = (isOdd(startLevel) ? 'R' : 'L');
  36357. var sor = e;
  36358. var eor = sor;
  36359. /*
  36360. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36361. type of the NSM to the type of the previous character. If the NSM is at the
  36362. start of the level run, it will get the type of sor.
  36363. */
  36364. var lastType = sor;
  36365. for (i = 0; i < strLength; ++i) {
  36366. if (types[i] === 'NSM') {
  36367. types[i] = lastType;
  36368. } else {
  36369. lastType = types[i];
  36370. }
  36371. }
  36372. /*
  36373. W2. Search backwards from each instance of a European number until the
  36374. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36375. the type of the European number to Arabic number.
  36376. */
  36377. lastType = sor;
  36378. var t;
  36379. for (i = 0; i < strLength; ++i) {
  36380. t = types[i];
  36381. if (t === 'EN') {
  36382. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36383. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36384. lastType = t;
  36385. }
  36386. }
  36387. /*
  36388. W3. Change all ALs to R.
  36389. */
  36390. for (i = 0; i < strLength; ++i) {
  36391. t = types[i];
  36392. if (t === 'AL') {
  36393. types[i] = 'R';
  36394. }
  36395. }
  36396. /*
  36397. W4. A single European separator between two European numbers changes to a
  36398. European number. A single common separator between two numbers of the same
  36399. type changes to that type:
  36400. */
  36401. for (i = 1; i < strLength - 1; ++i) {
  36402. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36403. types[i] = 'EN';
  36404. }
  36405. if (types[i] === 'CS' &&
  36406. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36407. types[i + 1] === types[i - 1]) {
  36408. types[i] = types[i - 1];
  36409. }
  36410. }
  36411. /*
  36412. W5. A sequence of European terminators adjacent to European numbers changes
  36413. to all European numbers:
  36414. */
  36415. for (i = 0; i < strLength; ++i) {
  36416. if (types[i] === 'EN') {
  36417. // do before
  36418. var j;
  36419. for (j = i - 1; j >= 0; --j) {
  36420. if (types[j] !== 'ET') {
  36421. break;
  36422. }
  36423. types[j] = 'EN';
  36424. }
  36425. // do after
  36426. for (j = i + 1; j < strLength; --j) {
  36427. if (types[j] !== 'ET') {
  36428. break;
  36429. }
  36430. types[j] = 'EN';
  36431. }
  36432. }
  36433. }
  36434. /*
  36435. W6. Otherwise, separators and terminators change to Other Neutral:
  36436. */
  36437. for (i = 0; i < strLength; ++i) {
  36438. t = types[i];
  36439. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36440. types[i] = 'ON';
  36441. }
  36442. }
  36443. /*
  36444. W7. Search backwards from each instance of a European number until the
  36445. first strong type (R, L, or sor) is found. If an L is found, then change
  36446. the type of the European number to L.
  36447. */
  36448. lastType = sor;
  36449. for (i = 0; i < strLength; ++i) {
  36450. t = types[i];
  36451. if (t === 'EN') {
  36452. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36453. } else if (t === 'R' || t === 'L') {
  36454. lastType = t;
  36455. }
  36456. }
  36457. /*
  36458. N1. A sequence of neutrals takes the direction of the surrounding strong
  36459. text if the text on both sides has the same direction. European and Arabic
  36460. numbers are treated as though they were R. Start-of-level-run (sor) and
  36461. end-of-level-run (eor) are used at level run boundaries.
  36462. */
  36463. for (i = 0; i < strLength; ++i) {
  36464. if (types[i] === 'ON') {
  36465. var end = findUnequal(types, i + 1, 'ON');
  36466. var before = sor;
  36467. if (i > 0) {
  36468. before = types[i - 1];
  36469. }
  36470. var after = eor;
  36471. if (end + 1 < strLength) {
  36472. after = types[end + 1];
  36473. }
  36474. if (before !== 'L') {
  36475. before = 'R';
  36476. }
  36477. if (after !== 'L') {
  36478. after = 'R';
  36479. }
  36480. if (before === after) {
  36481. setValues(types, i, end, before);
  36482. }
  36483. i = end - 1; // reset to end (-1 so next iteration is ok)
  36484. }
  36485. }
  36486. /*
  36487. N2. Any remaining neutrals take the embedding direction.
  36488. */
  36489. for (i = 0; i < strLength; ++i) {
  36490. if (types[i] === 'ON') {
  36491. types[i] = e;
  36492. }
  36493. }
  36494. /*
  36495. I1. For all characters with an even (left-to-right) embedding direction,
  36496. those of type R go up one level and those of type AN or EN go up two
  36497. levels.
  36498. I2. For all characters with an odd (right-to-left) embedding direction,
  36499. those of type L, EN or AN go up one level.
  36500. */
  36501. for (i = 0; i < strLength; ++i) {
  36502. t = types[i];
  36503. if (isEven(levels[i])) {
  36504. if (t === 'R') {
  36505. levels[i] += 1;
  36506. } else if (t === 'AN' || t === 'EN') {
  36507. levels[i] += 2;
  36508. }
  36509. } else { // isOdd
  36510. if (t === 'L' || t === 'AN' || t === 'EN') {
  36511. levels[i] += 1;
  36512. }
  36513. }
  36514. }
  36515. /*
  36516. L1. On each line, reset the embedding level of the following characters to
  36517. the paragraph embedding level:
  36518. segment separators,
  36519. paragraph separators,
  36520. any sequence of whitespace characters preceding a segment separator or
  36521. paragraph separator, and any sequence of white space characters at the end
  36522. of the line.
  36523. */
  36524. // don't bother as text is only single line
  36525. /*
  36526. L2. From the highest level found in the text to the lowest odd level on
  36527. each line, reverse any contiguous sequence of characters that are at that
  36528. level or higher.
  36529. */
  36530. // find highest level & lowest odd level
  36531. var highestLevel = -1;
  36532. var lowestOddLevel = 99;
  36533. var level;
  36534. for (i = 0, ii = levels.length; i < ii; ++i) {
  36535. level = levels[i];
  36536. if (highestLevel < level) {
  36537. highestLevel = level;
  36538. }
  36539. if (lowestOddLevel > level && isOdd(level)) {
  36540. lowestOddLevel = level;
  36541. }
  36542. }
  36543. // now reverse between those limits
  36544. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36545. // find segments to reverse
  36546. var start = -1;
  36547. for (i = 0, ii = levels.length; i < ii; ++i) {
  36548. if (levels[i] < level) {
  36549. if (start >= 0) {
  36550. reverseValues(chars, start, i);
  36551. start = -1;
  36552. }
  36553. } else if (start < 0) {
  36554. start = i;
  36555. }
  36556. }
  36557. if (start >= 0) {
  36558. reverseValues(chars, start, levels.length);
  36559. }
  36560. }
  36561. /*
  36562. L3. Combining marks applied to a right-to-left base character will at this
  36563. point precede their base character. If the rendering engine expects them to
  36564. follow the base characters in the final display process, then the ordering
  36565. of the marks and the base character must be reversed.
  36566. */
  36567. // don't bother for now
  36568. /*
  36569. L4. A character that possesses the mirrored property as specified by
  36570. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36571. directionality of that character is R.
  36572. */
  36573. // don't mirror as characters are already mirrored in the pdf
  36574. // Finally, return string
  36575. var result = '';
  36576. for (i = 0, ii = chars.length; i < ii; ++i) {
  36577. var ch = chars[i];
  36578. if (ch !== '<' && ch !== '>') {
  36579. result += ch;
  36580. }
  36581. }
  36582. return createBidiText(result, isLTR);
  36583. }
  36584. return bidi;
  36585. })();
  36586. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36587. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36588. /* Copyright 2014 Opera Software ASA
  36589. *
  36590. * Licensed under the Apache License, Version 2.0 (the "License");
  36591. * you may not use this file except in compliance with the License.
  36592. * You may obtain a copy of the License at
  36593. *
  36594. * http://www.apache.org/licenses/LICENSE-2.0
  36595. *
  36596. * Unless required by applicable law or agreed to in writing, software
  36597. * distributed under the License is distributed on an "AS IS" BASIS,
  36598. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36599. * See the License for the specific language governing permissions and
  36600. * limitations under the License.
  36601. *
  36602. *
  36603. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36604. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36605. */
  36606. /* globals Uint32ArrayView */
  36607. 'use strict';
  36608. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36609. // Workaround for missing math precison in JS.
  36610. var MASK_HIGH = 0xffff0000;
  36611. var MASK_LOW = 0xffff;
  36612. function MurmurHash3_64 (seed) {
  36613. var SEED = 0xc3d2e1f0;
  36614. this.h1 = seed ? seed & 0xffffffff : SEED;
  36615. this.h2 = seed ? seed & 0xffffffff : SEED;
  36616. }
  36617. var alwaysUseUint32ArrayView = false;
  36618. // old webkits have issues with non-aligned arrays
  36619. try {
  36620. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36621. } catch (e) {
  36622. alwaysUseUint32ArrayView = true;
  36623. }
  36624. MurmurHash3_64.prototype = {
  36625. update: function MurmurHash3_64_update(input) {
  36626. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36627. var i;
  36628. if (typeof input === 'string') {
  36629. var data = new Uint8Array(input.length * 2);
  36630. var length = 0;
  36631. for (i = 0; i < input.length; i++) {
  36632. var code = input.charCodeAt(i);
  36633. if (code <= 0xff) {
  36634. data[length++] = code;
  36635. }
  36636. else {
  36637. data[length++] = code >>> 8;
  36638. data[length++] = code & 0xff;
  36639. }
  36640. }
  36641. } else if (input instanceof Uint8Array) {
  36642. data = input;
  36643. length = data.length;
  36644. } else if (typeof input === 'object' && ('length' in input)) {
  36645. // processing regular arrays as well, e.g. for IE9
  36646. data = input;
  36647. length = data.length;
  36648. useUint32ArrayView = true;
  36649. } else {
  36650. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  36651. 'Input must be a string or array.');
  36652. }
  36653. var blockCounts = length >> 2;
  36654. var tailLength = length - blockCounts * 4;
  36655. // we don't care about endianness here
  36656. var dataUint32 = useUint32ArrayView ?
  36657. new Uint32ArrayView(data, blockCounts) :
  36658. new Uint32Array(data.buffer, 0, blockCounts);
  36659. var k1 = 0;
  36660. var k2 = 0;
  36661. var h1 = this.h1;
  36662. var h2 = this.h2;
  36663. var C1 = 0xcc9e2d51;
  36664. var C2 = 0x1b873593;
  36665. var C1_LOW = C1 & MASK_LOW;
  36666. var C2_LOW = C2 & MASK_LOW;
  36667. for (i = 0; i < blockCounts; i++) {
  36668. if (i & 1) {
  36669. k1 = dataUint32[i];
  36670. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36671. k1 = k1 << 15 | k1 >>> 17;
  36672. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36673. h1 ^= k1;
  36674. h1 = h1 << 13 | h1 >>> 19;
  36675. h1 = h1 * 5 + 0xe6546b64;
  36676. } else {
  36677. k2 = dataUint32[i];
  36678. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  36679. k2 = k2 << 15 | k2 >>> 17;
  36680. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  36681. h2 ^= k2;
  36682. h2 = h2 << 13 | h2 >>> 19;
  36683. h2 = h2 * 5 + 0xe6546b64;
  36684. }
  36685. }
  36686. k1 = 0;
  36687. switch (tailLength) {
  36688. case 3:
  36689. k1 ^= data[blockCounts * 4 + 2] << 16;
  36690. /* falls through */
  36691. case 2:
  36692. k1 ^= data[blockCounts * 4 + 1] << 8;
  36693. /* falls through */
  36694. case 1:
  36695. k1 ^= data[blockCounts * 4];
  36696. /* falls through */
  36697. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  36698. k1 = k1 << 15 | k1 >>> 17;
  36699. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  36700. if (blockCounts & 1) {
  36701. h1 ^= k1;
  36702. } else {
  36703. h2 ^= k1;
  36704. }
  36705. }
  36706. this.h1 = h1;
  36707. this.h2 = h2;
  36708. return this;
  36709. },
  36710. hexdigest: function MurmurHash3_64_hexdigest () {
  36711. var h1 = this.h1;
  36712. var h2 = this.h2;
  36713. h1 ^= h2 >>> 1;
  36714. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  36715. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  36716. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  36717. h1 ^= h2 >>> 1;
  36718. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  36719. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  36720. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  36721. h1 ^= h2 >>> 1;
  36722. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  36723. var hex = (arr[i] >>> 0).toString(16);
  36724. while (hex.length < 8) {
  36725. hex = '0' + hex;
  36726. }
  36727. str += hex;
  36728. }
  36729. return str;
  36730. }
  36731. };
  36732. return MurmurHash3_64;
  36733. })();
  36734. }).call((typeof window === 'undefined') ? this : window);
  36735. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  36736. // workerSrc is not set -- using last script url to define default location
  36737. PDFJS.workerSrc = (function () {
  36738. 'use strict';
  36739. var scriptTagContainer = document.body ||
  36740. document.getElementsByTagName('head')[0];
  36741. var pdfjsSrc = scriptTagContainer.lastChild.src;
  36742. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  36743. })();
  36744. }