pdf.worker.js 1.2 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.1.238';
  24. PDFJS.build = '98339f6';
  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 AnnotationBorderStyleType = {
  73. SOLID: 1,
  74. DASHED: 2,
  75. BEVELED: 3,
  76. INSET: 4,
  77. UNDERLINE: 5
  78. };
  79. var StreamType = {
  80. UNKNOWN: 0,
  81. FLATE: 1,
  82. LZW: 2,
  83. DCT: 3,
  84. JPX: 4,
  85. JBIG: 5,
  86. A85: 6,
  87. AHX: 7,
  88. CCF: 8,
  89. RL: 9
  90. };
  91. var FontType = {
  92. UNKNOWN: 0,
  93. TYPE1: 1,
  94. TYPE1C: 2,
  95. CIDFONTTYPE0: 3,
  96. CIDFONTTYPE0C: 4,
  97. TRUETYPE: 5,
  98. CIDFONTTYPE2: 6,
  99. TYPE3: 7,
  100. OPENTYPE: 8,
  101. TYPE0: 9,
  102. MMTYPE1: 10
  103. };
  104. // The global PDFJS object exposes the API
  105. // In production, it will be declared outside a global wrapper
  106. // In development, it will be declared here
  107. if (!globalScope.PDFJS) {
  108. globalScope.PDFJS = {};
  109. }
  110. globalScope.PDFJS.pdfBug = false;
  111. PDFJS.VERBOSITY_LEVELS = {
  112. errors: 0,
  113. warnings: 1,
  114. infos: 5
  115. };
  116. // All the possible operations for an operator list.
  117. var OPS = PDFJS.OPS = {
  118. // Intentionally start from 1 so it is easy to spot bad operators that will be
  119. // 0's.
  120. dependency: 1,
  121. setLineWidth: 2,
  122. setLineCap: 3,
  123. setLineJoin: 4,
  124. setMiterLimit: 5,
  125. setDash: 6,
  126. setRenderingIntent: 7,
  127. setFlatness: 8,
  128. setGState: 9,
  129. save: 10,
  130. restore: 11,
  131. transform: 12,
  132. moveTo: 13,
  133. lineTo: 14,
  134. curveTo: 15,
  135. curveTo2: 16,
  136. curveTo3: 17,
  137. closePath: 18,
  138. rectangle: 19,
  139. stroke: 20,
  140. closeStroke: 21,
  141. fill: 22,
  142. eoFill: 23,
  143. fillStroke: 24,
  144. eoFillStroke: 25,
  145. closeFillStroke: 26,
  146. closeEOFillStroke: 27,
  147. endPath: 28,
  148. clip: 29,
  149. eoClip: 30,
  150. beginText: 31,
  151. endText: 32,
  152. setCharSpacing: 33,
  153. setWordSpacing: 34,
  154. setHScale: 35,
  155. setLeading: 36,
  156. setFont: 37,
  157. setTextRenderingMode: 38,
  158. setTextRise: 39,
  159. moveText: 40,
  160. setLeadingMoveText: 41,
  161. setTextMatrix: 42,
  162. nextLine: 43,
  163. showText: 44,
  164. showSpacedText: 45,
  165. nextLineShowText: 46,
  166. nextLineSetSpacingShowText: 47,
  167. setCharWidth: 48,
  168. setCharWidthAndBounds: 49,
  169. setStrokeColorSpace: 50,
  170. setFillColorSpace: 51,
  171. setStrokeColor: 52,
  172. setStrokeColorN: 53,
  173. setFillColor: 54,
  174. setFillColorN: 55,
  175. setStrokeGray: 56,
  176. setFillGray: 57,
  177. setStrokeRGBColor: 58,
  178. setFillRGBColor: 59,
  179. setStrokeCMYKColor: 60,
  180. setFillCMYKColor: 61,
  181. shadingFill: 62,
  182. beginInlineImage: 63,
  183. beginImageData: 64,
  184. endInlineImage: 65,
  185. paintXObject: 66,
  186. markPoint: 67,
  187. markPointProps: 68,
  188. beginMarkedContent: 69,
  189. beginMarkedContentProps: 70,
  190. endMarkedContent: 71,
  191. beginCompat: 72,
  192. endCompat: 73,
  193. paintFormXObjectBegin: 74,
  194. paintFormXObjectEnd: 75,
  195. beginGroup: 76,
  196. endGroup: 77,
  197. beginAnnotations: 78,
  198. endAnnotations: 79,
  199. beginAnnotation: 80,
  200. endAnnotation: 81,
  201. paintJpegXObject: 82,
  202. paintImageMaskXObject: 83,
  203. paintImageMaskXObjectGroup: 84,
  204. paintImageXObject: 85,
  205. paintInlineImageXObject: 86,
  206. paintInlineImageXObjectGroup: 87,
  207. paintImageXObjectRepeat: 88,
  208. paintImageMaskXObjectRepeat: 89,
  209. paintSolidColorImageMask: 90,
  210. constructPath: 91
  211. };
  212. // A notice for devs. These are good for things that are helpful to devs, such
  213. // as warning that Workers were disabled, which is important to devs but not
  214. // end users.
  215. function info(msg) {
  216. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  217. console.log('Info: ' + msg);
  218. }
  219. }
  220. // Non-fatal warnings.
  221. function warn(msg) {
  222. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  223. console.log('Warning: ' + msg);
  224. }
  225. }
  226. // Fatal errors that should trigger the fallback UI and halt execution by
  227. // throwing an exception.
  228. function error(msg) {
  229. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  230. console.log('Error: ' + msg);
  231. console.log(backtrace());
  232. }
  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. PDFJS.shadow = shadow;
  333. var PasswordResponses = PDFJS.PasswordResponses = {
  334. NEED_PASSWORD: 1,
  335. INCORRECT_PASSWORD: 2
  336. };
  337. var PasswordException = (function PasswordExceptionClosure() {
  338. function PasswordException(msg, code) {
  339. this.name = 'PasswordException';
  340. this.message = msg;
  341. this.code = code;
  342. }
  343. PasswordException.prototype = new Error();
  344. PasswordException.constructor = PasswordException;
  345. return PasswordException;
  346. })();
  347. PDFJS.PasswordException = PasswordException;
  348. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  349. function UnknownErrorException(msg, details) {
  350. this.name = 'UnknownErrorException';
  351. this.message = msg;
  352. this.details = details;
  353. }
  354. UnknownErrorException.prototype = new Error();
  355. UnknownErrorException.constructor = UnknownErrorException;
  356. return UnknownErrorException;
  357. })();
  358. PDFJS.UnknownErrorException = UnknownErrorException;
  359. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  360. function InvalidPDFException(msg) {
  361. this.name = 'InvalidPDFException';
  362. this.message = msg;
  363. }
  364. InvalidPDFException.prototype = new Error();
  365. InvalidPDFException.constructor = InvalidPDFException;
  366. return InvalidPDFException;
  367. })();
  368. PDFJS.InvalidPDFException = InvalidPDFException;
  369. var MissingPDFException = (function MissingPDFExceptionClosure() {
  370. function MissingPDFException(msg) {
  371. this.name = 'MissingPDFException';
  372. this.message = msg;
  373. }
  374. MissingPDFException.prototype = new Error();
  375. MissingPDFException.constructor = MissingPDFException;
  376. return MissingPDFException;
  377. })();
  378. PDFJS.MissingPDFException = MissingPDFException;
  379. var UnexpectedResponseException =
  380. (function UnexpectedResponseExceptionClosure() {
  381. function UnexpectedResponseException(msg, status) {
  382. this.name = 'UnexpectedResponseException';
  383. this.message = msg;
  384. this.status = status;
  385. }
  386. UnexpectedResponseException.prototype = new Error();
  387. UnexpectedResponseException.constructor = UnexpectedResponseException;
  388. return UnexpectedResponseException;
  389. })();
  390. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  391. var NotImplementedException = (function NotImplementedExceptionClosure() {
  392. function NotImplementedException(msg) {
  393. this.message = msg;
  394. }
  395. NotImplementedException.prototype = new Error();
  396. NotImplementedException.prototype.name = 'NotImplementedException';
  397. NotImplementedException.constructor = NotImplementedException;
  398. return NotImplementedException;
  399. })();
  400. var MissingDataException = (function MissingDataExceptionClosure() {
  401. function MissingDataException(begin, end) {
  402. this.begin = begin;
  403. this.end = end;
  404. this.message = 'Missing data [' + begin + ', ' + end + ')';
  405. }
  406. MissingDataException.prototype = new Error();
  407. MissingDataException.prototype.name = 'MissingDataException';
  408. MissingDataException.constructor = MissingDataException;
  409. return MissingDataException;
  410. })();
  411. var XRefParseException = (function XRefParseExceptionClosure() {
  412. function XRefParseException(msg) {
  413. this.message = msg;
  414. }
  415. XRefParseException.prototype = new Error();
  416. XRefParseException.prototype.name = 'XRefParseException';
  417. XRefParseException.constructor = XRefParseException;
  418. return XRefParseException;
  419. })();
  420. function bytesToString(bytes) {
  421. assert(bytes !== null && typeof bytes === 'object' &&
  422. bytes.length !== undefined, 'Invalid argument for bytesToString');
  423. var length = bytes.length;
  424. var MAX_ARGUMENT_COUNT = 8192;
  425. if (length < MAX_ARGUMENT_COUNT) {
  426. return String.fromCharCode.apply(null, bytes);
  427. }
  428. var strBuf = [];
  429. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  430. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  431. var chunk = bytes.subarray(i, chunkEnd);
  432. strBuf.push(String.fromCharCode.apply(null, chunk));
  433. }
  434. return strBuf.join('');
  435. }
  436. function stringToBytes(str) {
  437. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  438. var length = str.length;
  439. var bytes = new Uint8Array(length);
  440. for (var i = 0; i < length; ++i) {
  441. bytes[i] = str.charCodeAt(i) & 0xFF;
  442. }
  443. return bytes;
  444. }
  445. function string32(value) {
  446. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  447. (value >> 8) & 0xff, value & 0xff);
  448. }
  449. function log2(x) {
  450. var n = 1, i = 0;
  451. while (x > n) {
  452. n <<= 1;
  453. i++;
  454. }
  455. return i;
  456. }
  457. function readInt8(data, start) {
  458. return (data[start] << 24) >> 24;
  459. }
  460. function readUint16(data, offset) {
  461. return (data[offset] << 8) | data[offset + 1];
  462. }
  463. function readUint32(data, offset) {
  464. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  465. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  466. }
  467. // Lazy test the endianness of the platform
  468. // NOTE: This will be 'true' for simulated TypedArrays
  469. function isLittleEndian() {
  470. var buffer8 = new Uint8Array(2);
  471. buffer8[0] = 1;
  472. var buffer16 = new Uint16Array(buffer8.buffer);
  473. return (buffer16[0] === 1);
  474. }
  475. Object.defineProperty(PDFJS, 'isLittleEndian', {
  476. configurable: true,
  477. get: function PDFJS_isLittleEndian() {
  478. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  479. }
  480. });
  481. // Lazy test if the userAgent support CanvasTypedArrays
  482. function hasCanvasTypedArrays() {
  483. var canvas = document.createElement('canvas');
  484. canvas.width = canvas.height = 1;
  485. var ctx = canvas.getContext('2d');
  486. var imageData = ctx.createImageData(1, 1);
  487. return (typeof imageData.data.buffer !== 'undefined');
  488. }
  489. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  490. configurable: true,
  491. get: function PDFJS_hasCanvasTypedArrays() {
  492. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  493. }
  494. });
  495. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  496. function Uint32ArrayView(buffer, length) {
  497. this.buffer = buffer;
  498. this.byteLength = buffer.length;
  499. this.length = length === undefined ? (this.byteLength >> 2) : length;
  500. ensureUint32ArrayViewProps(this.length);
  501. }
  502. Uint32ArrayView.prototype = Object.create(null);
  503. var uint32ArrayViewSetters = 0;
  504. function createUint32ArrayProp(index) {
  505. return {
  506. get: function () {
  507. var buffer = this.buffer, offset = index << 2;
  508. return (buffer[offset] | (buffer[offset + 1] << 8) |
  509. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  510. },
  511. set: function (value) {
  512. var buffer = this.buffer, offset = index << 2;
  513. buffer[offset] = value & 255;
  514. buffer[offset + 1] = (value >> 8) & 255;
  515. buffer[offset + 2] = (value >> 16) & 255;
  516. buffer[offset + 3] = (value >>> 24) & 255;
  517. }
  518. };
  519. }
  520. function ensureUint32ArrayViewProps(length) {
  521. while (uint32ArrayViewSetters < length) {
  522. Object.defineProperty(Uint32ArrayView.prototype,
  523. uint32ArrayViewSetters,
  524. createUint32ArrayProp(uint32ArrayViewSetters));
  525. uint32ArrayViewSetters++;
  526. }
  527. }
  528. return Uint32ArrayView;
  529. })();
  530. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  531. var Util = PDFJS.Util = (function UtilClosure() {
  532. function Util() {}
  533. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  534. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  535. // creating many intermediate strings.
  536. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  537. rgbBuf[1] = r;
  538. rgbBuf[3] = g;
  539. rgbBuf[5] = b;
  540. return rgbBuf.join('');
  541. };
  542. // Concatenates two transformation matrices together and returns the result.
  543. Util.transform = function Util_transform(m1, m2) {
  544. return [
  545. m1[0] * m2[0] + m1[2] * m2[1],
  546. m1[1] * m2[0] + m1[3] * m2[1],
  547. m1[0] * m2[2] + m1[2] * m2[3],
  548. m1[1] * m2[2] + m1[3] * m2[3],
  549. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  550. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  551. ];
  552. };
  553. // For 2d affine transforms
  554. Util.applyTransform = function Util_applyTransform(p, m) {
  555. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  556. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  557. return [xt, yt];
  558. };
  559. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  560. var d = m[0] * m[3] - m[1] * m[2];
  561. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  562. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  563. return [xt, yt];
  564. };
  565. // Applies the transform to the rectangle and finds the minimum axially
  566. // aligned bounding box.
  567. Util.getAxialAlignedBoundingBox =
  568. function Util_getAxialAlignedBoundingBox(r, m) {
  569. var p1 = Util.applyTransform(r, m);
  570. var p2 = Util.applyTransform(r.slice(2, 4), m);
  571. var p3 = Util.applyTransform([r[0], r[3]], m);
  572. var p4 = Util.applyTransform([r[2], r[1]], m);
  573. return [
  574. Math.min(p1[0], p2[0], p3[0], p4[0]),
  575. Math.min(p1[1], p2[1], p3[1], p4[1]),
  576. Math.max(p1[0], p2[0], p3[0], p4[0]),
  577. Math.max(p1[1], p2[1], p3[1], p4[1])
  578. ];
  579. };
  580. Util.inverseTransform = function Util_inverseTransform(m) {
  581. var d = m[0] * m[3] - m[1] * m[2];
  582. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  583. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  584. };
  585. // Apply a generic 3d matrix M on a 3-vector v:
  586. // | a b c | | X |
  587. // | d e f | x | Y |
  588. // | g h i | | Z |
  589. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  590. // with v as [X,Y,Z]
  591. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  592. return [
  593. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  594. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  595. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  596. ];
  597. };
  598. // This calculation uses Singular Value Decomposition.
  599. // The SVD can be represented with formula A = USV. We are interested in the
  600. // matrix S here because it represents the scale values.
  601. Util.singularValueDecompose2dScale =
  602. function Util_singularValueDecompose2dScale(m) {
  603. var transpose = [m[0], m[2], m[1], m[3]];
  604. // Multiply matrix m with its transpose.
  605. var a = m[0] * transpose[0] + m[1] * transpose[2];
  606. var b = m[0] * transpose[1] + m[1] * transpose[3];
  607. var c = m[2] * transpose[0] + m[3] * transpose[2];
  608. var d = m[2] * transpose[1] + m[3] * transpose[3];
  609. // Solve the second degree polynomial to get roots.
  610. var first = (a + d) / 2;
  611. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  612. var sx = first + second || 1;
  613. var sy = first - second || 1;
  614. // Scale values are the square roots of the eigenvalues.
  615. return [Math.sqrt(sx), Math.sqrt(sy)];
  616. };
  617. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  618. // For coordinate systems whose origin lies in the bottom-left, this
  619. // means normalization to (BL,TR) ordering. For systems with origin in the
  620. // top-left, this means (TL,BR) ordering.
  621. Util.normalizeRect = function Util_normalizeRect(rect) {
  622. var r = rect.slice(0); // clone rect
  623. if (rect[0] > rect[2]) {
  624. r[0] = rect[2];
  625. r[2] = rect[0];
  626. }
  627. if (rect[1] > rect[3]) {
  628. r[1] = rect[3];
  629. r[3] = rect[1];
  630. }
  631. return r;
  632. };
  633. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  634. // intersection of rect1 and rect2. If no intersection, returns 'false'
  635. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  636. Util.intersect = function Util_intersect(rect1, rect2) {
  637. function compare(a, b) {
  638. return a - b;
  639. }
  640. // Order points along the axes
  641. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  642. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  643. result = [];
  644. rect1 = Util.normalizeRect(rect1);
  645. rect2 = Util.normalizeRect(rect2);
  646. // X: first and second points belong to different rectangles?
  647. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  648. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  649. // Intersection must be between second and third points
  650. result[0] = orderedX[1];
  651. result[2] = orderedX[2];
  652. } else {
  653. return false;
  654. }
  655. // Y: first and second points belong to different rectangles?
  656. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  657. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  658. // Intersection must be between second and third points
  659. result[1] = orderedY[1];
  660. result[3] = orderedY[2];
  661. } else {
  662. return false;
  663. }
  664. return result;
  665. };
  666. Util.sign = function Util_sign(num) {
  667. return num < 0 ? -1 : 1;
  668. };
  669. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  670. Array.prototype.push.apply(arr1, arr2);
  671. };
  672. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  673. Array.prototype.unshift.apply(arr1, arr2);
  674. };
  675. Util.extendObj = function extendObj(obj1, obj2) {
  676. for (var key in obj2) {
  677. obj1[key] = obj2[key];
  678. }
  679. };
  680. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  681. name) {
  682. while (dict && !dict.has(name)) {
  683. dict = dict.get('Parent');
  684. }
  685. if (!dict) {
  686. return null;
  687. }
  688. return dict.get(name);
  689. };
  690. Util.inherit = function Util_inherit(sub, base, prototype) {
  691. sub.prototype = Object.create(base.prototype);
  692. sub.prototype.constructor = sub;
  693. for (var prop in prototype) {
  694. sub.prototype[prop] = prototype[prop];
  695. }
  696. };
  697. Util.loadScript = function Util_loadScript(src, callback) {
  698. var script = document.createElement('script');
  699. var loaded = false;
  700. script.setAttribute('src', src);
  701. if (callback) {
  702. script.onload = function() {
  703. if (!loaded) {
  704. callback();
  705. }
  706. loaded = true;
  707. };
  708. }
  709. document.getElementsByTagName('head')[0].appendChild(script);
  710. };
  711. return Util;
  712. })();
  713. /**
  714. * PDF page viewport created based on scale, rotation and offset.
  715. * @class
  716. * @alias PDFJS.PageViewport
  717. */
  718. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  719. /**
  720. * @constructor
  721. * @private
  722. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  723. * @param scale {number} scale of the viewport.
  724. * @param rotation {number} rotations of the viewport in degrees.
  725. * @param offsetX {number} offset X
  726. * @param offsetY {number} offset Y
  727. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  728. */
  729. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  730. this.viewBox = viewBox;
  731. this.scale = scale;
  732. this.rotation = rotation;
  733. this.offsetX = offsetX;
  734. this.offsetY = offsetY;
  735. // creating transform to convert pdf coordinate system to the normal
  736. // canvas like coordinates taking in account scale and rotation
  737. var centerX = (viewBox[2] + viewBox[0]) / 2;
  738. var centerY = (viewBox[3] + viewBox[1]) / 2;
  739. var rotateA, rotateB, rotateC, rotateD;
  740. rotation = rotation % 360;
  741. rotation = rotation < 0 ? rotation + 360 : rotation;
  742. switch (rotation) {
  743. case 180:
  744. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  745. break;
  746. case 90:
  747. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  748. break;
  749. case 270:
  750. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  751. break;
  752. //case 0:
  753. default:
  754. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  755. break;
  756. }
  757. if (dontFlip) {
  758. rotateC = -rotateC; rotateD = -rotateD;
  759. }
  760. var offsetCanvasX, offsetCanvasY;
  761. var width, height;
  762. if (rotateA === 0) {
  763. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  764. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  765. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  766. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  767. } else {
  768. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  769. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  770. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  771. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  772. }
  773. // creating transform for the following operations:
  774. // translate(-centerX, -centerY), rotate and flip vertically,
  775. // scale, and translate(offsetCanvasX, offsetCanvasY)
  776. this.transform = [
  777. rotateA * scale,
  778. rotateB * scale,
  779. rotateC * scale,
  780. rotateD * scale,
  781. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  782. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  783. ];
  784. this.width = width;
  785. this.height = height;
  786. this.fontScale = scale;
  787. }
  788. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  789. /**
  790. * Clones viewport with additional properties.
  791. * @param args {Object} (optional) If specified, may contain the 'scale' or
  792. * 'rotation' properties to override the corresponding properties in
  793. * the cloned viewport.
  794. * @returns {PDFJS.PageViewport} Cloned viewport.
  795. */
  796. clone: function PageViewPort_clone(args) {
  797. args = args || {};
  798. var scale = 'scale' in args ? args.scale : this.scale;
  799. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  800. return new PageViewport(this.viewBox.slice(), scale, rotation,
  801. this.offsetX, this.offsetY, args.dontFlip);
  802. },
  803. /**
  804. * Converts PDF point to the viewport coordinates. For examples, useful for
  805. * converting PDF location into canvas pixel coordinates.
  806. * @param x {number} X coordinate.
  807. * @param y {number} Y coordinate.
  808. * @returns {Object} Object that contains 'x' and 'y' properties of the
  809. * point in the viewport coordinate space.
  810. * @see {@link convertToPdfPoint}
  811. * @see {@link convertToViewportRectangle}
  812. */
  813. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  814. return Util.applyTransform([x, y], this.transform);
  815. },
  816. /**
  817. * Converts PDF rectangle to the viewport coordinates.
  818. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  819. * @returns {Array} Contains corresponding coordinates of the rectangle
  820. * in the viewport coordinate space.
  821. * @see {@link convertToViewportPoint}
  822. */
  823. convertToViewportRectangle:
  824. function PageViewport_convertToViewportRectangle(rect) {
  825. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  826. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  827. return [tl[0], tl[1], br[0], br[1]];
  828. },
  829. /**
  830. * Converts viewport coordinates to the PDF location. For examples, useful
  831. * for converting canvas pixel location into PDF one.
  832. * @param x {number} X coordinate.
  833. * @param y {number} Y coordinate.
  834. * @returns {Object} Object that contains 'x' and 'y' properties of the
  835. * point in the PDF coordinate space.
  836. * @see {@link convertToViewportPoint}
  837. */
  838. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  839. return Util.applyInverseTransform([x, y], this.transform);
  840. }
  841. };
  842. return PageViewport;
  843. })();
  844. var PDFStringTranslateTable = [
  845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  846. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  851. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  852. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  853. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  854. ];
  855. function stringToPDFString(str) {
  856. var i, n = str.length, strBuf = [];
  857. if (str[0] === '\xFE' && str[1] === '\xFF') {
  858. // UTF16BE BOM
  859. for (i = 2; i < n; i += 2) {
  860. strBuf.push(String.fromCharCode(
  861. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  862. }
  863. } else {
  864. for (i = 0; i < n; ++i) {
  865. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  866. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  867. }
  868. }
  869. return strBuf.join('');
  870. }
  871. function stringToUTF8String(str) {
  872. return decodeURIComponent(escape(str));
  873. }
  874. function utf8StringToString(str) {
  875. return unescape(encodeURIComponent(str));
  876. }
  877. function isEmptyObj(obj) {
  878. for (var key in obj) {
  879. return false;
  880. }
  881. return true;
  882. }
  883. function isBool(v) {
  884. return typeof v === 'boolean';
  885. }
  886. function isInt(v) {
  887. return typeof v === 'number' && ((v | 0) === v);
  888. }
  889. function isNum(v) {
  890. return typeof v === 'number';
  891. }
  892. function isString(v) {
  893. return typeof v === 'string';
  894. }
  895. function isName(v) {
  896. return v instanceof Name;
  897. }
  898. function isCmd(v, cmd) {
  899. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  900. }
  901. function isDict(v, type) {
  902. if (!(v instanceof Dict)) {
  903. return false;
  904. }
  905. if (!type) {
  906. return true;
  907. }
  908. var dictType = v.get('Type');
  909. return isName(dictType) && dictType.name === type;
  910. }
  911. function isArray(v) {
  912. return v instanceof Array;
  913. }
  914. function isStream(v) {
  915. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  916. }
  917. function isArrayBuffer(v) {
  918. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  919. }
  920. function isRef(v) {
  921. return v instanceof Ref;
  922. }
  923. /**
  924. * Promise Capability object.
  925. *
  926. * @typedef {Object} PromiseCapability
  927. * @property {Promise} promise - A promise object.
  928. * @property {function} resolve - Fullfills the promise.
  929. * @property {function} reject - Rejects the promise.
  930. */
  931. /**
  932. * Creates a promise capability object.
  933. * @alias PDFJS.createPromiseCapability
  934. *
  935. * @return {PromiseCapability} A capability object contains:
  936. * - a Promise, resolve and reject methods.
  937. */
  938. function createPromiseCapability() {
  939. var capability = {};
  940. capability.promise = new Promise(function (resolve, reject) {
  941. capability.resolve = resolve;
  942. capability.reject = reject;
  943. });
  944. return capability;
  945. }
  946. PDFJS.createPromiseCapability = createPromiseCapability;
  947. /**
  948. * Polyfill for Promises:
  949. * The following promise implementation tries to generally implement the
  950. * Promise/A+ spec. Some notable differences from other promise libaries are:
  951. * - There currently isn't a seperate deferred and promise object.
  952. * - Unhandled rejections eventually show an error if they aren't handled.
  953. *
  954. * Based off of the work in:
  955. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  956. */
  957. (function PromiseClosure() {
  958. if (globalScope.Promise) {
  959. // Promises existing in the DOM/Worker, checking presence of all/resolve
  960. if (typeof globalScope.Promise.all !== 'function') {
  961. globalScope.Promise.all = function (iterable) {
  962. var count = 0, results = [], resolve, reject;
  963. var promise = new globalScope.Promise(function (resolve_, reject_) {
  964. resolve = resolve_;
  965. reject = reject_;
  966. });
  967. iterable.forEach(function (p, i) {
  968. count++;
  969. p.then(function (result) {
  970. results[i] = result;
  971. count--;
  972. if (count === 0) {
  973. resolve(results);
  974. }
  975. }, reject);
  976. });
  977. if (count === 0) {
  978. resolve(results);
  979. }
  980. return promise;
  981. };
  982. }
  983. if (typeof globalScope.Promise.resolve !== 'function') {
  984. globalScope.Promise.resolve = function (value) {
  985. return new globalScope.Promise(function (resolve) { resolve(value); });
  986. };
  987. }
  988. if (typeof globalScope.Promise.reject !== 'function') {
  989. globalScope.Promise.reject = function (reason) {
  990. return new globalScope.Promise(function (resolve, reject) {
  991. reject(reason);
  992. });
  993. };
  994. }
  995. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  996. globalScope.Promise.prototype.catch = function (onReject) {
  997. return globalScope.Promise.prototype.then(undefined, onReject);
  998. };
  999. }
  1000. return;
  1001. }
  1002. var STATUS_PENDING = 0;
  1003. var STATUS_RESOLVED = 1;
  1004. var STATUS_REJECTED = 2;
  1005. // In an attempt to avoid silent exceptions, unhandled rejections are
  1006. // tracked and if they aren't handled in a certain amount of time an
  1007. // error is logged.
  1008. var REJECTION_TIMEOUT = 500;
  1009. var HandlerManager = {
  1010. handlers: [],
  1011. running: false,
  1012. unhandledRejections: [],
  1013. pendingRejectionCheck: false,
  1014. scheduleHandlers: function scheduleHandlers(promise) {
  1015. if (promise._status === STATUS_PENDING) {
  1016. return;
  1017. }
  1018. this.handlers = this.handlers.concat(promise._handlers);
  1019. promise._handlers = [];
  1020. if (this.running) {
  1021. return;
  1022. }
  1023. this.running = true;
  1024. setTimeout(this.runHandlers.bind(this), 0);
  1025. },
  1026. runHandlers: function runHandlers() {
  1027. var RUN_TIMEOUT = 1; // ms
  1028. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1029. while (this.handlers.length > 0) {
  1030. var handler = this.handlers.shift();
  1031. var nextStatus = handler.thisPromise._status;
  1032. var nextValue = handler.thisPromise._value;
  1033. try {
  1034. if (nextStatus === STATUS_RESOLVED) {
  1035. if (typeof handler.onResolve === 'function') {
  1036. nextValue = handler.onResolve(nextValue);
  1037. }
  1038. } else if (typeof handler.onReject === 'function') {
  1039. nextValue = handler.onReject(nextValue);
  1040. nextStatus = STATUS_RESOLVED;
  1041. if (handler.thisPromise._unhandledRejection) {
  1042. this.removeUnhandeledRejection(handler.thisPromise);
  1043. }
  1044. }
  1045. } catch (ex) {
  1046. nextStatus = STATUS_REJECTED;
  1047. nextValue = ex;
  1048. }
  1049. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1050. if (Date.now() >= timeoutAt) {
  1051. break;
  1052. }
  1053. }
  1054. if (this.handlers.length > 0) {
  1055. setTimeout(this.runHandlers.bind(this), 0);
  1056. return;
  1057. }
  1058. this.running = false;
  1059. },
  1060. addUnhandledRejection: function addUnhandledRejection(promise) {
  1061. this.unhandledRejections.push({
  1062. promise: promise,
  1063. time: Date.now()
  1064. });
  1065. this.scheduleRejectionCheck();
  1066. },
  1067. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1068. promise._unhandledRejection = false;
  1069. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1070. if (this.unhandledRejections[i].promise === promise) {
  1071. this.unhandledRejections.splice(i);
  1072. i--;
  1073. }
  1074. }
  1075. },
  1076. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1077. if (this.pendingRejectionCheck) {
  1078. return;
  1079. }
  1080. this.pendingRejectionCheck = true;
  1081. setTimeout(function rejectionCheck() {
  1082. this.pendingRejectionCheck = false;
  1083. var now = Date.now();
  1084. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1085. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1086. var unhandled = this.unhandledRejections[i].promise._value;
  1087. var msg = 'Unhandled rejection: ' + unhandled;
  1088. if (unhandled.stack) {
  1089. msg += '\n' + unhandled.stack;
  1090. }
  1091. warn(msg);
  1092. this.unhandledRejections.splice(i);
  1093. i--;
  1094. }
  1095. }
  1096. if (this.unhandledRejections.length) {
  1097. this.scheduleRejectionCheck();
  1098. }
  1099. }.bind(this), REJECTION_TIMEOUT);
  1100. }
  1101. };
  1102. function Promise(resolver) {
  1103. this._status = STATUS_PENDING;
  1104. this._handlers = [];
  1105. try {
  1106. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1107. } catch (e) {
  1108. this._reject(e);
  1109. }
  1110. }
  1111. /**
  1112. * Builds a promise that is resolved when all the passed in promises are
  1113. * resolved.
  1114. * @param {array} array of data and/or promises to wait for.
  1115. * @return {Promise} New dependant promise.
  1116. */
  1117. Promise.all = function Promise_all(promises) {
  1118. var resolveAll, rejectAll;
  1119. var deferred = new Promise(function (resolve, reject) {
  1120. resolveAll = resolve;
  1121. rejectAll = reject;
  1122. });
  1123. var unresolved = promises.length;
  1124. var results = [];
  1125. if (unresolved === 0) {
  1126. resolveAll(results);
  1127. return deferred;
  1128. }
  1129. function reject(reason) {
  1130. if (deferred._status === STATUS_REJECTED) {
  1131. return;
  1132. }
  1133. results = [];
  1134. rejectAll(reason);
  1135. }
  1136. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1137. var promise = promises[i];
  1138. var resolve = (function(i) {
  1139. return function(value) {
  1140. if (deferred._status === STATUS_REJECTED) {
  1141. return;
  1142. }
  1143. results[i] = value;
  1144. unresolved--;
  1145. if (unresolved === 0) {
  1146. resolveAll(results);
  1147. }
  1148. };
  1149. })(i);
  1150. if (Promise.isPromise(promise)) {
  1151. promise.then(resolve, reject);
  1152. } else {
  1153. resolve(promise);
  1154. }
  1155. }
  1156. return deferred;
  1157. };
  1158. /**
  1159. * Checks if the value is likely a promise (has a 'then' function).
  1160. * @return {boolean} true if value is thenable
  1161. */
  1162. Promise.isPromise = function Promise_isPromise(value) {
  1163. return value && typeof value.then === 'function';
  1164. };
  1165. /**
  1166. * Creates resolved promise
  1167. * @param value resolve value
  1168. * @returns {Promise}
  1169. */
  1170. Promise.resolve = function Promise_resolve(value) {
  1171. return new Promise(function (resolve) { resolve(value); });
  1172. };
  1173. /**
  1174. * Creates rejected promise
  1175. * @param reason rejection value
  1176. * @returns {Promise}
  1177. */
  1178. Promise.reject = function Promise_reject(reason) {
  1179. return new Promise(function (resolve, reject) { reject(reason); });
  1180. };
  1181. Promise.prototype = {
  1182. _status: null,
  1183. _value: null,
  1184. _handlers: null,
  1185. _unhandledRejection: null,
  1186. _updateStatus: function Promise__updateStatus(status, value) {
  1187. if (this._status === STATUS_RESOLVED ||
  1188. this._status === STATUS_REJECTED) {
  1189. return;
  1190. }
  1191. if (status === STATUS_RESOLVED &&
  1192. Promise.isPromise(value)) {
  1193. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1194. this._updateStatus.bind(this, STATUS_REJECTED));
  1195. return;
  1196. }
  1197. this._status = status;
  1198. this._value = value;
  1199. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1200. this._unhandledRejection = true;
  1201. HandlerManager.addUnhandledRejection(this);
  1202. }
  1203. HandlerManager.scheduleHandlers(this);
  1204. },
  1205. _resolve: function Promise_resolve(value) {
  1206. this._updateStatus(STATUS_RESOLVED, value);
  1207. },
  1208. _reject: function Promise_reject(reason) {
  1209. this._updateStatus(STATUS_REJECTED, reason);
  1210. },
  1211. then: function Promise_then(onResolve, onReject) {
  1212. var nextPromise = new Promise(function (resolve, reject) {
  1213. this.resolve = resolve;
  1214. this.reject = reject;
  1215. });
  1216. this._handlers.push({
  1217. thisPromise: this,
  1218. onResolve: onResolve,
  1219. onReject: onReject,
  1220. nextPromise: nextPromise
  1221. });
  1222. HandlerManager.scheduleHandlers(this);
  1223. return nextPromise;
  1224. },
  1225. catch: function Promise_catch(onReject) {
  1226. return this.then(undefined, onReject);
  1227. }
  1228. };
  1229. globalScope.Promise = Promise;
  1230. })();
  1231. var StatTimer = (function StatTimerClosure() {
  1232. function rpad(str, pad, length) {
  1233. while (str.length < length) {
  1234. str += pad;
  1235. }
  1236. return str;
  1237. }
  1238. function StatTimer() {
  1239. this.started = {};
  1240. this.times = [];
  1241. this.enabled = true;
  1242. }
  1243. StatTimer.prototype = {
  1244. time: function StatTimer_time(name) {
  1245. if (!this.enabled) {
  1246. return;
  1247. }
  1248. if (name in this.started) {
  1249. warn('Timer is already running for ' + name);
  1250. }
  1251. this.started[name] = Date.now();
  1252. },
  1253. timeEnd: function StatTimer_timeEnd(name) {
  1254. if (!this.enabled) {
  1255. return;
  1256. }
  1257. if (!(name in this.started)) {
  1258. warn('Timer has not been started for ' + name);
  1259. }
  1260. this.times.push({
  1261. 'name': name,
  1262. 'start': this.started[name],
  1263. 'end': Date.now()
  1264. });
  1265. // Remove timer from started so it can be called again.
  1266. delete this.started[name];
  1267. },
  1268. toString: function StatTimer_toString() {
  1269. var i, ii;
  1270. var times = this.times;
  1271. var out = '';
  1272. // Find the longest name for padding purposes.
  1273. var longest = 0;
  1274. for (i = 0, ii = times.length; i < ii; ++i) {
  1275. var name = times[i]['name'];
  1276. if (name.length > longest) {
  1277. longest = name.length;
  1278. }
  1279. }
  1280. for (i = 0, ii = times.length; i < ii; ++i) {
  1281. var span = times[i];
  1282. var duration = span.end - span.start;
  1283. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1284. }
  1285. return out;
  1286. }
  1287. };
  1288. return StatTimer;
  1289. })();
  1290. PDFJS.createBlob = function createBlob(data, contentType) {
  1291. if (typeof Blob !== 'undefined') {
  1292. return new Blob([data], { type: contentType });
  1293. }
  1294. // Blob builder is deprecated in FF14 and removed in FF18.
  1295. var bb = new MozBlobBuilder();
  1296. bb.append(data);
  1297. return bb.getBlob(contentType);
  1298. };
  1299. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1300. // Blob/createObjectURL is not available, falling back to data schema.
  1301. var digits =
  1302. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1303. return function createObjectURL(data, contentType) {
  1304. if (!PDFJS.disableCreateObjectURL &&
  1305. typeof URL !== 'undefined' && URL.createObjectURL) {
  1306. var blob = PDFJS.createBlob(data, contentType);
  1307. return URL.createObjectURL(blob);
  1308. }
  1309. var buffer = 'data:' + contentType + ';base64,';
  1310. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1311. var b1 = data[i] & 0xFF;
  1312. var b2 = data[i + 1] & 0xFF;
  1313. var b3 = data[i + 2] & 0xFF;
  1314. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1315. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1316. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1317. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1318. }
  1319. return buffer;
  1320. };
  1321. })();
  1322. function MessageHandler(name, comObj) {
  1323. this.name = name;
  1324. this.comObj = comObj;
  1325. this.callbackIndex = 1;
  1326. this.postMessageTransfers = true;
  1327. var callbacksCapabilities = this.callbacksCapabilities = {};
  1328. var ah = this.actionHandler = {};
  1329. ah['console_log'] = [function ahConsoleLog(data) {
  1330. console.log.apply(console, data);
  1331. }];
  1332. ah['console_error'] = [function ahConsoleError(data) {
  1333. console.error.apply(console, data);
  1334. }];
  1335. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1336. UnsupportedManager.notify(data);
  1337. }];
  1338. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1339. var data = event.data;
  1340. if (data.isReply) {
  1341. var callbackId = data.callbackId;
  1342. if (data.callbackId in callbacksCapabilities) {
  1343. var callback = callbacksCapabilities[callbackId];
  1344. delete callbacksCapabilities[callbackId];
  1345. if ('error' in data) {
  1346. callback.reject(data.error);
  1347. } else {
  1348. callback.resolve(data.data);
  1349. }
  1350. } else {
  1351. error('Cannot resolve callback ' + callbackId);
  1352. }
  1353. } else if (data.action in ah) {
  1354. var action = ah[data.action];
  1355. if (data.callbackId) {
  1356. Promise.resolve().then(function () {
  1357. return action[0].call(action[1], data.data);
  1358. }).then(function (result) {
  1359. comObj.postMessage({
  1360. isReply: true,
  1361. callbackId: data.callbackId,
  1362. data: result
  1363. });
  1364. }, function (reason) {
  1365. comObj.postMessage({
  1366. isReply: true,
  1367. callbackId: data.callbackId,
  1368. error: reason
  1369. });
  1370. });
  1371. } else {
  1372. action[0].call(action[1], data.data);
  1373. }
  1374. } else {
  1375. error('Unknown action from worker: ' + data.action);
  1376. }
  1377. };
  1378. }
  1379. MessageHandler.prototype = {
  1380. on: function messageHandlerOn(actionName, handler, scope) {
  1381. var ah = this.actionHandler;
  1382. if (ah[actionName]) {
  1383. error('There is already an actionName called "' + actionName + '"');
  1384. }
  1385. ah[actionName] = [handler, scope];
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * @param {String} actionName Action to call.
  1390. * @param {JSON} data JSON data to send.
  1391. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1392. */
  1393. send: function messageHandlerSend(actionName, data, transfers) {
  1394. var message = {
  1395. action: actionName,
  1396. data: data
  1397. };
  1398. this.postMessage(message, transfers);
  1399. },
  1400. /**
  1401. * Sends a message to the comObj to invoke the action with the supplied data.
  1402. * Expects that other side will callback with the response.
  1403. * @param {String} actionName Action to call.
  1404. * @param {JSON} data JSON data to send.
  1405. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1406. * @returns {Promise} Promise to be resolved with response data.
  1407. */
  1408. sendWithPromise:
  1409. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1410. var callbackId = this.callbackIndex++;
  1411. var message = {
  1412. action: actionName,
  1413. data: data,
  1414. callbackId: callbackId
  1415. };
  1416. var capability = createPromiseCapability();
  1417. this.callbacksCapabilities[callbackId] = capability;
  1418. try {
  1419. this.postMessage(message, transfers);
  1420. } catch (e) {
  1421. capability.reject(e);
  1422. }
  1423. return capability.promise;
  1424. },
  1425. /**
  1426. * Sends raw message to the comObj.
  1427. * @private
  1428. * @param message {Object} Raw message.
  1429. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1430. */
  1431. postMessage: function (message, transfers) {
  1432. if (transfers && this.postMessageTransfers) {
  1433. this.comObj.postMessage(message, transfers);
  1434. } else {
  1435. this.comObj.postMessage(message);
  1436. }
  1437. }
  1438. };
  1439. function loadJpegStream(id, imageUrl, objs) {
  1440. var img = new Image();
  1441. img.onload = (function loadJpegStream_onloadClosure() {
  1442. objs.resolve(id, img);
  1443. });
  1444. img.onerror = (function loadJpegStream_onerrorClosure() {
  1445. objs.resolve(id, null);
  1446. warn('Error during JPEG image loading');
  1447. });
  1448. img.src = imageUrl;
  1449. }
  1450. var NetworkManager = (function NetworkManagerClosure() {
  1451. var OK_RESPONSE = 200;
  1452. var PARTIAL_CONTENT_RESPONSE = 206;
  1453. function NetworkManager(url, args) {
  1454. this.url = url;
  1455. args = args || {};
  1456. this.isHttp = /^https?:/i.test(url);
  1457. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1458. this.withCredentials = args.withCredentials || false;
  1459. this.getXhr = args.getXhr ||
  1460. function NetworkManager_getXhr() {
  1461. return new XMLHttpRequest();
  1462. };
  1463. this.currXhrId = 0;
  1464. this.pendingRequests = {};
  1465. this.loadedRequests = {};
  1466. }
  1467. function getArrayBuffer(xhr) {
  1468. var data = xhr.response;
  1469. if (typeof data !== 'string') {
  1470. return data;
  1471. }
  1472. var length = data.length;
  1473. var array = new Uint8Array(length);
  1474. for (var i = 0; i < length; i++) {
  1475. array[i] = data.charCodeAt(i) & 0xFF;
  1476. }
  1477. return array.buffer;
  1478. }
  1479. NetworkManager.prototype = {
  1480. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1481. var args = {
  1482. begin: begin,
  1483. end: end
  1484. };
  1485. for (var prop in listeners) {
  1486. args[prop] = listeners[prop];
  1487. }
  1488. return this.request(args);
  1489. },
  1490. requestFull: function NetworkManager_requestFull(listeners) {
  1491. return this.request(listeners);
  1492. },
  1493. request: function NetworkManager_request(args) {
  1494. var xhr = this.getXhr();
  1495. var xhrId = this.currXhrId++;
  1496. var pendingRequest = this.pendingRequests[xhrId] = {
  1497. xhr: xhr
  1498. };
  1499. xhr.open('GET', this.url);
  1500. xhr.withCredentials = this.withCredentials;
  1501. for (var property in this.httpHeaders) {
  1502. var value = this.httpHeaders[property];
  1503. if (typeof value === 'undefined') {
  1504. continue;
  1505. }
  1506. xhr.setRequestHeader(property, value);
  1507. }
  1508. if (this.isHttp && 'begin' in args && 'end' in args) {
  1509. var rangeStr = args.begin + '-' + (args.end - 1);
  1510. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1511. pendingRequest.expectedStatus = 206;
  1512. } else {
  1513. pendingRequest.expectedStatus = 200;
  1514. }
  1515. if (args.onProgressiveData) {
  1516. // Some legacy browsers might throw an exception.
  1517. try {
  1518. xhr.responseType = 'moz-chunked-arraybuffer';
  1519. } catch(e) {}
  1520. if (xhr.responseType === 'moz-chunked-arraybuffer') {
  1521. pendingRequest.onProgressiveData = args.onProgressiveData;
  1522. pendingRequest.mozChunked = true;
  1523. } else {
  1524. xhr.responseType = 'arraybuffer';
  1525. }
  1526. } else {
  1527. xhr.responseType = 'arraybuffer';
  1528. }
  1529. if (args.onError) {
  1530. xhr.onerror = function(evt) {
  1531. args.onError(xhr.status);
  1532. };
  1533. }
  1534. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1535. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1536. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1537. pendingRequest.onDone = args.onDone;
  1538. pendingRequest.onError = args.onError;
  1539. pendingRequest.onProgress = args.onProgress;
  1540. xhr.send(null);
  1541. return xhrId;
  1542. },
  1543. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1544. var pendingRequest = this.pendingRequests[xhrId];
  1545. if (!pendingRequest) {
  1546. // Maybe abortRequest was called...
  1547. return;
  1548. }
  1549. if (pendingRequest.mozChunked) {
  1550. var chunk = getArrayBuffer(pendingRequest.xhr);
  1551. pendingRequest.onProgressiveData(chunk);
  1552. }
  1553. var onProgress = pendingRequest.onProgress;
  1554. if (onProgress) {
  1555. onProgress(evt);
  1556. }
  1557. },
  1558. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1559. var pendingRequest = this.pendingRequests[xhrId];
  1560. if (!pendingRequest) {
  1561. // Maybe abortRequest was called...
  1562. return;
  1563. }
  1564. var xhr = pendingRequest.xhr;
  1565. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1566. pendingRequest.onHeadersReceived();
  1567. delete pendingRequest.onHeadersReceived;
  1568. }
  1569. if (xhr.readyState !== 4) {
  1570. return;
  1571. }
  1572. if (!(xhrId in this.pendingRequests)) {
  1573. // The XHR request might have been aborted in onHeadersReceived()
  1574. // callback, in which case we should abort request
  1575. return;
  1576. }
  1577. delete this.pendingRequests[xhrId];
  1578. // success status == 0 can be on ftp, file and other protocols
  1579. if (xhr.status === 0 && this.isHttp) {
  1580. if (pendingRequest.onError) {
  1581. pendingRequest.onError(xhr.status);
  1582. }
  1583. return;
  1584. }
  1585. var xhrStatus = xhr.status || OK_RESPONSE;
  1586. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1587. // "A server MAY ignore the Range header". This means it's possible to
  1588. // get a 200 rather than a 206 response from a range request.
  1589. var ok_response_on_range_request =
  1590. xhrStatus === OK_RESPONSE &&
  1591. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1592. if (!ok_response_on_range_request &&
  1593. xhrStatus !== pendingRequest.expectedStatus) {
  1594. if (pendingRequest.onError) {
  1595. pendingRequest.onError(xhr.status);
  1596. }
  1597. return;
  1598. }
  1599. this.loadedRequests[xhrId] = true;
  1600. var chunk = getArrayBuffer(xhr);
  1601. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1602. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1603. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1604. var begin = parseInt(matches[1], 10);
  1605. pendingRequest.onDone({
  1606. begin: begin,
  1607. chunk: chunk
  1608. });
  1609. } else if (pendingRequest.onProgressiveData) {
  1610. pendingRequest.onDone(null);
  1611. } else {
  1612. pendingRequest.onDone({
  1613. begin: 0,
  1614. chunk: chunk
  1615. });
  1616. }
  1617. },
  1618. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1619. for (var xhrId in this.pendingRequests) {
  1620. return true;
  1621. }
  1622. return false;
  1623. },
  1624. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1625. return this.pendingRequests[xhrId].xhr;
  1626. },
  1627. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1628. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1629. },
  1630. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1631. return xhrId in this.pendingRequests;
  1632. },
  1633. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1634. return xhrId in this.loadedRequests;
  1635. },
  1636. abortAllRequests: function NetworkManager_abortAllRequests() {
  1637. for (var xhrId in this.pendingRequests) {
  1638. this.abortRequest(xhrId | 0);
  1639. }
  1640. },
  1641. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1642. var xhr = this.pendingRequests[xhrId].xhr;
  1643. delete this.pendingRequests[xhrId];
  1644. xhr.abort();
  1645. }
  1646. };
  1647. return NetworkManager;
  1648. })();
  1649. var ChunkedStream = (function ChunkedStreamClosure() {
  1650. function ChunkedStream(length, chunkSize, manager) {
  1651. this.bytes = new Uint8Array(length);
  1652. this.start = 0;
  1653. this.pos = 0;
  1654. this.end = length;
  1655. this.chunkSize = chunkSize;
  1656. this.loadedChunks = [];
  1657. this.numChunksLoaded = 0;
  1658. this.numChunks = Math.ceil(length / chunkSize);
  1659. this.manager = manager;
  1660. this.progressiveDataLength = 0;
  1661. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1662. }
  1663. // required methods for a stream. if a particular stream does not
  1664. // implement these, an error should be thrown
  1665. ChunkedStream.prototype = {
  1666. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1667. var chunks = [];
  1668. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1669. if (!this.loadedChunks[chunk]) {
  1670. chunks.push(chunk);
  1671. }
  1672. }
  1673. return chunks;
  1674. },
  1675. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1676. return [this];
  1677. },
  1678. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1679. return this.numChunksLoaded === this.numChunks;
  1680. },
  1681. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1682. var end = begin + chunk.byteLength;
  1683. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1684. // Using this.length is inaccurate here since this.start can be moved
  1685. // See ChunkedStream.moveStart()
  1686. var length = this.bytes.length;
  1687. assert(end % this.chunkSize === 0 || end === length,
  1688. 'Bad end offset: ' + end);
  1689. this.bytes.set(new Uint8Array(chunk), begin);
  1690. var chunkSize = this.chunkSize;
  1691. var beginChunk = Math.floor(begin / chunkSize);
  1692. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1693. var curChunk;
  1694. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1695. if (!this.loadedChunks[curChunk]) {
  1696. this.loadedChunks[curChunk] = true;
  1697. ++this.numChunksLoaded;
  1698. }
  1699. }
  1700. },
  1701. onReceiveProgressiveData:
  1702. function ChunkedStream_onReceiveProgressiveData(data) {
  1703. var position = this.progressiveDataLength;
  1704. var beginChunk = Math.floor(position / this.chunkSize);
  1705. this.bytes.set(new Uint8Array(data), position);
  1706. position += data.byteLength;
  1707. this.progressiveDataLength = position;
  1708. var endChunk = position >= this.end ? this.numChunks :
  1709. Math.floor(position / this.chunkSize);
  1710. var curChunk;
  1711. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1712. if (!this.loadedChunks[curChunk]) {
  1713. this.loadedChunks[curChunk] = true;
  1714. ++this.numChunksLoaded;
  1715. }
  1716. }
  1717. },
  1718. ensureByte: function ChunkedStream_ensureByte(pos) {
  1719. var chunk = Math.floor(pos / this.chunkSize);
  1720. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1721. return;
  1722. }
  1723. if (!this.loadedChunks[chunk]) {
  1724. throw new MissingDataException(pos, pos + 1);
  1725. }
  1726. this.lastSuccessfulEnsureByteChunk = chunk;
  1727. },
  1728. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1729. if (begin >= end) {
  1730. return;
  1731. }
  1732. if (end <= this.progressiveDataLength) {
  1733. return;
  1734. }
  1735. var chunkSize = this.chunkSize;
  1736. var beginChunk = Math.floor(begin / chunkSize);
  1737. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1738. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1739. if (!this.loadedChunks[chunk]) {
  1740. throw new MissingDataException(begin, end);
  1741. }
  1742. }
  1743. },
  1744. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1745. var chunk, n;
  1746. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1747. if (!this.loadedChunks[chunk]) {
  1748. return chunk;
  1749. }
  1750. }
  1751. // Wrap around to beginning
  1752. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1753. if (!this.loadedChunks[chunk]) {
  1754. return chunk;
  1755. }
  1756. }
  1757. return null;
  1758. },
  1759. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1760. return !!this.loadedChunks[chunk];
  1761. },
  1762. get length() {
  1763. return this.end - this.start;
  1764. },
  1765. get isEmpty() {
  1766. return this.length === 0;
  1767. },
  1768. getByte: function ChunkedStream_getByte() {
  1769. var pos = this.pos;
  1770. if (pos >= this.end) {
  1771. return -1;
  1772. }
  1773. this.ensureByte(pos);
  1774. return this.bytes[this.pos++];
  1775. },
  1776. getUint16: function ChunkedStream_getUint16() {
  1777. var b0 = this.getByte();
  1778. var b1 = this.getByte();
  1779. if (b0 === -1 || b1 === -1) {
  1780. return -1;
  1781. }
  1782. return (b0 << 8) + b1;
  1783. },
  1784. getInt32: function ChunkedStream_getInt32() {
  1785. var b0 = this.getByte();
  1786. var b1 = this.getByte();
  1787. var b2 = this.getByte();
  1788. var b3 = this.getByte();
  1789. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1790. },
  1791. // returns subarray of original buffer
  1792. // should only be read
  1793. getBytes: function ChunkedStream_getBytes(length) {
  1794. var bytes = this.bytes;
  1795. var pos = this.pos;
  1796. var strEnd = this.end;
  1797. if (!length) {
  1798. this.ensureRange(pos, strEnd);
  1799. return bytes.subarray(pos, strEnd);
  1800. }
  1801. var end = pos + length;
  1802. if (end > strEnd) {
  1803. end = strEnd;
  1804. }
  1805. this.ensureRange(pos, end);
  1806. this.pos = end;
  1807. return bytes.subarray(pos, end);
  1808. },
  1809. peekByte: function ChunkedStream_peekByte() {
  1810. var peekedByte = this.getByte();
  1811. this.pos--;
  1812. return peekedByte;
  1813. },
  1814. peekBytes: function ChunkedStream_peekBytes(length) {
  1815. var bytes = this.getBytes(length);
  1816. this.pos -= bytes.length;
  1817. return bytes;
  1818. },
  1819. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1820. this.ensureRange(begin, end);
  1821. return this.bytes.subarray(begin, end);
  1822. },
  1823. skip: function ChunkedStream_skip(n) {
  1824. if (!n) {
  1825. n = 1;
  1826. }
  1827. this.pos += n;
  1828. },
  1829. reset: function ChunkedStream_reset() {
  1830. this.pos = this.start;
  1831. },
  1832. moveStart: function ChunkedStream_moveStart() {
  1833. this.start = this.pos;
  1834. },
  1835. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1836. this.ensureRange(start, start + length);
  1837. function ChunkedStreamSubstream() {}
  1838. ChunkedStreamSubstream.prototype = Object.create(this);
  1839. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1840. var chunkSize = this.chunkSize;
  1841. var beginChunk = Math.floor(this.start / chunkSize);
  1842. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1843. var missingChunks = [];
  1844. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1845. if (!this.loadedChunks[chunk]) {
  1846. missingChunks.push(chunk);
  1847. }
  1848. }
  1849. return missingChunks;
  1850. };
  1851. var subStream = new ChunkedStreamSubstream();
  1852. subStream.pos = subStream.start = start;
  1853. subStream.end = start + length || this.end;
  1854. subStream.dict = dict;
  1855. return subStream;
  1856. },
  1857. isStream: true
  1858. };
  1859. return ChunkedStream;
  1860. })();
  1861. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1862. function ChunkedStreamManager(length, chunkSize, url, args) {
  1863. this.stream = new ChunkedStream(length, chunkSize, this);
  1864. this.length = length;
  1865. this.chunkSize = chunkSize;
  1866. this.url = url;
  1867. this.disableAutoFetch = args.disableAutoFetch;
  1868. var msgHandler = this.msgHandler = args.msgHandler;
  1869. if (args.chunkedViewerLoading) {
  1870. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1871. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1872. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1873. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1874. };
  1875. } else {
  1876. var getXhr = function getXhr() {
  1877. return new XMLHttpRequest();
  1878. };
  1879. this.networkManager = new NetworkManager(this.url, {
  1880. getXhr: getXhr,
  1881. httpHeaders: args.httpHeaders,
  1882. withCredentials: args.withCredentials
  1883. });
  1884. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1885. this.networkManager.requestRange(begin, end, {
  1886. onDone: this.onReceiveData.bind(this),
  1887. onProgress: this.onProgress.bind(this)
  1888. });
  1889. };
  1890. }
  1891. this.currRequestId = 0;
  1892. this.chunksNeededByRequest = {};
  1893. this.requestsByChunk = {};
  1894. this.callbacksByRequest = {};
  1895. this.progressiveDataLength = 0;
  1896. this._loadedStreamCapability = createPromiseCapability();
  1897. if (args.initialData) {
  1898. this.onReceiveData({chunk: args.initialData});
  1899. }
  1900. }
  1901. ChunkedStreamManager.prototype = {
  1902. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1903. return this._loadedStreamCapability.promise;
  1904. },
  1905. // Get all the chunks that are not yet loaded and groups them into
  1906. // contiguous ranges to load in as few requests as possible
  1907. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1908. var missingChunks = this.stream.getMissingChunks();
  1909. this.requestChunks(missingChunks);
  1910. return this._loadedStreamCapability.promise;
  1911. },
  1912. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1913. callback) {
  1914. var requestId = this.currRequestId++;
  1915. var chunksNeeded;
  1916. var i, ii;
  1917. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1918. for (i = 0, ii = chunks.length; i < ii; i++) {
  1919. if (!this.stream.hasChunk(chunks[i])) {
  1920. chunksNeeded[chunks[i]] = true;
  1921. }
  1922. }
  1923. if (isEmptyObj(chunksNeeded)) {
  1924. if (callback) {
  1925. callback();
  1926. }
  1927. return;
  1928. }
  1929. this.callbacksByRequest[requestId] = callback;
  1930. var chunksToRequest = [];
  1931. for (var chunk in chunksNeeded) {
  1932. chunk = chunk | 0;
  1933. if (!(chunk in this.requestsByChunk)) {
  1934. this.requestsByChunk[chunk] = [];
  1935. chunksToRequest.push(chunk);
  1936. }
  1937. this.requestsByChunk[chunk].push(requestId);
  1938. }
  1939. if (!chunksToRequest.length) {
  1940. return;
  1941. }
  1942. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1943. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1944. var groupedChunk = groupedChunksToRequest[i];
  1945. var begin = groupedChunk.beginChunk * this.chunkSize;
  1946. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1947. this.sendRequest(begin, end);
  1948. }
  1949. },
  1950. getStream: function ChunkedStreamManager_getStream() {
  1951. return this.stream;
  1952. },
  1953. // Loads any chunks in the requested range that are not yet loaded
  1954. requestRange: function ChunkedStreamManager_requestRange(
  1955. begin, end, callback) {
  1956. end = Math.min(end, this.length);
  1957. var beginChunk = this.getBeginChunk(begin);
  1958. var endChunk = this.getEndChunk(end);
  1959. var chunks = [];
  1960. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1961. chunks.push(chunk);
  1962. }
  1963. this.requestChunks(chunks, callback);
  1964. },
  1965. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1966. callback) {
  1967. ranges = ranges || [];
  1968. var chunksToRequest = [];
  1969. for (var i = 0; i < ranges.length; i++) {
  1970. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1971. var endChunk = this.getEndChunk(ranges[i].end);
  1972. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1973. if (chunksToRequest.indexOf(chunk) < 0) {
  1974. chunksToRequest.push(chunk);
  1975. }
  1976. }
  1977. }
  1978. chunksToRequest.sort(function(a, b) { return a - b; });
  1979. this.requestChunks(chunksToRequest, callback);
  1980. },
  1981. // Groups a sorted array of chunks into as few continguous larger
  1982. // chunks as possible
  1983. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1984. var groupedChunks = [];
  1985. var beginChunk = -1;
  1986. var prevChunk = -1;
  1987. for (var i = 0; i < chunks.length; ++i) {
  1988. var chunk = chunks[i];
  1989. if (beginChunk < 0) {
  1990. beginChunk = chunk;
  1991. }
  1992. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1993. groupedChunks.push({ beginChunk: beginChunk,
  1994. endChunk: prevChunk + 1 });
  1995. beginChunk = chunk;
  1996. }
  1997. if (i + 1 === chunks.length) {
  1998. groupedChunks.push({ beginChunk: beginChunk,
  1999. endChunk: chunk + 1 });
  2000. }
  2001. prevChunk = chunk;
  2002. }
  2003. return groupedChunks;
  2004. },
  2005. onProgress: function ChunkedStreamManager_onProgress(args) {
  2006. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  2007. args.loaded);
  2008. this.msgHandler.send('DocProgress', {
  2009. loaded: bytesLoaded,
  2010. total: this.length
  2011. });
  2012. },
  2013. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  2014. var chunk = args.chunk;
  2015. var isProgressive = args.begin === undefined;
  2016. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  2017. var end = begin + chunk.byteLength;
  2018. var beginChunk = Math.floor(begin / this.chunkSize);
  2019. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  2020. Math.ceil(end / this.chunkSize);
  2021. if (isProgressive) {
  2022. this.stream.onReceiveProgressiveData(chunk);
  2023. this.progressiveDataLength = end;
  2024. } else {
  2025. this.stream.onReceiveData(begin, chunk);
  2026. }
  2027. if (this.stream.allChunksLoaded()) {
  2028. this._loadedStreamCapability.resolve(this.stream);
  2029. }
  2030. var loadedRequests = [];
  2031. var i, requestId;
  2032. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  2033. // The server might return more chunks than requested
  2034. var requestIds = this.requestsByChunk[chunk] || [];
  2035. delete this.requestsByChunk[chunk];
  2036. for (i = 0; i < requestIds.length; ++i) {
  2037. requestId = requestIds[i];
  2038. var chunksNeeded = this.chunksNeededByRequest[requestId];
  2039. if (chunk in chunksNeeded) {
  2040. delete chunksNeeded[chunk];
  2041. }
  2042. if (!isEmptyObj(chunksNeeded)) {
  2043. continue;
  2044. }
  2045. loadedRequests.push(requestId);
  2046. }
  2047. }
  2048. // If there are no pending requests, automatically fetch the next
  2049. // unfetched chunk of the PDF
  2050. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2051. var nextEmptyChunk;
  2052. if (this.stream.numChunksLoaded === 1) {
  2053. // This is a special optimization so that after fetching the first
  2054. // chunk, rather than fetching the second chunk, we fetch the last
  2055. // chunk.
  2056. var lastChunk = this.stream.numChunks - 1;
  2057. if (!this.stream.hasChunk(lastChunk)) {
  2058. nextEmptyChunk = lastChunk;
  2059. }
  2060. } else {
  2061. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2062. }
  2063. if (isInt(nextEmptyChunk)) {
  2064. this.requestChunks([nextEmptyChunk]);
  2065. }
  2066. }
  2067. for (i = 0; i < loadedRequests.length; ++i) {
  2068. requestId = loadedRequests[i];
  2069. var callback = this.callbacksByRequest[requestId];
  2070. delete this.callbacksByRequest[requestId];
  2071. if (callback) {
  2072. callback();
  2073. }
  2074. }
  2075. this.msgHandler.send('DocProgress', {
  2076. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2077. total: this.length
  2078. });
  2079. },
  2080. onError: function ChunkedStreamManager_onError(err) {
  2081. this._loadedStreamCapability.reject(err);
  2082. },
  2083. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2084. var chunk = Math.floor(begin / this.chunkSize);
  2085. return chunk;
  2086. },
  2087. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2088. if (end % this.chunkSize === 0) {
  2089. return end / this.chunkSize;
  2090. }
  2091. // 0 -> 0
  2092. // 1 -> 1
  2093. // 99 -> 1
  2094. // 100 -> 1
  2095. // 101 -> 2
  2096. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2097. return chunk;
  2098. }
  2099. };
  2100. return ChunkedStreamManager;
  2101. })();
  2102. // The maximum number of bytes fetched per range request
  2103. var RANGE_CHUNK_SIZE = 65536;
  2104. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2105. var BasePdfManager = (function BasePdfManagerClosure() {
  2106. function BasePdfManager() {
  2107. throw new Error('Cannot initialize BaseManagerManager');
  2108. }
  2109. BasePdfManager.prototype = {
  2110. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2111. throw new NotImplementedException();
  2112. },
  2113. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2114. return this.ensure(this.pdfDocument, prop, args);
  2115. },
  2116. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2117. return this.ensure(this.pdfDocument.xref, prop, args);
  2118. },
  2119. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2120. return this.ensure(this.pdfDocument.catalog, prop, args);
  2121. },
  2122. getPage: function BasePdfManager_pagePage(pageIndex) {
  2123. return this.pdfDocument.getPage(pageIndex);
  2124. },
  2125. cleanup: function BasePdfManager_cleanup() {
  2126. return this.pdfDocument.cleanup();
  2127. },
  2128. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2129. return new NotImplementedException();
  2130. },
  2131. requestRange: function BasePdfManager_ensure(begin, end) {
  2132. return new NotImplementedException();
  2133. },
  2134. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2135. return new NotImplementedException();
  2136. },
  2137. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  2138. return new NotImplementedException();
  2139. },
  2140. updatePassword: function BasePdfManager_updatePassword(password) {
  2141. this.pdfDocument.xref.password = this.password = password;
  2142. if (this._passwordChangedCapability) {
  2143. this._passwordChangedCapability.resolve();
  2144. }
  2145. },
  2146. passwordChanged: function BasePdfManager_passwordChanged() {
  2147. this._passwordChangedCapability = createPromiseCapability();
  2148. return this._passwordChangedCapability.promise;
  2149. },
  2150. terminate: function BasePdfManager_terminate() {
  2151. return new NotImplementedException();
  2152. }
  2153. };
  2154. return BasePdfManager;
  2155. })();
  2156. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2157. function LocalPdfManager(data, password) {
  2158. var stream = new Stream(data);
  2159. this.pdfDocument = new PDFDocument(this, stream, password);
  2160. this._loadedStreamCapability = createPromiseCapability();
  2161. this._loadedStreamCapability.resolve(stream);
  2162. }
  2163. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2164. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2165. LocalPdfManager.prototype.ensure =
  2166. function LocalPdfManager_ensure(obj, prop, args) {
  2167. return new Promise(function (resolve, reject) {
  2168. try {
  2169. var value = obj[prop];
  2170. var result;
  2171. if (typeof value === 'function') {
  2172. result = value.apply(obj, args);
  2173. } else {
  2174. result = value;
  2175. }
  2176. resolve(result);
  2177. } catch (e) {
  2178. reject(e);
  2179. }
  2180. });
  2181. };
  2182. LocalPdfManager.prototype.requestRange =
  2183. function LocalPdfManager_requestRange(begin, end) {
  2184. return Promise.resolve();
  2185. };
  2186. LocalPdfManager.prototype.requestLoadedStream =
  2187. function LocalPdfManager_requestLoadedStream() {
  2188. };
  2189. LocalPdfManager.prototype.onLoadedStream =
  2190. function LocalPdfManager_getLoadedStream() {
  2191. return this._loadedStreamCapability.promise;
  2192. };
  2193. LocalPdfManager.prototype.terminate =
  2194. function LocalPdfManager_terminate() {
  2195. return;
  2196. };
  2197. return LocalPdfManager;
  2198. })();
  2199. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2200. function NetworkPdfManager(args, msgHandler) {
  2201. this.msgHandler = msgHandler;
  2202. var params = {
  2203. msgHandler: msgHandler,
  2204. httpHeaders: args.httpHeaders,
  2205. withCredentials: args.withCredentials,
  2206. chunkedViewerLoading: args.chunkedViewerLoading,
  2207. disableAutoFetch: args.disableAutoFetch,
  2208. initialData: args.initialData
  2209. };
  2210. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2211. args.url, params);
  2212. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2213. args.password);
  2214. }
  2215. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2216. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2217. NetworkPdfManager.prototype.ensure =
  2218. function NetworkPdfManager_ensure(obj, prop, args) {
  2219. var pdfManager = this;
  2220. return new Promise(function (resolve, reject) {
  2221. function ensureHelper() {
  2222. try {
  2223. var result;
  2224. var value = obj[prop];
  2225. if (typeof value === 'function') {
  2226. result = value.apply(obj, args);
  2227. } else {
  2228. result = value;
  2229. }
  2230. resolve(result);
  2231. } catch(e) {
  2232. if (!(e instanceof MissingDataException)) {
  2233. reject(e);
  2234. return;
  2235. }
  2236. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2237. }
  2238. }
  2239. ensureHelper();
  2240. });
  2241. };
  2242. NetworkPdfManager.prototype.requestRange =
  2243. function NetworkPdfManager_requestRange(begin, end) {
  2244. return new Promise(function (resolve) {
  2245. this.streamManager.requestRange(begin, end, function() {
  2246. resolve();
  2247. });
  2248. }.bind(this));
  2249. };
  2250. NetworkPdfManager.prototype.requestLoadedStream =
  2251. function NetworkPdfManager_requestLoadedStream() {
  2252. this.streamManager.requestAllChunks();
  2253. };
  2254. NetworkPdfManager.prototype.sendProgressiveData =
  2255. function NetworkPdfManager_sendProgressiveData(chunk) {
  2256. this.streamManager.onReceiveData({ chunk: chunk });
  2257. };
  2258. NetworkPdfManager.prototype.onLoadedStream =
  2259. function NetworkPdfManager_getLoadedStream() {
  2260. return this.streamManager.onLoadedStream();
  2261. };
  2262. NetworkPdfManager.prototype.terminate =
  2263. function NetworkPdfManager_terminate() {
  2264. this.streamManager.networkManager.abortAllRequests();
  2265. };
  2266. return NetworkPdfManager;
  2267. })();
  2268. var Page = (function PageClosure() {
  2269. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2270. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2271. this.pdfManager = pdfManager;
  2272. this.pageIndex = pageIndex;
  2273. this.pageDict = pageDict;
  2274. this.xref = xref;
  2275. this.ref = ref;
  2276. this.fontCache = fontCache;
  2277. this.idCounters = {
  2278. obj: 0
  2279. };
  2280. this.resourcesPromise = null;
  2281. }
  2282. Page.prototype = {
  2283. getPageProp: function Page_getPageProp(key) {
  2284. return this.pageDict.get(key);
  2285. },
  2286. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  2287. var dict = this.pageDict, valueArray = null, loopCount = 0;
  2288. var MAX_LOOP_COUNT = 100;
  2289. // Always walk up the entire parent chain, to be able to find
  2290. // e.g. \Resources placed on multiple levels of the tree.
  2291. while (dict) {
  2292. var value = dict.get(key);
  2293. if (value) {
  2294. if (!valueArray) {
  2295. valueArray = [];
  2296. }
  2297. valueArray.push(value);
  2298. }
  2299. if (++loopCount > MAX_LOOP_COUNT) {
  2300. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  2301. break;
  2302. }
  2303. dict = dict.get('Parent');
  2304. }
  2305. if (!valueArray) {
  2306. return Dict.empty;
  2307. }
  2308. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  2309. loopCount > MAX_LOOP_COUNT) {
  2310. return valueArray[0];
  2311. }
  2312. return Dict.merge(this.xref, valueArray);
  2313. },
  2314. get content() {
  2315. return this.getPageProp('Contents');
  2316. },
  2317. get resources() {
  2318. // For robustness: The spec states that a \Resources entry has to be
  2319. // present, but can be empty. Some document omit it still, in this case
  2320. // we return an empty dictionary.
  2321. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  2322. },
  2323. get mediaBox() {
  2324. var obj = this.getInheritedPageProp('MediaBox');
  2325. // Reset invalid media box to letter size.
  2326. if (!isArray(obj) || obj.length !== 4) {
  2327. obj = LETTER_SIZE_MEDIABOX;
  2328. }
  2329. return shadow(this, 'mediaBox', obj);
  2330. },
  2331. get view() {
  2332. var mediaBox = this.mediaBox;
  2333. var cropBox = this.getInheritedPageProp('CropBox');
  2334. if (!isArray(cropBox) || cropBox.length !== 4) {
  2335. return shadow(this, 'view', mediaBox);
  2336. }
  2337. // From the spec, 6th ed., p.963:
  2338. // "The crop, bleed, trim, and art boxes should not ordinarily
  2339. // extend beyond the boundaries of the media box. If they do, they are
  2340. // effectively reduced to their intersection with the media box."
  2341. cropBox = Util.intersect(cropBox, mediaBox);
  2342. if (!cropBox) {
  2343. return shadow(this, 'view', mediaBox);
  2344. }
  2345. return shadow(this, 'view', cropBox);
  2346. },
  2347. get annotationRefs() {
  2348. return shadow(this, 'annotationRefs',
  2349. this.getInheritedPageProp('Annots'));
  2350. },
  2351. get rotate() {
  2352. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2353. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2354. if (rotate % 90 !== 0) {
  2355. rotate = 0;
  2356. } else if (rotate >= 360) {
  2357. rotate = rotate % 360;
  2358. } else if (rotate < 0) {
  2359. // The spec doesn't cover negatives, assume its counterclockwise
  2360. // rotation. The following is the other implementation of modulo.
  2361. rotate = ((rotate % 360) + 360) % 360;
  2362. }
  2363. return shadow(this, 'rotate', rotate);
  2364. },
  2365. getContentStream: function Page_getContentStream() {
  2366. var content = this.content;
  2367. var stream;
  2368. if (isArray(content)) {
  2369. // fetching items
  2370. var xref = this.xref;
  2371. var i, n = content.length;
  2372. var streams = [];
  2373. for (i = 0; i < n; ++i) {
  2374. streams.push(xref.fetchIfRef(content[i]));
  2375. }
  2376. stream = new StreamsSequenceStream(streams);
  2377. } else if (isStream(content)) {
  2378. stream = content;
  2379. } else {
  2380. // replacing non-existent page content with empty one
  2381. stream = new NullStream();
  2382. }
  2383. return stream;
  2384. },
  2385. loadResources: function Page_loadResources(keys) {
  2386. if (!this.resourcesPromise) {
  2387. // TODO: add async getInheritedPageProp and remove this.
  2388. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2389. }
  2390. return this.resourcesPromise.then(function resourceSuccess() {
  2391. var objectLoader = new ObjectLoader(this.resources.map,
  2392. keys,
  2393. this.xref);
  2394. return objectLoader.load();
  2395. }.bind(this));
  2396. },
  2397. getOperatorList: function Page_getOperatorList(handler, intent) {
  2398. var self = this;
  2399. var pdfManager = this.pdfManager;
  2400. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2401. []);
  2402. var resourcesPromise = this.loadResources([
  2403. 'ExtGState',
  2404. 'ColorSpace',
  2405. 'Pattern',
  2406. 'Shading',
  2407. 'XObject',
  2408. 'Font'
  2409. // ProcSet
  2410. // Properties
  2411. ]);
  2412. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2413. handler, this.pageIndex,
  2414. 'p' + this.pageIndex + '_',
  2415. this.idCounters,
  2416. this.fontCache);
  2417. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2418. var pageListPromise = dataPromises.then(function(data) {
  2419. var contentStream = data[0];
  2420. var opList = new OperatorList(intent, handler, self.pageIndex);
  2421. handler.send('StartRenderPage', {
  2422. transparency: partialEvaluator.hasBlendModes(self.resources),
  2423. pageIndex: self.pageIndex,
  2424. intent: intent
  2425. });
  2426. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2427. opList).then(function () {
  2428. return opList;
  2429. });
  2430. });
  2431. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2432. return Promise.all([pageListPromise, annotationsPromise]).then(
  2433. function(datas) {
  2434. var pageOpList = datas[0];
  2435. var annotations = datas[1];
  2436. if (annotations.length === 0) {
  2437. pageOpList.flush(true);
  2438. return pageOpList;
  2439. }
  2440. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2441. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2442. return annotationsReadyPromise.then(function () {
  2443. pageOpList.flush(true);
  2444. return pageOpList;
  2445. });
  2446. });
  2447. },
  2448. extractTextContent: function Page_extractTextContent() {
  2449. var handler = {
  2450. on: function nullHandlerOn() {},
  2451. send: function nullHandlerSend() {}
  2452. };
  2453. var self = this;
  2454. var pdfManager = this.pdfManager;
  2455. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2456. []);
  2457. var resourcesPromise = this.loadResources([
  2458. 'ExtGState',
  2459. 'XObject',
  2460. 'Font'
  2461. ]);
  2462. var dataPromises = Promise.all([contentStreamPromise,
  2463. resourcesPromise]);
  2464. return dataPromises.then(function(data) {
  2465. var contentStream = data[0];
  2466. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2467. handler, self.pageIndex,
  2468. 'p' + self.pageIndex + '_',
  2469. self.idCounters,
  2470. self.fontCache);
  2471. return partialEvaluator.getTextContent(contentStream,
  2472. self.resources);
  2473. });
  2474. },
  2475. getAnnotationsData: function Page_getAnnotationsData() {
  2476. var annotations = this.annotations;
  2477. var annotationsData = [];
  2478. for (var i = 0, n = annotations.length; i < n; ++i) {
  2479. annotationsData.push(annotations[i].getData());
  2480. }
  2481. return annotationsData;
  2482. },
  2483. get annotations() {
  2484. var annotations = [];
  2485. var annotationRefs = (this.annotationRefs || []);
  2486. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2487. var annotationRef = annotationRefs[i];
  2488. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2489. if (annotation) {
  2490. annotations.push(annotation);
  2491. }
  2492. }
  2493. return shadow(this, 'annotations', annotations);
  2494. }
  2495. };
  2496. return Page;
  2497. })();
  2498. /**
  2499. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2500. * `PDFDoc`, this one doesn't have any job management code.
  2501. * Right now there exists one PDFDocument on the main thread + one object
  2502. * for each worker. If there is no worker support enabled, there are two
  2503. * `PDFDocument` objects on the main thread created.
  2504. */
  2505. var PDFDocument = (function PDFDocumentClosure() {
  2506. var FINGERPRINT_FIRST_BYTES = 1024;
  2507. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  2508. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  2509. function PDFDocument(pdfManager, arg, password) {
  2510. if (isStream(arg)) {
  2511. init.call(this, pdfManager, arg, password);
  2512. } else if (isArrayBuffer(arg)) {
  2513. init.call(this, pdfManager, new Stream(arg), password);
  2514. } else {
  2515. error('PDFDocument: Unknown argument type');
  2516. }
  2517. }
  2518. function init(pdfManager, stream, password) {
  2519. assert(stream.length > 0, 'stream must have data');
  2520. this.pdfManager = pdfManager;
  2521. this.stream = stream;
  2522. var xref = new XRef(this.stream, password, pdfManager);
  2523. this.xref = xref;
  2524. }
  2525. function find(stream, needle, limit, backwards) {
  2526. var pos = stream.pos;
  2527. var end = stream.end;
  2528. var strBuf = [];
  2529. if (pos + limit > end) {
  2530. limit = end - pos;
  2531. }
  2532. for (var n = 0; n < limit; ++n) {
  2533. strBuf.push(String.fromCharCode(stream.getByte()));
  2534. }
  2535. var str = strBuf.join('');
  2536. stream.pos = pos;
  2537. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2538. if (index === -1) {
  2539. return false; /* not found */
  2540. }
  2541. stream.pos += index;
  2542. return true; /* found */
  2543. }
  2544. var DocumentInfoValidators = {
  2545. get entries() {
  2546. // Lazily build this since all the validation functions below are not
  2547. // defined until after this file loads.
  2548. return shadow(this, 'entries', {
  2549. Title: isString,
  2550. Author: isString,
  2551. Subject: isString,
  2552. Keywords: isString,
  2553. Creator: isString,
  2554. Producer: isString,
  2555. CreationDate: isString,
  2556. ModDate: isString,
  2557. Trapped: isName
  2558. });
  2559. }
  2560. };
  2561. PDFDocument.prototype = {
  2562. parse: function PDFDocument_parse(recoveryMode) {
  2563. this.setup(recoveryMode);
  2564. var version = this.catalog.catDict.get('Version');
  2565. if (isName(version)) {
  2566. this.pdfFormatVersion = version.name;
  2567. }
  2568. try {
  2569. // checking if AcroForm is present
  2570. this.acroForm = this.catalog.catDict.get('AcroForm');
  2571. if (this.acroForm) {
  2572. this.xfa = this.acroForm.get('XFA');
  2573. var fields = this.acroForm.get('Fields');
  2574. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2575. !this.xfa) {
  2576. // no fields and no XFA -- not a form (?)
  2577. this.acroForm = null;
  2578. }
  2579. }
  2580. } catch (ex) {
  2581. info('Something wrong with AcroForm entry');
  2582. this.acroForm = null;
  2583. }
  2584. },
  2585. get linearization() {
  2586. var linearization = null;
  2587. if (this.stream.length) {
  2588. try {
  2589. linearization = Linearization.create(this.stream);
  2590. } catch (err) {
  2591. if (err instanceof MissingDataException) {
  2592. throw err;
  2593. }
  2594. info(err);
  2595. }
  2596. }
  2597. // shadow the prototype getter with a data property
  2598. return shadow(this, 'linearization', linearization);
  2599. },
  2600. get startXRef() {
  2601. var stream = this.stream;
  2602. var startXRef = 0;
  2603. var linearization = this.linearization;
  2604. if (linearization) {
  2605. // Find end of first obj.
  2606. stream.reset();
  2607. if (find(stream, 'endobj', 1024)) {
  2608. startXRef = stream.pos + 6;
  2609. }
  2610. } else {
  2611. // Find startxref by jumping backward from the end of the file.
  2612. var step = 1024;
  2613. var found = false, pos = stream.end;
  2614. while (!found && pos > 0) {
  2615. pos -= step - 'startxref'.length;
  2616. if (pos < 0) {
  2617. pos = 0;
  2618. }
  2619. stream.pos = pos;
  2620. found = find(stream, 'startxref', step, true);
  2621. }
  2622. if (found) {
  2623. stream.skip(9);
  2624. var ch;
  2625. do {
  2626. ch = stream.getByte();
  2627. } while (Lexer.isSpace(ch));
  2628. var str = '';
  2629. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2630. str += String.fromCharCode(ch);
  2631. ch = stream.getByte();
  2632. }
  2633. startXRef = parseInt(str, 10);
  2634. if (isNaN(startXRef)) {
  2635. startXRef = 0;
  2636. }
  2637. }
  2638. }
  2639. // shadow the prototype getter with a data property
  2640. return shadow(this, 'startXRef', startXRef);
  2641. },
  2642. get mainXRefEntriesOffset() {
  2643. var mainXRefEntriesOffset = 0;
  2644. var linearization = this.linearization;
  2645. if (linearization) {
  2646. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2647. }
  2648. // shadow the prototype getter with a data property
  2649. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2650. },
  2651. // Find the header, remove leading garbage and setup the stream
  2652. // starting from the header.
  2653. checkHeader: function PDFDocument_checkHeader() {
  2654. var stream = this.stream;
  2655. stream.reset();
  2656. if (find(stream, '%PDF-', 1024)) {
  2657. // Found the header, trim off any garbage before it.
  2658. stream.moveStart();
  2659. // Reading file format version
  2660. var MAX_VERSION_LENGTH = 12;
  2661. var version = '', ch;
  2662. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2663. if (version.length >= MAX_VERSION_LENGTH) {
  2664. break;
  2665. }
  2666. version += String.fromCharCode(ch);
  2667. }
  2668. if (!this.pdfFormatVersion) {
  2669. // removing "%PDF-"-prefix
  2670. this.pdfFormatVersion = version.substring(5);
  2671. }
  2672. return;
  2673. }
  2674. // May not be a PDF file, continue anyway.
  2675. },
  2676. parseStartXRef: function PDFDocument_parseStartXRef() {
  2677. var startXRef = this.startXRef;
  2678. this.xref.setStartXRef(startXRef);
  2679. },
  2680. setup: function PDFDocument_setup(recoveryMode) {
  2681. this.xref.parse(recoveryMode);
  2682. this.catalog = new Catalog(this.pdfManager, this.xref);
  2683. },
  2684. get numPages() {
  2685. var linearization = this.linearization;
  2686. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2687. // shadow the prototype getter
  2688. return shadow(this, 'numPages', num);
  2689. },
  2690. get documentInfo() {
  2691. var docInfo = {
  2692. PDFFormatVersion: this.pdfFormatVersion,
  2693. IsAcroFormPresent: !!this.acroForm,
  2694. IsXFAPresent: !!this.xfa
  2695. };
  2696. var infoDict;
  2697. try {
  2698. infoDict = this.xref.trailer.get('Info');
  2699. } catch (err) {
  2700. info('The document information dictionary is invalid.');
  2701. }
  2702. if (infoDict) {
  2703. var validEntries = DocumentInfoValidators.entries;
  2704. // Only fill the document info with valid entries from the spec.
  2705. for (var key in validEntries) {
  2706. if (infoDict.has(key)) {
  2707. var value = infoDict.get(key);
  2708. // Make sure the value conforms to the spec.
  2709. if (validEntries[key](value)) {
  2710. docInfo[key] = (typeof value !== 'string' ?
  2711. value : stringToPDFString(value));
  2712. } else {
  2713. info('Bad value in document info for "' + key + '"');
  2714. }
  2715. }
  2716. }
  2717. }
  2718. return shadow(this, 'documentInfo', docInfo);
  2719. },
  2720. get fingerprint() {
  2721. var xref = this.xref, idArray, hash, fileID = '';
  2722. if (xref.trailer.has('ID')) {
  2723. idArray = xref.trailer.get('ID');
  2724. }
  2725. if (idArray && isArray(idArray) && idArray[0] !== EMPTY_FINGERPRINT) {
  2726. hash = stringToBytes(idArray[0]);
  2727. } else {
  2728. if (this.stream.ensureRange) {
  2729. this.stream.ensureRange(0,
  2730. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  2731. }
  2732. hash = calculateMD5(this.stream.bytes.subarray(0,
  2733. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  2734. }
  2735. for (var i = 0, n = hash.length; i < n; i++) {
  2736. var hex = hash[i].toString(16);
  2737. fileID += hex.length === 1 ? '0' + hex : hex;
  2738. }
  2739. return shadow(this, 'fingerprint', fileID);
  2740. },
  2741. getPage: function PDFDocument_getPage(pageIndex) {
  2742. return this.catalog.getPage(pageIndex);
  2743. },
  2744. cleanup: function PDFDocument_cleanup() {
  2745. return this.catalog.cleanup();
  2746. }
  2747. };
  2748. return PDFDocument;
  2749. })();
  2750. var Name = (function NameClosure() {
  2751. function Name(name) {
  2752. this.name = name;
  2753. }
  2754. Name.prototype = {};
  2755. var nameCache = {};
  2756. Name.get = function Name_get(name) {
  2757. var nameValue = nameCache[name];
  2758. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2759. };
  2760. return Name;
  2761. })();
  2762. var Cmd = (function CmdClosure() {
  2763. function Cmd(cmd) {
  2764. this.cmd = cmd;
  2765. }
  2766. Cmd.prototype = {};
  2767. var cmdCache = {};
  2768. Cmd.get = function Cmd_get(cmd) {
  2769. var cmdValue = cmdCache[cmd];
  2770. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2771. };
  2772. return Cmd;
  2773. })();
  2774. var Dict = (function DictClosure() {
  2775. var nonSerializable = function nonSerializableClosure() {
  2776. return nonSerializable; // creating closure on some variable
  2777. };
  2778. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2779. 'Background': true,
  2780. 'ExtGState': true,
  2781. 'Halftone': true,
  2782. 'Layout': true,
  2783. 'Mask': true,
  2784. 'Pagination': true,
  2785. 'Printing': true
  2786. };
  2787. function isRecursionAllowedFor(dict) {
  2788. if (!isName(dict.Type)) {
  2789. return true;
  2790. }
  2791. var dictType = dict.Type.name;
  2792. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2793. }
  2794. // xref is optional
  2795. function Dict(xref) {
  2796. // Map should only be used internally, use functions below to access.
  2797. this.map = Object.create(null);
  2798. this.xref = xref;
  2799. this.objId = null;
  2800. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2801. }
  2802. Dict.prototype = {
  2803. assignXref: function Dict_assignXref(newXref) {
  2804. this.xref = newXref;
  2805. },
  2806. // automatically dereferences Ref objects
  2807. get: function Dict_get(key1, key2, key3) {
  2808. var value;
  2809. var xref = this.xref;
  2810. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2811. typeof key2 === 'undefined') {
  2812. return xref ? xref.fetchIfRef(value) : value;
  2813. }
  2814. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2815. typeof key3 === 'undefined') {
  2816. return xref ? xref.fetchIfRef(value) : value;
  2817. }
  2818. value = this.map[key3] || null;
  2819. return xref ? xref.fetchIfRef(value) : value;
  2820. },
  2821. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2822. getAsync: function Dict_getAsync(key1, key2, key3) {
  2823. var value;
  2824. var xref = this.xref;
  2825. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2826. typeof key2 === 'undefined') {
  2827. if (xref) {
  2828. return xref.fetchIfRefAsync(value);
  2829. }
  2830. return Promise.resolve(value);
  2831. }
  2832. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2833. typeof key3 === 'undefined') {
  2834. if (xref) {
  2835. return xref.fetchIfRefAsync(value);
  2836. }
  2837. return Promise.resolve(value);
  2838. }
  2839. value = this.map[key3] || null;
  2840. if (xref) {
  2841. return xref.fetchIfRefAsync(value);
  2842. }
  2843. return Promise.resolve(value);
  2844. },
  2845. // no dereferencing
  2846. getRaw: function Dict_getRaw(key) {
  2847. return this.map[key];
  2848. },
  2849. // creates new map and dereferences all Refs
  2850. getAll: function Dict_getAll() {
  2851. var all = Object.create(null);
  2852. var queue = null;
  2853. var key, obj;
  2854. for (key in this.map) {
  2855. obj = this.get(key);
  2856. if (obj instanceof Dict) {
  2857. if (isRecursionAllowedFor(obj)) {
  2858. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2859. } else {
  2860. all[key] = this.getRaw(key);
  2861. }
  2862. } else {
  2863. all[key] = obj;
  2864. }
  2865. }
  2866. if (!queue) {
  2867. return all;
  2868. }
  2869. // trying to take cyclic references into the account
  2870. var processed = Object.create(null);
  2871. while (queue.length > 0) {
  2872. var item = queue.shift();
  2873. var itemObj = item.obj;
  2874. var objId = itemObj.objId;
  2875. if (objId && objId in processed) {
  2876. item.target[item.key] = processed[objId];
  2877. continue;
  2878. }
  2879. var dereferenced = Object.create(null);
  2880. for (key in itemObj.map) {
  2881. obj = itemObj.get(key);
  2882. if (obj instanceof Dict) {
  2883. if (isRecursionAllowedFor(obj)) {
  2884. queue.push({target: dereferenced, key: key, obj: obj});
  2885. } else {
  2886. dereferenced[key] = itemObj.getRaw(key);
  2887. }
  2888. } else {
  2889. dereferenced[key] = obj;
  2890. }
  2891. }
  2892. if (objId) {
  2893. processed[objId] = dereferenced;
  2894. }
  2895. item.target[item.key] = dereferenced;
  2896. }
  2897. return all;
  2898. },
  2899. getKeys: function Dict_getKeys() {
  2900. return Object.keys(this.map);
  2901. },
  2902. set: function Dict_set(key, value) {
  2903. this.map[key] = value;
  2904. },
  2905. has: function Dict_has(key) {
  2906. return key in this.map;
  2907. },
  2908. forEach: function Dict_forEach(callback) {
  2909. for (var key in this.map) {
  2910. callback(key, this.get(key));
  2911. }
  2912. }
  2913. };
  2914. Dict.empty = new Dict(null);
  2915. Dict.merge = function Dict_merge(xref, dictArray) {
  2916. var mergedDict = new Dict(xref);
  2917. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  2918. var dict = dictArray[i];
  2919. if (!isDict(dict)) {
  2920. continue;
  2921. }
  2922. for (var keyName in dict.map) {
  2923. if (mergedDict.map[keyName]) {
  2924. continue;
  2925. }
  2926. mergedDict.map[keyName] = dict.map[keyName];
  2927. }
  2928. }
  2929. return mergedDict;
  2930. };
  2931. return Dict;
  2932. })();
  2933. var Ref = (function RefClosure() {
  2934. function Ref(num, gen) {
  2935. this.num = num;
  2936. this.gen = gen;
  2937. }
  2938. Ref.prototype = {
  2939. toString: function Ref_toString() {
  2940. // This function is hot, so we make the string as compact as possible.
  2941. // |this.gen| is almost always zero, so we treat that case specially.
  2942. var str = this.num + 'R';
  2943. if (this.gen !== 0) {
  2944. str += this.gen;
  2945. }
  2946. return str;
  2947. }
  2948. };
  2949. return Ref;
  2950. })();
  2951. // The reference is identified by number and generation.
  2952. // This structure stores only one instance of the reference.
  2953. var RefSet = (function RefSetClosure() {
  2954. function RefSet() {
  2955. this.dict = {};
  2956. }
  2957. RefSet.prototype = {
  2958. has: function RefSet_has(ref) {
  2959. return ref.toString() in this.dict;
  2960. },
  2961. put: function RefSet_put(ref) {
  2962. this.dict[ref.toString()] = true;
  2963. },
  2964. remove: function RefSet_remove(ref) {
  2965. delete this.dict[ref.toString()];
  2966. }
  2967. };
  2968. return RefSet;
  2969. })();
  2970. var RefSetCache = (function RefSetCacheClosure() {
  2971. function RefSetCache() {
  2972. this.dict = Object.create(null);
  2973. }
  2974. RefSetCache.prototype = {
  2975. get: function RefSetCache_get(ref) {
  2976. return this.dict[ref.toString()];
  2977. },
  2978. has: function RefSetCache_has(ref) {
  2979. return ref.toString() in this.dict;
  2980. },
  2981. put: function RefSetCache_put(ref, obj) {
  2982. this.dict[ref.toString()] = obj;
  2983. },
  2984. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2985. this.dict[ref.toString()] = this.get(aliasRef);
  2986. },
  2987. forEach: function RefSetCache_forEach(fn, thisArg) {
  2988. for (var i in this.dict) {
  2989. fn.call(thisArg, this.dict[i]);
  2990. }
  2991. },
  2992. clear: function RefSetCache_clear() {
  2993. this.dict = Object.create(null);
  2994. }
  2995. };
  2996. return RefSetCache;
  2997. })();
  2998. var Catalog = (function CatalogClosure() {
  2999. function Catalog(pdfManager, xref) {
  3000. this.pdfManager = pdfManager;
  3001. this.xref = xref;
  3002. this.catDict = xref.getCatalogObj();
  3003. this.fontCache = new RefSetCache();
  3004. assert(isDict(this.catDict),
  3005. 'catalog object is not a dictionary');
  3006. this.pagePromises = [];
  3007. }
  3008. Catalog.prototype = {
  3009. get metadata() {
  3010. var streamRef = this.catDict.getRaw('Metadata');
  3011. if (!isRef(streamRef)) {
  3012. return shadow(this, 'metadata', null);
  3013. }
  3014. var encryptMetadata = (!this.xref.encrypt ? false :
  3015. this.xref.encrypt.encryptMetadata);
  3016. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  3017. var metadata;
  3018. if (stream && isDict(stream.dict)) {
  3019. var type = stream.dict.get('Type');
  3020. var subtype = stream.dict.get('Subtype');
  3021. if (isName(type) && isName(subtype) &&
  3022. type.name === 'Metadata' && subtype.name === 'XML') {
  3023. // XXX: This should examine the charset the XML document defines,
  3024. // however since there are currently no real means to decode
  3025. // arbitrary charsets, let's just hope that the author of the PDF
  3026. // was reasonable enough to stick with the XML default charset,
  3027. // which is UTF-8.
  3028. try {
  3029. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  3030. } catch (e) {
  3031. info('Skipping invalid metadata.');
  3032. }
  3033. }
  3034. }
  3035. return shadow(this, 'metadata', metadata);
  3036. },
  3037. get toplevelPagesDict() {
  3038. var pagesObj = this.catDict.get('Pages');
  3039. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  3040. // shadow the prototype getter
  3041. return shadow(this, 'toplevelPagesDict', pagesObj);
  3042. },
  3043. get documentOutline() {
  3044. var obj = null;
  3045. try {
  3046. obj = this.readDocumentOutline();
  3047. } catch (ex) {
  3048. if (ex instanceof MissingDataException) {
  3049. throw ex;
  3050. }
  3051. warn('Unable to read document outline');
  3052. }
  3053. return shadow(this, 'documentOutline', obj);
  3054. },
  3055. readDocumentOutline: function Catalog_readDocumentOutline() {
  3056. var xref = this.xref;
  3057. var obj = this.catDict.get('Outlines');
  3058. var root = { items: [] };
  3059. if (isDict(obj)) {
  3060. obj = obj.getRaw('First');
  3061. var processed = new RefSet();
  3062. if (isRef(obj)) {
  3063. var queue = [{obj: obj, parent: root}];
  3064. // to avoid recursion keeping track of the items
  3065. // in the processed dictionary
  3066. processed.put(obj);
  3067. while (queue.length > 0) {
  3068. var i = queue.shift();
  3069. var outlineDict = xref.fetchIfRef(i.obj);
  3070. if (outlineDict === null) {
  3071. continue;
  3072. }
  3073. if (!outlineDict.has('Title')) {
  3074. error('Invalid outline item');
  3075. }
  3076. var dest = outlineDict.get('A');
  3077. if (dest) {
  3078. dest = dest.get('D');
  3079. } else if (outlineDict.has('Dest')) {
  3080. dest = outlineDict.getRaw('Dest');
  3081. if (isName(dest)) {
  3082. dest = dest.name;
  3083. }
  3084. }
  3085. var title = outlineDict.get('Title');
  3086. var outlineItem = {
  3087. dest: dest,
  3088. title: stringToPDFString(title),
  3089. color: outlineDict.get('C') || [0, 0, 0],
  3090. count: outlineDict.get('Count'),
  3091. bold: !!(outlineDict.get('F') & 2),
  3092. italic: !!(outlineDict.get('F') & 1),
  3093. items: []
  3094. };
  3095. i.parent.items.push(outlineItem);
  3096. obj = outlineDict.getRaw('First');
  3097. if (isRef(obj) && !processed.has(obj)) {
  3098. queue.push({obj: obj, parent: outlineItem});
  3099. processed.put(obj);
  3100. }
  3101. obj = outlineDict.getRaw('Next');
  3102. if (isRef(obj) && !processed.has(obj)) {
  3103. queue.push({obj: obj, parent: i.parent});
  3104. processed.put(obj);
  3105. }
  3106. }
  3107. }
  3108. }
  3109. return (root.items.length > 0 ? root.items : null);
  3110. },
  3111. get numPages() {
  3112. var obj = this.toplevelPagesDict.get('Count');
  3113. assert(
  3114. isInt(obj),
  3115. 'page count in top level pages object is not an integer'
  3116. );
  3117. // shadow the prototype getter
  3118. return shadow(this, 'num', obj);
  3119. },
  3120. get destinations() {
  3121. function fetchDestination(dest) {
  3122. return isDict(dest) ? dest.get('D') : dest;
  3123. }
  3124. var xref = this.xref;
  3125. var dests = {}, nameTreeRef, nameDictionaryRef;
  3126. var obj = this.catDict.get('Names');
  3127. if (obj && obj.has('Dests')) {
  3128. nameTreeRef = obj.getRaw('Dests');
  3129. } else if (this.catDict.has('Dests')) {
  3130. nameDictionaryRef = this.catDict.get('Dests');
  3131. }
  3132. if (nameDictionaryRef) {
  3133. // reading simple destination dictionary
  3134. obj = nameDictionaryRef;
  3135. obj.forEach(function catalogForEach(key, value) {
  3136. if (!value) {
  3137. return;
  3138. }
  3139. dests[key] = fetchDestination(value);
  3140. });
  3141. }
  3142. if (nameTreeRef) {
  3143. var nameTree = new NameTree(nameTreeRef, xref);
  3144. var names = nameTree.getAll();
  3145. for (var name in names) {
  3146. if (!names.hasOwnProperty(name)) {
  3147. continue;
  3148. }
  3149. dests[name] = fetchDestination(names[name]);
  3150. }
  3151. }
  3152. return shadow(this, 'destinations', dests);
  3153. },
  3154. getDestination: function Catalog_getDestination(destinationId) {
  3155. function fetchDestination(dest) {
  3156. return isDict(dest) ? dest.get('D') : dest;
  3157. }
  3158. var xref = this.xref;
  3159. var dest, nameTreeRef, nameDictionaryRef;
  3160. var obj = this.catDict.get('Names');
  3161. if (obj && obj.has('Dests')) {
  3162. nameTreeRef = obj.getRaw('Dests');
  3163. } else if (this.catDict.has('Dests')) {
  3164. nameDictionaryRef = this.catDict.get('Dests');
  3165. }
  3166. if (nameDictionaryRef) {
  3167. // reading simple destination dictionary
  3168. obj = nameDictionaryRef;
  3169. obj.forEach(function catalogForEach(key, value) {
  3170. if (!value) {
  3171. return;
  3172. }
  3173. if (key === destinationId) {
  3174. dest = fetchDestination(value);
  3175. }
  3176. });
  3177. }
  3178. if (nameTreeRef) {
  3179. var nameTree = new NameTree(nameTreeRef, xref);
  3180. dest = fetchDestination(nameTree.get(destinationId));
  3181. }
  3182. return dest;
  3183. },
  3184. get attachments() {
  3185. var xref = this.xref;
  3186. var attachments = null, nameTreeRef;
  3187. var obj = this.catDict.get('Names');
  3188. if (obj) {
  3189. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3190. }
  3191. if (nameTreeRef) {
  3192. var nameTree = new NameTree(nameTreeRef, xref);
  3193. var names = nameTree.getAll();
  3194. for (var name in names) {
  3195. if (!names.hasOwnProperty(name)) {
  3196. continue;
  3197. }
  3198. var fs = new FileSpec(names[name], xref);
  3199. if (!attachments) {
  3200. attachments = {};
  3201. }
  3202. attachments[stringToPDFString(name)] = fs.serializable;
  3203. }
  3204. }
  3205. return shadow(this, 'attachments', attachments);
  3206. },
  3207. get javaScript() {
  3208. var xref = this.xref;
  3209. var obj = this.catDict.get('Names');
  3210. var javaScript = [];
  3211. if (obj && obj.has('JavaScript')) {
  3212. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3213. var names = nameTree.getAll();
  3214. for (var name in names) {
  3215. if (!names.hasOwnProperty(name)) {
  3216. continue;
  3217. }
  3218. // We don't really use the JavaScript right now. This code is
  3219. // defensive so we don't cause errors on document load.
  3220. var jsDict = names[name];
  3221. if (!isDict(jsDict)) {
  3222. continue;
  3223. }
  3224. var type = jsDict.get('S');
  3225. if (!isName(type) || type.name !== 'JavaScript') {
  3226. continue;
  3227. }
  3228. var js = jsDict.get('JS');
  3229. if (!isString(js) && !isStream(js)) {
  3230. continue;
  3231. }
  3232. if (isStream(js)) {
  3233. js = bytesToString(js.getBytes());
  3234. }
  3235. javaScript.push(stringToPDFString(js));
  3236. }
  3237. }
  3238. // Append OpenAction actions to javaScript array
  3239. var openactionDict = this.catDict.get('OpenAction');
  3240. if (isDict(openactionDict)) {
  3241. var objType = openactionDict.get('Type');
  3242. var actionType = openactionDict.get('S');
  3243. var action = openactionDict.get('N');
  3244. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3245. isName(actionType) && actionType.name === 'Named' &&
  3246. isName(action) && action.name === 'Print');
  3247. if (isPrintAction) {
  3248. javaScript.push('print(true);');
  3249. }
  3250. }
  3251. return shadow(this, 'javaScript', javaScript);
  3252. },
  3253. cleanup: function Catalog_cleanup() {
  3254. var promises = [];
  3255. this.fontCache.forEach(function (promise) {
  3256. promises.push(promise);
  3257. });
  3258. return Promise.all(promises).then(function (translatedFonts) {
  3259. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3260. var font = translatedFonts[i].dict;
  3261. delete font.translated;
  3262. }
  3263. this.fontCache.clear();
  3264. }.bind(this));
  3265. },
  3266. getPage: function Catalog_getPage(pageIndex) {
  3267. if (!(pageIndex in this.pagePromises)) {
  3268. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3269. function (a) {
  3270. var dict = a[0];
  3271. var ref = a[1];
  3272. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3273. this.fontCache);
  3274. }.bind(this)
  3275. );
  3276. }
  3277. return this.pagePromises[pageIndex];
  3278. },
  3279. getPageDict: function Catalog_getPageDict(pageIndex) {
  3280. var capability = createPromiseCapability();
  3281. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3282. var currentPageIndex = 0;
  3283. var xref = this.xref;
  3284. var checkAllKids = false;
  3285. function next() {
  3286. while (nodesToVisit.length) {
  3287. var currentNode = nodesToVisit.pop();
  3288. if (isRef(currentNode)) {
  3289. xref.fetchAsync(currentNode).then(function (obj) {
  3290. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  3291. if (pageIndex === currentPageIndex) {
  3292. capability.resolve([obj, currentNode]);
  3293. } else {
  3294. currentPageIndex++;
  3295. next();
  3296. }
  3297. return;
  3298. }
  3299. nodesToVisit.push(obj);
  3300. next();
  3301. }, capability.reject);
  3302. return;
  3303. }
  3304. // Must be a child page dictionary.
  3305. assert(
  3306. isDict(currentNode),
  3307. 'page dictionary kid reference points to wrong type of object'
  3308. );
  3309. var count = currentNode.get('Count');
  3310. // If the current node doesn't have any children, avoid getting stuck
  3311. // in an empty node further down in the tree (see issue5644.pdf).
  3312. if (count === 0) {
  3313. checkAllKids = true;
  3314. }
  3315. // Skip nodes where the page can't be.
  3316. if (currentPageIndex + count <= pageIndex) {
  3317. currentPageIndex += count;
  3318. continue;
  3319. }
  3320. var kids = currentNode.get('Kids');
  3321. assert(isArray(kids), 'page dictionary kids object is not an array');
  3322. if (!checkAllKids && count === kids.length) {
  3323. // Nodes that don't have the page have been skipped and this is the
  3324. // bottom of the tree which means the page requested must be a
  3325. // descendant of this pages node. Ideally we would just resolve the
  3326. // promise with the page ref here, but there is the case where more
  3327. // pages nodes could link to single a page (see issue 3666 pdf). To
  3328. // handle this push it back on the queue so if it is a pages node it
  3329. // will be descended into.
  3330. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3331. currentPageIndex = pageIndex;
  3332. continue;
  3333. } else {
  3334. for (var last = kids.length - 1; last >= 0; last--) {
  3335. nodesToVisit.push(kids[last]);
  3336. }
  3337. }
  3338. }
  3339. capability.reject('Page index ' + pageIndex + ' not found.');
  3340. }
  3341. next();
  3342. return capability.promise;
  3343. },
  3344. getPageIndex: function Catalog_getPageIndex(ref) {
  3345. // The page tree nodes have the count of all the leaves below them. To get
  3346. // how many pages are before we just have to walk up the tree and keep
  3347. // adding the count of siblings to the left of the node.
  3348. var xref = this.xref;
  3349. function pagesBeforeRef(kidRef) {
  3350. var total = 0;
  3351. var parentRef;
  3352. return xref.fetchAsync(kidRef).then(function (node) {
  3353. if (!node) {
  3354. return null;
  3355. }
  3356. parentRef = node.getRaw('Parent');
  3357. return node.getAsync('Parent');
  3358. }).then(function (parent) {
  3359. if (!parent) {
  3360. return null;
  3361. }
  3362. return parent.getAsync('Kids');
  3363. }).then(function (kids) {
  3364. if (!kids) {
  3365. return null;
  3366. }
  3367. var kidPromises = [];
  3368. var found = false;
  3369. for (var i = 0; i < kids.length; i++) {
  3370. var kid = kids[i];
  3371. assert(isRef(kid), 'kids must be a ref');
  3372. if (kid.num === kidRef.num) {
  3373. found = true;
  3374. break;
  3375. }
  3376. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3377. if (kid.has('Count')) {
  3378. var count = kid.get('Count');
  3379. total += count;
  3380. } else { // page leaf node
  3381. total++;
  3382. }
  3383. }));
  3384. }
  3385. if (!found) {
  3386. error('kid ref not found in parents kids');
  3387. }
  3388. return Promise.all(kidPromises).then(function () {
  3389. return [total, parentRef];
  3390. });
  3391. });
  3392. }
  3393. var total = 0;
  3394. function next(ref) {
  3395. return pagesBeforeRef(ref).then(function (args) {
  3396. if (!args) {
  3397. return total;
  3398. }
  3399. var count = args[0];
  3400. var parentRef = args[1];
  3401. total += count;
  3402. return next(parentRef);
  3403. });
  3404. }
  3405. return next(ref);
  3406. }
  3407. };
  3408. return Catalog;
  3409. })();
  3410. var XRef = (function XRefClosure() {
  3411. function XRef(stream, password) {
  3412. this.stream = stream;
  3413. this.entries = [];
  3414. this.xrefstms = {};
  3415. // prepare the XRef cache
  3416. this.cache = [];
  3417. this.password = password;
  3418. this.stats = {
  3419. streamTypes: [],
  3420. fontTypes: []
  3421. };
  3422. }
  3423. XRef.prototype = {
  3424. setStartXRef: function XRef_setStartXRef(startXRef) {
  3425. // Store the starting positions of xref tables as we process them
  3426. // so we can recover from missing data errors
  3427. this.startXRefQueue = [startXRef];
  3428. },
  3429. parse: function XRef_parse(recoveryMode) {
  3430. var trailerDict;
  3431. if (!recoveryMode) {
  3432. trailerDict = this.readXRef();
  3433. } else {
  3434. warn('Indexing all PDF objects');
  3435. trailerDict = this.indexObjects();
  3436. }
  3437. trailerDict.assignXref(this);
  3438. this.trailer = trailerDict;
  3439. var encrypt = trailerDict.get('Encrypt');
  3440. if (encrypt) {
  3441. var ids = trailerDict.get('ID');
  3442. var fileId = (ids && ids.length) ? ids[0] : '';
  3443. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3444. this.password);
  3445. }
  3446. // get the root dictionary (catalog) object
  3447. if (!(this.root = trailerDict.get('Root'))) {
  3448. error('Invalid root reference');
  3449. }
  3450. },
  3451. processXRefTable: function XRef_processXRefTable(parser) {
  3452. if (!('tableState' in this)) {
  3453. // Stores state of the table as we process it so we can resume
  3454. // from middle of table in case of missing data error
  3455. this.tableState = {
  3456. entryNum: 0,
  3457. streamPos: parser.lexer.stream.pos,
  3458. parserBuf1: parser.buf1,
  3459. parserBuf2: parser.buf2
  3460. };
  3461. }
  3462. var obj = this.readXRefTable(parser);
  3463. // Sanity check
  3464. if (!isCmd(obj, 'trailer')) {
  3465. error('Invalid XRef table: could not find trailer dictionary');
  3466. }
  3467. // Read trailer dictionary, e.g.
  3468. // trailer
  3469. // << /Size 22
  3470. // /Root 20R
  3471. // /Info 10R
  3472. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3473. // >>
  3474. // The parser goes through the entire stream << ... >> and provides
  3475. // a getter interface for the key-value table
  3476. var dict = parser.getObj();
  3477. // The pdflib PDF generator can generate a nested trailer dictionary
  3478. if (!isDict(dict) && dict.dict) {
  3479. dict = dict.dict;
  3480. }
  3481. if (!isDict(dict)) {
  3482. error('Invalid XRef table: could not parse trailer dictionary');
  3483. }
  3484. delete this.tableState;
  3485. return dict;
  3486. },
  3487. readXRefTable: function XRef_readXRefTable(parser) {
  3488. // Example of cross-reference table:
  3489. // xref
  3490. // 0 1 <-- subsection header (first obj #, obj count)
  3491. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3492. // 23 2 <-- subsection header ... and so on ...
  3493. // 0000025518 00002 n
  3494. // 0000025635 00000 n
  3495. // trailer
  3496. // ...
  3497. var stream = parser.lexer.stream;
  3498. var tableState = this.tableState;
  3499. stream.pos = tableState.streamPos;
  3500. parser.buf1 = tableState.parserBuf1;
  3501. parser.buf2 = tableState.parserBuf2;
  3502. // Outer loop is over subsection headers
  3503. var obj;
  3504. while (true) {
  3505. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3506. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3507. break;
  3508. }
  3509. tableState.firstEntryNum = obj;
  3510. tableState.entryCount = parser.getObj();
  3511. }
  3512. var first = tableState.firstEntryNum;
  3513. var count = tableState.entryCount;
  3514. if (!isInt(first) || !isInt(count)) {
  3515. error('Invalid XRef table: wrong types in subsection header');
  3516. }
  3517. // Inner loop is over objects themselves
  3518. for (var i = tableState.entryNum; i < count; i++) {
  3519. tableState.streamPos = stream.pos;
  3520. tableState.entryNum = i;
  3521. tableState.parserBuf1 = parser.buf1;
  3522. tableState.parserBuf2 = parser.buf2;
  3523. var entry = {};
  3524. entry.offset = parser.getObj();
  3525. entry.gen = parser.getObj();
  3526. var type = parser.getObj();
  3527. if (isCmd(type, 'f')) {
  3528. entry.free = true;
  3529. } else if (isCmd(type, 'n')) {
  3530. entry.uncompressed = true;
  3531. }
  3532. // Validate entry obj
  3533. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3534. !(entry.free || entry.uncompressed)) {
  3535. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3536. }
  3537. if (!this.entries[i + first]) {
  3538. this.entries[i + first] = entry;
  3539. }
  3540. }
  3541. tableState.entryNum = 0;
  3542. tableState.streamPos = stream.pos;
  3543. tableState.parserBuf1 = parser.buf1;
  3544. tableState.parserBuf2 = parser.buf2;
  3545. delete tableState.firstEntryNum;
  3546. delete tableState.entryCount;
  3547. }
  3548. // Per issue 3248: hp scanners generate bad XRef
  3549. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3550. // shifting the entries
  3551. this.entries.shift();
  3552. }
  3553. // Sanity check: as per spec, first object must be free
  3554. if (this.entries[0] && !this.entries[0].free) {
  3555. error('Invalid XRef table: unexpected first object');
  3556. }
  3557. return obj;
  3558. },
  3559. processXRefStream: function XRef_processXRefStream(stream) {
  3560. if (!('streamState' in this)) {
  3561. // Stores state of the stream as we process it so we can resume
  3562. // from middle of stream in case of missing data error
  3563. var streamParameters = stream.dict;
  3564. var byteWidths = streamParameters.get('W');
  3565. var range = streamParameters.get('Index');
  3566. if (!range) {
  3567. range = [0, streamParameters.get('Size')];
  3568. }
  3569. this.streamState = {
  3570. entryRanges: range,
  3571. byteWidths: byteWidths,
  3572. entryNum: 0,
  3573. streamPos: stream.pos
  3574. };
  3575. }
  3576. this.readXRefStream(stream);
  3577. delete this.streamState;
  3578. return stream.dict;
  3579. },
  3580. readXRefStream: function XRef_readXRefStream(stream) {
  3581. var i, j;
  3582. var streamState = this.streamState;
  3583. stream.pos = streamState.streamPos;
  3584. var byteWidths = streamState.byteWidths;
  3585. var typeFieldWidth = byteWidths[0];
  3586. var offsetFieldWidth = byteWidths[1];
  3587. var generationFieldWidth = byteWidths[2];
  3588. var entryRanges = streamState.entryRanges;
  3589. while (entryRanges.length > 0) {
  3590. var first = entryRanges[0];
  3591. var n = entryRanges[1];
  3592. if (!isInt(first) || !isInt(n)) {
  3593. error('Invalid XRef range fields: ' + first + ', ' + n);
  3594. }
  3595. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3596. !isInt(generationFieldWidth)) {
  3597. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3598. }
  3599. for (i = streamState.entryNum; i < n; ++i) {
  3600. streamState.entryNum = i;
  3601. streamState.streamPos = stream.pos;
  3602. var type = 0, offset = 0, generation = 0;
  3603. for (j = 0; j < typeFieldWidth; ++j) {
  3604. type = (type << 8) | stream.getByte();
  3605. }
  3606. // if type field is absent, its default value is 1
  3607. if (typeFieldWidth === 0) {
  3608. type = 1;
  3609. }
  3610. for (j = 0; j < offsetFieldWidth; ++j) {
  3611. offset = (offset << 8) | stream.getByte();
  3612. }
  3613. for (j = 0; j < generationFieldWidth; ++j) {
  3614. generation = (generation << 8) | stream.getByte();
  3615. }
  3616. var entry = {};
  3617. entry.offset = offset;
  3618. entry.gen = generation;
  3619. switch (type) {
  3620. case 0:
  3621. entry.free = true;
  3622. break;
  3623. case 1:
  3624. entry.uncompressed = true;
  3625. break;
  3626. case 2:
  3627. break;
  3628. default:
  3629. error('Invalid XRef entry type: ' + type);
  3630. }
  3631. if (!this.entries[first + i]) {
  3632. this.entries[first + i] = entry;
  3633. }
  3634. }
  3635. streamState.entryNum = 0;
  3636. streamState.streamPos = stream.pos;
  3637. entryRanges.splice(0, 2);
  3638. }
  3639. },
  3640. indexObjects: function XRef_indexObjects() {
  3641. // Simple scan through the PDF content to find objects,
  3642. // trailers and XRef streams.
  3643. function readToken(data, offset) {
  3644. var token = '', ch = data[offset];
  3645. while (ch !== 13 && ch !== 10) {
  3646. if (++offset >= data.length) {
  3647. break;
  3648. }
  3649. token += String.fromCharCode(ch);
  3650. ch = data[offset];
  3651. }
  3652. return token;
  3653. }
  3654. function skipUntil(data, offset, what) {
  3655. var length = what.length, dataLength = data.length;
  3656. var skipped = 0;
  3657. // finding byte sequence
  3658. while (offset < dataLength) {
  3659. var i = 0;
  3660. while (i < length && data[offset + i] === what[i]) {
  3661. ++i;
  3662. }
  3663. if (i >= length) {
  3664. break; // sequence found
  3665. }
  3666. offset++;
  3667. skipped++;
  3668. }
  3669. return skipped;
  3670. }
  3671. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3672. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3673. 101, 102]);
  3674. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3675. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3676. var stream = this.stream;
  3677. stream.pos = 0;
  3678. var buffer = stream.getBytes();
  3679. var position = stream.start, length = buffer.length;
  3680. var trailers = [], xrefStms = [];
  3681. while (position < length) {
  3682. var ch = buffer[position];
  3683. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3684. ++position;
  3685. continue;
  3686. }
  3687. if (ch === 37) { // %-comment
  3688. do {
  3689. ++position;
  3690. if (position >= length) {
  3691. break;
  3692. }
  3693. ch = buffer[position];
  3694. } while (ch !== 13 && ch !== 10);
  3695. continue;
  3696. }
  3697. var token = readToken(buffer, position);
  3698. var m;
  3699. if (token === 'xref') {
  3700. position += skipUntil(buffer, position, trailerBytes);
  3701. trailers.push(position);
  3702. position += skipUntil(buffer, position, startxrefBytes);
  3703. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3704. if (typeof this.entries[m[1]] === 'undefined') {
  3705. this.entries[m[1]] = {
  3706. offset: position,
  3707. gen: m[2] | 0,
  3708. uncompressed: true
  3709. };
  3710. }
  3711. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3712. var content = buffer.subarray(position, position + contentLength);
  3713. // checking XRef stream suspect
  3714. // (it shall have '/XRef' and next char is not a letter)
  3715. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3716. if (xrefTagOffset < contentLength &&
  3717. content[xrefTagOffset + 5] < 64) {
  3718. xrefStms.push(position);
  3719. this.xrefstms[position] = 1; // don't read it recursively
  3720. }
  3721. position += contentLength;
  3722. } else {
  3723. position += token.length + 1;
  3724. }
  3725. }
  3726. // reading XRef streams
  3727. var i, ii;
  3728. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3729. this.startXRefQueue.push(xrefStms[i]);
  3730. this.readXRef(/* recoveryMode */ true);
  3731. }
  3732. // finding main trailer
  3733. var dict;
  3734. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3735. stream.pos = trailers[i];
  3736. var parser = new Parser(new Lexer(stream), true, this);
  3737. var obj = parser.getObj();
  3738. if (!isCmd(obj, 'trailer')) {
  3739. continue;
  3740. }
  3741. // read the trailer dictionary
  3742. if (!isDict(dict = parser.getObj())) {
  3743. continue;
  3744. }
  3745. // taking the first one with 'ID'
  3746. if (dict.has('ID')) {
  3747. return dict;
  3748. }
  3749. }
  3750. // no tailer with 'ID', taking last one (if exists)
  3751. if (dict) {
  3752. return dict;
  3753. }
  3754. // nothing helps
  3755. // calling error() would reject worker with an UnknownErrorException.
  3756. throw new InvalidPDFException('Invalid PDF structure');
  3757. },
  3758. readXRef: function XRef_readXRef(recoveryMode) {
  3759. var stream = this.stream;
  3760. try {
  3761. while (this.startXRefQueue.length) {
  3762. var startXRef = this.startXRefQueue[0];
  3763. stream.pos = startXRef + stream.start;
  3764. var parser = new Parser(new Lexer(stream), true, this);
  3765. var obj = parser.getObj();
  3766. var dict;
  3767. // Get dictionary
  3768. if (isCmd(obj, 'xref')) {
  3769. // Parse end-of-file XRef
  3770. dict = this.processXRefTable(parser);
  3771. if (!this.topDict) {
  3772. this.topDict = dict;
  3773. }
  3774. // Recursively get other XRefs 'XRefStm', if any
  3775. obj = dict.get('XRefStm');
  3776. if (isInt(obj)) {
  3777. var pos = obj;
  3778. // ignore previously loaded xref streams
  3779. // (possible infinite recursion)
  3780. if (!(pos in this.xrefstms)) {
  3781. this.xrefstms[pos] = 1;
  3782. this.startXRefQueue.push(pos);
  3783. }
  3784. }
  3785. } else if (isInt(obj)) {
  3786. // Parse in-stream XRef
  3787. if (!isInt(parser.getObj()) ||
  3788. !isCmd(parser.getObj(), 'obj') ||
  3789. !isStream(obj = parser.getObj())) {
  3790. error('Invalid XRef stream');
  3791. }
  3792. dict = this.processXRefStream(obj);
  3793. if (!this.topDict) {
  3794. this.topDict = dict;
  3795. }
  3796. if (!dict) {
  3797. error('Failed to read XRef stream');
  3798. }
  3799. } else {
  3800. error('Invalid XRef stream header');
  3801. }
  3802. // Recursively get previous dictionary, if any
  3803. obj = dict.get('Prev');
  3804. if (isInt(obj)) {
  3805. this.startXRefQueue.push(obj);
  3806. } else if (isRef(obj)) {
  3807. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3808. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3809. this.startXRefQueue.push(obj.num);
  3810. }
  3811. this.startXRefQueue.shift();
  3812. }
  3813. return this.topDict;
  3814. } catch (e) {
  3815. if (e instanceof MissingDataException) {
  3816. throw e;
  3817. }
  3818. info('(while reading XRef): ' + e);
  3819. }
  3820. if (recoveryMode) {
  3821. return;
  3822. }
  3823. throw new XRefParseException();
  3824. },
  3825. getEntry: function XRef_getEntry(i) {
  3826. var xrefEntry = this.entries[i];
  3827. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3828. return xrefEntry;
  3829. }
  3830. return null;
  3831. },
  3832. fetchIfRef: function XRef_fetchIfRef(obj) {
  3833. if (!isRef(obj)) {
  3834. return obj;
  3835. }
  3836. return this.fetch(obj);
  3837. },
  3838. fetch: function XRef_fetch(ref, suppressEncryption) {
  3839. assert(isRef(ref), 'ref object is not a reference');
  3840. var num = ref.num;
  3841. if (num in this.cache) {
  3842. var cacheEntry = this.cache[num];
  3843. return cacheEntry;
  3844. }
  3845. var xrefEntry = this.getEntry(num);
  3846. // the referenced entry can be free
  3847. if (xrefEntry === null) {
  3848. return (this.cache[num] = null);
  3849. }
  3850. if (xrefEntry.uncompressed) {
  3851. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3852. } else {
  3853. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3854. }
  3855. if (isDict(xrefEntry)){
  3856. xrefEntry.objId = ref.toString();
  3857. } else if (isStream(xrefEntry)) {
  3858. xrefEntry.dict.objId = ref.toString();
  3859. }
  3860. return xrefEntry;
  3861. },
  3862. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3863. suppressEncryption) {
  3864. var gen = ref.gen;
  3865. var num = ref.num;
  3866. if (xrefEntry.gen !== gen) {
  3867. error('inconsistent generation in XRef');
  3868. }
  3869. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3870. this.stream.start);
  3871. var parser = new Parser(new Lexer(stream), true, this);
  3872. var obj1 = parser.getObj();
  3873. var obj2 = parser.getObj();
  3874. var obj3 = parser.getObj();
  3875. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3876. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3877. !isCmd(obj3)) {
  3878. error('bad XRef entry');
  3879. }
  3880. if (!isCmd(obj3, 'obj')) {
  3881. // some bad PDFs use "obj1234" and really mean 1234
  3882. if (obj3.cmd.indexOf('obj') === 0) {
  3883. num = parseInt(obj3.cmd.substring(3), 10);
  3884. if (!isNaN(num)) {
  3885. return num;
  3886. }
  3887. }
  3888. error('bad XRef entry');
  3889. }
  3890. if (this.encrypt && !suppressEncryption) {
  3891. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3892. } else {
  3893. xrefEntry = parser.getObj();
  3894. }
  3895. if (!isStream(xrefEntry)) {
  3896. this.cache[num] = xrefEntry;
  3897. }
  3898. return xrefEntry;
  3899. },
  3900. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3901. suppressEncryption) {
  3902. var tableOffset = xrefEntry.offset;
  3903. var stream = this.fetch(new Ref(tableOffset, 0));
  3904. if (!isStream(stream)) {
  3905. error('bad ObjStm stream');
  3906. }
  3907. var first = stream.dict.get('First');
  3908. var n = stream.dict.get('N');
  3909. if (!isInt(first) || !isInt(n)) {
  3910. error('invalid first and n parameters for ObjStm stream');
  3911. }
  3912. var parser = new Parser(new Lexer(stream), false, this);
  3913. parser.allowStreams = true;
  3914. var i, entries = [], num, nums = [];
  3915. // read the object numbers to populate cache
  3916. for (i = 0; i < n; ++i) {
  3917. num = parser.getObj();
  3918. if (!isInt(num)) {
  3919. error('invalid object number in the ObjStm stream: ' + num);
  3920. }
  3921. nums.push(num);
  3922. var offset = parser.getObj();
  3923. if (!isInt(offset)) {
  3924. error('invalid object offset in the ObjStm stream: ' + offset);
  3925. }
  3926. }
  3927. // read stream objects for cache
  3928. for (i = 0; i < n; ++i) {
  3929. entries.push(parser.getObj());
  3930. num = nums[i];
  3931. var entry = this.entries[num];
  3932. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3933. this.cache[num] = entries[i];
  3934. }
  3935. }
  3936. xrefEntry = entries[xrefEntry.gen];
  3937. if (xrefEntry === undefined) {
  3938. error('bad XRef entry for compressed object');
  3939. }
  3940. return xrefEntry;
  3941. },
  3942. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3943. if (!isRef(obj)) {
  3944. return Promise.resolve(obj);
  3945. }
  3946. return this.fetchAsync(obj);
  3947. },
  3948. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3949. var streamManager = this.stream.manager;
  3950. var xref = this;
  3951. return new Promise(function tryFetch(resolve, reject) {
  3952. try {
  3953. resolve(xref.fetch(ref, suppressEncryption));
  3954. } catch (e) {
  3955. if (e instanceof MissingDataException) {
  3956. streamManager.requestRange(e.begin, e.end, function () {
  3957. tryFetch(resolve, reject);
  3958. });
  3959. return;
  3960. }
  3961. reject(e);
  3962. }
  3963. });
  3964. },
  3965. getCatalogObj: function XRef_getCatalogObj() {
  3966. return this.root;
  3967. }
  3968. };
  3969. return XRef;
  3970. })();
  3971. /**
  3972. * A NameTree is like a Dict but has some advantageous properties, see the
  3973. * spec (7.9.6) for more details.
  3974. * TODO: implement all the Dict functions and make this more efficent.
  3975. */
  3976. var NameTree = (function NameTreeClosure() {
  3977. function NameTree(root, xref) {
  3978. this.root = root;
  3979. this.xref = xref;
  3980. }
  3981. NameTree.prototype = {
  3982. getAll: function NameTree_getAll() {
  3983. var dict = {};
  3984. if (!this.root) {
  3985. return dict;
  3986. }
  3987. var xref = this.xref;
  3988. // reading name tree
  3989. var processed = new RefSet();
  3990. processed.put(this.root);
  3991. var queue = [this.root];
  3992. while (queue.length > 0) {
  3993. var i, n;
  3994. var obj = xref.fetchIfRef(queue.shift());
  3995. if (!isDict(obj)) {
  3996. continue;
  3997. }
  3998. if (obj.has('Kids')) {
  3999. var kids = obj.get('Kids');
  4000. for (i = 0, n = kids.length; i < n; i++) {
  4001. var kid = kids[i];
  4002. if (processed.has(kid)) {
  4003. error('invalid destinations');
  4004. }
  4005. queue.push(kid);
  4006. processed.put(kid);
  4007. }
  4008. continue;
  4009. }
  4010. var names = obj.get('Names');
  4011. if (names) {
  4012. for (i = 0, n = names.length; i < n; i += 2) {
  4013. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  4014. }
  4015. }
  4016. }
  4017. return dict;
  4018. },
  4019. get: function NameTree_get(destinationId) {
  4020. if (!this.root) {
  4021. return null;
  4022. }
  4023. var xref = this.xref;
  4024. var kidsOrNames = xref.fetchIfRef(this.root);
  4025. var loopCount = 0;
  4026. var MAX_NAMES_LEVELS = 10;
  4027. var l, r, m;
  4028. // Perform a binary search to quickly find the entry that
  4029. // contains the named destination we are looking for.
  4030. while (kidsOrNames.has('Kids')) {
  4031. loopCount++;
  4032. if (loopCount > MAX_NAMES_LEVELS) {
  4033. warn('Search depth limit for named destionations has been reached.');
  4034. return null;
  4035. }
  4036. var kids = kidsOrNames.get('Kids');
  4037. if (!isArray(kids)) {
  4038. return null;
  4039. }
  4040. l = 0;
  4041. r = kids.length - 1;
  4042. while (l <= r) {
  4043. m = (l + r) >> 1;
  4044. var kid = xref.fetchIfRef(kids[m]);
  4045. var limits = kid.get('Limits');
  4046. if (destinationId < limits[0]) {
  4047. r = m - 1;
  4048. } else if (destinationId > limits[1]) {
  4049. l = m + 1;
  4050. } else {
  4051. kidsOrNames = xref.fetchIfRef(kids[m]);
  4052. break;
  4053. }
  4054. }
  4055. if (l > r) {
  4056. return null;
  4057. }
  4058. }
  4059. // If we get here, then we have found the right entry. Now
  4060. // go through the named destinations in the Named dictionary
  4061. // until we find the exact destination we're looking for.
  4062. var names = kidsOrNames.get('Names');
  4063. if (isArray(names)) {
  4064. // Perform a binary search to reduce the lookup time.
  4065. l = 0;
  4066. r = names.length - 2;
  4067. while (l <= r) {
  4068. // Check only even indices (0, 2, 4, ...) because the
  4069. // odd indices contain the actual D array.
  4070. m = (l + r) & ~1;
  4071. if (destinationId < names[m]) {
  4072. r = m - 2;
  4073. } else if (destinationId > names[m]) {
  4074. l = m + 2;
  4075. } else {
  4076. return xref.fetchIfRef(names[m + 1]);
  4077. }
  4078. }
  4079. }
  4080. return null;
  4081. }
  4082. };
  4083. return NameTree;
  4084. })();
  4085. /**
  4086. * "A PDF file can refer to the contents of another file by using a File
  4087. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  4088. * NOTE: Only embedded files are supported (as part of the attachments support)
  4089. * TODO: support the 'URL' file system (with caching if !/V), portable
  4090. * collections attributes and related files (/RF)
  4091. */
  4092. var FileSpec = (function FileSpecClosure() {
  4093. function FileSpec(root, xref) {
  4094. if (!root || !isDict(root)) {
  4095. return;
  4096. }
  4097. this.xref = xref;
  4098. this.root = root;
  4099. if (root.has('FS')) {
  4100. this.fs = root.get('FS');
  4101. }
  4102. this.description = root.has('Desc') ?
  4103. stringToPDFString(root.get('Desc')) :
  4104. '';
  4105. if (root.has('RF')) {
  4106. warn('Related file specifications are not supported');
  4107. }
  4108. this.contentAvailable = true;
  4109. if (!root.has('EF')) {
  4110. this.contentAvailable = false;
  4111. warn('Non-embedded file specifications are not supported');
  4112. }
  4113. }
  4114. function pickPlatformItem(dict) {
  4115. // Look for the filename in this order:
  4116. // UF, F, Unix, Mac, DOS
  4117. if (dict.has('UF')) {
  4118. return dict.get('UF');
  4119. } else if (dict.has('F')) {
  4120. return dict.get('F');
  4121. } else if (dict.has('Unix')) {
  4122. return dict.get('Unix');
  4123. } else if (dict.has('Mac')) {
  4124. return dict.get('Mac');
  4125. } else if (dict.has('DOS')) {
  4126. return dict.get('DOS');
  4127. } else {
  4128. return null;
  4129. }
  4130. }
  4131. FileSpec.prototype = {
  4132. get filename() {
  4133. if (!this._filename && this.root) {
  4134. var filename = pickPlatformItem(this.root) || 'unnamed';
  4135. this._filename = stringToPDFString(filename).
  4136. replace(/\\\\/g, '\\').
  4137. replace(/\\\//g, '/').
  4138. replace(/\\/g, '/');
  4139. }
  4140. return this._filename;
  4141. },
  4142. get content() {
  4143. if (!this.contentAvailable) {
  4144. return null;
  4145. }
  4146. if (!this.contentRef && this.root) {
  4147. this.contentRef = pickPlatformItem(this.root.get('EF'));
  4148. }
  4149. var content = null;
  4150. if (this.contentRef) {
  4151. var xref = this.xref;
  4152. var fileObj = xref.fetchIfRef(this.contentRef);
  4153. if (fileObj && isStream(fileObj)) {
  4154. content = fileObj.getBytes();
  4155. } else {
  4156. warn('Embedded file specification points to non-existing/invalid ' +
  4157. 'content');
  4158. }
  4159. } else {
  4160. warn('Embedded file specification does not have a content');
  4161. }
  4162. return content;
  4163. },
  4164. get serializable() {
  4165. return {
  4166. filename: this.filename,
  4167. content: this.content
  4168. };
  4169. }
  4170. };
  4171. return FileSpec;
  4172. })();
  4173. /**
  4174. * A helper for loading missing data in object graphs. It traverses the graph
  4175. * depth first and queues up any objects that have missing data. Once it has
  4176. * has traversed as many objects that are available it attempts to bundle the
  4177. * missing data requests and then resume from the nodes that weren't ready.
  4178. *
  4179. * NOTE: It provides protection from circular references by keeping track of
  4180. * of loaded references. However, you must be careful not to load any graphs
  4181. * that have references to the catalog or other pages since that will cause the
  4182. * entire PDF document object graph to be traversed.
  4183. */
  4184. var ObjectLoader = (function() {
  4185. function mayHaveChildren(value) {
  4186. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  4187. }
  4188. function addChildren(node, nodesToVisit) {
  4189. var value;
  4190. if (isDict(node) || isStream(node)) {
  4191. var map;
  4192. if (isDict(node)) {
  4193. map = node.map;
  4194. } else {
  4195. map = node.dict.map;
  4196. }
  4197. for (var key in map) {
  4198. value = map[key];
  4199. if (mayHaveChildren(value)) {
  4200. nodesToVisit.push(value);
  4201. }
  4202. }
  4203. } else if (isArray(node)) {
  4204. for (var i = 0, ii = node.length; i < ii; i++) {
  4205. value = node[i];
  4206. if (mayHaveChildren(value)) {
  4207. nodesToVisit.push(value);
  4208. }
  4209. }
  4210. }
  4211. }
  4212. function ObjectLoader(obj, keys, xref) {
  4213. this.obj = obj;
  4214. this.keys = keys;
  4215. this.xref = xref;
  4216. this.refSet = null;
  4217. }
  4218. ObjectLoader.prototype = {
  4219. load: function ObjectLoader_load() {
  4220. var keys = this.keys;
  4221. this.capability = createPromiseCapability();
  4222. // Don't walk the graph if all the data is already loaded.
  4223. if (!(this.xref.stream instanceof ChunkedStream) ||
  4224. this.xref.stream.getMissingChunks().length === 0) {
  4225. this.capability.resolve();
  4226. return this.capability.promise;
  4227. }
  4228. this.refSet = new RefSet();
  4229. // Setup the initial nodes to visit.
  4230. var nodesToVisit = [];
  4231. for (var i = 0; i < keys.length; i++) {
  4232. nodesToVisit.push(this.obj[keys[i]]);
  4233. }
  4234. this.walk(nodesToVisit);
  4235. return this.capability.promise;
  4236. },
  4237. walk: function ObjectLoader_walk(nodesToVisit) {
  4238. var nodesToRevisit = [];
  4239. var pendingRequests = [];
  4240. // DFS walk of the object graph.
  4241. while (nodesToVisit.length) {
  4242. var currentNode = nodesToVisit.pop();
  4243. // Only references or chunked streams can cause missing data exceptions.
  4244. if (isRef(currentNode)) {
  4245. // Skip nodes that have already been visited.
  4246. if (this.refSet.has(currentNode)) {
  4247. continue;
  4248. }
  4249. try {
  4250. var ref = currentNode;
  4251. this.refSet.put(ref);
  4252. currentNode = this.xref.fetch(currentNode);
  4253. } catch (e) {
  4254. if (!(e instanceof MissingDataException)) {
  4255. throw e;
  4256. }
  4257. nodesToRevisit.push(currentNode);
  4258. pendingRequests.push({ begin: e.begin, end: e.end });
  4259. }
  4260. }
  4261. if (currentNode && currentNode.getBaseStreams) {
  4262. var baseStreams = currentNode.getBaseStreams();
  4263. var foundMissingData = false;
  4264. for (var i = 0; i < baseStreams.length; i++) {
  4265. var stream = baseStreams[i];
  4266. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4267. foundMissingData = true;
  4268. pendingRequests.push({
  4269. begin: stream.start,
  4270. end: stream.end
  4271. });
  4272. }
  4273. }
  4274. if (foundMissingData) {
  4275. nodesToRevisit.push(currentNode);
  4276. }
  4277. }
  4278. addChildren(currentNode, nodesToVisit);
  4279. }
  4280. if (pendingRequests.length) {
  4281. this.xref.stream.manager.requestRanges(pendingRequests,
  4282. function pendingRequestCallback() {
  4283. nodesToVisit = nodesToRevisit;
  4284. for (var i = 0; i < nodesToRevisit.length; i++) {
  4285. var node = nodesToRevisit[i];
  4286. // Remove any reference nodes from the currrent refset so they
  4287. // aren't skipped when we revist them.
  4288. if (isRef(node)) {
  4289. this.refSet.remove(node);
  4290. }
  4291. }
  4292. this.walk(nodesToVisit);
  4293. }.bind(this));
  4294. return;
  4295. }
  4296. // Everything is loaded.
  4297. this.refSet = null;
  4298. this.capability.resolve();
  4299. }
  4300. };
  4301. return ObjectLoader;
  4302. })();
  4303. var ISOAdobeCharset = [
  4304. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4305. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4306. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4307. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4308. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4309. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4310. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4311. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4312. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4313. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4314. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4315. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4316. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4317. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4318. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4319. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4320. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4321. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4322. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4323. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4324. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4325. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4326. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4327. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4328. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4329. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4330. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4331. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4332. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4333. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4334. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4335. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4336. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4337. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4338. ];
  4339. var ExpertCharset = [
  4340. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4341. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4342. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4343. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4344. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4345. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4346. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4347. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4348. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4349. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4350. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4351. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4352. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4353. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4354. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4355. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4356. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4357. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4358. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4359. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4360. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4361. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4362. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4363. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4364. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4365. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4366. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4367. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4368. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4369. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4370. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4371. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4372. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4373. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4374. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4375. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4376. 'Ydieresissmall'
  4377. ];
  4378. var ExpertSubsetCharset = [
  4379. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4380. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4381. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4382. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4383. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4384. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4385. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4386. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4387. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4388. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4389. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4390. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4391. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4392. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4393. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4394. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4395. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4396. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4397. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4398. 'periodinferior', 'commainferior'
  4399. ];
  4400. var DEFAULT_ICON_SIZE = 22; // px
  4401. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4402. var Annotation = (function AnnotationClosure() {
  4403. // 12.5.5: Algorithm: Appearance streams
  4404. function getTransformMatrix(rect, bbox, matrix) {
  4405. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4406. var minX = bounds[0];
  4407. var minY = bounds[1];
  4408. var maxX = bounds[2];
  4409. var maxY = bounds[3];
  4410. if (minX === maxX || minY === maxY) {
  4411. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4412. // just apply the transform for rect
  4413. return [1, 0, 0, 1, rect[0], rect[1]];
  4414. }
  4415. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4416. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4417. return [
  4418. xRatio,
  4419. 0,
  4420. 0,
  4421. yRatio,
  4422. rect[0] - minX * xRatio,
  4423. rect[1] - minY * yRatio
  4424. ];
  4425. }
  4426. function getDefaultAppearance(dict) {
  4427. var appearanceState = dict.get('AP');
  4428. if (!isDict(appearanceState)) {
  4429. return;
  4430. }
  4431. var appearance;
  4432. var appearances = appearanceState.get('N');
  4433. if (isDict(appearances)) {
  4434. var as = dict.get('AS');
  4435. if (as && appearances.has(as.name)) {
  4436. appearance = appearances.get(as.name);
  4437. }
  4438. } else {
  4439. appearance = appearances;
  4440. }
  4441. return appearance;
  4442. }
  4443. function Annotation(params) {
  4444. var dict = params.dict;
  4445. var data = this.data = {};
  4446. data.subtype = dict.get('Subtype').name;
  4447. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4448. data.rect = Util.normalizeRect(rect);
  4449. data.annotationFlags = dict.get('F');
  4450. var color = dict.get('C');
  4451. if (!color) {
  4452. // The PDF spec does not mention how a missing color array is interpreted.
  4453. // Adobe Reader seems to default to black in this case.
  4454. data.color = [0, 0, 0];
  4455. } else if (isArray(color)) {
  4456. switch (color.length) {
  4457. case 0:
  4458. // Empty array denotes transparent border.
  4459. data.color = null;
  4460. break;
  4461. case 1:
  4462. // TODO: implement DeviceGray
  4463. break;
  4464. case 3:
  4465. data.color = color;
  4466. break;
  4467. case 4:
  4468. // TODO: implement DeviceCMYK
  4469. break;
  4470. }
  4471. }
  4472. this.borderStyle = data.borderStyle = new AnnotationBorderStyle();
  4473. this.setBorderStyle(dict);
  4474. this.appearance = getDefaultAppearance(dict);
  4475. data.hasAppearance = !!this.appearance;
  4476. data.id = params.ref.num;
  4477. }
  4478. Annotation.prototype = {
  4479. /**
  4480. * Set the border style (as AnnotationBorderStyle object).
  4481. *
  4482. * @public
  4483. * @memberof Annotation
  4484. * @param {Dict} borderStyle - The border style dictionary
  4485. */
  4486. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  4487. if (!isDict(borderStyle)) {
  4488. return;
  4489. }
  4490. if (borderStyle.has('BS')) {
  4491. var dict = borderStyle.get('BS');
  4492. var dictType;
  4493. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  4494. dictType.name === 'Border')) {
  4495. this.borderStyle.setWidth(dict.get('W'));
  4496. this.borderStyle.setStyle(dict.get('S'));
  4497. this.borderStyle.setDashArray(dict.get('D'));
  4498. }
  4499. } else if (borderStyle.has('Border')) {
  4500. var array = borderStyle.get('Border');
  4501. if (isArray(array) && array.length >= 3) {
  4502. this.borderStyle.setHorizontalCornerRadius(array[0]);
  4503. this.borderStyle.setVerticalCornerRadius(array[1]);
  4504. this.borderStyle.setWidth(array[2]);
  4505. this.borderStyle.setStyle('S');
  4506. if (array.length === 4) { // Dash array available
  4507. this.borderStyle.setDashArray(array[3]);
  4508. }
  4509. }
  4510. }
  4511. },
  4512. getData: function Annotation_getData() {
  4513. return this.data;
  4514. },
  4515. isInvisible: function Annotation_isInvisible() {
  4516. var data = this.data;
  4517. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4518. return false;
  4519. } else {
  4520. return !!(data &&
  4521. data.annotationFlags && // Default: not invisible
  4522. data.annotationFlags & 0x1); // Invisible
  4523. }
  4524. },
  4525. isViewable: function Annotation_isViewable() {
  4526. var data = this.data;
  4527. return !!(!this.isInvisible() &&
  4528. data &&
  4529. (!data.annotationFlags ||
  4530. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4531. data.rect); // rectangle is necessary
  4532. },
  4533. isPrintable: function Annotation_isPrintable() {
  4534. var data = this.data;
  4535. return !!(!this.isInvisible() &&
  4536. data &&
  4537. data.annotationFlags && // Default: not printable
  4538. data.annotationFlags & 0x4 && // Print
  4539. !(data.annotationFlags & 0x2) && // Hidden
  4540. data.rect); // rectangle is necessary
  4541. },
  4542. loadResources: function Annotation_loadResources(keys) {
  4543. return new Promise(function (resolve, reject) {
  4544. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4545. if (!resources) {
  4546. resolve();
  4547. return;
  4548. }
  4549. var objectLoader = new ObjectLoader(resources.map,
  4550. keys,
  4551. resources.xref);
  4552. objectLoader.load().then(function() {
  4553. resolve(resources);
  4554. }, reject);
  4555. }, reject);
  4556. }.bind(this));
  4557. },
  4558. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4559. if (!this.appearance) {
  4560. return Promise.resolve(new OperatorList());
  4561. }
  4562. var data = this.data;
  4563. var appearanceDict = this.appearance.dict;
  4564. var resourcesPromise = this.loadResources([
  4565. 'ExtGState',
  4566. 'ColorSpace',
  4567. 'Pattern',
  4568. 'Shading',
  4569. 'XObject',
  4570. 'Font'
  4571. // ProcSet
  4572. // Properties
  4573. ]);
  4574. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4575. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4576. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4577. var self = this;
  4578. return resourcesPromise.then(function(resources) {
  4579. var opList = new OperatorList();
  4580. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4581. return evaluator.getOperatorList(self.appearance, resources, opList).
  4582. then(function () {
  4583. opList.addOp(OPS.endAnnotation, []);
  4584. self.appearance.reset();
  4585. return opList;
  4586. });
  4587. });
  4588. }
  4589. };
  4590. Annotation.getConstructor =
  4591. function Annotation_getConstructor(subtype, fieldType) {
  4592. if (!subtype) {
  4593. return;
  4594. }
  4595. // TODO(mack): Implement FreeText annotations
  4596. if (subtype === 'Link') {
  4597. return LinkAnnotation;
  4598. } else if (subtype === 'Text') {
  4599. return TextAnnotation;
  4600. } else if (subtype === 'Widget') {
  4601. if (!fieldType) {
  4602. return;
  4603. }
  4604. if (fieldType === 'Tx') {
  4605. return TextWidgetAnnotation;
  4606. } else {
  4607. return WidgetAnnotation;
  4608. }
  4609. } else {
  4610. return Annotation;
  4611. }
  4612. };
  4613. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4614. var dict = xref.fetchIfRef(ref);
  4615. if (!isDict(dict)) {
  4616. return;
  4617. }
  4618. var subtype = dict.get('Subtype');
  4619. subtype = isName(subtype) ? subtype.name : '';
  4620. if (!subtype) {
  4621. return;
  4622. }
  4623. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4624. fieldType = isName(fieldType) ? fieldType.name : '';
  4625. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4626. if (!Constructor) {
  4627. return;
  4628. }
  4629. var params = {
  4630. dict: dict,
  4631. ref: ref,
  4632. };
  4633. var annotation = new Constructor(params);
  4634. if (annotation.isViewable() || annotation.isPrintable()) {
  4635. return annotation;
  4636. } else {
  4637. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4638. warn('unimplemented annotation type: ' + subtype);
  4639. }
  4640. }
  4641. };
  4642. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4643. annotations, opList, pdfManager, partialEvaluator, intent) {
  4644. function reject(e) {
  4645. annotationsReadyCapability.reject(e);
  4646. }
  4647. var annotationsReadyCapability = createPromiseCapability();
  4648. var annotationPromises = [];
  4649. for (var i = 0, n = annotations.length; i < n; ++i) {
  4650. if (intent === 'display' && annotations[i].isViewable() ||
  4651. intent === 'print' && annotations[i].isPrintable()) {
  4652. annotationPromises.push(
  4653. annotations[i].getOperatorList(partialEvaluator));
  4654. }
  4655. }
  4656. Promise.all(annotationPromises).then(function(datas) {
  4657. opList.addOp(OPS.beginAnnotations, []);
  4658. for (var i = 0, n = datas.length; i < n; ++i) {
  4659. var annotOpList = datas[i];
  4660. opList.addOpList(annotOpList);
  4661. }
  4662. opList.addOp(OPS.endAnnotations, []);
  4663. annotationsReadyCapability.resolve();
  4664. }, reject);
  4665. return annotationsReadyCapability.promise;
  4666. };
  4667. return Annotation;
  4668. })();
  4669. /**
  4670. * Contains all data regarding an annotation's border style.
  4671. *
  4672. * @class
  4673. */
  4674. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  4675. /**
  4676. * @constructor
  4677. * @private
  4678. */
  4679. function AnnotationBorderStyle() {
  4680. this.width = 1;
  4681. this.style = AnnotationBorderStyleType.SOLID;
  4682. this.dashArray = [3];
  4683. this.horizontalCornerRadius = 0;
  4684. this.verticalCornerRadius = 0;
  4685. }
  4686. AnnotationBorderStyle.prototype = {
  4687. /**
  4688. * Set the width.
  4689. *
  4690. * @public
  4691. * @memberof AnnotationBorderStyle
  4692. * @param {integer} width - The width
  4693. */
  4694. setWidth: function AnnotationBorderStyle_setWidth(width) {
  4695. if (width === (width | 0)) {
  4696. this.width = width;
  4697. }
  4698. },
  4699. /**
  4700. * Set the style.
  4701. *
  4702. * @public
  4703. * @memberof AnnotationBorderStyle
  4704. * @param {Object} style - The style object
  4705. * @see {@link shared/util.js}
  4706. */
  4707. setStyle: function AnnotationBorderStyle_setStyle(style) {
  4708. if (!style) {
  4709. return;
  4710. }
  4711. switch (style.name) {
  4712. case 'S':
  4713. this.style = AnnotationBorderStyleType.SOLID;
  4714. break;
  4715. case 'D':
  4716. this.style = AnnotationBorderStyleType.DASHED;
  4717. break;
  4718. case 'B':
  4719. this.style = AnnotationBorderStyleType.BEVELED;
  4720. break;
  4721. case 'I':
  4722. this.style = AnnotationBorderStyleType.INSET;
  4723. break;
  4724. case 'U':
  4725. this.style = AnnotationBorderStyleType.UNDERLINE;
  4726. break;
  4727. default:
  4728. break;
  4729. }
  4730. },
  4731. /**
  4732. * Set the dash array.
  4733. *
  4734. * @public
  4735. * @memberof AnnotationBorderStyle
  4736. * @param {Array} dashArray - The dash array with at least one element
  4737. */
  4738. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  4739. // We validate the dash array, but we do not use it because CSS does not
  4740. // allow us to change spacing of dashes. For more information, visit
  4741. // http://www.w3.org/TR/css3-background/#the-border-style.
  4742. if (isArray(dashArray) && dashArray.length > 0) {
  4743. // According to the PDF specification: the elements in a dashArray
  4744. // shall be numbers that are nonnegative and not all equal to zero.
  4745. var isValid = true;
  4746. var allZeros = true;
  4747. for (var i = 0, len = dashArray.length; i < len; i++) {
  4748. var element = dashArray[i];
  4749. var validNumber = (+element >= 0);
  4750. if (!validNumber) {
  4751. isValid = false;
  4752. break;
  4753. } else if (element > 0) {
  4754. allZeros = false;
  4755. }
  4756. }
  4757. if (isValid && !allZeros) {
  4758. this.dashArray = dashArray;
  4759. } else {
  4760. this.width = 0; // Adobe behavior when the array is invalid.
  4761. }
  4762. } else if (dashArray) {
  4763. this.width = 0; // Adobe behavior when the array is invalid.
  4764. }
  4765. },
  4766. /**
  4767. * Set the horizontal corner radius (from a Border dictionary).
  4768. *
  4769. * @public
  4770. * @memberof AnnotationBorderStyle
  4771. * @param {integer} radius - The horizontal corner radius
  4772. */
  4773. setHorizontalCornerRadius:
  4774. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  4775. if (radius === (radius | 0)) {
  4776. this.horizontalCornerRadius = radius;
  4777. }
  4778. },
  4779. /**
  4780. * Set the vertical corner radius (from a Border dictionary).
  4781. *
  4782. * @public
  4783. * @memberof AnnotationBorderStyle
  4784. * @param {integer} radius - The vertical corner radius
  4785. */
  4786. setVerticalCornerRadius:
  4787. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  4788. if (radius === (radius | 0)) {
  4789. this.verticalCornerRadius = radius;
  4790. }
  4791. }
  4792. };
  4793. return AnnotationBorderStyle;
  4794. })();
  4795. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4796. function WidgetAnnotation(params) {
  4797. Annotation.call(this, params);
  4798. var dict = params.dict;
  4799. var data = this.data;
  4800. data.fieldValue = stringToPDFString(
  4801. Util.getInheritableProperty(dict, 'V') || '');
  4802. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4803. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4804. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4805. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4806. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4807. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4808. // Building the full field name by collecting the field and
  4809. // its ancestors 'T' data and joining them using '.'.
  4810. var fieldName = [];
  4811. var namedItem = dict;
  4812. var ref = params.ref;
  4813. while (namedItem) {
  4814. var parent = namedItem.get('Parent');
  4815. var parentRef = namedItem.getRaw('Parent');
  4816. var name = namedItem.get('T');
  4817. if (name) {
  4818. fieldName.unshift(stringToPDFString(name));
  4819. } else if (parent && ref) {
  4820. // The field name is absent, that means more than one field
  4821. // with the same name may exist. Replacing the empty name
  4822. // with the '`' plus index in the parent's 'Kids' array.
  4823. // This is not in the PDF spec but necessary to id the
  4824. // the input controls.
  4825. var kids = parent.get('Kids');
  4826. var j, jj;
  4827. for (j = 0, jj = kids.length; j < jj; j++) {
  4828. var kidRef = kids[j];
  4829. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  4830. break;
  4831. }
  4832. }
  4833. fieldName.unshift('`' + j);
  4834. }
  4835. namedItem = parent;
  4836. ref = parentRef;
  4837. }
  4838. data.fullName = fieldName.join('.');
  4839. }
  4840. var parent = Annotation.prototype;
  4841. Util.inherit(WidgetAnnotation, Annotation, {
  4842. isViewable: function WidgetAnnotation_isViewable() {
  4843. if (this.data.fieldType === 'Sig') {
  4844. warn('unimplemented annotation type: Widget signature');
  4845. return false;
  4846. }
  4847. return parent.isViewable.call(this);
  4848. }
  4849. });
  4850. return WidgetAnnotation;
  4851. })();
  4852. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4853. function TextWidgetAnnotation(params) {
  4854. WidgetAnnotation.call(this, params);
  4855. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4856. this.data.annotationType = AnnotationType.WIDGET;
  4857. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4858. }
  4859. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4860. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4861. if (this.appearance) {
  4862. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4863. }
  4864. var opList = new OperatorList();
  4865. var data = this.data;
  4866. // Even if there is an appearance stream, ignore it. This is the
  4867. // behaviour used by Adobe Reader.
  4868. if (!data.defaultAppearance) {
  4869. return Promise.resolve(opList);
  4870. }
  4871. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4872. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4873. then(function () {
  4874. return opList;
  4875. });
  4876. }
  4877. });
  4878. return TextWidgetAnnotation;
  4879. })();
  4880. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4881. function InteractiveAnnotation(params) {
  4882. Annotation.call(this, params);
  4883. this.data.hasHtml = true;
  4884. }
  4885. Util.inherit(InteractiveAnnotation, Annotation, { });
  4886. return InteractiveAnnotation;
  4887. })();
  4888. var TextAnnotation = (function TextAnnotationClosure() {
  4889. function TextAnnotation(params) {
  4890. InteractiveAnnotation.call(this, params);
  4891. var dict = params.dict;
  4892. var data = this.data;
  4893. var content = dict.get('Contents');
  4894. var title = dict.get('T');
  4895. data.annotationType = AnnotationType.TEXT;
  4896. data.content = stringToPDFString(content || '');
  4897. data.title = stringToPDFString(title || '');
  4898. if (data.hasAppearance) {
  4899. data.name = 'NoIcon';
  4900. } else {
  4901. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4902. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4903. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4904. }
  4905. if (dict.has('C')) {
  4906. data.hasBgColor = true;
  4907. }
  4908. }
  4909. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4910. return TextAnnotation;
  4911. })();
  4912. var LinkAnnotation = (function LinkAnnotationClosure() {
  4913. function LinkAnnotation(params) {
  4914. InteractiveAnnotation.call(this, params);
  4915. var dict = params.dict;
  4916. var data = this.data;
  4917. data.annotationType = AnnotationType.LINK;
  4918. var action = dict.get('A');
  4919. if (action && isDict(action)) {
  4920. var linkType = action.get('S').name;
  4921. if (linkType === 'URI') {
  4922. var url = action.get('URI');
  4923. if (isName(url)) {
  4924. // Some bad PDFs do not put parentheses around relative URLs.
  4925. url = '/' + url.name;
  4926. } else if (url) {
  4927. url = addDefaultProtocolToUrl(url);
  4928. }
  4929. // TODO: pdf spec mentions urls can be relative to a Base
  4930. // entry in the dictionary.
  4931. if (!isValidUrl(url, false)) {
  4932. url = '';
  4933. }
  4934. // According to ISO 32000-1:2008, section 12.6.4.7,
  4935. // URI should to be encoded in 7-bit ASCII.
  4936. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  4937. try {
  4938. data.url = stringToUTF8String(url);
  4939. } catch (e) {
  4940. // Fall back to a simple copy.
  4941. data.url = url;
  4942. }
  4943. } else if (linkType === 'GoTo') {
  4944. data.dest = action.get('D');
  4945. } else if (linkType === 'GoToR') {
  4946. var urlDict = action.get('F');
  4947. if (isDict(urlDict)) {
  4948. // We assume that the 'url' is a Filspec dictionary
  4949. // and fetch the url without checking any further
  4950. url = urlDict.get('F') || '';
  4951. }
  4952. // TODO: pdf reference says that GoToR
  4953. // can also have 'NewWindow' attribute
  4954. if (!isValidUrl(url, false)) {
  4955. url = '';
  4956. }
  4957. data.url = url;
  4958. data.dest = action.get('D');
  4959. } else if (linkType === 'Named') {
  4960. data.action = action.get('N').name;
  4961. } else {
  4962. warn('unrecognized link type: ' + linkType);
  4963. }
  4964. } else if (dict.has('Dest')) {
  4965. // simple destination link
  4966. var dest = dict.get('Dest');
  4967. data.dest = isName(dest) ? dest.name : dest;
  4968. }
  4969. }
  4970. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4971. function addDefaultProtocolToUrl(url) {
  4972. if (url && url.indexOf('www.') === 0) {
  4973. return ('http://' + url);
  4974. }
  4975. return url;
  4976. }
  4977. Util.inherit(LinkAnnotation, InteractiveAnnotation, { });
  4978. return LinkAnnotation;
  4979. })();
  4980. var PDFFunction = (function PDFFunctionClosure() {
  4981. var CONSTRUCT_SAMPLED = 0;
  4982. var CONSTRUCT_INTERPOLATED = 2;
  4983. var CONSTRUCT_STICHED = 3;
  4984. var CONSTRUCT_POSTSCRIPT = 4;
  4985. return {
  4986. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4987. str) {
  4988. var i, ii;
  4989. var length = 1;
  4990. for (i = 0, ii = size.length; i < ii; i++) {
  4991. length *= size[i];
  4992. }
  4993. length *= outputSize;
  4994. var array = new Array(length);
  4995. var codeSize = 0;
  4996. var codeBuf = 0;
  4997. // 32 is a valid bps so shifting won't work
  4998. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4999. var strBytes = str.getBytes((length * bps + 7) / 8);
  5000. var strIdx = 0;
  5001. for (i = 0; i < length; i++) {
  5002. while (codeSize < bps) {
  5003. codeBuf <<= 8;
  5004. codeBuf |= strBytes[strIdx++];
  5005. codeSize += 8;
  5006. }
  5007. codeSize -= bps;
  5008. array[i] = (codeBuf >> codeSize) * sampleMul;
  5009. codeBuf &= (1 << codeSize) - 1;
  5010. }
  5011. return array;
  5012. },
  5013. getIR: function PDFFunction_getIR(xref, fn) {
  5014. var dict = fn.dict;
  5015. if (!dict) {
  5016. dict = fn;
  5017. }
  5018. var types = [this.constructSampled,
  5019. null,
  5020. this.constructInterpolated,
  5021. this.constructStiched,
  5022. this.constructPostScript];
  5023. var typeNum = dict.get('FunctionType');
  5024. var typeFn = types[typeNum];
  5025. if (!typeFn) {
  5026. error('Unknown type of function');
  5027. }
  5028. return typeFn.call(this, fn, dict, xref);
  5029. },
  5030. fromIR: function PDFFunction_fromIR(IR) {
  5031. var type = IR[0];
  5032. switch (type) {
  5033. case CONSTRUCT_SAMPLED:
  5034. return this.constructSampledFromIR(IR);
  5035. case CONSTRUCT_INTERPOLATED:
  5036. return this.constructInterpolatedFromIR(IR);
  5037. case CONSTRUCT_STICHED:
  5038. return this.constructStichedFromIR(IR);
  5039. //case CONSTRUCT_POSTSCRIPT:
  5040. default:
  5041. return this.constructPostScriptFromIR(IR);
  5042. }
  5043. },
  5044. parse: function PDFFunction_parse(xref, fn) {
  5045. var IR = this.getIR(xref, fn);
  5046. return this.fromIR(IR);
  5047. },
  5048. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  5049. if (!isArray(fnObj)) {
  5050. // not an array -- parsing as regular function
  5051. return this.parse(xref, fnObj);
  5052. }
  5053. var fnArray = [];
  5054. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  5055. var obj = xref.fetchIfRef(fnObj[j]);
  5056. fnArray.push(PDFFunction.parse(xref, obj));
  5057. }
  5058. return function (src, srcOffset, dest, destOffset) {
  5059. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  5060. fnArray[i](src, srcOffset, dest, destOffset + i);
  5061. }
  5062. };
  5063. },
  5064. constructSampled: function PDFFunction_constructSampled(str, dict) {
  5065. function toMultiArray(arr) {
  5066. var inputLength = arr.length;
  5067. var out = [];
  5068. var index = 0;
  5069. for (var i = 0; i < inputLength; i += 2) {
  5070. out[index] = [arr[i], arr[i + 1]];
  5071. ++index;
  5072. }
  5073. return out;
  5074. }
  5075. var domain = dict.get('Domain');
  5076. var range = dict.get('Range');
  5077. if (!domain || !range) {
  5078. error('No domain or range');
  5079. }
  5080. var inputSize = domain.length / 2;
  5081. var outputSize = range.length / 2;
  5082. domain = toMultiArray(domain);
  5083. range = toMultiArray(range);
  5084. var size = dict.get('Size');
  5085. var bps = dict.get('BitsPerSample');
  5086. var order = dict.get('Order') || 1;
  5087. if (order !== 1) {
  5088. // No description how cubic spline interpolation works in PDF32000:2008
  5089. // As in poppler, ignoring order, linear interpolation may work as good
  5090. info('No support for cubic spline interpolation: ' + order);
  5091. }
  5092. var encode = dict.get('Encode');
  5093. if (!encode) {
  5094. encode = [];
  5095. for (var i = 0; i < inputSize; ++i) {
  5096. encode.push(0);
  5097. encode.push(size[i] - 1);
  5098. }
  5099. }
  5100. encode = toMultiArray(encode);
  5101. var decode = dict.get('Decode');
  5102. if (!decode) {
  5103. decode = range;
  5104. } else {
  5105. decode = toMultiArray(decode);
  5106. }
  5107. var samples = this.getSampleArray(size, outputSize, bps, str);
  5108. return [
  5109. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  5110. outputSize, Math.pow(2, bps) - 1, range
  5111. ];
  5112. },
  5113. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  5114. // See chapter 3, page 109 of the PDF reference
  5115. function interpolate(x, xmin, xmax, ymin, ymax) {
  5116. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  5117. }
  5118. return function constructSampledFromIRResult(src, srcOffset,
  5119. dest, destOffset) {
  5120. // See chapter 3, page 110 of the PDF reference.
  5121. var m = IR[1];
  5122. var domain = IR[2];
  5123. var encode = IR[3];
  5124. var decode = IR[4];
  5125. var samples = IR[5];
  5126. var size = IR[6];
  5127. var n = IR[7];
  5128. //var mask = IR[8];
  5129. var range = IR[9];
  5130. // Building the cube vertices: its part and sample index
  5131. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  5132. var cubeVertices = 1 << m;
  5133. var cubeN = new Float64Array(cubeVertices);
  5134. var cubeVertex = new Uint32Array(cubeVertices);
  5135. var i, j;
  5136. for (j = 0; j < cubeVertices; j++) {
  5137. cubeN[j] = 1;
  5138. }
  5139. var k = n, pos = 1;
  5140. // Map x_i to y_j for 0 <= i < m using the sampled function.
  5141. for (i = 0; i < m; ++i) {
  5142. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  5143. var domain_2i = domain[i][0];
  5144. var domain_2i_1 = domain[i][1];
  5145. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  5146. domain_2i_1);
  5147. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  5148. // Encode_2i, Encode_2i+1)
  5149. var e = interpolate(xi, domain_2i, domain_2i_1,
  5150. encode[i][0], encode[i][1]);
  5151. // e_i' = min(max(e_i, 0), Size_i - 1)
  5152. var size_i = size[i];
  5153. e = Math.min(Math.max(e, 0), size_i - 1);
  5154. // Adjusting the cube: N and vertex sample index
  5155. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  5156. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  5157. var n1 = e - e0; // (e - e0) / (e1 - e0);
  5158. var offset0 = e0 * k;
  5159. var offset1 = offset0 + k; // e1 * k
  5160. for (j = 0; j < cubeVertices; j++) {
  5161. if (j & pos) {
  5162. cubeN[j] *= n1;
  5163. cubeVertex[j] += offset1;
  5164. } else {
  5165. cubeN[j] *= n0;
  5166. cubeVertex[j] += offset0;
  5167. }
  5168. }
  5169. k *= size_i;
  5170. pos <<= 1;
  5171. }
  5172. for (j = 0; j < n; ++j) {
  5173. // Sum all cube vertices' samples portions
  5174. var rj = 0;
  5175. for (i = 0; i < cubeVertices; i++) {
  5176. rj += samples[cubeVertex[i] + j] * cubeN[i];
  5177. }
  5178. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  5179. // Decode_2j, Decode_2j+1)
  5180. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  5181. // y_j = min(max(r_j, range_2j), range_2j+1)
  5182. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  5183. range[j][1]);
  5184. }
  5185. };
  5186. },
  5187. constructInterpolated: function PDFFunction_constructInterpolated(str,
  5188. dict) {
  5189. var c0 = dict.get('C0') || [0];
  5190. var c1 = dict.get('C1') || [1];
  5191. var n = dict.get('N');
  5192. if (!isArray(c0) || !isArray(c1)) {
  5193. error('Illegal dictionary for interpolated function');
  5194. }
  5195. var length = c0.length;
  5196. var diff = [];
  5197. for (var i = 0; i < length; ++i) {
  5198. diff.push(c1[i] - c0[i]);
  5199. }
  5200. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  5201. },
  5202. constructInterpolatedFromIR:
  5203. function PDFFunction_constructInterpolatedFromIR(IR) {
  5204. var c0 = IR[1];
  5205. var diff = IR[2];
  5206. var n = IR[3];
  5207. var length = diff.length;
  5208. return function constructInterpolatedFromIRResult(src, srcOffset,
  5209. dest, destOffset) {
  5210. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  5211. for (var j = 0; j < length; ++j) {
  5212. dest[destOffset + j] = c0[j] + (x * diff[j]);
  5213. }
  5214. };
  5215. },
  5216. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  5217. var domain = dict.get('Domain');
  5218. if (!domain) {
  5219. error('No domain');
  5220. }
  5221. var inputSize = domain.length / 2;
  5222. if (inputSize !== 1) {
  5223. error('Bad domain for stiched function');
  5224. }
  5225. var fnRefs = dict.get('Functions');
  5226. var fns = [];
  5227. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  5228. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  5229. }
  5230. var bounds = dict.get('Bounds');
  5231. var encode = dict.get('Encode');
  5232. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  5233. },
  5234. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  5235. var domain = IR[1];
  5236. var bounds = IR[2];
  5237. var encode = IR[3];
  5238. var fnsIR = IR[4];
  5239. var fns = [];
  5240. var tmpBuf = new Float32Array(1);
  5241. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  5242. fns.push(PDFFunction.fromIR(fnsIR[i]));
  5243. }
  5244. return function constructStichedFromIRResult(src, srcOffset,
  5245. dest, destOffset) {
  5246. var clip = function constructStichedFromIRClip(v, min, max) {
  5247. if (v > max) {
  5248. v = max;
  5249. } else if (v < min) {
  5250. v = min;
  5251. }
  5252. return v;
  5253. };
  5254. // clip to domain
  5255. var v = clip(src[srcOffset], domain[0], domain[1]);
  5256. // calulate which bound the value is in
  5257. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  5258. if (v < bounds[i]) {
  5259. break;
  5260. }
  5261. }
  5262. // encode value into domain of function
  5263. var dmin = domain[0];
  5264. if (i > 0) {
  5265. dmin = bounds[i - 1];
  5266. }
  5267. var dmax = domain[1];
  5268. if (i < bounds.length) {
  5269. dmax = bounds[i];
  5270. }
  5271. var rmin = encode[2 * i];
  5272. var rmax = encode[2 * i + 1];
  5273. // Prevent the value from becoming NaN as a result
  5274. // of division by zero (fixes issue6113.pdf).
  5275. tmpBuf[0] = dmin === dmax ? rmin :
  5276. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  5277. // call the appropriate function
  5278. fns[i](tmpBuf, 0, dest, destOffset);
  5279. };
  5280. },
  5281. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  5282. xref) {
  5283. var domain = dict.get('Domain');
  5284. var range = dict.get('Range');
  5285. if (!domain) {
  5286. error('No domain.');
  5287. }
  5288. if (!range) {
  5289. error('No range.');
  5290. }
  5291. var lexer = new PostScriptLexer(fn);
  5292. var parser = new PostScriptParser(lexer);
  5293. var code = parser.parse();
  5294. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  5295. },
  5296. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  5297. IR) {
  5298. var domain = IR[1];
  5299. var range = IR[2];
  5300. var code = IR[3];
  5301. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  5302. if (compiled) {
  5303. // Compiled function consists of simple expressions such as addition,
  5304. // subtraction, Math.max, and also contains 'var' and 'return'
  5305. // statements. See the generation in the PostScriptCompiler below.
  5306. /*jshint -W054 */
  5307. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  5308. }
  5309. info('Unable to compile PS function');
  5310. var numOutputs = range.length >> 1;
  5311. var numInputs = domain.length >> 1;
  5312. var evaluator = new PostScriptEvaluator(code);
  5313. // Cache the values for a big speed up, the cache size is limited though
  5314. // since the number of possible values can be huge from a PS function.
  5315. var cache = {};
  5316. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  5317. // seen in our tests.
  5318. var MAX_CACHE_SIZE = 2048 * 4;
  5319. var cache_available = MAX_CACHE_SIZE;
  5320. var tmpBuf = new Float32Array(numInputs);
  5321. return function constructPostScriptFromIRResult(src, srcOffset,
  5322. dest, destOffset) {
  5323. var i, value;
  5324. var key = '';
  5325. var input = tmpBuf;
  5326. for (i = 0; i < numInputs; i++) {
  5327. value = src[srcOffset + i];
  5328. input[i] = value;
  5329. key += value + '_';
  5330. }
  5331. var cachedValue = cache[key];
  5332. if (cachedValue !== undefined) {
  5333. dest.set(cachedValue, destOffset);
  5334. return;
  5335. }
  5336. var output = new Float32Array(numOutputs);
  5337. var stack = evaluator.execute(input);
  5338. var stackIndex = stack.length - numOutputs;
  5339. for (i = 0; i < numOutputs; i++) {
  5340. value = stack[stackIndex + i];
  5341. var bound = range[i * 2];
  5342. if (value < bound) {
  5343. value = bound;
  5344. } else {
  5345. bound = range[i * 2 +1];
  5346. if (value > bound) {
  5347. value = bound;
  5348. }
  5349. }
  5350. output[i] = value;
  5351. }
  5352. if (cache_available > 0) {
  5353. cache_available--;
  5354. cache[key] = output;
  5355. }
  5356. dest.set(output, destOffset);
  5357. };
  5358. }
  5359. };
  5360. })();
  5361. function isPDFFunction(v) {
  5362. var fnDict;
  5363. if (typeof v !== 'object') {
  5364. return false;
  5365. } else if (isDict(v)) {
  5366. fnDict = v;
  5367. } else if (isStream(v)) {
  5368. fnDict = v.dict;
  5369. } else {
  5370. return false;
  5371. }
  5372. return fnDict.has('FunctionType');
  5373. }
  5374. var PostScriptStack = (function PostScriptStackClosure() {
  5375. var MAX_STACK_SIZE = 100;
  5376. function PostScriptStack(initialStack) {
  5377. this.stack = !initialStack ? [] :
  5378. Array.prototype.slice.call(initialStack, 0);
  5379. }
  5380. PostScriptStack.prototype = {
  5381. push: function PostScriptStack_push(value) {
  5382. if (this.stack.length >= MAX_STACK_SIZE) {
  5383. error('PostScript function stack overflow.');
  5384. }
  5385. this.stack.push(value);
  5386. },
  5387. pop: function PostScriptStack_pop() {
  5388. if (this.stack.length <= 0) {
  5389. error('PostScript function stack underflow.');
  5390. }
  5391. return this.stack.pop();
  5392. },
  5393. copy: function PostScriptStack_copy(n) {
  5394. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5395. error('PostScript function stack overflow.');
  5396. }
  5397. var stack = this.stack;
  5398. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5399. stack.push(stack[i]);
  5400. }
  5401. },
  5402. index: function PostScriptStack_index(n) {
  5403. this.push(this.stack[this.stack.length - n - 1]);
  5404. },
  5405. // rotate the last n stack elements p times
  5406. roll: function PostScriptStack_roll(n, p) {
  5407. var stack = this.stack;
  5408. var l = stack.length - n;
  5409. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5410. for (i = l, j = r; i < j; i++, j--) {
  5411. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5412. }
  5413. for (i = l, j = c - 1; i < j; i++, j--) {
  5414. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5415. }
  5416. for (i = c, j = r; i < j; i++, j--) {
  5417. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5418. }
  5419. }
  5420. };
  5421. return PostScriptStack;
  5422. })();
  5423. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5424. function PostScriptEvaluator(operators) {
  5425. this.operators = operators;
  5426. }
  5427. PostScriptEvaluator.prototype = {
  5428. execute: function PostScriptEvaluator_execute(initialStack) {
  5429. var stack = new PostScriptStack(initialStack);
  5430. var counter = 0;
  5431. var operators = this.operators;
  5432. var length = operators.length;
  5433. var operator, a, b;
  5434. while (counter < length) {
  5435. operator = operators[counter++];
  5436. if (typeof operator === 'number') {
  5437. // Operator is really an operand and should be pushed to the stack.
  5438. stack.push(operator);
  5439. continue;
  5440. }
  5441. switch (operator) {
  5442. // non standard ps operators
  5443. case 'jz': // jump if false
  5444. b = stack.pop();
  5445. a = stack.pop();
  5446. if (!a) {
  5447. counter = b;
  5448. }
  5449. break;
  5450. case 'j': // jump
  5451. a = stack.pop();
  5452. counter = a;
  5453. break;
  5454. // all ps operators in alphabetical order (excluding if/ifelse)
  5455. case 'abs':
  5456. a = stack.pop();
  5457. stack.push(Math.abs(a));
  5458. break;
  5459. case 'add':
  5460. b = stack.pop();
  5461. a = stack.pop();
  5462. stack.push(a + b);
  5463. break;
  5464. case 'and':
  5465. b = stack.pop();
  5466. a = stack.pop();
  5467. if (isBool(a) && isBool(b)) {
  5468. stack.push(a && b);
  5469. } else {
  5470. stack.push(a & b);
  5471. }
  5472. break;
  5473. case 'atan':
  5474. a = stack.pop();
  5475. stack.push(Math.atan(a));
  5476. break;
  5477. case 'bitshift':
  5478. b = stack.pop();
  5479. a = stack.pop();
  5480. if (a > 0) {
  5481. stack.push(a << b);
  5482. } else {
  5483. stack.push(a >> b);
  5484. }
  5485. break;
  5486. case 'ceiling':
  5487. a = stack.pop();
  5488. stack.push(Math.ceil(a));
  5489. break;
  5490. case 'copy':
  5491. a = stack.pop();
  5492. stack.copy(a);
  5493. break;
  5494. case 'cos':
  5495. a = stack.pop();
  5496. stack.push(Math.cos(a));
  5497. break;
  5498. case 'cvi':
  5499. a = stack.pop() | 0;
  5500. stack.push(a);
  5501. break;
  5502. case 'cvr':
  5503. // noop
  5504. break;
  5505. case 'div':
  5506. b = stack.pop();
  5507. a = stack.pop();
  5508. stack.push(a / b);
  5509. break;
  5510. case 'dup':
  5511. stack.copy(1);
  5512. break;
  5513. case 'eq':
  5514. b = stack.pop();
  5515. a = stack.pop();
  5516. stack.push(a === b);
  5517. break;
  5518. case 'exch':
  5519. stack.roll(2, 1);
  5520. break;
  5521. case 'exp':
  5522. b = stack.pop();
  5523. a = stack.pop();
  5524. stack.push(Math.pow(a, b));
  5525. break;
  5526. case 'false':
  5527. stack.push(false);
  5528. break;
  5529. case 'floor':
  5530. a = stack.pop();
  5531. stack.push(Math.floor(a));
  5532. break;
  5533. case 'ge':
  5534. b = stack.pop();
  5535. a = stack.pop();
  5536. stack.push(a >= b);
  5537. break;
  5538. case 'gt':
  5539. b = stack.pop();
  5540. a = stack.pop();
  5541. stack.push(a > b);
  5542. break;
  5543. case 'idiv':
  5544. b = stack.pop();
  5545. a = stack.pop();
  5546. stack.push((a / b) | 0);
  5547. break;
  5548. case 'index':
  5549. a = stack.pop();
  5550. stack.index(a);
  5551. break;
  5552. case 'le':
  5553. b = stack.pop();
  5554. a = stack.pop();
  5555. stack.push(a <= b);
  5556. break;
  5557. case 'ln':
  5558. a = stack.pop();
  5559. stack.push(Math.log(a));
  5560. break;
  5561. case 'log':
  5562. a = stack.pop();
  5563. stack.push(Math.log(a) / Math.LN10);
  5564. break;
  5565. case 'lt':
  5566. b = stack.pop();
  5567. a = stack.pop();
  5568. stack.push(a < b);
  5569. break;
  5570. case 'mod':
  5571. b = stack.pop();
  5572. a = stack.pop();
  5573. stack.push(a % b);
  5574. break;
  5575. case 'mul':
  5576. b = stack.pop();
  5577. a = stack.pop();
  5578. stack.push(a * b);
  5579. break;
  5580. case 'ne':
  5581. b = stack.pop();
  5582. a = stack.pop();
  5583. stack.push(a !== b);
  5584. break;
  5585. case 'neg':
  5586. a = stack.pop();
  5587. stack.push(-a);
  5588. break;
  5589. case 'not':
  5590. a = stack.pop();
  5591. if (isBool(a)) {
  5592. stack.push(!a);
  5593. } else {
  5594. stack.push(~a);
  5595. }
  5596. break;
  5597. case 'or':
  5598. b = stack.pop();
  5599. a = stack.pop();
  5600. if (isBool(a) && isBool(b)) {
  5601. stack.push(a || b);
  5602. } else {
  5603. stack.push(a | b);
  5604. }
  5605. break;
  5606. case 'pop':
  5607. stack.pop();
  5608. break;
  5609. case 'roll':
  5610. b = stack.pop();
  5611. a = stack.pop();
  5612. stack.roll(a, b);
  5613. break;
  5614. case 'round':
  5615. a = stack.pop();
  5616. stack.push(Math.round(a));
  5617. break;
  5618. case 'sin':
  5619. a = stack.pop();
  5620. stack.push(Math.sin(a));
  5621. break;
  5622. case 'sqrt':
  5623. a = stack.pop();
  5624. stack.push(Math.sqrt(a));
  5625. break;
  5626. case 'sub':
  5627. b = stack.pop();
  5628. a = stack.pop();
  5629. stack.push(a - b);
  5630. break;
  5631. case 'true':
  5632. stack.push(true);
  5633. break;
  5634. case 'truncate':
  5635. a = stack.pop();
  5636. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5637. stack.push(a);
  5638. break;
  5639. case 'xor':
  5640. b = stack.pop();
  5641. a = stack.pop();
  5642. if (isBool(a) && isBool(b)) {
  5643. stack.push(a !== b);
  5644. } else {
  5645. stack.push(a ^ b);
  5646. }
  5647. break;
  5648. default:
  5649. error('Unknown operator ' + operator);
  5650. break;
  5651. }
  5652. }
  5653. return stack.stack;
  5654. }
  5655. };
  5656. return PostScriptEvaluator;
  5657. })();
  5658. // Most of the PDFs functions consist of simple operations such as:
  5659. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  5660. //
  5661. // We can compile most of such programs, and at the same moment, we can
  5662. // optimize some expressions using basic math properties. Keeping track of
  5663. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  5664. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  5665. function AstNode(type) {
  5666. this.type = type;
  5667. }
  5668. AstNode.prototype.visit = function (visitor) {
  5669. throw new Error('abstract method');
  5670. };
  5671. function AstArgument(index, min, max) {
  5672. AstNode.call(this, 'args');
  5673. this.index = index;
  5674. this.min = min;
  5675. this.max = max;
  5676. }
  5677. AstArgument.prototype = Object.create(AstNode.prototype);
  5678. AstArgument.prototype.visit = function (visitor) {
  5679. visitor.visitArgument(this);
  5680. };
  5681. function AstLiteral(number) {
  5682. AstNode.call(this, 'literal');
  5683. this.number = number;
  5684. this.min = number;
  5685. this.max = number;
  5686. }
  5687. AstLiteral.prototype = Object.create(AstNode.prototype);
  5688. AstLiteral.prototype.visit = function (visitor) {
  5689. visitor.visitLiteral(this);
  5690. };
  5691. function AstBinaryOperation(op, arg1, arg2, min, max) {
  5692. AstNode.call(this, 'binary');
  5693. this.op = op;
  5694. this.arg1 = arg1;
  5695. this.arg2 = arg2;
  5696. this.min = min;
  5697. this.max = max;
  5698. }
  5699. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  5700. AstBinaryOperation.prototype.visit = function (visitor) {
  5701. visitor.visitBinaryOperation(this);
  5702. };
  5703. function AstMin(arg, max) {
  5704. AstNode.call(this, 'max');
  5705. this.arg = arg;
  5706. this.min = arg.min;
  5707. this.max = max;
  5708. }
  5709. AstMin.prototype = Object.create(AstNode.prototype);
  5710. AstMin.prototype.visit = function (visitor) {
  5711. visitor.visitMin(this);
  5712. };
  5713. function AstVariable(index, min, max) {
  5714. AstNode.call(this, 'var');
  5715. this.index = index;
  5716. this.min = min;
  5717. this.max = max;
  5718. }
  5719. AstVariable.prototype = Object.create(AstNode.prototype);
  5720. AstVariable.prototype.visit = function (visitor) {
  5721. visitor.visitVariable(this);
  5722. };
  5723. function AstVariableDefinition(variable, arg) {
  5724. AstNode.call(this, 'definition');
  5725. this.variable = variable;
  5726. this.arg = arg;
  5727. }
  5728. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  5729. AstVariableDefinition.prototype.visit = function (visitor) {
  5730. visitor.visitVariableDefinition(this);
  5731. };
  5732. function ExpressionBuilderVisitor() {
  5733. this.parts = [];
  5734. }
  5735. ExpressionBuilderVisitor.prototype = {
  5736. visitArgument: function (arg) {
  5737. this.parts.push('Math.max(', arg.min, ', Math.min(',
  5738. arg.max, ', src[srcOffset + ', arg.index, ']))');
  5739. },
  5740. visitVariable: function (variable) {
  5741. this.parts.push('v', variable.index);
  5742. },
  5743. visitLiteral: function (literal) {
  5744. this.parts.push(literal.number);
  5745. },
  5746. visitBinaryOperation: function (operation) {
  5747. this.parts.push('(');
  5748. operation.arg1.visit(this);
  5749. this.parts.push(' ', operation.op, ' ');
  5750. operation.arg2.visit(this);
  5751. this.parts.push(')');
  5752. },
  5753. visitVariableDefinition: function (definition) {
  5754. this.parts.push('var ');
  5755. definition.variable.visit(this);
  5756. this.parts.push(' = ');
  5757. definition.arg.visit(this);
  5758. this.parts.push(';');
  5759. },
  5760. visitMin: function (max) {
  5761. this.parts.push('Math.min(');
  5762. max.arg.visit(this);
  5763. this.parts.push(', ', max.max, ')');
  5764. },
  5765. toString: function () {
  5766. return this.parts.join('');
  5767. }
  5768. };
  5769. function buildAddOperation(num1, num2) {
  5770. if (num2.type === 'literal' && num2.number === 0) {
  5771. // optimization: second operand is 0
  5772. return num1;
  5773. }
  5774. if (num1.type === 'literal' && num1.number === 0) {
  5775. // optimization: first operand is 0
  5776. return num2;
  5777. }
  5778. if (num2.type === 'literal' && num1.type === 'literal') {
  5779. // optimization: operands operand are literals
  5780. return new AstLiteral(num1.number + num2.number);
  5781. }
  5782. return new AstBinaryOperation('+', num1, num2,
  5783. num1.min + num2.min, num1.max + num2.max);
  5784. }
  5785. function buildMulOperation(num1, num2) {
  5786. if (num2.type === 'literal') {
  5787. // optimization: second operands is a literal...
  5788. if (num2.number === 0) {
  5789. return new AstLiteral(0); // and it's 0
  5790. } else if (num2.number === 1) {
  5791. return num1; // and it's 1
  5792. } else if (num1.type === 'literal') {
  5793. // ... and first operands is a literal too
  5794. return new AstLiteral(num1.number * num2.number);
  5795. }
  5796. }
  5797. if (num1.type === 'literal') {
  5798. // optimization: first operands is a literal...
  5799. if (num1.number === 0) {
  5800. return new AstLiteral(0); // and it's 0
  5801. } else if (num1.number === 1) {
  5802. return num2; // and it's 1
  5803. }
  5804. }
  5805. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  5806. num1.max * num2.min, num1.max * num2.max);
  5807. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  5808. num1.max * num2.min, num1.max * num2.max);
  5809. return new AstBinaryOperation('*', num1, num2, min, max);
  5810. }
  5811. function buildSubOperation(num1, num2) {
  5812. if (num2.type === 'literal') {
  5813. // optimization: second operands is a literal...
  5814. if (num2.number === 0) {
  5815. return num1; // ... and it's 0
  5816. } else if (num1.type === 'literal') {
  5817. // ... and first operands is a literal too
  5818. return new AstLiteral(num1.number - num2.number);
  5819. }
  5820. }
  5821. if (num2.type === 'binary' && num2.op === '-' &&
  5822. num1.type === 'literal' && num1.number === 1 &&
  5823. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  5824. // optimization for case: 1 - (1 - x)
  5825. return num2.arg2;
  5826. }
  5827. return new AstBinaryOperation('-', num1, num2,
  5828. num1.min - num2.max, num1.max - num2.min);
  5829. }
  5830. function buildMinOperation(num1, max) {
  5831. if (num1.min >= max) {
  5832. // optimization: num1 min value is not less than required max
  5833. return new AstLiteral(max); // just returning max
  5834. } else if (num1.max <= max) {
  5835. // optimization: num1 max value is not greater than required max
  5836. return num1; // just returning an argument
  5837. }
  5838. return new AstMin(num1, max);
  5839. }
  5840. function PostScriptCompiler() {}
  5841. PostScriptCompiler.prototype = {
  5842. compile: function PostScriptCompiler_compile(code, domain, range) {
  5843. var stack = [];
  5844. var i, ii;
  5845. var instructions = [];
  5846. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  5847. var lastRegister = 0;
  5848. var n, j, min, max;
  5849. var num1, num2, ast1, ast2, tmpVar, item;
  5850. for (i = 0; i < inputSize; i++) {
  5851. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  5852. }
  5853. for (i = 0, ii = code.length; i < ii; i++) {
  5854. item = code[i];
  5855. if (typeof item === 'number') {
  5856. stack.push(new AstLiteral(item));
  5857. continue;
  5858. }
  5859. switch (item) {
  5860. case 'add':
  5861. if (stack.length < 2) {
  5862. return null;
  5863. }
  5864. num2 = stack.pop();
  5865. num1 = stack.pop();
  5866. stack.push(buildAddOperation(num1, num2));
  5867. break;
  5868. case 'cvr':
  5869. if (stack.length < 1) {
  5870. return null;
  5871. }
  5872. break;
  5873. case 'mul':
  5874. if (stack.length < 2) {
  5875. return null;
  5876. }
  5877. num2 = stack.pop();
  5878. num1 = stack.pop();
  5879. stack.push(buildMulOperation(num1, num2));
  5880. break;
  5881. case 'sub':
  5882. if (stack.length < 2) {
  5883. return null;
  5884. }
  5885. num2 = stack.pop();
  5886. num1 = stack.pop();
  5887. stack.push(buildSubOperation(num1, num2));
  5888. break;
  5889. case 'exch':
  5890. if (stack.length < 2) {
  5891. return null;
  5892. }
  5893. ast1 = stack.pop(); ast2 = stack.pop();
  5894. stack.push(ast1, ast2);
  5895. break;
  5896. case 'pop':
  5897. if (stack.length < 1) {
  5898. return null;
  5899. }
  5900. stack.pop();
  5901. break;
  5902. case 'index':
  5903. if (stack.length < 1) {
  5904. return null;
  5905. }
  5906. num1 = stack.pop();
  5907. if (num1.type !== 'literal') {
  5908. return null;
  5909. }
  5910. n = num1.number;
  5911. if (n < 0 || (n|0) !== n || stack.length < n) {
  5912. return null;
  5913. }
  5914. ast1 = stack[stack.length - n - 1];
  5915. if (ast1.type === 'literal' || ast1.type === 'var') {
  5916. stack.push(ast1);
  5917. break;
  5918. }
  5919. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5920. stack[stack.length - n - 1] = tmpVar;
  5921. stack.push(tmpVar);
  5922. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5923. break;
  5924. case 'dup':
  5925. if (stack.length < 1) {
  5926. return null;
  5927. }
  5928. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  5929. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  5930. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  5931. // special case of the commands sequence for the min operation
  5932. num1 = stack.pop();
  5933. stack.push(buildMinOperation(num1, code[i + 1]));
  5934. i += 6;
  5935. break;
  5936. }
  5937. ast1 = stack[stack.length - 1];
  5938. if (ast1.type === 'literal' || ast1.type === 'var') {
  5939. // we don't have to save into intermediate variable a literal or
  5940. // variable.
  5941. stack.push(ast1);
  5942. break;
  5943. }
  5944. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  5945. stack[stack.length - 1] = tmpVar;
  5946. stack.push(tmpVar);
  5947. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  5948. break;
  5949. case 'roll':
  5950. if (stack.length < 2) {
  5951. return null;
  5952. }
  5953. num2 = stack.pop();
  5954. num1 = stack.pop();
  5955. if (num2.type !== 'literal' || num1.type !== 'literal') {
  5956. // both roll operands must be numbers
  5957. return null;
  5958. }
  5959. j = num2.number;
  5960. n = num1.number;
  5961. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  5962. // ... and integers
  5963. return null;
  5964. }
  5965. j = ((j % n) + n) % n;
  5966. if (j === 0) {
  5967. break; // just skipping -- there are nothing to rotate
  5968. }
  5969. Array.prototype.push.apply(stack,
  5970. stack.splice(stack.length - n, n - j));
  5971. break;
  5972. default:
  5973. return null; // unsupported operator
  5974. }
  5975. }
  5976. if (stack.length !== outputSize) {
  5977. return null;
  5978. }
  5979. var result = [];
  5980. instructions.forEach(function (instruction) {
  5981. var statementBuilder = new ExpressionBuilderVisitor();
  5982. instruction.visit(statementBuilder);
  5983. result.push(statementBuilder.toString());
  5984. });
  5985. stack.forEach(function (expr, i) {
  5986. var statementBuilder = new ExpressionBuilderVisitor();
  5987. expr.visit(statementBuilder);
  5988. var min = range[i * 2], max = range[i * 2 + 1];
  5989. var out = [statementBuilder.toString()];
  5990. if (min > expr.min) {
  5991. out.unshift('Math.max(', min, ', ');
  5992. out.push(')');
  5993. }
  5994. if (max < expr.max) {
  5995. out.unshift('Math.min(', max, ', ');
  5996. out.push(')');
  5997. }
  5998. out.unshift('dest[destOffset + ', i, '] = ');
  5999. out.push(';');
  6000. result.push(out.join(''));
  6001. });
  6002. return result.join('\n');
  6003. }
  6004. };
  6005. return PostScriptCompiler;
  6006. })();
  6007. var ColorSpace = (function ColorSpaceClosure() {
  6008. // Constructor should define this.numComps, this.defaultColor, this.name
  6009. function ColorSpace() {
  6010. error('should not call ColorSpace constructor');
  6011. }
  6012. ColorSpace.prototype = {
  6013. /**
  6014. * Converts the color value to the RGB color. The color components are
  6015. * located in the src array starting from the srcOffset. Returns the array
  6016. * of the rgb components, each value ranging from [0,255].
  6017. */
  6018. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  6019. var rgb = new Uint8Array(3);
  6020. this.getRgbItem(src, srcOffset, rgb, 0);
  6021. return rgb;
  6022. },
  6023. /**
  6024. * Converts the color value to the RGB color, similar to the getRgb method.
  6025. * The result placed into the dest array starting from the destOffset.
  6026. */
  6027. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  6028. dest, destOffset) {
  6029. error('Should not call ColorSpace.getRgbItem');
  6030. },
  6031. /**
  6032. * Converts the specified number of the color values to the RGB colors.
  6033. * The colors are located in the src array starting from the srcOffset.
  6034. * The result is placed into the dest array starting from the destOffset.
  6035. * The src array items shall be in [0,2^bits) range, the dest array items
  6036. * will be in [0,255] range. alpha01 indicates how many alpha components
  6037. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  6038. * array).
  6039. */
  6040. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  6041. dest, destOffset, bits,
  6042. alpha01) {
  6043. error('Should not call ColorSpace.getRgbBuffer');
  6044. },
  6045. /**
  6046. * Determines the number of bytes required to store the result of the
  6047. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  6048. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  6049. */
  6050. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  6051. alpha01) {
  6052. error('Should not call ColorSpace.getOutputLength');
  6053. },
  6054. /**
  6055. * Returns true if source data will be equal the result/output data.
  6056. */
  6057. isPassthrough: function ColorSpace_isPassthrough(bits) {
  6058. return false;
  6059. },
  6060. /**
  6061. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  6062. * how many alpha components there are in the dest array; it will be either
  6063. * 0 (RGB array) or 1 (RGBA array).
  6064. */
  6065. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  6066. originalHeight, width, height,
  6067. actualHeight, bpc, comps, alpha01) {
  6068. var count = originalWidth * originalHeight;
  6069. var rgbBuf = null;
  6070. var numComponentColors = 1 << bpc;
  6071. var needsResizing = originalHeight !== height || originalWidth !== width;
  6072. var i, ii;
  6073. if (this.isPassthrough(bpc)) {
  6074. rgbBuf = comps;
  6075. } else if (this.numComps === 1 && count > numComponentColors &&
  6076. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  6077. // Optimization: create a color map when there is just one component and
  6078. // we are converting more colors than the size of the color map. We
  6079. // don't build the map if the colorspace is gray or rgb since those
  6080. // methods are faster than building a map. This mainly offers big speed
  6081. // ups for indexed and alternate colorspaces.
  6082. //
  6083. // TODO it may be worth while to cache the color map. While running
  6084. // testing I never hit a cache so I will leave that out for now (perhaps
  6085. // we are reparsing colorspaces too much?).
  6086. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  6087. new Uint16Array(numComponentColors);
  6088. var key;
  6089. for (i = 0; i < numComponentColors; i++) {
  6090. allColors[i] = i;
  6091. }
  6092. var colorMap = new Uint8Array(numComponentColors * 3);
  6093. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  6094. /* alpha01 = */ 0);
  6095. var destPos, rgbPos;
  6096. if (!needsResizing) {
  6097. // Fill in the RGB values directly into |dest|.
  6098. destPos = 0;
  6099. for (i = 0; i < count; ++i) {
  6100. key = comps[i] * 3;
  6101. dest[destPos++] = colorMap[key];
  6102. dest[destPos++] = colorMap[key + 1];
  6103. dest[destPos++] = colorMap[key + 2];
  6104. destPos += alpha01;
  6105. }
  6106. } else {
  6107. rgbBuf = new Uint8Array(count * 3);
  6108. rgbPos = 0;
  6109. for (i = 0; i < count; ++i) {
  6110. key = comps[i] * 3;
  6111. rgbBuf[rgbPos++] = colorMap[key];
  6112. rgbBuf[rgbPos++] = colorMap[key + 1];
  6113. rgbBuf[rgbPos++] = colorMap[key + 2];
  6114. }
  6115. }
  6116. } else {
  6117. if (!needsResizing) {
  6118. // Fill in the RGB values directly into |dest|.
  6119. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  6120. alpha01);
  6121. } else {
  6122. rgbBuf = new Uint8Array(count * 3);
  6123. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  6124. /* alpha01 = */ 0);
  6125. }
  6126. }
  6127. if (rgbBuf) {
  6128. if (needsResizing) {
  6129. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  6130. height, dest, alpha01);
  6131. } else {
  6132. rgbPos = 0;
  6133. destPos = 0;
  6134. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  6135. dest[destPos++] = rgbBuf[rgbPos++];
  6136. dest[destPos++] = rgbBuf[rgbPos++];
  6137. dest[destPos++] = rgbBuf[rgbPos++];
  6138. destPos += alpha01;
  6139. }
  6140. }
  6141. }
  6142. },
  6143. /**
  6144. * True if the colorspace has components in the default range of [0, 1].
  6145. * This should be true for all colorspaces except for lab color spaces
  6146. * which are [0,100], [-128, 127], [-128, 127].
  6147. */
  6148. usesZeroToOneRange: true
  6149. };
  6150. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  6151. var IR = ColorSpace.parseToIR(cs, xref, res);
  6152. if (IR instanceof AlternateCS) {
  6153. return IR;
  6154. }
  6155. return ColorSpace.fromIR(IR);
  6156. };
  6157. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  6158. var name = isArray(IR) ? IR[0] : IR;
  6159. var whitePoint, blackPoint, gamma;
  6160. switch (name) {
  6161. case 'DeviceGrayCS':
  6162. return this.singletons.gray;
  6163. case 'DeviceRgbCS':
  6164. return this.singletons.rgb;
  6165. case 'DeviceCmykCS':
  6166. return this.singletons.cmyk;
  6167. case 'CalGrayCS':
  6168. whitePoint = IR[1].WhitePoint;
  6169. blackPoint = IR[1].BlackPoint;
  6170. gamma = IR[1].Gamma;
  6171. return new CalGrayCS(whitePoint, blackPoint, gamma);
  6172. case 'CalRGBCS':
  6173. whitePoint = IR[1].WhitePoint;
  6174. blackPoint = IR[1].BlackPoint;
  6175. gamma = IR[1].Gamma;
  6176. var matrix = IR[1].Matrix;
  6177. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  6178. case 'PatternCS':
  6179. var basePatternCS = IR[1];
  6180. if (basePatternCS) {
  6181. basePatternCS = ColorSpace.fromIR(basePatternCS);
  6182. }
  6183. return new PatternCS(basePatternCS);
  6184. case 'IndexedCS':
  6185. var baseIndexedCS = IR[1];
  6186. var hiVal = IR[2];
  6187. var lookup = IR[3];
  6188. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  6189. case 'AlternateCS':
  6190. var numComps = IR[1];
  6191. var alt = IR[2];
  6192. var tintFnIR = IR[3];
  6193. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  6194. PDFFunction.fromIR(tintFnIR));
  6195. case 'LabCS':
  6196. whitePoint = IR[1].WhitePoint;
  6197. blackPoint = IR[1].BlackPoint;
  6198. var range = IR[1].Range;
  6199. return new LabCS(whitePoint, blackPoint, range);
  6200. default:
  6201. error('Unknown name ' + name);
  6202. }
  6203. return null;
  6204. };
  6205. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  6206. if (isName(cs)) {
  6207. var colorSpaces = res.get('ColorSpace');
  6208. if (isDict(colorSpaces)) {
  6209. var refcs = colorSpaces.get(cs.name);
  6210. if (refcs) {
  6211. cs = refcs;
  6212. }
  6213. }
  6214. }
  6215. cs = xref.fetchIfRef(cs);
  6216. var mode;
  6217. if (isName(cs)) {
  6218. mode = cs.name;
  6219. this.mode = mode;
  6220. switch (mode) {
  6221. case 'DeviceGray':
  6222. case 'G':
  6223. return 'DeviceGrayCS';
  6224. case 'DeviceRGB':
  6225. case 'RGB':
  6226. return 'DeviceRgbCS';
  6227. case 'DeviceCMYK':
  6228. case 'CMYK':
  6229. return 'DeviceCmykCS';
  6230. case 'Pattern':
  6231. return ['PatternCS', null];
  6232. default:
  6233. error('unrecognized colorspace ' + mode);
  6234. }
  6235. } else if (isArray(cs)) {
  6236. mode = xref.fetchIfRef(cs[0]).name;
  6237. this.mode = mode;
  6238. var numComps, params, alt;
  6239. switch (mode) {
  6240. case 'DeviceGray':
  6241. case 'G':
  6242. return 'DeviceGrayCS';
  6243. case 'DeviceRGB':
  6244. case 'RGB':
  6245. return 'DeviceRgbCS';
  6246. case 'DeviceCMYK':
  6247. case 'CMYK':
  6248. return 'DeviceCmykCS';
  6249. case 'CalGray':
  6250. params = xref.fetchIfRef(cs[1]).getAll();
  6251. return ['CalGrayCS', params];
  6252. case 'CalRGB':
  6253. params = xref.fetchIfRef(cs[1]).getAll();
  6254. return ['CalRGBCS', params];
  6255. case 'ICCBased':
  6256. var stream = xref.fetchIfRef(cs[1]);
  6257. var dict = stream.dict;
  6258. numComps = dict.get('N');
  6259. alt = dict.get('Alternate');
  6260. if (alt) {
  6261. var altIR = ColorSpace.parseToIR(alt, xref, res);
  6262. // Parse the /Alternate CS to ensure that the number of components
  6263. // are correct, and also (indirectly) that it is not a PatternCS.
  6264. var altCS = ColorSpace.fromIR(altIR);
  6265. if (altCS.numComps === numComps) {
  6266. return altIR;
  6267. }
  6268. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  6269. }
  6270. if (numComps === 1) {
  6271. return 'DeviceGrayCS';
  6272. } else if (numComps === 3) {
  6273. return 'DeviceRgbCS';
  6274. } else if (numComps === 4) {
  6275. return 'DeviceCmykCS';
  6276. }
  6277. break;
  6278. case 'Pattern':
  6279. var basePatternCS = cs[1] || null;
  6280. if (basePatternCS) {
  6281. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  6282. }
  6283. return ['PatternCS', basePatternCS];
  6284. case 'Indexed':
  6285. case 'I':
  6286. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  6287. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  6288. var lookup = xref.fetchIfRef(cs[3]);
  6289. if (isStream(lookup)) {
  6290. lookup = lookup.getBytes();
  6291. }
  6292. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  6293. case 'Separation':
  6294. case 'DeviceN':
  6295. var name = xref.fetchIfRef(cs[1]);
  6296. numComps = 1;
  6297. if (isName(name)) {
  6298. numComps = 1;
  6299. } else if (isArray(name)) {
  6300. numComps = name.length;
  6301. }
  6302. alt = ColorSpace.parseToIR(cs[2], xref, res);
  6303. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  6304. return ['AlternateCS', numComps, alt, tintFnIR];
  6305. case 'Lab':
  6306. params = xref.fetchIfRef(cs[1]).getAll();
  6307. return ['LabCS', params];
  6308. default:
  6309. error('unimplemented color space object "' + mode + '"');
  6310. }
  6311. } else {
  6312. error('unrecognized color space object: "' + cs + '"');
  6313. }
  6314. return null;
  6315. };
  6316. /**
  6317. * Checks if a decode map matches the default decode map for a color space.
  6318. * This handles the general decode maps where there are two values per
  6319. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  6320. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  6321. * slightly different.
  6322. * @param {Array} decode Decode map (usually from an image).
  6323. * @param {Number} n Number of components the color space has.
  6324. */
  6325. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  6326. if (!decode) {
  6327. return true;
  6328. }
  6329. if (n * 2 !== decode.length) {
  6330. warn('The decode map is not the correct length');
  6331. return true;
  6332. }
  6333. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  6334. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  6335. return false;
  6336. }
  6337. }
  6338. return true;
  6339. };
  6340. ColorSpace.singletons = {
  6341. get gray() {
  6342. return shadow(this, 'gray', new DeviceGrayCS());
  6343. },
  6344. get rgb() {
  6345. return shadow(this, 'rgb', new DeviceRgbCS());
  6346. },
  6347. get cmyk() {
  6348. return shadow(this, 'cmyk', new DeviceCmykCS());
  6349. }
  6350. };
  6351. return ColorSpace;
  6352. })();
  6353. /**
  6354. * Alternate color space handles both Separation and DeviceN color spaces. A
  6355. * Separation color space is actually just a DeviceN with one color component.
  6356. * Both color spaces use a tinting function to convert colors to a base color
  6357. * space.
  6358. */
  6359. var AlternateCS = (function AlternateCSClosure() {
  6360. function AlternateCS(numComps, base, tintFn) {
  6361. this.name = 'Alternate';
  6362. this.numComps = numComps;
  6363. this.defaultColor = new Float32Array(numComps);
  6364. for (var i = 0; i < numComps; ++i) {
  6365. this.defaultColor[i] = 1;
  6366. }
  6367. this.base = base;
  6368. this.tintFn = tintFn;
  6369. this.tmpBuf = new Float32Array(base.numComps);
  6370. }
  6371. AlternateCS.prototype = {
  6372. getRgb: ColorSpace.prototype.getRgb,
  6373. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  6374. dest, destOffset) {
  6375. var tmpBuf = this.tmpBuf;
  6376. this.tintFn(src, srcOffset, tmpBuf, 0);
  6377. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  6378. },
  6379. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  6380. dest, destOffset, bits,
  6381. alpha01) {
  6382. var tintFn = this.tintFn;
  6383. var base = this.base;
  6384. var scale = 1 / ((1 << bits) - 1);
  6385. var baseNumComps = base.numComps;
  6386. var usesZeroToOneRange = base.usesZeroToOneRange;
  6387. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  6388. alpha01 === 0;
  6389. var pos = isPassthrough ? destOffset : 0;
  6390. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  6391. var numComps = this.numComps;
  6392. var scaled = new Float32Array(numComps);
  6393. var tinted = new Float32Array(baseNumComps);
  6394. var i, j;
  6395. if (usesZeroToOneRange) {
  6396. for (i = 0; i < count; i++) {
  6397. for (j = 0; j < numComps; j++) {
  6398. scaled[j] = src[srcOffset++] * scale;
  6399. }
  6400. tintFn(scaled, 0, tinted, 0);
  6401. for (j = 0; j < baseNumComps; j++) {
  6402. baseBuf[pos++] = tinted[j] * 255;
  6403. }
  6404. }
  6405. } else {
  6406. for (i = 0; i < count; i++) {
  6407. for (j = 0; j < numComps; j++) {
  6408. scaled[j] = src[srcOffset++] * scale;
  6409. }
  6410. tintFn(scaled, 0, tinted, 0);
  6411. base.getRgbItem(tinted, 0, baseBuf, pos);
  6412. pos += baseNumComps;
  6413. }
  6414. }
  6415. if (!isPassthrough) {
  6416. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  6417. }
  6418. },
  6419. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  6420. alpha01) {
  6421. return this.base.getOutputLength(inputLength *
  6422. this.base.numComps / this.numComps,
  6423. alpha01);
  6424. },
  6425. isPassthrough: ColorSpace.prototype.isPassthrough,
  6426. fillRgb: ColorSpace.prototype.fillRgb,
  6427. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  6428. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6429. },
  6430. usesZeroToOneRange: true
  6431. };
  6432. return AlternateCS;
  6433. })();
  6434. var PatternCS = (function PatternCSClosure() {
  6435. function PatternCS(baseCS) {
  6436. this.name = 'Pattern';
  6437. this.base = baseCS;
  6438. }
  6439. PatternCS.prototype = {};
  6440. return PatternCS;
  6441. })();
  6442. var IndexedCS = (function IndexedCSClosure() {
  6443. function IndexedCS(base, highVal, lookup) {
  6444. this.name = 'Indexed';
  6445. this.numComps = 1;
  6446. this.defaultColor = new Uint8Array([0]);
  6447. this.base = base;
  6448. this.highVal = highVal;
  6449. var baseNumComps = base.numComps;
  6450. var length = baseNumComps * highVal;
  6451. var lookupArray;
  6452. if (isStream(lookup)) {
  6453. lookupArray = new Uint8Array(length);
  6454. var bytes = lookup.getBytes(length);
  6455. lookupArray.set(bytes);
  6456. } else if (isString(lookup)) {
  6457. lookupArray = new Uint8Array(length);
  6458. for (var i = 0; i < length; ++i) {
  6459. lookupArray[i] = lookup.charCodeAt(i);
  6460. }
  6461. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  6462. lookupArray = lookup;
  6463. } else {
  6464. error('Unrecognized lookup table: ' + lookup);
  6465. }
  6466. this.lookup = lookupArray;
  6467. }
  6468. IndexedCS.prototype = {
  6469. getRgb: ColorSpace.prototype.getRgb,
  6470. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  6471. dest, destOffset) {
  6472. var numComps = this.base.numComps;
  6473. var start = src[srcOffset] * numComps;
  6474. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  6475. },
  6476. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  6477. dest, destOffset, bits,
  6478. alpha01) {
  6479. var base = this.base;
  6480. var numComps = base.numComps;
  6481. var outputDelta = base.getOutputLength(numComps, alpha01);
  6482. var lookup = this.lookup;
  6483. for (var i = 0; i < count; ++i) {
  6484. var lookupPos = src[srcOffset++] * numComps;
  6485. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  6486. destOffset += outputDelta;
  6487. }
  6488. },
  6489. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  6490. return this.base.getOutputLength(inputLength * this.base.numComps,
  6491. alpha01);
  6492. },
  6493. isPassthrough: ColorSpace.prototype.isPassthrough,
  6494. fillRgb: ColorSpace.prototype.fillRgb,
  6495. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  6496. // indexed color maps shouldn't be changed
  6497. return true;
  6498. },
  6499. usesZeroToOneRange: true
  6500. };
  6501. return IndexedCS;
  6502. })();
  6503. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  6504. function DeviceGrayCS() {
  6505. this.name = 'DeviceGray';
  6506. this.numComps = 1;
  6507. this.defaultColor = new Float32Array([0]);
  6508. }
  6509. DeviceGrayCS.prototype = {
  6510. getRgb: ColorSpace.prototype.getRgb,
  6511. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  6512. dest, destOffset) {
  6513. var c = (src[srcOffset] * 255) | 0;
  6514. c = c < 0 ? 0 : c > 255 ? 255 : c;
  6515. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  6516. },
  6517. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  6518. dest, destOffset, bits,
  6519. alpha01) {
  6520. var scale = 255 / ((1 << bits) - 1);
  6521. var j = srcOffset, q = destOffset;
  6522. for (var i = 0; i < count; ++i) {
  6523. var c = (scale * src[j++]) | 0;
  6524. dest[q++] = c;
  6525. dest[q++] = c;
  6526. dest[q++] = c;
  6527. q += alpha01;
  6528. }
  6529. },
  6530. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  6531. alpha01) {
  6532. return inputLength * (3 + alpha01);
  6533. },
  6534. isPassthrough: ColorSpace.prototype.isPassthrough,
  6535. fillRgb: ColorSpace.prototype.fillRgb,
  6536. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  6537. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6538. },
  6539. usesZeroToOneRange: true
  6540. };
  6541. return DeviceGrayCS;
  6542. })();
  6543. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  6544. function DeviceRgbCS() {
  6545. this.name = 'DeviceRGB';
  6546. this.numComps = 3;
  6547. this.defaultColor = new Float32Array([0, 0, 0]);
  6548. }
  6549. DeviceRgbCS.prototype = {
  6550. getRgb: ColorSpace.prototype.getRgb,
  6551. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  6552. dest, destOffset) {
  6553. var r = (src[srcOffset] * 255) | 0;
  6554. var g = (src[srcOffset + 1] * 255) | 0;
  6555. var b = (src[srcOffset + 2] * 255) | 0;
  6556. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  6557. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  6558. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  6559. },
  6560. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  6561. dest, destOffset, bits,
  6562. alpha01) {
  6563. if (bits === 8 && alpha01 === 0) {
  6564. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  6565. return;
  6566. }
  6567. var scale = 255 / ((1 << bits) - 1);
  6568. var j = srcOffset, q = destOffset;
  6569. for (var i = 0; i < count; ++i) {
  6570. dest[q++] = (scale * src[j++]) | 0;
  6571. dest[q++] = (scale * src[j++]) | 0;
  6572. dest[q++] = (scale * src[j++]) | 0;
  6573. q += alpha01;
  6574. }
  6575. },
  6576. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  6577. alpha01) {
  6578. return (inputLength * (3 + alpha01) / 3) | 0;
  6579. },
  6580. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  6581. return bits === 8;
  6582. },
  6583. fillRgb: ColorSpace.prototype.fillRgb,
  6584. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  6585. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6586. },
  6587. usesZeroToOneRange: true
  6588. };
  6589. return DeviceRgbCS;
  6590. })();
  6591. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  6592. // The coefficients below was found using numerical analysis: the method of
  6593. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  6594. // where color_value is the tabular value from the table of sampled RGB colors
  6595. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  6596. // CMYK color conversion using the estimation below:
  6597. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  6598. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  6599. var c = src[srcOffset + 0] * srcScale;
  6600. var m = src[srcOffset + 1] * srcScale;
  6601. var y = src[srcOffset + 2] * srcScale;
  6602. var k = src[srcOffset + 3] * srcScale;
  6603. var r =
  6604. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  6605. 18.82290502165302 * y + 212.25662451639585 * k +
  6606. -285.2331026137004) +
  6607. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  6608. -17.873870861415444 * k - 5.497006427196366) +
  6609. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  6610. 17.5119270841813) +
  6611. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  6612. var g =
  6613. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  6614. 6.871425592049007 * y + 31.159100130055922 * k +
  6615. -79.2970844816548) +
  6616. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  6617. 131.35250912493976 * k - 190.9453302588951) +
  6618. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  6619. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  6620. var b =
  6621. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  6622. 30.89978309703729 * y - 0.23883238689178934 * k +
  6623. -14.183576799673286) +
  6624. m * (10.49593273432072 * m + 63.02378494754052 * y +
  6625. 50.606957656360734 * k - 112.23884253719248) +
  6626. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  6627. -193.58209356861505) +
  6628. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  6629. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  6630. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  6631. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  6632. }
  6633. function DeviceCmykCS() {
  6634. this.name = 'DeviceCMYK';
  6635. this.numComps = 4;
  6636. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  6637. }
  6638. DeviceCmykCS.prototype = {
  6639. getRgb: ColorSpace.prototype.getRgb,
  6640. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  6641. dest, destOffset) {
  6642. convertToRgb(src, srcOffset, 1, dest, destOffset);
  6643. },
  6644. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  6645. dest, destOffset, bits,
  6646. alpha01) {
  6647. var scale = 1 / ((1 << bits) - 1);
  6648. for (var i = 0; i < count; i++) {
  6649. convertToRgb(src, srcOffset, scale, dest, destOffset);
  6650. srcOffset += 4;
  6651. destOffset += 3 + alpha01;
  6652. }
  6653. },
  6654. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  6655. alpha01) {
  6656. return (inputLength / 4 * (3 + alpha01)) | 0;
  6657. },
  6658. isPassthrough: ColorSpace.prototype.isPassthrough,
  6659. fillRgb: ColorSpace.prototype.fillRgb,
  6660. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  6661. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6662. },
  6663. usesZeroToOneRange: true
  6664. };
  6665. return DeviceCmykCS;
  6666. })();
  6667. //
  6668. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  6669. //
  6670. var CalGrayCS = (function CalGrayCSClosure() {
  6671. function CalGrayCS(whitePoint, blackPoint, gamma) {
  6672. this.name = 'CalGray';
  6673. this.numComps = 1;
  6674. this.defaultColor = new Float32Array([0]);
  6675. if (!whitePoint) {
  6676. error('WhitePoint missing - required for color space CalGray');
  6677. }
  6678. blackPoint = blackPoint || [0, 0, 0];
  6679. gamma = gamma || 1;
  6680. // Translate arguments to spec variables.
  6681. this.XW = whitePoint[0];
  6682. this.YW = whitePoint[1];
  6683. this.ZW = whitePoint[2];
  6684. this.XB = blackPoint[0];
  6685. this.YB = blackPoint[1];
  6686. this.ZB = blackPoint[2];
  6687. this.G = gamma;
  6688. // Validate variables as per spec.
  6689. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6690. error('Invalid WhitePoint components for ' + this.name +
  6691. ', no fallback available');
  6692. }
  6693. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6694. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  6695. this.XB = this.YB = this.ZB = 0;
  6696. }
  6697. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  6698. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  6699. ', ZB: ' + this.ZB + ', only default values are supported.');
  6700. }
  6701. if (this.G < 1) {
  6702. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  6703. ', falling back to default');
  6704. this.G = 1;
  6705. }
  6706. }
  6707. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6708. // A represents a gray component of a calibrated gray space.
  6709. // A <---> AG in the spec
  6710. var A = src[srcOffset] * scale;
  6711. var AG = Math.pow(A, cs.G);
  6712. // Computes L as per spec. ( = cs.YW * AG )
  6713. // Except if other than default BlackPoint values are used.
  6714. var L = cs.YW * AG;
  6715. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  6716. // Convert values to rgb range [0, 255].
  6717. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  6718. dest[destOffset] = val;
  6719. dest[destOffset + 1] = val;
  6720. dest[destOffset + 2] = val;
  6721. }
  6722. CalGrayCS.prototype = {
  6723. getRgb: ColorSpace.prototype.getRgb,
  6724. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  6725. dest, destOffset) {
  6726. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6727. },
  6728. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  6729. dest, destOffset, bits,
  6730. alpha01) {
  6731. var scale = 1 / ((1 << bits) - 1);
  6732. for (var i = 0; i < count; ++i) {
  6733. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6734. srcOffset += 1;
  6735. destOffset += 3 + alpha01;
  6736. }
  6737. },
  6738. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  6739. return inputLength * (3 + alpha01);
  6740. },
  6741. isPassthrough: ColorSpace.prototype.isPassthrough,
  6742. fillRgb: ColorSpace.prototype.fillRgb,
  6743. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6744. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6745. },
  6746. usesZeroToOneRange: true
  6747. };
  6748. return CalGrayCS;
  6749. })();
  6750. //
  6751. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  6752. //
  6753. var CalRGBCS = (function CalRGBCSClosure() {
  6754. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  6755. // matrices.
  6756. var BRADFORD_SCALE_MATRIX = new Float32Array([
  6757. 0.8951, 0.2664, -0.1614,
  6758. -0.7502, 1.7135, 0.0367,
  6759. 0.0389, -0.0685, 1.0296]);
  6760. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  6761. 0.9869929, -0.1470543, 0.1599627,
  6762. 0.4323053, 0.5183603, 0.0492912,
  6763. -0.0085287, 0.0400428, 0.9684867]);
  6764. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  6765. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  6766. 3.2404542, -1.5371385, -0.4985314,
  6767. -0.9692660, 1.8760108, 0.0415560,
  6768. 0.0556434, -0.2040259, 1.0572252]);
  6769. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  6770. var tempNormalizeMatrix = new Float32Array(3);
  6771. var tempConvertMatrix1 = new Float32Array(3);
  6772. var tempConvertMatrix2 = new Float32Array(3);
  6773. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  6774. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  6775. this.name = 'CalRGB';
  6776. this.numComps = 3;
  6777. this.defaultColor = new Float32Array(3);
  6778. if (!whitePoint) {
  6779. error('WhitePoint missing - required for color space CalRGB');
  6780. }
  6781. blackPoint = blackPoint || new Float32Array(3);
  6782. gamma = gamma || new Float32Array([1, 1, 1]);
  6783. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  6784. // Translate arguments to spec variables.
  6785. var XW = whitePoint[0];
  6786. var YW = whitePoint[1];
  6787. var ZW = whitePoint[2];
  6788. this.whitePoint = whitePoint;
  6789. var XB = blackPoint[0];
  6790. var YB = blackPoint[1];
  6791. var ZB = blackPoint[2];
  6792. this.blackPoint = blackPoint;
  6793. this.GR = gamma[0];
  6794. this.GG = gamma[1];
  6795. this.GB = gamma[2];
  6796. this.MXA = matrix[0];
  6797. this.MYA = matrix[1];
  6798. this.MZA = matrix[2];
  6799. this.MXB = matrix[3];
  6800. this.MYB = matrix[4];
  6801. this.MZB = matrix[5];
  6802. this.MXC = matrix[6];
  6803. this.MYC = matrix[7];
  6804. this.MZC = matrix[8];
  6805. // Validate variables as per spec.
  6806. if (XW < 0 || ZW < 0 || YW !== 1) {
  6807. error('Invalid WhitePoint components for ' + this.name +
  6808. ', no fallback available');
  6809. }
  6810. if (XB < 0 || YB < 0 || ZB < 0) {
  6811. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  6812. ', ' + ZB + '], falling back to default');
  6813. this.blackPoint = new Float32Array(3);
  6814. }
  6815. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  6816. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  6817. '] for ' + this.name + ', falling back to default');
  6818. this.GR = this.GG = this.GB = 1;
  6819. }
  6820. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  6821. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  6822. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  6823. info('Invalid Matrix for ' + this.name + ' [' +
  6824. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  6825. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  6826. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  6827. '], falling back to default');
  6828. this.MXA = this.MYB = this.MZC = 1;
  6829. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  6830. }
  6831. }
  6832. function matrixProduct(a, b, result) {
  6833. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  6834. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  6835. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  6836. }
  6837. function convertToFlat(sourceWhitePoint, LMS, result) {
  6838. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  6839. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  6840. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  6841. }
  6842. function convertToD65(sourceWhitePoint, LMS, result) {
  6843. var D65X = 0.95047;
  6844. var D65Y = 1;
  6845. var D65Z = 1.08883;
  6846. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  6847. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  6848. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  6849. }
  6850. function sRGBTransferFunction(color) {
  6851. // See http://en.wikipedia.org/wiki/SRGB.
  6852. if (color <= 0.0031308){
  6853. return adjustToRange(0, 1, 12.92 * color);
  6854. }
  6855. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  6856. }
  6857. function adjustToRange(min, max, value) {
  6858. return Math.max(min, Math.min(max, value));
  6859. }
  6860. function decodeL(L) {
  6861. if (L < 0) {
  6862. return -decodeL(-L);
  6863. }
  6864. if (L > 8.0) {
  6865. return Math.pow(((L + 16) / 116), 3);
  6866. }
  6867. return L * DECODE_L_CONSTANT;
  6868. }
  6869. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  6870. // In case the blackPoint is already the default blackPoint then there is
  6871. // no need to do compensation.
  6872. if (sourceBlackPoint[0] === 0 &&
  6873. sourceBlackPoint[1] === 0 &&
  6874. sourceBlackPoint[2] === 0) {
  6875. result[0] = XYZ_Flat[0];
  6876. result[1] = XYZ_Flat[1];
  6877. result[2] = XYZ_Flat[2];
  6878. return;
  6879. }
  6880. // For the blackPoint calculation details, please see
  6881. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6882. // AdobeBPC.pdf.
  6883. // The destination blackPoint is the default blackPoint [0, 0, 0].
  6884. var zeroDecodeL = decodeL(0);
  6885. var X_DST = zeroDecodeL;
  6886. var X_SRC = decodeL(sourceBlackPoint[0]);
  6887. var Y_DST = zeroDecodeL;
  6888. var Y_SRC = decodeL(sourceBlackPoint[1]);
  6889. var Z_DST = zeroDecodeL;
  6890. var Z_SRC = decodeL(sourceBlackPoint[2]);
  6891. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  6892. var X_Offset = 1 - X_Scale;
  6893. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  6894. var Y_Offset = 1 - Y_Scale;
  6895. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  6896. var Z_Offset = 1 - Z_Scale;
  6897. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  6898. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  6899. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  6900. }
  6901. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  6902. // In case the whitePoint is already flat then there is no need to do
  6903. // normalization.
  6904. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  6905. result[0] = XYZ_In[0];
  6906. result[1] = XYZ_In[1];
  6907. result[2] = XYZ_In[2];
  6908. return;
  6909. }
  6910. var LMS = result;
  6911. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6912. var LMS_Flat = tempNormalizeMatrix;
  6913. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  6914. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  6915. }
  6916. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  6917. var LMS = result;
  6918. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  6919. var LMS_D65 = tempNormalizeMatrix;
  6920. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  6921. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  6922. }
  6923. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  6924. // A, B and C represent a red, green and blue components of a calibrated
  6925. // rgb space.
  6926. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  6927. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  6928. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  6929. // A <---> AGR in the spec
  6930. // B <---> BGG in the spec
  6931. // C <---> CGB in the spec
  6932. var AGR = Math.pow(A, cs.GR);
  6933. var BGG = Math.pow(B, cs.GG);
  6934. var CGB = Math.pow(C, cs.GB);
  6935. // Computes intermediate variables L, M, N as per spec.
  6936. // To decode X, Y, Z values map L, M, N directly to them.
  6937. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  6938. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  6939. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  6940. // The following calculations are based on this document:
  6941. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  6942. // AdobeBPC.pdf.
  6943. var XYZ = tempConvertMatrix1;
  6944. XYZ[0] = X;
  6945. XYZ[1] = Y;
  6946. XYZ[2] = Z;
  6947. var XYZ_Flat = tempConvertMatrix2;
  6948. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  6949. var XYZ_Black = tempConvertMatrix1;
  6950. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  6951. var XYZ_D65 = tempConvertMatrix2;
  6952. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  6953. var SRGB = tempConvertMatrix1;
  6954. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  6955. var sR = sRGBTransferFunction(SRGB[0]);
  6956. var sG = sRGBTransferFunction(SRGB[1]);
  6957. var sB = sRGBTransferFunction(SRGB[2]);
  6958. // Convert the values to rgb range [0, 255].
  6959. dest[destOffset] = Math.round(sR * 255);
  6960. dest[destOffset + 1] = Math.round(sG * 255);
  6961. dest[destOffset + 2] = Math.round(sB * 255);
  6962. }
  6963. CalRGBCS.prototype = {
  6964. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  6965. var rgb = new Uint8Array(3);
  6966. this.getRgbItem(src, srcOffset, rgb, 0);
  6967. return rgb;
  6968. },
  6969. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  6970. dest, destOffset) {
  6971. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  6972. },
  6973. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  6974. dest, destOffset, bits,
  6975. alpha01) {
  6976. var scale = 1 / ((1 << bits) - 1);
  6977. for (var i = 0; i < count; ++i) {
  6978. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  6979. srcOffset += 3;
  6980. destOffset += 3 + alpha01;
  6981. }
  6982. },
  6983. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  6984. return (inputLength * (3 + alpha01) / 3) | 0;
  6985. },
  6986. isPassthrough: ColorSpace.prototype.isPassthrough,
  6987. fillRgb: ColorSpace.prototype.fillRgb,
  6988. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  6989. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6990. },
  6991. usesZeroToOneRange: true
  6992. };
  6993. return CalRGBCS;
  6994. })();
  6995. //
  6996. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6997. //
  6998. var LabCS = (function LabCSClosure() {
  6999. function LabCS(whitePoint, blackPoint, range) {
  7000. this.name = 'Lab';
  7001. this.numComps = 3;
  7002. this.defaultColor = new Float32Array([0, 0, 0]);
  7003. if (!whitePoint) {
  7004. error('WhitePoint missing - required for color space Lab');
  7005. }
  7006. blackPoint = blackPoint || [0, 0, 0];
  7007. range = range || [-100, 100, -100, 100];
  7008. // Translate args to spec variables
  7009. this.XW = whitePoint[0];
  7010. this.YW = whitePoint[1];
  7011. this.ZW = whitePoint[2];
  7012. this.amin = range[0];
  7013. this.amax = range[1];
  7014. this.bmin = range[2];
  7015. this.bmax = range[3];
  7016. // These are here just for completeness - the spec doesn't offer any
  7017. // formulas that use BlackPoint in Lab
  7018. this.XB = blackPoint[0];
  7019. this.YB = blackPoint[1];
  7020. this.ZB = blackPoint[2];
  7021. // Validate vars as per spec
  7022. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  7023. error('Invalid WhitePoint components, no fallback available');
  7024. }
  7025. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  7026. info('Invalid BlackPoint, falling back to default');
  7027. this.XB = this.YB = this.ZB = 0;
  7028. }
  7029. if (this.amin > this.amax || this.bmin > this.bmax) {
  7030. info('Invalid Range, falling back to defaults');
  7031. this.amin = -100;
  7032. this.amax = 100;
  7033. this.bmin = -100;
  7034. this.bmax = 100;
  7035. }
  7036. }
  7037. // Function g(x) from spec
  7038. function fn_g(x) {
  7039. if (x >= 6 / 29) {
  7040. return x * x * x;
  7041. } else {
  7042. return (108 / 841) * (x - 4 / 29);
  7043. }
  7044. }
  7045. function decode(value, high1, low2, high2) {
  7046. return low2 + (value) * (high2 - low2) / (high1);
  7047. }
  7048. // If decoding is needed maxVal should be 2^bits per component - 1.
  7049. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  7050. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  7051. // not the usual [0, 1]. If a command like setFillColor is used the src
  7052. // values will already be within the correct range. However, if we are
  7053. // converting an image we have to map the values to the correct range given
  7054. // above.
  7055. // Ls,as,bs <---> L*,a*,b* in the spec
  7056. var Ls = src[srcOffset];
  7057. var as = src[srcOffset + 1];
  7058. var bs = src[srcOffset + 2];
  7059. if (maxVal !== false) {
  7060. Ls = decode(Ls, maxVal, 0, 100);
  7061. as = decode(as, maxVal, cs.amin, cs.amax);
  7062. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  7063. }
  7064. // Adjust limits of 'as' and 'bs'
  7065. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  7066. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  7067. // Computes intermediate variables X,Y,Z as per spec
  7068. var M = (Ls + 16) / 116;
  7069. var L = M + (as / 500);
  7070. var N = M - (bs / 200);
  7071. var X = cs.XW * fn_g(L);
  7072. var Y = cs.YW * fn_g(M);
  7073. var Z = cs.ZW * fn_g(N);
  7074. var r, g, b;
  7075. // Using different conversions for D50 and D65 white points,
  7076. // per http://www.color.org/srgb.pdf
  7077. if (cs.ZW < 1) {
  7078. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  7079. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  7080. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  7081. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  7082. } else {
  7083. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  7084. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  7085. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  7086. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  7087. }
  7088. // clamp color values to [0,1] range then convert to [0,255] range.
  7089. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  7090. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  7091. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  7092. }
  7093. LabCS.prototype = {
  7094. getRgb: ColorSpace.prototype.getRgb,
  7095. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  7096. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  7097. },
  7098. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  7099. dest, destOffset, bits,
  7100. alpha01) {
  7101. var maxVal = (1 << bits) - 1;
  7102. for (var i = 0; i < count; i++) {
  7103. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  7104. srcOffset += 3;
  7105. destOffset += 3 + alpha01;
  7106. }
  7107. },
  7108. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  7109. return (inputLength * (3 + alpha01) / 3) | 0;
  7110. },
  7111. isPassthrough: ColorSpace.prototype.isPassthrough,
  7112. fillRgb: ColorSpace.prototype.fillRgb,
  7113. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  7114. // XXX: Decoding is handled with the lab conversion because of the strange
  7115. // ranges that are used.
  7116. return true;
  7117. },
  7118. usesZeroToOneRange: false
  7119. };
  7120. return LabCS;
  7121. })();
  7122. var ARCFourCipher = (function ARCFourCipherClosure() {
  7123. function ARCFourCipher(key) {
  7124. this.a = 0;
  7125. this.b = 0;
  7126. var s = new Uint8Array(256);
  7127. var i, j = 0, tmp, keyLength = key.length;
  7128. for (i = 0; i < 256; ++i) {
  7129. s[i] = i;
  7130. }
  7131. for (i = 0; i < 256; ++i) {
  7132. tmp = s[i];
  7133. j = (j + tmp + key[i % keyLength]) & 0xFF;
  7134. s[i] = s[j];
  7135. s[j] = tmp;
  7136. }
  7137. this.s = s;
  7138. }
  7139. ARCFourCipher.prototype = {
  7140. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  7141. var i, n = data.length, tmp, tmp2;
  7142. var a = this.a, b = this.b, s = this.s;
  7143. var output = new Uint8Array(n);
  7144. for (i = 0; i < n; ++i) {
  7145. a = (a + 1) & 0xFF;
  7146. tmp = s[a];
  7147. b = (b + tmp) & 0xFF;
  7148. tmp2 = s[b];
  7149. s[a] = tmp2;
  7150. s[b] = tmp;
  7151. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  7152. }
  7153. this.a = a;
  7154. this.b = b;
  7155. return output;
  7156. }
  7157. };
  7158. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  7159. return ARCFourCipher;
  7160. })();
  7161. var calculateMD5 = (function calculateMD5Closure() {
  7162. var r = new Uint8Array([
  7163. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  7164. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  7165. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  7166. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  7167. var k = new Int32Array([
  7168. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  7169. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  7170. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  7171. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  7172. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  7173. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  7174. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  7175. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  7176. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  7177. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  7178. -145523070, -1120210379, 718787259, -343485551]);
  7179. function hash(data, offset, length) {
  7180. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  7181. // pre-processing
  7182. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  7183. var padded = new Uint8Array(paddedLength);
  7184. var i, j, n;
  7185. for (i = 0; i < length; ++i) {
  7186. padded[i] = data[offset++];
  7187. }
  7188. padded[i++] = 0x80;
  7189. n = paddedLength - 8;
  7190. while (i < n) {
  7191. padded[i++] = 0;
  7192. }
  7193. padded[i++] = (length << 3) & 0xFF;
  7194. padded[i++] = (length >> 5) & 0xFF;
  7195. padded[i++] = (length >> 13) & 0xFF;
  7196. padded[i++] = (length >> 21) & 0xFF;
  7197. padded[i++] = (length >>> 29) & 0xFF;
  7198. padded[i++] = 0;
  7199. padded[i++] = 0;
  7200. padded[i++] = 0;
  7201. var w = new Int32Array(16);
  7202. for (i = 0; i < paddedLength;) {
  7203. for (j = 0; j < 16; ++j, i += 4) {
  7204. w[j] = (padded[i] | (padded[i + 1] << 8) |
  7205. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  7206. }
  7207. var a = h0, b = h1, c = h2, d = h3, f, g;
  7208. for (j = 0; j < 64; ++j) {
  7209. if (j < 16) {
  7210. f = (b & c) | ((~b) & d);
  7211. g = j;
  7212. } else if (j < 32) {
  7213. f = (d & b) | ((~d) & c);
  7214. g = (5 * j + 1) & 15;
  7215. } else if (j < 48) {
  7216. f = b ^ c ^ d;
  7217. g = (3 * j + 5) & 15;
  7218. } else {
  7219. f = c ^ (b | (~d));
  7220. g = (7 * j) & 15;
  7221. }
  7222. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  7223. d = c;
  7224. c = b;
  7225. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  7226. a = tmp;
  7227. }
  7228. h0 = (h0 + a) | 0;
  7229. h1 = (h1 + b) | 0;
  7230. h2 = (h2 + c) | 0;
  7231. h3 = (h3 + d) | 0;
  7232. }
  7233. return new Uint8Array([
  7234. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  7235. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  7236. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  7237. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  7238. ]);
  7239. }
  7240. return hash;
  7241. })();
  7242. var Word64 = (function Word64Closure() {
  7243. function Word64(highInteger, lowInteger) {
  7244. this.high = highInteger | 0;
  7245. this.low = lowInteger | 0;
  7246. }
  7247. Word64.prototype = {
  7248. and: function Word64_and(word) {
  7249. this.high &= word.high;
  7250. this.low &= word.low;
  7251. },
  7252. xor: function Word64_xor(word) {
  7253. this.high ^= word.high;
  7254. this.low ^= word.low;
  7255. },
  7256. or: function Word64_or(word) {
  7257. this.high |= word.high;
  7258. this.low |= word.low;
  7259. },
  7260. shiftRight: function Word64_shiftRight(places) {
  7261. if (places >= 32) {
  7262. this.low = (this.high >>> (places - 32)) | 0;
  7263. this.high = 0;
  7264. } else {
  7265. this.low = (this.low >>> places) | (this.high << (32 - places));
  7266. this.high = (this.high >>> places) | 0;
  7267. }
  7268. },
  7269. shiftLeft: function Word64_shiftLeft(places) {
  7270. if (places >= 32) {
  7271. this.high = this.low << (places - 32);
  7272. this.low = 0;
  7273. } else {
  7274. this.high = (this.high << places) | (this.low >>> (32 - places));
  7275. this.low = this.low << places;
  7276. }
  7277. },
  7278. rotateRight: function Word64_rotateRight(places) {
  7279. var low, high;
  7280. if (places & 32) {
  7281. high = this.low;
  7282. low = this.high;
  7283. } else {
  7284. low = this.low;
  7285. high = this.high;
  7286. }
  7287. places &= 31;
  7288. this.low = (low >>> places) | (high << (32 - places));
  7289. this.high = (high >>> places) | (low << (32 - places));
  7290. },
  7291. not: function Word64_not() {
  7292. this.high = ~this.high;
  7293. this.low = ~this.low;
  7294. },
  7295. add: function Word64_add(word) {
  7296. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  7297. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  7298. if (lowAdd > 0xFFFFFFFF) {
  7299. highAdd += 1;
  7300. }
  7301. this.low = lowAdd | 0;
  7302. this.high = highAdd | 0;
  7303. },
  7304. copyTo: function Word64_copyTo(bytes, offset) {
  7305. bytes[offset] = (this.high >>> 24) & 0xFF;
  7306. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  7307. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  7308. bytes[offset + 3] = this.high & 0xFF;
  7309. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  7310. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  7311. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  7312. bytes[offset + 7] = this.low & 0xFF;
  7313. },
  7314. assign: function Word64_assign(word) {
  7315. this.high = word.high;
  7316. this.low = word.low;
  7317. }
  7318. };
  7319. return Word64;
  7320. })();
  7321. var calculateSHA256 = (function calculateSHA256Closure() {
  7322. function rotr(x, n) {
  7323. return (x >>> n) | (x << 32 - n);
  7324. }
  7325. function ch(x, y, z) {
  7326. return (x & y) ^ (~x & z);
  7327. }
  7328. function maj(x, y, z) {
  7329. return (x & y) ^ (x & z) ^ (y & z);
  7330. }
  7331. function sigma(x) {
  7332. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  7333. }
  7334. function sigmaPrime(x) {
  7335. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  7336. }
  7337. function littleSigma(x) {
  7338. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  7339. }
  7340. function littleSigmaPrime(x) {
  7341. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  7342. }
  7343. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  7344. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  7345. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  7346. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  7347. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  7348. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  7349. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  7350. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  7351. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  7352. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  7353. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  7354. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  7355. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  7356. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  7357. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  7358. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  7359. function hash(data, offset, length) {
  7360. // initial hash values
  7361. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  7362. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  7363. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  7364. // pre-processing
  7365. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  7366. var padded = new Uint8Array(paddedLength);
  7367. var i, j, n;
  7368. for (i = 0; i < length; ++i) {
  7369. padded[i] = data[offset++];
  7370. }
  7371. padded[i++] = 0x80;
  7372. n = paddedLength - 8;
  7373. while (i < n) {
  7374. padded[i++] = 0;
  7375. }
  7376. padded[i++] = 0;
  7377. padded[i++] = 0;
  7378. padded[i++] = 0;
  7379. padded[i++] = (length >>> 29) & 0xFF;
  7380. padded[i++] = (length >> 21) & 0xFF;
  7381. padded[i++] = (length >> 13) & 0xFF;
  7382. padded[i++] = (length >> 5) & 0xFF;
  7383. padded[i++] = (length << 3) & 0xFF;
  7384. var w = new Uint32Array(64);
  7385. // for each 512 bit block
  7386. for (i = 0; i < paddedLength;) {
  7387. for (j = 0; j < 16; ++j) {
  7388. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  7389. (padded[i + 2] << 8) | (padded[i + 3]));
  7390. i += 4;
  7391. }
  7392. for (j = 16; j < 64; ++j) {
  7393. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  7394. littleSigma(w[j - 15]) + w[j - 16] | 0;
  7395. }
  7396. var a = h0, b = h1, c = h2, d = h3, e = h4,
  7397. f = h5, g = h6, h = h7, t1, t2;
  7398. for (j = 0; j < 64; ++j) {
  7399. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  7400. t2 = sigma(a) + maj(a, b, c);
  7401. h = g;
  7402. g = f;
  7403. f = e;
  7404. e = (d + t1) | 0;
  7405. d = c;
  7406. c = b;
  7407. b = a;
  7408. a = (t1 + t2) | 0;
  7409. }
  7410. h0 = (h0 + a) | 0;
  7411. h1 = (h1 + b) | 0;
  7412. h2 = (h2 + c) | 0;
  7413. h3 = (h3 + d) | 0;
  7414. h4 = (h4 + e) | 0;
  7415. h5 = (h5 + f) | 0;
  7416. h6 = (h6 + g) | 0;
  7417. h7 = (h7 + h) | 0;
  7418. }
  7419. return new Uint8Array([
  7420. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  7421. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  7422. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  7423. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  7424. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  7425. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  7426. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  7427. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  7428. ]);
  7429. }
  7430. return hash;
  7431. })();
  7432. var calculateSHA512 = (function calculateSHA512Closure() {
  7433. function ch(result, x, y, z, tmp) {
  7434. result.assign(x);
  7435. result.and(y);
  7436. tmp.assign(x);
  7437. tmp.not();
  7438. tmp.and(z);
  7439. result.xor(tmp);
  7440. }
  7441. function maj(result, x, y, z, tmp) {
  7442. result.assign(x);
  7443. result.and(y);
  7444. tmp.assign(x);
  7445. tmp.and(z);
  7446. result.xor(tmp);
  7447. tmp.assign(y);
  7448. tmp.and(z);
  7449. result.xor(tmp);
  7450. }
  7451. function sigma(result, x, tmp) {
  7452. result.assign(x);
  7453. result.rotateRight(28);
  7454. tmp.assign(x);
  7455. tmp.rotateRight(34);
  7456. result.xor(tmp);
  7457. tmp.assign(x);
  7458. tmp.rotateRight(39);
  7459. result.xor(tmp);
  7460. }
  7461. function sigmaPrime(result, x, tmp) {
  7462. result.assign(x);
  7463. result.rotateRight(14);
  7464. tmp.assign(x);
  7465. tmp.rotateRight(18);
  7466. result.xor(tmp);
  7467. tmp.assign(x);
  7468. tmp.rotateRight(41);
  7469. result.xor(tmp);
  7470. }
  7471. function littleSigma(result, x, tmp) {
  7472. result.assign(x);
  7473. result.rotateRight(1);
  7474. tmp.assign(x);
  7475. tmp.rotateRight(8);
  7476. result.xor(tmp);
  7477. tmp.assign(x);
  7478. tmp.shiftRight(7);
  7479. result.xor(tmp);
  7480. }
  7481. function littleSigmaPrime(result, x, tmp) {
  7482. result.assign(x);
  7483. result.rotateRight(19);
  7484. tmp.assign(x);
  7485. tmp.rotateRight(61);
  7486. result.xor(tmp);
  7487. tmp.assign(x);
  7488. tmp.shiftRight(6);
  7489. result.xor(tmp);
  7490. }
  7491. var k = [
  7492. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  7493. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  7494. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  7495. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  7496. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  7497. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  7498. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  7499. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  7500. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  7501. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  7502. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  7503. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  7504. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  7505. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  7506. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  7507. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  7508. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  7509. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  7510. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  7511. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  7512. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  7513. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  7514. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  7515. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  7516. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  7517. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  7518. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  7519. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  7520. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  7521. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  7522. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  7523. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  7524. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  7525. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  7526. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  7527. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  7528. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  7529. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  7530. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  7531. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  7532. function hash(data, offset, length, mode384) {
  7533. mode384 = !!mode384;
  7534. // initial hash values
  7535. var h0, h1, h2, h3, h4, h5, h6, h7;
  7536. if (!mode384) {
  7537. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  7538. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  7539. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  7540. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  7541. h4 = new Word64(0x510e527f, 0xade682d1);
  7542. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  7543. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  7544. h7 = new Word64(0x5be0cd19, 0x137e2179);
  7545. }
  7546. else {
  7547. // SHA384 is exactly the same
  7548. // except with different starting values and a trimmed result
  7549. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  7550. h1 = new Word64(0x629a292a, 0x367cd507);
  7551. h2 = new Word64(0x9159015a, 0x3070dd17);
  7552. h3 = new Word64(0x152fecd8, 0xf70e5939);
  7553. h4 = new Word64(0x67332667, 0xffc00b31);
  7554. h5 = new Word64(0x8eb44a87, 0x68581511);
  7555. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  7556. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  7557. }
  7558. // pre-processing
  7559. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  7560. var padded = new Uint8Array(paddedLength);
  7561. var i, j, n;
  7562. for (i = 0; i < length; ++i) {
  7563. padded[i] = data[offset++];
  7564. }
  7565. padded[i++] = 0x80;
  7566. n = paddedLength - 16;
  7567. while (i < n) {
  7568. padded[i++] = 0;
  7569. }
  7570. padded[i++] = 0;
  7571. padded[i++] = 0;
  7572. padded[i++] = 0;
  7573. padded[i++] = 0;
  7574. padded[i++] = 0;
  7575. padded[i++] = 0;
  7576. padded[i++] = 0;
  7577. padded[i++] = 0;
  7578. padded[i++] = 0;
  7579. padded[i++] = 0;
  7580. padded[i++] = 0;
  7581. padded[i++] = (length >>> 29) & 0xFF;
  7582. padded[i++] = (length >> 21) & 0xFF;
  7583. padded[i++] = (length >> 13) & 0xFF;
  7584. padded[i++] = (length >> 5) & 0xFF;
  7585. padded[i++] = (length << 3) & 0xFF;
  7586. var w = new Array(80);
  7587. for (i = 0; i < 80; i++) {
  7588. w[i] = new Word64(0, 0);
  7589. }
  7590. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  7591. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  7592. var g = new Word64(0, 0), h = new Word64(0, 0);
  7593. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  7594. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  7595. // for each 1024 bit block
  7596. for (i = 0; i < paddedLength;) {
  7597. for (j = 0; j < 16; ++j) {
  7598. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  7599. (padded[i + 2] << 8) | (padded[i + 3]);
  7600. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  7601. (padded[i + 6]) << 8 | (padded[i + 7]);
  7602. i += 8;
  7603. }
  7604. for (j = 16; j < 80; ++j) {
  7605. tmp3 = w[j];
  7606. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  7607. tmp3.add(w[j - 7]);
  7608. littleSigma(tmp1, w[j - 15], tmp2);
  7609. tmp3.add(tmp1);
  7610. tmp3.add(w[j - 16]);
  7611. }
  7612. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  7613. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  7614. for (j = 0; j < 80; ++j) {
  7615. t1.assign(h);
  7616. sigmaPrime(tmp1, e, tmp2);
  7617. t1.add(tmp1);
  7618. ch(tmp1, e, f, g, tmp2);
  7619. t1.add(tmp1);
  7620. t1.add(k[j]);
  7621. t1.add(w[j]);
  7622. sigma(t2, a, tmp2);
  7623. maj(tmp1, a, b, c, tmp2);
  7624. t2.add(tmp1);
  7625. tmp3 = h;
  7626. h = g;
  7627. g = f;
  7628. f = e;
  7629. d.add(t1);
  7630. e = d;
  7631. d = c;
  7632. c = b;
  7633. b = a;
  7634. tmp3.assign(t1);
  7635. tmp3.add(t2);
  7636. a = tmp3;
  7637. }
  7638. h0.add(a);
  7639. h1.add(b);
  7640. h2.add(c);
  7641. h3.add(d);
  7642. h4.add(e);
  7643. h5.add(f);
  7644. h6.add(g);
  7645. h7.add(h);
  7646. }
  7647. var result;
  7648. if (!mode384) {
  7649. result = new Uint8Array(64);
  7650. h0.copyTo(result,0);
  7651. h1.copyTo(result,8);
  7652. h2.copyTo(result,16);
  7653. h3.copyTo(result,24);
  7654. h4.copyTo(result,32);
  7655. h5.copyTo(result,40);
  7656. h6.copyTo(result,48);
  7657. h7.copyTo(result,56);
  7658. }
  7659. else {
  7660. result = new Uint8Array(48);
  7661. h0.copyTo(result,0);
  7662. h1.copyTo(result,8);
  7663. h2.copyTo(result,16);
  7664. h3.copyTo(result,24);
  7665. h4.copyTo(result,32);
  7666. h5.copyTo(result,40);
  7667. }
  7668. return result;
  7669. }
  7670. return hash;
  7671. })();
  7672. var calculateSHA384 = (function calculateSHA384Closure() {
  7673. function hash(data, offset, length) {
  7674. return calculateSHA512(data, offset, length, true);
  7675. }
  7676. return hash;
  7677. })();
  7678. var NullCipher = (function NullCipherClosure() {
  7679. function NullCipher() {
  7680. }
  7681. NullCipher.prototype = {
  7682. decryptBlock: function NullCipher_decryptBlock(data) {
  7683. return data;
  7684. }
  7685. };
  7686. return NullCipher;
  7687. })();
  7688. var AES128Cipher = (function AES128CipherClosure() {
  7689. var rcon = new Uint8Array([
  7690. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7691. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7692. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7693. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7694. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7695. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7696. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7697. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7698. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7699. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7700. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7701. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7702. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7703. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7704. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7705. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7706. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7707. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7708. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7709. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7710. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7711. 0x74, 0xe8, 0xcb, 0x8d]);
  7712. var s = new Uint8Array([
  7713. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7714. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7715. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7716. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7717. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7718. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7719. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7720. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7721. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7722. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7723. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7724. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7725. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7726. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7727. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7728. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7729. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7730. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7731. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7732. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7733. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7734. 0xb0, 0x54, 0xbb, 0x16]);
  7735. var inv_s = new Uint8Array([
  7736. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7737. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7738. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7739. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7740. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7741. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7742. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7743. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7744. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7745. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7746. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7747. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7748. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7749. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7750. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7751. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7752. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7753. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7754. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7755. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7756. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7757. 0x55, 0x21, 0x0c, 0x7d]);
  7758. var mixCol = new Uint8Array(256);
  7759. for (var i = 0; i < 256; i++) {
  7760. if (i < 128) {
  7761. mixCol[i] = i << 1;
  7762. } else {
  7763. mixCol[i] = (i << 1) ^ 0x1b;
  7764. }
  7765. }
  7766. var mix = new Uint32Array([
  7767. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7768. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7769. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7770. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7771. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7772. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7773. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7774. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7775. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7776. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7777. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7778. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7779. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7780. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7781. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7782. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7783. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7784. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7785. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7786. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7787. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7788. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7789. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7790. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7791. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7792. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7793. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7794. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7795. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7796. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7797. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7798. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7799. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7800. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7801. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7802. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7803. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7804. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7805. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7806. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7807. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7808. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7809. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7810. function expandKey128(cipherKey) {
  7811. var b = 176, result = new Uint8Array(b);
  7812. result.set(cipherKey);
  7813. for (var j = 16, i = 1; j < b; ++i) {
  7814. // RotWord
  7815. var t1 = result[j - 3], t2 = result[j - 2],
  7816. t3 = result[j - 1], t4 = result[j - 4];
  7817. // SubWord
  7818. t1 = s[t1];
  7819. t2 = s[t2];
  7820. t3 = s[t3];
  7821. t4 = s[t4];
  7822. // Rcon
  7823. t1 = t1 ^ rcon[i];
  7824. for (var n = 0; n < 4; ++n) {
  7825. result[j] = (t1 ^= result[j - 16]);
  7826. j++;
  7827. result[j] = (t2 ^= result[j - 16]);
  7828. j++;
  7829. result[j] = (t3 ^= result[j - 16]);
  7830. j++;
  7831. result[j] = (t4 ^= result[j - 16]);
  7832. j++;
  7833. }
  7834. }
  7835. return result;
  7836. }
  7837. function decrypt128(input, key) {
  7838. var state = new Uint8Array(16);
  7839. state.set(input);
  7840. var i, j, k;
  7841. var t, u, v;
  7842. // AddRoundKey
  7843. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7844. state[j] ^= key[k];
  7845. }
  7846. for (i = 9; i >= 1; --i) {
  7847. // InvShiftRows
  7848. t = state[13];
  7849. state[13] = state[9];
  7850. state[9] = state[5];
  7851. state[5] = state[1];
  7852. state[1] = t;
  7853. t = state[14];
  7854. u = state[10];
  7855. state[14] = state[6];
  7856. state[10] = state[2];
  7857. state[6] = t;
  7858. state[2] = u;
  7859. t = state[15];
  7860. u = state[11];
  7861. v = state[7];
  7862. state[15] = state[3];
  7863. state[11] = t;
  7864. state[7] = u;
  7865. state[3] = v;
  7866. // InvSubBytes
  7867. for (j = 0; j < 16; ++j) {
  7868. state[j] = inv_s[state[j]];
  7869. }
  7870. // AddRoundKey
  7871. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7872. state[j] ^= key[k];
  7873. }
  7874. // InvMixColumns
  7875. for (j = 0; j < 16; j += 4) {
  7876. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7877. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7878. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7879. (s3 >>> 24) ^ (s3 << 8));
  7880. state[j] = (t >>> 24) & 0xFF;
  7881. state[j + 1] = (t >> 16) & 0xFF;
  7882. state[j + 2] = (t >> 8) & 0xFF;
  7883. state[j + 3] = t & 0xFF;
  7884. }
  7885. }
  7886. // InvShiftRows
  7887. t = state[13];
  7888. state[13] = state[9];
  7889. state[9] = state[5];
  7890. state[5] = state[1];
  7891. state[1] = t;
  7892. t = state[14];
  7893. u = state[10];
  7894. state[14] = state[6];
  7895. state[10] = state[2];
  7896. state[6] = t;
  7897. state[2] = u;
  7898. t = state[15];
  7899. u = state[11];
  7900. v = state[7];
  7901. state[15] = state[3];
  7902. state[11] = t;
  7903. state[7] = u;
  7904. state[3] = v;
  7905. for (j = 0; j < 16; ++j) {
  7906. // InvSubBytes
  7907. state[j] = inv_s[state[j]];
  7908. // AddRoundKey
  7909. state[j] ^= key[j];
  7910. }
  7911. return state;
  7912. }
  7913. function encrypt128(input, key) {
  7914. var t, u, v, k;
  7915. var state = new Uint8Array(16);
  7916. state.set(input);
  7917. for (j = 0; j < 16; ++j) {
  7918. // AddRoundKey
  7919. state[j] ^= key[j];
  7920. }
  7921. for (i = 1; i < 10; i++) {
  7922. //SubBytes
  7923. for (j = 0; j < 16; ++j) {
  7924. state[j] = s[state[j]];
  7925. }
  7926. //ShiftRows
  7927. v = state[1];
  7928. state[1] = state[5];
  7929. state[5] = state[9];
  7930. state[9] = state[13];
  7931. state[13] = v;
  7932. v = state[2];
  7933. u = state[6];
  7934. state[2] = state[10];
  7935. state[6] = state[14];
  7936. state[10] = v;
  7937. state[14] = u;
  7938. v = state[3];
  7939. u = state[7];
  7940. t = state[11];
  7941. state[3] = state[15];
  7942. state[7] = v;
  7943. state[11] = u;
  7944. state[15] = t;
  7945. //MixColumns
  7946. for (var j = 0; j < 16; j += 4) {
  7947. var s0 = state[j + 0], s1 = state[j + 1];
  7948. var s2 = state[j + 2], s3 = state[j + 3];
  7949. t = s0 ^ s1 ^ s2 ^ s3;
  7950. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7951. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7952. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7953. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7954. }
  7955. //AddRoundKey
  7956. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7957. state[j] ^= key[k];
  7958. }
  7959. }
  7960. //SubBytes
  7961. for (j = 0; j < 16; ++j) {
  7962. state[j] = s[state[j]];
  7963. }
  7964. //ShiftRows
  7965. v = state[1];
  7966. state[1] = state[5];
  7967. state[5] = state[9];
  7968. state[9] = state[13];
  7969. state[13] = v;
  7970. v = state[2];
  7971. u = state[6];
  7972. state[2] = state[10];
  7973. state[6] = state[14];
  7974. state[10] = v;
  7975. state[14] = u;
  7976. v = state[3];
  7977. u = state[7];
  7978. t = state[11];
  7979. state[3] = state[15];
  7980. state[7] = v;
  7981. state[11] = u;
  7982. state[15] = t;
  7983. //AddRoundKey
  7984. for (j = 0, k = 160; j < 16; ++j, ++k) {
  7985. state[j] ^= key[k];
  7986. }
  7987. return state;
  7988. }
  7989. function AES128Cipher(key) {
  7990. this.key = expandKey128(key);
  7991. this.buffer = new Uint8Array(16);
  7992. this.bufferPosition = 0;
  7993. }
  7994. function decryptBlock2(data, finalize) {
  7995. var i, j, ii, sourceLength = data.length,
  7996. buffer = this.buffer, bufferLength = this.bufferPosition,
  7997. result = [], iv = this.iv;
  7998. for (i = 0; i < sourceLength; ++i) {
  7999. buffer[bufferLength] = data[i];
  8000. ++bufferLength;
  8001. if (bufferLength < 16) {
  8002. continue;
  8003. }
  8004. // buffer is full, decrypting
  8005. var plain = decrypt128(buffer, this.key);
  8006. // xor-ing the IV vector to get plain text
  8007. for (j = 0; j < 16; ++j) {
  8008. plain[j] ^= iv[j];
  8009. }
  8010. iv = buffer;
  8011. result.push(plain);
  8012. buffer = new Uint8Array(16);
  8013. bufferLength = 0;
  8014. }
  8015. // saving incomplete buffer
  8016. this.buffer = buffer;
  8017. this.bufferLength = bufferLength;
  8018. this.iv = iv;
  8019. if (result.length === 0) {
  8020. return new Uint8Array([]);
  8021. }
  8022. // combining plain text blocks into one
  8023. var outputLength = 16 * result.length;
  8024. if (finalize) {
  8025. // undo a padding that is described in RFC 2898
  8026. var lastBlock = result[result.length - 1];
  8027. var psLen = lastBlock[15];
  8028. if (psLen <= 16) {
  8029. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8030. if (lastBlock[i] !== psLen) {
  8031. // Invalid padding, assume that the block has no padding.
  8032. psLen = 0;
  8033. break;
  8034. }
  8035. }
  8036. outputLength -= psLen;
  8037. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8038. }
  8039. }
  8040. var output = new Uint8Array(outputLength);
  8041. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8042. output.set(result[i], j);
  8043. }
  8044. return output;
  8045. }
  8046. AES128Cipher.prototype = {
  8047. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  8048. var i, sourceLength = data.length;
  8049. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8050. // waiting for IV values -- they are at the start of the stream
  8051. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  8052. buffer[bufferLength] = data[i];
  8053. }
  8054. if (bufferLength < 16) {
  8055. // need more data
  8056. this.bufferLength = bufferLength;
  8057. return new Uint8Array([]);
  8058. }
  8059. this.iv = buffer;
  8060. this.buffer = new Uint8Array(16);
  8061. this.bufferLength = 0;
  8062. // starting decryption
  8063. this.decryptBlock = decryptBlock2;
  8064. return this.decryptBlock(data.subarray(16), finalize);
  8065. },
  8066. encrypt: function AES128Cipher_encrypt(data, iv) {
  8067. var i, j, ii, sourceLength = data.length,
  8068. buffer = this.buffer, bufferLength = this.bufferPosition,
  8069. result = [];
  8070. if (!iv) {
  8071. iv = new Uint8Array(16);
  8072. }
  8073. for (i = 0; i < sourceLength; ++i) {
  8074. buffer[bufferLength] = data[i];
  8075. ++bufferLength;
  8076. if (bufferLength < 16) {
  8077. continue;
  8078. }
  8079. for (j = 0; j < 16; ++j) {
  8080. buffer[j] ^= iv[j];
  8081. }
  8082. // buffer is full, encrypting
  8083. var cipher = encrypt128(buffer, this.key);
  8084. iv = cipher;
  8085. result.push(cipher);
  8086. buffer = new Uint8Array(16);
  8087. bufferLength = 0;
  8088. }
  8089. // saving incomplete buffer
  8090. this.buffer = buffer;
  8091. this.bufferLength = bufferLength;
  8092. this.iv = iv;
  8093. if (result.length === 0) {
  8094. return new Uint8Array([]);
  8095. }
  8096. // combining plain text blocks into one
  8097. var outputLength = 16 * result.length;
  8098. var output = new Uint8Array(outputLength);
  8099. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8100. output.set(result[i], j);
  8101. }
  8102. return output;
  8103. }
  8104. };
  8105. return AES128Cipher;
  8106. })();
  8107. var AES256Cipher = (function AES256CipherClosure() {
  8108. var rcon = new Uint8Array([
  8109. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8110. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8111. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8112. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8113. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  8114. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  8115. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  8116. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  8117. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  8118. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  8119. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  8120. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  8121. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  8122. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  8123. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  8124. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  8125. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  8126. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  8127. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  8128. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  8129. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  8130. 0x74, 0xe8, 0xcb, 0x8d]);
  8131. var s = new Uint8Array([
  8132. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  8133. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  8134. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  8135. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  8136. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  8137. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  8138. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  8139. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  8140. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  8141. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  8142. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  8143. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  8144. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  8145. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  8146. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  8147. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  8148. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  8149. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  8150. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  8151. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  8152. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  8153. 0xb0, 0x54, 0xbb, 0x16]);
  8154. var inv_s = new Uint8Array([
  8155. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  8156. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  8157. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  8158. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  8159. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  8160. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  8161. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  8162. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  8163. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  8164. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  8165. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  8166. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  8167. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  8168. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  8169. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  8170. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  8171. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  8172. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  8173. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  8174. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  8175. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  8176. 0x55, 0x21, 0x0c, 0x7d]);
  8177. var mixCol = new Uint8Array(256);
  8178. for (var i = 0; i < 256; i++) {
  8179. if (i < 128) {
  8180. mixCol[i] = i << 1;
  8181. } else {
  8182. mixCol[i] = (i << 1) ^ 0x1b;
  8183. }
  8184. }
  8185. var mix = new Uint32Array([
  8186. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  8187. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  8188. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  8189. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  8190. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  8191. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  8192. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  8193. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  8194. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  8195. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  8196. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  8197. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  8198. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  8199. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  8200. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  8201. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  8202. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  8203. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  8204. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  8205. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  8206. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  8207. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  8208. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  8209. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  8210. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  8211. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  8212. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  8213. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  8214. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  8215. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  8216. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  8217. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  8218. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  8219. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  8220. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  8221. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  8222. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  8223. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  8224. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  8225. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  8226. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  8227. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  8228. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  8229. function expandKey256(cipherKey) {
  8230. var b = 240, result = new Uint8Array(b);
  8231. var r = 1;
  8232. result.set(cipherKey);
  8233. for (var j = 32, i = 1; j < b; ++i) {
  8234. if (j % 32 === 16) {
  8235. t1 = s[t1];
  8236. t2 = s[t2];
  8237. t3 = s[t3];
  8238. t4 = s[t4];
  8239. } else if (j % 32 === 0) {
  8240. // RotWord
  8241. var t1 = result[j - 3], t2 = result[j - 2],
  8242. t3 = result[j - 1], t4 = result[j - 4];
  8243. // SubWord
  8244. t1 = s[t1];
  8245. t2 = s[t2];
  8246. t3 = s[t3];
  8247. t4 = s[t4];
  8248. // Rcon
  8249. t1 = t1 ^ r;
  8250. if ((r <<= 1) >= 256) {
  8251. r = (r ^ 0x1b) & 0xFF;
  8252. }
  8253. }
  8254. for (var n = 0; n < 4; ++n) {
  8255. result[j] = (t1 ^= result[j - 32]);
  8256. j++;
  8257. result[j] = (t2 ^= result[j - 32]);
  8258. j++;
  8259. result[j] = (t3 ^= result[j - 32]);
  8260. j++;
  8261. result[j] = (t4 ^= result[j - 32]);
  8262. j++;
  8263. }
  8264. }
  8265. return result;
  8266. }
  8267. function decrypt256(input, key) {
  8268. var state = new Uint8Array(16);
  8269. state.set(input);
  8270. var i, j, k;
  8271. var t, u, v;
  8272. // AddRoundKey
  8273. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8274. state[j] ^= key[k];
  8275. }
  8276. for (i = 13; i >= 1; --i) {
  8277. // InvShiftRows
  8278. t = state[13];
  8279. state[13] = state[9];
  8280. state[9] = state[5];
  8281. state[5] = state[1];
  8282. state[1] = t;
  8283. t = state[14];
  8284. u = state[10];
  8285. state[14] = state[6];
  8286. state[10] = state[2];
  8287. state[6] = t;
  8288. state[2] = u;
  8289. t = state[15];
  8290. u = state[11];
  8291. v = state[7];
  8292. state[15] = state[3];
  8293. state[11] = t;
  8294. state[7] = u;
  8295. state[3] = v;
  8296. // InvSubBytes
  8297. for (j = 0; j < 16; ++j) {
  8298. state[j] = inv_s[state[j]];
  8299. }
  8300. // AddRoundKey
  8301. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8302. state[j] ^= key[k];
  8303. }
  8304. // InvMixColumns
  8305. for (j = 0; j < 16; j += 4) {
  8306. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  8307. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  8308. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  8309. (s3 >>> 24) ^ (s3 << 8));
  8310. state[j] = (t >>> 24) & 0xFF;
  8311. state[j + 1] = (t >> 16) & 0xFF;
  8312. state[j + 2] = (t >> 8) & 0xFF;
  8313. state[j + 3] = t & 0xFF;
  8314. }
  8315. }
  8316. // InvShiftRows
  8317. t = state[13];
  8318. state[13] = state[9];
  8319. state[9] = state[5];
  8320. state[5] = state[1];
  8321. state[1] = t;
  8322. t = state[14];
  8323. u = state[10];
  8324. state[14] = state[6];
  8325. state[10] = state[2];
  8326. state[6] = t;
  8327. state[2] = u;
  8328. t = state[15];
  8329. u = state[11];
  8330. v = state[7];
  8331. state[15] = state[3];
  8332. state[11] = t;
  8333. state[7] = u;
  8334. state[3] = v;
  8335. for (j = 0; j < 16; ++j) {
  8336. // InvSubBytes
  8337. state[j] = inv_s[state[j]];
  8338. // AddRoundKey
  8339. state[j] ^= key[j];
  8340. }
  8341. return state;
  8342. }
  8343. function encrypt256(input, key) {
  8344. var t, u, v, k;
  8345. var state = new Uint8Array(16);
  8346. state.set(input);
  8347. for (j = 0; j < 16; ++j) {
  8348. // AddRoundKey
  8349. state[j] ^= key[j];
  8350. }
  8351. for (i = 1; i < 14; i++) {
  8352. //SubBytes
  8353. for (j = 0; j < 16; ++j) {
  8354. state[j] = s[state[j]];
  8355. }
  8356. //ShiftRows
  8357. v = state[1];
  8358. state[1] = state[5];
  8359. state[5] = state[9];
  8360. state[9] = state[13];
  8361. state[13] = v;
  8362. v = state[2];
  8363. u = state[6];
  8364. state[2] = state[10];
  8365. state[6] = state[14];
  8366. state[10] = v;
  8367. state[14] = u;
  8368. v = state[3];
  8369. u = state[7];
  8370. t = state[11];
  8371. state[3] = state[15];
  8372. state[7] = v;
  8373. state[11] = u;
  8374. state[15] = t;
  8375. //MixColumns
  8376. for (var j = 0; j < 16; j += 4) {
  8377. var s0 = state[j + 0], s1 = state[j + 1];
  8378. var s2 = state[j + 2], s3 = state[j + 3];
  8379. t = s0 ^ s1 ^ s2 ^ s3;
  8380. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  8381. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  8382. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  8383. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  8384. }
  8385. //AddRoundKey
  8386. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  8387. state[j] ^= key[k];
  8388. }
  8389. }
  8390. //SubBytes
  8391. for (j = 0; j < 16; ++j) {
  8392. state[j] = s[state[j]];
  8393. }
  8394. //ShiftRows
  8395. v = state[1];
  8396. state[1] = state[5];
  8397. state[5] = state[9];
  8398. state[9] = state[13];
  8399. state[13] = v;
  8400. v = state[2];
  8401. u = state[6];
  8402. state[2] = state[10];
  8403. state[6] = state[14];
  8404. state[10] = v;
  8405. state[14] = u;
  8406. v = state[3];
  8407. u = state[7];
  8408. t = state[11];
  8409. state[3] = state[15];
  8410. state[7] = v;
  8411. state[11] = u;
  8412. state[15] = t;
  8413. //AddRoundKey
  8414. for (j = 0, k = 224; j < 16; ++j, ++k) {
  8415. state[j] ^= key[k];
  8416. }
  8417. return state;
  8418. }
  8419. function AES256Cipher(key) {
  8420. this.key = expandKey256(key);
  8421. this.buffer = new Uint8Array(16);
  8422. this.bufferPosition = 0;
  8423. }
  8424. function decryptBlock2(data, finalize) {
  8425. var i, j, ii, sourceLength = data.length,
  8426. buffer = this.buffer, bufferLength = this.bufferPosition,
  8427. result = [], iv = this.iv;
  8428. for (i = 0; i < sourceLength; ++i) {
  8429. buffer[bufferLength] = data[i];
  8430. ++bufferLength;
  8431. if (bufferLength < 16) {
  8432. continue;
  8433. }
  8434. // buffer is full, decrypting
  8435. var plain = decrypt256(buffer, this.key);
  8436. // xor-ing the IV vector to get plain text
  8437. for (j = 0; j < 16; ++j) {
  8438. plain[j] ^= iv[j];
  8439. }
  8440. iv = buffer;
  8441. result.push(plain);
  8442. buffer = new Uint8Array(16);
  8443. bufferLength = 0;
  8444. }
  8445. // saving incomplete buffer
  8446. this.buffer = buffer;
  8447. this.bufferLength = bufferLength;
  8448. this.iv = iv;
  8449. if (result.length === 0) {
  8450. return new Uint8Array([]);
  8451. }
  8452. // combining plain text blocks into one
  8453. var outputLength = 16 * result.length;
  8454. if (finalize) {
  8455. // undo a padding that is described in RFC 2898
  8456. var lastBlock = result[result.length - 1];
  8457. var psLen = lastBlock[15];
  8458. if (psLen <= 16) {
  8459. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  8460. if (lastBlock[i] !== psLen) {
  8461. // Invalid padding, assume that the block has no padding.
  8462. psLen = 0;
  8463. break;
  8464. }
  8465. }
  8466. outputLength -= psLen;
  8467. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  8468. }
  8469. }
  8470. var output = new Uint8Array(outputLength);
  8471. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8472. output.set(result[i], j);
  8473. }
  8474. return output;
  8475. }
  8476. AES256Cipher.prototype = {
  8477. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  8478. var i, sourceLength = data.length;
  8479. var buffer = this.buffer, bufferLength = this.bufferPosition;
  8480. // if not supplied an IV wait for IV values
  8481. // they are at the start of the stream
  8482. if (iv) {
  8483. this.iv = iv;
  8484. } else {
  8485. for (i = 0; bufferLength < 16 &&
  8486. i < sourceLength; ++i, ++bufferLength) {
  8487. buffer[bufferLength] = data[i];
  8488. }
  8489. if (bufferLength < 16) {
  8490. //need more data
  8491. this.bufferLength = bufferLength;
  8492. return new Uint8Array([]);
  8493. }
  8494. this.iv = buffer;
  8495. data = data.subarray(16);
  8496. }
  8497. this.buffer = new Uint8Array(16);
  8498. this.bufferLength = 0;
  8499. // starting decryption
  8500. this.decryptBlock = decryptBlock2;
  8501. return this.decryptBlock(data, finalize);
  8502. },
  8503. encrypt: function AES256Cipher_encrypt(data, iv) {
  8504. var i, j, ii, sourceLength = data.length,
  8505. buffer = this.buffer, bufferLength = this.bufferPosition,
  8506. result = [];
  8507. if (!iv) {
  8508. iv = new Uint8Array(16);
  8509. }
  8510. for (i = 0; i < sourceLength; ++i) {
  8511. buffer[bufferLength] = data[i];
  8512. ++bufferLength;
  8513. if (bufferLength < 16) {
  8514. continue;
  8515. }
  8516. for (j = 0; j < 16; ++j) {
  8517. buffer[j] ^= iv[j];
  8518. }
  8519. // buffer is full, encrypting
  8520. var cipher = encrypt256(buffer, this.key);
  8521. this.iv = cipher;
  8522. result.push(cipher);
  8523. buffer = new Uint8Array(16);
  8524. bufferLength = 0;
  8525. }
  8526. // saving incomplete buffer
  8527. this.buffer = buffer;
  8528. this.bufferLength = bufferLength;
  8529. this.iv = iv;
  8530. if (result.length === 0) {
  8531. return new Uint8Array([]);
  8532. }
  8533. // combining plain text blocks into one
  8534. var outputLength = 16 * result.length;
  8535. var output = new Uint8Array(outputLength);
  8536. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  8537. output.set(result[i], j);
  8538. }
  8539. return output;
  8540. }
  8541. };
  8542. return AES256Cipher;
  8543. })();
  8544. var PDF17 = (function PDF17Closure() {
  8545. function compareByteArrays(array1, array2) {
  8546. if (array1.length !== array2.length) {
  8547. return false;
  8548. }
  8549. for (var i = 0; i < array1.length; i++) {
  8550. if (array1[i] !== array2[i]) {
  8551. return false;
  8552. }
  8553. }
  8554. return true;
  8555. }
  8556. function PDF17() {
  8557. }
  8558. PDF17.prototype = {
  8559. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  8560. ownerValidationSalt,
  8561. userBytes,
  8562. ownerPassword) {
  8563. var hashData = new Uint8Array(password.length + 56);
  8564. hashData.set(password, 0);
  8565. hashData.set(ownerValidationSalt, password.length);
  8566. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8567. var result = calculateSHA256(hashData, 0, hashData.length);
  8568. return compareByteArrays(result, ownerPassword);
  8569. },
  8570. checkUserPassword: function PDF17_checkUserPassword(password,
  8571. userValidationSalt,
  8572. userPassword) {
  8573. var hashData = new Uint8Array(password.length + 8);
  8574. hashData.set(password, 0);
  8575. hashData.set(userValidationSalt, password.length);
  8576. var result = calculateSHA256(hashData, 0, hashData.length);
  8577. return compareByteArrays(result, userPassword);
  8578. },
  8579. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  8580. ownerEncryption) {
  8581. var hashData = new Uint8Array(password.length + 56);
  8582. hashData.set(password, 0);
  8583. hashData.set(ownerKeySalt, password.length);
  8584. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8585. var key = calculateSHA256(hashData, 0, hashData.length);
  8586. var cipher = new AES256Cipher(key);
  8587. return cipher.decryptBlock(ownerEncryption,
  8588. false,
  8589. new Uint8Array(16));
  8590. },
  8591. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  8592. userEncryption) {
  8593. var hashData = new Uint8Array(password.length + 8);
  8594. hashData.set(password, 0);
  8595. hashData.set(userKeySalt, password.length);
  8596. //key is the decryption key for the UE string
  8597. var key = calculateSHA256(hashData, 0, hashData.length);
  8598. var cipher = new AES256Cipher(key);
  8599. return cipher.decryptBlock(userEncryption,
  8600. false,
  8601. new Uint8Array(16));
  8602. }
  8603. };
  8604. return PDF17;
  8605. })();
  8606. var PDF20 = (function PDF20Closure() {
  8607. function concatArrays(array1, array2) {
  8608. var t = new Uint8Array(array1.length + array2.length);
  8609. t.set(array1, 0);
  8610. t.set(array2, array1.length);
  8611. return t;
  8612. }
  8613. function calculatePDF20Hash(password, input, userBytes) {
  8614. //This refers to Algorithm 2.B as defined in ISO 32000-2
  8615. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  8616. var e = [0];
  8617. var i = 0;
  8618. while (i < 64 || e[e.length - 1] > i - 32) {
  8619. var arrayLength = password.length + k.length + userBytes.length;
  8620. var k1 = new Uint8Array(arrayLength * 64);
  8621. var array = concatArrays(password, k);
  8622. array = concatArrays(array, userBytes);
  8623. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  8624. k1.set(array, pos);
  8625. }
  8626. //AES128 CBC NO PADDING with
  8627. //first 16 bytes of k as the key and the second 16 as the iv.
  8628. var cipher = new AES128Cipher(k.subarray(0, 16));
  8629. e = cipher.encrypt(k1, k.subarray(16, 32));
  8630. //Now we have to take the first 16 bytes of an unsigned
  8631. //big endian integer... and compute the remainder
  8632. //modulo 3.... That is a fairly large number and
  8633. //JavaScript isn't going to handle that well...
  8634. //So we're using a trick that allows us to perform
  8635. //modulo math byte by byte
  8636. var remainder = 0;
  8637. for (var z = 0; z < 16; z++) {
  8638. remainder *= (256 % 3);
  8639. remainder %= 3;
  8640. remainder += ((e[z] >>> 0) % 3);
  8641. remainder %= 3;
  8642. }
  8643. if (remainder === 0) {
  8644. k = calculateSHA256(e, 0, e.length);
  8645. }
  8646. else if (remainder === 1) {
  8647. k = calculateSHA384(e, 0, e.length);
  8648. }
  8649. else if (remainder === 2) {
  8650. k = calculateSHA512(e, 0, e.length);
  8651. }
  8652. i++;
  8653. }
  8654. return k.subarray(0, 32);
  8655. }
  8656. function PDF20() {
  8657. }
  8658. function compareByteArrays(array1, array2) {
  8659. if (array1.length !== array2.length) {
  8660. return false;
  8661. }
  8662. for (var i = 0; i < array1.length; i++) {
  8663. if (array1[i] !== array2[i]) {
  8664. return false;
  8665. }
  8666. }
  8667. return true;
  8668. }
  8669. PDF20.prototype = {
  8670. hash: function PDF20_hash(password, concatBytes, userBytes) {
  8671. return calculatePDF20Hash(password, concatBytes, userBytes);
  8672. },
  8673. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  8674. ownerValidationSalt,
  8675. userBytes,
  8676. ownerPassword) {
  8677. var hashData = new Uint8Array(password.length + 56);
  8678. hashData.set(password, 0);
  8679. hashData.set(ownerValidationSalt, password.length);
  8680. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  8681. var result = calculatePDF20Hash(password, hashData, userBytes);
  8682. return compareByteArrays(result, ownerPassword);
  8683. },
  8684. checkUserPassword: function PDF20_checkUserPassword(password,
  8685. userValidationSalt,
  8686. userPassword) {
  8687. var hashData = new Uint8Array(password.length + 8);
  8688. hashData.set(password, 0);
  8689. hashData.set(userValidationSalt, password.length);
  8690. var result = calculatePDF20Hash(password, hashData, []);
  8691. return compareByteArrays(result, userPassword);
  8692. },
  8693. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  8694. ownerEncryption) {
  8695. var hashData = new Uint8Array(password.length + 56);
  8696. hashData.set(password, 0);
  8697. hashData.set(ownerKeySalt, password.length);
  8698. hashData.set(userBytes, password.length + ownerKeySalt.length);
  8699. var key = calculatePDF20Hash(password, hashData, userBytes);
  8700. var cipher = new AES256Cipher(key);
  8701. return cipher.decryptBlock(ownerEncryption,
  8702. false,
  8703. new Uint8Array(16));
  8704. },
  8705. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  8706. userEncryption) {
  8707. var hashData = new Uint8Array(password.length + 8);
  8708. hashData.set(password, 0);
  8709. hashData.set(userKeySalt, password.length);
  8710. //key is the decryption key for the UE string
  8711. var key = calculatePDF20Hash(password, hashData, []);
  8712. var cipher = new AES256Cipher(key);
  8713. return cipher.decryptBlock(userEncryption,
  8714. false,
  8715. new Uint8Array(16));
  8716. }
  8717. };
  8718. return PDF20;
  8719. })();
  8720. var CipherTransform = (function CipherTransformClosure() {
  8721. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  8722. this.stringCipherConstructor = stringCipherConstructor;
  8723. this.streamCipherConstructor = streamCipherConstructor;
  8724. }
  8725. CipherTransform.prototype = {
  8726. createStream: function CipherTransform_createStream(stream, length) {
  8727. var cipher = new this.streamCipherConstructor();
  8728. return new DecryptStream(stream, length,
  8729. function cipherTransformDecryptStream(data, finalize) {
  8730. return cipher.decryptBlock(data, finalize);
  8731. }
  8732. );
  8733. },
  8734. decryptString: function CipherTransform_decryptString(s) {
  8735. var cipher = new this.stringCipherConstructor();
  8736. var data = stringToBytes(s);
  8737. data = cipher.decryptBlock(data, true);
  8738. return bytesToString(data);
  8739. }
  8740. };
  8741. return CipherTransform;
  8742. })();
  8743. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  8744. var defaultPasswordBytes = new Uint8Array([
  8745. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  8746. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  8747. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  8748. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  8749. function createEncryptionKey20(revision, password, ownerPassword,
  8750. ownerValidationSalt, ownerKeySalt, uBytes,
  8751. userPassword, userValidationSalt, userKeySalt,
  8752. ownerEncryption, userEncryption, perms) {
  8753. if (password) {
  8754. var passwordLength = Math.min(127, password.length);
  8755. password = password.subarray(0, passwordLength);
  8756. } else {
  8757. password = [];
  8758. }
  8759. var pdfAlgorithm;
  8760. if (revision === 6) {
  8761. pdfAlgorithm = new PDF20();
  8762. } else {
  8763. pdfAlgorithm = new PDF17();
  8764. }
  8765. if (pdfAlgorithm) {
  8766. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  8767. userPassword)) {
  8768. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  8769. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  8770. uBytes,
  8771. ownerPassword)) {
  8772. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  8773. ownerEncryption);
  8774. }
  8775. }
  8776. return null;
  8777. }
  8778. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  8779. flags, revision, keyLength, encryptMetadata) {
  8780. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  8781. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  8782. if (password) {
  8783. n = Math.min(32, password.length);
  8784. for (; i < n; ++i) {
  8785. hashData[i] = password[i];
  8786. }
  8787. }
  8788. j = 0;
  8789. while (i < 32) {
  8790. hashData[i++] = defaultPasswordBytes[j++];
  8791. }
  8792. // as now the padded password in the hashData[0..i]
  8793. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  8794. hashData[i++] = ownerPassword[j];
  8795. }
  8796. hashData[i++] = flags & 0xFF;
  8797. hashData[i++] = (flags >> 8) & 0xFF;
  8798. hashData[i++] = (flags >> 16) & 0xFF;
  8799. hashData[i++] = (flags >>> 24) & 0xFF;
  8800. for (j = 0, n = fileId.length; j < n; ++j) {
  8801. hashData[i++] = fileId[j];
  8802. }
  8803. if (revision >= 4 && !encryptMetadata) {
  8804. hashData[i++] = 0xFF;
  8805. hashData[i++] = 0xFF;
  8806. hashData[i++] = 0xFF;
  8807. hashData[i++] = 0xFF;
  8808. }
  8809. var hash = calculateMD5(hashData, 0, i);
  8810. var keyLengthInBytes = keyLength >> 3;
  8811. if (revision >= 3) {
  8812. for (j = 0; j < 50; ++j) {
  8813. hash = calculateMD5(hash, 0, keyLengthInBytes);
  8814. }
  8815. }
  8816. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  8817. var cipher, checkData;
  8818. if (revision >= 3) {
  8819. for (i = 0; i < 32; ++i) {
  8820. hashData[i] = defaultPasswordBytes[i];
  8821. }
  8822. for (j = 0, n = fileId.length; j < n; ++j) {
  8823. hashData[i++] = fileId[j];
  8824. }
  8825. cipher = new ARCFourCipher(encryptionKey);
  8826. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  8827. n = encryptionKey.length;
  8828. var derivedKey = new Uint8Array(n), k;
  8829. for (j = 1; j <= 19; ++j) {
  8830. for (k = 0; k < n; ++k) {
  8831. derivedKey[k] = encryptionKey[k] ^ j;
  8832. }
  8833. cipher = new ARCFourCipher(derivedKey);
  8834. checkData = cipher.encryptBlock(checkData);
  8835. }
  8836. for (j = 0, n = checkData.length; j < n; ++j) {
  8837. if (userPassword[j] !== checkData[j]) {
  8838. return null;
  8839. }
  8840. }
  8841. } else {
  8842. cipher = new ARCFourCipher(encryptionKey);
  8843. checkData = cipher.encryptBlock(defaultPasswordBytes);
  8844. for (j = 0, n = checkData.length; j < n; ++j) {
  8845. if (userPassword[j] !== checkData[j]) {
  8846. return null;
  8847. }
  8848. }
  8849. }
  8850. return encryptionKey;
  8851. }
  8852. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  8853. var hashData = new Uint8Array(32), i = 0, j, n;
  8854. n = Math.min(32, password.length);
  8855. for (; i < n; ++i) {
  8856. hashData[i] = password[i];
  8857. }
  8858. j = 0;
  8859. while (i < 32) {
  8860. hashData[i++] = defaultPasswordBytes[j++];
  8861. }
  8862. var hash = calculateMD5(hashData, 0, i);
  8863. var keyLengthInBytes = keyLength >> 3;
  8864. if (revision >= 3) {
  8865. for (j = 0; j < 50; ++j) {
  8866. hash = calculateMD5(hash, 0, hash.length);
  8867. }
  8868. }
  8869. var cipher, userPassword;
  8870. if (revision >= 3) {
  8871. userPassword = ownerPassword;
  8872. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  8873. for (j = 19; j >= 0; j--) {
  8874. for (k = 0; k < keyLengthInBytes; ++k) {
  8875. derivedKey[k] = hash[k] ^ j;
  8876. }
  8877. cipher = new ARCFourCipher(derivedKey);
  8878. userPassword = cipher.encryptBlock(userPassword);
  8879. }
  8880. } else {
  8881. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  8882. userPassword = cipher.encryptBlock(ownerPassword);
  8883. }
  8884. return userPassword;
  8885. }
  8886. var identityName = Name.get('Identity');
  8887. function CipherTransformFactory(dict, fileId, password) {
  8888. var filter = dict.get('Filter');
  8889. if (!isName(filter) || filter.name !== 'Standard') {
  8890. error('unknown encryption method');
  8891. }
  8892. this.dict = dict;
  8893. var algorithm = dict.get('V');
  8894. if (!isInt(algorithm) ||
  8895. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  8896. algorithm !== 5)) {
  8897. error('unsupported encryption algorithm');
  8898. }
  8899. this.algorithm = algorithm;
  8900. var keyLength = dict.get('Length') || 40;
  8901. if (!isInt(keyLength) ||
  8902. keyLength < 40 || (keyLength % 8) !== 0) {
  8903. error('invalid key length');
  8904. }
  8905. // prepare keys
  8906. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  8907. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  8908. var flags = dict.get('P');
  8909. var revision = dict.get('R');
  8910. // meaningful when V is 4 or 5
  8911. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  8912. dict.get('EncryptMetadata') !== false);
  8913. this.encryptMetadata = encryptMetadata;
  8914. var fileIdBytes = stringToBytes(fileId);
  8915. var passwordBytes;
  8916. if (password) {
  8917. if (revision === 6) {
  8918. try {
  8919. password = utf8StringToString(password);
  8920. } catch (ex) {
  8921. warn('CipherTransformFactory: ' +
  8922. 'Unable to convert UTF8 encoded password.');
  8923. }
  8924. }
  8925. passwordBytes = stringToBytes(password);
  8926. }
  8927. var encryptionKey;
  8928. if (algorithm !== 5) {
  8929. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  8930. ownerPassword, userPassword, flags,
  8931. revision, keyLength, encryptMetadata);
  8932. }
  8933. else {
  8934. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  8935. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  8936. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  8937. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  8938. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  8939. var ownerEncryption = stringToBytes(dict.get('OE'));
  8940. var userEncryption = stringToBytes(dict.get('UE'));
  8941. var perms = stringToBytes(dict.get('Perms'));
  8942. encryptionKey =
  8943. createEncryptionKey20(revision, passwordBytes,
  8944. ownerPassword, ownerValidationSalt,
  8945. ownerKeySalt, uBytes,
  8946. userPassword, userValidationSalt,
  8947. userKeySalt, ownerEncryption,
  8948. userEncryption, perms);
  8949. }
  8950. if (!encryptionKey && !password) {
  8951. throw new PasswordException('No password given',
  8952. PasswordResponses.NEED_PASSWORD);
  8953. } else if (!encryptionKey && password) {
  8954. // Attempting use the password as an owner password
  8955. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  8956. revision, keyLength);
  8957. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  8958. ownerPassword, userPassword, flags,
  8959. revision, keyLength, encryptMetadata);
  8960. }
  8961. if (!encryptionKey) {
  8962. throw new PasswordException('Incorrect Password',
  8963. PasswordResponses.INCORRECT_PASSWORD);
  8964. }
  8965. this.encryptionKey = encryptionKey;
  8966. if (algorithm >= 4) {
  8967. this.cf = dict.get('CF');
  8968. this.stmf = dict.get('StmF') || identityName;
  8969. this.strf = dict.get('StrF') || identityName;
  8970. this.eff = dict.get('EFF') || this.stmf;
  8971. }
  8972. }
  8973. function buildObjectKey(num, gen, encryptionKey, isAes) {
  8974. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  8975. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  8976. key[i] = encryptionKey[i];
  8977. }
  8978. key[i++] = num & 0xFF;
  8979. key[i++] = (num >> 8) & 0xFF;
  8980. key[i++] = (num >> 16) & 0xFF;
  8981. key[i++] = gen & 0xFF;
  8982. key[i++] = (gen >> 8) & 0xFF;
  8983. if (isAes) {
  8984. key[i++] = 0x73;
  8985. key[i++] = 0x41;
  8986. key[i++] = 0x6C;
  8987. key[i++] = 0x54;
  8988. }
  8989. var hash = calculateMD5(key, 0, i);
  8990. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  8991. }
  8992. function buildCipherConstructor(cf, name, num, gen, key) {
  8993. var cryptFilter = cf.get(name.name);
  8994. var cfm;
  8995. if (cryptFilter !== null && cryptFilter !== undefined) {
  8996. cfm = cryptFilter.get('CFM');
  8997. }
  8998. if (!cfm || cfm.name === 'None') {
  8999. return function cipherTransformFactoryBuildCipherConstructorNone() {
  9000. return new NullCipher();
  9001. };
  9002. }
  9003. if ('V2' === cfm.name) {
  9004. return function cipherTransformFactoryBuildCipherConstructorV2() {
  9005. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  9006. };
  9007. }
  9008. if ('AESV2' === cfm.name) {
  9009. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  9010. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  9011. };
  9012. }
  9013. if ('AESV3' === cfm.name) {
  9014. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  9015. return new AES256Cipher(key);
  9016. };
  9017. }
  9018. error('Unknown crypto method');
  9019. }
  9020. CipherTransformFactory.prototype = {
  9021. createCipherTransform:
  9022. function CipherTransformFactory_createCipherTransform(num, gen) {
  9023. if (this.algorithm === 4 || this.algorithm === 5) {
  9024. return new CipherTransform(
  9025. buildCipherConstructor(this.cf, this.stmf,
  9026. num, gen, this.encryptionKey),
  9027. buildCipherConstructor(this.cf, this.strf,
  9028. num, gen, this.encryptionKey));
  9029. }
  9030. // algorithms 1 and 2
  9031. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  9032. var cipherConstructor = function buildCipherCipherConstructor() {
  9033. return new ARCFourCipher(key);
  9034. };
  9035. return new CipherTransform(cipherConstructor, cipherConstructor);
  9036. }
  9037. };
  9038. return CipherTransformFactory;
  9039. })();
  9040. var PatternType = {
  9041. FUNCTION_BASED: 1,
  9042. AXIAL: 2,
  9043. RADIAL: 3,
  9044. FREE_FORM_MESH: 4,
  9045. LATTICE_FORM_MESH: 5,
  9046. COONS_PATCH_MESH: 6,
  9047. TENSOR_PATCH_MESH: 7
  9048. };
  9049. var Pattern = (function PatternClosure() {
  9050. // Constructor should define this.getPattern
  9051. function Pattern() {
  9052. error('should not call Pattern constructor');
  9053. }
  9054. Pattern.prototype = {
  9055. // Input: current Canvas context
  9056. // Output: the appropriate fillStyle or strokeStyle
  9057. getPattern: function Pattern_getPattern(ctx) {
  9058. error('Should not call Pattern.getStyle: ' + ctx);
  9059. }
  9060. };
  9061. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  9062. res) {
  9063. var dict = isStream(shading) ? shading.dict : shading;
  9064. var type = dict.get('ShadingType');
  9065. try {
  9066. switch (type) {
  9067. case PatternType.AXIAL:
  9068. case PatternType.RADIAL:
  9069. // Both radial and axial shadings are handled by RadialAxial shading.
  9070. return new Shadings.RadialAxial(dict, matrix, xref, res);
  9071. case PatternType.FREE_FORM_MESH:
  9072. case PatternType.LATTICE_FORM_MESH:
  9073. case PatternType.COONS_PATCH_MESH:
  9074. case PatternType.TENSOR_PATCH_MESH:
  9075. return new Shadings.Mesh(shading, matrix, xref, res);
  9076. default:
  9077. throw new Error('Unknown PatternType: ' + type);
  9078. }
  9079. } catch (ex) {
  9080. if (ex instanceof MissingDataException) {
  9081. throw ex;
  9082. }
  9083. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  9084. warn(ex);
  9085. return new Shadings.Dummy();
  9086. }
  9087. };
  9088. return Pattern;
  9089. })();
  9090. var Shadings = {};
  9091. // A small number to offset the first/last color stops so we can insert ones to
  9092. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  9093. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  9094. // internally so we have to go bigger.
  9095. Shadings.SMALL_NUMBER = 1e-2;
  9096. // Radial and axial shading have very similar implementations
  9097. // If needed, the implementations can be broken into two classes
  9098. Shadings.RadialAxial = (function RadialAxialClosure() {
  9099. function RadialAxial(dict, matrix, xref, res) {
  9100. this.matrix = matrix;
  9101. this.coordsArr = dict.get('Coords');
  9102. this.shadingType = dict.get('ShadingType');
  9103. this.type = 'Pattern';
  9104. var cs = dict.get('ColorSpace', 'CS');
  9105. cs = ColorSpace.parse(cs, xref, res);
  9106. this.cs = cs;
  9107. var t0 = 0.0, t1 = 1.0;
  9108. if (dict.has('Domain')) {
  9109. var domainArr = dict.get('Domain');
  9110. t0 = domainArr[0];
  9111. t1 = domainArr[1];
  9112. }
  9113. var extendStart = false, extendEnd = false;
  9114. if (dict.has('Extend')) {
  9115. var extendArr = dict.get('Extend');
  9116. extendStart = extendArr[0];
  9117. extendEnd = extendArr[1];
  9118. }
  9119. if (this.shadingType === PatternType.RADIAL &&
  9120. (!extendStart || !extendEnd)) {
  9121. // Radial gradient only currently works if either circle is fully within
  9122. // the other circle.
  9123. var x1 = this.coordsArr[0];
  9124. var y1 = this.coordsArr[1];
  9125. var r1 = this.coordsArr[2];
  9126. var x2 = this.coordsArr[3];
  9127. var y2 = this.coordsArr[4];
  9128. var r2 = this.coordsArr[5];
  9129. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  9130. if (r1 <= r2 + distance &&
  9131. r2 <= r1 + distance) {
  9132. warn('Unsupported radial gradient.');
  9133. }
  9134. }
  9135. this.extendStart = extendStart;
  9136. this.extendEnd = extendEnd;
  9137. var fnObj = dict.get('Function');
  9138. var fn = PDFFunction.parseArray(xref, fnObj);
  9139. // 10 samples seems good enough for now, but probably won't work
  9140. // if there are sharp color changes. Ideally, we would implement
  9141. // the spec faithfully and add lossless optimizations.
  9142. var diff = t1 - t0;
  9143. var step = diff / 10;
  9144. var colorStops = this.colorStops = [];
  9145. // Protect against bad domains so we don't end up in an infinte loop below.
  9146. if (t0 >= t1 || step <= 0) {
  9147. // Acrobat doesn't seem to handle these cases so we'll ignore for
  9148. // now.
  9149. info('Bad shading domain.');
  9150. return;
  9151. }
  9152. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  9153. var rgbColor;
  9154. for (var i = t0; i <= t1; i += step) {
  9155. ratio[0] = i;
  9156. fn(ratio, 0, color, 0);
  9157. rgbColor = cs.getRgb(color, 0);
  9158. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9159. colorStops.push([(i - t0) / diff, cssColor]);
  9160. }
  9161. var background = 'transparent';
  9162. if (dict.has('Background')) {
  9163. rgbColor = cs.getRgb(dict.get('Background'), 0);
  9164. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  9165. }
  9166. if (!extendStart) {
  9167. // Insert a color stop at the front and offset the first real color stop
  9168. // so it doesn't conflict with the one we insert.
  9169. colorStops.unshift([0, background]);
  9170. colorStops[1][0] += Shadings.SMALL_NUMBER;
  9171. }
  9172. if (!extendEnd) {
  9173. // Same idea as above in extendStart but for the end.
  9174. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  9175. colorStops.push([1, background]);
  9176. }
  9177. this.colorStops = colorStops;
  9178. }
  9179. RadialAxial.prototype = {
  9180. getIR: function RadialAxial_getIR() {
  9181. var coordsArr = this.coordsArr;
  9182. var shadingType = this.shadingType;
  9183. var type, p0, p1, r0, r1;
  9184. if (shadingType === PatternType.AXIAL) {
  9185. p0 = [coordsArr[0], coordsArr[1]];
  9186. p1 = [coordsArr[2], coordsArr[3]];
  9187. r0 = null;
  9188. r1 = null;
  9189. type = 'axial';
  9190. } else if (shadingType === PatternType.RADIAL) {
  9191. p0 = [coordsArr[0], coordsArr[1]];
  9192. p1 = [coordsArr[3], coordsArr[4]];
  9193. r0 = coordsArr[2];
  9194. r1 = coordsArr[5];
  9195. type = 'radial';
  9196. } else {
  9197. error('getPattern type unknown: ' + shadingType);
  9198. }
  9199. var matrix = this.matrix;
  9200. if (matrix) {
  9201. p0 = Util.applyTransform(p0, matrix);
  9202. p1 = Util.applyTransform(p1, matrix);
  9203. }
  9204. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  9205. }
  9206. };
  9207. return RadialAxial;
  9208. })();
  9209. // All mesh shading. For now, they will be presented as set of the triangles
  9210. // to be drawn on the canvas and rgb color for each vertex.
  9211. Shadings.Mesh = (function MeshClosure() {
  9212. function MeshStreamReader(stream, context) {
  9213. this.stream = stream;
  9214. this.context = context;
  9215. this.buffer = 0;
  9216. this.bufferLength = 0;
  9217. var numComps = context.numComps;
  9218. this.tmpCompsBuf = new Float32Array(numComps);
  9219. var csNumComps = context.colorSpace;
  9220. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  9221. this.tmpCompsBuf;
  9222. }
  9223. MeshStreamReader.prototype = {
  9224. get hasData() {
  9225. if (this.stream.end) {
  9226. return this.stream.pos < this.stream.end;
  9227. }
  9228. if (this.bufferLength > 0) {
  9229. return true;
  9230. }
  9231. var nextByte = this.stream.getByte();
  9232. if (nextByte < 0) {
  9233. return false;
  9234. }
  9235. this.buffer = nextByte;
  9236. this.bufferLength = 8;
  9237. return true;
  9238. },
  9239. readBits: function MeshStreamReader_readBits(n) {
  9240. var buffer = this.buffer;
  9241. var bufferLength = this.bufferLength;
  9242. if (n === 32) {
  9243. if (bufferLength === 0) {
  9244. return ((this.stream.getByte() << 24) |
  9245. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  9246. this.stream.getByte()) >>> 0;
  9247. }
  9248. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  9249. (this.stream.getByte() << 8) | this.stream.getByte();
  9250. var nextByte = this.stream.getByte();
  9251. this.buffer = nextByte & ((1 << bufferLength) - 1);
  9252. return ((buffer << (8 - bufferLength)) |
  9253. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  9254. }
  9255. if (n === 8 && bufferLength === 0) {
  9256. return this.stream.getByte();
  9257. }
  9258. while (bufferLength < n) {
  9259. buffer = (buffer << 8) | this.stream.getByte();
  9260. bufferLength += 8;
  9261. }
  9262. bufferLength -= n;
  9263. this.bufferLength = bufferLength;
  9264. this.buffer = buffer & ((1 << bufferLength) - 1);
  9265. return buffer >> bufferLength;
  9266. },
  9267. align: function MeshStreamReader_align() {
  9268. this.buffer = 0;
  9269. this.bufferLength = 0;
  9270. },
  9271. readFlag: function MeshStreamReader_readFlag() {
  9272. return this.readBits(this.context.bitsPerFlag);
  9273. },
  9274. readCoordinate: function MeshStreamReader_readCoordinate() {
  9275. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  9276. var xi = this.readBits(bitsPerCoordinate);
  9277. var yi = this.readBits(bitsPerCoordinate);
  9278. var decode = this.context.decode;
  9279. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  9280. 2.3283064365386963e-10; // 2 ^ -32
  9281. return [
  9282. xi * scale * (decode[1] - decode[0]) + decode[0],
  9283. yi * scale * (decode[3] - decode[2]) + decode[2]
  9284. ];
  9285. },
  9286. readComponents: function MeshStreamReader_readComponents() {
  9287. var numComps = this.context.numComps;
  9288. var bitsPerComponent = this.context.bitsPerComponent;
  9289. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  9290. 2.3283064365386963e-10; // 2 ^ -32
  9291. var decode = this.context.decode;
  9292. var components = this.tmpCompsBuf;
  9293. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  9294. var ci = this.readBits(bitsPerComponent);
  9295. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  9296. }
  9297. var color = this.tmpCsCompsBuf;
  9298. if (this.context.colorFn) {
  9299. this.context.colorFn(components, 0, color, 0);
  9300. }
  9301. return this.context.colorSpace.getRgb(color, 0);
  9302. }
  9303. };
  9304. function decodeType4Shading(mesh, reader) {
  9305. var coords = mesh.coords;
  9306. var colors = mesh.colors;
  9307. var operators = [];
  9308. var ps = []; // not maintaining cs since that will match ps
  9309. var verticesLeft = 0; // assuming we have all data to start a new triangle
  9310. while (reader.hasData) {
  9311. var f = reader.readFlag();
  9312. var coord = reader.readCoordinate();
  9313. var color = reader.readComponents();
  9314. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  9315. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  9316. switch (f) {
  9317. case 0:
  9318. verticesLeft = 3;
  9319. break;
  9320. case 1:
  9321. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  9322. verticesLeft = 1;
  9323. break;
  9324. case 2:
  9325. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  9326. verticesLeft = 1;
  9327. break;
  9328. }
  9329. operators.push(f);
  9330. }
  9331. ps.push(coords.length);
  9332. coords.push(coord);
  9333. colors.push(color);
  9334. verticesLeft--;
  9335. reader.align();
  9336. }
  9337. var psPacked = new Int32Array(ps);
  9338. mesh.figures.push({
  9339. type: 'triangles',
  9340. coords: psPacked,
  9341. colors: psPacked
  9342. });
  9343. }
  9344. function decodeType5Shading(mesh, reader, verticesPerRow) {
  9345. var coords = mesh.coords;
  9346. var colors = mesh.colors;
  9347. var ps = []; // not maintaining cs since that will match ps
  9348. while (reader.hasData) {
  9349. var coord = reader.readCoordinate();
  9350. var color = reader.readComponents();
  9351. ps.push(coords.length);
  9352. coords.push(coord);
  9353. colors.push(color);
  9354. }
  9355. var psPacked = new Int32Array(ps);
  9356. mesh.figures.push({
  9357. type: 'lattice',
  9358. coords: psPacked,
  9359. colors: psPacked,
  9360. verticesPerRow: verticesPerRow
  9361. });
  9362. }
  9363. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  9364. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  9365. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  9366. var getB = (function getBClosure() {
  9367. function buildB(count) {
  9368. var lut = [];
  9369. for (var i = 0; i <= count; i++) {
  9370. var t = i / count, t_ = 1 - t;
  9371. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  9372. 3 * t * t * t_, t * t * t]));
  9373. }
  9374. return lut;
  9375. }
  9376. var cache = [];
  9377. return function getB(count) {
  9378. if (!cache[count]) {
  9379. cache[count] = buildB(count);
  9380. }
  9381. return cache[count];
  9382. };
  9383. })();
  9384. function buildFigureFromPatch(mesh, index) {
  9385. var figure = mesh.figures[index];
  9386. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  9387. var coords = mesh.coords, colors = mesh.colors;
  9388. var pi = figure.coords;
  9389. var ci = figure.colors;
  9390. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  9391. coords[pi[12]][0], coords[pi[15]][0]);
  9392. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  9393. coords[pi[12]][1], coords[pi[15]][1]);
  9394. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  9395. coords[pi[12]][0], coords[pi[15]][0]);
  9396. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  9397. coords[pi[12]][1], coords[pi[15]][1]);
  9398. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  9399. (mesh.bounds[2] - mesh.bounds[0]));
  9400. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9401. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  9402. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  9403. (mesh.bounds[3] - mesh.bounds[1]));
  9404. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  9405. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  9406. var verticesPerRow = splitXBy + 1;
  9407. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  9408. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  9409. var k = 0;
  9410. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  9411. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  9412. c2 = colors[ci[2]], c3 = colors[ci[3]];
  9413. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  9414. for (var row = 0; row <= splitYBy; row++) {
  9415. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  9416. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  9417. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  9418. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  9419. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  9420. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  9421. for (var col = 0; col <= splitXBy; col++, k++) {
  9422. if ((row === 0 || row === splitYBy) &&
  9423. (col === 0 || col === splitXBy)) {
  9424. continue;
  9425. }
  9426. var x = 0, y = 0;
  9427. var q = 0;
  9428. for (var i = 0; i <= 3; i++) {
  9429. for (var j = 0; j <= 3; j++, q++) {
  9430. var m = bRow[row][i] * bCol[col][j];
  9431. x += coords[pi[q]][0] * m;
  9432. y += coords[pi[q]][1] * m;
  9433. }
  9434. }
  9435. figureCoords[k] = coords.length;
  9436. coords.push([x, y]);
  9437. figureColors[k] = colors.length;
  9438. var newColor = new Uint8Array(3);
  9439. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  9440. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  9441. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  9442. colors.push(newColor);
  9443. }
  9444. }
  9445. figureCoords[0] = pi[0];
  9446. figureColors[0] = ci[0];
  9447. figureCoords[splitXBy] = pi[3];
  9448. figureColors[splitXBy] = ci[1];
  9449. figureCoords[verticesPerRow * splitYBy] = pi[12];
  9450. figureColors[verticesPerRow * splitYBy] = ci[2];
  9451. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  9452. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  9453. mesh.figures[index] = {
  9454. type: 'lattice',
  9455. coords: figureCoords,
  9456. colors: figureColors,
  9457. verticesPerRow: verticesPerRow
  9458. };
  9459. }
  9460. function decodeType6Shading(mesh, reader) {
  9461. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  9462. var coords = mesh.coords;
  9463. var colors = mesh.colors;
  9464. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9465. var cs = new Int32Array(4); // c00, c30, c03, c33
  9466. while (reader.hasData) {
  9467. var f = reader.readFlag();
  9468. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  9469. var i, ii;
  9470. var pi = coords.length;
  9471. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  9472. coords.push(reader.readCoordinate());
  9473. }
  9474. var ci = colors.length;
  9475. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9476. colors.push(reader.readComponents());
  9477. }
  9478. var tmp1, tmp2, tmp3, tmp4;
  9479. switch (f) {
  9480. case 0:
  9481. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9482. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9483. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  9484. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9485. cs[2] = ci + 1; cs[3] = ci + 2;
  9486. cs[0] = ci; cs[1] = ci + 3;
  9487. break;
  9488. case 1:
  9489. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9490. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9491. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  9492. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  9493. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9494. tmp1 = cs[2]; tmp2 = cs[3];
  9495. cs[2] = ci + 1; cs[3] = ci;
  9496. cs[0] = tmp1; cs[1] = tmp2;
  9497. break;
  9498. case 2:
  9499. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9500. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  9501. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  9502. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9503. cs[2] = cs[3]; cs[3] = ci + 1;
  9504. cs[0] = cs[1]; cs[1] = ci;
  9505. break;
  9506. case 3:
  9507. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9508. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  9509. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  9510. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9511. cs[2] = cs[0]; cs[3] = cs[1];
  9512. cs[0] = ci; cs[1] = ci + 1;
  9513. break;
  9514. }
  9515. // set p11, p12, p21, p22
  9516. ps[5] = coords.length;
  9517. coords.push([
  9518. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  9519. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  9520. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9521. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  9522. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  9523. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  9524. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9525. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  9526. ]);
  9527. ps[6] = coords.length;
  9528. coords.push([
  9529. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  9530. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  9531. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9532. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  9533. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  9534. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  9535. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9536. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  9537. ]);
  9538. ps[9] = coords.length;
  9539. coords.push([
  9540. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  9541. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  9542. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  9543. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  9544. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  9545. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  9546. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  9547. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  9548. ]);
  9549. ps[10] = coords.length;
  9550. coords.push([
  9551. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  9552. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  9553. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  9554. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  9555. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  9556. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  9557. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  9558. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  9559. ]);
  9560. mesh.figures.push({
  9561. type: 'patch',
  9562. coords: new Int32Array(ps), // making copies of ps and cs
  9563. colors: new Int32Array(cs)
  9564. });
  9565. }
  9566. }
  9567. function decodeType7Shading(mesh, reader) {
  9568. var coords = mesh.coords;
  9569. var colors = mesh.colors;
  9570. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  9571. var cs = new Int32Array(4); // c00, c30, c03, c33
  9572. while (reader.hasData) {
  9573. var f = reader.readFlag();
  9574. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  9575. var i, ii;
  9576. var pi = coords.length;
  9577. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  9578. coords.push(reader.readCoordinate());
  9579. }
  9580. var ci = colors.length;
  9581. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  9582. colors.push(reader.readComponents());
  9583. }
  9584. var tmp1, tmp2, tmp3, tmp4;
  9585. switch (f) {
  9586. case 0:
  9587. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  9588. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  9589. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  9590. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  9591. cs[2] = ci + 1; cs[3] = ci + 2;
  9592. cs[0] = ci; cs[1] = ci + 3;
  9593. break;
  9594. case 1:
  9595. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  9596. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  9597. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  9598. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  9599. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  9600. tmp1 = cs[2]; tmp2 = cs[3];
  9601. cs[2] = ci + 1; cs[3] = ci;
  9602. cs[0] = tmp1; cs[1] = tmp2;
  9603. break;
  9604. case 2:
  9605. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  9606. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  9607. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  9608. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  9609. cs[2] = cs[3]; cs[3] = ci + 1;
  9610. cs[0] = cs[1]; cs[1] = ci;
  9611. break;
  9612. case 3:
  9613. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  9614. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  9615. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  9616. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  9617. cs[2] = cs[0]; cs[3] = cs[1];
  9618. cs[0] = ci; cs[1] = ci + 1;
  9619. break;
  9620. }
  9621. mesh.figures.push({
  9622. type: 'patch',
  9623. coords: new Int32Array(ps), // making copies of ps and cs
  9624. colors: new Int32Array(cs)
  9625. });
  9626. }
  9627. }
  9628. function updateBounds(mesh) {
  9629. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  9630. maxX = minX, maxY = minY;
  9631. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  9632. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  9633. minX = minX > x ? x : minX;
  9634. minY = minY > y ? y : minY;
  9635. maxX = maxX < x ? x : maxX;
  9636. maxY = maxY < y ? y : maxY;
  9637. }
  9638. mesh.bounds = [minX, minY, maxX, maxY];
  9639. }
  9640. function packData(mesh) {
  9641. var i, ii, j, jj;
  9642. var coords = mesh.coords;
  9643. var coordsPacked = new Float32Array(coords.length * 2);
  9644. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  9645. var xy = coords[i];
  9646. coordsPacked[j++] = xy[0];
  9647. coordsPacked[j++] = xy[1];
  9648. }
  9649. mesh.coords = coordsPacked;
  9650. var colors = mesh.colors;
  9651. var colorsPacked = new Uint8Array(colors.length * 3);
  9652. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  9653. var c = colors[i];
  9654. colorsPacked[j++] = c[0];
  9655. colorsPacked[j++] = c[1];
  9656. colorsPacked[j++] = c[2];
  9657. }
  9658. mesh.colors = colorsPacked;
  9659. var figures = mesh.figures;
  9660. for (i = 0, ii = figures.length; i < ii; i++) {
  9661. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  9662. for (j = 0, jj = ps.length; j < jj; j++) {
  9663. ps[j] *= 2;
  9664. cs[j] *= 3;
  9665. }
  9666. }
  9667. }
  9668. function Mesh(stream, matrix, xref, res) {
  9669. assert(isStream(stream), 'Mesh data is not a stream');
  9670. var dict = stream.dict;
  9671. this.matrix = matrix;
  9672. this.shadingType = dict.get('ShadingType');
  9673. this.type = 'Pattern';
  9674. this.bbox = dict.get('BBox');
  9675. var cs = dict.get('ColorSpace', 'CS');
  9676. cs = ColorSpace.parse(cs, xref, res);
  9677. this.cs = cs;
  9678. this.background = dict.has('Background') ?
  9679. cs.getRgb(dict.get('Background'), 0) : null;
  9680. var fnObj = dict.get('Function');
  9681. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  9682. this.coords = [];
  9683. this.colors = [];
  9684. this.figures = [];
  9685. var decodeContext = {
  9686. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  9687. bitsPerComponent: dict.get('BitsPerComponent'),
  9688. bitsPerFlag: dict.get('BitsPerFlag'),
  9689. decode: dict.get('Decode'),
  9690. colorFn: fn,
  9691. colorSpace: cs,
  9692. numComps: fn ? 1 : cs.numComps
  9693. };
  9694. var reader = new MeshStreamReader(stream, decodeContext);
  9695. var patchMesh = false;
  9696. switch (this.shadingType) {
  9697. case PatternType.FREE_FORM_MESH:
  9698. decodeType4Shading(this, reader);
  9699. break;
  9700. case PatternType.LATTICE_FORM_MESH:
  9701. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  9702. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  9703. decodeType5Shading(this, reader, verticesPerRow);
  9704. break;
  9705. case PatternType.COONS_PATCH_MESH:
  9706. decodeType6Shading(this, reader);
  9707. patchMesh = true;
  9708. break;
  9709. case PatternType.TENSOR_PATCH_MESH:
  9710. decodeType7Shading(this, reader);
  9711. patchMesh = true;
  9712. break;
  9713. default:
  9714. error('Unsupported mesh type.');
  9715. break;
  9716. }
  9717. if (patchMesh) {
  9718. // dirty bounds calculation for determining, how dense shall be triangles
  9719. updateBounds(this);
  9720. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  9721. buildFigureFromPatch(this, i);
  9722. }
  9723. }
  9724. // calculate bounds
  9725. updateBounds(this);
  9726. packData(this);
  9727. }
  9728. Mesh.prototype = {
  9729. getIR: function Mesh_getIR() {
  9730. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  9731. this.bounds, this.matrix, this.bbox, this.background];
  9732. }
  9733. };
  9734. return Mesh;
  9735. })();
  9736. Shadings.Dummy = (function DummyClosure() {
  9737. function Dummy() {
  9738. this.type = 'Pattern';
  9739. }
  9740. Dummy.prototype = {
  9741. getIR: function Dummy_getIR() {
  9742. return ['Dummy'];
  9743. }
  9744. };
  9745. return Dummy;
  9746. })();
  9747. function getTilingPatternIR(operatorList, dict, args) {
  9748. var matrix = dict.get('Matrix');
  9749. var bbox = dict.get('BBox');
  9750. var xstep = dict.get('XStep');
  9751. var ystep = dict.get('YStep');
  9752. var paintType = dict.get('PaintType');
  9753. var tilingType = dict.get('TilingType');
  9754. return [
  9755. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  9756. paintType, tilingType
  9757. ];
  9758. }
  9759. var PartialEvaluator = (function PartialEvaluatorClosure() {
  9760. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  9761. uniquePrefix, idCounters, fontCache) {
  9762. this.pdfManager = pdfManager;
  9763. this.xref = xref;
  9764. this.handler = handler;
  9765. this.pageIndex = pageIndex;
  9766. this.uniquePrefix = uniquePrefix;
  9767. this.idCounters = idCounters;
  9768. this.fontCache = fontCache;
  9769. }
  9770. // Trying to minimize Date.now() usage and check every 100 time
  9771. var TIME_SLOT_DURATION_MS = 20;
  9772. var CHECK_TIME_EVERY = 100;
  9773. function TimeSlotManager() {
  9774. this.reset();
  9775. }
  9776. TimeSlotManager.prototype = {
  9777. check: function TimeSlotManager_check() {
  9778. if (++this.checked < CHECK_TIME_EVERY) {
  9779. return false;
  9780. }
  9781. this.checked = 0;
  9782. return this.endTime <= Date.now();
  9783. },
  9784. reset: function TimeSlotManager_reset() {
  9785. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  9786. this.checked = 0;
  9787. }
  9788. };
  9789. var deferred = Promise.resolve();
  9790. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  9791. PartialEvaluator.prototype = {
  9792. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  9793. if (!isDict(resources)) {
  9794. return false;
  9795. }
  9796. var processed = Object.create(null);
  9797. if (resources.objId) {
  9798. processed[resources.objId] = true;
  9799. }
  9800. var nodes = [resources];
  9801. while (nodes.length) {
  9802. var key;
  9803. var node = nodes.shift();
  9804. // First check the current resources for blend modes.
  9805. var graphicStates = node.get('ExtGState');
  9806. if (isDict(graphicStates)) {
  9807. graphicStates = graphicStates.getAll();
  9808. for (key in graphicStates) {
  9809. var graphicState = graphicStates[key];
  9810. var bm = graphicState['BM'];
  9811. if (isName(bm) && bm.name !== 'Normal') {
  9812. return true;
  9813. }
  9814. }
  9815. }
  9816. // Descend into the XObjects to look for more resources and blend modes.
  9817. var xObjects = node.get('XObject');
  9818. if (!isDict(xObjects)) {
  9819. continue;
  9820. }
  9821. xObjects = xObjects.getAll();
  9822. for (key in xObjects) {
  9823. var xObject = xObjects[key];
  9824. if (!isStream(xObject)) {
  9825. continue;
  9826. }
  9827. if (xObject.dict.objId) {
  9828. if (processed[xObject.dict.objId]) {
  9829. // stream has objId and is processed already
  9830. continue;
  9831. }
  9832. processed[xObject.dict.objId] = true;
  9833. }
  9834. var xResources = xObject.dict.get('Resources');
  9835. // Checking objId to detect an infinite loop.
  9836. if (isDict(xResources) &&
  9837. (!xResources.objId || !processed[xResources.objId])) {
  9838. nodes.push(xResources);
  9839. if (xResources.objId) {
  9840. processed[xResources.objId] = true;
  9841. }
  9842. }
  9843. }
  9844. }
  9845. return false;
  9846. },
  9847. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  9848. xobj, smask,
  9849. operatorList,
  9850. initialState) {
  9851. var matrix = xobj.dict.get('Matrix');
  9852. var bbox = xobj.dict.get('BBox');
  9853. var group = xobj.dict.get('Group');
  9854. if (group) {
  9855. var groupOptions = {
  9856. matrix: matrix,
  9857. bbox: bbox,
  9858. smask: smask,
  9859. isolated: false,
  9860. knockout: false
  9861. };
  9862. var groupSubtype = group.get('S');
  9863. var colorSpace;
  9864. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  9865. groupOptions.isolated = (group.get('I') || false);
  9866. groupOptions.knockout = (group.get('K') || false);
  9867. colorSpace = (group.has('CS') ?
  9868. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  9869. }
  9870. if (smask && smask.backdrop) {
  9871. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  9872. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  9873. }
  9874. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  9875. }
  9876. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  9877. return this.getOperatorList(xobj,
  9878. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  9879. then(function () {
  9880. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  9881. if (group) {
  9882. operatorList.addOp(OPS.endGroup, [groupOptions]);
  9883. }
  9884. });
  9885. },
  9886. buildPaintImageXObject:
  9887. function PartialEvaluator_buildPaintImageXObject(resources, image,
  9888. inline, operatorList,
  9889. cacheKey, imageCache) {
  9890. var self = this;
  9891. var dict = image.dict;
  9892. var w = dict.get('Width', 'W');
  9893. var h = dict.get('Height', 'H');
  9894. if (!(w && isNum(w)) || !(h && isNum(h))) {
  9895. warn('Image dimensions are missing, or not numbers.');
  9896. return;
  9897. }
  9898. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  9899. warn('Image exceeded maximum allowed size and was removed.');
  9900. return;
  9901. }
  9902. var imageMask = (dict.get('ImageMask', 'IM') || false);
  9903. var imgData, args;
  9904. if (imageMask) {
  9905. // This depends on a tmpCanvas being filled with the
  9906. // current fillStyle, such that processing the pixel
  9907. // data can't be done here. Instead of creating a
  9908. // complete PDFImage, only read the information needed
  9909. // for later.
  9910. var width = dict.get('Width', 'W');
  9911. var height = dict.get('Height', 'H');
  9912. var bitStrideLength = (width + 7) >> 3;
  9913. var imgArray = image.getBytes(bitStrideLength * height);
  9914. var decode = dict.get('Decode', 'D');
  9915. var inverseDecode = (!!decode && decode[0] > 0);
  9916. imgData = PDFImage.createMask(imgArray, width, height,
  9917. image instanceof DecodeStream,
  9918. inverseDecode);
  9919. imgData.cached = true;
  9920. args = [imgData];
  9921. operatorList.addOp(OPS.paintImageMaskXObject, args);
  9922. if (cacheKey) {
  9923. imageCache[cacheKey] = {
  9924. fn: OPS.paintImageMaskXObject,
  9925. args: args
  9926. };
  9927. }
  9928. return;
  9929. }
  9930. var softMask = (dict.get('SMask', 'SM') || false);
  9931. var mask = (dict.get('Mask') || false);
  9932. var SMALL_IMAGE_DIMENSIONS = 200;
  9933. // Inlining small images into the queue as RGB data
  9934. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  9935. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  9936. var imageObj = new PDFImage(this.xref, resources, image,
  9937. inline, null, null);
  9938. // We force the use of RGBA_32BPP images here, because we can't handle
  9939. // any other kind.
  9940. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  9941. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  9942. return;
  9943. }
  9944. // If there is no imageMask, create the PDFImage and a lot
  9945. // of image processing can be done here.
  9946. var uniquePrefix = (this.uniquePrefix || '');
  9947. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  9948. operatorList.addDependency(objId);
  9949. args = [objId, w, h];
  9950. if (!softMask && !mask && image instanceof JpegStream &&
  9951. image.isNativelySupported(this.xref, resources)) {
  9952. // These JPEGs don't need any more processing so we can just send it.
  9953. operatorList.addOp(OPS.paintJpegXObject, args);
  9954. this.handler.send('obj',
  9955. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  9956. return;
  9957. }
  9958. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  9959. then(function(imageObj) {
  9960. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  9961. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  9962. [imgData.data.buffer]);
  9963. }).then(undefined, function (reason) {
  9964. warn('Unable to decode image: ' + reason);
  9965. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  9966. });
  9967. operatorList.addOp(OPS.paintImageXObject, args);
  9968. if (cacheKey) {
  9969. imageCache[cacheKey] = {
  9970. fn: OPS.paintImageXObject,
  9971. args: args
  9972. };
  9973. }
  9974. },
  9975. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  9976. operatorList,
  9977. stateManager) {
  9978. var smaskContent = smask.get('G');
  9979. var smaskOptions = {
  9980. subtype: smask.get('S').name,
  9981. backdrop: smask.get('BC')
  9982. };
  9983. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  9984. operatorList, stateManager.state.clone());
  9985. },
  9986. handleTilingType:
  9987. function PartialEvaluator_handleTilingType(fn, args, resources,
  9988. pattern, patternDict,
  9989. operatorList) {
  9990. // Create an IR of the pattern code.
  9991. var tilingOpList = new OperatorList();
  9992. return this.getOperatorList(pattern,
  9993. (patternDict.get('Resources') || resources), tilingOpList).
  9994. then(function () {
  9995. // Add the dependencies to the parent operator list so they are
  9996. // resolved before sub operator list is executed synchronously.
  9997. operatorList.addDependencies(tilingOpList.dependencies);
  9998. operatorList.addOp(fn, getTilingPatternIR({
  9999. fnArray: tilingOpList.fnArray,
  10000. argsArray: tilingOpList.argsArray
  10001. }, patternDict, args));
  10002. });
  10003. },
  10004. handleSetFont:
  10005. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  10006. operatorList, state) {
  10007. // TODO(mack): Not needed?
  10008. var fontName;
  10009. if (fontArgs) {
  10010. fontArgs = fontArgs.slice();
  10011. fontName = fontArgs[0].name;
  10012. }
  10013. var self = this;
  10014. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  10015. function (translated) {
  10016. if (!translated.font.isType3Font) {
  10017. return translated;
  10018. }
  10019. return translated.loadType3Data(self, resources, operatorList).then(
  10020. function () {
  10021. return translated;
  10022. });
  10023. }).then(function (translated) {
  10024. state.font = translated.font;
  10025. translated.send(self.handler);
  10026. return translated.loadedName;
  10027. });
  10028. },
  10029. handleText: function PartialEvaluator_handleText(chars, state) {
  10030. var font = state.font;
  10031. var glyphs = font.charsToGlyphs(chars);
  10032. var isAddToPathSet = !!(state.textRenderingMode &
  10033. TextRenderingMode.ADD_TO_PATH_FLAG);
  10034. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  10035. var buildPath = function (fontChar) {
  10036. if (!font.renderer.hasBuiltPath(fontChar)) {
  10037. var path = font.renderer.getPathJs(fontChar);
  10038. this.handler.send('commonobj', [
  10039. font.loadedName + '_path_' + fontChar,
  10040. 'FontPath',
  10041. path
  10042. ]);
  10043. }
  10044. }.bind(this);
  10045. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  10046. var glyph = glyphs[i];
  10047. if (glyph === null) {
  10048. continue;
  10049. }
  10050. buildPath(glyph.fontChar);
  10051. // If the glyph has an accent we need to build a path for its
  10052. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  10053. var accent = glyph.accent;
  10054. if (accent && accent.fontChar) {
  10055. buildPath(accent.fontChar);
  10056. }
  10057. }
  10058. }
  10059. return glyphs;
  10060. },
  10061. setGState: function PartialEvaluator_setGState(resources, gState,
  10062. operatorList, xref,
  10063. stateManager) {
  10064. // This array holds the converted/processed state data.
  10065. var gStateObj = [];
  10066. var gStateMap = gState.map;
  10067. var self = this;
  10068. var promise = Promise.resolve();
  10069. for (var key in gStateMap) {
  10070. var value = gStateMap[key];
  10071. switch (key) {
  10072. case 'Type':
  10073. break;
  10074. case 'LW':
  10075. case 'LC':
  10076. case 'LJ':
  10077. case 'ML':
  10078. case 'D':
  10079. case 'RI':
  10080. case 'FL':
  10081. case 'CA':
  10082. case 'ca':
  10083. gStateObj.push([key, value]);
  10084. break;
  10085. case 'Font':
  10086. promise = promise.then(function () {
  10087. return self.handleSetFont(resources, null, value[0],
  10088. operatorList, stateManager.state).
  10089. then(function (loadedName) {
  10090. operatorList.addDependency(loadedName);
  10091. gStateObj.push([key, [loadedName, value[1]]]);
  10092. });
  10093. });
  10094. break;
  10095. case 'BM':
  10096. gStateObj.push([key, value]);
  10097. break;
  10098. case 'SMask':
  10099. if (isName(value) && value.name === 'None') {
  10100. gStateObj.push([key, false]);
  10101. break;
  10102. }
  10103. var dict = xref.fetchIfRef(value);
  10104. if (isDict(dict)) {
  10105. promise = promise.then(function () {
  10106. return self.handleSMask(dict, resources, operatorList,
  10107. stateManager);
  10108. });
  10109. gStateObj.push([key, true]);
  10110. } else {
  10111. warn('Unsupported SMask type');
  10112. }
  10113. break;
  10114. // Only generate info log messages for the following since
  10115. // they are unlikely to have a big impact on the rendering.
  10116. case 'OP':
  10117. case 'op':
  10118. case 'OPM':
  10119. case 'BG':
  10120. case 'BG2':
  10121. case 'UCR':
  10122. case 'UCR2':
  10123. case 'TR':
  10124. case 'TR2':
  10125. case 'HT':
  10126. case 'SM':
  10127. case 'SA':
  10128. case 'AIS':
  10129. case 'TK':
  10130. // TODO implement these operators.
  10131. info('graphic state operator ' + key);
  10132. break;
  10133. default:
  10134. info('Unknown graphic state operator ' + key);
  10135. break;
  10136. }
  10137. }
  10138. return promise.then(function () {
  10139. if (gStateObj.length >= 0) {
  10140. operatorList.addOp(OPS.setGState, [gStateObj]);
  10141. }
  10142. });
  10143. },
  10144. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  10145. resources) {
  10146. function errorFont() {
  10147. return Promise.resolve(new TranslatedFont('g_font_error',
  10148. new ErrorFont('Font ' + fontName + ' is not available'), font));
  10149. }
  10150. var fontRef;
  10151. if (font) { // Loading by ref.
  10152. assert(isRef(font));
  10153. fontRef = font;
  10154. } else { // Loading by name.
  10155. var fontRes = resources.get('Font');
  10156. if (fontRes) {
  10157. fontRef = fontRes.getRaw(fontName);
  10158. } else {
  10159. warn('fontRes not available');
  10160. return errorFont();
  10161. }
  10162. }
  10163. if (!fontRef) {
  10164. warn('fontRef not available');
  10165. return errorFont();
  10166. }
  10167. if (this.fontCache.has(fontRef)) {
  10168. return this.fontCache.get(fontRef);
  10169. }
  10170. font = xref.fetchIfRef(fontRef);
  10171. if (!isDict(font)) {
  10172. return errorFont();
  10173. }
  10174. // We are holding font.translated references just for fontRef that are not
  10175. // dictionaries (Dict). See explanation below.
  10176. if (font.translated) {
  10177. return font.translated;
  10178. }
  10179. var fontCapability = createPromiseCapability();
  10180. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  10181. var descriptor = preEvaluatedFont.descriptor;
  10182. var fontID = fontRef.num + '_' + fontRef.gen;
  10183. if (isDict(descriptor)) {
  10184. if (!descriptor.fontAliases) {
  10185. descriptor.fontAliases = Object.create(null);
  10186. }
  10187. var fontAliases = descriptor.fontAliases;
  10188. var hash = preEvaluatedFont.hash;
  10189. if (fontAliases[hash]) {
  10190. var aliasFontRef = fontAliases[hash].aliasRef;
  10191. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  10192. this.fontCache.putAlias(fontRef, aliasFontRef);
  10193. return this.fontCache.get(fontRef);
  10194. }
  10195. }
  10196. if (!fontAliases[hash]) {
  10197. fontAliases[hash] = {
  10198. fontID: Font.getFontID()
  10199. };
  10200. }
  10201. fontAliases[hash].aliasRef = fontRef;
  10202. fontID = fontAliases[hash].fontID;
  10203. }
  10204. // Workaround for bad PDF generators that don't reference fonts
  10205. // properly, i.e. by not using an object identifier.
  10206. // Check if the fontRef is a Dict (as opposed to a standard object),
  10207. // in which case we don't cache the font and instead reference it by
  10208. // fontName in font.loadedName below.
  10209. var fontRefIsDict = isDict(fontRef);
  10210. if (!fontRefIsDict) {
  10211. this.fontCache.put(fontRef, fontCapability.promise);
  10212. }
  10213. // Keep track of each font we translated so the caller can
  10214. // load them asynchronously before calling display on a page.
  10215. font.loadedName = 'g_font_' + (fontRefIsDict ?
  10216. fontName.replace(/\W/g, '') : fontID);
  10217. font.translated = fontCapability.promise;
  10218. // TODO move promises into translate font
  10219. var translatedPromise;
  10220. try {
  10221. translatedPromise = Promise.resolve(
  10222. this.translateFont(preEvaluatedFont, xref));
  10223. } catch (e) {
  10224. translatedPromise = Promise.reject(e);
  10225. }
  10226. translatedPromise.then(function (translatedFont) {
  10227. if (translatedFont.fontType !== undefined) {
  10228. var xrefFontStats = xref.stats.fontTypes;
  10229. xrefFontStats[translatedFont.fontType] = true;
  10230. }
  10231. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10232. translatedFont, font));
  10233. }, function (reason) {
  10234. // TODO fontCapability.reject?
  10235. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  10236. try {
  10237. // error, but it's still nice to have font type reported
  10238. var descriptor = preEvaluatedFont.descriptor;
  10239. var fontFile3 = descriptor && descriptor.get('FontFile3');
  10240. var subtype = fontFile3 && fontFile3.get('Subtype');
  10241. var fontType = getFontType(preEvaluatedFont.type,
  10242. subtype && subtype.name);
  10243. var xrefFontStats = xref.stats.fontTypes;
  10244. xrefFontStats[fontType] = true;
  10245. } catch (ex) { }
  10246. fontCapability.resolve(new TranslatedFont(font.loadedName,
  10247. new ErrorFont(reason instanceof Error ? reason.message : reason),
  10248. font));
  10249. });
  10250. return fontCapability.promise;
  10251. },
  10252. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  10253. var lastIndex = operatorList.length - 1;
  10254. if (!args) {
  10255. args = [];
  10256. }
  10257. if (lastIndex < 0 ||
  10258. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  10259. operatorList.addOp(OPS.constructPath, [[fn], args]);
  10260. } else {
  10261. var opArgs = operatorList.argsArray[lastIndex];
  10262. opArgs[0].push(fn);
  10263. Array.prototype.push.apply(opArgs[1], args);
  10264. }
  10265. },
  10266. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  10267. cs, patterns, resources, xref) {
  10268. // compile tiling patterns
  10269. var patternName = args[args.length - 1];
  10270. // SCN/scn applies patterns along with normal colors
  10271. var pattern;
  10272. if (isName(patternName) &&
  10273. (pattern = patterns.get(patternName.name))) {
  10274. var dict = (isStream(pattern) ? pattern.dict : pattern);
  10275. var typeNum = dict.get('PatternType');
  10276. if (typeNum === TILING_PATTERN) {
  10277. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  10278. return this.handleTilingType(fn, color, resources, pattern,
  10279. dict, operatorList);
  10280. } else if (typeNum === SHADING_PATTERN) {
  10281. var shading = dict.get('Shading');
  10282. var matrix = dict.get('Matrix');
  10283. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  10284. operatorList.addOp(fn, pattern.getIR());
  10285. return Promise.resolve();
  10286. } else {
  10287. return Promise.reject('Unknown PatternType: ' + typeNum);
  10288. }
  10289. }
  10290. // TODO shall we fail here?
  10291. operatorList.addOp(fn, args);
  10292. return Promise.resolve();
  10293. },
  10294. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  10295. resources,
  10296. operatorList,
  10297. initialState) {
  10298. var self = this;
  10299. var xref = this.xref;
  10300. var imageCache = {};
  10301. assert(operatorList);
  10302. resources = (resources || Dict.empty);
  10303. var xobjs = (resources.get('XObject') || Dict.empty);
  10304. var patterns = (resources.get('Pattern') || Dict.empty);
  10305. var stateManager = new StateManager(initialState || new EvalState());
  10306. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10307. var timeSlotManager = new TimeSlotManager();
  10308. return new Promise(function next(resolve, reject) {
  10309. timeSlotManager.reset();
  10310. var stop, operation = {}, i, ii, cs;
  10311. while (!(stop = timeSlotManager.check())) {
  10312. // The arguments parsed by read() are used beyond this loop, so we
  10313. // cannot reuse the same array on each iteration. Therefore we pass
  10314. // in |null| as the initial value (see the comment on
  10315. // EvaluatorPreprocessor_read() for why).
  10316. operation.args = null;
  10317. if (!(preprocessor.read(operation))) {
  10318. break;
  10319. }
  10320. var args = operation.args;
  10321. var fn = operation.fn;
  10322. switch (fn | 0) {
  10323. case OPS.paintXObject:
  10324. if (args[0].code) {
  10325. break;
  10326. }
  10327. // eagerly compile XForm objects
  10328. var name = args[0].name;
  10329. if (!name) {
  10330. warn('XObject must be referred to by name.');
  10331. continue;
  10332. }
  10333. if (imageCache[name] !== undefined) {
  10334. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  10335. args = null;
  10336. continue;
  10337. }
  10338. var xobj = xobjs.get(name);
  10339. if (xobj) {
  10340. assert(isStream(xobj), 'XObject should be a stream');
  10341. var type = xobj.dict.get('Subtype');
  10342. assert(isName(type),
  10343. 'XObject should have a Name subtype');
  10344. if (type.name === 'Form') {
  10345. stateManager.save();
  10346. return self.buildFormXObject(resources, xobj, null,
  10347. operatorList,
  10348. stateManager.state.clone()).
  10349. then(function () {
  10350. stateManager.restore();
  10351. next(resolve, reject);
  10352. }, reject);
  10353. } else if (type.name === 'Image') {
  10354. self.buildPaintImageXObject(resources, xobj, false,
  10355. operatorList, name, imageCache);
  10356. args = null;
  10357. continue;
  10358. } else if (type.name === 'PS') {
  10359. // PostScript XObjects are unused when viewing documents.
  10360. // See section 4.7.1 of Adobe's PDF reference.
  10361. info('Ignored XObject subtype PS');
  10362. continue;
  10363. } else {
  10364. error('Unhandled XObject subtype ' + type.name);
  10365. }
  10366. }
  10367. break;
  10368. case OPS.setFont:
  10369. var fontSize = args[1];
  10370. // eagerly collect all fonts
  10371. return self.handleSetFont(resources, args, null,
  10372. operatorList, stateManager.state).
  10373. then(function (loadedName) {
  10374. operatorList.addDependency(loadedName);
  10375. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  10376. next(resolve, reject);
  10377. }, reject);
  10378. case OPS.endInlineImage:
  10379. var cacheKey = args[0].cacheKey;
  10380. if (cacheKey) {
  10381. var cacheEntry = imageCache[cacheKey];
  10382. if (cacheEntry !== undefined) {
  10383. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  10384. args = null;
  10385. continue;
  10386. }
  10387. }
  10388. self.buildPaintImageXObject(resources, args[0], true,
  10389. operatorList, cacheKey, imageCache);
  10390. args = null;
  10391. continue;
  10392. case OPS.showText:
  10393. args[0] = self.handleText(args[0], stateManager.state);
  10394. break;
  10395. case OPS.showSpacedText:
  10396. var arr = args[0];
  10397. var combinedGlyphs = [];
  10398. var arrLength = arr.length;
  10399. for (i = 0; i < arrLength; ++i) {
  10400. var arrItem = arr[i];
  10401. if (isString(arrItem)) {
  10402. Array.prototype.push.apply(combinedGlyphs,
  10403. self.handleText(arrItem, stateManager.state));
  10404. } else if (isNum(arrItem)) {
  10405. combinedGlyphs.push(arrItem);
  10406. }
  10407. }
  10408. args[0] = combinedGlyphs;
  10409. fn = OPS.showText;
  10410. break;
  10411. case OPS.nextLineShowText:
  10412. operatorList.addOp(OPS.nextLine);
  10413. args[0] = self.handleText(args[0], stateManager.state);
  10414. fn = OPS.showText;
  10415. break;
  10416. case OPS.nextLineSetSpacingShowText:
  10417. operatorList.addOp(OPS.nextLine);
  10418. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  10419. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  10420. args[0] = self.handleText(args[0], stateManager.state);
  10421. fn = OPS.showText;
  10422. break;
  10423. case OPS.setTextRenderingMode:
  10424. stateManager.state.textRenderingMode = args[0];
  10425. break;
  10426. case OPS.setFillColorSpace:
  10427. stateManager.state.fillColorSpace =
  10428. ColorSpace.parse(args[0], xref, resources);
  10429. continue;
  10430. case OPS.setStrokeColorSpace:
  10431. stateManager.state.strokeColorSpace =
  10432. ColorSpace.parse(args[0], xref, resources);
  10433. continue;
  10434. case OPS.setFillColor:
  10435. cs = stateManager.state.fillColorSpace;
  10436. args = cs.getRgb(args, 0);
  10437. fn = OPS.setFillRGBColor;
  10438. break;
  10439. case OPS.setStrokeColor:
  10440. cs = stateManager.state.strokeColorSpace;
  10441. args = cs.getRgb(args, 0);
  10442. fn = OPS.setStrokeRGBColor;
  10443. break;
  10444. case OPS.setFillGray:
  10445. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  10446. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10447. fn = OPS.setFillRGBColor;
  10448. break;
  10449. case OPS.setStrokeGray:
  10450. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  10451. args = ColorSpace.singletons.gray.getRgb(args, 0);
  10452. fn = OPS.setStrokeRGBColor;
  10453. break;
  10454. case OPS.setFillCMYKColor:
  10455. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  10456. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10457. fn = OPS.setFillRGBColor;
  10458. break;
  10459. case OPS.setStrokeCMYKColor:
  10460. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  10461. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  10462. fn = OPS.setStrokeRGBColor;
  10463. break;
  10464. case OPS.setFillRGBColor:
  10465. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  10466. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10467. break;
  10468. case OPS.setStrokeRGBColor:
  10469. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  10470. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  10471. break;
  10472. case OPS.setFillColorN:
  10473. cs = stateManager.state.fillColorSpace;
  10474. if (cs.name === 'Pattern') {
  10475. return self.handleColorN(operatorList, OPS.setFillColorN,
  10476. args, cs, patterns, resources, xref).then(function() {
  10477. next(resolve, reject);
  10478. }, reject);
  10479. }
  10480. args = cs.getRgb(args, 0);
  10481. fn = OPS.setFillRGBColor;
  10482. break;
  10483. case OPS.setStrokeColorN:
  10484. cs = stateManager.state.strokeColorSpace;
  10485. if (cs.name === 'Pattern') {
  10486. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  10487. args, cs, patterns, resources, xref).then(function() {
  10488. next(resolve, reject);
  10489. }, reject);
  10490. }
  10491. args = cs.getRgb(args, 0);
  10492. fn = OPS.setStrokeRGBColor;
  10493. break;
  10494. case OPS.shadingFill:
  10495. var shadingRes = resources.get('Shading');
  10496. if (!shadingRes) {
  10497. error('No shading resource found');
  10498. }
  10499. var shading = shadingRes.get(args[0].name);
  10500. if (!shading) {
  10501. error('No shading object found');
  10502. }
  10503. var shadingFill = Pattern.parseShading(shading, null, xref,
  10504. resources);
  10505. var patternIR = shadingFill.getIR();
  10506. args = [patternIR];
  10507. fn = OPS.shadingFill;
  10508. break;
  10509. case OPS.setGState:
  10510. var dictName = args[0];
  10511. var extGState = resources.get('ExtGState');
  10512. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10513. break;
  10514. }
  10515. var gState = extGState.get(dictName.name);
  10516. return self.setGState(resources, gState, operatorList, xref,
  10517. stateManager).then(function() {
  10518. next(resolve, reject);
  10519. }, reject);
  10520. case OPS.moveTo:
  10521. case OPS.lineTo:
  10522. case OPS.curveTo:
  10523. case OPS.curveTo2:
  10524. case OPS.curveTo3:
  10525. case OPS.closePath:
  10526. self.buildPath(operatorList, fn, args);
  10527. continue;
  10528. case OPS.rectangle:
  10529. self.buildPath(operatorList, fn, args);
  10530. continue;
  10531. }
  10532. operatorList.addOp(fn, args);
  10533. }
  10534. if (stop) {
  10535. deferred.then(function () {
  10536. next(resolve, reject);
  10537. });
  10538. return;
  10539. }
  10540. // Some PDFs don't close all restores inside object/form.
  10541. // Closing those for them.
  10542. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  10543. operatorList.addOp(OPS.restore, []);
  10544. }
  10545. resolve();
  10546. });
  10547. },
  10548. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  10549. stateManager) {
  10550. stateManager = (stateManager || new StateManager(new TextState()));
  10551. var textContent = {
  10552. items: [],
  10553. styles: Object.create(null)
  10554. };
  10555. var bidiTexts = textContent.items;
  10556. var SPACE_FACTOR = 0.3;
  10557. var MULTI_SPACE_FACTOR = 1.5;
  10558. var self = this;
  10559. var xref = this.xref;
  10560. resources = (xref.fetchIfRef(resources) || Dict.empty);
  10561. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  10562. var xobjs = null;
  10563. var xobjsCache = {};
  10564. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  10565. var textState;
  10566. function newTextChunk() {
  10567. var font = textState.font;
  10568. if (!(font.loadedName in textContent.styles)) {
  10569. textContent.styles[font.loadedName] = {
  10570. fontFamily: font.fallbackName,
  10571. ascent: font.ascent,
  10572. descent: font.descent,
  10573. vertical: font.vertical
  10574. };
  10575. }
  10576. return {
  10577. // |str| is initially an array which we push individual chars to, and
  10578. // then runBidi() overwrites it with the final string.
  10579. str: [],
  10580. dir: null,
  10581. width: 0,
  10582. height: 0,
  10583. transform: null,
  10584. fontName: font.loadedName
  10585. };
  10586. }
  10587. function runBidi(textChunk) {
  10588. var str = textChunk.str.join('');
  10589. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  10590. textChunk.str = bidiResult.str;
  10591. textChunk.dir = bidiResult.dir;
  10592. return textChunk;
  10593. }
  10594. function handleSetFont(fontName, fontRef) {
  10595. return self.loadFont(fontName, fontRef, xref, resources).
  10596. then(function (translated) {
  10597. textState.font = translated.font;
  10598. textState.fontMatrix = translated.font.fontMatrix ||
  10599. FONT_IDENTITY_MATRIX;
  10600. });
  10601. }
  10602. function buildTextGeometry(chars, textChunk) {
  10603. var font = textState.font;
  10604. textChunk = textChunk || newTextChunk();
  10605. if (!textChunk.transform) {
  10606. // 9.4.4 Text Space Details
  10607. var tsm = [textState.fontSize * textState.textHScale, 0,
  10608. 0, textState.fontSize,
  10609. 0, textState.textRise];
  10610. if (font.isType3Font &&
  10611. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  10612. textState.fontSize === 1) {
  10613. var glyphHeight = font.bbox[3] - font.bbox[1];
  10614. if (glyphHeight > 0) {
  10615. glyphHeight = glyphHeight * textState.fontMatrix[3];
  10616. tsm[3] *= glyphHeight;
  10617. }
  10618. }
  10619. var trm = textChunk.transform = Util.transform(textState.ctm,
  10620. Util.transform(textState.textMatrix, tsm));
  10621. if (!font.vertical) {
  10622. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  10623. } else {
  10624. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  10625. }
  10626. }
  10627. var width = 0;
  10628. var height = 0;
  10629. var glyphs = font.charsToGlyphs(chars);
  10630. var defaultVMetrics = font.defaultVMetrics;
  10631. for (var i = 0; i < glyphs.length; i++) {
  10632. var glyph = glyphs[i];
  10633. if (!glyph) { // Previous glyph was a space.
  10634. width += textState.wordSpacing * textState.textHScale;
  10635. continue;
  10636. }
  10637. var vMetricX = null;
  10638. var vMetricY = null;
  10639. var glyphWidth = null;
  10640. if (font.vertical) {
  10641. if (glyph.vmetric) {
  10642. glyphWidth = glyph.vmetric[0];
  10643. vMetricX = glyph.vmetric[1];
  10644. vMetricY = glyph.vmetric[2];
  10645. } else {
  10646. glyphWidth = glyph.width;
  10647. vMetricX = glyph.width * 0.5;
  10648. vMetricY = defaultVMetrics[2];
  10649. }
  10650. } else {
  10651. glyphWidth = glyph.width;
  10652. }
  10653. var glyphUnicode = glyph.unicode;
  10654. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  10655. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  10656. }
  10657. glyphUnicode = reverseIfRtl(glyphUnicode);
  10658. // The following will calculate the x and y of the individual glyphs.
  10659. // if (font.vertical) {
  10660. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  10661. // textState.fontMatrix[0];
  10662. // tsm[5] -= vMetricY * textState.fontSize *
  10663. // textState.fontMatrix[0];
  10664. // }
  10665. // var trm = Util.transform(textState.textMatrix, tsm);
  10666. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  10667. // var x = pt[0];
  10668. // var y = pt[1];
  10669. var charSpacing = 0;
  10670. if (textChunk.str.length > 0) {
  10671. // Apply char spacing only when there are chars.
  10672. // As a result there is only spacing between glyphs.
  10673. charSpacing = textState.charSpacing;
  10674. }
  10675. var tx = 0;
  10676. var ty = 0;
  10677. if (!font.vertical) {
  10678. var w0 = glyphWidth * textState.fontMatrix[0];
  10679. tx = (w0 * textState.fontSize + charSpacing) *
  10680. textState.textHScale;
  10681. width += tx;
  10682. } else {
  10683. var w1 = glyphWidth * textState.fontMatrix[0];
  10684. ty = w1 * textState.fontSize + charSpacing;
  10685. height += ty;
  10686. }
  10687. textState.translateTextMatrix(tx, ty);
  10688. textChunk.str.push(glyphUnicode);
  10689. }
  10690. var a = textState.textLineMatrix[0];
  10691. var b = textState.textLineMatrix[1];
  10692. var scaleLineX = Math.sqrt(a * a + b * b);
  10693. a = textState.ctm[0];
  10694. b = textState.ctm[1];
  10695. var scaleCtmX = Math.sqrt(a * a + b * b);
  10696. if (!font.vertical) {
  10697. textChunk.width += width * scaleCtmX * scaleLineX;
  10698. } else {
  10699. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  10700. }
  10701. return textChunk;
  10702. }
  10703. var timeSlotManager = new TimeSlotManager();
  10704. return new Promise(function next(resolve, reject) {
  10705. timeSlotManager.reset();
  10706. var stop, operation = {}, args = [];
  10707. while (!(stop = timeSlotManager.check())) {
  10708. // The arguments parsed by read() are not used beyond this loop, so
  10709. // we can reuse the same array on every iteration, thus avoiding
  10710. // unnecessary allocations.
  10711. args.length = 0;
  10712. operation.args = args;
  10713. if (!(preprocessor.read(operation))) {
  10714. break;
  10715. }
  10716. textState = stateManager.state;
  10717. var fn = operation.fn;
  10718. args = operation.args;
  10719. switch (fn | 0) {
  10720. case OPS.setFont:
  10721. textState.fontSize = args[1];
  10722. return handleSetFont(args[0].name).then(function() {
  10723. next(resolve, reject);
  10724. }, reject);
  10725. case OPS.setTextRise:
  10726. textState.textRise = args[0];
  10727. break;
  10728. case OPS.setHScale:
  10729. textState.textHScale = args[0] / 100;
  10730. break;
  10731. case OPS.setLeading:
  10732. textState.leading = args[0];
  10733. break;
  10734. case OPS.moveText:
  10735. textState.translateTextLineMatrix(args[0], args[1]);
  10736. textState.textMatrix = textState.textLineMatrix.slice();
  10737. break;
  10738. case OPS.setLeadingMoveText:
  10739. textState.leading = -args[1];
  10740. textState.translateTextLineMatrix(args[0], args[1]);
  10741. textState.textMatrix = textState.textLineMatrix.slice();
  10742. break;
  10743. case OPS.nextLine:
  10744. textState.carriageReturn();
  10745. break;
  10746. case OPS.setTextMatrix:
  10747. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  10748. args[4], args[5]);
  10749. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  10750. args[4], args[5]);
  10751. break;
  10752. case OPS.setCharSpacing:
  10753. textState.charSpacing = args[0];
  10754. break;
  10755. case OPS.setWordSpacing:
  10756. textState.wordSpacing = args[0];
  10757. break;
  10758. case OPS.beginText:
  10759. textState.textMatrix = IDENTITY_MATRIX.slice();
  10760. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  10761. break;
  10762. case OPS.showSpacedText:
  10763. var items = args[0];
  10764. var textChunk = newTextChunk();
  10765. var offset;
  10766. for (var j = 0, jj = items.length; j < jj; j++) {
  10767. if (typeof items[j] === 'string') {
  10768. buildTextGeometry(items[j], textChunk);
  10769. } else {
  10770. var val = items[j] / 1000;
  10771. if (!textState.font.vertical) {
  10772. offset = -val * textState.fontSize * textState.textHScale *
  10773. textState.textMatrix[0];
  10774. textState.translateTextMatrix(offset, 0);
  10775. textChunk.width += offset;
  10776. } else {
  10777. offset = -val * textState.fontSize *
  10778. textState.textMatrix[3];
  10779. textState.translateTextMatrix(0, offset);
  10780. textChunk.height += offset;
  10781. }
  10782. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  10783. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  10784. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  10785. fakeSpaces = Math.round(fakeSpaces);
  10786. while (fakeSpaces--) {
  10787. textChunk.str.push(' ');
  10788. }
  10789. } else if (fakeSpaces > SPACE_FACTOR) {
  10790. textChunk.str.push(' ');
  10791. }
  10792. }
  10793. }
  10794. }
  10795. bidiTexts.push(runBidi(textChunk));
  10796. break;
  10797. case OPS.showText:
  10798. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10799. break;
  10800. case OPS.nextLineShowText:
  10801. textState.carriageReturn();
  10802. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  10803. break;
  10804. case OPS.nextLineSetSpacingShowText:
  10805. textState.wordSpacing = args[0];
  10806. textState.charSpacing = args[1];
  10807. textState.carriageReturn();
  10808. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  10809. break;
  10810. case OPS.paintXObject:
  10811. if (args[0].code) {
  10812. break;
  10813. }
  10814. if (!xobjs) {
  10815. xobjs = (resources.get('XObject') || Dict.empty);
  10816. }
  10817. var name = args[0].name;
  10818. if (xobjsCache.key === name) {
  10819. if (xobjsCache.texts) {
  10820. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  10821. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  10822. }
  10823. break;
  10824. }
  10825. var xobj = xobjs.get(name);
  10826. if (!xobj) {
  10827. break;
  10828. }
  10829. assert(isStream(xobj), 'XObject should be a stream');
  10830. var type = xobj.dict.get('Subtype');
  10831. assert(isName(type),
  10832. 'XObject should have a Name subtype');
  10833. if ('Form' !== type.name) {
  10834. xobjsCache.key = name;
  10835. xobjsCache.texts = null;
  10836. break;
  10837. }
  10838. stateManager.save();
  10839. var matrix = xobj.dict.get('Matrix');
  10840. if (isArray(matrix) && matrix.length === 6) {
  10841. stateManager.transform(matrix);
  10842. }
  10843. return self.getTextContent(xobj,
  10844. xobj.dict.get('Resources') || resources, stateManager).
  10845. then(function (formTextContent) {
  10846. Util.appendToArray(bidiTexts, formTextContent.items);
  10847. Util.extendObj(textContent.styles, formTextContent.styles);
  10848. stateManager.restore();
  10849. xobjsCache.key = name;
  10850. xobjsCache.texts = formTextContent;
  10851. next(resolve, reject);
  10852. }, reject);
  10853. case OPS.setGState:
  10854. var dictName = args[0];
  10855. var extGState = resources.get('ExtGState');
  10856. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  10857. break;
  10858. }
  10859. var gsStateMap = extGState.get(dictName.name);
  10860. var gsStateFont = null;
  10861. for (var key in gsStateMap) {
  10862. if (key === 'Font') {
  10863. assert(!gsStateFont);
  10864. gsStateFont = gsStateMap[key];
  10865. }
  10866. }
  10867. if (gsStateFont) {
  10868. textState.fontSize = gsStateFont[1];
  10869. return handleSetFont(gsStateFont[0]).then(function() {
  10870. next(resolve, reject);
  10871. }, reject);
  10872. }
  10873. break;
  10874. } // switch
  10875. } // while
  10876. if (stop) {
  10877. deferred.then(function () {
  10878. next(resolve, reject);
  10879. });
  10880. return;
  10881. }
  10882. resolve(textContent);
  10883. });
  10884. },
  10885. extractDataStructures: function
  10886. partialEvaluatorExtractDataStructures(dict, baseDict,
  10887. xref, properties) {
  10888. // 9.10.2
  10889. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  10890. if (toUnicode) {
  10891. properties.toUnicode = this.readToUnicode(toUnicode);
  10892. }
  10893. if (properties.composite) {
  10894. // CIDSystemInfo helps to match CID to glyphs
  10895. var cidSystemInfo = dict.get('CIDSystemInfo');
  10896. if (isDict(cidSystemInfo)) {
  10897. properties.cidSystemInfo = {
  10898. registry: cidSystemInfo.get('Registry'),
  10899. ordering: cidSystemInfo.get('Ordering'),
  10900. supplement: cidSystemInfo.get('Supplement')
  10901. };
  10902. }
  10903. var cidToGidMap = dict.get('CIDToGIDMap');
  10904. if (isStream(cidToGidMap)) {
  10905. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  10906. }
  10907. }
  10908. // Based on 9.6.6 of the spec the encoding can come from multiple places
  10909. // and depends on the font type. The base encoding and differences are
  10910. // read here, but the encoding that is actually used is chosen during
  10911. // glyph mapping in the font.
  10912. // TODO: Loading the built in encoding in the font would allow the
  10913. // differences to be merged in here not require us to hold on to it.
  10914. var differences = [];
  10915. var baseEncodingName = null;
  10916. var encoding;
  10917. if (dict.has('Encoding')) {
  10918. encoding = dict.get('Encoding');
  10919. if (isDict(encoding)) {
  10920. baseEncodingName = encoding.get('BaseEncoding');
  10921. baseEncodingName = (isName(baseEncodingName) ?
  10922. baseEncodingName.name : null);
  10923. // Load the differences between the base and original
  10924. if (encoding.has('Differences')) {
  10925. var diffEncoding = encoding.get('Differences');
  10926. var index = 0;
  10927. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  10928. var data = diffEncoding[j];
  10929. if (isNum(data)) {
  10930. index = data;
  10931. } else if (isName(data)) {
  10932. differences[index++] = data.name;
  10933. } else if (isRef(data)) {
  10934. diffEncoding[j--] = xref.fetch(data);
  10935. continue;
  10936. } else {
  10937. error('Invalid entry in \'Differences\' array: ' + data);
  10938. }
  10939. }
  10940. }
  10941. } else if (isName(encoding)) {
  10942. baseEncodingName = encoding.name;
  10943. } else {
  10944. error('Encoding is not a Name nor a Dict');
  10945. }
  10946. // According to table 114 if the encoding is a named encoding it must be
  10947. // one of these predefined encodings.
  10948. if ((baseEncodingName !== 'MacRomanEncoding' &&
  10949. baseEncodingName !== 'MacExpertEncoding' &&
  10950. baseEncodingName !== 'WinAnsiEncoding')) {
  10951. baseEncodingName = null;
  10952. }
  10953. }
  10954. if (baseEncodingName) {
  10955. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  10956. } else {
  10957. encoding = (properties.type === 'TrueType' ?
  10958. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  10959. // The Symbolic attribute can be misused for regular fonts
  10960. // Heuristic: we have to check if the font is a standard one also
  10961. if (!!(properties.flags & FontFlags.Symbolic)) {
  10962. encoding = Encodings.MacRomanEncoding;
  10963. if (!properties.file) {
  10964. if (/Symbol/i.test(properties.name)) {
  10965. encoding = Encodings.SymbolSetEncoding;
  10966. } else if (/Dingbats/i.test(properties.name)) {
  10967. encoding = Encodings.ZapfDingbatsEncoding;
  10968. }
  10969. }
  10970. }
  10971. properties.defaultEncoding = encoding;
  10972. }
  10973. properties.differences = differences;
  10974. properties.baseEncodingName = baseEncodingName;
  10975. properties.dict = dict;
  10976. },
  10977. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  10978. var cmap, cmapObj = toUnicode;
  10979. if (isName(cmapObj)) {
  10980. cmap = CMapFactory.create(cmapObj,
  10981. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10982. if (cmap instanceof IdentityCMap) {
  10983. return new IdentityToUnicodeMap(0, 0xFFFF);
  10984. }
  10985. return new ToUnicodeMap(cmap.getMap());
  10986. } else if (isStream(cmapObj)) {
  10987. cmap = CMapFactory.create(cmapObj,
  10988. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10989. if (cmap instanceof IdentityCMap) {
  10990. return new IdentityToUnicodeMap(0, 0xFFFF);
  10991. }
  10992. cmap = cmap.getMap();
  10993. // Convert UTF-16BE
  10994. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  10995. // to iterate over all keys.
  10996. cmap.forEach(function(token, i) {
  10997. var str = [];
  10998. for (var k = 0; k < token.length; k += 2) {
  10999. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11000. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  11001. str.push(w1);
  11002. continue;
  11003. }
  11004. k += 2;
  11005. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  11006. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  11007. }
  11008. cmap[i] = String.fromCharCode.apply(String, str);
  11009. });
  11010. return new ToUnicodeMap(cmap);
  11011. }
  11012. return null;
  11013. },
  11014. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  11015. // Extract the encoding from the CIDToGIDMap
  11016. var glyphsData = cidToGidStream.getBytes();
  11017. // Set encoding 0 to later verify the font has an encoding
  11018. var result = [];
  11019. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  11020. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  11021. if (glyphID === 0) {
  11022. continue;
  11023. }
  11024. var code = j >> 1;
  11025. result[code] = glyphID;
  11026. }
  11027. return result;
  11028. },
  11029. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  11030. descriptor,
  11031. properties) {
  11032. var glyphsWidths = [];
  11033. var defaultWidth = 0;
  11034. var glyphsVMetrics = [];
  11035. var defaultVMetrics;
  11036. var i, ii, j, jj, start, code, widths;
  11037. if (properties.composite) {
  11038. defaultWidth = dict.get('DW') || 1000;
  11039. widths = dict.get('W');
  11040. if (widths) {
  11041. for (i = 0, ii = widths.length; i < ii; i++) {
  11042. start = widths[i++];
  11043. code = xref.fetchIfRef(widths[i]);
  11044. if (isArray(code)) {
  11045. for (j = 0, jj = code.length; j < jj; j++) {
  11046. glyphsWidths[start++] = code[j];
  11047. }
  11048. } else {
  11049. var width = widths[++i];
  11050. for (j = start; j <= code; j++) {
  11051. glyphsWidths[j] = width;
  11052. }
  11053. }
  11054. }
  11055. }
  11056. if (properties.vertical) {
  11057. var vmetrics = (dict.get('DW2') || [880, -1000]);
  11058. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  11059. vmetrics = dict.get('W2');
  11060. if (vmetrics) {
  11061. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  11062. start = vmetrics[i++];
  11063. code = xref.fetchIfRef(vmetrics[i]);
  11064. if (isArray(code)) {
  11065. for (j = 0, jj = code.length; j < jj; j++) {
  11066. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  11067. }
  11068. } else {
  11069. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  11070. for (j = start; j <= code; j++) {
  11071. glyphsVMetrics[j] = vmetric;
  11072. }
  11073. }
  11074. }
  11075. }
  11076. }
  11077. } else {
  11078. var firstChar = properties.firstChar;
  11079. widths = dict.get('Widths');
  11080. if (widths) {
  11081. j = firstChar;
  11082. for (i = 0, ii = widths.length; i < ii; i++) {
  11083. glyphsWidths[j++] = widths[i];
  11084. }
  11085. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  11086. } else {
  11087. // Trying get the BaseFont metrics (see comment above).
  11088. var baseFontName = dict.get('BaseFont');
  11089. if (isName(baseFontName)) {
  11090. var metrics = this.getBaseFontMetrics(baseFontName.name);
  11091. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  11092. properties);
  11093. defaultWidth = metrics.defaultWidth;
  11094. }
  11095. }
  11096. }
  11097. // Heuristic: detection of monospace font by checking all non-zero widths
  11098. var isMonospace = true;
  11099. var firstWidth = defaultWidth;
  11100. for (var glyph in glyphsWidths) {
  11101. var glyphWidth = glyphsWidths[glyph];
  11102. if (!glyphWidth) {
  11103. continue;
  11104. }
  11105. if (!firstWidth) {
  11106. firstWidth = glyphWidth;
  11107. continue;
  11108. }
  11109. if (firstWidth !== glyphWidth) {
  11110. isMonospace = false;
  11111. break;
  11112. }
  11113. }
  11114. if (isMonospace) {
  11115. properties.flags |= FontFlags.FixedPitch;
  11116. }
  11117. properties.defaultWidth = defaultWidth;
  11118. properties.widths = glyphsWidths;
  11119. properties.defaultVMetrics = defaultVMetrics;
  11120. properties.vmetrics = glyphsVMetrics;
  11121. },
  11122. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  11123. // Simulating descriptor flags attribute
  11124. var fontNameWoStyle = baseFontName.split('-')[0];
  11125. return (fontNameWoStyle in serifFonts) ||
  11126. (fontNameWoStyle.search(/serif/gi) !== -1);
  11127. },
  11128. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  11129. var defaultWidth = 0;
  11130. var widths = [];
  11131. var monospace = false;
  11132. var lookupName = (stdFontMap[name] || name);
  11133. if (!(lookupName in Metrics)) {
  11134. // Use default fonts for looking up font metrics if the passed
  11135. // font is not a base font
  11136. if (this.isSerifFont(name)) {
  11137. lookupName = 'Times-Roman';
  11138. } else {
  11139. lookupName = 'Helvetica';
  11140. }
  11141. }
  11142. var glyphWidths = Metrics[lookupName];
  11143. if (isNum(glyphWidths)) {
  11144. defaultWidth = glyphWidths;
  11145. monospace = true;
  11146. } else {
  11147. widths = glyphWidths;
  11148. }
  11149. return {
  11150. defaultWidth: defaultWidth,
  11151. monospace: monospace,
  11152. widths: widths
  11153. };
  11154. },
  11155. buildCharCodeToWidth:
  11156. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  11157. properties) {
  11158. var widths = Object.create(null);
  11159. var differences = properties.differences;
  11160. var encoding = properties.defaultEncoding;
  11161. for (var charCode = 0; charCode < 256; charCode++) {
  11162. if (charCode in differences &&
  11163. widthsByGlyphName[differences[charCode]]) {
  11164. widths[charCode] = widthsByGlyphName[differences[charCode]];
  11165. continue;
  11166. }
  11167. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  11168. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  11169. continue;
  11170. }
  11171. }
  11172. return widths;
  11173. },
  11174. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  11175. var baseDict = dict;
  11176. var type = dict.get('Subtype');
  11177. assert(isName(type), 'invalid font Subtype');
  11178. var composite = false;
  11179. var uint8array;
  11180. if (type.name === 'Type0') {
  11181. // If font is a composite
  11182. // - get the descendant font
  11183. // - set the type according to the descendant font
  11184. // - get the FontDescriptor from the descendant font
  11185. var df = dict.get('DescendantFonts');
  11186. if (!df) {
  11187. error('Descendant fonts are not specified');
  11188. }
  11189. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  11190. type = dict.get('Subtype');
  11191. assert(isName(type), 'invalid font Subtype');
  11192. composite = true;
  11193. }
  11194. var descriptor = dict.get('FontDescriptor');
  11195. if (descriptor) {
  11196. var hash = new MurmurHash3_64();
  11197. var encoding = baseDict.getRaw('Encoding');
  11198. if (isName(encoding)) {
  11199. hash.update(encoding.name);
  11200. } else if (isRef(encoding)) {
  11201. hash.update(encoding.num + '_' + encoding.gen);
  11202. } else if (isDict(encoding)) {
  11203. var keys = encoding.getKeys();
  11204. for (var i = 0, ii = keys.length; i < ii; i++) {
  11205. var entry = encoding.getRaw(keys[i]);
  11206. if (isName(entry)) {
  11207. hash.update(entry.name);
  11208. } else if (isRef(entry)) {
  11209. hash.update(entry.num + '_' + entry.gen);
  11210. } else if (isArray(entry)) { // 'Differences' entry.
  11211. // Ideally we should check the contents of the array, but to avoid
  11212. // parsing it here and then again in |extractDataStructures|,
  11213. // we only use the array length for now (fixes bug1157493.pdf).
  11214. hash.update(entry.length.toString());
  11215. }
  11216. }
  11217. }
  11218. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  11219. if (isStream(toUnicode)) {
  11220. var stream = toUnicode.str || toUnicode;
  11221. uint8array = stream.buffer ?
  11222. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  11223. new Uint8Array(stream.bytes.buffer,
  11224. stream.start, stream.end - stream.start);
  11225. hash.update(uint8array);
  11226. } else if (isName(toUnicode)) {
  11227. hash.update(toUnicode.name);
  11228. }
  11229. var widths = dict.get('Widths') || baseDict.get('Widths');
  11230. if (widths) {
  11231. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  11232. hash.update(uint8array);
  11233. }
  11234. }
  11235. return {
  11236. descriptor: descriptor,
  11237. dict: dict,
  11238. baseDict: baseDict,
  11239. composite: composite,
  11240. type: type.name,
  11241. hash: hash ? hash.hexdigest() : ''
  11242. };
  11243. },
  11244. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  11245. xref) {
  11246. var baseDict = preEvaluatedFont.baseDict;
  11247. var dict = preEvaluatedFont.dict;
  11248. var composite = preEvaluatedFont.composite;
  11249. var descriptor = preEvaluatedFont.descriptor;
  11250. var type = preEvaluatedFont.type;
  11251. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  11252. var properties;
  11253. if (!descriptor) {
  11254. if (type === 'Type3') {
  11255. // FontDescriptor is only required for Type3 fonts when the document
  11256. // is a tagged pdf. Create a barbebones one to get by.
  11257. descriptor = new Dict(null);
  11258. descriptor.set('FontName', Name.get(type));
  11259. descriptor.set('FontBBox', dict.get('FontBBox'));
  11260. } else {
  11261. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  11262. // FontDescriptor was not required.
  11263. // This case is here for compatibility.
  11264. var baseFontName = dict.get('BaseFont');
  11265. if (!isName(baseFontName)) {
  11266. error('Base font is not specified');
  11267. }
  11268. // Using base font name as a font name.
  11269. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  11270. var metrics = this.getBaseFontMetrics(baseFontName);
  11271. // Simulating descriptor flags attribute
  11272. var fontNameWoStyle = baseFontName.split('-')[0];
  11273. var flags =
  11274. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  11275. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  11276. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  11277. FontFlags.Nonsymbolic);
  11278. properties = {
  11279. type: type,
  11280. name: baseFontName,
  11281. widths: metrics.widths,
  11282. defaultWidth: metrics.defaultWidth,
  11283. flags: flags,
  11284. firstChar: 0,
  11285. lastChar: maxCharIndex
  11286. };
  11287. this.extractDataStructures(dict, dict, xref, properties);
  11288. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  11289. properties);
  11290. return new Font(baseFontName, null, properties);
  11291. }
  11292. }
  11293. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  11294. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  11295. // to ignore this rule when a variant of a standart font is used.
  11296. // TODO Fill the width array depending on which of the base font this is
  11297. // a variant.
  11298. var firstChar = (dict.get('FirstChar') || 0);
  11299. var lastChar = (dict.get('LastChar') || maxCharIndex);
  11300. var fontName = descriptor.get('FontName');
  11301. var baseFont = dict.get('BaseFont');
  11302. // Some bad PDFs have a string as the font name.
  11303. if (isString(fontName)) {
  11304. fontName = Name.get(fontName);
  11305. }
  11306. if (isString(baseFont)) {
  11307. baseFont = Name.get(baseFont);
  11308. }
  11309. if (type !== 'Type3') {
  11310. var fontNameStr = fontName && fontName.name;
  11311. var baseFontStr = baseFont && baseFont.name;
  11312. if (fontNameStr !== baseFontStr) {
  11313. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  11314. '" but should be the same as the Font\'s BaseFont "' +
  11315. baseFontStr + '"');
  11316. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  11317. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  11318. if (fontNameStr && baseFontStr &&
  11319. baseFontStr.indexOf(fontNameStr) === 0) {
  11320. fontName = baseFont;
  11321. }
  11322. }
  11323. }
  11324. fontName = (fontName || baseFont);
  11325. assert(isName(fontName), 'invalid font name');
  11326. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  11327. if (fontFile) {
  11328. if (fontFile.dict) {
  11329. var subtype = fontFile.dict.get('Subtype');
  11330. if (subtype) {
  11331. subtype = subtype.name;
  11332. }
  11333. var length1 = fontFile.dict.get('Length1');
  11334. var length2 = fontFile.dict.get('Length2');
  11335. }
  11336. }
  11337. properties = {
  11338. type: type,
  11339. name: fontName.name,
  11340. subtype: subtype,
  11341. file: fontFile,
  11342. length1: length1,
  11343. length2: length2,
  11344. loadedName: baseDict.loadedName,
  11345. composite: composite,
  11346. wideChars: composite,
  11347. fixedPitch: false,
  11348. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  11349. firstChar: firstChar || 0,
  11350. lastChar: (lastChar || maxCharIndex),
  11351. bbox: descriptor.get('FontBBox'),
  11352. ascent: descriptor.get('Ascent'),
  11353. descent: descriptor.get('Descent'),
  11354. xHeight: descriptor.get('XHeight'),
  11355. capHeight: descriptor.get('CapHeight'),
  11356. flags: descriptor.get('Flags'),
  11357. italicAngle: descriptor.get('ItalicAngle'),
  11358. coded: false
  11359. };
  11360. if (composite) {
  11361. var cidEncoding = baseDict.get('Encoding');
  11362. if (isName(cidEncoding)) {
  11363. properties.cidEncoding = cidEncoding.name;
  11364. }
  11365. properties.cMap = CMapFactory.create(cidEncoding,
  11366. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  11367. properties.vertical = properties.cMap.vertical;
  11368. }
  11369. this.extractDataStructures(dict, baseDict, xref, properties);
  11370. this.extractWidths(dict, xref, descriptor, properties);
  11371. if (type === 'Type3') {
  11372. properties.isType3Font = true;
  11373. }
  11374. return new Font(fontName.name, fontFile, properties);
  11375. }
  11376. };
  11377. return PartialEvaluator;
  11378. })();
  11379. var TranslatedFont = (function TranslatedFontClosure() {
  11380. function TranslatedFont(loadedName, font, dict) {
  11381. this.loadedName = loadedName;
  11382. this.font = font;
  11383. this.dict = dict;
  11384. this.type3Loaded = null;
  11385. this.sent = false;
  11386. }
  11387. TranslatedFont.prototype = {
  11388. send: function (handler) {
  11389. if (this.sent) {
  11390. return;
  11391. }
  11392. var fontData = this.font.exportData();
  11393. handler.send('commonobj', [
  11394. this.loadedName,
  11395. 'Font',
  11396. fontData
  11397. ]);
  11398. this.sent = true;
  11399. },
  11400. loadType3Data: function (evaluator, resources, parentOperatorList) {
  11401. assert(this.font.isType3Font);
  11402. if (this.type3Loaded) {
  11403. return this.type3Loaded;
  11404. }
  11405. var translatedFont = this.font;
  11406. var loadCharProcsPromise = Promise.resolve();
  11407. var charProcs = this.dict.get('CharProcs').getAll();
  11408. var fontResources = this.dict.get('Resources') || resources;
  11409. var charProcKeys = Object.keys(charProcs);
  11410. var charProcOperatorList = {};
  11411. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  11412. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  11413. var glyphStream = charProcs[key];
  11414. var operatorList = new OperatorList();
  11415. return evaluator.getOperatorList(glyphStream, fontResources,
  11416. operatorList).then(function () {
  11417. charProcOperatorList[key] = operatorList.getIR();
  11418. // Add the dependencies to the parent operator list so they are
  11419. // resolved before sub operator list is executed synchronously.
  11420. parentOperatorList.addDependencies(operatorList.dependencies);
  11421. }, function (reason) {
  11422. warn('Type3 font resource \"' + key + '\" is not available');
  11423. var operatorList = new OperatorList();
  11424. charProcOperatorList[key] = operatorList.getIR();
  11425. });
  11426. }.bind(this, charProcKeys[i]));
  11427. }
  11428. this.type3Loaded = loadCharProcsPromise.then(function () {
  11429. translatedFont.charProcOperatorList = charProcOperatorList;
  11430. });
  11431. return this.type3Loaded;
  11432. }
  11433. };
  11434. return TranslatedFont;
  11435. })();
  11436. var OperatorList = (function OperatorListClosure() {
  11437. var CHUNK_SIZE = 1000;
  11438. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  11439. function getTransfers(queue) {
  11440. var transfers = [];
  11441. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11442. for (var i = 0, ii = queue.length; i < ii; i++) {
  11443. switch (fnArray[i]) {
  11444. case OPS.paintInlineImageXObject:
  11445. case OPS.paintInlineImageXObjectGroup:
  11446. case OPS.paintImageMaskXObject:
  11447. var arg = argsArray[i][0]; // first param in imgData
  11448. if (!arg.cached) {
  11449. transfers.push(arg.data.buffer);
  11450. }
  11451. break;
  11452. }
  11453. }
  11454. return transfers;
  11455. }
  11456. function OperatorList(intent, messageHandler, pageIndex) {
  11457. this.messageHandler = messageHandler;
  11458. this.fnArray = [];
  11459. this.argsArray = [];
  11460. this.dependencies = {};
  11461. this.pageIndex = pageIndex;
  11462. this.intent = intent;
  11463. }
  11464. OperatorList.prototype = {
  11465. get length() {
  11466. return this.argsArray.length;
  11467. },
  11468. addOp: function(fn, args) {
  11469. this.fnArray.push(fn);
  11470. this.argsArray.push(args);
  11471. if (this.messageHandler) {
  11472. if (this.fnArray.length >= CHUNK_SIZE) {
  11473. this.flush();
  11474. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  11475. (fn === OPS.restore || fn === OPS.endText)) {
  11476. // heuristic to flush on boundary of restore or endText
  11477. this.flush();
  11478. }
  11479. }
  11480. },
  11481. addDependency: function(dependency) {
  11482. if (dependency in this.dependencies) {
  11483. return;
  11484. }
  11485. this.dependencies[dependency] = true;
  11486. this.addOp(OPS.dependency, [dependency]);
  11487. },
  11488. addDependencies: function(dependencies) {
  11489. for (var key in dependencies) {
  11490. this.addDependency(key);
  11491. }
  11492. },
  11493. addOpList: function(opList) {
  11494. Util.extendObj(this.dependencies, opList.dependencies);
  11495. for (var i = 0, ii = opList.length; i < ii; i++) {
  11496. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  11497. }
  11498. },
  11499. getIR: function() {
  11500. return {
  11501. fnArray: this.fnArray,
  11502. argsArray: this.argsArray,
  11503. length: this.length
  11504. };
  11505. },
  11506. flush: function(lastChunk) {
  11507. if (this.intent !== 'oplist') {
  11508. new QueueOptimizer().optimize(this);
  11509. }
  11510. var transfers = getTransfers(this);
  11511. this.messageHandler.send('RenderPageChunk', {
  11512. operatorList: {
  11513. fnArray: this.fnArray,
  11514. argsArray: this.argsArray,
  11515. lastChunk: lastChunk,
  11516. length: this.length
  11517. },
  11518. pageIndex: this.pageIndex,
  11519. intent: this.intent
  11520. }, transfers);
  11521. this.dependencies = {};
  11522. this.fnArray.length = 0;
  11523. this.argsArray.length = 0;
  11524. }
  11525. };
  11526. return OperatorList;
  11527. })();
  11528. var StateManager = (function StateManagerClosure() {
  11529. function StateManager(initialState) {
  11530. this.state = initialState;
  11531. this.stateStack = [];
  11532. }
  11533. StateManager.prototype = {
  11534. save: function () {
  11535. var old = this.state;
  11536. this.stateStack.push(this.state);
  11537. this.state = old.clone();
  11538. },
  11539. restore: function () {
  11540. var prev = this.stateStack.pop();
  11541. if (prev) {
  11542. this.state = prev;
  11543. }
  11544. },
  11545. transform: function (args) {
  11546. this.state.ctm = Util.transform(this.state.ctm, args);
  11547. }
  11548. };
  11549. return StateManager;
  11550. })();
  11551. var TextState = (function TextStateClosure() {
  11552. function TextState() {
  11553. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11554. this.fontSize = 0;
  11555. this.font = null;
  11556. this.fontMatrix = FONT_IDENTITY_MATRIX;
  11557. this.textMatrix = IDENTITY_MATRIX.slice();
  11558. this.textLineMatrix = IDENTITY_MATRIX.slice();
  11559. this.charSpacing = 0;
  11560. this.wordSpacing = 0;
  11561. this.leading = 0;
  11562. this.textHScale = 1;
  11563. this.textRise = 0;
  11564. }
  11565. TextState.prototype = {
  11566. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11567. var m = this.textMatrix;
  11568. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11569. },
  11570. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  11571. var m = this.textLineMatrix;
  11572. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  11573. },
  11574. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  11575. var m = this.textMatrix;
  11576. m[4] = m[0] * x + m[2] * y + m[4];
  11577. m[5] = m[1] * x + m[3] * y + m[5];
  11578. },
  11579. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  11580. var m = this.textLineMatrix;
  11581. m[4] = m[0] * x + m[2] * y + m[4];
  11582. m[5] = m[1] * x + m[3] * y + m[5];
  11583. },
  11584. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  11585. // 9.4.4 Text Space Details
  11586. var tsm = [this.fontSize * this.textHScale, 0,
  11587. 0, this.fontSize,
  11588. 0, this.textRise];
  11589. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  11590. },
  11591. carriageReturn: function TextState_carriageReturn() {
  11592. this.translateTextLineMatrix(0, -this.leading);
  11593. this.textMatrix = this.textLineMatrix.slice();
  11594. },
  11595. clone: function TextState_clone() {
  11596. var clone = Object.create(this);
  11597. clone.textMatrix = this.textMatrix.slice();
  11598. clone.textLineMatrix = this.textLineMatrix.slice();
  11599. clone.fontMatrix = this.fontMatrix.slice();
  11600. return clone;
  11601. }
  11602. };
  11603. return TextState;
  11604. })();
  11605. var EvalState = (function EvalStateClosure() {
  11606. function EvalState() {
  11607. this.ctm = new Float32Array(IDENTITY_MATRIX);
  11608. this.font = null;
  11609. this.textRenderingMode = TextRenderingMode.FILL;
  11610. this.fillColorSpace = ColorSpace.singletons.gray;
  11611. this.strokeColorSpace = ColorSpace.singletons.gray;
  11612. }
  11613. EvalState.prototype = {
  11614. clone: function CanvasExtraState_clone() {
  11615. return Object.create(this);
  11616. },
  11617. };
  11618. return EvalState;
  11619. })();
  11620. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  11621. // Specifies properties for each command
  11622. //
  11623. // If variableArgs === true: [0, `numArgs`] expected
  11624. // If variableArgs === false: exactly `numArgs` expected
  11625. var OP_MAP = {
  11626. // Graphic state
  11627. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  11628. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  11629. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  11630. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  11631. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  11632. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  11633. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  11634. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  11635. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  11636. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  11637. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  11638. // Path
  11639. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  11640. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  11641. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  11642. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  11643. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  11644. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  11645. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  11646. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  11647. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  11648. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11649. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  11650. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  11651. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  11652. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  11653. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  11654. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  11655. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  11656. // Clipping
  11657. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  11658. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  11659. // Text
  11660. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  11661. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  11662. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  11663. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  11664. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  11665. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  11666. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  11667. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  11668. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  11669. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  11670. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  11671. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  11672. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  11673. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  11674. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  11675. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  11676. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  11677. variableArgs: false },
  11678. // Type3 fonts
  11679. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  11680. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  11681. // Color
  11682. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  11683. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  11684. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  11685. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  11686. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  11687. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  11688. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  11689. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  11690. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  11691. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  11692. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  11693. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  11694. // Shading
  11695. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  11696. // Images
  11697. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  11698. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  11699. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  11700. // XObjects
  11701. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  11702. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  11703. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  11704. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  11705. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  11706. variableArgs: false },
  11707. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  11708. // Compatibility
  11709. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  11710. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  11711. // (reserved partial commands for the lexer)
  11712. BM: null,
  11713. BD: null,
  11714. 'true': null,
  11715. fa: null,
  11716. fal: null,
  11717. fals: null,
  11718. 'false': null,
  11719. nu: null,
  11720. nul: null,
  11721. 'null': null
  11722. };
  11723. function EvaluatorPreprocessor(stream, xref, stateManager) {
  11724. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  11725. // dictionary
  11726. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  11727. this.stateManager = stateManager;
  11728. this.nonProcessedArgs = [];
  11729. }
  11730. EvaluatorPreprocessor.prototype = {
  11731. get savedStatesDepth() {
  11732. return this.stateManager.stateStack.length;
  11733. },
  11734. // |operation| is an object with two fields:
  11735. //
  11736. // - |fn| is an out param.
  11737. //
  11738. // - |args| is an inout param. On entry, it should have one of two values.
  11739. //
  11740. // - An empty array. This indicates that the caller is providing the
  11741. // array in which the args will be stored in. The caller should use
  11742. // this value if it can reuse a single array for each call to read().
  11743. //
  11744. // - |null|. This indicates that the caller needs this function to create
  11745. // the array in which any args are stored in. If there are zero args,
  11746. // this function will leave |operation.args| as |null| (thus avoiding
  11747. // allocations that would occur if we used an empty array to represent
  11748. // zero arguments). Otherwise, it will replace |null| with a new array
  11749. // containing the arguments. The caller should use this value if it
  11750. // cannot reuse an array for each call to read().
  11751. //
  11752. // These two modes are present because this function is very hot and so
  11753. // avoiding allocations where possible is worthwhile.
  11754. //
  11755. read: function EvaluatorPreprocessor_read(operation) {
  11756. var args = operation.args;
  11757. while (true) {
  11758. var obj = this.parser.getObj();
  11759. if (isCmd(obj)) {
  11760. var cmd = obj.cmd;
  11761. // Check that the command is valid
  11762. var opSpec = OP_MAP[cmd];
  11763. if (!opSpec) {
  11764. warn('Unknown command "' + cmd + '"');
  11765. continue;
  11766. }
  11767. var fn = opSpec.id;
  11768. var numArgs = opSpec.numArgs;
  11769. var argsLength = args !== null ? args.length : 0;
  11770. if (!opSpec.variableArgs) {
  11771. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  11772. if (argsLength !== numArgs) {
  11773. var nonProcessedArgs = this.nonProcessedArgs;
  11774. while (argsLength > numArgs) {
  11775. nonProcessedArgs.push(args.shift());
  11776. argsLength--;
  11777. }
  11778. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  11779. if (!args) {
  11780. args = [];
  11781. }
  11782. args.unshift(nonProcessedArgs.pop());
  11783. argsLength++;
  11784. }
  11785. }
  11786. if (argsLength < numArgs) {
  11787. // If we receive too few args, it's not possible to possible
  11788. // to execute the command, so skip the command
  11789. info('Command ' + fn + ': because expected ' +
  11790. numArgs + ' args, but received ' + argsLength +
  11791. ' args; skipping');
  11792. args = null;
  11793. continue;
  11794. }
  11795. } else if (argsLength > numArgs) {
  11796. info('Command ' + fn + ': expected [0,' + numArgs +
  11797. '] args, but received ' + argsLength + ' args');
  11798. }
  11799. // TODO figure out how to type-check vararg functions
  11800. this.preprocessCommand(fn, args);
  11801. operation.fn = fn;
  11802. operation.args = args;
  11803. return true;
  11804. } else {
  11805. if (isEOF(obj)) {
  11806. return false; // no more commands
  11807. }
  11808. // argument
  11809. if (obj !== null) {
  11810. if (!args) {
  11811. args = [];
  11812. }
  11813. args.push((obj instanceof Dict ? obj.getAll() : obj));
  11814. assert(args.length <= 33, 'Too many arguments');
  11815. }
  11816. }
  11817. }
  11818. },
  11819. preprocessCommand:
  11820. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  11821. switch (fn | 0) {
  11822. case OPS.save:
  11823. this.stateManager.save();
  11824. break;
  11825. case OPS.restore:
  11826. this.stateManager.restore();
  11827. break;
  11828. case OPS.transform:
  11829. this.stateManager.transform(args);
  11830. break;
  11831. }
  11832. }
  11833. };
  11834. return EvaluatorPreprocessor;
  11835. })();
  11836. var QueueOptimizer = (function QueueOptimizerClosure() {
  11837. function addState(parentState, pattern, fn) {
  11838. var state = parentState;
  11839. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  11840. var item = pattern[i];
  11841. state = (state[item] || (state[item] = []));
  11842. }
  11843. state[pattern[pattern.length - 1]] = fn;
  11844. }
  11845. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11846. argsArray) {
  11847. // Handles special case of mainly LaTeX documents which use image masks to
  11848. // draw lines with the current fill style.
  11849. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  11850. // have been found at iFirstSave.
  11851. var iFirstPIMXO = iFirstSave + 2;
  11852. for (var i = 0; i < count; i++) {
  11853. var arg = argsArray[iFirstPIMXO + 4 * i];
  11854. var imageMask = arg.length === 1 && arg[0];
  11855. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  11856. (!imageMask.data.length ||
  11857. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  11858. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  11859. continue;
  11860. }
  11861. break;
  11862. }
  11863. return count - i;
  11864. }
  11865. var InitialState = [];
  11866. // This replaces (save, transform, paintInlineImageXObject, restore)+
  11867. // sequences with one |paintInlineImageXObjectGroup| operation.
  11868. addState(InitialState,
  11869. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  11870. function foundInlineImageGroup(context) {
  11871. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  11872. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  11873. var MAX_WIDTH = 1000;
  11874. var IMAGE_PADDING = 1;
  11875. var fnArray = context.fnArray, argsArray = context.argsArray;
  11876. var curr = context.iCurr;
  11877. var iFirstSave = curr - 3;
  11878. var iFirstTransform = curr - 2;
  11879. var iFirstPIIXO = curr - 1;
  11880. // Look for the quartets.
  11881. var i = iFirstSave + 4;
  11882. var ii = fnArray.length;
  11883. while (i + 3 < ii) {
  11884. if (fnArray[i] !== OPS.save ||
  11885. fnArray[i + 1] !== OPS.transform ||
  11886. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  11887. fnArray[i + 3] !== OPS.restore) {
  11888. break; // ops don't match
  11889. }
  11890. i += 4;
  11891. }
  11892. // At this point, i is the index of the first op past the last valid
  11893. // quartet.
  11894. var count = Math.min((i - iFirstSave) / 4,
  11895. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  11896. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  11897. return i;
  11898. }
  11899. // assuming that heights of those image is too small (~1 pixel)
  11900. // packing as much as possible by lines
  11901. var maxX = 0;
  11902. var map = [], maxLineHeight = 0;
  11903. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  11904. var q;
  11905. for (q = 0; q < count; q++) {
  11906. var transform = argsArray[iFirstTransform + (q << 2)];
  11907. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  11908. if (currentX + img.width > MAX_WIDTH) {
  11909. // starting new line
  11910. maxX = Math.max(maxX, currentX);
  11911. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  11912. currentX = 0;
  11913. maxLineHeight = 0;
  11914. }
  11915. map.push({
  11916. transform: transform,
  11917. x: currentX, y: currentY,
  11918. w: img.width, h: img.height
  11919. });
  11920. currentX += img.width + 2 * IMAGE_PADDING;
  11921. maxLineHeight = Math.max(maxLineHeight, img.height);
  11922. }
  11923. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  11924. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  11925. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  11926. var imgRowSize = imgWidth << 2;
  11927. for (q = 0; q < count; q++) {
  11928. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  11929. // Copy image by lines and extends pixels into padding.
  11930. var rowSize = map[q].w << 2;
  11931. var dataOffset = 0;
  11932. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  11933. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  11934. for (var k = 0, kk = map[q].h; k < kk; k++) {
  11935. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  11936. dataOffset += rowSize;
  11937. offset += imgRowSize;
  11938. }
  11939. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  11940. while (offset >= 0) {
  11941. data[offset - 4] = data[offset];
  11942. data[offset - 3] = data[offset + 1];
  11943. data[offset - 2] = data[offset + 2];
  11944. data[offset - 1] = data[offset + 3];
  11945. data[offset + rowSize] = data[offset + rowSize - 4];
  11946. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  11947. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  11948. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  11949. offset -= imgRowSize;
  11950. }
  11951. }
  11952. // Replace queue items.
  11953. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  11954. argsArray.splice(iFirstSave, count * 4,
  11955. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  11956. data: imgData }, map]);
  11957. return iFirstSave + 1;
  11958. });
  11959. // This replaces (save, transform, paintImageMaskXObject, restore)+
  11960. // sequences with one |paintImageMaskXObjectGroup| or one
  11961. // |paintImageMaskXObjectRepeat| operation.
  11962. addState(InitialState,
  11963. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  11964. function foundImageMaskGroup(context) {
  11965. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  11966. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  11967. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  11968. var fnArray = context.fnArray, argsArray = context.argsArray;
  11969. var curr = context.iCurr;
  11970. var iFirstSave = curr - 3;
  11971. var iFirstTransform = curr - 2;
  11972. var iFirstPIMXO = curr - 1;
  11973. // Look for the quartets.
  11974. var i = iFirstSave + 4;
  11975. var ii = fnArray.length;
  11976. while (i + 3 < ii) {
  11977. if (fnArray[i] !== OPS.save ||
  11978. fnArray[i + 1] !== OPS.transform ||
  11979. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  11980. fnArray[i + 3] !== OPS.restore) {
  11981. break; // ops don't match
  11982. }
  11983. i += 4;
  11984. }
  11985. // At this point, i is the index of the first op past the last valid
  11986. // quartet.
  11987. var count = (i - iFirstSave) / 4;
  11988. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  11989. argsArray);
  11990. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  11991. return i;
  11992. }
  11993. var q;
  11994. var isSameImage = false;
  11995. var iTransform, transformArgs;
  11996. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  11997. if (argsArray[iFirstTransform][1] === 0 &&
  11998. argsArray[iFirstTransform][2] === 0) {
  11999. isSameImage = true;
  12000. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12001. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12002. iTransform = iFirstTransform + 4;
  12003. var iPIMXO = iFirstPIMXO + 4;
  12004. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  12005. transformArgs = argsArray[iTransform];
  12006. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  12007. transformArgs[0] !== firstTransformArg0 ||
  12008. transformArgs[1] !== 0 ||
  12009. transformArgs[2] !== 0 ||
  12010. transformArgs[3] !== firstTransformArg3) {
  12011. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  12012. isSameImage = false;
  12013. } else {
  12014. count = q;
  12015. }
  12016. break; // different image or transform
  12017. }
  12018. }
  12019. }
  12020. if (isSameImage) {
  12021. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  12022. var positions = new Float32Array(count * 2);
  12023. iTransform = iFirstTransform;
  12024. for (q = 0; q < count; q++, iTransform += 4) {
  12025. transformArgs = argsArray[iTransform];
  12026. positions[(q << 1)] = transformArgs[4];
  12027. positions[(q << 1) + 1] = transformArgs[5];
  12028. }
  12029. // Replace queue items.
  12030. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  12031. argsArray.splice(iFirstSave, count * 4,
  12032. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  12033. } else {
  12034. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  12035. var images = [];
  12036. for (q = 0; q < count; q++) {
  12037. transformArgs = argsArray[iFirstTransform + (q << 2)];
  12038. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  12039. images.push({ data: maskParams.data, width: maskParams.width,
  12040. height: maskParams.height,
  12041. transform: transformArgs });
  12042. }
  12043. // Replace queue items.
  12044. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  12045. argsArray.splice(iFirstSave, count * 4, [images]);
  12046. }
  12047. return iFirstSave + 1;
  12048. });
  12049. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  12050. // with one paintImageXObjectRepeat operation, if the |transform| and
  12051. // |paintImageXObjectRepeat| ops are appropriate.
  12052. addState(InitialState,
  12053. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  12054. function (context) {
  12055. var MIN_IMAGES_IN_BLOCK = 3;
  12056. var MAX_IMAGES_IN_BLOCK = 1000;
  12057. var fnArray = context.fnArray, argsArray = context.argsArray;
  12058. var curr = context.iCurr;
  12059. var iFirstSave = curr - 3;
  12060. var iFirstTransform = curr - 2;
  12061. var iFirstPIXO = curr - 1;
  12062. var iFirstRestore = curr;
  12063. if (argsArray[iFirstTransform][1] !== 0 ||
  12064. argsArray[iFirstTransform][2] !== 0) {
  12065. return iFirstRestore + 1; // transform has the wrong form
  12066. }
  12067. // Look for the quartets.
  12068. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  12069. var firstTransformArg0 = argsArray[iFirstTransform][0];
  12070. var firstTransformArg3 = argsArray[iFirstTransform][3];
  12071. var i = iFirstSave + 4;
  12072. var ii = fnArray.length;
  12073. while (i + 3 < ii) {
  12074. if (fnArray[i] !== OPS.save ||
  12075. fnArray[i + 1] !== OPS.transform ||
  12076. fnArray[i + 2] !== OPS.paintImageXObject ||
  12077. fnArray[i + 3] !== OPS.restore) {
  12078. break; // ops don't match
  12079. }
  12080. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  12081. argsArray[i + 1][1] !== 0 ||
  12082. argsArray[i + 1][2] !== 0 ||
  12083. argsArray[i + 1][3] !== firstTransformArg3) {
  12084. break; // transforms don't match
  12085. }
  12086. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  12087. break; // images don't match
  12088. }
  12089. i += 4;
  12090. }
  12091. // At this point, i is the index of the first op past the last valid
  12092. // quartet.
  12093. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  12094. if (count < MIN_IMAGES_IN_BLOCK) {
  12095. return i;
  12096. }
  12097. // Extract the (x,y) positions from all of the matching transforms.
  12098. var positions = new Float32Array(count * 2);
  12099. var iTransform = iFirstTransform;
  12100. for (var q = 0; q < count; q++, iTransform += 4) {
  12101. var transformArgs = argsArray[iTransform];
  12102. positions[(q << 1)] = transformArgs[4];
  12103. positions[(q << 1) + 1] = transformArgs[5];
  12104. }
  12105. // Replace queue items.
  12106. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  12107. positions];
  12108. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  12109. argsArray.splice(iFirstSave, count * 4, args);
  12110. return iFirstSave + 1;
  12111. });
  12112. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  12113. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  12114. // sequences, if the font for each one is the same.
  12115. addState(InitialState,
  12116. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  12117. function (context) {
  12118. var MIN_CHARS_IN_BLOCK = 3;
  12119. var MAX_CHARS_IN_BLOCK = 1000;
  12120. var fnArray = context.fnArray, argsArray = context.argsArray;
  12121. var curr = context.iCurr;
  12122. var iFirstBeginText = curr - 4;
  12123. var iFirstSetFont = curr - 3;
  12124. var iFirstSetTextMatrix = curr - 2;
  12125. var iFirstShowText = curr - 1;
  12126. var iFirstEndText = curr;
  12127. // Look for the quintets.
  12128. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  12129. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  12130. var i = iFirstBeginText + 5;
  12131. var ii = fnArray.length;
  12132. while (i + 4 < ii) {
  12133. if (fnArray[i] !== OPS.beginText ||
  12134. fnArray[i + 1] !== OPS.setFont ||
  12135. fnArray[i + 2] !== OPS.setTextMatrix ||
  12136. fnArray[i + 3] !== OPS.showText ||
  12137. fnArray[i + 4] !== OPS.endText) {
  12138. break; // ops don't match
  12139. }
  12140. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  12141. argsArray[i + 1][1] !== firstSetFontArg1) {
  12142. break; // fonts don't match
  12143. }
  12144. i += 5;
  12145. }
  12146. // At this point, i is the index of the first op past the last valid
  12147. // quintet.
  12148. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  12149. if (count < MIN_CHARS_IN_BLOCK) {
  12150. return i;
  12151. }
  12152. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  12153. // showText, endText), include that as well. (E.g. <something> might be
  12154. // |dependency|.)
  12155. var iFirst = iFirstBeginText;
  12156. if (iFirstBeginText >= 4 &&
  12157. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  12158. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  12159. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  12160. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  12161. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  12162. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  12163. count++;
  12164. iFirst -= 5;
  12165. }
  12166. // Remove (endText, beginText, setFont) trios.
  12167. var iEndText = iFirst + 4;
  12168. for (var q = 1; q < count; q++) {
  12169. fnArray.splice(iEndText, 3);
  12170. argsArray.splice(iEndText, 3);
  12171. iEndText += 2;
  12172. }
  12173. return iEndText + 1;
  12174. });
  12175. function QueueOptimizer() {}
  12176. QueueOptimizer.prototype = {
  12177. optimize: function QueueOptimizer_optimize(queue) {
  12178. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  12179. var context = {
  12180. iCurr: 0,
  12181. fnArray: fnArray,
  12182. argsArray: argsArray
  12183. };
  12184. var state;
  12185. var i = 0, ii = fnArray.length;
  12186. while (i < ii) {
  12187. state = (state || InitialState)[fnArray[i]];
  12188. if (typeof state === 'function') { // we found some handler
  12189. context.iCurr = i;
  12190. // state() returns the index of the first non-matching op (if we
  12191. // didn't match) or the first op past the modified ops (if we did
  12192. // match and replace).
  12193. i = state(context);
  12194. state = undefined; // reset the state machine
  12195. ii = context.fnArray.length;
  12196. } else {
  12197. i++;
  12198. }
  12199. }
  12200. }
  12201. };
  12202. return QueueOptimizer;
  12203. })();
  12204. var BUILT_IN_CMAPS = [
  12205. // << Start unicode maps.
  12206. 'Adobe-GB1-UCS2',
  12207. 'Adobe-CNS1-UCS2',
  12208. 'Adobe-Japan1-UCS2',
  12209. 'Adobe-Korea1-UCS2',
  12210. // >> End unicode maps.
  12211. '78-EUC-H',
  12212. '78-EUC-V',
  12213. '78-H',
  12214. '78-RKSJ-H',
  12215. '78-RKSJ-V',
  12216. '78-V',
  12217. '78ms-RKSJ-H',
  12218. '78ms-RKSJ-V',
  12219. '83pv-RKSJ-H',
  12220. '90ms-RKSJ-H',
  12221. '90ms-RKSJ-V',
  12222. '90msp-RKSJ-H',
  12223. '90msp-RKSJ-V',
  12224. '90pv-RKSJ-H',
  12225. '90pv-RKSJ-V',
  12226. 'Add-H',
  12227. 'Add-RKSJ-H',
  12228. 'Add-RKSJ-V',
  12229. 'Add-V',
  12230. 'Adobe-CNS1-0',
  12231. 'Adobe-CNS1-1',
  12232. 'Adobe-CNS1-2',
  12233. 'Adobe-CNS1-3',
  12234. 'Adobe-CNS1-4',
  12235. 'Adobe-CNS1-5',
  12236. 'Adobe-CNS1-6',
  12237. 'Adobe-GB1-0',
  12238. 'Adobe-GB1-1',
  12239. 'Adobe-GB1-2',
  12240. 'Adobe-GB1-3',
  12241. 'Adobe-GB1-4',
  12242. 'Adobe-GB1-5',
  12243. 'Adobe-Japan1-0',
  12244. 'Adobe-Japan1-1',
  12245. 'Adobe-Japan1-2',
  12246. 'Adobe-Japan1-3',
  12247. 'Adobe-Japan1-4',
  12248. 'Adobe-Japan1-5',
  12249. 'Adobe-Japan1-6',
  12250. 'Adobe-Korea1-0',
  12251. 'Adobe-Korea1-1',
  12252. 'Adobe-Korea1-2',
  12253. 'B5-H',
  12254. 'B5-V',
  12255. 'B5pc-H',
  12256. 'B5pc-V',
  12257. 'CNS-EUC-H',
  12258. 'CNS-EUC-V',
  12259. 'CNS1-H',
  12260. 'CNS1-V',
  12261. 'CNS2-H',
  12262. 'CNS2-V',
  12263. 'ETHK-B5-H',
  12264. 'ETHK-B5-V',
  12265. 'ETen-B5-H',
  12266. 'ETen-B5-V',
  12267. 'ETenms-B5-H',
  12268. 'ETenms-B5-V',
  12269. 'EUC-H',
  12270. 'EUC-V',
  12271. 'Ext-H',
  12272. 'Ext-RKSJ-H',
  12273. 'Ext-RKSJ-V',
  12274. 'Ext-V',
  12275. 'GB-EUC-H',
  12276. 'GB-EUC-V',
  12277. 'GB-H',
  12278. 'GB-V',
  12279. 'GBK-EUC-H',
  12280. 'GBK-EUC-V',
  12281. 'GBK2K-H',
  12282. 'GBK2K-V',
  12283. 'GBKp-EUC-H',
  12284. 'GBKp-EUC-V',
  12285. 'GBT-EUC-H',
  12286. 'GBT-EUC-V',
  12287. 'GBT-H',
  12288. 'GBT-V',
  12289. 'GBTpc-EUC-H',
  12290. 'GBTpc-EUC-V',
  12291. 'GBpc-EUC-H',
  12292. 'GBpc-EUC-V',
  12293. 'H',
  12294. 'HKdla-B5-H',
  12295. 'HKdla-B5-V',
  12296. 'HKdlb-B5-H',
  12297. 'HKdlb-B5-V',
  12298. 'HKgccs-B5-H',
  12299. 'HKgccs-B5-V',
  12300. 'HKm314-B5-H',
  12301. 'HKm314-B5-V',
  12302. 'HKm471-B5-H',
  12303. 'HKm471-B5-V',
  12304. 'HKscs-B5-H',
  12305. 'HKscs-B5-V',
  12306. 'Hankaku',
  12307. 'Hiragana',
  12308. 'KSC-EUC-H',
  12309. 'KSC-EUC-V',
  12310. 'KSC-H',
  12311. 'KSC-Johab-H',
  12312. 'KSC-Johab-V',
  12313. 'KSC-V',
  12314. 'KSCms-UHC-H',
  12315. 'KSCms-UHC-HW-H',
  12316. 'KSCms-UHC-HW-V',
  12317. 'KSCms-UHC-V',
  12318. 'KSCpc-EUC-H',
  12319. 'KSCpc-EUC-V',
  12320. 'Katakana',
  12321. 'NWP-H',
  12322. 'NWP-V',
  12323. 'RKSJ-H',
  12324. 'RKSJ-V',
  12325. 'Roman',
  12326. 'UniCNS-UCS2-H',
  12327. 'UniCNS-UCS2-V',
  12328. 'UniCNS-UTF16-H',
  12329. 'UniCNS-UTF16-V',
  12330. 'UniCNS-UTF32-H',
  12331. 'UniCNS-UTF32-V',
  12332. 'UniCNS-UTF8-H',
  12333. 'UniCNS-UTF8-V',
  12334. 'UniGB-UCS2-H',
  12335. 'UniGB-UCS2-V',
  12336. 'UniGB-UTF16-H',
  12337. 'UniGB-UTF16-V',
  12338. 'UniGB-UTF32-H',
  12339. 'UniGB-UTF32-V',
  12340. 'UniGB-UTF8-H',
  12341. 'UniGB-UTF8-V',
  12342. 'UniJIS-UCS2-H',
  12343. 'UniJIS-UCS2-HW-H',
  12344. 'UniJIS-UCS2-HW-V',
  12345. 'UniJIS-UCS2-V',
  12346. 'UniJIS-UTF16-H',
  12347. 'UniJIS-UTF16-V',
  12348. 'UniJIS-UTF32-H',
  12349. 'UniJIS-UTF32-V',
  12350. 'UniJIS-UTF8-H',
  12351. 'UniJIS-UTF8-V',
  12352. 'UniJIS2004-UTF16-H',
  12353. 'UniJIS2004-UTF16-V',
  12354. 'UniJIS2004-UTF32-H',
  12355. 'UniJIS2004-UTF32-V',
  12356. 'UniJIS2004-UTF8-H',
  12357. 'UniJIS2004-UTF8-V',
  12358. 'UniJISPro-UCS2-HW-V',
  12359. 'UniJISPro-UCS2-V',
  12360. 'UniJISPro-UTF8-V',
  12361. 'UniJISX0213-UTF32-H',
  12362. 'UniJISX0213-UTF32-V',
  12363. 'UniJISX02132004-UTF32-H',
  12364. 'UniJISX02132004-UTF32-V',
  12365. 'UniKS-UCS2-H',
  12366. 'UniKS-UCS2-V',
  12367. 'UniKS-UTF16-H',
  12368. 'UniKS-UTF16-V',
  12369. 'UniKS-UTF32-H',
  12370. 'UniKS-UTF32-V',
  12371. 'UniKS-UTF8-H',
  12372. 'UniKS-UTF8-V',
  12373. 'V',
  12374. 'WP-Symbol'];
  12375. // CMap, not to be confused with TrueType's cmap.
  12376. var CMap = (function CMapClosure() {
  12377. function CMap(builtInCMap) {
  12378. // Codespace ranges are stored as follows:
  12379. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  12380. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  12381. this.codespaceRanges = [[], [], [], []];
  12382. this.numCodespaceRanges = 0;
  12383. // Map entries have one of two forms.
  12384. // - cid chars are 16-bit unsigned integers, stored as integers.
  12385. // - bf chars are variable-length byte sequences, stored as strings, with
  12386. // one byte per character.
  12387. this._map = [];
  12388. this.name = '';
  12389. this.vertical = false;
  12390. this.useCMap = null;
  12391. this.builtInCMap = builtInCMap;
  12392. }
  12393. CMap.prototype = {
  12394. addCodespaceRange: function(n, low, high) {
  12395. this.codespaceRanges[n - 1].push(low, high);
  12396. this.numCodespaceRanges++;
  12397. },
  12398. mapCidRange: function(low, high, dstLow) {
  12399. while (low <= high) {
  12400. this._map[low++] = dstLow++;
  12401. }
  12402. },
  12403. mapBfRange: function(low, high, dstLow) {
  12404. var lastByte = dstLow.length - 1;
  12405. while (low <= high) {
  12406. this._map[low++] = dstLow;
  12407. // Only the last byte has to be incremented.
  12408. dstLow = dstLow.substr(0, lastByte) +
  12409. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  12410. }
  12411. },
  12412. mapBfRangeToArray: function(low, high, array) {
  12413. var i = 0, ii = array.length;
  12414. while (low <= high && i < ii) {
  12415. this._map[low] = array[i++];
  12416. ++low;
  12417. }
  12418. },
  12419. // This is used for both bf and cid chars.
  12420. mapOne: function(src, dst) {
  12421. this._map[src] = dst;
  12422. },
  12423. lookup: function(code) {
  12424. return this._map[code];
  12425. },
  12426. contains: function(code) {
  12427. return this._map[code] !== undefined;
  12428. },
  12429. forEach: function(callback) {
  12430. // Most maps have fewer than 65536 entries, and for those we use normal
  12431. // array iteration. But really sparse tables are possible -- e.g. with
  12432. // indices in the *billions*. For such tables we use for..in, which isn't
  12433. // ideal because it stringifies the indices for all present elements, but
  12434. // it does avoid iterating over every undefined entry.
  12435. var map = this._map;
  12436. var length = map.length;
  12437. var i;
  12438. if (length <= 0x10000) {
  12439. for (i = 0; i < length; i++) {
  12440. if (map[i] !== undefined) {
  12441. callback(i, map[i]);
  12442. }
  12443. }
  12444. } else {
  12445. for (i in this._map) {
  12446. callback(i, map[i]);
  12447. }
  12448. }
  12449. },
  12450. charCodeOf: function(value) {
  12451. return this._map.indexOf(value);
  12452. },
  12453. getMap: function() {
  12454. return this._map;
  12455. },
  12456. readCharCode: function(str, offset, out) {
  12457. var c = 0;
  12458. var codespaceRanges = this.codespaceRanges;
  12459. var codespaceRangesLen = this.codespaceRanges.length;
  12460. // 9.7.6.2 CMap Mapping
  12461. // The code length is at most 4.
  12462. for (var n = 0; n < codespaceRangesLen; n++) {
  12463. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  12464. // Check each codespace range to see if it falls within.
  12465. var codespaceRange = codespaceRanges[n];
  12466. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  12467. var low = codespaceRange[k++];
  12468. var high = codespaceRange[k++];
  12469. if (c >= low && c <= high) {
  12470. out.charcode = c;
  12471. out.length = n + 1;
  12472. return;
  12473. }
  12474. }
  12475. }
  12476. out.charcode = 0;
  12477. out.length = 1;
  12478. },
  12479. get isIdentityCMap() {
  12480. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  12481. return false;
  12482. }
  12483. if (this._map.length !== 0x10000) {
  12484. return false;
  12485. }
  12486. for (var i = 0; i < 0x10000; i++) {
  12487. if (this._map[i] !== i) {
  12488. return false;
  12489. }
  12490. }
  12491. return true;
  12492. }
  12493. };
  12494. return CMap;
  12495. })();
  12496. // A special case of CMap, where the _map array implicitly has a length of
  12497. // 65536 and each element is equal to its index.
  12498. var IdentityCMap = (function IdentityCMapClosure() {
  12499. function IdentityCMap(vertical, n) {
  12500. CMap.call(this);
  12501. this.vertical = vertical;
  12502. this.addCodespaceRange(n, 0, 0xffff);
  12503. }
  12504. Util.inherit(IdentityCMap, CMap, {});
  12505. IdentityCMap.prototype = {
  12506. addCodespaceRange: CMap.prototype.addCodespaceRange,
  12507. mapCidRange: function(low, high, dstLow) {
  12508. error('should not call mapCidRange');
  12509. },
  12510. mapBfRange: function(low, high, dstLow) {
  12511. error('should not call mapBfRange');
  12512. },
  12513. mapBfRangeToArray: function(low, high, array) {
  12514. error('should not call mapBfRangeToArray');
  12515. },
  12516. mapOne: function(src, dst) {
  12517. error('should not call mapCidOne');
  12518. },
  12519. lookup: function(code) {
  12520. return (isInt(code) && code <= 0xffff) ? code : undefined;
  12521. },
  12522. contains: function(code) {
  12523. return isInt(code) && code <= 0xffff;
  12524. },
  12525. forEach: function(callback) {
  12526. for (var i = 0; i <= 0xffff; i++) {
  12527. callback(i, i);
  12528. }
  12529. },
  12530. charCodeOf: function(value) {
  12531. return (isInt(value) && value <= 0xffff) ? value : -1;
  12532. },
  12533. getMap: function() {
  12534. // Sometimes identity maps must be instantiated, but it's rare.
  12535. var map = new Array(0x10000);
  12536. for (var i = 0; i <= 0xffff; i++) {
  12537. map[i] = i;
  12538. }
  12539. return map;
  12540. },
  12541. readCharCode: CMap.prototype.readCharCode,
  12542. get isIdentityCMap() {
  12543. error('should not access .isIdentityCMap');
  12544. }
  12545. };
  12546. return IdentityCMap;
  12547. })();
  12548. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  12549. function fetchBinaryData(url) {
  12550. var nonBinaryRequest = PDFJS.disableWorker;
  12551. var request = new XMLHttpRequest();
  12552. request.open('GET', url, false);
  12553. if (!nonBinaryRequest) {
  12554. try {
  12555. request.responseType = 'arraybuffer';
  12556. nonBinaryRequest = request.responseType !== 'arraybuffer';
  12557. } catch (e) {
  12558. nonBinaryRequest = true;
  12559. }
  12560. }
  12561. if (nonBinaryRequest && request.overrideMimeType) {
  12562. request.overrideMimeType('text/plain; charset=x-user-defined');
  12563. }
  12564. request.send(null);
  12565. if (nonBinaryRequest ? !request.responseText : !request.response) {
  12566. error('Unable to get binary cMap at: ' + url);
  12567. }
  12568. if (nonBinaryRequest) {
  12569. var data = Array.prototype.map.call(request.responseText, function (ch) {
  12570. return ch.charCodeAt(0) & 255;
  12571. });
  12572. return new Uint8Array(data);
  12573. }
  12574. return new Uint8Array(request.response);
  12575. }
  12576. function hexToInt(a, size) {
  12577. var n = 0;
  12578. for (var i = 0; i <= size; i++) {
  12579. n = (n << 8) | a[i];
  12580. }
  12581. return n >>> 0;
  12582. }
  12583. function hexToStr(a, size) {
  12584. // This code is hot. Special-case some common values to avoid creating an
  12585. // object with subarray().
  12586. if (size === 1) {
  12587. return String.fromCharCode(a[0], a[1]);
  12588. }
  12589. if (size === 3) {
  12590. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  12591. }
  12592. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  12593. }
  12594. function addHex(a, b, size) {
  12595. var c = 0;
  12596. for (var i = size; i >= 0; i--) {
  12597. c += a[i] + b[i];
  12598. a[i] = c & 255;
  12599. c >>= 8;
  12600. }
  12601. }
  12602. function incHex(a, size) {
  12603. var c = 1;
  12604. for (var i = size; i >= 0 && c > 0; i--) {
  12605. c += a[i];
  12606. a[i] = c & 255;
  12607. c >>= 8;
  12608. }
  12609. }
  12610. var MAX_NUM_SIZE = 16;
  12611. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  12612. function BinaryCMapStream(data) {
  12613. this.buffer = data;
  12614. this.pos = 0;
  12615. this.end = data.length;
  12616. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  12617. }
  12618. BinaryCMapStream.prototype = {
  12619. readByte: function () {
  12620. if (this.pos >= this.end) {
  12621. return -1;
  12622. }
  12623. return this.buffer[this.pos++];
  12624. },
  12625. readNumber: function () {
  12626. var n = 0;
  12627. var last;
  12628. do {
  12629. var b = this.readByte();
  12630. if (b < 0) {
  12631. error('unexpected EOF in bcmap');
  12632. }
  12633. last = !(b & 0x80);
  12634. n = (n << 7) | (b & 0x7F);
  12635. } while (!last);
  12636. return n;
  12637. },
  12638. readSigned: function () {
  12639. var n = this.readNumber();
  12640. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  12641. },
  12642. readHex: function (num, size) {
  12643. num.set(this.buffer.subarray(this.pos,
  12644. this.pos + size + 1));
  12645. this.pos += size + 1;
  12646. },
  12647. readHexNumber: function (num, size) {
  12648. var last;
  12649. var stack = this.tmpBuf, sp = 0;
  12650. do {
  12651. var b = this.readByte();
  12652. if (b < 0) {
  12653. error('unexpected EOF in bcmap');
  12654. }
  12655. last = !(b & 0x80);
  12656. stack[sp++] = b & 0x7F;
  12657. } while (!last);
  12658. var i = size, buffer = 0, bufferSize = 0;
  12659. while (i >= 0) {
  12660. while (bufferSize < 8 && stack.length > 0) {
  12661. buffer = (stack[--sp] << bufferSize) | buffer;
  12662. bufferSize += 7;
  12663. }
  12664. num[i] = buffer & 255;
  12665. i--;
  12666. buffer >>= 8;
  12667. bufferSize -= 8;
  12668. }
  12669. },
  12670. readHexSigned: function (num, size) {
  12671. this.readHexNumber(num, size);
  12672. var sign = num[size] & 1 ? 255 : 0;
  12673. var c = 0;
  12674. for (var i = 0; i <= size; i++) {
  12675. c = ((c & 1) << 8) | num[i];
  12676. num[i] = (c >> 1) ^ sign;
  12677. }
  12678. },
  12679. readString: function () {
  12680. var len = this.readNumber();
  12681. var s = '';
  12682. for (var i = 0; i < len; i++) {
  12683. s += String.fromCharCode(this.readNumber());
  12684. }
  12685. return s;
  12686. }
  12687. };
  12688. function processBinaryCMap(url, cMap, extend) {
  12689. var data = fetchBinaryData(url);
  12690. var stream = new BinaryCMapStream(data);
  12691. var header = stream.readByte();
  12692. cMap.vertical = !!(header & 1);
  12693. var useCMap = null;
  12694. var start = new Uint8Array(MAX_NUM_SIZE);
  12695. var end = new Uint8Array(MAX_NUM_SIZE);
  12696. var char = new Uint8Array(MAX_NUM_SIZE);
  12697. var charCode = new Uint8Array(MAX_NUM_SIZE);
  12698. var tmp = new Uint8Array(MAX_NUM_SIZE);
  12699. var code;
  12700. var b;
  12701. while ((b = stream.readByte()) >= 0) {
  12702. var type = b >> 5;
  12703. if (type === 7) { // metadata, e.g. comment or usecmap
  12704. switch (b & 0x1F) {
  12705. case 0:
  12706. stream.readString(); // skipping comment
  12707. break;
  12708. case 1:
  12709. useCMap = stream.readString();
  12710. break;
  12711. }
  12712. continue;
  12713. }
  12714. var sequence = !!(b & 0x10);
  12715. var dataSize = b & 15;
  12716. assert(dataSize + 1 <= MAX_NUM_SIZE);
  12717. var ucs2DataSize = 1;
  12718. var subitemsCount = stream.readNumber();
  12719. var i;
  12720. switch (type) {
  12721. case 0: // codespacerange
  12722. stream.readHex(start, dataSize);
  12723. stream.readHexNumber(end, dataSize);
  12724. addHex(end, start, dataSize);
  12725. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12726. hexToInt(end, dataSize));
  12727. for (i = 1; i < subitemsCount; i++) {
  12728. incHex(end, dataSize);
  12729. stream.readHexNumber(start, dataSize);
  12730. addHex(start, end, dataSize);
  12731. stream.readHexNumber(end, dataSize);
  12732. addHex(end, start, dataSize);
  12733. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  12734. hexToInt(end, dataSize));
  12735. }
  12736. break;
  12737. case 1: // notdefrange
  12738. stream.readHex(start, dataSize);
  12739. stream.readHexNumber(end, dataSize);
  12740. addHex(end, start, dataSize);
  12741. code = stream.readNumber();
  12742. // undefined range, skipping
  12743. for (i = 1; i < subitemsCount; i++) {
  12744. incHex(end, dataSize);
  12745. stream.readHexNumber(start, dataSize);
  12746. addHex(start, end, dataSize);
  12747. stream.readHexNumber(end, dataSize);
  12748. addHex(end, start, dataSize);
  12749. code = stream.readNumber();
  12750. // nop
  12751. }
  12752. break;
  12753. case 2: // cidchar
  12754. stream.readHex(char, dataSize);
  12755. code = stream.readNumber();
  12756. cMap.mapOne(hexToInt(char, dataSize), code);
  12757. for (i = 1; i < subitemsCount; i++) {
  12758. incHex(char, dataSize);
  12759. if (!sequence) {
  12760. stream.readHexNumber(tmp, dataSize);
  12761. addHex(char, tmp, dataSize);
  12762. }
  12763. code = stream.readSigned() + (code + 1);
  12764. cMap.mapOne(hexToInt(char, dataSize), code);
  12765. }
  12766. break;
  12767. case 3: // cidrange
  12768. stream.readHex(start, dataSize);
  12769. stream.readHexNumber(end, dataSize);
  12770. addHex(end, start, dataSize);
  12771. code = stream.readNumber();
  12772. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12773. code);
  12774. for (i = 1; i < subitemsCount; i++) {
  12775. incHex(end, dataSize);
  12776. if (!sequence) {
  12777. stream.readHexNumber(start, dataSize);
  12778. addHex(start, end, dataSize);
  12779. } else {
  12780. start.set(end);
  12781. }
  12782. stream.readHexNumber(end, dataSize);
  12783. addHex(end, start, dataSize);
  12784. code = stream.readNumber();
  12785. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  12786. code);
  12787. }
  12788. break;
  12789. case 4: // bfchar
  12790. stream.readHex(char, ucs2DataSize);
  12791. stream.readHex(charCode, dataSize);
  12792. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12793. hexToStr(charCode, dataSize));
  12794. for (i = 1; i < subitemsCount; i++) {
  12795. incHex(char, ucs2DataSize);
  12796. if (!sequence) {
  12797. stream.readHexNumber(tmp, ucs2DataSize);
  12798. addHex(char, tmp, ucs2DataSize);
  12799. }
  12800. incHex(charCode, dataSize);
  12801. stream.readHexSigned(tmp, dataSize);
  12802. addHex(charCode, tmp, dataSize);
  12803. cMap.mapOne(hexToInt(char, ucs2DataSize),
  12804. hexToStr(charCode, dataSize));
  12805. }
  12806. break;
  12807. case 5: // bfrange
  12808. stream.readHex(start, ucs2DataSize);
  12809. stream.readHexNumber(end, ucs2DataSize);
  12810. addHex(end, start, ucs2DataSize);
  12811. stream.readHex(charCode, dataSize);
  12812. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12813. hexToInt(end, ucs2DataSize),
  12814. hexToStr(charCode, dataSize));
  12815. for (i = 1; i < subitemsCount; i++) {
  12816. incHex(end, ucs2DataSize);
  12817. if (!sequence) {
  12818. stream.readHexNumber(start, ucs2DataSize);
  12819. addHex(start, end, ucs2DataSize);
  12820. } else {
  12821. start.set(end);
  12822. }
  12823. stream.readHexNumber(end, ucs2DataSize);
  12824. addHex(end, start, ucs2DataSize);
  12825. stream.readHex(charCode, dataSize);
  12826. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  12827. hexToInt(end, ucs2DataSize),
  12828. hexToStr(charCode, dataSize));
  12829. }
  12830. break;
  12831. default:
  12832. error('Unknown type: ' + type);
  12833. break;
  12834. }
  12835. }
  12836. if (useCMap) {
  12837. extend(useCMap);
  12838. }
  12839. return cMap;
  12840. }
  12841. function BinaryCMapReader() {}
  12842. BinaryCMapReader.prototype = {
  12843. read: processBinaryCMap
  12844. };
  12845. return BinaryCMapReader;
  12846. })();
  12847. var CMapFactory = (function CMapFactoryClosure() {
  12848. function strToInt(str) {
  12849. var a = 0;
  12850. for (var i = 0; i < str.length; i++) {
  12851. a = (a << 8) | str.charCodeAt(i);
  12852. }
  12853. return a >>> 0;
  12854. }
  12855. function expectString(obj) {
  12856. if (!isString(obj)) {
  12857. error('Malformed CMap: expected string.');
  12858. }
  12859. }
  12860. function expectInt(obj) {
  12861. if (!isInt(obj)) {
  12862. error('Malformed CMap: expected int.');
  12863. }
  12864. }
  12865. function parseBfChar(cMap, lexer) {
  12866. while (true) {
  12867. var obj = lexer.getObj();
  12868. if (isEOF(obj)) {
  12869. break;
  12870. }
  12871. if (isCmd(obj, 'endbfchar')) {
  12872. return;
  12873. }
  12874. expectString(obj);
  12875. var src = strToInt(obj);
  12876. obj = lexer.getObj();
  12877. // TODO are /dstName used?
  12878. expectString(obj);
  12879. var dst = obj;
  12880. cMap.mapOne(src, dst);
  12881. }
  12882. }
  12883. function parseBfRange(cMap, lexer) {
  12884. while (true) {
  12885. var obj = lexer.getObj();
  12886. if (isEOF(obj)) {
  12887. break;
  12888. }
  12889. if (isCmd(obj, 'endbfrange')) {
  12890. return;
  12891. }
  12892. expectString(obj);
  12893. var low = strToInt(obj);
  12894. obj = lexer.getObj();
  12895. expectString(obj);
  12896. var high = strToInt(obj);
  12897. obj = lexer.getObj();
  12898. if (isInt(obj) || isString(obj)) {
  12899. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  12900. cMap.mapBfRange(low, high, dstLow);
  12901. } else if (isCmd(obj, '[')) {
  12902. obj = lexer.getObj();
  12903. var array = [];
  12904. while (!isCmd(obj, ']') && !isEOF(obj)) {
  12905. array.push(obj);
  12906. obj = lexer.getObj();
  12907. }
  12908. cMap.mapBfRangeToArray(low, high, array);
  12909. } else {
  12910. break;
  12911. }
  12912. }
  12913. error('Invalid bf range.');
  12914. }
  12915. function parseCidChar(cMap, lexer) {
  12916. while (true) {
  12917. var obj = lexer.getObj();
  12918. if (isEOF(obj)) {
  12919. break;
  12920. }
  12921. if (isCmd(obj, 'endcidchar')) {
  12922. return;
  12923. }
  12924. expectString(obj);
  12925. var src = strToInt(obj);
  12926. obj = lexer.getObj();
  12927. expectInt(obj);
  12928. var dst = obj;
  12929. cMap.mapOne(src, dst);
  12930. }
  12931. }
  12932. function parseCidRange(cMap, lexer) {
  12933. while (true) {
  12934. var obj = lexer.getObj();
  12935. if (isEOF(obj)) {
  12936. break;
  12937. }
  12938. if (isCmd(obj, 'endcidrange')) {
  12939. return;
  12940. }
  12941. expectString(obj);
  12942. var low = strToInt(obj);
  12943. obj = lexer.getObj();
  12944. expectString(obj);
  12945. var high = strToInt(obj);
  12946. obj = lexer.getObj();
  12947. expectInt(obj);
  12948. var dstLow = obj;
  12949. cMap.mapCidRange(low, high, dstLow);
  12950. }
  12951. }
  12952. function parseCodespaceRange(cMap, lexer) {
  12953. while (true) {
  12954. var obj = lexer.getObj();
  12955. if (isEOF(obj)) {
  12956. break;
  12957. }
  12958. if (isCmd(obj, 'endcodespacerange')) {
  12959. return;
  12960. }
  12961. if (!isString(obj)) {
  12962. break;
  12963. }
  12964. var low = strToInt(obj);
  12965. obj = lexer.getObj();
  12966. if (!isString(obj)) {
  12967. break;
  12968. }
  12969. var high = strToInt(obj);
  12970. cMap.addCodespaceRange(obj.length, low, high);
  12971. }
  12972. error('Invalid codespace range.');
  12973. }
  12974. function parseWMode(cMap, lexer) {
  12975. var obj = lexer.getObj();
  12976. if (isInt(obj)) {
  12977. cMap.vertical = !!obj;
  12978. }
  12979. }
  12980. function parseCMapName(cMap, lexer) {
  12981. var obj = lexer.getObj();
  12982. if (isName(obj) && isString(obj.name)) {
  12983. cMap.name = obj.name;
  12984. }
  12985. }
  12986. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  12987. var previous;
  12988. var embededUseCMap;
  12989. objLoop: while (true) {
  12990. var obj = lexer.getObj();
  12991. if (isEOF(obj)) {
  12992. break;
  12993. } else if (isName(obj)) {
  12994. if (obj.name === 'WMode') {
  12995. parseWMode(cMap, lexer);
  12996. } else if (obj.name === 'CMapName') {
  12997. parseCMapName(cMap, lexer);
  12998. }
  12999. previous = obj;
  13000. } else if (isCmd(obj)) {
  13001. switch (obj.cmd) {
  13002. case 'endcmap':
  13003. break objLoop;
  13004. case 'usecmap':
  13005. if (isName(previous)) {
  13006. embededUseCMap = previous.name;
  13007. }
  13008. break;
  13009. case 'begincodespacerange':
  13010. parseCodespaceRange(cMap, lexer);
  13011. break;
  13012. case 'beginbfchar':
  13013. parseBfChar(cMap, lexer);
  13014. break;
  13015. case 'begincidchar':
  13016. parseCidChar(cMap, lexer);
  13017. break;
  13018. case 'beginbfrange':
  13019. parseBfRange(cMap, lexer);
  13020. break;
  13021. case 'begincidrange':
  13022. parseCidRange(cMap, lexer);
  13023. break;
  13024. }
  13025. }
  13026. }
  13027. if (!useCMap && embededUseCMap) {
  13028. // Load the usecmap definition from the file only if there wasn't one
  13029. // specified.
  13030. useCMap = embededUseCMap;
  13031. }
  13032. if (useCMap) {
  13033. extendCMap(cMap, builtInCMapParams, useCMap);
  13034. }
  13035. }
  13036. function extendCMap(cMap, builtInCMapParams, useCMap) {
  13037. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  13038. // If there aren't any code space ranges defined clone all the parent ones
  13039. // into this cMap.
  13040. if (cMap.numCodespaceRanges === 0) {
  13041. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  13042. for (var i = 0; i < useCodespaceRanges.length; i++) {
  13043. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  13044. }
  13045. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  13046. }
  13047. // Merge the map into the current one, making sure not to override
  13048. // any previously defined entries.
  13049. cMap.useCMap.forEach(function(key, value) {
  13050. if (!cMap.contains(key)) {
  13051. cMap.mapOne(key, cMap.useCMap.lookup(key));
  13052. }
  13053. });
  13054. }
  13055. function parseBinaryCMap(name, builtInCMapParams) {
  13056. var url = builtInCMapParams.url + name + '.bcmap';
  13057. var cMap = new CMap(true);
  13058. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  13059. extendCMap(cMap, builtInCMapParams, useCMap);
  13060. });
  13061. return cMap;
  13062. }
  13063. function createBuiltInCMap(name, builtInCMapParams) {
  13064. if (name === 'Identity-H') {
  13065. return new IdentityCMap(false, 2);
  13066. } else if (name === 'Identity-V') {
  13067. return new IdentityCMap(true, 2);
  13068. }
  13069. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  13070. error('Unknown cMap name: ' + name);
  13071. }
  13072. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  13073. if (builtInCMapParams.packed) {
  13074. return parseBinaryCMap(name, builtInCMapParams);
  13075. }
  13076. var request = new XMLHttpRequest();
  13077. var url = builtInCMapParams.url + name;
  13078. request.open('GET', url, false);
  13079. request.send(null);
  13080. if (!request.responseText) {
  13081. error('Unable to get cMap at: ' + url);
  13082. }
  13083. var cMap = new CMap(true);
  13084. var lexer = new Lexer(new StringStream(request.responseText));
  13085. parseCMap(cMap, lexer, builtInCMapParams, null);
  13086. return cMap;
  13087. }
  13088. return {
  13089. create: function (encoding, builtInCMapParams, useCMap) {
  13090. if (isName(encoding)) {
  13091. return createBuiltInCMap(encoding.name, builtInCMapParams);
  13092. } else if (isStream(encoding)) {
  13093. var cMap = new CMap();
  13094. var lexer = new Lexer(encoding);
  13095. try {
  13096. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  13097. } catch (e) {
  13098. warn('Invalid CMap data. ' + e);
  13099. }
  13100. if (cMap.isIdentityCMap) {
  13101. return createBuiltInCMap(cMap.name, builtInCMapParams);
  13102. }
  13103. return cMap;
  13104. }
  13105. error('Encoding required.');
  13106. }
  13107. };
  13108. })();
  13109. // Unicode Private Use Area
  13110. var PRIVATE_USE_OFFSET_START = 0xE000;
  13111. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  13112. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  13113. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  13114. // except for Type 3 fonts
  13115. var PDF_GLYPH_SPACE_UNITS = 1000;
  13116. // Hinting is currently disabled due to unknown problems on windows
  13117. // in tracemonkey and various other pdfs with type1 fonts.
  13118. var HINTING_ENABLED = false;
  13119. // Accented charactars are not displayed properly on windows, using this flag
  13120. // to control analysis of seac charstrings.
  13121. var SEAC_ANALYSIS_ENABLED = false;
  13122. var FontFlags = {
  13123. FixedPitch: 1,
  13124. Serif: 2,
  13125. Symbolic: 4,
  13126. Script: 8,
  13127. Nonsymbolic: 32,
  13128. Italic: 64,
  13129. AllCap: 65536,
  13130. SmallCap: 131072,
  13131. ForceBold: 262144
  13132. };
  13133. var Encodings = {
  13134. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13135. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13136. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  13137. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  13138. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  13139. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  13140. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  13141. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  13142. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  13143. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  13144. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  13145. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  13146. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  13147. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  13148. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  13149. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  13150. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  13151. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  13152. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  13153. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13154. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  13155. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  13156. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  13157. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  13158. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  13159. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  13160. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  13161. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  13162. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  13163. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  13164. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  13165. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  13166. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  13167. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  13168. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  13169. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  13170. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  13171. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  13172. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  13173. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  13174. 'Ydieresissmall'],
  13175. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13176. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13177. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  13178. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  13179. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  13180. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  13181. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  13182. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  13183. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  13184. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  13185. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  13186. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  13187. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  13188. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  13189. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  13190. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  13191. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  13192. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  13193. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  13194. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  13195. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  13196. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  13197. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  13198. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  13199. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  13200. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  13201. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  13202. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  13203. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  13204. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  13205. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  13206. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  13207. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  13208. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  13209. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  13210. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  13211. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  13212. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  13213. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  13214. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  13215. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13216. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13217. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13218. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13219. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13220. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13221. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13222. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13223. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13224. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13225. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13226. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  13227. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  13228. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  13229. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13230. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  13231. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  13232. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  13233. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  13234. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  13235. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  13236. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  13237. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  13238. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  13239. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  13240. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  13241. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  13242. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  13243. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  13244. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  13245. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  13246. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  13247. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  13248. 'ogonek', 'caron'],
  13249. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13250. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13251. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13252. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  13253. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13254. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13255. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13256. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13257. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13258. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  13259. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  13260. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13261. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13262. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  13263. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  13264. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  13265. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  13266. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  13267. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  13268. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  13269. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  13270. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  13271. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  13272. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  13273. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  13274. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13275. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13276. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  13277. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  13278. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  13279. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  13280. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  13281. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  13282. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  13283. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  13284. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  13285. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  13286. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  13287. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  13288. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  13289. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  13290. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  13291. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  13292. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  13293. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  13294. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  13295. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  13296. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  13297. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  13298. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  13299. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  13300. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  13301. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  13302. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  13303. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  13304. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  13305. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  13306. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  13307. 'ydieresis'],
  13308. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13309. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13310. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  13311. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  13312. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  13313. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  13314. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  13315. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  13316. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  13317. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  13318. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  13319. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  13320. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  13321. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  13322. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  13323. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13324. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  13325. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  13326. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  13327. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  13328. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  13329. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  13330. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  13331. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  13332. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  13333. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  13334. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  13335. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  13336. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  13337. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  13338. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  13339. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  13340. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  13341. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  13342. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  13343. 'bracerightbt'],
  13344. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13345. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  13346. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  13347. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  13348. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  13349. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  13350. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  13351. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  13352. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  13353. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  13354. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  13355. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  13356. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  13357. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  13358. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  13359. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  13360. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  13361. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  13362. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  13363. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  13364. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  13365. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  13366. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  13367. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  13368. };
  13369. /**
  13370. * Hold a map of decoded fonts and of the standard fourteen Type1
  13371. * fonts and their acronyms.
  13372. */
  13373. var stdFontMap = {
  13374. 'ArialNarrow': 'Helvetica',
  13375. 'ArialNarrow-Bold': 'Helvetica-Bold',
  13376. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  13377. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  13378. 'ArialBlack': 'Helvetica',
  13379. 'ArialBlack-Bold': 'Helvetica-Bold',
  13380. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  13381. 'ArialBlack-Italic': 'Helvetica-Oblique',
  13382. 'Arial': 'Helvetica',
  13383. 'Arial-Bold': 'Helvetica-Bold',
  13384. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  13385. 'Arial-Italic': 'Helvetica-Oblique',
  13386. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  13387. 'Arial-BoldMT': 'Helvetica-Bold',
  13388. 'Arial-ItalicMT': 'Helvetica-Oblique',
  13389. 'ArialMT': 'Helvetica',
  13390. 'Courier-Bold': 'Courier-Bold',
  13391. 'Courier-BoldItalic': 'Courier-BoldOblique',
  13392. 'Courier-Italic': 'Courier-Oblique',
  13393. 'CourierNew': 'Courier',
  13394. 'CourierNew-Bold': 'Courier-Bold',
  13395. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  13396. 'CourierNew-Italic': 'Courier-Oblique',
  13397. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  13398. 'CourierNewPS-BoldMT': 'Courier-Bold',
  13399. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  13400. 'CourierNewPSMT': 'Courier',
  13401. 'Helvetica': 'Helvetica',
  13402. 'Helvetica-Bold': 'Helvetica-Bold',
  13403. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  13404. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  13405. 'Helvetica-Italic': 'Helvetica-Oblique',
  13406. 'Helvetica-Oblique':'Helvetica-Oblique',
  13407. 'Symbol-Bold': 'Symbol',
  13408. 'Symbol-BoldItalic': 'Symbol',
  13409. 'Symbol-Italic': 'Symbol',
  13410. 'TimesNewRoman': 'Times-Roman',
  13411. 'TimesNewRoman-Bold': 'Times-Bold',
  13412. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  13413. 'TimesNewRoman-Italic': 'Times-Italic',
  13414. 'TimesNewRomanPS': 'Times-Roman',
  13415. 'TimesNewRomanPS-Bold': 'Times-Bold',
  13416. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  13417. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  13418. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  13419. 'TimesNewRomanPS-Italic': 'Times-Italic',
  13420. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  13421. 'TimesNewRomanPSMT': 'Times-Roman',
  13422. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  13423. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  13424. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  13425. };
  13426. /**
  13427. * Holds the map of the non-standard fonts that might be included as a standard
  13428. * fonts without glyph data.
  13429. */
  13430. var nonStdFontMap = {
  13431. 'CenturyGothic': 'Helvetica',
  13432. 'CenturyGothic-Bold': 'Helvetica-Bold',
  13433. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  13434. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  13435. 'ComicSansMS': 'Comic Sans MS',
  13436. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  13437. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  13438. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  13439. 'LucidaConsole': 'Courier',
  13440. 'LucidaConsole-Bold': 'Courier-Bold',
  13441. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  13442. 'LucidaConsole-Italic': 'Courier-Oblique',
  13443. 'MS-Gothic': 'MS Gothic',
  13444. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  13445. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  13446. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  13447. 'MS-Mincho': 'MS Mincho',
  13448. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  13449. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  13450. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  13451. 'MS-PGothic': 'MS PGothic',
  13452. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  13453. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  13454. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  13455. 'MS-PMincho': 'MS PMincho',
  13456. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  13457. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  13458. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  13459. 'Wingdings': 'ZapfDingbats'
  13460. };
  13461. var serifFonts = {
  13462. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  13463. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  13464. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  13465. 'Arno': true, 'Aster': true, 'Aurora': true,
  13466. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  13467. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  13468. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  13469. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  13470. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  13471. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  13472. 'Cartier': true, 'Caslon': true, 'Catull': true,
  13473. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  13474. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  13475. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  13476. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  13477. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  13478. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  13479. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  13480. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  13481. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  13482. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  13483. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  13484. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  13485. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  13486. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  13487. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  13488. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  13489. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  13490. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  13491. 'Miller': true, 'Minion': true, 'Modern': true,
  13492. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  13493. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  13494. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  13495. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  13496. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  13497. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  13498. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  13499. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  13500. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  13501. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  13502. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  13503. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  13504. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  13505. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  13506. };
  13507. var symbolsFonts = {
  13508. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  13509. };
  13510. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  13511. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  13512. // glyphs, but common for some set of the standard fonts.
  13513. var GlyphMapForStandardFonts = {
  13514. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  13515. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  13516. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  13517. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  13518. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  13519. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  13520. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  13521. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  13522. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  13523. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  13524. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  13525. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  13526. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  13527. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  13528. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  13529. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  13530. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  13531. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  13532. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  13533. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  13534. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  13535. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  13536. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  13537. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  13538. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  13539. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  13540. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  13541. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  13542. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  13543. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  13544. '298': 380, '305': 963,
  13545. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  13546. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  13547. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  13548. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  13549. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  13550. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  13551. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  13552. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  13553. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  13554. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  13555. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  13556. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  13557. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  13558. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  13559. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  13560. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  13561. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  13562. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  13563. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  13564. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  13565. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  13566. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  13567. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  13568. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  13569. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  13570. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  13571. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  13572. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  13573. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  13574. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  13575. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  13576. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  13577. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  13578. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  13579. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  13580. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  13581. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  13582. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  13583. };
  13584. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  13585. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  13586. // to the similar equivalents in the normal characters range.
  13587. var SpecialPUASymbols = {
  13588. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  13589. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  13590. '63720': 0x00AE, // registersans (0xF8E8) => registered
  13591. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  13592. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  13593. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  13594. '63729': 0x23A7, // bracelefttp (0xF8F1)
  13595. '63730': 0x23A8, // braceleftmid (0xF8F2)
  13596. '63731': 0x23A9, // braceleftbt (0xF8F3)
  13597. '63740': 0x23AB, // bracerighttp (0xF8FC)
  13598. '63741': 0x23AC, // bracerightmid (0xF8FD)
  13599. '63742': 0x23AD, // bracerightbt (0xF8FE)
  13600. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  13601. '63727': 0x23A2, // bracketleftex (0xF8EF)
  13602. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  13603. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  13604. '63738': 0x23A5, // bracketrightex (0xF8FA)
  13605. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  13606. '63723': 0x239B, // parenlefttp (0xF8EB)
  13607. '63724': 0x239C, // parenleftex (0xF8EC)
  13608. '63725': 0x239D, // parenleftbt (0xF8ED)
  13609. '63734': 0x239E, // parenrighttp (0xF8F6)
  13610. '63735': 0x239F, // parenrightex (0xF8F7)
  13611. '63736': 0x23A0, // parenrightbt (0xF8F8)
  13612. };
  13613. function mapSpecialUnicodeValues(code) {
  13614. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  13615. return 0;
  13616. } else if (code >= 0xF600 && code <= 0xF8FF) {
  13617. return (SpecialPUASymbols[code] || code);
  13618. }
  13619. return code;
  13620. }
  13621. var UnicodeRanges = [
  13622. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  13623. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  13624. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  13625. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  13626. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  13627. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  13628. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  13629. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  13630. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  13631. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  13632. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  13633. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  13634. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  13635. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  13636. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  13637. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  13638. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  13639. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  13640. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  13641. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  13642. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  13643. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  13644. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  13645. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  13646. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  13647. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  13648. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  13649. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  13650. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  13651. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  13652. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  13653. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  13654. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  13655. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  13656. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  13657. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  13658. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  13659. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  13660. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  13661. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  13662. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  13663. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  13664. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  13665. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  13666. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  13667. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  13668. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  13669. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  13670. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  13671. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  13672. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  13673. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  13674. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  13675. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  13676. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  13677. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  13678. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  13679. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  13680. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  13681. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  13682. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  13683. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  13684. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  13685. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  13686. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  13687. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  13688. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  13689. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  13690. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  13691. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  13692. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  13693. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  13694. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  13695. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  13696. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  13697. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  13698. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  13699. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  13700. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  13701. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  13702. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  13703. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  13704. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  13705. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  13706. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  13707. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  13708. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  13709. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  13710. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  13711. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  13712. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  13713. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  13714. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  13715. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  13716. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  13717. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  13718. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  13719. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  13720. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  13721. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  13722. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  13723. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  13724. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  13725. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  13726. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  13727. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  13728. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  13729. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  13730. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  13731. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  13732. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  13733. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  13734. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  13735. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  13736. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  13737. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  13738. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  13739. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  13740. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  13741. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  13742. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  13743. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  13744. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  13745. ];
  13746. var MacStandardGlyphOrdering = [
  13747. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  13748. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  13749. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  13750. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  13751. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  13752. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  13753. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  13754. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  13755. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  13756. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  13757. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  13758. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  13759. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  13760. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  13761. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  13762. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  13763. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  13764. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  13765. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  13766. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  13767. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  13768. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  13769. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  13770. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  13771. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  13772. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  13773. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  13774. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  13775. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  13776. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  13777. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  13778. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  13779. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  13780. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  13781. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  13782. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  13783. function getUnicodeRangeFor(value) {
  13784. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  13785. var range = UnicodeRanges[i];
  13786. if (value >= range.begin && value < range.end) {
  13787. return i;
  13788. }
  13789. }
  13790. return -1;
  13791. }
  13792. function isRTLRangeFor(value) {
  13793. var range = UnicodeRanges[13];
  13794. if (value >= range.begin && value < range.end) {
  13795. return true;
  13796. }
  13797. range = UnicodeRanges[11];
  13798. if (value >= range.begin && value < range.end) {
  13799. return true;
  13800. }
  13801. return false;
  13802. }
  13803. // The normalization table is obtained by filtering the Unicode characters
  13804. // database with <compat> entries.
  13805. var NormalizedUnicodes = {
  13806. '\u00A8': '\u0020\u0308',
  13807. '\u00AF': '\u0020\u0304',
  13808. '\u00B4': '\u0020\u0301',
  13809. '\u00B5': '\u03BC',
  13810. '\u00B8': '\u0020\u0327',
  13811. '\u0132': '\u0049\u004A',
  13812. '\u0133': '\u0069\u006A',
  13813. '\u013F': '\u004C\u00B7',
  13814. '\u0140': '\u006C\u00B7',
  13815. '\u0149': '\u02BC\u006E',
  13816. '\u017F': '\u0073',
  13817. '\u01C4': '\u0044\u017D',
  13818. '\u01C5': '\u0044\u017E',
  13819. '\u01C6': '\u0064\u017E',
  13820. '\u01C7': '\u004C\u004A',
  13821. '\u01C8': '\u004C\u006A',
  13822. '\u01C9': '\u006C\u006A',
  13823. '\u01CA': '\u004E\u004A',
  13824. '\u01CB': '\u004E\u006A',
  13825. '\u01CC': '\u006E\u006A',
  13826. '\u01F1': '\u0044\u005A',
  13827. '\u01F2': '\u0044\u007A',
  13828. '\u01F3': '\u0064\u007A',
  13829. '\u02D8': '\u0020\u0306',
  13830. '\u02D9': '\u0020\u0307',
  13831. '\u02DA': '\u0020\u030A',
  13832. '\u02DB': '\u0020\u0328',
  13833. '\u02DC': '\u0020\u0303',
  13834. '\u02DD': '\u0020\u030B',
  13835. '\u037A': '\u0020\u0345',
  13836. '\u0384': '\u0020\u0301',
  13837. '\u03D0': '\u03B2',
  13838. '\u03D1': '\u03B8',
  13839. '\u03D2': '\u03A5',
  13840. '\u03D5': '\u03C6',
  13841. '\u03D6': '\u03C0',
  13842. '\u03F0': '\u03BA',
  13843. '\u03F1': '\u03C1',
  13844. '\u03F2': '\u03C2',
  13845. '\u03F4': '\u0398',
  13846. '\u03F5': '\u03B5',
  13847. '\u03F9': '\u03A3',
  13848. '\u0587': '\u0565\u0582',
  13849. '\u0675': '\u0627\u0674',
  13850. '\u0676': '\u0648\u0674',
  13851. '\u0677': '\u06C7\u0674',
  13852. '\u0678': '\u064A\u0674',
  13853. '\u0E33': '\u0E4D\u0E32',
  13854. '\u0EB3': '\u0ECD\u0EB2',
  13855. '\u0EDC': '\u0EAB\u0E99',
  13856. '\u0EDD': '\u0EAB\u0EA1',
  13857. '\u0F77': '\u0FB2\u0F81',
  13858. '\u0F79': '\u0FB3\u0F81',
  13859. '\u1E9A': '\u0061\u02BE',
  13860. '\u1FBD': '\u0020\u0313',
  13861. '\u1FBF': '\u0020\u0313',
  13862. '\u1FC0': '\u0020\u0342',
  13863. '\u1FFE': '\u0020\u0314',
  13864. '\u2002': '\u0020',
  13865. '\u2003': '\u0020',
  13866. '\u2004': '\u0020',
  13867. '\u2005': '\u0020',
  13868. '\u2006': '\u0020',
  13869. '\u2008': '\u0020',
  13870. '\u2009': '\u0020',
  13871. '\u200A': '\u0020',
  13872. '\u2017': '\u0020\u0333',
  13873. '\u2024': '\u002E',
  13874. '\u2025': '\u002E\u002E',
  13875. '\u2026': '\u002E\u002E\u002E',
  13876. '\u2033': '\u2032\u2032',
  13877. '\u2034': '\u2032\u2032\u2032',
  13878. '\u2036': '\u2035\u2035',
  13879. '\u2037': '\u2035\u2035\u2035',
  13880. '\u203C': '\u0021\u0021',
  13881. '\u203E': '\u0020\u0305',
  13882. '\u2047': '\u003F\u003F',
  13883. '\u2048': '\u003F\u0021',
  13884. '\u2049': '\u0021\u003F',
  13885. '\u2057': '\u2032\u2032\u2032\u2032',
  13886. '\u205F': '\u0020',
  13887. '\u20A8': '\u0052\u0073',
  13888. '\u2100': '\u0061\u002F\u0063',
  13889. '\u2101': '\u0061\u002F\u0073',
  13890. '\u2103': '\u00B0\u0043',
  13891. '\u2105': '\u0063\u002F\u006F',
  13892. '\u2106': '\u0063\u002F\u0075',
  13893. '\u2107': '\u0190',
  13894. '\u2109': '\u00B0\u0046',
  13895. '\u2116': '\u004E\u006F',
  13896. '\u2121': '\u0054\u0045\u004C',
  13897. '\u2135': '\u05D0',
  13898. '\u2136': '\u05D1',
  13899. '\u2137': '\u05D2',
  13900. '\u2138': '\u05D3',
  13901. '\u213B': '\u0046\u0041\u0058',
  13902. '\u2160': '\u0049',
  13903. '\u2161': '\u0049\u0049',
  13904. '\u2162': '\u0049\u0049\u0049',
  13905. '\u2163': '\u0049\u0056',
  13906. '\u2164': '\u0056',
  13907. '\u2165': '\u0056\u0049',
  13908. '\u2166': '\u0056\u0049\u0049',
  13909. '\u2167': '\u0056\u0049\u0049\u0049',
  13910. '\u2168': '\u0049\u0058',
  13911. '\u2169': '\u0058',
  13912. '\u216A': '\u0058\u0049',
  13913. '\u216B': '\u0058\u0049\u0049',
  13914. '\u216C': '\u004C',
  13915. '\u216D': '\u0043',
  13916. '\u216E': '\u0044',
  13917. '\u216F': '\u004D',
  13918. '\u2170': '\u0069',
  13919. '\u2171': '\u0069\u0069',
  13920. '\u2172': '\u0069\u0069\u0069',
  13921. '\u2173': '\u0069\u0076',
  13922. '\u2174': '\u0076',
  13923. '\u2175': '\u0076\u0069',
  13924. '\u2176': '\u0076\u0069\u0069',
  13925. '\u2177': '\u0076\u0069\u0069\u0069',
  13926. '\u2178': '\u0069\u0078',
  13927. '\u2179': '\u0078',
  13928. '\u217A': '\u0078\u0069',
  13929. '\u217B': '\u0078\u0069\u0069',
  13930. '\u217C': '\u006C',
  13931. '\u217D': '\u0063',
  13932. '\u217E': '\u0064',
  13933. '\u217F': '\u006D',
  13934. '\u222C': '\u222B\u222B',
  13935. '\u222D': '\u222B\u222B\u222B',
  13936. '\u222F': '\u222E\u222E',
  13937. '\u2230': '\u222E\u222E\u222E',
  13938. '\u2474': '\u0028\u0031\u0029',
  13939. '\u2475': '\u0028\u0032\u0029',
  13940. '\u2476': '\u0028\u0033\u0029',
  13941. '\u2477': '\u0028\u0034\u0029',
  13942. '\u2478': '\u0028\u0035\u0029',
  13943. '\u2479': '\u0028\u0036\u0029',
  13944. '\u247A': '\u0028\u0037\u0029',
  13945. '\u247B': '\u0028\u0038\u0029',
  13946. '\u247C': '\u0028\u0039\u0029',
  13947. '\u247D': '\u0028\u0031\u0030\u0029',
  13948. '\u247E': '\u0028\u0031\u0031\u0029',
  13949. '\u247F': '\u0028\u0031\u0032\u0029',
  13950. '\u2480': '\u0028\u0031\u0033\u0029',
  13951. '\u2481': '\u0028\u0031\u0034\u0029',
  13952. '\u2482': '\u0028\u0031\u0035\u0029',
  13953. '\u2483': '\u0028\u0031\u0036\u0029',
  13954. '\u2484': '\u0028\u0031\u0037\u0029',
  13955. '\u2485': '\u0028\u0031\u0038\u0029',
  13956. '\u2486': '\u0028\u0031\u0039\u0029',
  13957. '\u2487': '\u0028\u0032\u0030\u0029',
  13958. '\u2488': '\u0031\u002E',
  13959. '\u2489': '\u0032\u002E',
  13960. '\u248A': '\u0033\u002E',
  13961. '\u248B': '\u0034\u002E',
  13962. '\u248C': '\u0035\u002E',
  13963. '\u248D': '\u0036\u002E',
  13964. '\u248E': '\u0037\u002E',
  13965. '\u248F': '\u0038\u002E',
  13966. '\u2490': '\u0039\u002E',
  13967. '\u2491': '\u0031\u0030\u002E',
  13968. '\u2492': '\u0031\u0031\u002E',
  13969. '\u2493': '\u0031\u0032\u002E',
  13970. '\u2494': '\u0031\u0033\u002E',
  13971. '\u2495': '\u0031\u0034\u002E',
  13972. '\u2496': '\u0031\u0035\u002E',
  13973. '\u2497': '\u0031\u0036\u002E',
  13974. '\u2498': '\u0031\u0037\u002E',
  13975. '\u2499': '\u0031\u0038\u002E',
  13976. '\u249A': '\u0031\u0039\u002E',
  13977. '\u249B': '\u0032\u0030\u002E',
  13978. '\u249C': '\u0028\u0061\u0029',
  13979. '\u249D': '\u0028\u0062\u0029',
  13980. '\u249E': '\u0028\u0063\u0029',
  13981. '\u249F': '\u0028\u0064\u0029',
  13982. '\u24A0': '\u0028\u0065\u0029',
  13983. '\u24A1': '\u0028\u0066\u0029',
  13984. '\u24A2': '\u0028\u0067\u0029',
  13985. '\u24A3': '\u0028\u0068\u0029',
  13986. '\u24A4': '\u0028\u0069\u0029',
  13987. '\u24A5': '\u0028\u006A\u0029',
  13988. '\u24A6': '\u0028\u006B\u0029',
  13989. '\u24A7': '\u0028\u006C\u0029',
  13990. '\u24A8': '\u0028\u006D\u0029',
  13991. '\u24A9': '\u0028\u006E\u0029',
  13992. '\u24AA': '\u0028\u006F\u0029',
  13993. '\u24AB': '\u0028\u0070\u0029',
  13994. '\u24AC': '\u0028\u0071\u0029',
  13995. '\u24AD': '\u0028\u0072\u0029',
  13996. '\u24AE': '\u0028\u0073\u0029',
  13997. '\u24AF': '\u0028\u0074\u0029',
  13998. '\u24B0': '\u0028\u0075\u0029',
  13999. '\u24B1': '\u0028\u0076\u0029',
  14000. '\u24B2': '\u0028\u0077\u0029',
  14001. '\u24B3': '\u0028\u0078\u0029',
  14002. '\u24B4': '\u0028\u0079\u0029',
  14003. '\u24B5': '\u0028\u007A\u0029',
  14004. '\u2A0C': '\u222B\u222B\u222B\u222B',
  14005. '\u2A74': '\u003A\u003A\u003D',
  14006. '\u2A75': '\u003D\u003D',
  14007. '\u2A76': '\u003D\u003D\u003D',
  14008. '\u2E9F': '\u6BCD',
  14009. '\u2EF3': '\u9F9F',
  14010. '\u2F00': '\u4E00',
  14011. '\u2F01': '\u4E28',
  14012. '\u2F02': '\u4E36',
  14013. '\u2F03': '\u4E3F',
  14014. '\u2F04': '\u4E59',
  14015. '\u2F05': '\u4E85',
  14016. '\u2F06': '\u4E8C',
  14017. '\u2F07': '\u4EA0',
  14018. '\u2F08': '\u4EBA',
  14019. '\u2F09': '\u513F',
  14020. '\u2F0A': '\u5165',
  14021. '\u2F0B': '\u516B',
  14022. '\u2F0C': '\u5182',
  14023. '\u2F0D': '\u5196',
  14024. '\u2F0E': '\u51AB',
  14025. '\u2F0F': '\u51E0',
  14026. '\u2F10': '\u51F5',
  14027. '\u2F11': '\u5200',
  14028. '\u2F12': '\u529B',
  14029. '\u2F13': '\u52F9',
  14030. '\u2F14': '\u5315',
  14031. '\u2F15': '\u531A',
  14032. '\u2F16': '\u5338',
  14033. '\u2F17': '\u5341',
  14034. '\u2F18': '\u535C',
  14035. '\u2F19': '\u5369',
  14036. '\u2F1A': '\u5382',
  14037. '\u2F1B': '\u53B6',
  14038. '\u2F1C': '\u53C8',
  14039. '\u2F1D': '\u53E3',
  14040. '\u2F1E': '\u56D7',
  14041. '\u2F1F': '\u571F',
  14042. '\u2F20': '\u58EB',
  14043. '\u2F21': '\u5902',
  14044. '\u2F22': '\u590A',
  14045. '\u2F23': '\u5915',
  14046. '\u2F24': '\u5927',
  14047. '\u2F25': '\u5973',
  14048. '\u2F26': '\u5B50',
  14049. '\u2F27': '\u5B80',
  14050. '\u2F28': '\u5BF8',
  14051. '\u2F29': '\u5C0F',
  14052. '\u2F2A': '\u5C22',
  14053. '\u2F2B': '\u5C38',
  14054. '\u2F2C': '\u5C6E',
  14055. '\u2F2D': '\u5C71',
  14056. '\u2F2E': '\u5DDB',
  14057. '\u2F2F': '\u5DE5',
  14058. '\u2F30': '\u5DF1',
  14059. '\u2F31': '\u5DFE',
  14060. '\u2F32': '\u5E72',
  14061. '\u2F33': '\u5E7A',
  14062. '\u2F34': '\u5E7F',
  14063. '\u2F35': '\u5EF4',
  14064. '\u2F36': '\u5EFE',
  14065. '\u2F37': '\u5F0B',
  14066. '\u2F38': '\u5F13',
  14067. '\u2F39': '\u5F50',
  14068. '\u2F3A': '\u5F61',
  14069. '\u2F3B': '\u5F73',
  14070. '\u2F3C': '\u5FC3',
  14071. '\u2F3D': '\u6208',
  14072. '\u2F3E': '\u6236',
  14073. '\u2F3F': '\u624B',
  14074. '\u2F40': '\u652F',
  14075. '\u2F41': '\u6534',
  14076. '\u2F42': '\u6587',
  14077. '\u2F43': '\u6597',
  14078. '\u2F44': '\u65A4',
  14079. '\u2F45': '\u65B9',
  14080. '\u2F46': '\u65E0',
  14081. '\u2F47': '\u65E5',
  14082. '\u2F48': '\u66F0',
  14083. '\u2F49': '\u6708',
  14084. '\u2F4A': '\u6728',
  14085. '\u2F4B': '\u6B20',
  14086. '\u2F4C': '\u6B62',
  14087. '\u2F4D': '\u6B79',
  14088. '\u2F4E': '\u6BB3',
  14089. '\u2F4F': '\u6BCB',
  14090. '\u2F50': '\u6BD4',
  14091. '\u2F51': '\u6BDB',
  14092. '\u2F52': '\u6C0F',
  14093. '\u2F53': '\u6C14',
  14094. '\u2F54': '\u6C34',
  14095. '\u2F55': '\u706B',
  14096. '\u2F56': '\u722A',
  14097. '\u2F57': '\u7236',
  14098. '\u2F58': '\u723B',
  14099. '\u2F59': '\u723F',
  14100. '\u2F5A': '\u7247',
  14101. '\u2F5B': '\u7259',
  14102. '\u2F5C': '\u725B',
  14103. '\u2F5D': '\u72AC',
  14104. '\u2F5E': '\u7384',
  14105. '\u2F5F': '\u7389',
  14106. '\u2F60': '\u74DC',
  14107. '\u2F61': '\u74E6',
  14108. '\u2F62': '\u7518',
  14109. '\u2F63': '\u751F',
  14110. '\u2F64': '\u7528',
  14111. '\u2F65': '\u7530',
  14112. '\u2F66': '\u758B',
  14113. '\u2F67': '\u7592',
  14114. '\u2F68': '\u7676',
  14115. '\u2F69': '\u767D',
  14116. '\u2F6A': '\u76AE',
  14117. '\u2F6B': '\u76BF',
  14118. '\u2F6C': '\u76EE',
  14119. '\u2F6D': '\u77DB',
  14120. '\u2F6E': '\u77E2',
  14121. '\u2F6F': '\u77F3',
  14122. '\u2F70': '\u793A',
  14123. '\u2F71': '\u79B8',
  14124. '\u2F72': '\u79BE',
  14125. '\u2F73': '\u7A74',
  14126. '\u2F74': '\u7ACB',
  14127. '\u2F75': '\u7AF9',
  14128. '\u2F76': '\u7C73',
  14129. '\u2F77': '\u7CF8',
  14130. '\u2F78': '\u7F36',
  14131. '\u2F79': '\u7F51',
  14132. '\u2F7A': '\u7F8A',
  14133. '\u2F7B': '\u7FBD',
  14134. '\u2F7C': '\u8001',
  14135. '\u2F7D': '\u800C',
  14136. '\u2F7E': '\u8012',
  14137. '\u2F7F': '\u8033',
  14138. '\u2F80': '\u807F',
  14139. '\u2F81': '\u8089',
  14140. '\u2F82': '\u81E3',
  14141. '\u2F83': '\u81EA',
  14142. '\u2F84': '\u81F3',
  14143. '\u2F85': '\u81FC',
  14144. '\u2F86': '\u820C',
  14145. '\u2F87': '\u821B',
  14146. '\u2F88': '\u821F',
  14147. '\u2F89': '\u826E',
  14148. '\u2F8A': '\u8272',
  14149. '\u2F8B': '\u8278',
  14150. '\u2F8C': '\u864D',
  14151. '\u2F8D': '\u866B',
  14152. '\u2F8E': '\u8840',
  14153. '\u2F8F': '\u884C',
  14154. '\u2F90': '\u8863',
  14155. '\u2F91': '\u897E',
  14156. '\u2F92': '\u898B',
  14157. '\u2F93': '\u89D2',
  14158. '\u2F94': '\u8A00',
  14159. '\u2F95': '\u8C37',
  14160. '\u2F96': '\u8C46',
  14161. '\u2F97': '\u8C55',
  14162. '\u2F98': '\u8C78',
  14163. '\u2F99': '\u8C9D',
  14164. '\u2F9A': '\u8D64',
  14165. '\u2F9B': '\u8D70',
  14166. '\u2F9C': '\u8DB3',
  14167. '\u2F9D': '\u8EAB',
  14168. '\u2F9E': '\u8ECA',
  14169. '\u2F9F': '\u8F9B',
  14170. '\u2FA0': '\u8FB0',
  14171. '\u2FA1': '\u8FB5',
  14172. '\u2FA2': '\u9091',
  14173. '\u2FA3': '\u9149',
  14174. '\u2FA4': '\u91C6',
  14175. '\u2FA5': '\u91CC',
  14176. '\u2FA6': '\u91D1',
  14177. '\u2FA7': '\u9577',
  14178. '\u2FA8': '\u9580',
  14179. '\u2FA9': '\u961C',
  14180. '\u2FAA': '\u96B6',
  14181. '\u2FAB': '\u96B9',
  14182. '\u2FAC': '\u96E8',
  14183. '\u2FAD': '\u9751',
  14184. '\u2FAE': '\u975E',
  14185. '\u2FAF': '\u9762',
  14186. '\u2FB0': '\u9769',
  14187. '\u2FB1': '\u97CB',
  14188. '\u2FB2': '\u97ED',
  14189. '\u2FB3': '\u97F3',
  14190. '\u2FB4': '\u9801',
  14191. '\u2FB5': '\u98A8',
  14192. '\u2FB6': '\u98DB',
  14193. '\u2FB7': '\u98DF',
  14194. '\u2FB8': '\u9996',
  14195. '\u2FB9': '\u9999',
  14196. '\u2FBA': '\u99AC',
  14197. '\u2FBB': '\u9AA8',
  14198. '\u2FBC': '\u9AD8',
  14199. '\u2FBD': '\u9ADF',
  14200. '\u2FBE': '\u9B25',
  14201. '\u2FBF': '\u9B2F',
  14202. '\u2FC0': '\u9B32',
  14203. '\u2FC1': '\u9B3C',
  14204. '\u2FC2': '\u9B5A',
  14205. '\u2FC3': '\u9CE5',
  14206. '\u2FC4': '\u9E75',
  14207. '\u2FC5': '\u9E7F',
  14208. '\u2FC6': '\u9EA5',
  14209. '\u2FC7': '\u9EBB',
  14210. '\u2FC8': '\u9EC3',
  14211. '\u2FC9': '\u9ECD',
  14212. '\u2FCA': '\u9ED1',
  14213. '\u2FCB': '\u9EF9',
  14214. '\u2FCC': '\u9EFD',
  14215. '\u2FCD': '\u9F0E',
  14216. '\u2FCE': '\u9F13',
  14217. '\u2FCF': '\u9F20',
  14218. '\u2FD0': '\u9F3B',
  14219. '\u2FD1': '\u9F4A',
  14220. '\u2FD2': '\u9F52',
  14221. '\u2FD3': '\u9F8D',
  14222. '\u2FD4': '\u9F9C',
  14223. '\u2FD5': '\u9FA0',
  14224. '\u3036': '\u3012',
  14225. '\u3038': '\u5341',
  14226. '\u3039': '\u5344',
  14227. '\u303A': '\u5345',
  14228. '\u309B': '\u0020\u3099',
  14229. '\u309C': '\u0020\u309A',
  14230. '\u3131': '\u1100',
  14231. '\u3132': '\u1101',
  14232. '\u3133': '\u11AA',
  14233. '\u3134': '\u1102',
  14234. '\u3135': '\u11AC',
  14235. '\u3136': '\u11AD',
  14236. '\u3137': '\u1103',
  14237. '\u3138': '\u1104',
  14238. '\u3139': '\u1105',
  14239. '\u313A': '\u11B0',
  14240. '\u313B': '\u11B1',
  14241. '\u313C': '\u11B2',
  14242. '\u313D': '\u11B3',
  14243. '\u313E': '\u11B4',
  14244. '\u313F': '\u11B5',
  14245. '\u3140': '\u111A',
  14246. '\u3141': '\u1106',
  14247. '\u3142': '\u1107',
  14248. '\u3143': '\u1108',
  14249. '\u3144': '\u1121',
  14250. '\u3145': '\u1109',
  14251. '\u3146': '\u110A',
  14252. '\u3147': '\u110B',
  14253. '\u3148': '\u110C',
  14254. '\u3149': '\u110D',
  14255. '\u314A': '\u110E',
  14256. '\u314B': '\u110F',
  14257. '\u314C': '\u1110',
  14258. '\u314D': '\u1111',
  14259. '\u314E': '\u1112',
  14260. '\u314F': '\u1161',
  14261. '\u3150': '\u1162',
  14262. '\u3151': '\u1163',
  14263. '\u3152': '\u1164',
  14264. '\u3153': '\u1165',
  14265. '\u3154': '\u1166',
  14266. '\u3155': '\u1167',
  14267. '\u3156': '\u1168',
  14268. '\u3157': '\u1169',
  14269. '\u3158': '\u116A',
  14270. '\u3159': '\u116B',
  14271. '\u315A': '\u116C',
  14272. '\u315B': '\u116D',
  14273. '\u315C': '\u116E',
  14274. '\u315D': '\u116F',
  14275. '\u315E': '\u1170',
  14276. '\u315F': '\u1171',
  14277. '\u3160': '\u1172',
  14278. '\u3161': '\u1173',
  14279. '\u3162': '\u1174',
  14280. '\u3163': '\u1175',
  14281. '\u3164': '\u1160',
  14282. '\u3165': '\u1114',
  14283. '\u3166': '\u1115',
  14284. '\u3167': '\u11C7',
  14285. '\u3168': '\u11C8',
  14286. '\u3169': '\u11CC',
  14287. '\u316A': '\u11CE',
  14288. '\u316B': '\u11D3',
  14289. '\u316C': '\u11D7',
  14290. '\u316D': '\u11D9',
  14291. '\u316E': '\u111C',
  14292. '\u316F': '\u11DD',
  14293. '\u3170': '\u11DF',
  14294. '\u3171': '\u111D',
  14295. '\u3172': '\u111E',
  14296. '\u3173': '\u1120',
  14297. '\u3174': '\u1122',
  14298. '\u3175': '\u1123',
  14299. '\u3176': '\u1127',
  14300. '\u3177': '\u1129',
  14301. '\u3178': '\u112B',
  14302. '\u3179': '\u112C',
  14303. '\u317A': '\u112D',
  14304. '\u317B': '\u112E',
  14305. '\u317C': '\u112F',
  14306. '\u317D': '\u1132',
  14307. '\u317E': '\u1136',
  14308. '\u317F': '\u1140',
  14309. '\u3180': '\u1147',
  14310. '\u3181': '\u114C',
  14311. '\u3182': '\u11F1',
  14312. '\u3183': '\u11F2',
  14313. '\u3184': '\u1157',
  14314. '\u3185': '\u1158',
  14315. '\u3186': '\u1159',
  14316. '\u3187': '\u1184',
  14317. '\u3188': '\u1185',
  14318. '\u3189': '\u1188',
  14319. '\u318A': '\u1191',
  14320. '\u318B': '\u1192',
  14321. '\u318C': '\u1194',
  14322. '\u318D': '\u119E',
  14323. '\u318E': '\u11A1',
  14324. '\u3200': '\u0028\u1100\u0029',
  14325. '\u3201': '\u0028\u1102\u0029',
  14326. '\u3202': '\u0028\u1103\u0029',
  14327. '\u3203': '\u0028\u1105\u0029',
  14328. '\u3204': '\u0028\u1106\u0029',
  14329. '\u3205': '\u0028\u1107\u0029',
  14330. '\u3206': '\u0028\u1109\u0029',
  14331. '\u3207': '\u0028\u110B\u0029',
  14332. '\u3208': '\u0028\u110C\u0029',
  14333. '\u3209': '\u0028\u110E\u0029',
  14334. '\u320A': '\u0028\u110F\u0029',
  14335. '\u320B': '\u0028\u1110\u0029',
  14336. '\u320C': '\u0028\u1111\u0029',
  14337. '\u320D': '\u0028\u1112\u0029',
  14338. '\u320E': '\u0028\u1100\u1161\u0029',
  14339. '\u320F': '\u0028\u1102\u1161\u0029',
  14340. '\u3210': '\u0028\u1103\u1161\u0029',
  14341. '\u3211': '\u0028\u1105\u1161\u0029',
  14342. '\u3212': '\u0028\u1106\u1161\u0029',
  14343. '\u3213': '\u0028\u1107\u1161\u0029',
  14344. '\u3214': '\u0028\u1109\u1161\u0029',
  14345. '\u3215': '\u0028\u110B\u1161\u0029',
  14346. '\u3216': '\u0028\u110C\u1161\u0029',
  14347. '\u3217': '\u0028\u110E\u1161\u0029',
  14348. '\u3218': '\u0028\u110F\u1161\u0029',
  14349. '\u3219': '\u0028\u1110\u1161\u0029',
  14350. '\u321A': '\u0028\u1111\u1161\u0029',
  14351. '\u321B': '\u0028\u1112\u1161\u0029',
  14352. '\u321C': '\u0028\u110C\u116E\u0029',
  14353. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  14354. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  14355. '\u3220': '\u0028\u4E00\u0029',
  14356. '\u3221': '\u0028\u4E8C\u0029',
  14357. '\u3222': '\u0028\u4E09\u0029',
  14358. '\u3223': '\u0028\u56DB\u0029',
  14359. '\u3224': '\u0028\u4E94\u0029',
  14360. '\u3225': '\u0028\u516D\u0029',
  14361. '\u3226': '\u0028\u4E03\u0029',
  14362. '\u3227': '\u0028\u516B\u0029',
  14363. '\u3228': '\u0028\u4E5D\u0029',
  14364. '\u3229': '\u0028\u5341\u0029',
  14365. '\u322A': '\u0028\u6708\u0029',
  14366. '\u322B': '\u0028\u706B\u0029',
  14367. '\u322C': '\u0028\u6C34\u0029',
  14368. '\u322D': '\u0028\u6728\u0029',
  14369. '\u322E': '\u0028\u91D1\u0029',
  14370. '\u322F': '\u0028\u571F\u0029',
  14371. '\u3230': '\u0028\u65E5\u0029',
  14372. '\u3231': '\u0028\u682A\u0029',
  14373. '\u3232': '\u0028\u6709\u0029',
  14374. '\u3233': '\u0028\u793E\u0029',
  14375. '\u3234': '\u0028\u540D\u0029',
  14376. '\u3235': '\u0028\u7279\u0029',
  14377. '\u3236': '\u0028\u8CA1\u0029',
  14378. '\u3237': '\u0028\u795D\u0029',
  14379. '\u3238': '\u0028\u52B4\u0029',
  14380. '\u3239': '\u0028\u4EE3\u0029',
  14381. '\u323A': '\u0028\u547C\u0029',
  14382. '\u323B': '\u0028\u5B66\u0029',
  14383. '\u323C': '\u0028\u76E3\u0029',
  14384. '\u323D': '\u0028\u4F01\u0029',
  14385. '\u323E': '\u0028\u8CC7\u0029',
  14386. '\u323F': '\u0028\u5354\u0029',
  14387. '\u3240': '\u0028\u796D\u0029',
  14388. '\u3241': '\u0028\u4F11\u0029',
  14389. '\u3242': '\u0028\u81EA\u0029',
  14390. '\u3243': '\u0028\u81F3\u0029',
  14391. '\u32C0': '\u0031\u6708',
  14392. '\u32C1': '\u0032\u6708',
  14393. '\u32C2': '\u0033\u6708',
  14394. '\u32C3': '\u0034\u6708',
  14395. '\u32C4': '\u0035\u6708',
  14396. '\u32C5': '\u0036\u6708',
  14397. '\u32C6': '\u0037\u6708',
  14398. '\u32C7': '\u0038\u6708',
  14399. '\u32C8': '\u0039\u6708',
  14400. '\u32C9': '\u0031\u0030\u6708',
  14401. '\u32CA': '\u0031\u0031\u6708',
  14402. '\u32CB': '\u0031\u0032\u6708',
  14403. '\u3358': '\u0030\u70B9',
  14404. '\u3359': '\u0031\u70B9',
  14405. '\u335A': '\u0032\u70B9',
  14406. '\u335B': '\u0033\u70B9',
  14407. '\u335C': '\u0034\u70B9',
  14408. '\u335D': '\u0035\u70B9',
  14409. '\u335E': '\u0036\u70B9',
  14410. '\u335F': '\u0037\u70B9',
  14411. '\u3360': '\u0038\u70B9',
  14412. '\u3361': '\u0039\u70B9',
  14413. '\u3362': '\u0031\u0030\u70B9',
  14414. '\u3363': '\u0031\u0031\u70B9',
  14415. '\u3364': '\u0031\u0032\u70B9',
  14416. '\u3365': '\u0031\u0033\u70B9',
  14417. '\u3366': '\u0031\u0034\u70B9',
  14418. '\u3367': '\u0031\u0035\u70B9',
  14419. '\u3368': '\u0031\u0036\u70B9',
  14420. '\u3369': '\u0031\u0037\u70B9',
  14421. '\u336A': '\u0031\u0038\u70B9',
  14422. '\u336B': '\u0031\u0039\u70B9',
  14423. '\u336C': '\u0032\u0030\u70B9',
  14424. '\u336D': '\u0032\u0031\u70B9',
  14425. '\u336E': '\u0032\u0032\u70B9',
  14426. '\u336F': '\u0032\u0033\u70B9',
  14427. '\u3370': '\u0032\u0034\u70B9',
  14428. '\u33E0': '\u0031\u65E5',
  14429. '\u33E1': '\u0032\u65E5',
  14430. '\u33E2': '\u0033\u65E5',
  14431. '\u33E3': '\u0034\u65E5',
  14432. '\u33E4': '\u0035\u65E5',
  14433. '\u33E5': '\u0036\u65E5',
  14434. '\u33E6': '\u0037\u65E5',
  14435. '\u33E7': '\u0038\u65E5',
  14436. '\u33E8': '\u0039\u65E5',
  14437. '\u33E9': '\u0031\u0030\u65E5',
  14438. '\u33EA': '\u0031\u0031\u65E5',
  14439. '\u33EB': '\u0031\u0032\u65E5',
  14440. '\u33EC': '\u0031\u0033\u65E5',
  14441. '\u33ED': '\u0031\u0034\u65E5',
  14442. '\u33EE': '\u0031\u0035\u65E5',
  14443. '\u33EF': '\u0031\u0036\u65E5',
  14444. '\u33F0': '\u0031\u0037\u65E5',
  14445. '\u33F1': '\u0031\u0038\u65E5',
  14446. '\u33F2': '\u0031\u0039\u65E5',
  14447. '\u33F3': '\u0032\u0030\u65E5',
  14448. '\u33F4': '\u0032\u0031\u65E5',
  14449. '\u33F5': '\u0032\u0032\u65E5',
  14450. '\u33F6': '\u0032\u0033\u65E5',
  14451. '\u33F7': '\u0032\u0034\u65E5',
  14452. '\u33F8': '\u0032\u0035\u65E5',
  14453. '\u33F9': '\u0032\u0036\u65E5',
  14454. '\u33FA': '\u0032\u0037\u65E5',
  14455. '\u33FB': '\u0032\u0038\u65E5',
  14456. '\u33FC': '\u0032\u0039\u65E5',
  14457. '\u33FD': '\u0033\u0030\u65E5',
  14458. '\u33FE': '\u0033\u0031\u65E5',
  14459. '\uFB00': '\u0066\u0066',
  14460. '\uFB01': '\u0066\u0069',
  14461. '\uFB02': '\u0066\u006C',
  14462. '\uFB03': '\u0066\u0066\u0069',
  14463. '\uFB04': '\u0066\u0066\u006C',
  14464. '\uFB05': '\u017F\u0074',
  14465. '\uFB06': '\u0073\u0074',
  14466. '\uFB13': '\u0574\u0576',
  14467. '\uFB14': '\u0574\u0565',
  14468. '\uFB15': '\u0574\u056B',
  14469. '\uFB16': '\u057E\u0576',
  14470. '\uFB17': '\u0574\u056D',
  14471. '\uFB4F': '\u05D0\u05DC',
  14472. '\uFB50': '\u0671',
  14473. '\uFB51': '\u0671',
  14474. '\uFB52': '\u067B',
  14475. '\uFB53': '\u067B',
  14476. '\uFB54': '\u067B',
  14477. '\uFB55': '\u067B',
  14478. '\uFB56': '\u067E',
  14479. '\uFB57': '\u067E',
  14480. '\uFB58': '\u067E',
  14481. '\uFB59': '\u067E',
  14482. '\uFB5A': '\u0680',
  14483. '\uFB5B': '\u0680',
  14484. '\uFB5C': '\u0680',
  14485. '\uFB5D': '\u0680',
  14486. '\uFB5E': '\u067A',
  14487. '\uFB5F': '\u067A',
  14488. '\uFB60': '\u067A',
  14489. '\uFB61': '\u067A',
  14490. '\uFB62': '\u067F',
  14491. '\uFB63': '\u067F',
  14492. '\uFB64': '\u067F',
  14493. '\uFB65': '\u067F',
  14494. '\uFB66': '\u0679',
  14495. '\uFB67': '\u0679',
  14496. '\uFB68': '\u0679',
  14497. '\uFB69': '\u0679',
  14498. '\uFB6A': '\u06A4',
  14499. '\uFB6B': '\u06A4',
  14500. '\uFB6C': '\u06A4',
  14501. '\uFB6D': '\u06A4',
  14502. '\uFB6E': '\u06A6',
  14503. '\uFB6F': '\u06A6',
  14504. '\uFB70': '\u06A6',
  14505. '\uFB71': '\u06A6',
  14506. '\uFB72': '\u0684',
  14507. '\uFB73': '\u0684',
  14508. '\uFB74': '\u0684',
  14509. '\uFB75': '\u0684',
  14510. '\uFB76': '\u0683',
  14511. '\uFB77': '\u0683',
  14512. '\uFB78': '\u0683',
  14513. '\uFB79': '\u0683',
  14514. '\uFB7A': '\u0686',
  14515. '\uFB7B': '\u0686',
  14516. '\uFB7C': '\u0686',
  14517. '\uFB7D': '\u0686',
  14518. '\uFB7E': '\u0687',
  14519. '\uFB7F': '\u0687',
  14520. '\uFB80': '\u0687',
  14521. '\uFB81': '\u0687',
  14522. '\uFB82': '\u068D',
  14523. '\uFB83': '\u068D',
  14524. '\uFB84': '\u068C',
  14525. '\uFB85': '\u068C',
  14526. '\uFB86': '\u068E',
  14527. '\uFB87': '\u068E',
  14528. '\uFB88': '\u0688',
  14529. '\uFB89': '\u0688',
  14530. '\uFB8A': '\u0698',
  14531. '\uFB8B': '\u0698',
  14532. '\uFB8C': '\u0691',
  14533. '\uFB8D': '\u0691',
  14534. '\uFB8E': '\u06A9',
  14535. '\uFB8F': '\u06A9',
  14536. '\uFB90': '\u06A9',
  14537. '\uFB91': '\u06A9',
  14538. '\uFB92': '\u06AF',
  14539. '\uFB93': '\u06AF',
  14540. '\uFB94': '\u06AF',
  14541. '\uFB95': '\u06AF',
  14542. '\uFB96': '\u06B3',
  14543. '\uFB97': '\u06B3',
  14544. '\uFB98': '\u06B3',
  14545. '\uFB99': '\u06B3',
  14546. '\uFB9A': '\u06B1',
  14547. '\uFB9B': '\u06B1',
  14548. '\uFB9C': '\u06B1',
  14549. '\uFB9D': '\u06B1',
  14550. '\uFB9E': '\u06BA',
  14551. '\uFB9F': '\u06BA',
  14552. '\uFBA0': '\u06BB',
  14553. '\uFBA1': '\u06BB',
  14554. '\uFBA2': '\u06BB',
  14555. '\uFBA3': '\u06BB',
  14556. '\uFBA4': '\u06C0',
  14557. '\uFBA5': '\u06C0',
  14558. '\uFBA6': '\u06C1',
  14559. '\uFBA7': '\u06C1',
  14560. '\uFBA8': '\u06C1',
  14561. '\uFBA9': '\u06C1',
  14562. '\uFBAA': '\u06BE',
  14563. '\uFBAB': '\u06BE',
  14564. '\uFBAC': '\u06BE',
  14565. '\uFBAD': '\u06BE',
  14566. '\uFBAE': '\u06D2',
  14567. '\uFBAF': '\u06D2',
  14568. '\uFBB0': '\u06D3',
  14569. '\uFBB1': '\u06D3',
  14570. '\uFBD3': '\u06AD',
  14571. '\uFBD4': '\u06AD',
  14572. '\uFBD5': '\u06AD',
  14573. '\uFBD6': '\u06AD',
  14574. '\uFBD7': '\u06C7',
  14575. '\uFBD8': '\u06C7',
  14576. '\uFBD9': '\u06C6',
  14577. '\uFBDA': '\u06C6',
  14578. '\uFBDB': '\u06C8',
  14579. '\uFBDC': '\u06C8',
  14580. '\uFBDD': '\u0677',
  14581. '\uFBDE': '\u06CB',
  14582. '\uFBDF': '\u06CB',
  14583. '\uFBE0': '\u06C5',
  14584. '\uFBE1': '\u06C5',
  14585. '\uFBE2': '\u06C9',
  14586. '\uFBE3': '\u06C9',
  14587. '\uFBE4': '\u06D0',
  14588. '\uFBE5': '\u06D0',
  14589. '\uFBE6': '\u06D0',
  14590. '\uFBE7': '\u06D0',
  14591. '\uFBE8': '\u0649',
  14592. '\uFBE9': '\u0649',
  14593. '\uFBEA': '\u0626\u0627',
  14594. '\uFBEB': '\u0626\u0627',
  14595. '\uFBEC': '\u0626\u06D5',
  14596. '\uFBED': '\u0626\u06D5',
  14597. '\uFBEE': '\u0626\u0648',
  14598. '\uFBEF': '\u0626\u0648',
  14599. '\uFBF0': '\u0626\u06C7',
  14600. '\uFBF1': '\u0626\u06C7',
  14601. '\uFBF2': '\u0626\u06C6',
  14602. '\uFBF3': '\u0626\u06C6',
  14603. '\uFBF4': '\u0626\u06C8',
  14604. '\uFBF5': '\u0626\u06C8',
  14605. '\uFBF6': '\u0626\u06D0',
  14606. '\uFBF7': '\u0626\u06D0',
  14607. '\uFBF8': '\u0626\u06D0',
  14608. '\uFBF9': '\u0626\u0649',
  14609. '\uFBFA': '\u0626\u0649',
  14610. '\uFBFB': '\u0626\u0649',
  14611. '\uFBFC': '\u06CC',
  14612. '\uFBFD': '\u06CC',
  14613. '\uFBFE': '\u06CC',
  14614. '\uFBFF': '\u06CC',
  14615. '\uFC00': '\u0626\u062C',
  14616. '\uFC01': '\u0626\u062D',
  14617. '\uFC02': '\u0626\u0645',
  14618. '\uFC03': '\u0626\u0649',
  14619. '\uFC04': '\u0626\u064A',
  14620. '\uFC05': '\u0628\u062C',
  14621. '\uFC06': '\u0628\u062D',
  14622. '\uFC07': '\u0628\u062E',
  14623. '\uFC08': '\u0628\u0645',
  14624. '\uFC09': '\u0628\u0649',
  14625. '\uFC0A': '\u0628\u064A',
  14626. '\uFC0B': '\u062A\u062C',
  14627. '\uFC0C': '\u062A\u062D',
  14628. '\uFC0D': '\u062A\u062E',
  14629. '\uFC0E': '\u062A\u0645',
  14630. '\uFC0F': '\u062A\u0649',
  14631. '\uFC10': '\u062A\u064A',
  14632. '\uFC11': '\u062B\u062C',
  14633. '\uFC12': '\u062B\u0645',
  14634. '\uFC13': '\u062B\u0649',
  14635. '\uFC14': '\u062B\u064A',
  14636. '\uFC15': '\u062C\u062D',
  14637. '\uFC16': '\u062C\u0645',
  14638. '\uFC17': '\u062D\u062C',
  14639. '\uFC18': '\u062D\u0645',
  14640. '\uFC19': '\u062E\u062C',
  14641. '\uFC1A': '\u062E\u062D',
  14642. '\uFC1B': '\u062E\u0645',
  14643. '\uFC1C': '\u0633\u062C',
  14644. '\uFC1D': '\u0633\u062D',
  14645. '\uFC1E': '\u0633\u062E',
  14646. '\uFC1F': '\u0633\u0645',
  14647. '\uFC20': '\u0635\u062D',
  14648. '\uFC21': '\u0635\u0645',
  14649. '\uFC22': '\u0636\u062C',
  14650. '\uFC23': '\u0636\u062D',
  14651. '\uFC24': '\u0636\u062E',
  14652. '\uFC25': '\u0636\u0645',
  14653. '\uFC26': '\u0637\u062D',
  14654. '\uFC27': '\u0637\u0645',
  14655. '\uFC28': '\u0638\u0645',
  14656. '\uFC29': '\u0639\u062C',
  14657. '\uFC2A': '\u0639\u0645',
  14658. '\uFC2B': '\u063A\u062C',
  14659. '\uFC2C': '\u063A\u0645',
  14660. '\uFC2D': '\u0641\u062C',
  14661. '\uFC2E': '\u0641\u062D',
  14662. '\uFC2F': '\u0641\u062E',
  14663. '\uFC30': '\u0641\u0645',
  14664. '\uFC31': '\u0641\u0649',
  14665. '\uFC32': '\u0641\u064A',
  14666. '\uFC33': '\u0642\u062D',
  14667. '\uFC34': '\u0642\u0645',
  14668. '\uFC35': '\u0642\u0649',
  14669. '\uFC36': '\u0642\u064A',
  14670. '\uFC37': '\u0643\u0627',
  14671. '\uFC38': '\u0643\u062C',
  14672. '\uFC39': '\u0643\u062D',
  14673. '\uFC3A': '\u0643\u062E',
  14674. '\uFC3B': '\u0643\u0644',
  14675. '\uFC3C': '\u0643\u0645',
  14676. '\uFC3D': '\u0643\u0649',
  14677. '\uFC3E': '\u0643\u064A',
  14678. '\uFC3F': '\u0644\u062C',
  14679. '\uFC40': '\u0644\u062D',
  14680. '\uFC41': '\u0644\u062E',
  14681. '\uFC42': '\u0644\u0645',
  14682. '\uFC43': '\u0644\u0649',
  14683. '\uFC44': '\u0644\u064A',
  14684. '\uFC45': '\u0645\u062C',
  14685. '\uFC46': '\u0645\u062D',
  14686. '\uFC47': '\u0645\u062E',
  14687. '\uFC48': '\u0645\u0645',
  14688. '\uFC49': '\u0645\u0649',
  14689. '\uFC4A': '\u0645\u064A',
  14690. '\uFC4B': '\u0646\u062C',
  14691. '\uFC4C': '\u0646\u062D',
  14692. '\uFC4D': '\u0646\u062E',
  14693. '\uFC4E': '\u0646\u0645',
  14694. '\uFC4F': '\u0646\u0649',
  14695. '\uFC50': '\u0646\u064A',
  14696. '\uFC51': '\u0647\u062C',
  14697. '\uFC52': '\u0647\u0645',
  14698. '\uFC53': '\u0647\u0649',
  14699. '\uFC54': '\u0647\u064A',
  14700. '\uFC55': '\u064A\u062C',
  14701. '\uFC56': '\u064A\u062D',
  14702. '\uFC57': '\u064A\u062E',
  14703. '\uFC58': '\u064A\u0645',
  14704. '\uFC59': '\u064A\u0649',
  14705. '\uFC5A': '\u064A\u064A',
  14706. '\uFC5B': '\u0630\u0670',
  14707. '\uFC5C': '\u0631\u0670',
  14708. '\uFC5D': '\u0649\u0670',
  14709. '\uFC5E': '\u0020\u064C\u0651',
  14710. '\uFC5F': '\u0020\u064D\u0651',
  14711. '\uFC60': '\u0020\u064E\u0651',
  14712. '\uFC61': '\u0020\u064F\u0651',
  14713. '\uFC62': '\u0020\u0650\u0651',
  14714. '\uFC63': '\u0020\u0651\u0670',
  14715. '\uFC64': '\u0626\u0631',
  14716. '\uFC65': '\u0626\u0632',
  14717. '\uFC66': '\u0626\u0645',
  14718. '\uFC67': '\u0626\u0646',
  14719. '\uFC68': '\u0626\u0649',
  14720. '\uFC69': '\u0626\u064A',
  14721. '\uFC6A': '\u0628\u0631',
  14722. '\uFC6B': '\u0628\u0632',
  14723. '\uFC6C': '\u0628\u0645',
  14724. '\uFC6D': '\u0628\u0646',
  14725. '\uFC6E': '\u0628\u0649',
  14726. '\uFC6F': '\u0628\u064A',
  14727. '\uFC70': '\u062A\u0631',
  14728. '\uFC71': '\u062A\u0632',
  14729. '\uFC72': '\u062A\u0645',
  14730. '\uFC73': '\u062A\u0646',
  14731. '\uFC74': '\u062A\u0649',
  14732. '\uFC75': '\u062A\u064A',
  14733. '\uFC76': '\u062B\u0631',
  14734. '\uFC77': '\u062B\u0632',
  14735. '\uFC78': '\u062B\u0645',
  14736. '\uFC79': '\u062B\u0646',
  14737. '\uFC7A': '\u062B\u0649',
  14738. '\uFC7B': '\u062B\u064A',
  14739. '\uFC7C': '\u0641\u0649',
  14740. '\uFC7D': '\u0641\u064A',
  14741. '\uFC7E': '\u0642\u0649',
  14742. '\uFC7F': '\u0642\u064A',
  14743. '\uFC80': '\u0643\u0627',
  14744. '\uFC81': '\u0643\u0644',
  14745. '\uFC82': '\u0643\u0645',
  14746. '\uFC83': '\u0643\u0649',
  14747. '\uFC84': '\u0643\u064A',
  14748. '\uFC85': '\u0644\u0645',
  14749. '\uFC86': '\u0644\u0649',
  14750. '\uFC87': '\u0644\u064A',
  14751. '\uFC88': '\u0645\u0627',
  14752. '\uFC89': '\u0645\u0645',
  14753. '\uFC8A': '\u0646\u0631',
  14754. '\uFC8B': '\u0646\u0632',
  14755. '\uFC8C': '\u0646\u0645',
  14756. '\uFC8D': '\u0646\u0646',
  14757. '\uFC8E': '\u0646\u0649',
  14758. '\uFC8F': '\u0646\u064A',
  14759. '\uFC90': '\u0649\u0670',
  14760. '\uFC91': '\u064A\u0631',
  14761. '\uFC92': '\u064A\u0632',
  14762. '\uFC93': '\u064A\u0645',
  14763. '\uFC94': '\u064A\u0646',
  14764. '\uFC95': '\u064A\u0649',
  14765. '\uFC96': '\u064A\u064A',
  14766. '\uFC97': '\u0626\u062C',
  14767. '\uFC98': '\u0626\u062D',
  14768. '\uFC99': '\u0626\u062E',
  14769. '\uFC9A': '\u0626\u0645',
  14770. '\uFC9B': '\u0626\u0647',
  14771. '\uFC9C': '\u0628\u062C',
  14772. '\uFC9D': '\u0628\u062D',
  14773. '\uFC9E': '\u0628\u062E',
  14774. '\uFC9F': '\u0628\u0645',
  14775. '\uFCA0': '\u0628\u0647',
  14776. '\uFCA1': '\u062A\u062C',
  14777. '\uFCA2': '\u062A\u062D',
  14778. '\uFCA3': '\u062A\u062E',
  14779. '\uFCA4': '\u062A\u0645',
  14780. '\uFCA5': '\u062A\u0647',
  14781. '\uFCA6': '\u062B\u0645',
  14782. '\uFCA7': '\u062C\u062D',
  14783. '\uFCA8': '\u062C\u0645',
  14784. '\uFCA9': '\u062D\u062C',
  14785. '\uFCAA': '\u062D\u0645',
  14786. '\uFCAB': '\u062E\u062C',
  14787. '\uFCAC': '\u062E\u0645',
  14788. '\uFCAD': '\u0633\u062C',
  14789. '\uFCAE': '\u0633\u062D',
  14790. '\uFCAF': '\u0633\u062E',
  14791. '\uFCB0': '\u0633\u0645',
  14792. '\uFCB1': '\u0635\u062D',
  14793. '\uFCB2': '\u0635\u062E',
  14794. '\uFCB3': '\u0635\u0645',
  14795. '\uFCB4': '\u0636\u062C',
  14796. '\uFCB5': '\u0636\u062D',
  14797. '\uFCB6': '\u0636\u062E',
  14798. '\uFCB7': '\u0636\u0645',
  14799. '\uFCB8': '\u0637\u062D',
  14800. '\uFCB9': '\u0638\u0645',
  14801. '\uFCBA': '\u0639\u062C',
  14802. '\uFCBB': '\u0639\u0645',
  14803. '\uFCBC': '\u063A\u062C',
  14804. '\uFCBD': '\u063A\u0645',
  14805. '\uFCBE': '\u0641\u062C',
  14806. '\uFCBF': '\u0641\u062D',
  14807. '\uFCC0': '\u0641\u062E',
  14808. '\uFCC1': '\u0641\u0645',
  14809. '\uFCC2': '\u0642\u062D',
  14810. '\uFCC3': '\u0642\u0645',
  14811. '\uFCC4': '\u0643\u062C',
  14812. '\uFCC5': '\u0643\u062D',
  14813. '\uFCC6': '\u0643\u062E',
  14814. '\uFCC7': '\u0643\u0644',
  14815. '\uFCC8': '\u0643\u0645',
  14816. '\uFCC9': '\u0644\u062C',
  14817. '\uFCCA': '\u0644\u062D',
  14818. '\uFCCB': '\u0644\u062E',
  14819. '\uFCCC': '\u0644\u0645',
  14820. '\uFCCD': '\u0644\u0647',
  14821. '\uFCCE': '\u0645\u062C',
  14822. '\uFCCF': '\u0645\u062D',
  14823. '\uFCD0': '\u0645\u062E',
  14824. '\uFCD1': '\u0645\u0645',
  14825. '\uFCD2': '\u0646\u062C',
  14826. '\uFCD3': '\u0646\u062D',
  14827. '\uFCD4': '\u0646\u062E',
  14828. '\uFCD5': '\u0646\u0645',
  14829. '\uFCD6': '\u0646\u0647',
  14830. '\uFCD7': '\u0647\u062C',
  14831. '\uFCD8': '\u0647\u0645',
  14832. '\uFCD9': '\u0647\u0670',
  14833. '\uFCDA': '\u064A\u062C',
  14834. '\uFCDB': '\u064A\u062D',
  14835. '\uFCDC': '\u064A\u062E',
  14836. '\uFCDD': '\u064A\u0645',
  14837. '\uFCDE': '\u064A\u0647',
  14838. '\uFCDF': '\u0626\u0645',
  14839. '\uFCE0': '\u0626\u0647',
  14840. '\uFCE1': '\u0628\u0645',
  14841. '\uFCE2': '\u0628\u0647',
  14842. '\uFCE3': '\u062A\u0645',
  14843. '\uFCE4': '\u062A\u0647',
  14844. '\uFCE5': '\u062B\u0645',
  14845. '\uFCE6': '\u062B\u0647',
  14846. '\uFCE7': '\u0633\u0645',
  14847. '\uFCE8': '\u0633\u0647',
  14848. '\uFCE9': '\u0634\u0645',
  14849. '\uFCEA': '\u0634\u0647',
  14850. '\uFCEB': '\u0643\u0644',
  14851. '\uFCEC': '\u0643\u0645',
  14852. '\uFCED': '\u0644\u0645',
  14853. '\uFCEE': '\u0646\u0645',
  14854. '\uFCEF': '\u0646\u0647',
  14855. '\uFCF0': '\u064A\u0645',
  14856. '\uFCF1': '\u064A\u0647',
  14857. '\uFCF2': '\u0640\u064E\u0651',
  14858. '\uFCF3': '\u0640\u064F\u0651',
  14859. '\uFCF4': '\u0640\u0650\u0651',
  14860. '\uFCF5': '\u0637\u0649',
  14861. '\uFCF6': '\u0637\u064A',
  14862. '\uFCF7': '\u0639\u0649',
  14863. '\uFCF8': '\u0639\u064A',
  14864. '\uFCF9': '\u063A\u0649',
  14865. '\uFCFA': '\u063A\u064A',
  14866. '\uFCFB': '\u0633\u0649',
  14867. '\uFCFC': '\u0633\u064A',
  14868. '\uFCFD': '\u0634\u0649',
  14869. '\uFCFE': '\u0634\u064A',
  14870. '\uFCFF': '\u062D\u0649',
  14871. '\uFD00': '\u062D\u064A',
  14872. '\uFD01': '\u062C\u0649',
  14873. '\uFD02': '\u062C\u064A',
  14874. '\uFD03': '\u062E\u0649',
  14875. '\uFD04': '\u062E\u064A',
  14876. '\uFD05': '\u0635\u0649',
  14877. '\uFD06': '\u0635\u064A',
  14878. '\uFD07': '\u0636\u0649',
  14879. '\uFD08': '\u0636\u064A',
  14880. '\uFD09': '\u0634\u062C',
  14881. '\uFD0A': '\u0634\u062D',
  14882. '\uFD0B': '\u0634\u062E',
  14883. '\uFD0C': '\u0634\u0645',
  14884. '\uFD0D': '\u0634\u0631',
  14885. '\uFD0E': '\u0633\u0631',
  14886. '\uFD0F': '\u0635\u0631',
  14887. '\uFD10': '\u0636\u0631',
  14888. '\uFD11': '\u0637\u0649',
  14889. '\uFD12': '\u0637\u064A',
  14890. '\uFD13': '\u0639\u0649',
  14891. '\uFD14': '\u0639\u064A',
  14892. '\uFD15': '\u063A\u0649',
  14893. '\uFD16': '\u063A\u064A',
  14894. '\uFD17': '\u0633\u0649',
  14895. '\uFD18': '\u0633\u064A',
  14896. '\uFD19': '\u0634\u0649',
  14897. '\uFD1A': '\u0634\u064A',
  14898. '\uFD1B': '\u062D\u0649',
  14899. '\uFD1C': '\u062D\u064A',
  14900. '\uFD1D': '\u062C\u0649',
  14901. '\uFD1E': '\u062C\u064A',
  14902. '\uFD1F': '\u062E\u0649',
  14903. '\uFD20': '\u062E\u064A',
  14904. '\uFD21': '\u0635\u0649',
  14905. '\uFD22': '\u0635\u064A',
  14906. '\uFD23': '\u0636\u0649',
  14907. '\uFD24': '\u0636\u064A',
  14908. '\uFD25': '\u0634\u062C',
  14909. '\uFD26': '\u0634\u062D',
  14910. '\uFD27': '\u0634\u062E',
  14911. '\uFD28': '\u0634\u0645',
  14912. '\uFD29': '\u0634\u0631',
  14913. '\uFD2A': '\u0633\u0631',
  14914. '\uFD2B': '\u0635\u0631',
  14915. '\uFD2C': '\u0636\u0631',
  14916. '\uFD2D': '\u0634\u062C',
  14917. '\uFD2E': '\u0634\u062D',
  14918. '\uFD2F': '\u0634\u062E',
  14919. '\uFD30': '\u0634\u0645',
  14920. '\uFD31': '\u0633\u0647',
  14921. '\uFD32': '\u0634\u0647',
  14922. '\uFD33': '\u0637\u0645',
  14923. '\uFD34': '\u0633\u062C',
  14924. '\uFD35': '\u0633\u062D',
  14925. '\uFD36': '\u0633\u062E',
  14926. '\uFD37': '\u0634\u062C',
  14927. '\uFD38': '\u0634\u062D',
  14928. '\uFD39': '\u0634\u062E',
  14929. '\uFD3A': '\u0637\u0645',
  14930. '\uFD3B': '\u0638\u0645',
  14931. '\uFD3C': '\u0627\u064B',
  14932. '\uFD3D': '\u0627\u064B',
  14933. '\uFD50': '\u062A\u062C\u0645',
  14934. '\uFD51': '\u062A\u062D\u062C',
  14935. '\uFD52': '\u062A\u062D\u062C',
  14936. '\uFD53': '\u062A\u062D\u0645',
  14937. '\uFD54': '\u062A\u062E\u0645',
  14938. '\uFD55': '\u062A\u0645\u062C',
  14939. '\uFD56': '\u062A\u0645\u062D',
  14940. '\uFD57': '\u062A\u0645\u062E',
  14941. '\uFD58': '\u062C\u0645\u062D',
  14942. '\uFD59': '\u062C\u0645\u062D',
  14943. '\uFD5A': '\u062D\u0645\u064A',
  14944. '\uFD5B': '\u062D\u0645\u0649',
  14945. '\uFD5C': '\u0633\u062D\u062C',
  14946. '\uFD5D': '\u0633\u062C\u062D',
  14947. '\uFD5E': '\u0633\u062C\u0649',
  14948. '\uFD5F': '\u0633\u0645\u062D',
  14949. '\uFD60': '\u0633\u0645\u062D',
  14950. '\uFD61': '\u0633\u0645\u062C',
  14951. '\uFD62': '\u0633\u0645\u0645',
  14952. '\uFD63': '\u0633\u0645\u0645',
  14953. '\uFD64': '\u0635\u062D\u062D',
  14954. '\uFD65': '\u0635\u062D\u062D',
  14955. '\uFD66': '\u0635\u0645\u0645',
  14956. '\uFD67': '\u0634\u062D\u0645',
  14957. '\uFD68': '\u0634\u062D\u0645',
  14958. '\uFD69': '\u0634\u062C\u064A',
  14959. '\uFD6A': '\u0634\u0645\u062E',
  14960. '\uFD6B': '\u0634\u0645\u062E',
  14961. '\uFD6C': '\u0634\u0645\u0645',
  14962. '\uFD6D': '\u0634\u0645\u0645',
  14963. '\uFD6E': '\u0636\u062D\u0649',
  14964. '\uFD6F': '\u0636\u062E\u0645',
  14965. '\uFD70': '\u0636\u062E\u0645',
  14966. '\uFD71': '\u0637\u0645\u062D',
  14967. '\uFD72': '\u0637\u0645\u062D',
  14968. '\uFD73': '\u0637\u0645\u0645',
  14969. '\uFD74': '\u0637\u0645\u064A',
  14970. '\uFD75': '\u0639\u062C\u0645',
  14971. '\uFD76': '\u0639\u0645\u0645',
  14972. '\uFD77': '\u0639\u0645\u0645',
  14973. '\uFD78': '\u0639\u0645\u0649',
  14974. '\uFD79': '\u063A\u0645\u0645',
  14975. '\uFD7A': '\u063A\u0645\u064A',
  14976. '\uFD7B': '\u063A\u0645\u0649',
  14977. '\uFD7C': '\u0641\u062E\u0645',
  14978. '\uFD7D': '\u0641\u062E\u0645',
  14979. '\uFD7E': '\u0642\u0645\u062D',
  14980. '\uFD7F': '\u0642\u0645\u0645',
  14981. '\uFD80': '\u0644\u062D\u0645',
  14982. '\uFD81': '\u0644\u062D\u064A',
  14983. '\uFD82': '\u0644\u062D\u0649',
  14984. '\uFD83': '\u0644\u062C\u062C',
  14985. '\uFD84': '\u0644\u062C\u062C',
  14986. '\uFD85': '\u0644\u062E\u0645',
  14987. '\uFD86': '\u0644\u062E\u0645',
  14988. '\uFD87': '\u0644\u0645\u062D',
  14989. '\uFD88': '\u0644\u0645\u062D',
  14990. '\uFD89': '\u0645\u062D\u062C',
  14991. '\uFD8A': '\u0645\u062D\u0645',
  14992. '\uFD8B': '\u0645\u062D\u064A',
  14993. '\uFD8C': '\u0645\u062C\u062D',
  14994. '\uFD8D': '\u0645\u062C\u0645',
  14995. '\uFD8E': '\u0645\u062E\u062C',
  14996. '\uFD8F': '\u0645\u062E\u0645',
  14997. '\uFD92': '\u0645\u062C\u062E',
  14998. '\uFD93': '\u0647\u0645\u062C',
  14999. '\uFD94': '\u0647\u0645\u0645',
  15000. '\uFD95': '\u0646\u062D\u0645',
  15001. '\uFD96': '\u0646\u062D\u0649',
  15002. '\uFD97': '\u0646\u062C\u0645',
  15003. '\uFD98': '\u0646\u062C\u0645',
  15004. '\uFD99': '\u0646\u062C\u0649',
  15005. '\uFD9A': '\u0646\u0645\u064A',
  15006. '\uFD9B': '\u0646\u0645\u0649',
  15007. '\uFD9C': '\u064A\u0645\u0645',
  15008. '\uFD9D': '\u064A\u0645\u0645',
  15009. '\uFD9E': '\u0628\u062E\u064A',
  15010. '\uFD9F': '\u062A\u062C\u064A',
  15011. '\uFDA0': '\u062A\u062C\u0649',
  15012. '\uFDA1': '\u062A\u062E\u064A',
  15013. '\uFDA2': '\u062A\u062E\u0649',
  15014. '\uFDA3': '\u062A\u0645\u064A',
  15015. '\uFDA4': '\u062A\u0645\u0649',
  15016. '\uFDA5': '\u062C\u0645\u064A',
  15017. '\uFDA6': '\u062C\u062D\u0649',
  15018. '\uFDA7': '\u062C\u0645\u0649',
  15019. '\uFDA8': '\u0633\u062E\u0649',
  15020. '\uFDA9': '\u0635\u062D\u064A',
  15021. '\uFDAA': '\u0634\u062D\u064A',
  15022. '\uFDAB': '\u0636\u062D\u064A',
  15023. '\uFDAC': '\u0644\u062C\u064A',
  15024. '\uFDAD': '\u0644\u0645\u064A',
  15025. '\uFDAE': '\u064A\u062D\u064A',
  15026. '\uFDAF': '\u064A\u062C\u064A',
  15027. '\uFDB0': '\u064A\u0645\u064A',
  15028. '\uFDB1': '\u0645\u0645\u064A',
  15029. '\uFDB2': '\u0642\u0645\u064A',
  15030. '\uFDB3': '\u0646\u062D\u064A',
  15031. '\uFDB4': '\u0642\u0645\u062D',
  15032. '\uFDB5': '\u0644\u062D\u0645',
  15033. '\uFDB6': '\u0639\u0645\u064A',
  15034. '\uFDB7': '\u0643\u0645\u064A',
  15035. '\uFDB8': '\u0646\u062C\u062D',
  15036. '\uFDB9': '\u0645\u062E\u064A',
  15037. '\uFDBA': '\u0644\u062C\u0645',
  15038. '\uFDBB': '\u0643\u0645\u0645',
  15039. '\uFDBC': '\u0644\u062C\u0645',
  15040. '\uFDBD': '\u0646\u062C\u062D',
  15041. '\uFDBE': '\u062C\u062D\u064A',
  15042. '\uFDBF': '\u062D\u062C\u064A',
  15043. '\uFDC0': '\u0645\u062C\u064A',
  15044. '\uFDC1': '\u0641\u0645\u064A',
  15045. '\uFDC2': '\u0628\u062D\u064A',
  15046. '\uFDC3': '\u0643\u0645\u0645',
  15047. '\uFDC4': '\u0639\u062C\u0645',
  15048. '\uFDC5': '\u0635\u0645\u0645',
  15049. '\uFDC6': '\u0633\u062E\u064A',
  15050. '\uFDC7': '\u0646\u062C\u064A',
  15051. '\uFE49': '\u203E',
  15052. '\uFE4A': '\u203E',
  15053. '\uFE4B': '\u203E',
  15054. '\uFE4C': '\u203E',
  15055. '\uFE4D': '\u005F',
  15056. '\uFE4E': '\u005F',
  15057. '\uFE4F': '\u005F',
  15058. '\uFE80': '\u0621',
  15059. '\uFE81': '\u0622',
  15060. '\uFE82': '\u0622',
  15061. '\uFE83': '\u0623',
  15062. '\uFE84': '\u0623',
  15063. '\uFE85': '\u0624',
  15064. '\uFE86': '\u0624',
  15065. '\uFE87': '\u0625',
  15066. '\uFE88': '\u0625',
  15067. '\uFE89': '\u0626',
  15068. '\uFE8A': '\u0626',
  15069. '\uFE8B': '\u0626',
  15070. '\uFE8C': '\u0626',
  15071. '\uFE8D': '\u0627',
  15072. '\uFE8E': '\u0627',
  15073. '\uFE8F': '\u0628',
  15074. '\uFE90': '\u0628',
  15075. '\uFE91': '\u0628',
  15076. '\uFE92': '\u0628',
  15077. '\uFE93': '\u0629',
  15078. '\uFE94': '\u0629',
  15079. '\uFE95': '\u062A',
  15080. '\uFE96': '\u062A',
  15081. '\uFE97': '\u062A',
  15082. '\uFE98': '\u062A',
  15083. '\uFE99': '\u062B',
  15084. '\uFE9A': '\u062B',
  15085. '\uFE9B': '\u062B',
  15086. '\uFE9C': '\u062B',
  15087. '\uFE9D': '\u062C',
  15088. '\uFE9E': '\u062C',
  15089. '\uFE9F': '\u062C',
  15090. '\uFEA0': '\u062C',
  15091. '\uFEA1': '\u062D',
  15092. '\uFEA2': '\u062D',
  15093. '\uFEA3': '\u062D',
  15094. '\uFEA4': '\u062D',
  15095. '\uFEA5': '\u062E',
  15096. '\uFEA6': '\u062E',
  15097. '\uFEA7': '\u062E',
  15098. '\uFEA8': '\u062E',
  15099. '\uFEA9': '\u062F',
  15100. '\uFEAA': '\u062F',
  15101. '\uFEAB': '\u0630',
  15102. '\uFEAC': '\u0630',
  15103. '\uFEAD': '\u0631',
  15104. '\uFEAE': '\u0631',
  15105. '\uFEAF': '\u0632',
  15106. '\uFEB0': '\u0632',
  15107. '\uFEB1': '\u0633',
  15108. '\uFEB2': '\u0633',
  15109. '\uFEB3': '\u0633',
  15110. '\uFEB4': '\u0633',
  15111. '\uFEB5': '\u0634',
  15112. '\uFEB6': '\u0634',
  15113. '\uFEB7': '\u0634',
  15114. '\uFEB8': '\u0634',
  15115. '\uFEB9': '\u0635',
  15116. '\uFEBA': '\u0635',
  15117. '\uFEBB': '\u0635',
  15118. '\uFEBC': '\u0635',
  15119. '\uFEBD': '\u0636',
  15120. '\uFEBE': '\u0636',
  15121. '\uFEBF': '\u0636',
  15122. '\uFEC0': '\u0636',
  15123. '\uFEC1': '\u0637',
  15124. '\uFEC2': '\u0637',
  15125. '\uFEC3': '\u0637',
  15126. '\uFEC4': '\u0637',
  15127. '\uFEC5': '\u0638',
  15128. '\uFEC6': '\u0638',
  15129. '\uFEC7': '\u0638',
  15130. '\uFEC8': '\u0638',
  15131. '\uFEC9': '\u0639',
  15132. '\uFECA': '\u0639',
  15133. '\uFECB': '\u0639',
  15134. '\uFECC': '\u0639',
  15135. '\uFECD': '\u063A',
  15136. '\uFECE': '\u063A',
  15137. '\uFECF': '\u063A',
  15138. '\uFED0': '\u063A',
  15139. '\uFED1': '\u0641',
  15140. '\uFED2': '\u0641',
  15141. '\uFED3': '\u0641',
  15142. '\uFED4': '\u0641',
  15143. '\uFED5': '\u0642',
  15144. '\uFED6': '\u0642',
  15145. '\uFED7': '\u0642',
  15146. '\uFED8': '\u0642',
  15147. '\uFED9': '\u0643',
  15148. '\uFEDA': '\u0643',
  15149. '\uFEDB': '\u0643',
  15150. '\uFEDC': '\u0643',
  15151. '\uFEDD': '\u0644',
  15152. '\uFEDE': '\u0644',
  15153. '\uFEDF': '\u0644',
  15154. '\uFEE0': '\u0644',
  15155. '\uFEE1': '\u0645',
  15156. '\uFEE2': '\u0645',
  15157. '\uFEE3': '\u0645',
  15158. '\uFEE4': '\u0645',
  15159. '\uFEE5': '\u0646',
  15160. '\uFEE6': '\u0646',
  15161. '\uFEE7': '\u0646',
  15162. '\uFEE8': '\u0646',
  15163. '\uFEE9': '\u0647',
  15164. '\uFEEA': '\u0647',
  15165. '\uFEEB': '\u0647',
  15166. '\uFEEC': '\u0647',
  15167. '\uFEED': '\u0648',
  15168. '\uFEEE': '\u0648',
  15169. '\uFEEF': '\u0649',
  15170. '\uFEF0': '\u0649',
  15171. '\uFEF1': '\u064A',
  15172. '\uFEF2': '\u064A',
  15173. '\uFEF3': '\u064A',
  15174. '\uFEF4': '\u064A',
  15175. '\uFEF5': '\u0644\u0622',
  15176. '\uFEF6': '\u0644\u0622',
  15177. '\uFEF7': '\u0644\u0623',
  15178. '\uFEF8': '\u0644\u0623',
  15179. '\uFEF9': '\u0644\u0625',
  15180. '\uFEFA': '\u0644\u0625',
  15181. '\uFEFB': '\u0644\u0627',
  15182. '\uFEFC': '\u0644\u0627'
  15183. };
  15184. function reverseIfRtl(chars) {
  15185. var charsLength = chars.length;
  15186. //reverse an arabic ligature
  15187. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  15188. return chars;
  15189. }
  15190. var s = '';
  15191. for (var ii = charsLength - 1; ii >= 0; ii--) {
  15192. s += chars[ii];
  15193. }
  15194. return s;
  15195. }
  15196. function adjustWidths(properties) {
  15197. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  15198. return;
  15199. }
  15200. // adjusting width to fontMatrix scale
  15201. var scale = 0.001 / properties.fontMatrix[0];
  15202. var glyphsWidths = properties.widths;
  15203. for (var glyph in glyphsWidths) {
  15204. glyphsWidths[glyph] *= scale;
  15205. }
  15206. properties.defaultWidth *= scale;
  15207. }
  15208. function getFontType(type, subtype) {
  15209. switch (type) {
  15210. case 'Type1':
  15211. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  15212. case 'CIDFontType0':
  15213. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  15214. FontType.CIDFONTTYPE0;
  15215. case 'OpenType':
  15216. return FontType.OPENTYPE;
  15217. case 'TrueType':
  15218. return FontType.TRUETYPE;
  15219. case 'CIDFontType2':
  15220. return FontType.CIDFONTTYPE2;
  15221. case 'MMType1':
  15222. return FontType.MMTYPE1;
  15223. case 'Type0':
  15224. return FontType.TYPE0;
  15225. default:
  15226. return FontType.UNKNOWN;
  15227. }
  15228. }
  15229. var Glyph = (function GlyphClosure() {
  15230. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15231. this.fontChar = fontChar;
  15232. this.unicode = unicode;
  15233. this.accent = accent;
  15234. this.width = width;
  15235. this.vmetric = vmetric;
  15236. this.operatorListId = operatorListId;
  15237. }
  15238. Glyph.prototype.matchesForCache =
  15239. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  15240. return this.fontChar === fontChar &&
  15241. this.unicode === unicode &&
  15242. this.accent === accent &&
  15243. this.width === width &&
  15244. this.vmetric === vmetric &&
  15245. this.operatorListId === operatorListId;
  15246. };
  15247. return Glyph;
  15248. })();
  15249. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  15250. function ToUnicodeMap(cmap) {
  15251. // The elements of this._map can be integers or strings, depending on how
  15252. // |cmap| was created.
  15253. this._map = cmap;
  15254. }
  15255. ToUnicodeMap.prototype = {
  15256. get length() {
  15257. return this._map.length;
  15258. },
  15259. forEach: function(callback) {
  15260. for (var charCode in this._map) {
  15261. callback(charCode, this._map[charCode].charCodeAt(0));
  15262. }
  15263. },
  15264. has: function(i) {
  15265. return this._map[i] !== undefined;
  15266. },
  15267. get: function(i) {
  15268. return this._map[i];
  15269. },
  15270. charCodeOf: function(v) {
  15271. return this._map.indexOf(v);
  15272. }
  15273. };
  15274. return ToUnicodeMap;
  15275. })();
  15276. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  15277. function IdentityToUnicodeMap(firstChar, lastChar) {
  15278. this.firstChar = firstChar;
  15279. this.lastChar = lastChar;
  15280. }
  15281. IdentityToUnicodeMap.prototype = {
  15282. get length() {
  15283. return (this.lastChar + 1) - this.firstChar;
  15284. },
  15285. forEach: function (callback) {
  15286. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  15287. callback(i, i);
  15288. }
  15289. },
  15290. has: function (i) {
  15291. return this.firstChar <= i && i <= this.lastChar;
  15292. },
  15293. get: function (i) {
  15294. if (this.firstChar <= i && i <= this.lastChar) {
  15295. return String.fromCharCode(i);
  15296. }
  15297. return undefined;
  15298. },
  15299. charCodeOf: function (v) {
  15300. error('should not call .charCodeOf');
  15301. }
  15302. };
  15303. return IdentityToUnicodeMap;
  15304. })();
  15305. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  15306. function writeInt16(dest, offset, num) {
  15307. dest[offset] = (num >> 8) & 0xFF;
  15308. dest[offset + 1] = num & 0xFF;
  15309. }
  15310. function writeInt32(dest, offset, num) {
  15311. dest[offset] = (num >> 24) & 0xFF;
  15312. dest[offset + 1] = (num >> 16) & 0xFF;
  15313. dest[offset + 2] = (num >> 8) & 0xFF;
  15314. dest[offset + 3] = num & 0xFF;
  15315. }
  15316. function writeData(dest, offset, data) {
  15317. var i, ii;
  15318. if (data instanceof Uint8Array) {
  15319. dest.set(data, offset);
  15320. } else if (typeof data === 'string') {
  15321. for (i = 0, ii = data.length; i < ii; i++) {
  15322. dest[offset++] = data.charCodeAt(i) & 0xFF;
  15323. }
  15324. } else {
  15325. // treating everything else as array
  15326. for (i = 0, ii = data.length; i < ii; i++) {
  15327. dest[offset++] = data[i] & 0xFF;
  15328. }
  15329. }
  15330. }
  15331. function OpenTypeFileBuilder(sfnt) {
  15332. this.sfnt = sfnt;
  15333. this.tables = Object.create(null);
  15334. }
  15335. OpenTypeFileBuilder.getSearchParams =
  15336. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  15337. var maxPower2 = 1, log2 = 0;
  15338. while ((maxPower2 ^ entriesCount) > maxPower2) {
  15339. maxPower2 <<= 1;
  15340. log2++;
  15341. }
  15342. var searchRange = maxPower2 * entrySize;
  15343. return {
  15344. range: searchRange,
  15345. entry: log2,
  15346. rangeShift: entrySize * entriesCount - searchRange
  15347. };
  15348. };
  15349. var OTF_HEADER_SIZE = 12;
  15350. var OTF_TABLE_ENTRY_SIZE = 16;
  15351. OpenTypeFileBuilder.prototype = {
  15352. toArray: function OpenTypeFileBuilder_toArray() {
  15353. var sfnt = this.sfnt;
  15354. // Tables needs to be written by ascendant alphabetic order
  15355. var tables = this.tables;
  15356. var tablesNames = Object.keys(tables);
  15357. tablesNames.sort();
  15358. var numTables = tablesNames.length;
  15359. var i, j, jj, table, tableName;
  15360. // layout the tables data
  15361. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  15362. var tableOffsets = [offset];
  15363. for (i = 0; i < numTables; i++) {
  15364. table = tables[tablesNames[i]];
  15365. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  15366. offset += paddedLength;
  15367. tableOffsets.push(offset);
  15368. }
  15369. var file = new Uint8Array(offset);
  15370. // write the table data first (mostly for checksum)
  15371. for (i = 0; i < numTables; i++) {
  15372. table = tables[tablesNames[i]];
  15373. writeData(file, tableOffsets[i], table);
  15374. }
  15375. // sfnt version (4 bytes)
  15376. if (sfnt === 'true') {
  15377. // Windows hates the Mac TrueType sfnt version number
  15378. sfnt = string32(0x00010000);
  15379. }
  15380. file[0] = sfnt.charCodeAt(0) & 0xFF;
  15381. file[1] = sfnt.charCodeAt(1) & 0xFF;
  15382. file[2] = sfnt.charCodeAt(2) & 0xFF;
  15383. file[3] = sfnt.charCodeAt(3) & 0xFF;
  15384. // numTables (2 bytes)
  15385. writeInt16(file, 4, numTables);
  15386. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  15387. // searchRange (2 bytes)
  15388. writeInt16(file, 6, searchParams.range);
  15389. // entrySelector (2 bytes)
  15390. writeInt16(file, 8, searchParams.entry);
  15391. // rangeShift (2 bytes)
  15392. writeInt16(file, 10, searchParams.rangeShift);
  15393. offset = OTF_HEADER_SIZE;
  15394. // writing table entries
  15395. for (i = 0; i < numTables; i++) {
  15396. tableName = tablesNames[i];
  15397. file[offset] = tableName.charCodeAt(0) & 0xFF;
  15398. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  15399. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  15400. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  15401. // checksum
  15402. var checksum = 0;
  15403. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  15404. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  15405. (file[j + 2] << 8) + file[j + 3];
  15406. checksum = (checksum + quad) | 0;
  15407. }
  15408. writeInt32(file, offset + 4, checksum);
  15409. // offset
  15410. writeInt32(file, offset + 8, tableOffsets[i]);
  15411. // length
  15412. writeInt32(file, offset + 12, tables[tableName].length);
  15413. offset += OTF_TABLE_ENTRY_SIZE;
  15414. }
  15415. return file;
  15416. },
  15417. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  15418. if (tag in this.tables) {
  15419. throw new Error('Table ' + tag + ' already exists');
  15420. }
  15421. this.tables[tag] = data;
  15422. }
  15423. };
  15424. return OpenTypeFileBuilder;
  15425. })();
  15426. /**
  15427. * 'Font' is the class the outside world should use, it encapsulate all the font
  15428. * decoding logics whatever type it is (assuming the font type is supported).
  15429. *
  15430. * For example to read a Type1 font and to attach it to the document:
  15431. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  15432. * type1Font.bind();
  15433. */
  15434. var Font = (function FontClosure() {
  15435. function Font(name, file, properties) {
  15436. var charCode, glyphName, fontChar;
  15437. this.name = name;
  15438. this.loadedName = properties.loadedName;
  15439. this.isType3Font = properties.isType3Font;
  15440. this.sizes = [];
  15441. this.glyphCache = {};
  15442. var names = name.split('+');
  15443. names = names.length > 1 ? names[1] : names[0];
  15444. names = names.split(/[-,_]/g)[0];
  15445. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  15446. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  15447. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  15448. var type = properties.type;
  15449. var subtype = properties.subtype;
  15450. this.type = type;
  15451. this.fallbackName = (this.isMonospace ? 'monospace' :
  15452. (this.isSerifFont ? 'serif' : 'sans-serif'));
  15453. this.differences = properties.differences;
  15454. this.widths = properties.widths;
  15455. this.defaultWidth = properties.defaultWidth;
  15456. this.composite = properties.composite;
  15457. this.wideChars = properties.wideChars;
  15458. this.cMap = properties.cMap;
  15459. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  15460. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  15461. this.fontMatrix = properties.fontMatrix;
  15462. this.bbox = properties.bbox;
  15463. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  15464. this.toFontChar = [];
  15465. if (properties.type === 'Type3') {
  15466. for (charCode = 0; charCode < 256; charCode++) {
  15467. this.toFontChar[charCode] = (this.differences[charCode] ||
  15468. properties.defaultEncoding[charCode]);
  15469. }
  15470. this.fontType = FontType.TYPE3;
  15471. return;
  15472. }
  15473. this.cidEncoding = properties.cidEncoding;
  15474. this.vertical = properties.vertical;
  15475. if (this.vertical) {
  15476. this.vmetrics = properties.vmetrics;
  15477. this.defaultVMetrics = properties.defaultVMetrics;
  15478. }
  15479. if (!file || file.isEmpty) {
  15480. if (file) {
  15481. // Some bad PDF generators will include empty font files,
  15482. // attempting to recover by assuming that no file exists.
  15483. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  15484. }
  15485. this.missingFile = true;
  15486. // The file data is not specified. Trying to fix the font name
  15487. // to be used with the canvas.font.
  15488. var fontName = name.replace(/[,_]/g, '-');
  15489. var isStandardFont = !!stdFontMap[fontName] ||
  15490. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  15491. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  15492. this.bold = (fontName.search(/bold/gi) !== -1);
  15493. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  15494. (fontName.search(/italic/gi) !== -1));
  15495. // Use 'name' instead of 'fontName' here because the original
  15496. // name ArialBlack for example will be replaced by Helvetica.
  15497. this.black = (name.search(/Black/g) !== -1);
  15498. // if at least one width is present, remeasure all chars when exists
  15499. this.remeasure = Object.keys(this.widths).length > 0;
  15500. if (isStandardFont && type === 'CIDFontType2' &&
  15501. properties.cidEncoding.indexOf('Identity-') === 0) {
  15502. // Standard fonts might be embedded as CID font without glyph mapping.
  15503. // Building one based on GlyphMapForStandardFonts.
  15504. var map = [];
  15505. for (var code in GlyphMapForStandardFonts) {
  15506. map[+code] = GlyphMapForStandardFonts[code];
  15507. }
  15508. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  15509. if (!isIdentityUnicode) {
  15510. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15511. map[+charCode] = unicodeCharCode;
  15512. });
  15513. }
  15514. this.toFontChar = map;
  15515. this.toUnicode = new ToUnicodeMap(map);
  15516. } else if (/Symbol/i.test(fontName)) {
  15517. var symbols = Encodings.SymbolSetEncoding;
  15518. for (charCode in symbols) {
  15519. fontChar = GlyphsUnicode[symbols[charCode]];
  15520. if (!fontChar) {
  15521. continue;
  15522. }
  15523. this.toFontChar[charCode] = fontChar;
  15524. }
  15525. for (charCode in properties.differences) {
  15526. fontChar = GlyphsUnicode[properties.differences[charCode]];
  15527. if (!fontChar) {
  15528. continue;
  15529. }
  15530. this.toFontChar[charCode] = fontChar;
  15531. }
  15532. } else if (/Dingbats/i.test(fontName)) {
  15533. if (/Wingdings/i.test(name)) {
  15534. warn('Wingdings font without embedded font file, ' +
  15535. 'falling back to the ZapfDingbats encoding.');
  15536. }
  15537. var dingbats = Encodings.ZapfDingbatsEncoding;
  15538. for (charCode in dingbats) {
  15539. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  15540. if (!fontChar) {
  15541. continue;
  15542. }
  15543. this.toFontChar[charCode] = fontChar;
  15544. }
  15545. for (charCode in properties.differences) {
  15546. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  15547. if (!fontChar) {
  15548. continue;
  15549. }
  15550. this.toFontChar[charCode] = fontChar;
  15551. }
  15552. } else if (isStandardFont) {
  15553. this.toFontChar = [];
  15554. for (charCode in properties.defaultEncoding) {
  15555. glyphName = (properties.differences[charCode] ||
  15556. properties.defaultEncoding[charCode]);
  15557. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  15558. }
  15559. } else {
  15560. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  15561. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  15562. if (notCidFont) {
  15563. glyphName = (properties.differences[charCode] ||
  15564. properties.defaultEncoding[charCode]);
  15565. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  15566. }
  15567. this.toFontChar[charCode] = unicodeCharCode;
  15568. }.bind(this));
  15569. }
  15570. this.loadedName = fontName.split('-')[0];
  15571. this.loading = false;
  15572. this.fontType = getFontType(type, subtype);
  15573. return;
  15574. }
  15575. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  15576. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  15577. // Some TrueType fonts by mistake claim Type1C
  15578. if (isTrueTypeFile(file)) {
  15579. subtype = 'TrueType';
  15580. } else {
  15581. type = 'Type1';
  15582. }
  15583. }
  15584. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  15585. type = 'CIDFontType0';
  15586. }
  15587. if (subtype === 'OpenType') {
  15588. type = 'OpenType';
  15589. }
  15590. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  15591. if (type === 'CIDFontType0') {
  15592. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  15593. }
  15594. var data;
  15595. switch (type) {
  15596. case 'MMType1':
  15597. info('MMType1 font (' + name + '), falling back to Type1.');
  15598. /* falls through */
  15599. case 'Type1':
  15600. case 'CIDFontType0':
  15601. this.mimetype = 'font/opentype';
  15602. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  15603. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  15604. adjustWidths(properties);
  15605. // Wrap the CFF data inside an OTF font file
  15606. data = this.convert(name, cff, properties);
  15607. break;
  15608. case 'OpenType':
  15609. case 'TrueType':
  15610. case 'CIDFontType2':
  15611. this.mimetype = 'font/opentype';
  15612. // Repair the TrueType file. It is can be damaged in the point of
  15613. // view of the sanitizer
  15614. data = this.checkAndRepair(name, file, properties);
  15615. if (this.isOpenType) {
  15616. type = 'OpenType';
  15617. }
  15618. break;
  15619. default:
  15620. error('Font ' + type + ' is not supported');
  15621. break;
  15622. }
  15623. this.data = data;
  15624. this.fontType = getFontType(type, subtype);
  15625. // Transfer some properties again that could change during font conversion
  15626. this.fontMatrix = properties.fontMatrix;
  15627. this.widths = properties.widths;
  15628. this.defaultWidth = properties.defaultWidth;
  15629. this.encoding = properties.baseEncoding;
  15630. this.seacMap = properties.seacMap;
  15631. this.loading = true;
  15632. }
  15633. Font.getFontID = (function () {
  15634. var ID = 1;
  15635. return function Font_getFontID() {
  15636. return String(ID++);
  15637. };
  15638. })();
  15639. function int16(b0, b1) {
  15640. return (b0 << 8) + b1;
  15641. }
  15642. function int32(b0, b1, b2, b3) {
  15643. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15644. }
  15645. function string16(value) {
  15646. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15647. }
  15648. function safeString16(value) {
  15649. // clamp value to the 16-bit int range
  15650. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  15651. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  15652. }
  15653. function isTrueTypeFile(file) {
  15654. var header = file.peekBytes(4);
  15655. return readUint32(header, 0) === 0x00010000;
  15656. }
  15657. function isType1File(file) {
  15658. var header = file.peekBytes(2);
  15659. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  15660. if (header[0] === 0x25 && header[1] === 0x21) {
  15661. return true;
  15662. }
  15663. // ... obviously some fonts violate that part of the specification,
  15664. // please refer to the comment in |Type1Font| below.
  15665. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  15666. return true;
  15667. }
  15668. return false;
  15669. }
  15670. /**
  15671. * Helper function for |adjustMapping|.
  15672. * @return {boolean}
  15673. */
  15674. function isProblematicUnicodeLocation(code) {
  15675. if (code <= 0x1F) { // Control chars
  15676. return true;
  15677. }
  15678. if (code >= 0x80 && code <= 0x9F) { // Control chars
  15679. return true;
  15680. }
  15681. if ((code >= 0x2000 && code <= 0x200F) || // General punctuation chars
  15682. (code >= 0x2028 && code <= 0x202F) ||
  15683. (code >= 0x2060 && code <= 0x206F)) {
  15684. return true;
  15685. }
  15686. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials Unicode block
  15687. return true;
  15688. }
  15689. switch (code) {
  15690. case 0x7F: // Control char
  15691. case 0xA0: // Non breaking space
  15692. case 0xAD: // Soft hyphen
  15693. case 0x2011: // Non breaking hyphen
  15694. case 0x205F: // Medium mathematical space
  15695. case 0x25CC: // Dotted circle (combining mark)
  15696. return true;
  15697. }
  15698. if ((code & ~0xFF) === 0x0E00) { // Thai/Lao chars (with combining mark)
  15699. return true;
  15700. }
  15701. return false;
  15702. }
  15703. /**
  15704. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  15705. * with their unicode value. It also moves char codes that are in known
  15706. * problematic locations.
  15707. * @return {Object} Two properties:
  15708. * 'toFontChar' - maps original char codes(the value that will be read
  15709. * from commands such as show text) to the char codes that will be used in the
  15710. * font that we build
  15711. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  15712. */
  15713. function adjustMapping(charCodeToGlyphId, properties) {
  15714. var toUnicode = properties.toUnicode;
  15715. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  15716. var isIdentityUnicode =
  15717. properties.toUnicode instanceof IdentityToUnicodeMap;
  15718. var newMap = Object.create(null);
  15719. var toFontChar = [];
  15720. var usedFontCharCodes = [];
  15721. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  15722. for (var originalCharCode in charCodeToGlyphId) {
  15723. originalCharCode |= 0;
  15724. var glyphId = charCodeToGlyphId[originalCharCode];
  15725. var fontCharCode = originalCharCode;
  15726. // First try to map the value to a unicode position if a non identity map
  15727. // was created.
  15728. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  15729. var unicode = toUnicode.get(fontCharCode);
  15730. // TODO: Try to map ligatures to the correct spot.
  15731. if (unicode.length === 1) {
  15732. fontCharCode = unicode.charCodeAt(0);
  15733. }
  15734. }
  15735. // Try to move control characters, special characters and already mapped
  15736. // characters to the private use area since they will not be drawn by
  15737. // canvas if left in their current position. Also, move characters if the
  15738. // font was symbolic and there is only an identity unicode map since the
  15739. // characters probably aren't in the correct position (fixes an issue
  15740. // with firefox and thuluthfont).
  15741. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  15742. isProblematicUnicodeLocation(fontCharCode) ||
  15743. (isSymbolic && isIdentityUnicode)) &&
  15744. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  15745. // Loop to try and find a free spot in the private use area.
  15746. do {
  15747. fontCharCode = nextAvailableFontCharCode++;
  15748. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  15749. fontCharCode = 0xF020;
  15750. nextAvailableFontCharCode = fontCharCode + 1;
  15751. }
  15752. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  15753. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  15754. }
  15755. newMap[fontCharCode] = glyphId;
  15756. toFontChar[originalCharCode] = fontCharCode;
  15757. usedFontCharCodes[fontCharCode] = true;
  15758. }
  15759. return {
  15760. toFontChar: toFontChar,
  15761. charCodeToGlyphId: newMap,
  15762. nextAvailableFontCharCode: nextAvailableFontCharCode
  15763. };
  15764. }
  15765. function getRanges(glyphs) {
  15766. // Array.sort() sorts by characters, not numerically, so convert to an
  15767. // array of characters.
  15768. var codes = [];
  15769. for (var charCode in glyphs) {
  15770. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  15771. }
  15772. codes.sort(function fontGetRangesSort(a, b) {
  15773. return a.fontCharCode - b.fontCharCode;
  15774. });
  15775. // Split the sorted codes into ranges.
  15776. var ranges = [];
  15777. var length = codes.length;
  15778. for (var n = 0; n < length; ) {
  15779. var start = codes[n].fontCharCode;
  15780. var codeIndices = [codes[n].glyphId];
  15781. ++n;
  15782. var end = start;
  15783. while (n < length && end + 1 === codes[n].fontCharCode) {
  15784. codeIndices.push(codes[n].glyphId);
  15785. ++end;
  15786. ++n;
  15787. if (end === 0xFFFF) {
  15788. break;
  15789. }
  15790. }
  15791. ranges.push([start, end, codeIndices]);
  15792. }
  15793. return ranges;
  15794. }
  15795. function createCmapTable(glyphs) {
  15796. var ranges = getRanges(glyphs);
  15797. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  15798. var cmap = '\x00\x00' + // version
  15799. string16(numTables) + // numTables
  15800. '\x00\x03' + // platformID
  15801. '\x00\x01' + // encodingID
  15802. string32(4 + numTables * 8); // start of the table record
  15803. var i, ii, j, jj;
  15804. for (i = ranges.length - 1; i >= 0; --i) {
  15805. if (ranges[i][0] <= 0xFFFF) { break; }
  15806. }
  15807. var bmpLength = i + 1;
  15808. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  15809. ranges[i][1] = 0xFFFE;
  15810. }
  15811. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  15812. var segCount = bmpLength + trailingRangesCount;
  15813. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  15814. // Fill up the 4 parallel arrays describing the segments.
  15815. var startCount = '';
  15816. var endCount = '';
  15817. var idDeltas = '';
  15818. var idRangeOffsets = '';
  15819. var glyphsIds = '';
  15820. var bias = 0;
  15821. var range, start, end, codes;
  15822. for (i = 0, ii = bmpLength; i < ii; i++) {
  15823. range = ranges[i];
  15824. start = range[0];
  15825. end = range[1];
  15826. startCount += string16(start);
  15827. endCount += string16(end);
  15828. codes = range[2];
  15829. var contiguous = true;
  15830. for (j = 1, jj = codes.length; j < jj; ++j) {
  15831. if (codes[j] !== codes[j - 1] + 1) {
  15832. contiguous = false;
  15833. break;
  15834. }
  15835. }
  15836. if (!contiguous) {
  15837. var offset = (segCount - i) * 2 + bias * 2;
  15838. bias += (end - start + 1);
  15839. idDeltas += string16(0);
  15840. idRangeOffsets += string16(offset);
  15841. for (j = 0, jj = codes.length; j < jj; ++j) {
  15842. glyphsIds += string16(codes[j]);
  15843. }
  15844. } else {
  15845. var startCode = codes[0];
  15846. idDeltas += string16((startCode - start) & 0xFFFF);
  15847. idRangeOffsets += string16(0);
  15848. }
  15849. }
  15850. if (trailingRangesCount > 0) {
  15851. endCount += '\xFF\xFF';
  15852. startCount += '\xFF\xFF';
  15853. idDeltas += '\x00\x01';
  15854. idRangeOffsets += '\x00\x00';
  15855. }
  15856. var format314 = '\x00\x00' + // language
  15857. string16(2 * segCount) +
  15858. string16(searchParams.range) +
  15859. string16(searchParams.entry) +
  15860. string16(searchParams.rangeShift) +
  15861. endCount + '\x00\x00' + startCount +
  15862. idDeltas + idRangeOffsets + glyphsIds;
  15863. var format31012 = '';
  15864. var header31012 = '';
  15865. if (numTables > 1) {
  15866. cmap += '\x00\x03' + // platformID
  15867. '\x00\x0A' + // encodingID
  15868. string32(4 + numTables * 8 +
  15869. 4 + format314.length); // start of the table record
  15870. format31012 = '';
  15871. for (i = 0, ii = ranges.length; i < ii; i++) {
  15872. range = ranges[i];
  15873. start = range[0];
  15874. codes = range[2];
  15875. var code = codes[0];
  15876. for (j = 1, jj = codes.length; j < jj; ++j) {
  15877. if (codes[j] !== codes[j - 1] + 1) {
  15878. end = range[0] + j - 1;
  15879. format31012 += string32(start) + // startCharCode
  15880. string32(end) + // endCharCode
  15881. string32(code); // startGlyphID
  15882. start = end + 1;
  15883. code = codes[j];
  15884. }
  15885. }
  15886. format31012 += string32(start) + // startCharCode
  15887. string32(range[1]) + // endCharCode
  15888. string32(code); // startGlyphID
  15889. }
  15890. header31012 = '\x00\x0C' + // format
  15891. '\x00\x00' + // reserved
  15892. string32(format31012.length + 16) + // length
  15893. '\x00\x00\x00\x00' + // language
  15894. string32(format31012.length / 12); // nGroups
  15895. }
  15896. return cmap + '\x00\x04' + // format
  15897. string16(format314.length + 4) + // length
  15898. format314 + header31012 + format31012;
  15899. }
  15900. function validateOS2Table(os2) {
  15901. var stream = new Stream(os2.data);
  15902. var version = stream.getUint16();
  15903. // TODO verify all OS/2 tables fields, but currently we validate only those
  15904. // that give us issues
  15905. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  15906. var selection = stream.getUint16();
  15907. if (version < 4 && (selection & 0x0300)) {
  15908. return false;
  15909. }
  15910. var firstChar = stream.getUint16();
  15911. var lastChar = stream.getUint16();
  15912. if (firstChar > lastChar) {
  15913. return false;
  15914. }
  15915. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  15916. var usWinAscent = stream.getUint16();
  15917. if (usWinAscent === 0) { // makes font unreadable by windows
  15918. return false;
  15919. }
  15920. // OS/2 appears to be valid, resetting some fields
  15921. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  15922. return true;
  15923. }
  15924. function createOS2Table(properties, charstrings, override) {
  15925. override = override || {
  15926. unitsPerEm: 0,
  15927. yMax: 0,
  15928. yMin: 0,
  15929. ascent: 0,
  15930. descent: 0
  15931. };
  15932. var ulUnicodeRange1 = 0;
  15933. var ulUnicodeRange2 = 0;
  15934. var ulUnicodeRange3 = 0;
  15935. var ulUnicodeRange4 = 0;
  15936. var firstCharIndex = null;
  15937. var lastCharIndex = 0;
  15938. if (charstrings) {
  15939. for (var code in charstrings) {
  15940. code |= 0;
  15941. if (firstCharIndex > code || !firstCharIndex) {
  15942. firstCharIndex = code;
  15943. }
  15944. if (lastCharIndex < code) {
  15945. lastCharIndex = code;
  15946. }
  15947. var position = getUnicodeRangeFor(code);
  15948. if (position < 32) {
  15949. ulUnicodeRange1 |= 1 << position;
  15950. } else if (position < 64) {
  15951. ulUnicodeRange2 |= 1 << position - 32;
  15952. } else if (position < 96) {
  15953. ulUnicodeRange3 |= 1 << position - 64;
  15954. } else if (position < 123) {
  15955. ulUnicodeRange4 |= 1 << position - 96;
  15956. } else {
  15957. error('Unicode ranges Bits > 123 are reserved for internal usage');
  15958. }
  15959. }
  15960. } else {
  15961. // TODO
  15962. firstCharIndex = 0;
  15963. lastCharIndex = 255;
  15964. }
  15965. var bbox = properties.bbox || [0, 0, 0, 0];
  15966. var unitsPerEm = (override.unitsPerEm ||
  15967. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  15968. // if the font units differ to the PDF glyph space units
  15969. // then scale up the values
  15970. var scale = (properties.ascentScaled ? 1.0 :
  15971. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  15972. var typoAscent = (override.ascent ||
  15973. Math.round(scale * (properties.ascent || bbox[3])));
  15974. var typoDescent = (override.descent ||
  15975. Math.round(scale * (properties.descent || bbox[1])));
  15976. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  15977. typoDescent = -typoDescent; // fixing incorrect descent
  15978. }
  15979. var winAscent = override.yMax || typoAscent;
  15980. var winDescent = -override.yMin || -typoDescent;
  15981. return '\x00\x03' + // version
  15982. '\x02\x24' + // xAvgCharWidth
  15983. '\x01\xF4' + // usWeightClass
  15984. '\x00\x05' + // usWidthClass
  15985. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  15986. '\x02\x8A' + // ySubscriptXSize
  15987. '\x02\xBB' + // ySubscriptYSize
  15988. '\x00\x00' + // ySubscriptXOffset
  15989. '\x00\x8C' + // ySubscriptYOffset
  15990. '\x02\x8A' + // ySuperScriptXSize
  15991. '\x02\xBB' + // ySuperScriptYSize
  15992. '\x00\x00' + // ySuperScriptXOffset
  15993. '\x01\xDF' + // ySuperScriptYOffset
  15994. '\x00\x31' + // yStrikeOutSize
  15995. '\x01\x02' + // yStrikeOutPosition
  15996. '\x00\x00' + // sFamilyClass
  15997. '\x00\x00\x06' +
  15998. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  15999. '\x00\x00\x00\x00\x00\x00' + // Panose
  16000. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  16001. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  16002. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  16003. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  16004. '\x2A\x32\x31\x2A' + // achVendID
  16005. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  16006. string16(firstCharIndex ||
  16007. properties.firstChar) + // usFirstCharIndex
  16008. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  16009. string16(typoAscent) + // sTypoAscender
  16010. string16(typoDescent) + // sTypoDescender
  16011. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  16012. string16(winAscent) + // usWinAscent
  16013. string16(winDescent) + // usWinDescent
  16014. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  16015. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  16016. string16(properties.xHeight) + // sxHeight
  16017. string16(properties.capHeight) + // sCapHeight
  16018. string16(0) + // usDefaultChar
  16019. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  16020. '\x00\x03'; // usMaxContext
  16021. }
  16022. function createPostTable(properties) {
  16023. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  16024. return ('\x00\x03\x00\x00' + // Version number
  16025. string32(angle) + // italicAngle
  16026. '\x00\x00' + // underlinePosition
  16027. '\x00\x00' + // underlineThickness
  16028. string32(properties.fixedPitch) + // isFixedPitch
  16029. '\x00\x00\x00\x00' + // minMemType42
  16030. '\x00\x00\x00\x00' + // maxMemType42
  16031. '\x00\x00\x00\x00' + // minMemType1
  16032. '\x00\x00\x00\x00'); // maxMemType1
  16033. }
  16034. function createNameTable(name, proto) {
  16035. if (!proto) {
  16036. proto = [[], []]; // no strings and unicode strings
  16037. }
  16038. var strings = [
  16039. proto[0][0] || 'Original licence', // 0.Copyright
  16040. proto[0][1] || name, // 1.Font family
  16041. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  16042. proto[0][3] || 'uniqueID', // 3.Unique ID
  16043. proto[0][4] || name, // 4.Full font name
  16044. proto[0][5] || 'Version 0.11', // 5.Version
  16045. proto[0][6] || '', // 6.Postscript name
  16046. proto[0][7] || 'Unknown', // 7.Trademark
  16047. proto[0][8] || 'Unknown', // 8.Manufacturer
  16048. proto[0][9] || 'Unknown' // 9.Designer
  16049. ];
  16050. // Mac want 1-byte per character strings while Windows want
  16051. // 2-bytes per character, so duplicate the names table
  16052. var stringsUnicode = [];
  16053. var i, ii, j, jj, str;
  16054. for (i = 0, ii = strings.length; i < ii; i++) {
  16055. str = proto[1][i] || strings[i];
  16056. var strBufUnicode = [];
  16057. for (j = 0, jj = str.length; j < jj; j++) {
  16058. strBufUnicode.push(string16(str.charCodeAt(j)));
  16059. }
  16060. stringsUnicode.push(strBufUnicode.join(''));
  16061. }
  16062. var names = [strings, stringsUnicode];
  16063. var platforms = ['\x00\x01', '\x00\x03'];
  16064. var encodings = ['\x00\x00', '\x00\x01'];
  16065. var languages = ['\x00\x00', '\x04\x09'];
  16066. var namesRecordCount = strings.length * platforms.length;
  16067. var nameTable =
  16068. '\x00\x00' + // format
  16069. string16(namesRecordCount) + // Number of names Record
  16070. string16(namesRecordCount * 12 + 6); // Storage
  16071. // Build the name records field
  16072. var strOffset = 0;
  16073. for (i = 0, ii = platforms.length; i < ii; i++) {
  16074. var strs = names[i];
  16075. for (j = 0, jj = strs.length; j < jj; j++) {
  16076. str = strs[j];
  16077. var nameRecord =
  16078. platforms[i] + // platform ID
  16079. encodings[i] + // encoding ID
  16080. languages[i] + // language ID
  16081. string16(j) + // name ID
  16082. string16(str.length) +
  16083. string16(strOffset);
  16084. nameTable += nameRecord;
  16085. strOffset += str.length;
  16086. }
  16087. }
  16088. nameTable += strings.join('') + stringsUnicode.join('');
  16089. return nameTable;
  16090. }
  16091. Font.prototype = {
  16092. name: null,
  16093. font: null,
  16094. mimetype: null,
  16095. encoding: null,
  16096. get renderer() {
  16097. var renderer = FontRendererFactory.create(this);
  16098. return shadow(this, 'renderer', renderer);
  16099. },
  16100. exportData: function Font_exportData() {
  16101. var data = {};
  16102. for (var i in this) {
  16103. if (this.hasOwnProperty(i)) {
  16104. data[i] = this[i];
  16105. }
  16106. }
  16107. return data;
  16108. },
  16109. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  16110. function readTableEntry(file) {
  16111. var tag = bytesToString(file.getBytes(4));
  16112. var checksum = file.getInt32();
  16113. var offset = file.getInt32() >>> 0;
  16114. var length = file.getInt32() >>> 0;
  16115. // Read the table associated data
  16116. var previousPosition = file.pos;
  16117. file.pos = file.start ? file.start : 0;
  16118. file.skip(offset);
  16119. var data = file.getBytes(length);
  16120. file.pos = previousPosition;
  16121. if (tag === 'head') {
  16122. // clearing checksum adjustment
  16123. data[8] = data[9] = data[10] = data[11] = 0;
  16124. data[17] |= 0x20; //Set font optimized for cleartype flag
  16125. }
  16126. return {
  16127. tag: tag,
  16128. checksum: checksum,
  16129. length: length,
  16130. offset: offset,
  16131. data: data
  16132. };
  16133. }
  16134. function readOpenTypeHeader(ttf) {
  16135. return {
  16136. version: bytesToString(ttf.getBytes(4)),
  16137. numTables: ttf.getUint16(),
  16138. searchRange: ttf.getUint16(),
  16139. entrySelector: ttf.getUint16(),
  16140. rangeShift: ttf.getUint16()
  16141. };
  16142. }
  16143. /**
  16144. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  16145. * PDF spec
  16146. */
  16147. function readCmapTable(cmap, font, isSymbolicFont) {
  16148. var segment;
  16149. var start = (font.start ? font.start : 0) + cmap.offset;
  16150. font.pos = start;
  16151. var version = font.getUint16();
  16152. var numTables = font.getUint16();
  16153. var potentialTable;
  16154. var canBreak = false;
  16155. // There's an order of preference in terms of which cmap subtable to
  16156. // use:
  16157. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  16158. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  16159. // The following takes advantage of the fact that the tables are sorted
  16160. // to work.
  16161. for (var i = 0; i < numTables; i++) {
  16162. var platformId = font.getUint16();
  16163. var encodingId = font.getUint16();
  16164. var offset = font.getInt32() >>> 0;
  16165. var useTable = false;
  16166. if (platformId === 0 && encodingId === 0) {
  16167. useTable = true;
  16168. // Continue the loop since there still may be a higher priority
  16169. // table.
  16170. } else if (platformId === 1 && encodingId === 0) {
  16171. useTable = true;
  16172. // Continue the loop since there still may be a higher priority
  16173. // table.
  16174. } else if (platformId === 3 && encodingId === 1 &&
  16175. (!isSymbolicFont || !potentialTable)) {
  16176. useTable = true;
  16177. if (!isSymbolicFont) {
  16178. canBreak = true;
  16179. }
  16180. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  16181. useTable = true;
  16182. canBreak = true;
  16183. }
  16184. if (useTable) {
  16185. potentialTable = {
  16186. platformId: platformId,
  16187. encodingId: encodingId,
  16188. offset: offset
  16189. };
  16190. }
  16191. if (canBreak) {
  16192. break;
  16193. }
  16194. }
  16195. if (potentialTable) {
  16196. font.pos = start + potentialTable.offset;
  16197. }
  16198. if (!potentialTable || font.peekByte() === -1) {
  16199. warn('Could not find a preferred cmap table.');
  16200. return {
  16201. platformId: -1,
  16202. encodingId: -1,
  16203. mappings: [],
  16204. hasShortCmap: false
  16205. };
  16206. }
  16207. var format = font.getUint16();
  16208. var length = font.getUint16();
  16209. var language = font.getUint16();
  16210. var hasShortCmap = false;
  16211. var mappings = [];
  16212. var j, glyphId;
  16213. // TODO(mack): refactor this cmap subtable reading logic out
  16214. if (format === 0) {
  16215. for (j = 0; j < 256; j++) {
  16216. var index = font.getByte();
  16217. if (!index) {
  16218. continue;
  16219. }
  16220. mappings.push({
  16221. charCode: j,
  16222. glyphId: index
  16223. });
  16224. }
  16225. hasShortCmap = true;
  16226. } else if (format === 4) {
  16227. // re-creating the table in format 4 since the encoding
  16228. // might be changed
  16229. var segCount = (font.getUint16() >> 1);
  16230. font.getBytes(6); // skipping range fields
  16231. var segIndex, segments = [];
  16232. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16233. segments.push({ end: font.getUint16() });
  16234. }
  16235. font.getUint16();
  16236. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16237. segments[segIndex].start = font.getUint16();
  16238. }
  16239. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16240. segments[segIndex].delta = font.getUint16();
  16241. }
  16242. var offsetsCount = 0;
  16243. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16244. segment = segments[segIndex];
  16245. var rangeOffset = font.getUint16();
  16246. if (!rangeOffset) {
  16247. segment.offsetIndex = -1;
  16248. continue;
  16249. }
  16250. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  16251. segment.offsetIndex = offsetIndex;
  16252. offsetsCount = Math.max(offsetsCount, offsetIndex +
  16253. segment.end - segment.start + 1);
  16254. }
  16255. var offsets = [];
  16256. for (j = 0; j < offsetsCount; j++) {
  16257. offsets.push(font.getUint16());
  16258. }
  16259. for (segIndex = 0; segIndex < segCount; segIndex++) {
  16260. segment = segments[segIndex];
  16261. start = segment.start;
  16262. var end = segment.end;
  16263. var delta = segment.delta;
  16264. offsetIndex = segment.offsetIndex;
  16265. for (j = start; j <= end; j++) {
  16266. if (j === 0xFFFF) {
  16267. continue;
  16268. }
  16269. glyphId = (offsetIndex < 0 ?
  16270. j : offsets[offsetIndex + j - start]);
  16271. glyphId = (glyphId + delta) & 0xFFFF;
  16272. if (glyphId === 0) {
  16273. continue;
  16274. }
  16275. mappings.push({
  16276. charCode: j,
  16277. glyphId: glyphId
  16278. });
  16279. }
  16280. }
  16281. } else if (format === 6) {
  16282. // Format 6 is a 2-bytes dense mapping, which means the font data
  16283. // lives glue together even if they are pretty far in the unicode
  16284. // table. (This looks weird, so I can have missed something), this
  16285. // works on Linux but seems to fails on Mac so let's rewrite the
  16286. // cmap table to a 3-1-4 style
  16287. var firstCode = font.getUint16();
  16288. var entryCount = font.getUint16();
  16289. for (j = 0; j < entryCount; j++) {
  16290. glyphId = font.getUint16();
  16291. var charCode = firstCode + j;
  16292. mappings.push({
  16293. charCode: charCode,
  16294. glyphId: glyphId
  16295. });
  16296. }
  16297. } else {
  16298. error('cmap table has unsupported format: ' + format);
  16299. }
  16300. // removing duplicate entries
  16301. mappings.sort(function (a, b) {
  16302. return a.charCode - b.charCode;
  16303. });
  16304. for (i = 1; i < mappings.length; i++) {
  16305. if (mappings[i - 1].charCode === mappings[i].charCode) {
  16306. mappings.splice(i, 1);
  16307. i--;
  16308. }
  16309. }
  16310. return {
  16311. platformId: potentialTable.platformId,
  16312. encodingId: potentialTable.encodingId,
  16313. mappings: mappings,
  16314. hasShortCmap: hasShortCmap
  16315. };
  16316. }
  16317. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  16318. if (!header) {
  16319. if (metrics) {
  16320. metrics.data = null;
  16321. }
  16322. return;
  16323. }
  16324. font.pos = (font.start ? font.start : 0) + header.offset;
  16325. font.pos += header.length - 2;
  16326. var numOfMetrics = font.getUint16();
  16327. if (numOfMetrics > numGlyphs) {
  16328. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  16329. 'greater than the numGlyphs (' + numGlyphs + ')');
  16330. // Reduce numOfMetrics if it is greater than numGlyphs
  16331. numOfMetrics = numGlyphs;
  16332. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  16333. header.data[35] = numOfMetrics & 0x00ff;
  16334. }
  16335. var numOfSidebearings = numGlyphs - numOfMetrics;
  16336. var numMissing = numOfSidebearings -
  16337. ((metrics.length - numOfMetrics * 4) >> 1);
  16338. if (numMissing > 0) {
  16339. // For each missing glyph, we set both the width and lsb to 0 (zero).
  16340. // Since we need to add two properties for each glyph, this explains
  16341. // the use of |numMissing * 2| when initializing the typed array.
  16342. var entries = new Uint8Array(metrics.length + numMissing * 2);
  16343. entries.set(metrics.data);
  16344. metrics.data = entries;
  16345. }
  16346. }
  16347. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  16348. hintsValid) {
  16349. if (sourceEnd - sourceStart <= 12) {
  16350. // glyph with data less than 12 is invalid one
  16351. return 0;
  16352. }
  16353. var glyf = source.subarray(sourceStart, sourceEnd);
  16354. var contoursCount = (glyf[0] << 8) | glyf[1];
  16355. if (contoursCount & 0x8000) {
  16356. // complex glyph, writing as is
  16357. dest.set(glyf, destStart);
  16358. return glyf.length;
  16359. }
  16360. var i, j = 10, flagsCount = 0;
  16361. for (i = 0; i < contoursCount; i++) {
  16362. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  16363. flagsCount = endPoint + 1;
  16364. j += 2;
  16365. }
  16366. // skipping instructions
  16367. var instructionsStart = j;
  16368. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  16369. j += 2 + instructionsLength;
  16370. var instructionsEnd = j;
  16371. // validating flags
  16372. var coordinatesLength = 0;
  16373. for (i = 0; i < flagsCount; i++) {
  16374. var flag = glyf[j++];
  16375. if (flag & 0xC0) {
  16376. // reserved flags must be zero, cleaning up
  16377. glyf[j - 1] = flag & 0x3F;
  16378. }
  16379. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  16380. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  16381. coordinatesLength += xyLength;
  16382. if (flag & 8) {
  16383. var repeat = glyf[j++];
  16384. i += repeat;
  16385. coordinatesLength += repeat * xyLength;
  16386. }
  16387. }
  16388. // glyph without coordinates will be rejected
  16389. if (coordinatesLength === 0) {
  16390. return 0;
  16391. }
  16392. var glyphDataLength = j + coordinatesLength;
  16393. if (glyphDataLength > glyf.length) {
  16394. // not enough data for coordinates
  16395. return 0;
  16396. }
  16397. if (!hintsValid && instructionsLength > 0) {
  16398. dest.set(glyf.subarray(0, instructionsStart), destStart);
  16399. dest.set([0, 0], destStart + instructionsStart);
  16400. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  16401. destStart + instructionsStart + 2);
  16402. glyphDataLength -= instructionsLength;
  16403. if (glyf.length - glyphDataLength > 3) {
  16404. glyphDataLength = (glyphDataLength + 3) & ~3;
  16405. }
  16406. return glyphDataLength;
  16407. }
  16408. if (glyf.length - glyphDataLength > 3) {
  16409. // truncating and aligning to 4 bytes the long glyph data
  16410. glyphDataLength = (glyphDataLength + 3) & ~3;
  16411. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  16412. return glyphDataLength;
  16413. }
  16414. // glyph data is fine
  16415. dest.set(glyf, destStart);
  16416. return glyf.length;
  16417. }
  16418. function sanitizeHead(head, numGlyphs, locaLength) {
  16419. var data = head.data;
  16420. // Validate version:
  16421. // Should always be 0x00010000
  16422. var version = int32(data[0], data[1], data[2], data[3]);
  16423. if (version >> 16 !== 1) {
  16424. info('Attempting to fix invalid version in head table: ' + version);
  16425. data[0] = 0;
  16426. data[1] = 1;
  16427. data[2] = 0;
  16428. data[3] = 0;
  16429. }
  16430. var indexToLocFormat = int16(data[50], data[51]);
  16431. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  16432. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  16433. indexToLocFormat);
  16434. // The value of indexToLocFormat should be 0 if the loca table
  16435. // consists of short offsets, and should be 1 if the loca table
  16436. // consists of long offsets.
  16437. //
  16438. // The number of entries in the loca table should be numGlyphs + 1.
  16439. //
  16440. // Using this information, we can work backwards to deduce if the
  16441. // size of each offset in the loca table, and thus figure out the
  16442. // appropriate value for indexToLocFormat.
  16443. var numGlyphsPlusOne = numGlyphs + 1;
  16444. if (locaLength === numGlyphsPlusOne << 1) {
  16445. // 0x0000 indicates the loca table consists of short offsets
  16446. data[50] = 0;
  16447. data[51] = 0;
  16448. } else if (locaLength === numGlyphsPlusOne << 2) {
  16449. // 0x0001 indicates the loca table consists of long offsets
  16450. data[50] = 0;
  16451. data[51] = 1;
  16452. } else {
  16453. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  16454. }
  16455. }
  16456. }
  16457. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  16458. isGlyphLocationsLong, hintsValid,
  16459. dupFirstEntry) {
  16460. var itemSize, itemDecode, itemEncode;
  16461. if (isGlyphLocationsLong) {
  16462. itemSize = 4;
  16463. itemDecode = function fontItemDecodeLong(data, offset) {
  16464. return (data[offset] << 24) | (data[offset + 1] << 16) |
  16465. (data[offset + 2] << 8) | data[offset + 3];
  16466. };
  16467. itemEncode = function fontItemEncodeLong(data, offset, value) {
  16468. data[offset] = (value >>> 24) & 0xFF;
  16469. data[offset + 1] = (value >> 16) & 0xFF;
  16470. data[offset + 2] = (value >> 8) & 0xFF;
  16471. data[offset + 3] = value & 0xFF;
  16472. };
  16473. } else {
  16474. itemSize = 2;
  16475. itemDecode = function fontItemDecode(data, offset) {
  16476. return (data[offset] << 9) | (data[offset + 1] << 1);
  16477. };
  16478. itemEncode = function fontItemEncode(data, offset, value) {
  16479. data[offset] = (value >> 9) & 0xFF;
  16480. data[offset + 1] = (value >> 1) & 0xFF;
  16481. };
  16482. }
  16483. var locaData = loca.data;
  16484. var locaDataSize = itemSize * (1 + numGlyphs);
  16485. // is loca.data too short or long?
  16486. if (locaData.length !== locaDataSize) {
  16487. locaData = new Uint8Array(locaDataSize);
  16488. locaData.set(loca.data.subarray(0, locaDataSize));
  16489. loca.data = locaData;
  16490. }
  16491. // removing the invalid glyphs
  16492. var oldGlyfData = glyf.data;
  16493. var oldGlyfDataLength = oldGlyfData.length;
  16494. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  16495. var startOffset = itemDecode(locaData, 0);
  16496. var writeOffset = 0;
  16497. var missingGlyphData = {};
  16498. itemEncode(locaData, 0, writeOffset);
  16499. var i, j;
  16500. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16501. var endOffset = itemDecode(locaData, j);
  16502. if (endOffset > oldGlyfDataLength &&
  16503. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  16504. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  16505. // the glyf table size, which makes last glyph out of range.
  16506. endOffset = oldGlyfDataLength;
  16507. }
  16508. if (endOffset > oldGlyfDataLength) {
  16509. // glyph end offset points outside glyf data, rejecting the glyph
  16510. itemEncode(locaData, j, writeOffset);
  16511. startOffset = endOffset;
  16512. continue;
  16513. }
  16514. if (startOffset === endOffset) {
  16515. missingGlyphData[i] = true;
  16516. }
  16517. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  16518. newGlyfData, writeOffset, hintsValid);
  16519. writeOffset += newLength;
  16520. itemEncode(locaData, j, writeOffset);
  16521. startOffset = endOffset;
  16522. }
  16523. if (writeOffset === 0) {
  16524. // glyf table cannot be empty -- redoing the glyf and loca tables
  16525. // to have single glyph with one point
  16526. var simpleGlyph = new Uint8Array(
  16527. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  16528. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  16529. itemEncode(locaData, j, simpleGlyph.length);
  16530. }
  16531. glyf.data = simpleGlyph;
  16532. return missingGlyphData;
  16533. }
  16534. if (dupFirstEntry) {
  16535. var firstEntryLength = itemDecode(locaData, itemSize);
  16536. if (newGlyfData.length > firstEntryLength + writeOffset) {
  16537. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  16538. } else {
  16539. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  16540. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  16541. }
  16542. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  16543. itemEncode(loca.data, locaData.length - itemSize,
  16544. writeOffset + firstEntryLength);
  16545. } else {
  16546. glyf.data = newGlyfData.subarray(0, writeOffset);
  16547. }
  16548. return missingGlyphData;
  16549. }
  16550. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  16551. var start = (font.start ? font.start : 0) + post.offset;
  16552. font.pos = start;
  16553. var length = post.length, end = start + length;
  16554. var version = font.getInt32();
  16555. // skip rest to the tables
  16556. font.getBytes(28);
  16557. var glyphNames;
  16558. var valid = true;
  16559. var i;
  16560. switch (version) {
  16561. case 0x00010000:
  16562. glyphNames = MacStandardGlyphOrdering;
  16563. break;
  16564. case 0x00020000:
  16565. var numGlyphs = font.getUint16();
  16566. if (numGlyphs !== maxpNumGlyphs) {
  16567. valid = false;
  16568. break;
  16569. }
  16570. var glyphNameIndexes = [];
  16571. for (i = 0; i < numGlyphs; ++i) {
  16572. var index = font.getUint16();
  16573. if (index >= 32768) {
  16574. valid = false;
  16575. break;
  16576. }
  16577. glyphNameIndexes.push(index);
  16578. }
  16579. if (!valid) {
  16580. break;
  16581. }
  16582. var customNames = [];
  16583. var strBuf = [];
  16584. while (font.pos < end) {
  16585. var stringLength = font.getByte();
  16586. strBuf.length = stringLength;
  16587. for (i = 0; i < stringLength; ++i) {
  16588. strBuf[i] = String.fromCharCode(font.getByte());
  16589. }
  16590. customNames.push(strBuf.join(''));
  16591. }
  16592. glyphNames = [];
  16593. for (i = 0; i < numGlyphs; ++i) {
  16594. var j = glyphNameIndexes[i];
  16595. if (j < 258) {
  16596. glyphNames.push(MacStandardGlyphOrdering[j]);
  16597. continue;
  16598. }
  16599. glyphNames.push(customNames[j - 258]);
  16600. }
  16601. break;
  16602. case 0x00030000:
  16603. break;
  16604. default:
  16605. warn('Unknown/unsupported post table version ' + version);
  16606. valid = false;
  16607. if (properties.defaultEncoding) {
  16608. glyphNames = properties.defaultEncoding;
  16609. }
  16610. break;
  16611. }
  16612. properties.glyphNames = glyphNames;
  16613. return valid;
  16614. }
  16615. function readNameTable(nameTable) {
  16616. var start = (font.start ? font.start : 0) + nameTable.offset;
  16617. font.pos = start;
  16618. var names = [[], []];
  16619. var length = nameTable.length, end = start + length;
  16620. var format = font.getUint16();
  16621. var FORMAT_0_HEADER_LENGTH = 6;
  16622. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  16623. // unsupported name table format or table "too" small
  16624. return names;
  16625. }
  16626. var numRecords = font.getUint16();
  16627. var stringsStart = font.getUint16();
  16628. var records = [];
  16629. var NAME_RECORD_LENGTH = 12;
  16630. var i, ii;
  16631. for (i = 0; i < numRecords &&
  16632. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  16633. var r = {
  16634. platform: font.getUint16(),
  16635. encoding: font.getUint16(),
  16636. language: font.getUint16(),
  16637. name: font.getUint16(),
  16638. length: font.getUint16(),
  16639. offset: font.getUint16()
  16640. };
  16641. // using only Macintosh and Windows platform/encoding names
  16642. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  16643. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  16644. records.push(r);
  16645. }
  16646. }
  16647. for (i = 0, ii = records.length; i < ii; i++) {
  16648. var record = records[i];
  16649. var pos = start + stringsStart + record.offset;
  16650. if (pos + record.length > end) {
  16651. continue; // outside of name table, ignoring
  16652. }
  16653. font.pos = pos;
  16654. var nameIndex = record.name;
  16655. if (record.encoding) {
  16656. // unicode
  16657. var str = '';
  16658. for (var j = 0, jj = record.length; j < jj; j += 2) {
  16659. str += String.fromCharCode(font.getUint16());
  16660. }
  16661. names[1][nameIndex] = str;
  16662. } else {
  16663. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  16664. }
  16665. }
  16666. return names;
  16667. }
  16668. var TTOpsStackDeltas = [
  16669. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  16670. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  16671. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  16672. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  16673. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  16674. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  16675. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  16676. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  16677. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  16678. // 0xC0-DF == -1 and 0xE0-FF == -2
  16679. function sanitizeTTProgram(table, ttContext) {
  16680. var data = table.data;
  16681. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  16682. var stack = [];
  16683. var callstack = [];
  16684. var functionsCalled = [];
  16685. var tooComplexToFollowFunctions =
  16686. ttContext.tooComplexToFollowFunctions;
  16687. var inFDEF = false, ifLevel = 0, inELSE = 0;
  16688. for (var ii = data.length; i < ii;) {
  16689. var op = data[i++];
  16690. // The TrueType instruction set docs can be found at
  16691. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  16692. if (op === 0x40) { // NPUSHB - pushes n bytes
  16693. n = data[i++];
  16694. if (inFDEF || inELSE) {
  16695. i += n;
  16696. } else {
  16697. for (j = 0; j < n; j++) {
  16698. stack.push(data[i++]);
  16699. }
  16700. }
  16701. } else if (op === 0x41) { // NPUSHW - pushes n words
  16702. n = data[i++];
  16703. if (inFDEF || inELSE) {
  16704. i += n * 2;
  16705. } else {
  16706. for (j = 0; j < n; j++) {
  16707. b = data[i++];
  16708. stack.push((b << 8) | data[i++]);
  16709. }
  16710. }
  16711. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  16712. n = op - 0xB0 + 1;
  16713. if (inFDEF || inELSE) {
  16714. i += n;
  16715. } else {
  16716. for (j = 0; j < n; j++) {
  16717. stack.push(data[i++]);
  16718. }
  16719. }
  16720. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  16721. n = op - 0xB8 + 1;
  16722. if (inFDEF || inELSE) {
  16723. i += n * 2;
  16724. } else {
  16725. for (j = 0; j < n; j++) {
  16726. b = data[i++];
  16727. stack.push((b << 8) | data[i++]);
  16728. }
  16729. }
  16730. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  16731. if (!inFDEF && !inELSE) {
  16732. // collecting inforamtion about which functions are used
  16733. funcId = stack[stack.length - 1];
  16734. ttContext.functionsUsed[funcId] = true;
  16735. if (funcId in ttContext.functionsStackDeltas) {
  16736. stack.length += ttContext.functionsStackDeltas[funcId];
  16737. } else if (funcId in ttContext.functionsDefined &&
  16738. functionsCalled.indexOf(funcId) < 0) {
  16739. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  16740. functionsCalled.push(funcId);
  16741. pc = ttContext.functionsDefined[funcId];
  16742. if (!pc) {
  16743. warn('TT: CALL non-existent function');
  16744. ttContext.hintsValid = false;
  16745. return;
  16746. }
  16747. data = pc.data;
  16748. i = pc.i;
  16749. }
  16750. }
  16751. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  16752. if (inFDEF || inELSE) {
  16753. warn('TT: nested FDEFs not allowed');
  16754. tooComplexToFollowFunctions = true;
  16755. }
  16756. inFDEF = true;
  16757. // collecting inforamtion about which functions are defined
  16758. lastDeff = i;
  16759. funcId = stack.pop();
  16760. ttContext.functionsDefined[funcId] = {data: data, i: i};
  16761. } else if (op === 0x2D) { // ENDF - end of function
  16762. if (inFDEF) {
  16763. inFDEF = false;
  16764. lastEndf = i;
  16765. } else {
  16766. pc = callstack.pop();
  16767. if (!pc) {
  16768. warn('TT: ENDF bad stack');
  16769. ttContext.hintsValid = false;
  16770. return;
  16771. }
  16772. funcId = functionsCalled.pop();
  16773. data = pc.data;
  16774. i = pc.i;
  16775. ttContext.functionsStackDeltas[funcId] =
  16776. stack.length - pc.stackTop;
  16777. }
  16778. } else if (op === 0x89) { // IDEF - instruction definition
  16779. if (inFDEF || inELSE) {
  16780. warn('TT: nested IDEFs not allowed');
  16781. tooComplexToFollowFunctions = true;
  16782. }
  16783. inFDEF = true;
  16784. // recording it as a function to track ENDF
  16785. lastDeff = i;
  16786. } else if (op === 0x58) { // IF
  16787. ++ifLevel;
  16788. } else if (op === 0x1B) { // ELSE
  16789. inELSE = ifLevel;
  16790. } else if (op === 0x59) { // EIF
  16791. if (inELSE === ifLevel) {
  16792. inELSE = 0;
  16793. }
  16794. --ifLevel;
  16795. } else if (op === 0x1C) { // JMPR
  16796. if (!inFDEF && !inELSE) {
  16797. var offset = stack[stack.length - 1];
  16798. // only jumping forward to prevent infinite loop
  16799. if (offset > 0) {
  16800. i += offset - 1;
  16801. }
  16802. }
  16803. }
  16804. // Adjusting stack not extactly, but just enough to get function id
  16805. if (!inFDEF && !inELSE) {
  16806. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  16807. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  16808. if (op >= 0x71 && op <= 0x75) {
  16809. n = stack.pop();
  16810. if (n === n) {
  16811. stackDelta = -n * 2;
  16812. }
  16813. }
  16814. while (stackDelta < 0 && stack.length > 0) {
  16815. stack.pop();
  16816. stackDelta++;
  16817. }
  16818. while (stackDelta > 0) {
  16819. stack.push(NaN); // pushing any number into stack
  16820. stackDelta--;
  16821. }
  16822. }
  16823. }
  16824. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  16825. var content = [data];
  16826. if (i > data.length) {
  16827. content.push(new Uint8Array(i - data.length));
  16828. }
  16829. if (lastDeff > lastEndf) {
  16830. warn('TT: complementing a missing function tail');
  16831. // new function definition started, but not finished
  16832. // complete function by [CLEAR, ENDF]
  16833. content.push(new Uint8Array([0x22, 0x2D]));
  16834. }
  16835. foldTTTable(table, content);
  16836. }
  16837. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  16838. if (ttContext.tooComplexToFollowFunctions) {
  16839. return;
  16840. }
  16841. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  16842. warn('TT: more functions defined than expected');
  16843. ttContext.hintsValid = false;
  16844. return;
  16845. }
  16846. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  16847. if (j > maxFunctionDefs) {
  16848. warn('TT: invalid function id: ' + j);
  16849. ttContext.hintsValid = false;
  16850. return;
  16851. }
  16852. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  16853. warn('TT: undefined function: ' + j);
  16854. ttContext.hintsValid = false;
  16855. return;
  16856. }
  16857. }
  16858. }
  16859. function foldTTTable(table, content) {
  16860. if (content.length > 1) {
  16861. // concatenating the content items
  16862. var newLength = 0;
  16863. var j, jj;
  16864. for (j = 0, jj = content.length; j < jj; j++) {
  16865. newLength += content[j].length;
  16866. }
  16867. newLength = (newLength + 3) & ~3;
  16868. var result = new Uint8Array(newLength);
  16869. var pos = 0;
  16870. for (j = 0, jj = content.length; j < jj; j++) {
  16871. result.set(content[j], pos);
  16872. pos += content[j].length;
  16873. }
  16874. table.data = result;
  16875. table.length = newLength;
  16876. }
  16877. }
  16878. function sanitizeTTPrograms(fpgm, prep, cvt) {
  16879. var ttContext = {
  16880. functionsDefined: [],
  16881. functionsUsed: [],
  16882. functionsStackDeltas: [],
  16883. tooComplexToFollowFunctions: false,
  16884. hintsValid: true
  16885. };
  16886. if (fpgm) {
  16887. sanitizeTTProgram(fpgm, ttContext);
  16888. }
  16889. if (prep) {
  16890. sanitizeTTProgram(prep, ttContext);
  16891. }
  16892. if (fpgm) {
  16893. checkInvalidFunctions(ttContext, maxFunctionDefs);
  16894. }
  16895. if (cvt && (cvt.length & 1)) {
  16896. var cvtData = new Uint8Array(cvt.length + 1);
  16897. cvtData.set(cvt.data);
  16898. cvt.data = cvtData;
  16899. }
  16900. return ttContext.hintsValid;
  16901. }
  16902. // The following steps modify the original font data, making copy
  16903. font = new Stream(new Uint8Array(font.getBytes()));
  16904. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  16905. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  16906. var header = readOpenTypeHeader(font);
  16907. var numTables = header.numTables;
  16908. var cff, cffFile;
  16909. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  16910. hmtx: null, maxp: null, name: null, post: null };
  16911. var table;
  16912. for (var i = 0; i < numTables; i++) {
  16913. table = readTableEntry(font);
  16914. if (VALID_TABLES.indexOf(table.tag) < 0) {
  16915. continue; // skipping table if it's not a required or optional table
  16916. }
  16917. if (table.length === 0) {
  16918. continue; // skipping empty tables
  16919. }
  16920. tables[table.tag] = table;
  16921. }
  16922. var isTrueType = !tables['CFF '];
  16923. if (!isTrueType) {
  16924. // OpenType font
  16925. if (header.version === 'OTTO' ||
  16926. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  16927. // no major tables: throwing everything at CFFFont
  16928. cffFile = new Stream(tables['CFF '].data);
  16929. cff = new CFFFont(cffFile, properties);
  16930. return this.convert(name, cff, properties);
  16931. }
  16932. delete tables.glyf;
  16933. delete tables.loca;
  16934. delete tables.fpgm;
  16935. delete tables.prep;
  16936. delete tables['cvt '];
  16937. this.isOpenType = true;
  16938. } else {
  16939. if (!tables.glyf || !tables.loca) {
  16940. error('Required "glyf" or "loca" tables are not found');
  16941. }
  16942. this.isOpenType = false;
  16943. }
  16944. if (!tables.maxp) {
  16945. error('Required "maxp" table is not found');
  16946. }
  16947. font.pos = (font.start || 0) + tables.maxp.offset;
  16948. var version = font.getInt32();
  16949. var numGlyphs = font.getUint16();
  16950. var maxFunctionDefs = 0;
  16951. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  16952. // maxZones can be invalid
  16953. font.pos += 8;
  16954. var maxZones = font.getUint16();
  16955. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  16956. tables.maxp.data[14] = 0;
  16957. tables.maxp.data[15] = 2;
  16958. }
  16959. font.pos += 4;
  16960. maxFunctionDefs = font.getUint16();
  16961. }
  16962. var dupFirstEntry = false;
  16963. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  16964. properties.toUnicode.get(0) > '\u0000') {
  16965. // oracle's defect (see 3427), duplicating first entry
  16966. dupFirstEntry = true;
  16967. numGlyphs++;
  16968. tables.maxp.data[4] = numGlyphs >> 8;
  16969. tables.maxp.data[5] = numGlyphs & 255;
  16970. }
  16971. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  16972. tables['cvt '], maxFunctionDefs);
  16973. if (!hintsValid) {
  16974. delete tables.fpgm;
  16975. delete tables.prep;
  16976. delete tables['cvt '];
  16977. }
  16978. // Ensure the hmtx table contains the advance width and
  16979. // sidebearings information for numGlyphs in the maxp table
  16980. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  16981. if (!tables.head) {
  16982. error('Required "head" table is not found');
  16983. }
  16984. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  16985. var missingGlyphs = {};
  16986. if (isTrueType) {
  16987. var isGlyphLocationsLong = int16(tables.head.data[50],
  16988. tables.head.data[51]);
  16989. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  16990. numGlyphs, isGlyphLocationsLong,
  16991. hintsValid, dupFirstEntry);
  16992. }
  16993. if (!tables.hhea) {
  16994. error('Required "hhea" table is not found');
  16995. }
  16996. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  16997. // Sometimes it's 0. That needs to be fixed
  16998. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  16999. tables.hhea.data[10] = 0xFF;
  17000. tables.hhea.data[11] = 0xFF;
  17001. }
  17002. // The 'post' table has glyphs names.
  17003. if (tables.post) {
  17004. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  17005. if (!valid) {
  17006. tables.post = null;
  17007. }
  17008. }
  17009. var charCodeToGlyphId = [], charCode;
  17010. var toUnicode = properties.toUnicode, widths = properties.widths;
  17011. var isIdentityUnicode = toUnicode instanceof IdentityToUnicodeMap;
  17012. function hasGlyph(glyphId, charCode, widthCode) {
  17013. if (!missingGlyphs[glyphId]) {
  17014. return true;
  17015. }
  17016. if (!isIdentityUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  17017. return true;
  17018. }
  17019. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  17020. return true;
  17021. }
  17022. return false;
  17023. }
  17024. if (properties.type === 'CIDFontType2') {
  17025. var cidToGidMap = properties.cidToGidMap || [];
  17026. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  17027. properties.cMap.forEach(function(charCode, cid) {
  17028. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17029. var glyphId = -1;
  17030. if (isCidToGidMapEmpty) {
  17031. glyphId = charCode;
  17032. } else if (cidToGidMap[cid] !== undefined) {
  17033. glyphId = cidToGidMap[cid];
  17034. }
  17035. if (glyphId >= 0 && glyphId < numGlyphs &&
  17036. hasGlyph(glyphId, charCode, cid)) {
  17037. charCodeToGlyphId[charCode] = glyphId;
  17038. }
  17039. });
  17040. if (dupFirstEntry) {
  17041. charCodeToGlyphId[0] = numGlyphs - 1;
  17042. }
  17043. } else {
  17044. // Most of the following logic in this code branch is based on the
  17045. // 9.6.6.4 of the PDF spec.
  17046. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  17047. var cmapPlatformId = cmapTable.platformId;
  17048. var cmapEncodingId = cmapTable.encodingId;
  17049. var cmapMappings = cmapTable.mappings;
  17050. var cmapMappingsLength = cmapMappings.length;
  17051. var hasEncoding = properties.differences.length ||
  17052. !!properties.baseEncodingName;
  17053. // The spec seems to imply that if the font is symbolic the encoding
  17054. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  17055. // where the the font is symbolic and it has an encoding.
  17056. if (hasEncoding &&
  17057. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  17058. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  17059. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  17060. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  17061. // When no preferred cmap table was found and |baseEncodingName| is
  17062. // one of the predefined encodings, we seem to obtain a better
  17063. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  17064. // TODO: Note that this is a hack which should be removed as soon as
  17065. // we have proper support for more exotic cmap tables.
  17066. var baseEncoding = [];
  17067. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  17068. properties.baseEncodingName === 'WinAnsiEncoding') {
  17069. baseEncoding = Encodings[properties.baseEncodingName];
  17070. }
  17071. for (charCode = 0; charCode < 256; charCode++) {
  17072. var glyphName;
  17073. if (this.differences && charCode in this.differences) {
  17074. glyphName = this.differences[charCode];
  17075. } else if (charCode in baseEncoding &&
  17076. baseEncoding[charCode] !== '') {
  17077. glyphName = baseEncoding[charCode];
  17078. } else {
  17079. glyphName = Encodings.StandardEncoding[charCode];
  17080. }
  17081. if (!glyphName) {
  17082. continue;
  17083. }
  17084. var unicodeOrCharCode;
  17085. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  17086. unicodeOrCharCode = GlyphsUnicode[glyphName];
  17087. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  17088. // TODO: the encoding needs to be updated with mac os table.
  17089. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  17090. }
  17091. var found = false;
  17092. for (i = 0; i < cmapMappingsLength; ++i) {
  17093. if (cmapMappings[i].charCode === unicodeOrCharCode &&
  17094. hasGlyph(cmapMappings[i].glyphId, unicodeOrCharCode, -1)) {
  17095. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17096. found = true;
  17097. break;
  17098. }
  17099. }
  17100. if (!found && properties.glyphNames) {
  17101. // Try to map using the post table.
  17102. var glyphId = properties.glyphNames.indexOf(glyphName);
  17103. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  17104. charCodeToGlyphId[charCode] = glyphId;
  17105. } else {
  17106. charCodeToGlyphId[charCode] = 0; // notdef
  17107. }
  17108. }
  17109. }
  17110. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  17111. // Default Unicode semantics, use the charcodes as is.
  17112. for (i = 0; i < cmapMappingsLength; ++i) {
  17113. charCodeToGlyphId[cmapMappings[i].charCode] =
  17114. cmapMappings[i].glyphId;
  17115. }
  17116. } else {
  17117. // For (3, 0) cmap tables:
  17118. // The charcode key being stored in charCodeToGlyphId is the lower
  17119. // byte of the two-byte charcodes of the cmap table since according to
  17120. // the spec: 'each byte from the string shall be prepended with the
  17121. // high byte of the range [of charcodes in the cmap table], to form
  17122. // a two-byte character, which shall be used to select the
  17123. // associated glyph description from the subtable'.
  17124. //
  17125. // For (1, 0) cmap tables:
  17126. // 'single bytes from the string shall be used to look up the
  17127. // associated glyph descriptions from the subtable'. This means
  17128. // charcodes in the cmap will be single bytes, so no-op since
  17129. // glyph.charCode & 0xFF === glyph.charCode
  17130. for (i = 0; i < cmapMappingsLength; ++i) {
  17131. charCode = cmapMappings[i].charCode & 0xFF;
  17132. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  17133. }
  17134. }
  17135. }
  17136. if (charCodeToGlyphId.length === 0) {
  17137. // defines at least one glyph
  17138. charCodeToGlyphId[0] = 0;
  17139. }
  17140. // Converting glyphs and ids into font's cmap table
  17141. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  17142. this.toFontChar = newMapping.toFontChar;
  17143. tables.cmap = {
  17144. tag: 'cmap',
  17145. data: createCmapTable(newMapping.charCodeToGlyphId)
  17146. };
  17147. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  17148. // extract some more font properties from the OpenType head and
  17149. // hhea tables; yMin and descent value are always negative
  17150. var override = {
  17151. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  17152. yMax: int16(tables.head.data[42], tables.head.data[43]),
  17153. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  17154. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  17155. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  17156. };
  17157. tables['OS/2'] = {
  17158. tag: 'OS/2',
  17159. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  17160. override)
  17161. };
  17162. }
  17163. // Rewrite the 'post' table if needed
  17164. if (!tables.post) {
  17165. tables.post = {
  17166. tag: 'post',
  17167. data: createPostTable(properties)
  17168. };
  17169. }
  17170. if (!isTrueType) {
  17171. try {
  17172. // Trying to repair CFF file
  17173. cffFile = new Stream(tables['CFF '].data);
  17174. var parser = new CFFParser(cffFile, properties);
  17175. cff = parser.parse();
  17176. var compiler = new CFFCompiler(cff);
  17177. tables['CFF '].data = compiler.compile();
  17178. } catch (e) {
  17179. warn('Failed to compile font ' + properties.loadedName);
  17180. }
  17181. }
  17182. // Re-creating 'name' table
  17183. if (!tables.name) {
  17184. tables.name = {
  17185. tag: 'name',
  17186. data: createNameTable(this.name)
  17187. };
  17188. } else {
  17189. // ... using existing 'name' table as prototype
  17190. var namePrototype = readNameTable(tables.name);
  17191. tables.name.data = createNameTable(name, namePrototype);
  17192. }
  17193. var builder = new OpenTypeFileBuilder(header.version);
  17194. for (var tableTag in tables) {
  17195. builder.addTable(tableTag, tables[tableTag].data);
  17196. }
  17197. return builder.toArray();
  17198. },
  17199. convert: function Font_convert(fontName, font, properties) {
  17200. // TODO: Check the charstring widths to determine this.
  17201. properties.fixedPitch = false;
  17202. var mapping = font.getGlyphMapping(properties);
  17203. var newMapping = adjustMapping(mapping, properties);
  17204. this.toFontChar = newMapping.toFontChar;
  17205. var numGlyphs = font.numGlyphs;
  17206. function getCharCodes(charCodeToGlyphId, glyphId) {
  17207. var charCodes = null;
  17208. for (var charCode in charCodeToGlyphId) {
  17209. if (glyphId === charCodeToGlyphId[charCode]) {
  17210. if (!charCodes) {
  17211. charCodes = [];
  17212. }
  17213. charCodes.push(charCode | 0);
  17214. }
  17215. }
  17216. return charCodes;
  17217. }
  17218. function createCharCode(charCodeToGlyphId, glyphId) {
  17219. for (var charCode in charCodeToGlyphId) {
  17220. if (glyphId === charCodeToGlyphId[charCode]) {
  17221. return charCode | 0;
  17222. }
  17223. }
  17224. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  17225. glyphId;
  17226. return newMapping.nextAvailableFontCharCode++;
  17227. }
  17228. var seacs = font.seacs;
  17229. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  17230. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  17231. var charset = font.getCharset();
  17232. var seacMap = Object.create(null);
  17233. for (var glyphId in seacs) {
  17234. glyphId |= 0;
  17235. var seac = seacs[glyphId];
  17236. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  17237. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  17238. var baseGlyphId = charset.indexOf(baseGlyphName);
  17239. var accentGlyphId = charset.indexOf(accentGlyphName);
  17240. if (baseGlyphId < 0 || accentGlyphId < 0) {
  17241. continue;
  17242. }
  17243. var accentOffset = {
  17244. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  17245. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  17246. };
  17247. var charCodes = getCharCodes(mapping, glyphId);
  17248. if (!charCodes) {
  17249. // There's no point in mapping it if the char code was never mapped
  17250. // to begin with.
  17251. continue;
  17252. }
  17253. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  17254. var charCode = charCodes[i];
  17255. // Find a fontCharCode that maps to the base and accent glyphs.
  17256. // If one doesn't exists, create it.
  17257. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  17258. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  17259. baseGlyphId);
  17260. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  17261. accentGlyphId);
  17262. seacMap[charCode] = {
  17263. baseFontCharCode: baseFontCharCode,
  17264. accentFontCharCode: accentFontCharCode,
  17265. accentOffset: accentOffset
  17266. };
  17267. }
  17268. }
  17269. properties.seacMap = seacMap;
  17270. }
  17271. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  17272. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  17273. // PostScript Font Program
  17274. builder.addTable('CFF ', font.data);
  17275. // OS/2 and Windows Specific metrics
  17276. builder.addTable('OS/2', createOS2Table(properties,
  17277. newMapping.charCodeToGlyphId));
  17278. // Character to glyphs mapping
  17279. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId));
  17280. // Font header
  17281. builder.addTable('head',
  17282. '\x00\x01\x00\x00' + // Version number
  17283. '\x00\x00\x10\x00' + // fontRevision
  17284. '\x00\x00\x00\x00' + // checksumAdjustement
  17285. '\x5F\x0F\x3C\xF5' + // magicNumber
  17286. '\x00\x00' + // Flags
  17287. safeString16(unitsPerEm) + // unitsPerEM
  17288. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  17289. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  17290. '\x00\x00' + // xMin
  17291. safeString16(properties.descent) + // yMin
  17292. '\x0F\xFF' + // xMax
  17293. safeString16(properties.ascent) + // yMax
  17294. string16(properties.italicAngle ? 2 : 0) + // macStyle
  17295. '\x00\x11' + // lowestRecPPEM
  17296. '\x00\x00' + // fontDirectionHint
  17297. '\x00\x00' + // indexToLocFormat
  17298. '\x00\x00'); // glyphDataFormat
  17299. // Horizontal header
  17300. builder.addTable('hhea',
  17301. '\x00\x01\x00\x00' + // Version number
  17302. safeString16(properties.ascent) + // Typographic Ascent
  17303. safeString16(properties.descent) + // Typographic Descent
  17304. '\x00\x00' + // Line Gap
  17305. '\xFF\xFF' + // advanceWidthMax
  17306. '\x00\x00' + // minLeftSidebearing
  17307. '\x00\x00' + // minRightSidebearing
  17308. '\x00\x00' + // xMaxExtent
  17309. safeString16(properties.capHeight) + // caretSlopeRise
  17310. safeString16(Math.tan(properties.italicAngle) *
  17311. properties.xHeight) + // caretSlopeRun
  17312. '\x00\x00' + // caretOffset
  17313. '\x00\x00' + // -reserved-
  17314. '\x00\x00' + // -reserved-
  17315. '\x00\x00' + // -reserved-
  17316. '\x00\x00' + // -reserved-
  17317. '\x00\x00' + // metricDataFormat
  17318. string16(numGlyphs)); // Number of HMetrics
  17319. // Horizontal metrics
  17320. builder.addTable('hmtx', (function fontFieldsHmtx() {
  17321. var charstrings = font.charstrings;
  17322. var cffWidths = font.cff ? font.cff.widths : null;
  17323. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  17324. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  17325. var width = 0;
  17326. if (charstrings) {
  17327. var charstring = charstrings[i - 1];
  17328. width = 'width' in charstring ? charstring.width : 0;
  17329. } else if (cffWidths) {
  17330. width = Math.ceil(cffWidths[i] || 0);
  17331. }
  17332. hmtx += string16(width) + string16(0);
  17333. }
  17334. return hmtx;
  17335. })());
  17336. // Maximum profile
  17337. builder.addTable('maxp',
  17338. '\x00\x00\x50\x00' + // Version number
  17339. string16(numGlyphs)); // Num of glyphs
  17340. // Naming tables
  17341. builder.addTable('name', createNameTable(fontName));
  17342. // PostScript informations
  17343. builder.addTable('post', createPostTable(properties));
  17344. return builder.toArray();
  17345. },
  17346. /**
  17347. * Builds a char code to unicode map based on section 9.10 of the spec.
  17348. * @param {Object} properties Font properties object.
  17349. * @return {Object} A ToUnicodeMap object.
  17350. */
  17351. buildToUnicode: function Font_buildToUnicode(properties) {
  17352. // Section 9.10.2 Mapping Character Codes to Unicode Values
  17353. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  17354. return properties.toUnicode;
  17355. }
  17356. // According to the spec if the font is a simple font we should only map
  17357. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  17358. // the differences array only contains adobe standard or symbol set names,
  17359. // in pratice it seems better to always try to create a toUnicode
  17360. // map based of the default encoding.
  17361. var toUnicode, charcode;
  17362. if (!properties.composite /* is simple font */) {
  17363. toUnicode = [];
  17364. var encoding = properties.defaultEncoding.slice();
  17365. var baseEncodingName = properties.baseEncodingName;
  17366. // Merge in the differences array.
  17367. var differences = properties.differences;
  17368. for (charcode in differences) {
  17369. encoding[charcode] = differences[charcode];
  17370. }
  17371. for (charcode in encoding) {
  17372. // a) Map the character code to a character name.
  17373. var glyphName = encoding[charcode];
  17374. // b) Look up the character name in the Adobe Glyph List (see the
  17375. // Bibliography) to obtain the corresponding Unicode value.
  17376. if (glyphName === '') {
  17377. continue;
  17378. } else if (GlyphsUnicode[glyphName] === undefined) {
  17379. // (undocumented) c) Few heuristics to recognize unknown glyphs
  17380. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  17381. var code = 0;
  17382. switch (glyphName[0]) {
  17383. case 'G': // Gxx glyph
  17384. if (glyphName.length === 3) {
  17385. code = parseInt(glyphName.substr(1), 16);
  17386. }
  17387. break;
  17388. case 'g': // g00xx glyph
  17389. if (glyphName.length === 5) {
  17390. code = parseInt(glyphName.substr(1), 16);
  17391. }
  17392. break;
  17393. case 'C': // Cddd glyph
  17394. case 'c': // cddd glyph
  17395. if (glyphName.length >= 3) {
  17396. code = +glyphName.substr(1);
  17397. }
  17398. break;
  17399. }
  17400. if (code) {
  17401. // If |baseEncodingName| is one the predefined encodings,
  17402. // and |code| equals |charcode|, using the glyph defined in the
  17403. // baseEncoding seems to yield a better |toUnicode| mapping
  17404. // (fixes issue 5070).
  17405. if (baseEncodingName && code === +charcode) {
  17406. var baseEncoding = Encodings[baseEncodingName];
  17407. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  17408. toUnicode[charcode] =
  17409. String.fromCharCode(GlyphsUnicode[glyphName]);
  17410. continue;
  17411. }
  17412. }
  17413. toUnicode[charcode] = String.fromCharCode(code);
  17414. }
  17415. continue;
  17416. }
  17417. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  17418. }
  17419. return new ToUnicodeMap(toUnicode);
  17420. }
  17421. // If the font is a composite font that uses one of the predefined CMaps
  17422. // listed in Table 118 (except Identity–H and Identity–V) or whose
  17423. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  17424. // Adobe-Korea1 character collection:
  17425. if (properties.composite && (
  17426. (properties.cMap.builtInCMap &&
  17427. !(properties.cMap instanceof IdentityCMap)) ||
  17428. (properties.cidSystemInfo.registry === 'Adobe' &&
  17429. (properties.cidSystemInfo.ordering === 'GB1' ||
  17430. properties.cidSystemInfo.ordering === 'CNS1' ||
  17431. properties.cidSystemInfo.ordering === 'Japan1' ||
  17432. properties.cidSystemInfo.ordering === 'Korea1')))) {
  17433. // Then:
  17434. // a) Map the character code to a character identifier (CID) according
  17435. // to the font’s CMap.
  17436. // b) Obtain the registry and ordering of the character collection used
  17437. // by the font’s CMap (for example, Adobe and Japan1) from its
  17438. // CIDSystemInfo dictionary.
  17439. var registry = properties.cidSystemInfo.registry;
  17440. var ordering = properties.cidSystemInfo.ordering;
  17441. // c) Construct a second CMap name by concatenating the registry and
  17442. // ordering obtained in step (b) in the format registry–ordering–UCS2
  17443. // (for example, Adobe–Japan1–UCS2).
  17444. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  17445. // d) Obtain the CMap with the name constructed in step (c) (available
  17446. // from the ASN Web site; see the Bibliography).
  17447. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  17448. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  17449. var cMap = properties.cMap;
  17450. toUnicode = [];
  17451. cMap.forEach(function(charcode, cid) {
  17452. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  17453. // e) Map the CID obtained in step (a) according to the CMap obtained
  17454. // in step (d), producing a Unicode value.
  17455. var ucs2 = ucs2CMap.lookup(cid);
  17456. if (ucs2) {
  17457. toUnicode[charcode] =
  17458. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  17459. ucs2.charCodeAt(1));
  17460. }
  17461. });
  17462. return new ToUnicodeMap(toUnicode);
  17463. }
  17464. // The viewer's choice, just use an identity map.
  17465. return new IdentityToUnicodeMap(properties.firstChar,
  17466. properties.lastChar);
  17467. },
  17468. get spaceWidth() {
  17469. if ('_shadowWidth' in this) {
  17470. return this._shadowWidth;
  17471. }
  17472. // trying to estimate space character width
  17473. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  17474. var width;
  17475. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  17476. var glyphName = possibleSpaceReplacements[i];
  17477. // if possible, getting width by glyph name
  17478. if (glyphName in this.widths) {
  17479. width = this.widths[glyphName];
  17480. break;
  17481. }
  17482. var glyphUnicode = GlyphsUnicode[glyphName];
  17483. // finding the charcode via unicodeToCID map
  17484. var charcode = 0;
  17485. if (this.composite) {
  17486. if (this.cMap.contains(glyphUnicode)) {
  17487. charcode = this.cMap.lookup(glyphUnicode);
  17488. }
  17489. }
  17490. // ... via toUnicode map
  17491. if (!charcode && 'toUnicode' in this) {
  17492. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  17493. }
  17494. // setting it to unicode if negative or undefined
  17495. if (charcode <= 0) {
  17496. charcode = glyphUnicode;
  17497. }
  17498. // trying to get width via charcode
  17499. width = this.widths[charcode];
  17500. if (width) {
  17501. break; // the non-zero width found
  17502. }
  17503. }
  17504. width = width || this.defaultWidth;
  17505. // Do not shadow the property here. See discussion:
  17506. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  17507. this._shadowWidth = width;
  17508. return width;
  17509. },
  17510. charToGlyph: function Font_charToGlyph(charcode) {
  17511. var fontCharCode, width, operatorListId;
  17512. var widthCode = charcode;
  17513. if (this.cMap && this.cMap.contains(charcode)) {
  17514. widthCode = this.cMap.lookup(charcode);
  17515. }
  17516. width = this.widths[widthCode];
  17517. width = isNum(width) ? width : this.defaultWidth;
  17518. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  17519. var unicode = this.toUnicode.get(charcode) || charcode;
  17520. if (typeof unicode === 'number') {
  17521. unicode = String.fromCharCode(unicode);
  17522. }
  17523. // First try the toFontChar map, if it's not there then try falling
  17524. // back to the char code.
  17525. fontCharCode = this.toFontChar[charcode] || charcode;
  17526. if (this.missingFile) {
  17527. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  17528. }
  17529. if (this.isType3Font) {
  17530. // Font char code in this case is actually a glyph name.
  17531. operatorListId = fontCharCode;
  17532. }
  17533. var accent = null;
  17534. if (this.seacMap && this.seacMap[charcode]) {
  17535. var seac = this.seacMap[charcode];
  17536. fontCharCode = seac.baseFontCharCode;
  17537. accent = {
  17538. fontChar: String.fromCharCode(seac.accentFontCharCode),
  17539. offset: seac.accentOffset
  17540. };
  17541. }
  17542. var fontChar = String.fromCharCode(fontCharCode);
  17543. var glyph = this.glyphCache[charcode];
  17544. if (!glyph ||
  17545. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  17546. operatorListId)) {
  17547. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  17548. operatorListId);
  17549. this.glyphCache[charcode] = glyph;
  17550. }
  17551. return glyph;
  17552. },
  17553. charsToGlyphs: function Font_charsToGlyphs(chars) {
  17554. var charsCache = this.charsCache;
  17555. var glyphs, glyph, charcode;
  17556. // if we translated this string before, just grab it from the cache
  17557. if (charsCache) {
  17558. glyphs = charsCache[chars];
  17559. if (glyphs) {
  17560. return glyphs;
  17561. }
  17562. }
  17563. // lazily create the translation cache
  17564. if (!charsCache) {
  17565. charsCache = this.charsCache = Object.create(null);
  17566. }
  17567. glyphs = [];
  17568. var charsCacheKey = chars;
  17569. var i = 0, ii;
  17570. if (this.cMap) {
  17571. // composite fonts have multi-byte strings convert the string from
  17572. // single-byte to multi-byte
  17573. var c = {};
  17574. while (i < chars.length) {
  17575. this.cMap.readCharCode(chars, i, c);
  17576. charcode = c.charcode;
  17577. var length = c.length;
  17578. i += length;
  17579. glyph = this.charToGlyph(charcode);
  17580. glyphs.push(glyph);
  17581. // placing null after each word break charcode (ASCII SPACE)
  17582. // Ignore occurences of 0x20 in multiple-byte codes.
  17583. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  17584. glyphs.push(null);
  17585. }
  17586. }
  17587. } else {
  17588. for (i = 0, ii = chars.length; i < ii; ++i) {
  17589. charcode = chars.charCodeAt(i);
  17590. glyph = this.charToGlyph(charcode);
  17591. glyphs.push(glyph);
  17592. if (charcode === 0x20) {
  17593. glyphs.push(null);
  17594. }
  17595. }
  17596. }
  17597. // Enter the translated string into the cache
  17598. return (charsCache[charsCacheKey] = glyphs);
  17599. }
  17600. };
  17601. return Font;
  17602. })();
  17603. var ErrorFont = (function ErrorFontClosure() {
  17604. function ErrorFont(error) {
  17605. this.error = error;
  17606. this.loadedName = 'g_font_error';
  17607. this.loading = false;
  17608. }
  17609. ErrorFont.prototype = {
  17610. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  17611. return [];
  17612. },
  17613. exportData: function ErrorFont_exportData() {
  17614. return {error: this.error};
  17615. }
  17616. };
  17617. return ErrorFont;
  17618. })();
  17619. /**
  17620. * Shared logic for building a char code to glyph id mapping for Type1 and
  17621. * simple CFF fonts. See section 9.6.6.2 of the spec.
  17622. * @param {Object} properties Font properties object.
  17623. * @param {Object} builtInEncoding The encoding contained within the actual font
  17624. * data.
  17625. * @param {Array} Array of glyph names where the index is the glyph ID.
  17626. * @returns {Object} A char code to glyph ID map.
  17627. */
  17628. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  17629. var charCodeToGlyphId = Object.create(null);
  17630. var glyphId, charCode, baseEncoding;
  17631. if (properties.baseEncodingName) {
  17632. // If a valid base encoding name was used, the mapping is initialized with
  17633. // that.
  17634. baseEncoding = Encodings[properties.baseEncodingName];
  17635. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17636. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17637. if (glyphId >= 0) {
  17638. charCodeToGlyphId[charCode] = glyphId;
  17639. } else {
  17640. charCodeToGlyphId[charCode] = 0; // notdef
  17641. }
  17642. }
  17643. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  17644. // For a symbolic font the encoding should be the fonts built-in
  17645. // encoding.
  17646. for (charCode in builtInEncoding) {
  17647. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  17648. }
  17649. } else {
  17650. // For non-symbolic fonts that don't have a base encoding the standard
  17651. // encoding should be used.
  17652. baseEncoding = Encodings.StandardEncoding;
  17653. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  17654. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  17655. if (glyphId >= 0) {
  17656. charCodeToGlyphId[charCode] = glyphId;
  17657. } else {
  17658. charCodeToGlyphId[charCode] = 0; // notdef
  17659. }
  17660. }
  17661. }
  17662. // Lastly, merge in the differences.
  17663. var differences = properties.differences;
  17664. if (differences) {
  17665. for (charCode in differences) {
  17666. var glyphName = differences[charCode];
  17667. glyphId = glyphNames.indexOf(glyphName);
  17668. if (glyphId >= 0) {
  17669. charCodeToGlyphId[charCode] = glyphId;
  17670. } else {
  17671. charCodeToGlyphId[charCode] = 0; // notdef
  17672. }
  17673. }
  17674. }
  17675. return charCodeToGlyphId;
  17676. }
  17677. /*
  17678. * CharStrings are encoded following the the CharString Encoding sequence
  17679. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  17680. * The value in a byte indicates a command, a number, or subsequent bytes
  17681. * that are to be interpreted in a special way.
  17682. *
  17683. * CharString Number Encoding:
  17684. * A CharString byte containing the values from 32 through 255 inclusive
  17685. * indicate an integer. These values are decoded in four ranges.
  17686. *
  17687. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  17688. * indicate the integer v - 139. Thus, the integer values from -107 through
  17689. * 107 inclusive may be encoded in single byte.
  17690. *
  17691. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  17692. * indicates an integer involving the next byte, w, according to the formula:
  17693. * [(v - 247) x 256] + w + 108
  17694. *
  17695. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  17696. * indicates an integer involving the next byte, w, according to the formula:
  17697. * -[(v - 251) * 256] - w - 108
  17698. *
  17699. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  17700. * are a two complement signed integer. The first of these bytes contains the
  17701. * highest order bits, the second byte contains the next higher order bits
  17702. * and the fourth byte contain the lowest order bits.
  17703. *
  17704. *
  17705. * CharString Command Encoding:
  17706. * CharStrings commands are encoded in 1 or 2 bytes.
  17707. *
  17708. * Single byte commands are encoded in 1 byte that contains a value between
  17709. * 0 and 31 inclusive.
  17710. * If a command byte contains the value 12, then the value in the next byte
  17711. * indicates a command. This "escape" mechanism allows many extra commands
  17712. * to be encoded and this encoding technique helps to minimize the length of
  17713. * the charStrings.
  17714. */
  17715. var Type1CharString = (function Type1CharStringClosure() {
  17716. var COMMAND_MAP = {
  17717. 'hstem': [1],
  17718. 'vstem': [3],
  17719. 'vmoveto': [4],
  17720. 'rlineto': [5],
  17721. 'hlineto': [6],
  17722. 'vlineto': [7],
  17723. 'rrcurveto': [8],
  17724. 'callsubr': [10],
  17725. 'flex': [12, 35],
  17726. 'drop' : [12, 18],
  17727. 'endchar': [14],
  17728. 'rmoveto': [21],
  17729. 'hmoveto': [22],
  17730. 'vhcurveto': [30],
  17731. 'hvcurveto': [31]
  17732. };
  17733. function Type1CharString() {
  17734. this.width = 0;
  17735. this.lsb = 0;
  17736. this.flexing = false;
  17737. this.output = [];
  17738. this.stack = [];
  17739. }
  17740. Type1CharString.prototype = {
  17741. convert: function Type1CharString_convert(encoded, subrs) {
  17742. var count = encoded.length;
  17743. var error = false;
  17744. var wx, sbx, subrNumber;
  17745. for (var i = 0; i < count; i++) {
  17746. var value = encoded[i];
  17747. if (value < 32) {
  17748. if (value === 12) {
  17749. value = (value << 8) + encoded[++i];
  17750. }
  17751. switch (value) {
  17752. case 1: // hstem
  17753. if (!HINTING_ENABLED) {
  17754. this.stack = [];
  17755. break;
  17756. }
  17757. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17758. break;
  17759. case 3: // vstem
  17760. if (!HINTING_ENABLED) {
  17761. this.stack = [];
  17762. break;
  17763. }
  17764. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17765. break;
  17766. case 4: // vmoveto
  17767. if (this.flexing) {
  17768. if (this.stack.length < 1) {
  17769. error = true;
  17770. break;
  17771. }
  17772. // Add the dx for flex and but also swap the values so they are
  17773. // the right order.
  17774. var dy = this.stack.pop();
  17775. this.stack.push(0, dy);
  17776. break;
  17777. }
  17778. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  17779. break;
  17780. case 5: // rlineto
  17781. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  17782. break;
  17783. case 6: // hlineto
  17784. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  17785. break;
  17786. case 7: // vlineto
  17787. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  17788. break;
  17789. case 8: // rrcurveto
  17790. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  17791. break;
  17792. case 9: // closepath
  17793. // closepath is a Type1 command that does not take argument and is
  17794. // useless in Type2 and it can simply be ignored.
  17795. this.stack = [];
  17796. break;
  17797. case 10: // callsubr
  17798. if (this.stack.length < 1) {
  17799. error = true;
  17800. break;
  17801. }
  17802. subrNumber = this.stack.pop();
  17803. error = this.convert(subrs[subrNumber], subrs);
  17804. break;
  17805. case 11: // return
  17806. return error;
  17807. case 13: // hsbw
  17808. if (this.stack.length < 2) {
  17809. error = true;
  17810. break;
  17811. }
  17812. // To convert to type2 we have to move the width value to the
  17813. // first part of the charstring and then use hmoveto with lsb.
  17814. wx = this.stack.pop();
  17815. sbx = this.stack.pop();
  17816. this.lsb = sbx;
  17817. this.width = wx;
  17818. this.stack.push(wx, sbx);
  17819. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  17820. break;
  17821. case 14: // endchar
  17822. this.output.push(COMMAND_MAP.endchar[0]);
  17823. break;
  17824. case 21: // rmoveto
  17825. if (this.flexing) {
  17826. break;
  17827. }
  17828. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  17829. break;
  17830. case 22: // hmoveto
  17831. if (this.flexing) {
  17832. // Add the dy for flex.
  17833. this.stack.push(0);
  17834. break;
  17835. }
  17836. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  17837. break;
  17838. case 30: // vhcurveto
  17839. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  17840. break;
  17841. case 31: // hvcurveto
  17842. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  17843. break;
  17844. case (12 << 8) + 0: // dotsection
  17845. // dotsection is a Type1 command to specify some hinting feature
  17846. // for dots that do not take a parameter and it can safely be
  17847. // ignored for Type2.
  17848. this.stack = [];
  17849. break;
  17850. case (12 << 8) + 1: // vstem3
  17851. if (!HINTING_ENABLED) {
  17852. this.stack = [];
  17853. break;
  17854. }
  17855. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  17856. // multiple parameters, so instead of returning [vh]stem3 take a
  17857. // shortcut and return [vhstem] instead.
  17858. error = this.executeCommand(2, COMMAND_MAP.vstem);
  17859. break;
  17860. case (12 << 8) + 2: // hstem3
  17861. if (!HINTING_ENABLED) {
  17862. this.stack = [];
  17863. break;
  17864. }
  17865. // See vstem3.
  17866. error = this.executeCommand(2, COMMAND_MAP.hstem);
  17867. break;
  17868. case (12 << 8) + 6: // seac
  17869. // seac is like type 2's special endchar but it doesn't use the
  17870. // first argument asb, so remove it.
  17871. if (SEAC_ANALYSIS_ENABLED) {
  17872. this.seac = this.stack.splice(-4, 4);
  17873. error = this.executeCommand(0, COMMAND_MAP.endchar);
  17874. } else {
  17875. error = this.executeCommand(4, COMMAND_MAP.endchar);
  17876. }
  17877. break;
  17878. case (12 << 8) + 7: // sbw
  17879. if (this.stack.length < 4) {
  17880. error = true;
  17881. break;
  17882. }
  17883. // To convert to type2 we have to move the width value to the
  17884. // first part of the charstring and then use rmoveto with
  17885. // (dx, dy). The height argument will not be used for vmtx and
  17886. // vhea tables reconstruction -- ignoring it.
  17887. var wy = this.stack.pop();
  17888. wx = this.stack.pop();
  17889. var sby = this.stack.pop();
  17890. sbx = this.stack.pop();
  17891. this.lsb = sbx;
  17892. this.width = wx;
  17893. this.stack.push(wx, sbx, sby);
  17894. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  17895. break;
  17896. case (12 << 8) + 12: // div
  17897. if (this.stack.length < 2) {
  17898. error = true;
  17899. break;
  17900. }
  17901. var num2 = this.stack.pop();
  17902. var num1 = this.stack.pop();
  17903. this.stack.push(num1 / num2);
  17904. break;
  17905. case (12 << 8) + 16: // callothersubr
  17906. if (this.stack.length < 2) {
  17907. error = true;
  17908. break;
  17909. }
  17910. subrNumber = this.stack.pop();
  17911. var numArgs = this.stack.pop();
  17912. if (subrNumber === 0 && numArgs === 3) {
  17913. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  17914. this.stack.push(
  17915. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  17916. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  17917. flexArgs[4], // bcp2x
  17918. flexArgs[5], // bcp2y
  17919. flexArgs[6], // p2x
  17920. flexArgs[7], // p2y
  17921. flexArgs[8], // bcp3x
  17922. flexArgs[9], // bcp3y
  17923. flexArgs[10], // bcp4x
  17924. flexArgs[11], // bcp4y
  17925. flexArgs[12], // p3x
  17926. flexArgs[13], // p3y
  17927. flexArgs[14] // flexDepth
  17928. // 15 = finalx unused by flex
  17929. // 16 = finaly unused by flex
  17930. );
  17931. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  17932. this.flexing = false;
  17933. this.stack.push(flexArgs[15], flexArgs[16]);
  17934. } else if (subrNumber === 1 && numArgs === 0) {
  17935. this.flexing = true;
  17936. }
  17937. break;
  17938. case (12 << 8) + 17: // pop
  17939. // Ignore this since it is only used with othersubr.
  17940. break;
  17941. case (12 << 8) + 33: // setcurrentpoint
  17942. // Ignore for now.
  17943. this.stack = [];
  17944. break;
  17945. default:
  17946. warn('Unknown type 1 charstring command of "' + value + '"');
  17947. break;
  17948. }
  17949. if (error) {
  17950. break;
  17951. }
  17952. continue;
  17953. } else if (value <= 246) {
  17954. value = value - 139;
  17955. } else if (value <= 250) {
  17956. value = ((value - 247) * 256) + encoded[++i] + 108;
  17957. } else if (value <= 254) {
  17958. value = -((value - 251) * 256) - encoded[++i] - 108;
  17959. } else {
  17960. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  17961. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  17962. }
  17963. this.stack.push(value);
  17964. }
  17965. return error;
  17966. },
  17967. executeCommand: function(howManyArgs, command, keepStack) {
  17968. var stackLength = this.stack.length;
  17969. if (howManyArgs > stackLength) {
  17970. return true;
  17971. }
  17972. var start = stackLength - howManyArgs;
  17973. for (var i = start; i < stackLength; i++) {
  17974. var value = this.stack[i];
  17975. if (value === (value | 0)) { // int
  17976. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  17977. } else { // fixed point
  17978. value = (65536 * value) | 0;
  17979. this.output.push(255,
  17980. (value >> 24) & 0xFF,
  17981. (value >> 16) & 0xFF,
  17982. (value >> 8) & 0xFF,
  17983. value & 0xFF);
  17984. }
  17985. }
  17986. this.output.push.apply(this.output, command);
  17987. if (keepStack) {
  17988. this.stack.splice(start, howManyArgs);
  17989. } else {
  17990. this.stack.length = 0;
  17991. }
  17992. return false;
  17993. }
  17994. };
  17995. return Type1CharString;
  17996. })();
  17997. /*
  17998. * Type1Parser encapsulate the needed code for parsing a Type1 font
  17999. * program. Some of its logic depends on the Type2 charstrings
  18000. * structure.
  18001. * Note: this doesn't really parse the font since that would require evaluation
  18002. * of PostScript, but it is possible in most cases to extract what we need
  18003. * without a full parse.
  18004. */
  18005. var Type1Parser = (function Type1ParserClosure() {
  18006. /*
  18007. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  18008. * of Plaintext Bytes. The function took a key as a parameter which can be
  18009. * for decrypting the eexec block of for decoding charStrings.
  18010. */
  18011. var EEXEC_ENCRYPT_KEY = 55665;
  18012. var CHAR_STRS_ENCRYPT_KEY = 4330;
  18013. function isHexDigit(code) {
  18014. return code >= 48 && code <= 57 || // '0'-'9'
  18015. code >= 65 && code <= 70 || // 'A'-'F'
  18016. code >= 97 && code <= 102; // 'a'-'f'
  18017. }
  18018. function decrypt(data, key, discardNumber) {
  18019. var r = key | 0, c1 = 52845, c2 = 22719;
  18020. var count = data.length;
  18021. var decrypted = new Uint8Array(count);
  18022. for (var i = 0; i < count; i++) {
  18023. var value = data[i];
  18024. decrypted[i] = value ^ (r >> 8);
  18025. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18026. }
  18027. return Array.prototype.slice.call(decrypted, discardNumber);
  18028. }
  18029. function decryptAscii(data, key, discardNumber) {
  18030. var r = key | 0, c1 = 52845, c2 = 22719;
  18031. var count = data.length, maybeLength = count >>> 1;
  18032. var decrypted = new Uint8Array(maybeLength);
  18033. var i, j;
  18034. for (i = 0, j = 0; i < count; i++) {
  18035. var digit1 = data[i];
  18036. if (!isHexDigit(digit1)) {
  18037. continue;
  18038. }
  18039. i++;
  18040. var digit2;
  18041. while (i < count && !isHexDigit(digit2 = data[i])) {
  18042. i++;
  18043. }
  18044. if (i < count) {
  18045. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  18046. decrypted[j++] = value ^ (r >> 8);
  18047. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  18048. }
  18049. }
  18050. return Array.prototype.slice.call(decrypted, discardNumber, j);
  18051. }
  18052. function isSpecial(c) {
  18053. return c === 0x2F || // '/'
  18054. c === 0x5B || c === 0x5D || // '[', ']'
  18055. c === 0x7B || c === 0x7D || // '{', '}'
  18056. c === 0x28 || c === 0x29; // '(', ')'
  18057. }
  18058. function Type1Parser(stream, encrypted) {
  18059. if (encrypted) {
  18060. var data = stream.getBytes();
  18061. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  18062. isHexDigit(data[2]) && isHexDigit(data[3]));
  18063. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  18064. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  18065. }
  18066. this.stream = stream;
  18067. this.nextChar();
  18068. }
  18069. Type1Parser.prototype = {
  18070. readNumberArray: function Type1Parser_readNumberArray() {
  18071. this.getToken(); // read '[' or '{' (arrays can start with either)
  18072. var array = [];
  18073. while (true) {
  18074. var token = this.getToken();
  18075. if (token === null || token === ']' || token === '}') {
  18076. break;
  18077. }
  18078. array.push(parseFloat(token || 0));
  18079. }
  18080. return array;
  18081. },
  18082. readNumber: function Type1Parser_readNumber() {
  18083. var token = this.getToken();
  18084. return parseFloat(token || 0);
  18085. },
  18086. readInt: function Type1Parser_readInt() {
  18087. // Use '| 0' to prevent setting a double into length such as the double
  18088. // does not flow into the loop variable.
  18089. var token = this.getToken();
  18090. return parseInt(token || 0, 10) | 0;
  18091. },
  18092. readBoolean: function Type1Parser_readBoolean() {
  18093. var token = this.getToken();
  18094. // Use 1 and 0 since that's what type2 charstrings use.
  18095. return token === 'true' ? 1 : 0;
  18096. },
  18097. nextChar : function Type1_nextChar() {
  18098. return (this.currentChar = this.stream.getByte());
  18099. },
  18100. getToken: function Type1Parser_getToken() {
  18101. // Eat whitespace and comments.
  18102. var comment = false;
  18103. var ch = this.currentChar;
  18104. while (true) {
  18105. if (ch === -1) {
  18106. return null;
  18107. }
  18108. if (comment) {
  18109. if (ch === 0x0A || ch === 0x0D) {
  18110. comment = false;
  18111. }
  18112. } else if (ch === 0x25) { // '%'
  18113. comment = true;
  18114. } else if (!Lexer.isSpace(ch)) {
  18115. break;
  18116. }
  18117. ch = this.nextChar();
  18118. }
  18119. if (isSpecial(ch)) {
  18120. this.nextChar();
  18121. return String.fromCharCode(ch);
  18122. }
  18123. var token = '';
  18124. do {
  18125. token += String.fromCharCode(ch);
  18126. ch = this.nextChar();
  18127. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  18128. return token;
  18129. },
  18130. /*
  18131. * Returns an object containing a Subrs array and a CharStrings
  18132. * array extracted from and eexec encrypted block of data
  18133. */
  18134. extractFontProgram: function Type1Parser_extractFontProgram() {
  18135. var stream = this.stream;
  18136. var subrs = [], charstrings = [];
  18137. var program = {
  18138. subrs: [],
  18139. charstrings: [],
  18140. properties: {
  18141. 'privateData': {
  18142. 'lenIV': 4
  18143. }
  18144. }
  18145. };
  18146. var token, length, data, lenIV, encoded;
  18147. while ((token = this.getToken()) !== null) {
  18148. if (token !== '/') {
  18149. continue;
  18150. }
  18151. token = this.getToken();
  18152. switch (token) {
  18153. case 'CharStrings':
  18154. // The number immediately following CharStrings must be greater or
  18155. // equal to the number of CharStrings.
  18156. this.getToken();
  18157. this.getToken(); // read in 'dict'
  18158. this.getToken(); // read in 'dup'
  18159. this.getToken(); // read in 'begin'
  18160. while(true) {
  18161. token = this.getToken();
  18162. if (token === null || token === 'end') {
  18163. break;
  18164. }
  18165. if (token !== '/') {
  18166. continue;
  18167. }
  18168. var glyph = this.getToken();
  18169. length = this.readInt();
  18170. this.getToken(); // read in 'RD' or '-|'
  18171. data = stream.makeSubStream(stream.pos, length);
  18172. lenIV = program.properties.privateData['lenIV'];
  18173. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18174. // Skip past the required space and binary data.
  18175. stream.skip(length);
  18176. this.nextChar();
  18177. token = this.getToken(); // read in 'ND' or '|-'
  18178. if (token === 'noaccess') {
  18179. this.getToken(); // read in 'def'
  18180. }
  18181. charstrings.push({
  18182. glyph: glyph,
  18183. encoded: encoded
  18184. });
  18185. }
  18186. break;
  18187. case 'Subrs':
  18188. var num = this.readInt();
  18189. this.getToken(); // read in 'array'
  18190. while ((token = this.getToken()) === 'dup') {
  18191. var index = this.readInt();
  18192. length = this.readInt();
  18193. this.getToken(); // read in 'RD' or '-|'
  18194. data = stream.makeSubStream(stream.pos, length);
  18195. lenIV = program.properties.privateData['lenIV'];
  18196. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  18197. // Skip past the required space and binary data.
  18198. stream.skip(length);
  18199. this.nextChar();
  18200. token = this.getToken(); // read in 'NP' or '|'
  18201. if (token === 'noaccess') {
  18202. this.getToken(); // read in 'put'
  18203. }
  18204. subrs[index] = encoded;
  18205. }
  18206. break;
  18207. case 'BlueValues':
  18208. case 'OtherBlues':
  18209. case 'FamilyBlues':
  18210. case 'FamilyOtherBlues':
  18211. var blueArray = this.readNumberArray();
  18212. // *Blue* values may contain invalid data: disables reading of
  18213. // those values when hinting is disabled.
  18214. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  18215. HINTING_ENABLED) {
  18216. program.properties.privateData[token] = blueArray;
  18217. }
  18218. break;
  18219. case 'StemSnapH':
  18220. case 'StemSnapV':
  18221. program.properties.privateData[token] = this.readNumberArray();
  18222. break;
  18223. case 'StdHW':
  18224. case 'StdVW':
  18225. program.properties.privateData[token] =
  18226. this.readNumberArray()[0];
  18227. break;
  18228. case 'BlueShift':
  18229. case 'lenIV':
  18230. case 'BlueFuzz':
  18231. case 'BlueScale':
  18232. case 'LanguageGroup':
  18233. case 'ExpansionFactor':
  18234. program.properties.privateData[token] = this.readNumber();
  18235. break;
  18236. case 'ForceBold':
  18237. program.properties.privateData[token] = this.readBoolean();
  18238. break;
  18239. }
  18240. }
  18241. for (var i = 0; i < charstrings.length; i++) {
  18242. glyph = charstrings[i].glyph;
  18243. encoded = charstrings[i].encoded;
  18244. var charString = new Type1CharString();
  18245. var error = charString.convert(encoded, subrs);
  18246. var output = charString.output;
  18247. if (error) {
  18248. // It seems when FreeType encounters an error while evaluating a glyph
  18249. // that it completely ignores the glyph so we'll mimic that behaviour
  18250. // here and put an endchar to make the validator happy.
  18251. output = [14];
  18252. }
  18253. program.charstrings.push({
  18254. glyphName: glyph,
  18255. charstring: output,
  18256. width: charString.width,
  18257. lsb: charString.lsb,
  18258. seac: charString.seac
  18259. });
  18260. }
  18261. return program;
  18262. },
  18263. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  18264. var token;
  18265. while ((token = this.getToken()) !== null) {
  18266. if (token !== '/') {
  18267. continue;
  18268. }
  18269. token = this.getToken();
  18270. switch (token) {
  18271. case 'FontMatrix':
  18272. var matrix = this.readNumberArray();
  18273. properties.fontMatrix = matrix;
  18274. break;
  18275. case 'Encoding':
  18276. var encodingArg = this.getToken();
  18277. var encoding;
  18278. if (!/^\d+$/.test(encodingArg)) {
  18279. // encoding name is specified
  18280. encoding = Encodings[encodingArg];
  18281. } else {
  18282. encoding = [];
  18283. var size = parseInt(encodingArg, 10) | 0;
  18284. this.getToken(); // read in 'array'
  18285. for (var j = 0; j < size; j++) {
  18286. token = this.getToken();
  18287. // skipping till first dup or def (e.g. ignoring for statement)
  18288. while (token !== 'dup' && token !== 'def') {
  18289. token = this.getToken();
  18290. if (token === null) {
  18291. return; // invalid header
  18292. }
  18293. }
  18294. if (token === 'def') {
  18295. break; // read all array data
  18296. }
  18297. var index = this.readInt();
  18298. this.getToken(); // read in '/'
  18299. var glyph = this.getToken();
  18300. encoding[index] = glyph;
  18301. this.getToken(); // read the in 'put'
  18302. }
  18303. }
  18304. properties.builtInEncoding = encoding;
  18305. break;
  18306. case 'FontBBox':
  18307. var fontBBox = this.readNumberArray();
  18308. // adjusting ascent/descent
  18309. properties.ascent = fontBBox[3];
  18310. properties.descent = fontBBox[1];
  18311. properties.ascentScaled = true;
  18312. break;
  18313. }
  18314. }
  18315. }
  18316. };
  18317. return Type1Parser;
  18318. })();
  18319. /**
  18320. * The CFF class takes a Type1 file and wrap it into a
  18321. * 'Compact Font Format' which itself embed Type2 charstrings.
  18322. */
  18323. var CFFStandardStrings = [
  18324. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  18325. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  18326. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  18327. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  18328. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  18329. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  18330. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  18331. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  18332. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  18333. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  18334. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  18335. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  18336. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  18337. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  18338. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  18339. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  18340. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  18341. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  18342. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  18343. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  18344. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  18345. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  18346. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  18347. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  18348. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  18349. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  18350. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  18351. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  18352. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  18353. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  18354. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  18355. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  18356. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  18357. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  18358. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  18359. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  18360. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  18361. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  18362. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  18363. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  18364. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  18365. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  18366. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  18367. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  18368. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  18369. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  18370. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  18371. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  18372. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  18373. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  18374. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  18375. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  18376. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  18377. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  18378. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  18379. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  18380. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  18381. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  18382. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  18383. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  18384. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  18385. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  18386. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  18387. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  18388. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  18389. ];
  18390. // Type1Font is also a CIDFontType0.
  18391. var Type1Font = function Type1Font(name, file, properties) {
  18392. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  18393. // Also, length1 and length2 might be off by 6 bytes as well.
  18394. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  18395. var PFB_HEADER_SIZE = 6;
  18396. var headerBlockLength = properties.length1;
  18397. var eexecBlockLength = properties.length2;
  18398. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  18399. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  18400. if (pfbHeaderPresent) {
  18401. file.skip(PFB_HEADER_SIZE);
  18402. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18403. (pfbHeader[3] << 8) | pfbHeader[2];
  18404. }
  18405. // Get the data block containing glyphs and subrs informations
  18406. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  18407. var headerBlockParser = new Type1Parser(headerBlock);
  18408. headerBlockParser.extractFontHeader(properties);
  18409. if (pfbHeaderPresent) {
  18410. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  18411. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  18412. (pfbHeader[3] << 8) | pfbHeader[2];
  18413. }
  18414. // Decrypt the data blocks and retrieve it's content
  18415. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  18416. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  18417. var data = eexecBlockParser.extractFontProgram();
  18418. for (var info in data.properties) {
  18419. properties[info] = data.properties[info];
  18420. }
  18421. var charstrings = data.charstrings;
  18422. var type2Charstrings = this.getType2Charstrings(charstrings);
  18423. var subrs = this.getType2Subrs(data.subrs);
  18424. this.charstrings = charstrings;
  18425. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  18426. subrs, properties);
  18427. this.seacs = this.getSeacs(data.charstrings);
  18428. };
  18429. Type1Font.prototype = {
  18430. get numGlyphs() {
  18431. return this.charstrings.length + 1;
  18432. },
  18433. getCharset: function Type1Font_getCharset() {
  18434. var charset = ['.notdef'];
  18435. var charstrings = this.charstrings;
  18436. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18437. charset.push(charstrings[glyphId].glyphName);
  18438. }
  18439. return charset;
  18440. },
  18441. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  18442. var charstrings = this.charstrings;
  18443. var glyphNames = ['.notdef'], glyphId;
  18444. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  18445. glyphNames.push(charstrings[glyphId].glyphName);
  18446. }
  18447. var encoding = properties.builtInEncoding;
  18448. if (encoding) {
  18449. var builtInEncoding = {};
  18450. for (var charCode in encoding) {
  18451. glyphId = glyphNames.indexOf(encoding[charCode]);
  18452. if (glyphId >= 0) {
  18453. builtInEncoding[charCode] = glyphId;
  18454. }
  18455. }
  18456. }
  18457. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  18458. },
  18459. getSeacs: function Type1Font_getSeacs(charstrings) {
  18460. var i, ii;
  18461. var seacMap = [];
  18462. for (i = 0, ii = charstrings.length; i < ii; i++) {
  18463. var charstring = charstrings[i];
  18464. if (charstring.seac) {
  18465. // Offset by 1 for .notdef
  18466. seacMap[i + 1] = charstring.seac;
  18467. }
  18468. }
  18469. return seacMap;
  18470. },
  18471. getType2Charstrings: function Type1Font_getType2Charstrings(
  18472. type1Charstrings) {
  18473. var type2Charstrings = [];
  18474. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  18475. type2Charstrings.push(type1Charstrings[i].charstring);
  18476. }
  18477. return type2Charstrings;
  18478. },
  18479. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  18480. var bias = 0;
  18481. var count = type1Subrs.length;
  18482. if (count < 1133) {
  18483. bias = 107;
  18484. } else if (count < 33769) {
  18485. bias = 1131;
  18486. } else {
  18487. bias = 32768;
  18488. }
  18489. // Add a bunch of empty subrs to deal with the Type2 bias
  18490. var type2Subrs = [];
  18491. var i;
  18492. for (i = 0; i < bias; i++) {
  18493. type2Subrs.push([0x0B]);
  18494. }
  18495. for (i = 0; i < count; i++) {
  18496. type2Subrs.push(type1Subrs[i]);
  18497. }
  18498. return type2Subrs;
  18499. },
  18500. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  18501. var cff = new CFF();
  18502. cff.header = new CFFHeader(1, 0, 4, 4);
  18503. cff.names = [name];
  18504. var topDict = new CFFTopDict();
  18505. // CFF strings IDs 0...390 are predefined names, so refering
  18506. // to entries in our own String INDEX starts at SID 391.
  18507. topDict.setByName('version', 391);
  18508. topDict.setByName('Notice', 392);
  18509. topDict.setByName('FullName', 393);
  18510. topDict.setByName('FamilyName', 394);
  18511. topDict.setByName('Weight', 395);
  18512. topDict.setByName('Encoding', null); // placeholder
  18513. topDict.setByName('FontMatrix', properties.fontMatrix);
  18514. topDict.setByName('FontBBox', properties.bbox);
  18515. topDict.setByName('charset', null); // placeholder
  18516. topDict.setByName('CharStrings', null); // placeholder
  18517. topDict.setByName('Private', null); // placeholder
  18518. cff.topDict = topDict;
  18519. var strings = new CFFStrings();
  18520. strings.add('Version 0.11'); // Version
  18521. strings.add('See original notice'); // Notice
  18522. strings.add(name); // FullName
  18523. strings.add(name); // FamilyName
  18524. strings.add('Medium'); // Weight
  18525. cff.strings = strings;
  18526. cff.globalSubrIndex = new CFFIndex();
  18527. var count = glyphs.length;
  18528. var charsetArray = [0];
  18529. var i, ii;
  18530. for (i = 0; i < count; i++) {
  18531. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  18532. // TODO: Insert the string and correctly map it. Previously it was
  18533. // thought mapping names that aren't in the standard strings to .notdef
  18534. // was fine, however in issue818 when mapping them all to .notdef the
  18535. // adieresis glyph no longer worked.
  18536. if (index === -1) {
  18537. index = 0;
  18538. }
  18539. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  18540. }
  18541. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  18542. var charStringsIndex = new CFFIndex();
  18543. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  18544. for (i = 0; i < count; i++) {
  18545. charStringsIndex.add(glyphs[i]);
  18546. }
  18547. cff.charStrings = charStringsIndex;
  18548. var privateDict = new CFFPrivateDict();
  18549. privateDict.setByName('Subrs', null); // placeholder
  18550. var fields = [
  18551. 'BlueValues',
  18552. 'OtherBlues',
  18553. 'FamilyBlues',
  18554. 'FamilyOtherBlues',
  18555. 'StemSnapH',
  18556. 'StemSnapV',
  18557. 'BlueShift',
  18558. 'BlueFuzz',
  18559. 'BlueScale',
  18560. 'LanguageGroup',
  18561. 'ExpansionFactor',
  18562. 'ForceBold',
  18563. 'StdHW',
  18564. 'StdVW'
  18565. ];
  18566. for (i = 0, ii = fields.length; i < ii; i++) {
  18567. var field = fields[i];
  18568. if (!properties.privateData.hasOwnProperty(field)) {
  18569. continue;
  18570. }
  18571. var value = properties.privateData[field];
  18572. if (isArray(value)) {
  18573. // All of the private dictionary array data in CFF must be stored as
  18574. // "delta-encoded" numbers.
  18575. for (var j = value.length - 1; j > 0; j--) {
  18576. value[j] -= value[j - 1]; // ... difference from previous value
  18577. }
  18578. }
  18579. privateDict.setByName(field, value);
  18580. }
  18581. cff.topDict.privateDict = privateDict;
  18582. var subrIndex = new CFFIndex();
  18583. for (i = 0, ii = subrs.length; i < ii; i++) {
  18584. subrIndex.add(subrs[i]);
  18585. }
  18586. privateDict.subrsIndex = subrIndex;
  18587. var compiler = new CFFCompiler(cff);
  18588. return compiler.compile();
  18589. }
  18590. };
  18591. var CFFFont = (function CFFFontClosure() {
  18592. function CFFFont(file, properties) {
  18593. this.properties = properties;
  18594. var parser = new CFFParser(file, properties);
  18595. this.cff = parser.parse();
  18596. var compiler = new CFFCompiler(this.cff);
  18597. this.seacs = this.cff.seacs;
  18598. try {
  18599. this.data = compiler.compile();
  18600. } catch (e) {
  18601. warn('Failed to compile font ' + properties.loadedName);
  18602. // There may have just been an issue with the compiler, set the data
  18603. // anyway and hope the font loaded.
  18604. this.data = file;
  18605. }
  18606. }
  18607. CFFFont.prototype = {
  18608. get numGlyphs() {
  18609. return this.cff.charStrings.count;
  18610. },
  18611. getCharset: function CFFFont_getCharset() {
  18612. return this.cff.charset.charset;
  18613. },
  18614. getGlyphMapping: function CFFFont_getGlyphMapping() {
  18615. var cff = this.cff;
  18616. var properties = this.properties;
  18617. var charsets = cff.charset.charset;
  18618. var charCodeToGlyphId;
  18619. var glyphId;
  18620. if (properties.composite) {
  18621. charCodeToGlyphId = Object.create(null);
  18622. if (cff.isCIDFont) {
  18623. // If the font is actually a CID font then we should use the charset
  18624. // to map CIDs to GIDs.
  18625. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  18626. var cid = charsets[glyphId];
  18627. var charCode = properties.cMap.charCodeOf(cid);
  18628. charCodeToGlyphId[charCode] = glyphId;
  18629. }
  18630. } else {
  18631. // If it is NOT actually a CID font then CIDs should be mapped
  18632. // directly to GIDs.
  18633. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  18634. charCodeToGlyphId[glyphId] = glyphId;
  18635. }
  18636. }
  18637. return charCodeToGlyphId;
  18638. }
  18639. var encoding = cff.encoding ? cff.encoding.encoding : null;
  18640. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  18641. return charCodeToGlyphId;
  18642. }
  18643. };
  18644. return CFFFont;
  18645. })();
  18646. var CFFParser = (function CFFParserClosure() {
  18647. var CharstringValidationData = [
  18648. null,
  18649. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  18650. null,
  18651. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  18652. { id: 'vmoveto', min: 1, stackClearing: true },
  18653. { id: 'rlineto', min: 2, resetStack: true },
  18654. { id: 'hlineto', min: 1, resetStack: true },
  18655. { id: 'vlineto', min: 1, resetStack: true },
  18656. { id: 'rrcurveto', min: 6, resetStack: true },
  18657. null,
  18658. { id: 'callsubr', min: 1, undefStack: true },
  18659. { id: 'return', min: 0, undefStack: true },
  18660. null, // 12
  18661. null,
  18662. { id: 'endchar', min: 0, stackClearing: true },
  18663. null,
  18664. null,
  18665. null,
  18666. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  18667. { id: 'hintmask', min: 0, stackClearing: true },
  18668. { id: 'cntrmask', min: 0, stackClearing: true },
  18669. { id: 'rmoveto', min: 2, stackClearing: true },
  18670. { id: 'hmoveto', min: 1, stackClearing: true },
  18671. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  18672. { id: 'rcurveline', min: 8, resetStack: true },
  18673. { id: 'rlinecurve', min: 8, resetStack: true },
  18674. { id: 'vvcurveto', min: 4, resetStack: true },
  18675. { id: 'hhcurveto', min: 4, resetStack: true },
  18676. null, // shortint
  18677. { id: 'callgsubr', min: 1, undefStack: true },
  18678. { id: 'vhcurveto', min: 4, resetStack: true },
  18679. { id: 'hvcurveto', min: 4, resetStack: true }
  18680. ];
  18681. var CharstringValidationData12 = [
  18682. null,
  18683. null,
  18684. null,
  18685. { id: 'and', min: 2, stackDelta: -1 },
  18686. { id: 'or', min: 2, stackDelta: -1 },
  18687. { id: 'not', min: 1, stackDelta: 0 },
  18688. null,
  18689. null,
  18690. null,
  18691. { id: 'abs', min: 1, stackDelta: 0 },
  18692. { id: 'add', min: 2, stackDelta: -1,
  18693. stackFn: function stack_div(stack, index) {
  18694. stack[index - 2] = stack[index - 2] + stack[index - 1];
  18695. }
  18696. },
  18697. { id: 'sub', min: 2, stackDelta: -1,
  18698. stackFn: function stack_div(stack, index) {
  18699. stack[index - 2] = stack[index - 2] - stack[index - 1];
  18700. }
  18701. },
  18702. { id: 'div', min: 2, stackDelta: -1,
  18703. stackFn: function stack_div(stack, index) {
  18704. stack[index - 2] = stack[index - 2] / stack[index - 1];
  18705. }
  18706. },
  18707. null,
  18708. { id: 'neg', min: 1, stackDelta: 0,
  18709. stackFn: function stack_div(stack, index) {
  18710. stack[index - 1] = -stack[index - 1];
  18711. }
  18712. },
  18713. { id: 'eq', min: 2, stackDelta: -1 },
  18714. null,
  18715. null,
  18716. { id: 'drop', min: 1, stackDelta: -1 },
  18717. null,
  18718. { id: 'put', min: 2, stackDelta: -2 },
  18719. { id: 'get', min: 1, stackDelta: 0 },
  18720. { id: 'ifelse', min: 4, stackDelta: -3 },
  18721. { id: 'random', min: 0, stackDelta: 1 },
  18722. { id: 'mul', min: 2, stackDelta: -1,
  18723. stackFn: function stack_div(stack, index) {
  18724. stack[index - 2] = stack[index - 2] * stack[index - 1];
  18725. }
  18726. },
  18727. null,
  18728. { id: 'sqrt', min: 1, stackDelta: 0 },
  18729. { id: 'dup', min: 1, stackDelta: 1 },
  18730. { id: 'exch', min: 2, stackDelta: 0 },
  18731. { id: 'index', min: 2, stackDelta: 0 },
  18732. { id: 'roll', min: 3, stackDelta: -2 },
  18733. null,
  18734. null,
  18735. null,
  18736. { id: 'hflex', min: 7, resetStack: true },
  18737. { id: 'flex', min: 13, resetStack: true },
  18738. { id: 'hflex1', min: 9, resetStack: true },
  18739. { id: 'flex1', min: 11, resetStack: true }
  18740. ];
  18741. function CFFParser(file, properties) {
  18742. this.bytes = file.getBytes();
  18743. this.properties = properties;
  18744. }
  18745. CFFParser.prototype = {
  18746. parse: function CFFParser_parse() {
  18747. var properties = this.properties;
  18748. var cff = new CFF();
  18749. this.cff = cff;
  18750. // The first five sections must be in order, all the others are reached
  18751. // via offsets contained in one of the below.
  18752. var header = this.parseHeader();
  18753. var nameIndex = this.parseIndex(header.endPos);
  18754. var topDictIndex = this.parseIndex(nameIndex.endPos);
  18755. var stringIndex = this.parseIndex(topDictIndex.endPos);
  18756. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  18757. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  18758. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  18759. cff.header = header.obj;
  18760. cff.names = this.parseNameIndex(nameIndex.obj);
  18761. cff.strings = this.parseStringIndex(stringIndex.obj);
  18762. cff.topDict = topDict;
  18763. cff.globalSubrIndex = globalSubrIndex.obj;
  18764. this.parsePrivateDict(cff.topDict);
  18765. cff.isCIDFont = topDict.hasName('ROS');
  18766. var charStringOffset = topDict.getByName('CharStrings');
  18767. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  18768. cff.charStrings = charStringsAndSeacs.charStrings;
  18769. cff.seacs = charStringsAndSeacs.seacs;
  18770. cff.widths = charStringsAndSeacs.widths;
  18771. var fontMatrix = topDict.getByName('FontMatrix');
  18772. if (fontMatrix) {
  18773. properties.fontMatrix = fontMatrix;
  18774. }
  18775. var fontBBox = topDict.getByName('FontBBox');
  18776. if (fontBBox) {
  18777. // adjusting ascent/descent
  18778. properties.ascent = fontBBox[3];
  18779. properties.descent = fontBBox[1];
  18780. properties.ascentScaled = true;
  18781. }
  18782. var charset, encoding;
  18783. if (cff.isCIDFont) {
  18784. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  18785. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  18786. var dictRaw = fdArrayIndex.get(i);
  18787. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  18788. cff.strings);
  18789. this.parsePrivateDict(fontDict);
  18790. cff.fdArray.push(fontDict);
  18791. }
  18792. // cid fonts don't have an encoding
  18793. encoding = null;
  18794. charset = this.parseCharsets(topDict.getByName('charset'),
  18795. cff.charStrings.count, cff.strings, true);
  18796. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  18797. cff.charStrings.count);
  18798. } else {
  18799. charset = this.parseCharsets(topDict.getByName('charset'),
  18800. cff.charStrings.count, cff.strings, false);
  18801. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  18802. properties,
  18803. cff.strings, charset.charset);
  18804. }
  18805. cff.charset = charset;
  18806. cff.encoding = encoding;
  18807. return cff;
  18808. },
  18809. parseHeader: function CFFParser_parseHeader() {
  18810. var bytes = this.bytes;
  18811. var bytesLength = bytes.length;
  18812. var offset = 0;
  18813. // Prevent an infinite loop, by checking that the offset is within the
  18814. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  18815. while (offset < bytesLength && bytes[offset] !== 1) {
  18816. ++offset;
  18817. }
  18818. if (offset >= bytesLength) {
  18819. error('Invalid CFF header');
  18820. } else if (offset !== 0) {
  18821. info('cff data is shifted');
  18822. bytes = bytes.subarray(offset);
  18823. this.bytes = bytes;
  18824. }
  18825. var major = bytes[0];
  18826. var minor = bytes[1];
  18827. var hdrSize = bytes[2];
  18828. var offSize = bytes[3];
  18829. var header = new CFFHeader(major, minor, hdrSize, offSize);
  18830. return { obj: header, endPos: hdrSize };
  18831. },
  18832. parseDict: function CFFParser_parseDict(dict) {
  18833. var pos = 0;
  18834. function parseOperand() {
  18835. var value = dict[pos++];
  18836. if (value === 30) {
  18837. return parseFloatOperand(pos);
  18838. } else if (value === 28) {
  18839. value = dict[pos++];
  18840. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  18841. return value;
  18842. } else if (value === 29) {
  18843. value = dict[pos++];
  18844. value = (value << 8) | dict[pos++];
  18845. value = (value << 8) | dict[pos++];
  18846. value = (value << 8) | dict[pos++];
  18847. return value;
  18848. } else if (value >= 32 && value <= 246) {
  18849. return value - 139;
  18850. } else if (value >= 247 && value <= 250) {
  18851. return ((value - 247) * 256) + dict[pos++] + 108;
  18852. } else if (value >= 251 && value <= 254) {
  18853. return -((value - 251) * 256) - dict[pos++] - 108;
  18854. } else {
  18855. error('255 is not a valid DICT command');
  18856. }
  18857. return -1;
  18858. }
  18859. function parseFloatOperand() {
  18860. var str = '';
  18861. var eof = 15;
  18862. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  18863. '9', '.', 'E', 'E-', null, '-'];
  18864. var length = dict.length;
  18865. while (pos < length) {
  18866. var b = dict[pos++];
  18867. var b1 = b >> 4;
  18868. var b2 = b & 15;
  18869. if (b1 === eof) {
  18870. break;
  18871. }
  18872. str += lookup[b1];
  18873. if (b2 === eof) {
  18874. break;
  18875. }
  18876. str += lookup[b2];
  18877. }
  18878. return parseFloat(str);
  18879. }
  18880. var operands = [];
  18881. var entries = [];
  18882. pos = 0;
  18883. var end = dict.length;
  18884. while (pos < end) {
  18885. var b = dict[pos];
  18886. if (b <= 21) {
  18887. if (b === 12) {
  18888. b = (b << 8) | dict[++pos];
  18889. }
  18890. entries.push([b, operands]);
  18891. operands = [];
  18892. ++pos;
  18893. } else {
  18894. operands.push(parseOperand());
  18895. }
  18896. }
  18897. return entries;
  18898. },
  18899. parseIndex: function CFFParser_parseIndex(pos) {
  18900. var cffIndex = new CFFIndex();
  18901. var bytes = this.bytes;
  18902. var count = (bytes[pos++] << 8) | bytes[pos++];
  18903. var offsets = [];
  18904. var end = pos;
  18905. var i, ii;
  18906. if (count !== 0) {
  18907. var offsetSize = bytes[pos++];
  18908. // add 1 for offset to determine size of last object
  18909. var startPos = pos + ((count + 1) * offsetSize) - 1;
  18910. for (i = 0, ii = count + 1; i < ii; ++i) {
  18911. var offset = 0;
  18912. for (var j = 0; j < offsetSize; ++j) {
  18913. offset <<= 8;
  18914. offset += bytes[pos++];
  18915. }
  18916. offsets.push(startPos + offset);
  18917. }
  18918. end = offsets[count];
  18919. }
  18920. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  18921. var offsetStart = offsets[i];
  18922. var offsetEnd = offsets[i + 1];
  18923. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  18924. }
  18925. return {obj: cffIndex, endPos: end};
  18926. },
  18927. parseNameIndex: function CFFParser_parseNameIndex(index) {
  18928. var names = [];
  18929. for (var i = 0, ii = index.count; i < ii; ++i) {
  18930. var name = index.get(i);
  18931. // OTS doesn't allow names to be over 127 characters.
  18932. var length = Math.min(name.length, 127);
  18933. var data = [];
  18934. // OTS also only permits certain characters in the name.
  18935. for (var j = 0; j < length; ++j) {
  18936. var c = name[j];
  18937. if (j === 0 && c === 0) {
  18938. data[j] = c;
  18939. continue;
  18940. }
  18941. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  18942. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  18943. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  18944. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  18945. data[j] = 95;
  18946. continue;
  18947. }
  18948. data[j] = c;
  18949. }
  18950. names.push(bytesToString(data));
  18951. }
  18952. return names;
  18953. },
  18954. parseStringIndex: function CFFParser_parseStringIndex(index) {
  18955. var strings = new CFFStrings();
  18956. for (var i = 0, ii = index.count; i < ii; ++i) {
  18957. var data = index.get(i);
  18958. strings.add(bytesToString(data));
  18959. }
  18960. return strings;
  18961. },
  18962. createDict: function CFFParser_createDict(Type, dict, strings) {
  18963. var cffDict = new Type(strings);
  18964. for (var i = 0, ii = dict.length; i < ii; ++i) {
  18965. var pair = dict[i];
  18966. var key = pair[0];
  18967. var value = pair[1];
  18968. cffDict.setByKey(key, value);
  18969. }
  18970. return cffDict;
  18971. },
  18972. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  18973. var charStrings = this.parseIndex(charStringOffset).obj;
  18974. var seacs = [];
  18975. var widths = [];
  18976. var count = charStrings.count;
  18977. for (var i = 0; i < count; i++) {
  18978. var charstring = charStrings.get(i);
  18979. var stackSize = 0;
  18980. var stack = [];
  18981. var undefStack = true;
  18982. var hints = 0;
  18983. var valid = true;
  18984. var data = charstring;
  18985. var length = data.length;
  18986. var firstStackClearing = true;
  18987. for (var j = 0; j < length;) {
  18988. var value = data[j++];
  18989. var validationCommand = null;
  18990. if (value === 12) {
  18991. var q = data[j++];
  18992. if (q === 0) {
  18993. // The CFF specification state that the 'dotsection' command
  18994. // (12, 0) is deprecated and treated as a no-op, but all Type2
  18995. // charstrings processors should support them. Unfortunately
  18996. // the font sanitizer don't. As a workaround the sequence (12, 0)
  18997. // is replaced by a useless (0, hmoveto).
  18998. data[j - 2] = 139;
  18999. data[j - 1] = 22;
  19000. stackSize = 0;
  19001. } else {
  19002. validationCommand = CharstringValidationData12[q];
  19003. }
  19004. } else if (value === 28) { // number (16 bit)
  19005. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  19006. j += 2;
  19007. stackSize++;
  19008. } else if (value === 14) {
  19009. if (stackSize >= 4) {
  19010. stackSize -= 4;
  19011. if (SEAC_ANALYSIS_ENABLED) {
  19012. seacs[i] = stack.slice(stackSize, stackSize + 4);
  19013. valid = false;
  19014. }
  19015. }
  19016. validationCommand = CharstringValidationData[value];
  19017. } else if (value >= 32 && value <= 246) { // number
  19018. stack[stackSize] = value - 139;
  19019. stackSize++;
  19020. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  19021. stack[stackSize] = (value < 251 ?
  19022. ((value - 247) << 8) + data[j] + 108 :
  19023. -((value - 251) << 8) - data[j] - 108);
  19024. j++;
  19025. stackSize++;
  19026. } else if (value === 255) { // number (32 bit)
  19027. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  19028. (data[j + 2] << 8) | data[j + 3]) / 65536;
  19029. j += 4;
  19030. stackSize++;
  19031. } else if (value === 19 || value === 20) {
  19032. hints += stackSize >> 1;
  19033. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  19034. stackSize %= 2;
  19035. validationCommand = CharstringValidationData[value];
  19036. } else {
  19037. validationCommand = CharstringValidationData[value];
  19038. }
  19039. if (validationCommand) {
  19040. if (validationCommand.stem) {
  19041. hints += stackSize >> 1;
  19042. }
  19043. if ('min' in validationCommand) {
  19044. if (!undefStack && stackSize < validationCommand.min) {
  19045. warn('Not enough parameters for ' + validationCommand.id +
  19046. '; actual: ' + stackSize +
  19047. ', expected: ' + validationCommand.min);
  19048. valid = false;
  19049. break;
  19050. }
  19051. }
  19052. if (firstStackClearing && validationCommand.stackClearing) {
  19053. firstStackClearing = false;
  19054. // the optional character width can be found before the first
  19055. // stack-clearing command arguments
  19056. stackSize -= validationCommand.min;
  19057. if (stackSize >= 2 && validationCommand.stem) {
  19058. // there are even amount of arguments for stem commands
  19059. stackSize %= 2;
  19060. } else if (stackSize > 1) {
  19061. warn('Found too many parameters for stack-clearing command');
  19062. }
  19063. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  19064. widths[i] = stack[stackSize - 1];
  19065. }
  19066. }
  19067. if ('stackDelta' in validationCommand) {
  19068. if ('stackFn' in validationCommand) {
  19069. validationCommand.stackFn(stack, stackSize);
  19070. }
  19071. stackSize += validationCommand.stackDelta;
  19072. } else if (validationCommand.stackClearing) {
  19073. stackSize = 0;
  19074. } else if (validationCommand.resetStack) {
  19075. stackSize = 0;
  19076. undefStack = false;
  19077. } else if (validationCommand.undefStack) {
  19078. stackSize = 0;
  19079. undefStack = true;
  19080. firstStackClearing = false;
  19081. }
  19082. }
  19083. }
  19084. if (!valid) {
  19085. // resetting invalid charstring to single 'endchar'
  19086. charStrings.set(i, new Uint8Array([14]));
  19087. }
  19088. }
  19089. return { charStrings: charStrings, seacs: seacs, widths: widths };
  19090. },
  19091. emptyPrivateDictionary:
  19092. function CFFParser_emptyPrivateDictionary(parentDict) {
  19093. var privateDict = this.createDict(CFFPrivateDict, [],
  19094. parentDict.strings);
  19095. parentDict.setByKey(18, [0, 0]);
  19096. parentDict.privateDict = privateDict;
  19097. },
  19098. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  19099. // no private dict, do nothing
  19100. if (!parentDict.hasName('Private')) {
  19101. this.emptyPrivateDictionary(parentDict);
  19102. return;
  19103. }
  19104. var privateOffset = parentDict.getByName('Private');
  19105. // make sure the params are formatted correctly
  19106. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  19107. parentDict.removeByName('Private');
  19108. return;
  19109. }
  19110. var size = privateOffset[0];
  19111. var offset = privateOffset[1];
  19112. // remove empty dicts or ones that refer to invalid location
  19113. if (size === 0 || offset >= this.bytes.length) {
  19114. this.emptyPrivateDictionary(parentDict);
  19115. return;
  19116. }
  19117. var privateDictEnd = offset + size;
  19118. var dictData = this.bytes.subarray(offset, privateDictEnd);
  19119. var dict = this.parseDict(dictData);
  19120. var privateDict = this.createDict(CFFPrivateDict, dict,
  19121. parentDict.strings);
  19122. parentDict.privateDict = privateDict;
  19123. // Parse the Subrs index also since it's relative to the private dict.
  19124. if (!privateDict.getByName('Subrs')) {
  19125. return;
  19126. }
  19127. var subrsOffset = privateDict.getByName('Subrs');
  19128. var relativeOffset = offset + subrsOffset;
  19129. // Validate the offset.
  19130. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  19131. this.emptyPrivateDictionary(parentDict);
  19132. return;
  19133. }
  19134. var subrsIndex = this.parseIndex(relativeOffset);
  19135. privateDict.subrsIndex = subrsIndex.obj;
  19136. },
  19137. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  19138. if (pos === 0) {
  19139. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  19140. ISOAdobeCharset);
  19141. } else if (pos === 1) {
  19142. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  19143. ExpertCharset);
  19144. } else if (pos === 2) {
  19145. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  19146. ExpertSubsetCharset);
  19147. }
  19148. var bytes = this.bytes;
  19149. var start = pos;
  19150. var format = bytes[pos++];
  19151. var charset = ['.notdef'];
  19152. var id, count, i;
  19153. // subtract 1 for the .notdef glyph
  19154. length -= 1;
  19155. switch (format) {
  19156. case 0:
  19157. for (i = 0; i < length; i++) {
  19158. id = (bytes[pos++] << 8) | bytes[pos++];
  19159. charset.push(cid ? id : strings.get(id));
  19160. }
  19161. break;
  19162. case 1:
  19163. while (charset.length <= length) {
  19164. id = (bytes[pos++] << 8) | bytes[pos++];
  19165. count = bytes[pos++];
  19166. for (i = 0; i <= count; i++) {
  19167. charset.push(cid ? id++ : strings.get(id++));
  19168. }
  19169. }
  19170. break;
  19171. case 2:
  19172. while (charset.length <= length) {
  19173. id = (bytes[pos++] << 8) | bytes[pos++];
  19174. count = (bytes[pos++] << 8) | bytes[pos++];
  19175. for (i = 0; i <= count; i++) {
  19176. charset.push(cid ? id++ : strings.get(id++));
  19177. }
  19178. }
  19179. break;
  19180. default:
  19181. error('Unknown charset format');
  19182. }
  19183. // Raw won't be needed if we actually compile the charset.
  19184. var end = pos;
  19185. var raw = bytes.subarray(start, end);
  19186. return new CFFCharset(false, format, charset, raw);
  19187. },
  19188. parseEncoding: function CFFParser_parseEncoding(pos,
  19189. properties,
  19190. strings,
  19191. charset) {
  19192. var encoding = {};
  19193. var bytes = this.bytes;
  19194. var predefined = false;
  19195. var hasSupplement = false;
  19196. var format, i, ii;
  19197. var raw = null;
  19198. function readSupplement() {
  19199. var supplementsCount = bytes[pos++];
  19200. for (i = 0; i < supplementsCount; i++) {
  19201. var code = bytes[pos++];
  19202. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  19203. encoding[code] = charset.indexOf(strings.get(sid));
  19204. }
  19205. }
  19206. if (pos === 0 || pos === 1) {
  19207. predefined = true;
  19208. format = pos;
  19209. var baseEncoding = pos ? Encodings.ExpertEncoding :
  19210. Encodings.StandardEncoding;
  19211. for (i = 0, ii = charset.length; i < ii; i++) {
  19212. var index = baseEncoding.indexOf(charset[i]);
  19213. if (index !== -1) {
  19214. encoding[index] = i;
  19215. }
  19216. }
  19217. } else {
  19218. var dataStart = pos;
  19219. format = bytes[pos++];
  19220. switch (format & 0x7f) {
  19221. case 0:
  19222. var glyphsCount = bytes[pos++];
  19223. for (i = 1; i <= glyphsCount; i++) {
  19224. encoding[bytes[pos++]] = i;
  19225. }
  19226. break;
  19227. case 1:
  19228. var rangesCount = bytes[pos++];
  19229. var gid = 1;
  19230. for (i = 0; i < rangesCount; i++) {
  19231. var start = bytes[pos++];
  19232. var left = bytes[pos++];
  19233. for (var j = start; j <= start + left; j++) {
  19234. encoding[j] = gid++;
  19235. }
  19236. }
  19237. break;
  19238. default:
  19239. error('Unknow encoding format: ' + format + ' in CFF');
  19240. break;
  19241. }
  19242. var dataEnd = pos;
  19243. if (format & 0x80) {
  19244. // The font sanitizer does not support CFF encoding with a
  19245. // supplement, since the encoding is not really used to map
  19246. // between gid to glyph, let's overwrite what is declared in
  19247. // the top dictionary to let the sanitizer think the font use
  19248. // StandardEncoding, that's a lie but that's ok.
  19249. bytes[dataStart] &= 0x7f;
  19250. readSupplement();
  19251. hasSupplement = true;
  19252. }
  19253. raw = bytes.subarray(dataStart, dataEnd);
  19254. }
  19255. format = format & 0x7f;
  19256. return new CFFEncoding(predefined, format, encoding, raw);
  19257. },
  19258. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  19259. var start = pos;
  19260. var bytes = this.bytes;
  19261. var format = bytes[pos++];
  19262. var fdSelect = [];
  19263. var i;
  19264. switch (format) {
  19265. case 0:
  19266. for (i = 0; i < length; ++i) {
  19267. var id = bytes[pos++];
  19268. fdSelect.push(id);
  19269. }
  19270. break;
  19271. case 3:
  19272. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  19273. for (i = 0; i < rangesCount; ++i) {
  19274. var first = (bytes[pos++] << 8) | bytes[pos++];
  19275. var fdIndex = bytes[pos++];
  19276. var next = (bytes[pos] << 8) | bytes[pos + 1];
  19277. for (var j = first; j < next; ++j) {
  19278. fdSelect.push(fdIndex);
  19279. }
  19280. }
  19281. // Advance past the sentinel(next).
  19282. pos += 2;
  19283. break;
  19284. default:
  19285. error('Unknown fdselect format ' + format);
  19286. break;
  19287. }
  19288. var end = pos;
  19289. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  19290. }
  19291. };
  19292. return CFFParser;
  19293. })();
  19294. // Compact Font Format
  19295. var CFF = (function CFFClosure() {
  19296. function CFF() {
  19297. this.header = null;
  19298. this.names = [];
  19299. this.topDict = null;
  19300. this.strings = new CFFStrings();
  19301. this.globalSubrIndex = null;
  19302. // The following could really be per font, but since we only have one font
  19303. // store them here.
  19304. this.encoding = null;
  19305. this.charset = null;
  19306. this.charStrings = null;
  19307. this.fdArray = [];
  19308. this.fdSelect = null;
  19309. this.isCIDFont = false;
  19310. }
  19311. return CFF;
  19312. })();
  19313. var CFFHeader = (function CFFHeaderClosure() {
  19314. function CFFHeader(major, minor, hdrSize, offSize) {
  19315. this.major = major;
  19316. this.minor = minor;
  19317. this.hdrSize = hdrSize;
  19318. this.offSize = offSize;
  19319. }
  19320. return CFFHeader;
  19321. })();
  19322. var CFFStrings = (function CFFStringsClosure() {
  19323. function CFFStrings() {
  19324. this.strings = [];
  19325. }
  19326. CFFStrings.prototype = {
  19327. get: function CFFStrings_get(index) {
  19328. if (index >= 0 && index <= 390) {
  19329. return CFFStandardStrings[index];
  19330. }
  19331. if (index - 391 <= this.strings.length) {
  19332. return this.strings[index - 391];
  19333. }
  19334. return CFFStandardStrings[0];
  19335. },
  19336. add: function CFFStrings_add(value) {
  19337. this.strings.push(value);
  19338. },
  19339. get count() {
  19340. return this.strings.length;
  19341. }
  19342. };
  19343. return CFFStrings;
  19344. })();
  19345. var CFFIndex = (function CFFIndexClosure() {
  19346. function CFFIndex() {
  19347. this.objects = [];
  19348. this.length = 0;
  19349. }
  19350. CFFIndex.prototype = {
  19351. add: function CFFIndex_add(data) {
  19352. this.length += data.length;
  19353. this.objects.push(data);
  19354. },
  19355. set: function CFFIndex_set(index, data) {
  19356. this.length += data.length - this.objects[index].length;
  19357. this.objects[index] = data;
  19358. },
  19359. get: function CFFIndex_get(index) {
  19360. return this.objects[index];
  19361. },
  19362. get count() {
  19363. return this.objects.length;
  19364. }
  19365. };
  19366. return CFFIndex;
  19367. })();
  19368. var CFFDict = (function CFFDictClosure() {
  19369. function CFFDict(tables, strings) {
  19370. this.keyToNameMap = tables.keyToNameMap;
  19371. this.nameToKeyMap = tables.nameToKeyMap;
  19372. this.defaults = tables.defaults;
  19373. this.types = tables.types;
  19374. this.opcodes = tables.opcodes;
  19375. this.order = tables.order;
  19376. this.strings = strings;
  19377. this.values = {};
  19378. }
  19379. CFFDict.prototype = {
  19380. // value should always be an array
  19381. setByKey: function CFFDict_setByKey(key, value) {
  19382. if (!(key in this.keyToNameMap)) {
  19383. return false;
  19384. }
  19385. // ignore empty values
  19386. if (value.length === 0) {
  19387. return true;
  19388. }
  19389. var type = this.types[key];
  19390. // remove the array wrapping these types of values
  19391. if (type === 'num' || type === 'sid' || type === 'offset') {
  19392. value = value[0];
  19393. }
  19394. this.values[key] = value;
  19395. return true;
  19396. },
  19397. setByName: function CFFDict_setByName(name, value) {
  19398. if (!(name in this.nameToKeyMap)) {
  19399. error('Invalid dictionary name "' + name + '"');
  19400. }
  19401. this.values[this.nameToKeyMap[name]] = value;
  19402. },
  19403. hasName: function CFFDict_hasName(name) {
  19404. return this.nameToKeyMap[name] in this.values;
  19405. },
  19406. getByName: function CFFDict_getByName(name) {
  19407. if (!(name in this.nameToKeyMap)) {
  19408. error('Invalid dictionary name "' + name + '"');
  19409. }
  19410. var key = this.nameToKeyMap[name];
  19411. if (!(key in this.values)) {
  19412. return this.defaults[key];
  19413. }
  19414. return this.values[key];
  19415. },
  19416. removeByName: function CFFDict_removeByName(name) {
  19417. delete this.values[this.nameToKeyMap[name]];
  19418. }
  19419. };
  19420. CFFDict.createTables = function CFFDict_createTables(layout) {
  19421. var tables = {
  19422. keyToNameMap: {},
  19423. nameToKeyMap: {},
  19424. defaults: {},
  19425. types: {},
  19426. opcodes: {},
  19427. order: []
  19428. };
  19429. for (var i = 0, ii = layout.length; i < ii; ++i) {
  19430. var entry = layout[i];
  19431. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  19432. tables.keyToNameMap[key] = entry[1];
  19433. tables.nameToKeyMap[entry[1]] = key;
  19434. tables.types[key] = entry[2];
  19435. tables.defaults[key] = entry[3];
  19436. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  19437. tables.order.push(key);
  19438. }
  19439. return tables;
  19440. };
  19441. return CFFDict;
  19442. })();
  19443. var CFFTopDict = (function CFFTopDictClosure() {
  19444. var layout = [
  19445. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  19446. [[12, 20], 'SyntheticBase', 'num', null],
  19447. [0, 'version', 'sid', null],
  19448. [1, 'Notice', 'sid', null],
  19449. [[12, 0], 'Copyright', 'sid', null],
  19450. [2, 'FullName', 'sid', null],
  19451. [3, 'FamilyName', 'sid', null],
  19452. [4, 'Weight', 'sid', null],
  19453. [[12, 1], 'isFixedPitch', 'num', 0],
  19454. [[12, 2], 'ItalicAngle', 'num', 0],
  19455. [[12, 3], 'UnderlinePosition', 'num', -100],
  19456. [[12, 4], 'UnderlineThickness', 'num', 50],
  19457. [[12, 5], 'PaintType', 'num', 0],
  19458. [[12, 6], 'CharstringType', 'num', 2],
  19459. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  19460. [0.001, 0, 0, 0.001, 0, 0]],
  19461. [13, 'UniqueID', 'num', null],
  19462. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  19463. [[12, 8], 'StrokeWidth', 'num', 0],
  19464. [14, 'XUID', 'array', null],
  19465. [15, 'charset', 'offset', 0],
  19466. [16, 'Encoding', 'offset', 0],
  19467. [17, 'CharStrings', 'offset', 0],
  19468. [18, 'Private', ['offset', 'offset'], null],
  19469. [[12, 21], 'PostScript', 'sid', null],
  19470. [[12, 22], 'BaseFontName', 'sid', null],
  19471. [[12, 23], 'BaseFontBlend', 'delta', null],
  19472. [[12, 31], 'CIDFontVersion', 'num', 0],
  19473. [[12, 32], 'CIDFontRevision', 'num', 0],
  19474. [[12, 33], 'CIDFontType', 'num', 0],
  19475. [[12, 34], 'CIDCount', 'num', 8720],
  19476. [[12, 35], 'UIDBase', 'num', null],
  19477. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  19478. // before FDArray.
  19479. [[12, 37], 'FDSelect', 'offset', null],
  19480. [[12, 36], 'FDArray', 'offset', null],
  19481. [[12, 38], 'FontName', 'sid', null]
  19482. ];
  19483. var tables = null;
  19484. function CFFTopDict(strings) {
  19485. if (tables === null) {
  19486. tables = CFFDict.createTables(layout);
  19487. }
  19488. CFFDict.call(this, tables, strings);
  19489. this.privateDict = null;
  19490. }
  19491. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  19492. return CFFTopDict;
  19493. })();
  19494. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  19495. var layout = [
  19496. [6, 'BlueValues', 'delta', null],
  19497. [7, 'OtherBlues', 'delta', null],
  19498. [8, 'FamilyBlues', 'delta', null],
  19499. [9, 'FamilyOtherBlues', 'delta', null],
  19500. [[12, 9], 'BlueScale', 'num', 0.039625],
  19501. [[12, 10], 'BlueShift', 'num', 7],
  19502. [[12, 11], 'BlueFuzz', 'num', 1],
  19503. [10, 'StdHW', 'num', null],
  19504. [11, 'StdVW', 'num', null],
  19505. [[12, 12], 'StemSnapH', 'delta', null],
  19506. [[12, 13], 'StemSnapV', 'delta', null],
  19507. [[12, 14], 'ForceBold', 'num', 0],
  19508. [[12, 17], 'LanguageGroup', 'num', 0],
  19509. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  19510. [[12, 19], 'initialRandomSeed', 'num', 0],
  19511. [20, 'defaultWidthX', 'num', 0],
  19512. [21, 'nominalWidthX', 'num', 0],
  19513. [19, 'Subrs', 'offset', null]
  19514. ];
  19515. var tables = null;
  19516. function CFFPrivateDict(strings) {
  19517. if (tables === null) {
  19518. tables = CFFDict.createTables(layout);
  19519. }
  19520. CFFDict.call(this, tables, strings);
  19521. this.subrsIndex = null;
  19522. }
  19523. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  19524. return CFFPrivateDict;
  19525. })();
  19526. var CFFCharsetPredefinedTypes = {
  19527. ISO_ADOBE: 0,
  19528. EXPERT: 1,
  19529. EXPERT_SUBSET: 2
  19530. };
  19531. var CFFCharset = (function CFFCharsetClosure() {
  19532. function CFFCharset(predefined, format, charset, raw) {
  19533. this.predefined = predefined;
  19534. this.format = format;
  19535. this.charset = charset;
  19536. this.raw = raw;
  19537. }
  19538. return CFFCharset;
  19539. })();
  19540. var CFFEncoding = (function CFFEncodingClosure() {
  19541. function CFFEncoding(predefined, format, encoding, raw) {
  19542. this.predefined = predefined;
  19543. this.format = format;
  19544. this.encoding = encoding;
  19545. this.raw = raw;
  19546. }
  19547. return CFFEncoding;
  19548. })();
  19549. var CFFFDSelect = (function CFFFDSelectClosure() {
  19550. function CFFFDSelect(fdSelect, raw) {
  19551. this.fdSelect = fdSelect;
  19552. this.raw = raw;
  19553. }
  19554. return CFFFDSelect;
  19555. })();
  19556. // Helper class to keep track of where an offset is within the data and helps
  19557. // filling in that offset once it's known.
  19558. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  19559. function CFFOffsetTracker() {
  19560. this.offsets = {};
  19561. }
  19562. CFFOffsetTracker.prototype = {
  19563. isTracking: function CFFOffsetTracker_isTracking(key) {
  19564. return key in this.offsets;
  19565. },
  19566. track: function CFFOffsetTracker_track(key, location) {
  19567. if (key in this.offsets) {
  19568. error('Already tracking location of ' + key);
  19569. }
  19570. this.offsets[key] = location;
  19571. },
  19572. offset: function CFFOffsetTracker_offset(value) {
  19573. for (var key in this.offsets) {
  19574. this.offsets[key] += value;
  19575. }
  19576. },
  19577. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  19578. values,
  19579. output) {
  19580. if (!(key in this.offsets)) {
  19581. error('Not tracking location of ' + key);
  19582. }
  19583. var data = output.data;
  19584. var dataOffset = this.offsets[key];
  19585. var size = 5;
  19586. for (var i = 0, ii = values.length; i < ii; ++i) {
  19587. var offset0 = i * size + dataOffset;
  19588. var offset1 = offset0 + 1;
  19589. var offset2 = offset0 + 2;
  19590. var offset3 = offset0 + 3;
  19591. var offset4 = offset0 + 4;
  19592. // It's easy to screw up offsets so perform this sanity check.
  19593. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  19594. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  19595. error('writing to an offset that is not empty');
  19596. }
  19597. var value = values[i];
  19598. data[offset0] = 0x1d;
  19599. data[offset1] = (value >> 24) & 0xFF;
  19600. data[offset2] = (value >> 16) & 0xFF;
  19601. data[offset3] = (value >> 8) & 0xFF;
  19602. data[offset4] = value & 0xFF;
  19603. }
  19604. }
  19605. };
  19606. return CFFOffsetTracker;
  19607. })();
  19608. // Takes a CFF and converts it to the binary representation.
  19609. var CFFCompiler = (function CFFCompilerClosure() {
  19610. function CFFCompiler(cff) {
  19611. this.cff = cff;
  19612. }
  19613. CFFCompiler.prototype = {
  19614. compile: function CFFCompiler_compile() {
  19615. var cff = this.cff;
  19616. var output = {
  19617. data: [],
  19618. length: 0,
  19619. add: function CFFCompiler_add(data) {
  19620. this.data = this.data.concat(data);
  19621. this.length = this.data.length;
  19622. }
  19623. };
  19624. // Compile the five entries that must be in order.
  19625. var header = this.compileHeader(cff.header);
  19626. output.add(header);
  19627. var nameIndex = this.compileNameIndex(cff.names);
  19628. output.add(nameIndex);
  19629. if (cff.isCIDFont) {
  19630. // The spec is unclear on how font matrices should relate to each other
  19631. // when there is one in the main top dict and the sub top dicts.
  19632. // Windows handles this differently than linux and osx so we have to
  19633. // normalize to work on all.
  19634. // Rules based off of some mailing list discussions:
  19635. // - If main font has a matrix and subfont doesn't, use the main matrix.
  19636. // - If no main font matrix and there is a subfont matrix, use the
  19637. // subfont matrix.
  19638. // - If both have matrices, concat together.
  19639. // - If neither have matrices, use default.
  19640. // To make this work on all platforms we move the top matrix into each
  19641. // sub top dict and concat if necessary.
  19642. if (cff.topDict.hasName('FontMatrix')) {
  19643. var base = cff.topDict.getByName('FontMatrix');
  19644. cff.topDict.removeByName('FontMatrix');
  19645. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  19646. var subDict = cff.fdArray[i];
  19647. var matrix = base.slice(0);
  19648. if (subDict.hasName('FontMatrix')) {
  19649. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  19650. }
  19651. subDict.setByName('FontMatrix', matrix);
  19652. }
  19653. }
  19654. }
  19655. var compiled = this.compileTopDicts([cff.topDict],
  19656. output.length,
  19657. cff.isCIDFont);
  19658. output.add(compiled.output);
  19659. var topDictTracker = compiled.trackers[0];
  19660. var stringIndex = this.compileStringIndex(cff.strings.strings);
  19661. output.add(stringIndex);
  19662. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  19663. output.add(globalSubrIndex);
  19664. // Now start on the other entries that have no specfic order.
  19665. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  19666. if (cff.encoding.predefined) {
  19667. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  19668. output);
  19669. } else {
  19670. var encoding = this.compileEncoding(cff.encoding);
  19671. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  19672. output.add(encoding);
  19673. }
  19674. }
  19675. if (cff.charset && cff.topDict.hasName('charset')) {
  19676. if (cff.charset.predefined) {
  19677. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  19678. output);
  19679. } else {
  19680. var charset = this.compileCharset(cff.charset);
  19681. topDictTracker.setEntryLocation('charset', [output.length], output);
  19682. output.add(charset);
  19683. }
  19684. }
  19685. var charStrings = this.compileCharStrings(cff.charStrings);
  19686. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  19687. output.add(charStrings);
  19688. if (cff.isCIDFont) {
  19689. // For some reason FDSelect must be in front of FDArray on windows. OSX
  19690. // and linux don't seem to care.
  19691. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  19692. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  19693. output.add(fdSelect);
  19694. // It is unclear if the sub font dictionary can have CID related
  19695. // dictionary keys, but the sanitizer doesn't like them so remove them.
  19696. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  19697. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  19698. output.add(compiled.output);
  19699. var fontDictTrackers = compiled.trackers;
  19700. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  19701. }
  19702. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  19703. // If the font data ends with INDEX whose object data is zero-length,
  19704. // the sanitizer will bail out. Add a dummy byte to avoid that.
  19705. output.add([0]);
  19706. return output.data;
  19707. },
  19708. encodeNumber: function CFFCompiler_encodeNumber(value) {
  19709. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  19710. return this.encodeInteger(value);
  19711. } else {
  19712. return this.encodeFloat(value);
  19713. }
  19714. },
  19715. encodeFloat: function CFFCompiler_encodeFloat(num) {
  19716. var value = num.toString();
  19717. // rounding inaccurate doubles
  19718. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  19719. if (m) {
  19720. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  19721. value = (Math.round(num * epsilon) / epsilon).toString();
  19722. }
  19723. var nibbles = '';
  19724. var i, ii;
  19725. for (i = 0, ii = value.length; i < ii; ++i) {
  19726. var a = value[i];
  19727. if (a === 'e') {
  19728. nibbles += value[++i] === '-' ? 'c' : 'b';
  19729. } else if (a === '.') {
  19730. nibbles += 'a';
  19731. } else if (a === '-') {
  19732. nibbles += 'e';
  19733. } else {
  19734. nibbles += a;
  19735. }
  19736. }
  19737. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  19738. var out = [30];
  19739. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  19740. out.push(parseInt(nibbles.substr(i, 2), 16));
  19741. }
  19742. return out;
  19743. },
  19744. encodeInteger: function CFFCompiler_encodeInteger(value) {
  19745. var code;
  19746. if (value >= -107 && value <= 107) {
  19747. code = [value + 139];
  19748. } else if (value >= 108 && value <= 1131) {
  19749. value = [value - 108];
  19750. code = [(value >> 8) + 247, value & 0xFF];
  19751. } else if (value >= -1131 && value <= -108) {
  19752. value = -value - 108;
  19753. code = [(value >> 8) + 251, value & 0xFF];
  19754. } else if (value >= -32768 && value <= 32767) {
  19755. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  19756. } else {
  19757. code = [0x1d,
  19758. (value >> 24) & 0xFF,
  19759. (value >> 16) & 0xFF,
  19760. (value >> 8) & 0xFF,
  19761. value & 0xFF];
  19762. }
  19763. return code;
  19764. },
  19765. compileHeader: function CFFCompiler_compileHeader(header) {
  19766. return [
  19767. header.major,
  19768. header.minor,
  19769. header.hdrSize,
  19770. header.offSize
  19771. ];
  19772. },
  19773. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  19774. var nameIndex = new CFFIndex();
  19775. for (var i = 0, ii = names.length; i < ii; ++i) {
  19776. nameIndex.add(stringToBytes(names[i]));
  19777. }
  19778. return this.compileIndex(nameIndex);
  19779. },
  19780. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  19781. length,
  19782. removeCidKeys) {
  19783. var fontDictTrackers = [];
  19784. var fdArrayIndex = new CFFIndex();
  19785. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19786. var fontDict = dicts[i];
  19787. if (removeCidKeys) {
  19788. fontDict.removeByName('CIDFontVersion');
  19789. fontDict.removeByName('CIDFontRevision');
  19790. fontDict.removeByName('CIDFontType');
  19791. fontDict.removeByName('CIDCount');
  19792. fontDict.removeByName('UIDBase');
  19793. }
  19794. var fontDictTracker = new CFFOffsetTracker();
  19795. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  19796. fontDictTrackers.push(fontDictTracker);
  19797. fdArrayIndex.add(fontDictData);
  19798. fontDictTracker.offset(length);
  19799. }
  19800. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  19801. return {
  19802. trackers: fontDictTrackers,
  19803. output: fdArrayIndex
  19804. };
  19805. },
  19806. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  19807. trackers,
  19808. output) {
  19809. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  19810. var fontDict = dicts[i];
  19811. assert(fontDict.privateDict && fontDict.hasName('Private'),
  19812. 'There must be an private dictionary.');
  19813. var privateDict = fontDict.privateDict;
  19814. var privateDictTracker = new CFFOffsetTracker();
  19815. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  19816. var outputLength = output.length;
  19817. privateDictTracker.offset(outputLength);
  19818. if (!privateDictData.length) {
  19819. // The private dictionary was empty, set the output length to zero to
  19820. // ensure the offset length isn't out of bounds in the eyes of the
  19821. // sanitizer.
  19822. outputLength = 0;
  19823. }
  19824. trackers[i].setEntryLocation('Private',
  19825. [privateDictData.length, outputLength],
  19826. output);
  19827. output.add(privateDictData);
  19828. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  19829. var subrs = this.compileIndex(privateDict.subrsIndex);
  19830. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  19831. output);
  19832. output.add(subrs);
  19833. }
  19834. }
  19835. },
  19836. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  19837. var out = [];
  19838. // The dictionary keys must be in a certain order.
  19839. var order = dict.order;
  19840. for (var i = 0; i < order.length; ++i) {
  19841. var key = order[i];
  19842. if (!(key in dict.values)) {
  19843. continue;
  19844. }
  19845. var values = dict.values[key];
  19846. var types = dict.types[key];
  19847. if (!isArray(types)) {
  19848. types = [types];
  19849. }
  19850. if (!isArray(values)) {
  19851. values = [values];
  19852. }
  19853. // Remove any empty dict values.
  19854. if (values.length === 0) {
  19855. continue;
  19856. }
  19857. for (var j = 0, jj = types.length; j < jj; ++j) {
  19858. var type = types[j];
  19859. var value = values[j];
  19860. switch (type) {
  19861. case 'num':
  19862. case 'sid':
  19863. out = out.concat(this.encodeNumber(value));
  19864. break;
  19865. case 'offset':
  19866. // For offsets we just insert a 32bit integer so we don't have to
  19867. // deal with figuring out the length of the offset when it gets
  19868. // replaced later on by the compiler.
  19869. var name = dict.keyToNameMap[key];
  19870. // Some offsets have the offset and the length, so just record the
  19871. // position of the first one.
  19872. if (!offsetTracker.isTracking(name)) {
  19873. offsetTracker.track(name, out.length);
  19874. }
  19875. out = out.concat([0x1d, 0, 0, 0, 0]);
  19876. break;
  19877. case 'array':
  19878. case 'delta':
  19879. out = out.concat(this.encodeNumber(value));
  19880. for (var k = 1, kk = values.length; k < kk; ++k) {
  19881. out = out.concat(this.encodeNumber(values[k]));
  19882. }
  19883. break;
  19884. default:
  19885. error('Unknown data type of ' + type);
  19886. break;
  19887. }
  19888. }
  19889. out = out.concat(dict.opcodes[key]);
  19890. }
  19891. return out;
  19892. },
  19893. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  19894. var stringIndex = new CFFIndex();
  19895. for (var i = 0, ii = strings.length; i < ii; ++i) {
  19896. stringIndex.add(stringToBytes(strings[i]));
  19897. }
  19898. return this.compileIndex(stringIndex);
  19899. },
  19900. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  19901. var globalSubrIndex = this.cff.globalSubrIndex;
  19902. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  19903. },
  19904. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  19905. return this.compileIndex(charStrings);
  19906. },
  19907. compileCharset: function CFFCompiler_compileCharset(charset) {
  19908. return this.compileTypedArray(charset.raw);
  19909. },
  19910. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  19911. return this.compileTypedArray(encoding.raw);
  19912. },
  19913. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  19914. return this.compileTypedArray(fdSelect);
  19915. },
  19916. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  19917. var out = [];
  19918. for (var i = 0, ii = data.length; i < ii; ++i) {
  19919. out[i] = data[i];
  19920. }
  19921. return out;
  19922. },
  19923. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  19924. trackers = trackers || [];
  19925. var objects = index.objects;
  19926. // First 2 bytes contains the number of objects contained into this index
  19927. var count = objects.length;
  19928. // If there is no object, just create an index. This technically
  19929. // should just be [0, 0] but OTS has an issue with that.
  19930. if (count === 0) {
  19931. return [0, 0, 0];
  19932. }
  19933. var data = [(count >> 8) & 0xFF, count & 0xff];
  19934. var lastOffset = 1, i;
  19935. for (i = 0; i < count; ++i) {
  19936. lastOffset += objects[i].length;
  19937. }
  19938. var offsetSize;
  19939. if (lastOffset < 0x100) {
  19940. offsetSize = 1;
  19941. } else if (lastOffset < 0x10000) {
  19942. offsetSize = 2;
  19943. } else if (lastOffset < 0x1000000) {
  19944. offsetSize = 3;
  19945. } else {
  19946. offsetSize = 4;
  19947. }
  19948. // Next byte contains the offset size use to reference object in the file
  19949. data.push(offsetSize);
  19950. // Add another offset after this one because we need a new offset
  19951. var relativeOffset = 1;
  19952. for (i = 0; i < count + 1; i++) {
  19953. if (offsetSize === 1) {
  19954. data.push(relativeOffset & 0xFF);
  19955. } else if (offsetSize === 2) {
  19956. data.push((relativeOffset >> 8) & 0xFF,
  19957. relativeOffset & 0xFF);
  19958. } else if (offsetSize === 3) {
  19959. data.push((relativeOffset >> 16) & 0xFF,
  19960. (relativeOffset >> 8) & 0xFF,
  19961. relativeOffset & 0xFF);
  19962. } else {
  19963. data.push((relativeOffset >>> 24) & 0xFF,
  19964. (relativeOffset >> 16) & 0xFF,
  19965. (relativeOffset >> 8) & 0xFF,
  19966. relativeOffset & 0xFF);
  19967. }
  19968. if (objects[i]) {
  19969. relativeOffset += objects[i].length;
  19970. }
  19971. }
  19972. for (i = 0; i < count; i++) {
  19973. // Notify the tracker where the object will be offset in the data.
  19974. if (trackers[i]) {
  19975. trackers[i].offset(data.length);
  19976. }
  19977. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  19978. data.push(objects[i][j]);
  19979. }
  19980. }
  19981. return data;
  19982. }
  19983. };
  19984. return CFFCompiler;
  19985. })();
  19986. // Workaround for seac on Windows.
  19987. (function checkSeacSupport() {
  19988. if (/Windows/.test(navigator.userAgent)) {
  19989. SEAC_ANALYSIS_ENABLED = true;
  19990. }
  19991. })();
  19992. // Workaround for Private Use Area characters in Chrome on Windows
  19993. // http://code.google.com/p/chromium/issues/detail?id=122465
  19994. // https://github.com/mozilla/pdf.js/issues/1689
  19995. (function checkChromeWindows() {
  19996. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  19997. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  19998. }
  19999. })();
  20000. var FontRendererFactory = (function FontRendererFactoryClosure() {
  20001. function getLong(data, offset) {
  20002. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20003. (data[offset + 2] << 8) | data[offset + 3];
  20004. }
  20005. function getUshort(data, offset) {
  20006. return (data[offset] << 8) | data[offset + 1];
  20007. }
  20008. function parseCmap(data, start, end) {
  20009. var offset = (getUshort(data, start + 2) === 1 ?
  20010. getLong(data, start + 8) : getLong(data, start + 16));
  20011. var format = getUshort(data, start + offset);
  20012. var length, ranges, p, i;
  20013. if (format === 4) {
  20014. length = getUshort(data, start + offset + 2);
  20015. var segCount = getUshort(data, start + offset + 6) >> 1;
  20016. p = start + offset + 14;
  20017. ranges = [];
  20018. for (i = 0; i < segCount; i++, p += 2) {
  20019. ranges[i] = {end: getUshort(data, p)};
  20020. }
  20021. p += 2;
  20022. for (i = 0; i < segCount; i++, p += 2) {
  20023. ranges[i].start = getUshort(data, p);
  20024. }
  20025. for (i = 0; i < segCount; i++, p += 2) {
  20026. ranges[i].idDelta = getUshort(data, p);
  20027. }
  20028. for (i = 0; i < segCount; i++, p += 2) {
  20029. var idOffset = getUshort(data, p);
  20030. if (idOffset === 0) {
  20031. continue;
  20032. }
  20033. ranges[i].ids = [];
  20034. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  20035. ranges[i].ids[j] = getUshort(data, p + idOffset);
  20036. idOffset += 2;
  20037. }
  20038. }
  20039. return ranges;
  20040. } else if (format === 12) {
  20041. length = getLong(data, start + offset + 4);
  20042. var groups = getLong(data, start + offset + 12);
  20043. p = start + offset + 16;
  20044. ranges = [];
  20045. for (i = 0; i < groups; i++) {
  20046. ranges.push({
  20047. start: getLong(data, p),
  20048. end: getLong(data, p + 4),
  20049. idDelta: getLong(data, p + 8) - getLong(data, p)
  20050. });
  20051. p += 12;
  20052. }
  20053. return ranges;
  20054. }
  20055. error('not supported cmap: ' + format);
  20056. }
  20057. function parseCff(data, start, end) {
  20058. var properties = {};
  20059. var parser = new CFFParser(new Stream(data, start, end - start),
  20060. properties);
  20061. var cff = parser.parse();
  20062. return {
  20063. glyphs: cff.charStrings.objects,
  20064. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  20065. cff.topDict.privateDict.subrsIndex.objects),
  20066. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  20067. };
  20068. }
  20069. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  20070. var itemSize, itemDecode;
  20071. if (isGlyphLocationsLong) {
  20072. itemSize = 4;
  20073. itemDecode = function fontItemDecodeLong(data, offset) {
  20074. return (data[offset] << 24) | (data[offset + 1] << 16) |
  20075. (data[offset + 2] << 8) | data[offset + 3];
  20076. };
  20077. } else {
  20078. itemSize = 2;
  20079. itemDecode = function fontItemDecode(data, offset) {
  20080. return (data[offset] << 9) | (data[offset + 1] << 1);
  20081. };
  20082. }
  20083. var glyphs = [];
  20084. var startOffset = itemDecode(loca, 0);
  20085. for (var j = itemSize; j < loca.length; j += itemSize) {
  20086. var endOffset = itemDecode(loca, j);
  20087. glyphs.push(glyf.subarray(startOffset, endOffset));
  20088. startOffset = endOffset;
  20089. }
  20090. return glyphs;
  20091. }
  20092. function lookupCmap(ranges, unicode) {
  20093. var code = unicode.charCodeAt(0);
  20094. var l = 0, r = ranges.length - 1;
  20095. while (l < r) {
  20096. var c = (l + r + 1) >> 1;
  20097. if (code < ranges[c].start) {
  20098. r = c - 1;
  20099. } else {
  20100. l = c;
  20101. }
  20102. }
  20103. if (ranges[l].start <= code && code <= ranges[l].end) {
  20104. return (ranges[l].idDelta + (ranges[l].ids ?
  20105. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  20106. }
  20107. return 0;
  20108. }
  20109. function compileGlyf(code, js, font) {
  20110. function moveTo(x, y) {
  20111. js.push('c.moveTo(' + x + ',' + y + ');');
  20112. }
  20113. function lineTo(x, y) {
  20114. js.push('c.lineTo(' + x + ',' + y + ');');
  20115. }
  20116. function quadraticCurveTo(xa, ya, x, y) {
  20117. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  20118. x + ',' + y + ');');
  20119. }
  20120. var i = 0;
  20121. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20122. var flags;
  20123. var x = 0, y = 0;
  20124. i += 10;
  20125. if (numberOfContours < 0) {
  20126. // composite glyph
  20127. do {
  20128. flags = (code[i] << 8) | code[i + 1];
  20129. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  20130. i += 4;
  20131. var arg1, arg2;
  20132. if ((flags & 0x01)) {
  20133. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20134. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  20135. i += 4;
  20136. } else {
  20137. arg1 = code[i++]; arg2 = code[i++];
  20138. }
  20139. if ((flags & 0x02)) {
  20140. x = arg1;
  20141. y = arg2;
  20142. } else {
  20143. x = 0; y = 0; // TODO "they are points" ?
  20144. }
  20145. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  20146. if ((flags & 0x08)) {
  20147. scaleX =
  20148. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20149. i += 2;
  20150. } else if ((flags & 0x40)) {
  20151. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20152. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20153. i += 4;
  20154. } else if ((flags & 0x80)) {
  20155. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  20156. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  20157. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  20158. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  20159. i += 8;
  20160. }
  20161. var subglyph = font.glyphs[glyphIndex];
  20162. if (subglyph) {
  20163. js.push('c.save();');
  20164. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  20165. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  20166. compileGlyf(subglyph, js, font);
  20167. js.push('c.restore();');
  20168. }
  20169. } while ((flags & 0x20));
  20170. } else {
  20171. // simple glyph
  20172. var endPtsOfContours = [];
  20173. var j, jj;
  20174. for (j = 0; j < numberOfContours; j++) {
  20175. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  20176. i += 2;
  20177. }
  20178. var instructionLength = (code[i] << 8) | code[i + 1];
  20179. i += 2 + instructionLength; // skipping the instructions
  20180. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  20181. var points = [];
  20182. while (points.length < numberOfPoints) {
  20183. flags = code[i++];
  20184. var repeat = 1;
  20185. if ((flags & 0x08)) {
  20186. repeat += code[i++];
  20187. }
  20188. while (repeat-- > 0) {
  20189. points.push({flags: flags});
  20190. }
  20191. }
  20192. for (j = 0; j < numberOfPoints; j++) {
  20193. switch (points[j].flags & 0x12) {
  20194. case 0x00:
  20195. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20196. i += 2;
  20197. break;
  20198. case 0x02:
  20199. x -= code[i++];
  20200. break;
  20201. case 0x12:
  20202. x += code[i++];
  20203. break;
  20204. }
  20205. points[j].x = x;
  20206. }
  20207. for (j = 0; j < numberOfPoints; j++) {
  20208. switch (points[j].flags & 0x24) {
  20209. case 0x00:
  20210. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  20211. i += 2;
  20212. break;
  20213. case 0x04:
  20214. y -= code[i++];
  20215. break;
  20216. case 0x24:
  20217. y += code[i++];
  20218. break;
  20219. }
  20220. points[j].y = y;
  20221. }
  20222. var startPoint = 0;
  20223. for (i = 0; i < numberOfContours; i++) {
  20224. var endPoint = endPtsOfContours[i];
  20225. // contours might have implicit points, which is located in the middle
  20226. // between two neighboring off-curve points
  20227. var contour = points.slice(startPoint, endPoint + 1);
  20228. if ((contour[0].flags & 1)) {
  20229. contour.push(contour[0]); // using start point at the contour end
  20230. } else if ((contour[contour.length - 1].flags & 1)) {
  20231. // first is off-curve point, trying to use one from the end
  20232. contour.unshift(contour[contour.length - 1]);
  20233. } else {
  20234. // start and end are off-curve points, creating implicit one
  20235. var p = {
  20236. flags: 1,
  20237. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  20238. y: (contour[0].y + contour[contour.length - 1].y) / 2
  20239. };
  20240. contour.unshift(p);
  20241. contour.push(p);
  20242. }
  20243. moveTo(contour[0].x, contour[0].y);
  20244. for (j = 1, jj = contour.length; j < jj; j++) {
  20245. if ((contour[j].flags & 1)) {
  20246. lineTo(contour[j].x, contour[j].y);
  20247. } else if ((contour[j + 1].flags & 1)){
  20248. quadraticCurveTo(contour[j].x, contour[j].y,
  20249. contour[j + 1].x, contour[j + 1].y);
  20250. j++;
  20251. } else {
  20252. quadraticCurveTo(contour[j].x, contour[j].y,
  20253. (contour[j].x + contour[j + 1].x) / 2,
  20254. (contour[j].y + contour[j + 1].y) / 2);
  20255. }
  20256. }
  20257. startPoint = endPoint + 1;
  20258. }
  20259. }
  20260. }
  20261. function compileCharString(code, js, font) {
  20262. var stack = [];
  20263. var x = 0, y = 0;
  20264. var stems = 0;
  20265. function moveTo(x, y) {
  20266. js.push('c.moveTo(' + x + ',' + y + ');');
  20267. }
  20268. function lineTo(x, y) {
  20269. js.push('c.lineTo(' + x + ',' + y + ');');
  20270. }
  20271. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  20272. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  20273. x + ',' + y + ');');
  20274. }
  20275. function parse(code) {
  20276. var i = 0;
  20277. while (i < code.length) {
  20278. var stackClean = false;
  20279. var v = code[i++];
  20280. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  20281. switch (v) {
  20282. case 1: // hstem
  20283. stems += stack.length >> 1;
  20284. stackClean = true;
  20285. break;
  20286. case 3: // vstem
  20287. stems += stack.length >> 1;
  20288. stackClean = true;
  20289. break;
  20290. case 4: // vmoveto
  20291. y += stack.pop();
  20292. moveTo(x, y);
  20293. stackClean = true;
  20294. break;
  20295. case 5: // rlineto
  20296. while (stack.length > 0) {
  20297. x += stack.shift();
  20298. y += stack.shift();
  20299. lineTo(x, y);
  20300. }
  20301. break;
  20302. case 6: // hlineto
  20303. while (stack.length > 0) {
  20304. x += stack.shift();
  20305. lineTo(x, y);
  20306. if (stack.length === 0) {
  20307. break;
  20308. }
  20309. y += stack.shift();
  20310. lineTo(x, y);
  20311. }
  20312. break;
  20313. case 7: // vlineto
  20314. while (stack.length > 0) {
  20315. y += stack.shift();
  20316. lineTo(x, y);
  20317. if (stack.length === 0) {
  20318. break;
  20319. }
  20320. x += stack.shift();
  20321. lineTo(x, y);
  20322. }
  20323. break;
  20324. case 8: // rrcurveto
  20325. while (stack.length > 0) {
  20326. xa = x + stack.shift(); ya = y + stack.shift();
  20327. xb = xa + stack.shift(); yb = ya + stack.shift();
  20328. x = xb + stack.shift(); y = yb + stack.shift();
  20329. bezierCurveTo(xa, ya, xb, yb, x, y);
  20330. }
  20331. break;
  20332. case 10: // callsubr
  20333. n = stack.pop() + font.subrsBias;
  20334. subrCode = font.subrs[n];
  20335. if (subrCode) {
  20336. parse(subrCode);
  20337. }
  20338. break;
  20339. case 11: // return
  20340. return;
  20341. case 12:
  20342. v = code[i++];
  20343. switch (v) {
  20344. case 34: // flex
  20345. xa = x + stack.shift();
  20346. xb = xa + stack.shift(); y1 = y + stack.shift();
  20347. x = xb + stack.shift();
  20348. bezierCurveTo(xa, y, xb, y1, x, y1);
  20349. xa = x + stack.shift();
  20350. xb = xa + stack.shift();
  20351. x = xb + stack.shift();
  20352. bezierCurveTo(xa, y1, xb, y, x, y);
  20353. break;
  20354. case 35: // flex
  20355. xa = x + stack.shift(); ya = y + stack.shift();
  20356. xb = xa + stack.shift(); yb = ya + stack.shift();
  20357. x = xb + stack.shift(); y = yb + stack.shift();
  20358. bezierCurveTo(xa, ya, xb, yb, x, y);
  20359. xa = x + stack.shift(); ya = y + stack.shift();
  20360. xb = xa + stack.shift(); yb = ya + stack.shift();
  20361. x = xb + stack.shift(); y = yb + stack.shift();
  20362. bezierCurveTo(xa, ya, xb, yb, x, y);
  20363. stack.pop(); // fd
  20364. break;
  20365. case 36: // hflex1
  20366. xa = x + stack.shift(); y1 = y + stack.shift();
  20367. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  20368. x = xb + stack.shift();
  20369. bezierCurveTo(xa, y1, xb, y2, x, y2);
  20370. xa = x + stack.shift();
  20371. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  20372. x = xb + stack.shift();
  20373. bezierCurveTo(xa, y2, xb, y3, x, y);
  20374. break;
  20375. case 37: // flex1
  20376. var x0 = x, y0 = y;
  20377. xa = x + stack.shift(); ya = y + stack.shift();
  20378. xb = xa + stack.shift(); yb = ya + stack.shift();
  20379. x = xb + stack.shift(); y = yb + stack.shift();
  20380. bezierCurveTo(xa, ya, xb, yb, x, y);
  20381. xa = x + stack.shift(); ya = y + stack.shift();
  20382. xb = xa + stack.shift(); yb = ya + stack.shift();
  20383. x = xb; y = yb;
  20384. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20385. x += stack.shift();
  20386. } else {
  20387. y += stack.shift();
  20388. }
  20389. bezierCurveTo(xa, ya, xb, yb, x, y);
  20390. break;
  20391. default:
  20392. error('unknown operator: 12 ' + v);
  20393. }
  20394. break;
  20395. case 14: // endchar
  20396. if (stack.length >= 4) {
  20397. var achar = stack.pop();
  20398. var bchar = stack.pop();
  20399. y = stack.pop();
  20400. x = stack.pop();
  20401. js.push('c.save();');
  20402. js.push('c.translate('+ x + ',' + y + ');');
  20403. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20404. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20405. compileCharString(font.glyphs[gid], js, font);
  20406. js.push('c.restore();');
  20407. gid = lookupCmap(font.cmap, String.fromCharCode(
  20408. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20409. compileCharString(font.glyphs[gid], js, font);
  20410. }
  20411. return;
  20412. case 18: // hstemhm
  20413. stems += stack.length >> 1;
  20414. stackClean = true;
  20415. break;
  20416. case 19: // hintmask
  20417. stems += stack.length >> 1;
  20418. i += (stems + 7) >> 3;
  20419. stackClean = true;
  20420. break;
  20421. case 20: // cntrmask
  20422. stems += stack.length >> 1;
  20423. i += (stems + 7) >> 3;
  20424. stackClean = true;
  20425. break;
  20426. case 21: // rmoveto
  20427. y += stack.pop();
  20428. x += stack.pop();
  20429. moveTo(x, y);
  20430. stackClean = true;
  20431. break;
  20432. case 22: // hmoveto
  20433. x += stack.pop();
  20434. moveTo(x, y);
  20435. stackClean = true;
  20436. break;
  20437. case 23: // vstemhm
  20438. stems += stack.length >> 1;
  20439. stackClean = true;
  20440. break;
  20441. case 24: // rcurveline
  20442. while (stack.length > 2) {
  20443. xa = x + stack.shift(); ya = y + stack.shift();
  20444. xb = xa + stack.shift(); yb = ya + stack.shift();
  20445. x = xb + stack.shift(); y = yb + stack.shift();
  20446. bezierCurveTo(xa, ya, xb, yb, x, y);
  20447. }
  20448. x += stack.shift();
  20449. y += stack.shift();
  20450. lineTo(x, y);
  20451. break;
  20452. case 25: // rlinecurve
  20453. while (stack.length > 6) {
  20454. x += stack.shift();
  20455. y += stack.shift();
  20456. lineTo(x, y);
  20457. }
  20458. xa = x + stack.shift(); ya = y + stack.shift();
  20459. xb = xa + stack.shift(); yb = ya + stack.shift();
  20460. x = xb + stack.shift(); y = yb + stack.shift();
  20461. bezierCurveTo(xa, ya, xb, yb, x, y);
  20462. break;
  20463. case 26: // vvcurveto
  20464. if (stack.length % 2) {
  20465. x += stack.shift();
  20466. }
  20467. while (stack.length > 0) {
  20468. xa = x; ya = y + stack.shift();
  20469. xb = xa + stack.shift(); yb = ya + stack.shift();
  20470. x = xb; y = yb + stack.shift();
  20471. bezierCurveTo(xa, ya, xb, yb, x, y);
  20472. }
  20473. break;
  20474. case 27: // hhcurveto
  20475. if (stack.length % 2) {
  20476. y += stack.shift();
  20477. }
  20478. while (stack.length > 0) {
  20479. xa = x + stack.shift(); ya = y;
  20480. xb = xa + stack.shift(); yb = ya + stack.shift();
  20481. x = xb + stack.shift(); y = yb;
  20482. bezierCurveTo(xa, ya, xb, yb, x, y);
  20483. }
  20484. break;
  20485. case 28:
  20486. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20487. i += 2;
  20488. break;
  20489. case 29: // callgsubr
  20490. n = stack.pop() + font.gsubrsBias;
  20491. subrCode = font.gsubrs[n];
  20492. if (subrCode) {
  20493. parse(subrCode);
  20494. }
  20495. break;
  20496. case 30: // vhcurveto
  20497. while (stack.length > 0) {
  20498. xa = x; ya = y + stack.shift();
  20499. xb = xa + stack.shift(); yb = ya + stack.shift();
  20500. x = xb + stack.shift();
  20501. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20502. bezierCurveTo(xa, ya, xb, yb, x, y);
  20503. if (stack.length === 0) {
  20504. break;
  20505. }
  20506. xa = x + stack.shift(); ya = y;
  20507. xb = xa + stack.shift(); yb = ya + stack.shift();
  20508. y = yb + stack.shift();
  20509. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20510. bezierCurveTo(xa, ya, xb, yb, x, y);
  20511. }
  20512. break;
  20513. case 31: // hvcurveto
  20514. while (stack.length > 0) {
  20515. xa = x + stack.shift(); ya = y;
  20516. xb = xa + stack.shift(); yb = ya + stack.shift();
  20517. y = yb + stack.shift();
  20518. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20519. bezierCurveTo(xa, ya, xb, yb, x, y);
  20520. if (stack.length === 0) {
  20521. break;
  20522. }
  20523. xa = x; ya = y + stack.shift();
  20524. xb = xa + stack.shift(); yb = ya + stack.shift();
  20525. x = xb + stack.shift();
  20526. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20527. bezierCurveTo(xa, ya, xb, yb, x, y);
  20528. }
  20529. break;
  20530. default:
  20531. if (v < 32) {
  20532. error('unknown operator: ' + v);
  20533. }
  20534. if (v < 247) {
  20535. stack.push(v - 139);
  20536. } else if (v < 251) {
  20537. stack.push((v - 247) * 256 + code[i++] + 108);
  20538. } else if (v < 255) {
  20539. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20540. } else {
  20541. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20542. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20543. i += 4;
  20544. }
  20545. break;
  20546. }
  20547. if (stackClean) {
  20548. stack.length = 0;
  20549. }
  20550. }
  20551. }
  20552. parse(code);
  20553. }
  20554. var noop = '';
  20555. function CompiledFont(fontMatrix) {
  20556. this.compiledGlyphs = {};
  20557. this.fontMatrix = fontMatrix;
  20558. }
  20559. CompiledFont.prototype = {
  20560. getPathJs: function (unicode) {
  20561. var gid = lookupCmap(this.cmap, unicode);
  20562. var fn = this.compiledGlyphs[gid];
  20563. if (!fn) {
  20564. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20565. }
  20566. return fn;
  20567. },
  20568. compileGlyph: function (code) {
  20569. if (!code || code.length === 0 || code[0] === 14) {
  20570. return noop;
  20571. }
  20572. var js = [];
  20573. js.push('c.save();');
  20574. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  20575. js.push('c.scale(size, -size);');
  20576. this.compileGlyphImpl(code, js);
  20577. js.push('c.restore();');
  20578. return js.join('\n');
  20579. },
  20580. compileGlyphImpl: function () {
  20581. error('Children classes should implement this.');
  20582. },
  20583. hasBuiltPath: function (unicode) {
  20584. var gid = lookupCmap(this.cmap, unicode);
  20585. return gid in this.compiledGlyphs;
  20586. }
  20587. };
  20588. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20589. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20590. CompiledFont.call(this, fontMatrix);
  20591. this.glyphs = glyphs;
  20592. this.cmap = cmap;
  20593. this.compiledGlyphs = [];
  20594. }
  20595. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20596. compileGlyphImpl: function (code, js) {
  20597. compileGlyf(code, js, this);
  20598. }
  20599. });
  20600. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20601. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20602. CompiledFont.call(this, fontMatrix);
  20603. this.glyphs = cffInfo.glyphs;
  20604. this.gsubrs = cffInfo.gsubrs || [];
  20605. this.subrs = cffInfo.subrs || [];
  20606. this.cmap = cmap;
  20607. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20608. this.compiledGlyphs = [];
  20609. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20610. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20611. this.subrsBias = (this.subrs.length < 1240 ?
  20612. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20613. }
  20614. Util.inherit(Type2Compiled, CompiledFont, {
  20615. compileGlyphImpl: function (code, js) {
  20616. compileCharString(code, js, this);
  20617. }
  20618. });
  20619. return {
  20620. create: function FontRendererFactory_create(font) {
  20621. var data = new Uint8Array(font.data);
  20622. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20623. var numTables = getUshort(data, 4);
  20624. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20625. var tag = bytesToString(data.subarray(p, p + 4));
  20626. var offset = getLong(data, p + 8);
  20627. var length = getLong(data, p + 12);
  20628. switch (tag) {
  20629. case 'cmap':
  20630. cmap = parseCmap(data, offset, offset + length);
  20631. break;
  20632. case 'glyf':
  20633. glyf = data.subarray(offset, offset + length);
  20634. break;
  20635. case 'loca':
  20636. loca = data.subarray(offset, offset + length);
  20637. break;
  20638. case 'head':
  20639. unitsPerEm = getUshort(data, offset + 18);
  20640. indexToLocFormat = getUshort(data, offset + 50);
  20641. break;
  20642. case 'CFF ':
  20643. cff = parseCff(data, offset, offset + length);
  20644. break;
  20645. }
  20646. }
  20647. if (glyf) {
  20648. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20649. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20650. return new TrueTypeCompiled(
  20651. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20652. } else {
  20653. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20654. }
  20655. }
  20656. };
  20657. })();
  20658. var GlyphsUnicode = {
  20659. A: 0x0041,
  20660. AE: 0x00C6,
  20661. AEacute: 0x01FC,
  20662. AEmacron: 0x01E2,
  20663. AEsmall: 0xF7E6,
  20664. Aacute: 0x00C1,
  20665. Aacutesmall: 0xF7E1,
  20666. Abreve: 0x0102,
  20667. Abreveacute: 0x1EAE,
  20668. Abrevecyrillic: 0x04D0,
  20669. Abrevedotbelow: 0x1EB6,
  20670. Abrevegrave: 0x1EB0,
  20671. Abrevehookabove: 0x1EB2,
  20672. Abrevetilde: 0x1EB4,
  20673. Acaron: 0x01CD,
  20674. Acircle: 0x24B6,
  20675. Acircumflex: 0x00C2,
  20676. Acircumflexacute: 0x1EA4,
  20677. Acircumflexdotbelow: 0x1EAC,
  20678. Acircumflexgrave: 0x1EA6,
  20679. Acircumflexhookabove: 0x1EA8,
  20680. Acircumflexsmall: 0xF7E2,
  20681. Acircumflextilde: 0x1EAA,
  20682. Acute: 0xF6C9,
  20683. Acutesmall: 0xF7B4,
  20684. Acyrillic: 0x0410,
  20685. Adblgrave: 0x0200,
  20686. Adieresis: 0x00C4,
  20687. Adieresiscyrillic: 0x04D2,
  20688. Adieresismacron: 0x01DE,
  20689. Adieresissmall: 0xF7E4,
  20690. Adotbelow: 0x1EA0,
  20691. Adotmacron: 0x01E0,
  20692. Agrave: 0x00C0,
  20693. Agravesmall: 0xF7E0,
  20694. Ahookabove: 0x1EA2,
  20695. Aiecyrillic: 0x04D4,
  20696. Ainvertedbreve: 0x0202,
  20697. Alpha: 0x0391,
  20698. Alphatonos: 0x0386,
  20699. Amacron: 0x0100,
  20700. Amonospace: 0xFF21,
  20701. Aogonek: 0x0104,
  20702. Aring: 0x00C5,
  20703. Aringacute: 0x01FA,
  20704. Aringbelow: 0x1E00,
  20705. Aringsmall: 0xF7E5,
  20706. Asmall: 0xF761,
  20707. Atilde: 0x00C3,
  20708. Atildesmall: 0xF7E3,
  20709. Aybarmenian: 0x0531,
  20710. B: 0x0042,
  20711. Bcircle: 0x24B7,
  20712. Bdotaccent: 0x1E02,
  20713. Bdotbelow: 0x1E04,
  20714. Becyrillic: 0x0411,
  20715. Benarmenian: 0x0532,
  20716. Beta: 0x0392,
  20717. Bhook: 0x0181,
  20718. Blinebelow: 0x1E06,
  20719. Bmonospace: 0xFF22,
  20720. Brevesmall: 0xF6F4,
  20721. Bsmall: 0xF762,
  20722. Btopbar: 0x0182,
  20723. C: 0x0043,
  20724. Caarmenian: 0x053E,
  20725. Cacute: 0x0106,
  20726. Caron: 0xF6CA,
  20727. Caronsmall: 0xF6F5,
  20728. Ccaron: 0x010C,
  20729. Ccedilla: 0x00C7,
  20730. Ccedillaacute: 0x1E08,
  20731. Ccedillasmall: 0xF7E7,
  20732. Ccircle: 0x24B8,
  20733. Ccircumflex: 0x0108,
  20734. Cdot: 0x010A,
  20735. Cdotaccent: 0x010A,
  20736. Cedillasmall: 0xF7B8,
  20737. Chaarmenian: 0x0549,
  20738. Cheabkhasiancyrillic: 0x04BC,
  20739. Checyrillic: 0x0427,
  20740. Chedescenderabkhasiancyrillic: 0x04BE,
  20741. Chedescendercyrillic: 0x04B6,
  20742. Chedieresiscyrillic: 0x04F4,
  20743. Cheharmenian: 0x0543,
  20744. Chekhakassiancyrillic: 0x04CB,
  20745. Cheverticalstrokecyrillic: 0x04B8,
  20746. Chi: 0x03A7,
  20747. Chook: 0x0187,
  20748. Circumflexsmall: 0xF6F6,
  20749. Cmonospace: 0xFF23,
  20750. Coarmenian: 0x0551,
  20751. Csmall: 0xF763,
  20752. D: 0x0044,
  20753. DZ: 0x01F1,
  20754. DZcaron: 0x01C4,
  20755. Daarmenian: 0x0534,
  20756. Dafrican: 0x0189,
  20757. Dcaron: 0x010E,
  20758. Dcedilla: 0x1E10,
  20759. Dcircle: 0x24B9,
  20760. Dcircumflexbelow: 0x1E12,
  20761. Dcroat: 0x0110,
  20762. Ddotaccent: 0x1E0A,
  20763. Ddotbelow: 0x1E0C,
  20764. Decyrillic: 0x0414,
  20765. Deicoptic: 0x03EE,
  20766. Delta: 0x2206,
  20767. Deltagreek: 0x0394,
  20768. Dhook: 0x018A,
  20769. Dieresis: 0xF6CB,
  20770. DieresisAcute: 0xF6CC,
  20771. DieresisGrave: 0xF6CD,
  20772. Dieresissmall: 0xF7A8,
  20773. Digammagreek: 0x03DC,
  20774. Djecyrillic: 0x0402,
  20775. Dlinebelow: 0x1E0E,
  20776. Dmonospace: 0xFF24,
  20777. Dotaccentsmall: 0xF6F7,
  20778. Dslash: 0x0110,
  20779. Dsmall: 0xF764,
  20780. Dtopbar: 0x018B,
  20781. Dz: 0x01F2,
  20782. Dzcaron: 0x01C5,
  20783. Dzeabkhasiancyrillic: 0x04E0,
  20784. Dzecyrillic: 0x0405,
  20785. Dzhecyrillic: 0x040F,
  20786. E: 0x0045,
  20787. Eacute: 0x00C9,
  20788. Eacutesmall: 0xF7E9,
  20789. Ebreve: 0x0114,
  20790. Ecaron: 0x011A,
  20791. Ecedillabreve: 0x1E1C,
  20792. Echarmenian: 0x0535,
  20793. Ecircle: 0x24BA,
  20794. Ecircumflex: 0x00CA,
  20795. Ecircumflexacute: 0x1EBE,
  20796. Ecircumflexbelow: 0x1E18,
  20797. Ecircumflexdotbelow: 0x1EC6,
  20798. Ecircumflexgrave: 0x1EC0,
  20799. Ecircumflexhookabove: 0x1EC2,
  20800. Ecircumflexsmall: 0xF7EA,
  20801. Ecircumflextilde: 0x1EC4,
  20802. Ecyrillic: 0x0404,
  20803. Edblgrave: 0x0204,
  20804. Edieresis: 0x00CB,
  20805. Edieresissmall: 0xF7EB,
  20806. Edot: 0x0116,
  20807. Edotaccent: 0x0116,
  20808. Edotbelow: 0x1EB8,
  20809. Efcyrillic: 0x0424,
  20810. Egrave: 0x00C8,
  20811. Egravesmall: 0xF7E8,
  20812. Eharmenian: 0x0537,
  20813. Ehookabove: 0x1EBA,
  20814. Eightroman: 0x2167,
  20815. Einvertedbreve: 0x0206,
  20816. Eiotifiedcyrillic: 0x0464,
  20817. Elcyrillic: 0x041B,
  20818. Elevenroman: 0x216A,
  20819. Emacron: 0x0112,
  20820. Emacronacute: 0x1E16,
  20821. Emacrongrave: 0x1E14,
  20822. Emcyrillic: 0x041C,
  20823. Emonospace: 0xFF25,
  20824. Encyrillic: 0x041D,
  20825. Endescendercyrillic: 0x04A2,
  20826. Eng: 0x014A,
  20827. Enghecyrillic: 0x04A4,
  20828. Enhookcyrillic: 0x04C7,
  20829. Eogonek: 0x0118,
  20830. Eopen: 0x0190,
  20831. Epsilon: 0x0395,
  20832. Epsilontonos: 0x0388,
  20833. Ercyrillic: 0x0420,
  20834. Ereversed: 0x018E,
  20835. Ereversedcyrillic: 0x042D,
  20836. Escyrillic: 0x0421,
  20837. Esdescendercyrillic: 0x04AA,
  20838. Esh: 0x01A9,
  20839. Esmall: 0xF765,
  20840. Eta: 0x0397,
  20841. Etarmenian: 0x0538,
  20842. Etatonos: 0x0389,
  20843. Eth: 0x00D0,
  20844. Ethsmall: 0xF7F0,
  20845. Etilde: 0x1EBC,
  20846. Etildebelow: 0x1E1A,
  20847. Euro: 0x20AC,
  20848. Ezh: 0x01B7,
  20849. Ezhcaron: 0x01EE,
  20850. Ezhreversed: 0x01B8,
  20851. F: 0x0046,
  20852. Fcircle: 0x24BB,
  20853. Fdotaccent: 0x1E1E,
  20854. Feharmenian: 0x0556,
  20855. Feicoptic: 0x03E4,
  20856. Fhook: 0x0191,
  20857. Fitacyrillic: 0x0472,
  20858. Fiveroman: 0x2164,
  20859. Fmonospace: 0xFF26,
  20860. Fourroman: 0x2163,
  20861. Fsmall: 0xF766,
  20862. G: 0x0047,
  20863. GBsquare: 0x3387,
  20864. Gacute: 0x01F4,
  20865. Gamma: 0x0393,
  20866. Gammaafrican: 0x0194,
  20867. Gangiacoptic: 0x03EA,
  20868. Gbreve: 0x011E,
  20869. Gcaron: 0x01E6,
  20870. Gcedilla: 0x0122,
  20871. Gcircle: 0x24BC,
  20872. Gcircumflex: 0x011C,
  20873. Gcommaaccent: 0x0122,
  20874. Gdot: 0x0120,
  20875. Gdotaccent: 0x0120,
  20876. Gecyrillic: 0x0413,
  20877. Ghadarmenian: 0x0542,
  20878. Ghemiddlehookcyrillic: 0x0494,
  20879. Ghestrokecyrillic: 0x0492,
  20880. Gheupturncyrillic: 0x0490,
  20881. Ghook: 0x0193,
  20882. Gimarmenian: 0x0533,
  20883. Gjecyrillic: 0x0403,
  20884. Gmacron: 0x1E20,
  20885. Gmonospace: 0xFF27,
  20886. Grave: 0xF6CE,
  20887. Gravesmall: 0xF760,
  20888. Gsmall: 0xF767,
  20889. Gsmallhook: 0x029B,
  20890. Gstroke: 0x01E4,
  20891. H: 0x0048,
  20892. H18533: 0x25CF,
  20893. H18543: 0x25AA,
  20894. H18551: 0x25AB,
  20895. H22073: 0x25A1,
  20896. HPsquare: 0x33CB,
  20897. Haabkhasiancyrillic: 0x04A8,
  20898. Hadescendercyrillic: 0x04B2,
  20899. Hardsigncyrillic: 0x042A,
  20900. Hbar: 0x0126,
  20901. Hbrevebelow: 0x1E2A,
  20902. Hcedilla: 0x1E28,
  20903. Hcircle: 0x24BD,
  20904. Hcircumflex: 0x0124,
  20905. Hdieresis: 0x1E26,
  20906. Hdotaccent: 0x1E22,
  20907. Hdotbelow: 0x1E24,
  20908. Hmonospace: 0xFF28,
  20909. Hoarmenian: 0x0540,
  20910. Horicoptic: 0x03E8,
  20911. Hsmall: 0xF768,
  20912. Hungarumlaut: 0xF6CF,
  20913. Hungarumlautsmall: 0xF6F8,
  20914. Hzsquare: 0x3390,
  20915. I: 0x0049,
  20916. IAcyrillic: 0x042F,
  20917. IJ: 0x0132,
  20918. IUcyrillic: 0x042E,
  20919. Iacute: 0x00CD,
  20920. Iacutesmall: 0xF7ED,
  20921. Ibreve: 0x012C,
  20922. Icaron: 0x01CF,
  20923. Icircle: 0x24BE,
  20924. Icircumflex: 0x00CE,
  20925. Icircumflexsmall: 0xF7EE,
  20926. Icyrillic: 0x0406,
  20927. Idblgrave: 0x0208,
  20928. Idieresis: 0x00CF,
  20929. Idieresisacute: 0x1E2E,
  20930. Idieresiscyrillic: 0x04E4,
  20931. Idieresissmall: 0xF7EF,
  20932. Idot: 0x0130,
  20933. Idotaccent: 0x0130,
  20934. Idotbelow: 0x1ECA,
  20935. Iebrevecyrillic: 0x04D6,
  20936. Iecyrillic: 0x0415,
  20937. Ifraktur: 0x2111,
  20938. Igrave: 0x00CC,
  20939. Igravesmall: 0xF7EC,
  20940. Ihookabove: 0x1EC8,
  20941. Iicyrillic: 0x0418,
  20942. Iinvertedbreve: 0x020A,
  20943. Iishortcyrillic: 0x0419,
  20944. Imacron: 0x012A,
  20945. Imacroncyrillic: 0x04E2,
  20946. Imonospace: 0xFF29,
  20947. Iniarmenian: 0x053B,
  20948. Iocyrillic: 0x0401,
  20949. Iogonek: 0x012E,
  20950. Iota: 0x0399,
  20951. Iotaafrican: 0x0196,
  20952. Iotadieresis: 0x03AA,
  20953. Iotatonos: 0x038A,
  20954. Ismall: 0xF769,
  20955. Istroke: 0x0197,
  20956. Itilde: 0x0128,
  20957. Itildebelow: 0x1E2C,
  20958. Izhitsacyrillic: 0x0474,
  20959. Izhitsadblgravecyrillic: 0x0476,
  20960. J: 0x004A,
  20961. Jaarmenian: 0x0541,
  20962. Jcircle: 0x24BF,
  20963. Jcircumflex: 0x0134,
  20964. Jecyrillic: 0x0408,
  20965. Jheharmenian: 0x054B,
  20966. Jmonospace: 0xFF2A,
  20967. Jsmall: 0xF76A,
  20968. K: 0x004B,
  20969. KBsquare: 0x3385,
  20970. KKsquare: 0x33CD,
  20971. Kabashkircyrillic: 0x04A0,
  20972. Kacute: 0x1E30,
  20973. Kacyrillic: 0x041A,
  20974. Kadescendercyrillic: 0x049A,
  20975. Kahookcyrillic: 0x04C3,
  20976. Kappa: 0x039A,
  20977. Kastrokecyrillic: 0x049E,
  20978. Kaverticalstrokecyrillic: 0x049C,
  20979. Kcaron: 0x01E8,
  20980. Kcedilla: 0x0136,
  20981. Kcircle: 0x24C0,
  20982. Kcommaaccent: 0x0136,
  20983. Kdotbelow: 0x1E32,
  20984. Keharmenian: 0x0554,
  20985. Kenarmenian: 0x053F,
  20986. Khacyrillic: 0x0425,
  20987. Kheicoptic: 0x03E6,
  20988. Khook: 0x0198,
  20989. Kjecyrillic: 0x040C,
  20990. Klinebelow: 0x1E34,
  20991. Kmonospace: 0xFF2B,
  20992. Koppacyrillic: 0x0480,
  20993. Koppagreek: 0x03DE,
  20994. Ksicyrillic: 0x046E,
  20995. Ksmall: 0xF76B,
  20996. L: 0x004C,
  20997. LJ: 0x01C7,
  20998. LL: 0xF6BF,
  20999. Lacute: 0x0139,
  21000. Lambda: 0x039B,
  21001. Lcaron: 0x013D,
  21002. Lcedilla: 0x013B,
  21003. Lcircle: 0x24C1,
  21004. Lcircumflexbelow: 0x1E3C,
  21005. Lcommaaccent: 0x013B,
  21006. Ldot: 0x013F,
  21007. Ldotaccent: 0x013F,
  21008. Ldotbelow: 0x1E36,
  21009. Ldotbelowmacron: 0x1E38,
  21010. Liwnarmenian: 0x053C,
  21011. Lj: 0x01C8,
  21012. Ljecyrillic: 0x0409,
  21013. Llinebelow: 0x1E3A,
  21014. Lmonospace: 0xFF2C,
  21015. Lslash: 0x0141,
  21016. Lslashsmall: 0xF6F9,
  21017. Lsmall: 0xF76C,
  21018. M: 0x004D,
  21019. MBsquare: 0x3386,
  21020. Macron: 0xF6D0,
  21021. Macronsmall: 0xF7AF,
  21022. Macute: 0x1E3E,
  21023. Mcircle: 0x24C2,
  21024. Mdotaccent: 0x1E40,
  21025. Mdotbelow: 0x1E42,
  21026. Menarmenian: 0x0544,
  21027. Mmonospace: 0xFF2D,
  21028. Msmall: 0xF76D,
  21029. Mturned: 0x019C,
  21030. Mu: 0x039C,
  21031. N: 0x004E,
  21032. NJ: 0x01CA,
  21033. Nacute: 0x0143,
  21034. Ncaron: 0x0147,
  21035. Ncedilla: 0x0145,
  21036. Ncircle: 0x24C3,
  21037. Ncircumflexbelow: 0x1E4A,
  21038. Ncommaaccent: 0x0145,
  21039. Ndotaccent: 0x1E44,
  21040. Ndotbelow: 0x1E46,
  21041. Nhookleft: 0x019D,
  21042. Nineroman: 0x2168,
  21043. Nj: 0x01CB,
  21044. Njecyrillic: 0x040A,
  21045. Nlinebelow: 0x1E48,
  21046. Nmonospace: 0xFF2E,
  21047. Nowarmenian: 0x0546,
  21048. Nsmall: 0xF76E,
  21049. Ntilde: 0x00D1,
  21050. Ntildesmall: 0xF7F1,
  21051. Nu: 0x039D,
  21052. O: 0x004F,
  21053. OE: 0x0152,
  21054. OEsmall: 0xF6FA,
  21055. Oacute: 0x00D3,
  21056. Oacutesmall: 0xF7F3,
  21057. Obarredcyrillic: 0x04E8,
  21058. Obarreddieresiscyrillic: 0x04EA,
  21059. Obreve: 0x014E,
  21060. Ocaron: 0x01D1,
  21061. Ocenteredtilde: 0x019F,
  21062. Ocircle: 0x24C4,
  21063. Ocircumflex: 0x00D4,
  21064. Ocircumflexacute: 0x1ED0,
  21065. Ocircumflexdotbelow: 0x1ED8,
  21066. Ocircumflexgrave: 0x1ED2,
  21067. Ocircumflexhookabove: 0x1ED4,
  21068. Ocircumflexsmall: 0xF7F4,
  21069. Ocircumflextilde: 0x1ED6,
  21070. Ocyrillic: 0x041E,
  21071. Odblacute: 0x0150,
  21072. Odblgrave: 0x020C,
  21073. Odieresis: 0x00D6,
  21074. Odieresiscyrillic: 0x04E6,
  21075. Odieresissmall: 0xF7F6,
  21076. Odotbelow: 0x1ECC,
  21077. Ogoneksmall: 0xF6FB,
  21078. Ograve: 0x00D2,
  21079. Ogravesmall: 0xF7F2,
  21080. Oharmenian: 0x0555,
  21081. Ohm: 0x2126,
  21082. Ohookabove: 0x1ECE,
  21083. Ohorn: 0x01A0,
  21084. Ohornacute: 0x1EDA,
  21085. Ohorndotbelow: 0x1EE2,
  21086. Ohorngrave: 0x1EDC,
  21087. Ohornhookabove: 0x1EDE,
  21088. Ohorntilde: 0x1EE0,
  21089. Ohungarumlaut: 0x0150,
  21090. Oi: 0x01A2,
  21091. Oinvertedbreve: 0x020E,
  21092. Omacron: 0x014C,
  21093. Omacronacute: 0x1E52,
  21094. Omacrongrave: 0x1E50,
  21095. Omega: 0x2126,
  21096. Omegacyrillic: 0x0460,
  21097. Omegagreek: 0x03A9,
  21098. Omegaroundcyrillic: 0x047A,
  21099. Omegatitlocyrillic: 0x047C,
  21100. Omegatonos: 0x038F,
  21101. Omicron: 0x039F,
  21102. Omicrontonos: 0x038C,
  21103. Omonospace: 0xFF2F,
  21104. Oneroman: 0x2160,
  21105. Oogonek: 0x01EA,
  21106. Oogonekmacron: 0x01EC,
  21107. Oopen: 0x0186,
  21108. Oslash: 0x00D8,
  21109. Oslashacute: 0x01FE,
  21110. Oslashsmall: 0xF7F8,
  21111. Osmall: 0xF76F,
  21112. Ostrokeacute: 0x01FE,
  21113. Otcyrillic: 0x047E,
  21114. Otilde: 0x00D5,
  21115. Otildeacute: 0x1E4C,
  21116. Otildedieresis: 0x1E4E,
  21117. Otildesmall: 0xF7F5,
  21118. P: 0x0050,
  21119. Pacute: 0x1E54,
  21120. Pcircle: 0x24C5,
  21121. Pdotaccent: 0x1E56,
  21122. Pecyrillic: 0x041F,
  21123. Peharmenian: 0x054A,
  21124. Pemiddlehookcyrillic: 0x04A6,
  21125. Phi: 0x03A6,
  21126. Phook: 0x01A4,
  21127. Pi: 0x03A0,
  21128. Piwrarmenian: 0x0553,
  21129. Pmonospace: 0xFF30,
  21130. Psi: 0x03A8,
  21131. Psicyrillic: 0x0470,
  21132. Psmall: 0xF770,
  21133. Q: 0x0051,
  21134. Qcircle: 0x24C6,
  21135. Qmonospace: 0xFF31,
  21136. Qsmall: 0xF771,
  21137. R: 0x0052,
  21138. Raarmenian: 0x054C,
  21139. Racute: 0x0154,
  21140. Rcaron: 0x0158,
  21141. Rcedilla: 0x0156,
  21142. Rcircle: 0x24C7,
  21143. Rcommaaccent: 0x0156,
  21144. Rdblgrave: 0x0210,
  21145. Rdotaccent: 0x1E58,
  21146. Rdotbelow: 0x1E5A,
  21147. Rdotbelowmacron: 0x1E5C,
  21148. Reharmenian: 0x0550,
  21149. Rfraktur: 0x211C,
  21150. Rho: 0x03A1,
  21151. Ringsmall: 0xF6FC,
  21152. Rinvertedbreve: 0x0212,
  21153. Rlinebelow: 0x1E5E,
  21154. Rmonospace: 0xFF32,
  21155. Rsmall: 0xF772,
  21156. Rsmallinverted: 0x0281,
  21157. Rsmallinvertedsuperior: 0x02B6,
  21158. S: 0x0053,
  21159. SF010000: 0x250C,
  21160. SF020000: 0x2514,
  21161. SF030000: 0x2510,
  21162. SF040000: 0x2518,
  21163. SF050000: 0x253C,
  21164. SF060000: 0x252C,
  21165. SF070000: 0x2534,
  21166. SF080000: 0x251C,
  21167. SF090000: 0x2524,
  21168. SF100000: 0x2500,
  21169. SF110000: 0x2502,
  21170. SF190000: 0x2561,
  21171. SF200000: 0x2562,
  21172. SF210000: 0x2556,
  21173. SF220000: 0x2555,
  21174. SF230000: 0x2563,
  21175. SF240000: 0x2551,
  21176. SF250000: 0x2557,
  21177. SF260000: 0x255D,
  21178. SF270000: 0x255C,
  21179. SF280000: 0x255B,
  21180. SF360000: 0x255E,
  21181. SF370000: 0x255F,
  21182. SF380000: 0x255A,
  21183. SF390000: 0x2554,
  21184. SF400000: 0x2569,
  21185. SF410000: 0x2566,
  21186. SF420000: 0x2560,
  21187. SF430000: 0x2550,
  21188. SF440000: 0x256C,
  21189. SF450000: 0x2567,
  21190. SF460000: 0x2568,
  21191. SF470000: 0x2564,
  21192. SF480000: 0x2565,
  21193. SF490000: 0x2559,
  21194. SF500000: 0x2558,
  21195. SF510000: 0x2552,
  21196. SF520000: 0x2553,
  21197. SF530000: 0x256B,
  21198. SF540000: 0x256A,
  21199. Sacute: 0x015A,
  21200. Sacutedotaccent: 0x1E64,
  21201. Sampigreek: 0x03E0,
  21202. Scaron: 0x0160,
  21203. Scarondotaccent: 0x1E66,
  21204. Scaronsmall: 0xF6FD,
  21205. Scedilla: 0x015E,
  21206. Schwa: 0x018F,
  21207. Schwacyrillic: 0x04D8,
  21208. Schwadieresiscyrillic: 0x04DA,
  21209. Scircle: 0x24C8,
  21210. Scircumflex: 0x015C,
  21211. Scommaaccent: 0x0218,
  21212. Sdotaccent: 0x1E60,
  21213. Sdotbelow: 0x1E62,
  21214. Sdotbelowdotaccent: 0x1E68,
  21215. Seharmenian: 0x054D,
  21216. Sevenroman: 0x2166,
  21217. Shaarmenian: 0x0547,
  21218. Shacyrillic: 0x0428,
  21219. Shchacyrillic: 0x0429,
  21220. Sheicoptic: 0x03E2,
  21221. Shhacyrillic: 0x04BA,
  21222. Shimacoptic: 0x03EC,
  21223. Sigma: 0x03A3,
  21224. Sixroman: 0x2165,
  21225. Smonospace: 0xFF33,
  21226. Softsigncyrillic: 0x042C,
  21227. Ssmall: 0xF773,
  21228. Stigmagreek: 0x03DA,
  21229. T: 0x0054,
  21230. Tau: 0x03A4,
  21231. Tbar: 0x0166,
  21232. Tcaron: 0x0164,
  21233. Tcedilla: 0x0162,
  21234. Tcircle: 0x24C9,
  21235. Tcircumflexbelow: 0x1E70,
  21236. Tcommaaccent: 0x0162,
  21237. Tdotaccent: 0x1E6A,
  21238. Tdotbelow: 0x1E6C,
  21239. Tecyrillic: 0x0422,
  21240. Tedescendercyrillic: 0x04AC,
  21241. Tenroman: 0x2169,
  21242. Tetsecyrillic: 0x04B4,
  21243. Theta: 0x0398,
  21244. Thook: 0x01AC,
  21245. Thorn: 0x00DE,
  21246. Thornsmall: 0xF7FE,
  21247. Threeroman: 0x2162,
  21248. Tildesmall: 0xF6FE,
  21249. Tiwnarmenian: 0x054F,
  21250. Tlinebelow: 0x1E6E,
  21251. Tmonospace: 0xFF34,
  21252. Toarmenian: 0x0539,
  21253. Tonefive: 0x01BC,
  21254. Tonesix: 0x0184,
  21255. Tonetwo: 0x01A7,
  21256. Tretroflexhook: 0x01AE,
  21257. Tsecyrillic: 0x0426,
  21258. Tshecyrillic: 0x040B,
  21259. Tsmall: 0xF774,
  21260. Twelveroman: 0x216B,
  21261. Tworoman: 0x2161,
  21262. U: 0x0055,
  21263. Uacute: 0x00DA,
  21264. Uacutesmall: 0xF7FA,
  21265. Ubreve: 0x016C,
  21266. Ucaron: 0x01D3,
  21267. Ucircle: 0x24CA,
  21268. Ucircumflex: 0x00DB,
  21269. Ucircumflexbelow: 0x1E76,
  21270. Ucircumflexsmall: 0xF7FB,
  21271. Ucyrillic: 0x0423,
  21272. Udblacute: 0x0170,
  21273. Udblgrave: 0x0214,
  21274. Udieresis: 0x00DC,
  21275. Udieresisacute: 0x01D7,
  21276. Udieresisbelow: 0x1E72,
  21277. Udieresiscaron: 0x01D9,
  21278. Udieresiscyrillic: 0x04F0,
  21279. Udieresisgrave: 0x01DB,
  21280. Udieresismacron: 0x01D5,
  21281. Udieresissmall: 0xF7FC,
  21282. Udotbelow: 0x1EE4,
  21283. Ugrave: 0x00D9,
  21284. Ugravesmall: 0xF7F9,
  21285. Uhookabove: 0x1EE6,
  21286. Uhorn: 0x01AF,
  21287. Uhornacute: 0x1EE8,
  21288. Uhorndotbelow: 0x1EF0,
  21289. Uhorngrave: 0x1EEA,
  21290. Uhornhookabove: 0x1EEC,
  21291. Uhorntilde: 0x1EEE,
  21292. Uhungarumlaut: 0x0170,
  21293. Uhungarumlautcyrillic: 0x04F2,
  21294. Uinvertedbreve: 0x0216,
  21295. Ukcyrillic: 0x0478,
  21296. Umacron: 0x016A,
  21297. Umacroncyrillic: 0x04EE,
  21298. Umacrondieresis: 0x1E7A,
  21299. Umonospace: 0xFF35,
  21300. Uogonek: 0x0172,
  21301. Upsilon: 0x03A5,
  21302. Upsilon1: 0x03D2,
  21303. Upsilonacutehooksymbolgreek: 0x03D3,
  21304. Upsilonafrican: 0x01B1,
  21305. Upsilondieresis: 0x03AB,
  21306. Upsilondieresishooksymbolgreek: 0x03D4,
  21307. Upsilonhooksymbol: 0x03D2,
  21308. Upsilontonos: 0x038E,
  21309. Uring: 0x016E,
  21310. Ushortcyrillic: 0x040E,
  21311. Usmall: 0xF775,
  21312. Ustraightcyrillic: 0x04AE,
  21313. Ustraightstrokecyrillic: 0x04B0,
  21314. Utilde: 0x0168,
  21315. Utildeacute: 0x1E78,
  21316. Utildebelow: 0x1E74,
  21317. V: 0x0056,
  21318. Vcircle: 0x24CB,
  21319. Vdotbelow: 0x1E7E,
  21320. Vecyrillic: 0x0412,
  21321. Vewarmenian: 0x054E,
  21322. Vhook: 0x01B2,
  21323. Vmonospace: 0xFF36,
  21324. Voarmenian: 0x0548,
  21325. Vsmall: 0xF776,
  21326. Vtilde: 0x1E7C,
  21327. W: 0x0057,
  21328. Wacute: 0x1E82,
  21329. Wcircle: 0x24CC,
  21330. Wcircumflex: 0x0174,
  21331. Wdieresis: 0x1E84,
  21332. Wdotaccent: 0x1E86,
  21333. Wdotbelow: 0x1E88,
  21334. Wgrave: 0x1E80,
  21335. Wmonospace: 0xFF37,
  21336. Wsmall: 0xF777,
  21337. X: 0x0058,
  21338. Xcircle: 0x24CD,
  21339. Xdieresis: 0x1E8C,
  21340. Xdotaccent: 0x1E8A,
  21341. Xeharmenian: 0x053D,
  21342. Xi: 0x039E,
  21343. Xmonospace: 0xFF38,
  21344. Xsmall: 0xF778,
  21345. Y: 0x0059,
  21346. Yacute: 0x00DD,
  21347. Yacutesmall: 0xF7FD,
  21348. Yatcyrillic: 0x0462,
  21349. Ycircle: 0x24CE,
  21350. Ycircumflex: 0x0176,
  21351. Ydieresis: 0x0178,
  21352. Ydieresissmall: 0xF7FF,
  21353. Ydotaccent: 0x1E8E,
  21354. Ydotbelow: 0x1EF4,
  21355. Yericyrillic: 0x042B,
  21356. Yerudieresiscyrillic: 0x04F8,
  21357. Ygrave: 0x1EF2,
  21358. Yhook: 0x01B3,
  21359. Yhookabove: 0x1EF6,
  21360. Yiarmenian: 0x0545,
  21361. Yicyrillic: 0x0407,
  21362. Yiwnarmenian: 0x0552,
  21363. Ymonospace: 0xFF39,
  21364. Ysmall: 0xF779,
  21365. Ytilde: 0x1EF8,
  21366. Yusbigcyrillic: 0x046A,
  21367. Yusbigiotifiedcyrillic: 0x046C,
  21368. Yuslittlecyrillic: 0x0466,
  21369. Yuslittleiotifiedcyrillic: 0x0468,
  21370. Z: 0x005A,
  21371. Zaarmenian: 0x0536,
  21372. Zacute: 0x0179,
  21373. Zcaron: 0x017D,
  21374. Zcaronsmall: 0xF6FF,
  21375. Zcircle: 0x24CF,
  21376. Zcircumflex: 0x1E90,
  21377. Zdot: 0x017B,
  21378. Zdotaccent: 0x017B,
  21379. Zdotbelow: 0x1E92,
  21380. Zecyrillic: 0x0417,
  21381. Zedescendercyrillic: 0x0498,
  21382. Zedieresiscyrillic: 0x04DE,
  21383. Zeta: 0x0396,
  21384. Zhearmenian: 0x053A,
  21385. Zhebrevecyrillic: 0x04C1,
  21386. Zhecyrillic: 0x0416,
  21387. Zhedescendercyrillic: 0x0496,
  21388. Zhedieresiscyrillic: 0x04DC,
  21389. Zlinebelow: 0x1E94,
  21390. Zmonospace: 0xFF3A,
  21391. Zsmall: 0xF77A,
  21392. Zstroke: 0x01B5,
  21393. a: 0x0061,
  21394. aabengali: 0x0986,
  21395. aacute: 0x00E1,
  21396. aadeva: 0x0906,
  21397. aagujarati: 0x0A86,
  21398. aagurmukhi: 0x0A06,
  21399. aamatragurmukhi: 0x0A3E,
  21400. aarusquare: 0x3303,
  21401. aavowelsignbengali: 0x09BE,
  21402. aavowelsigndeva: 0x093E,
  21403. aavowelsigngujarati: 0x0ABE,
  21404. abbreviationmarkarmenian: 0x055F,
  21405. abbreviationsigndeva: 0x0970,
  21406. abengali: 0x0985,
  21407. abopomofo: 0x311A,
  21408. abreve: 0x0103,
  21409. abreveacute: 0x1EAF,
  21410. abrevecyrillic: 0x04D1,
  21411. abrevedotbelow: 0x1EB7,
  21412. abrevegrave: 0x1EB1,
  21413. abrevehookabove: 0x1EB3,
  21414. abrevetilde: 0x1EB5,
  21415. acaron: 0x01CE,
  21416. acircle: 0x24D0,
  21417. acircumflex: 0x00E2,
  21418. acircumflexacute: 0x1EA5,
  21419. acircumflexdotbelow: 0x1EAD,
  21420. acircumflexgrave: 0x1EA7,
  21421. acircumflexhookabove: 0x1EA9,
  21422. acircumflextilde: 0x1EAB,
  21423. acute: 0x00B4,
  21424. acutebelowcmb: 0x0317,
  21425. acutecmb: 0x0301,
  21426. acutecomb: 0x0301,
  21427. acutedeva: 0x0954,
  21428. acutelowmod: 0x02CF,
  21429. acutetonecmb: 0x0341,
  21430. acyrillic: 0x0430,
  21431. adblgrave: 0x0201,
  21432. addakgurmukhi: 0x0A71,
  21433. adeva: 0x0905,
  21434. adieresis: 0x00E4,
  21435. adieresiscyrillic: 0x04D3,
  21436. adieresismacron: 0x01DF,
  21437. adotbelow: 0x1EA1,
  21438. adotmacron: 0x01E1,
  21439. ae: 0x00E6,
  21440. aeacute: 0x01FD,
  21441. aekorean: 0x3150,
  21442. aemacron: 0x01E3,
  21443. afii00208: 0x2015,
  21444. afii08941: 0x20A4,
  21445. afii10017: 0x0410,
  21446. afii10018: 0x0411,
  21447. afii10019: 0x0412,
  21448. afii10020: 0x0413,
  21449. afii10021: 0x0414,
  21450. afii10022: 0x0415,
  21451. afii10023: 0x0401,
  21452. afii10024: 0x0416,
  21453. afii10025: 0x0417,
  21454. afii10026: 0x0418,
  21455. afii10027: 0x0419,
  21456. afii10028: 0x041A,
  21457. afii10029: 0x041B,
  21458. afii10030: 0x041C,
  21459. afii10031: 0x041D,
  21460. afii10032: 0x041E,
  21461. afii10033: 0x041F,
  21462. afii10034: 0x0420,
  21463. afii10035: 0x0421,
  21464. afii10036: 0x0422,
  21465. afii10037: 0x0423,
  21466. afii10038: 0x0424,
  21467. afii10039: 0x0425,
  21468. afii10040: 0x0426,
  21469. afii10041: 0x0427,
  21470. afii10042: 0x0428,
  21471. afii10043: 0x0429,
  21472. afii10044: 0x042A,
  21473. afii10045: 0x042B,
  21474. afii10046: 0x042C,
  21475. afii10047: 0x042D,
  21476. afii10048: 0x042E,
  21477. afii10049: 0x042F,
  21478. afii10050: 0x0490,
  21479. afii10051: 0x0402,
  21480. afii10052: 0x0403,
  21481. afii10053: 0x0404,
  21482. afii10054: 0x0405,
  21483. afii10055: 0x0406,
  21484. afii10056: 0x0407,
  21485. afii10057: 0x0408,
  21486. afii10058: 0x0409,
  21487. afii10059: 0x040A,
  21488. afii10060: 0x040B,
  21489. afii10061: 0x040C,
  21490. afii10062: 0x040E,
  21491. afii10063: 0xF6C4,
  21492. afii10064: 0xF6C5,
  21493. afii10065: 0x0430,
  21494. afii10066: 0x0431,
  21495. afii10067: 0x0432,
  21496. afii10068: 0x0433,
  21497. afii10069: 0x0434,
  21498. afii10070: 0x0435,
  21499. afii10071: 0x0451,
  21500. afii10072: 0x0436,
  21501. afii10073: 0x0437,
  21502. afii10074: 0x0438,
  21503. afii10075: 0x0439,
  21504. afii10076: 0x043A,
  21505. afii10077: 0x043B,
  21506. afii10078: 0x043C,
  21507. afii10079: 0x043D,
  21508. afii10080: 0x043E,
  21509. afii10081: 0x043F,
  21510. afii10082: 0x0440,
  21511. afii10083: 0x0441,
  21512. afii10084: 0x0442,
  21513. afii10085: 0x0443,
  21514. afii10086: 0x0444,
  21515. afii10087: 0x0445,
  21516. afii10088: 0x0446,
  21517. afii10089: 0x0447,
  21518. afii10090: 0x0448,
  21519. afii10091: 0x0449,
  21520. afii10092: 0x044A,
  21521. afii10093: 0x044B,
  21522. afii10094: 0x044C,
  21523. afii10095: 0x044D,
  21524. afii10096: 0x044E,
  21525. afii10097: 0x044F,
  21526. afii10098: 0x0491,
  21527. afii10099: 0x0452,
  21528. afii10100: 0x0453,
  21529. afii10101: 0x0454,
  21530. afii10102: 0x0455,
  21531. afii10103: 0x0456,
  21532. afii10104: 0x0457,
  21533. afii10105: 0x0458,
  21534. afii10106: 0x0459,
  21535. afii10107: 0x045A,
  21536. afii10108: 0x045B,
  21537. afii10109: 0x045C,
  21538. afii10110: 0x045E,
  21539. afii10145: 0x040F,
  21540. afii10146: 0x0462,
  21541. afii10147: 0x0472,
  21542. afii10148: 0x0474,
  21543. afii10192: 0xF6C6,
  21544. afii10193: 0x045F,
  21545. afii10194: 0x0463,
  21546. afii10195: 0x0473,
  21547. afii10196: 0x0475,
  21548. afii10831: 0xF6C7,
  21549. afii10832: 0xF6C8,
  21550. afii10846: 0x04D9,
  21551. afii299: 0x200E,
  21552. afii300: 0x200F,
  21553. afii301: 0x200D,
  21554. afii57381: 0x066A,
  21555. afii57388: 0x060C,
  21556. afii57392: 0x0660,
  21557. afii57393: 0x0661,
  21558. afii57394: 0x0662,
  21559. afii57395: 0x0663,
  21560. afii57396: 0x0664,
  21561. afii57397: 0x0665,
  21562. afii57398: 0x0666,
  21563. afii57399: 0x0667,
  21564. afii57400: 0x0668,
  21565. afii57401: 0x0669,
  21566. afii57403: 0x061B,
  21567. afii57407: 0x061F,
  21568. afii57409: 0x0621,
  21569. afii57410: 0x0622,
  21570. afii57411: 0x0623,
  21571. afii57412: 0x0624,
  21572. afii57413: 0x0625,
  21573. afii57414: 0x0626,
  21574. afii57415: 0x0627,
  21575. afii57416: 0x0628,
  21576. afii57417: 0x0629,
  21577. afii57418: 0x062A,
  21578. afii57419: 0x062B,
  21579. afii57420: 0x062C,
  21580. afii57421: 0x062D,
  21581. afii57422: 0x062E,
  21582. afii57423: 0x062F,
  21583. afii57424: 0x0630,
  21584. afii57425: 0x0631,
  21585. afii57426: 0x0632,
  21586. afii57427: 0x0633,
  21587. afii57428: 0x0634,
  21588. afii57429: 0x0635,
  21589. afii57430: 0x0636,
  21590. afii57431: 0x0637,
  21591. afii57432: 0x0638,
  21592. afii57433: 0x0639,
  21593. afii57434: 0x063A,
  21594. afii57440: 0x0640,
  21595. afii57441: 0x0641,
  21596. afii57442: 0x0642,
  21597. afii57443: 0x0643,
  21598. afii57444: 0x0644,
  21599. afii57445: 0x0645,
  21600. afii57446: 0x0646,
  21601. afii57448: 0x0648,
  21602. afii57449: 0x0649,
  21603. afii57450: 0x064A,
  21604. afii57451: 0x064B,
  21605. afii57452: 0x064C,
  21606. afii57453: 0x064D,
  21607. afii57454: 0x064E,
  21608. afii57455: 0x064F,
  21609. afii57456: 0x0650,
  21610. afii57457: 0x0651,
  21611. afii57458: 0x0652,
  21612. afii57470: 0x0647,
  21613. afii57505: 0x06A4,
  21614. afii57506: 0x067E,
  21615. afii57507: 0x0686,
  21616. afii57508: 0x0698,
  21617. afii57509: 0x06AF,
  21618. afii57511: 0x0679,
  21619. afii57512: 0x0688,
  21620. afii57513: 0x0691,
  21621. afii57514: 0x06BA,
  21622. afii57519: 0x06D2,
  21623. afii57534: 0x06D5,
  21624. afii57636: 0x20AA,
  21625. afii57645: 0x05BE,
  21626. afii57658: 0x05C3,
  21627. afii57664: 0x05D0,
  21628. afii57665: 0x05D1,
  21629. afii57666: 0x05D2,
  21630. afii57667: 0x05D3,
  21631. afii57668: 0x05D4,
  21632. afii57669: 0x05D5,
  21633. afii57670: 0x05D6,
  21634. afii57671: 0x05D7,
  21635. afii57672: 0x05D8,
  21636. afii57673: 0x05D9,
  21637. afii57674: 0x05DA,
  21638. afii57675: 0x05DB,
  21639. afii57676: 0x05DC,
  21640. afii57677: 0x05DD,
  21641. afii57678: 0x05DE,
  21642. afii57679: 0x05DF,
  21643. afii57680: 0x05E0,
  21644. afii57681: 0x05E1,
  21645. afii57682: 0x05E2,
  21646. afii57683: 0x05E3,
  21647. afii57684: 0x05E4,
  21648. afii57685: 0x05E5,
  21649. afii57686: 0x05E6,
  21650. afii57687: 0x05E7,
  21651. afii57688: 0x05E8,
  21652. afii57689: 0x05E9,
  21653. afii57690: 0x05EA,
  21654. afii57694: 0xFB2A,
  21655. afii57695: 0xFB2B,
  21656. afii57700: 0xFB4B,
  21657. afii57705: 0xFB1F,
  21658. afii57716: 0x05F0,
  21659. afii57717: 0x05F1,
  21660. afii57718: 0x05F2,
  21661. afii57723: 0xFB35,
  21662. afii57793: 0x05B4,
  21663. afii57794: 0x05B5,
  21664. afii57795: 0x05B6,
  21665. afii57796: 0x05BB,
  21666. afii57797: 0x05B8,
  21667. afii57798: 0x05B7,
  21668. afii57799: 0x05B0,
  21669. afii57800: 0x05B2,
  21670. afii57801: 0x05B1,
  21671. afii57802: 0x05B3,
  21672. afii57803: 0x05C2,
  21673. afii57804: 0x05C1,
  21674. afii57806: 0x05B9,
  21675. afii57807: 0x05BC,
  21676. afii57839: 0x05BD,
  21677. afii57841: 0x05BF,
  21678. afii57842: 0x05C0,
  21679. afii57929: 0x02BC,
  21680. afii61248: 0x2105,
  21681. afii61289: 0x2113,
  21682. afii61352: 0x2116,
  21683. afii61573: 0x202C,
  21684. afii61574: 0x202D,
  21685. afii61575: 0x202E,
  21686. afii61664: 0x200C,
  21687. afii63167: 0x066D,
  21688. afii64937: 0x02BD,
  21689. agrave: 0x00E0,
  21690. agujarati: 0x0A85,
  21691. agurmukhi: 0x0A05,
  21692. ahiragana: 0x3042,
  21693. ahookabove: 0x1EA3,
  21694. aibengali: 0x0990,
  21695. aibopomofo: 0x311E,
  21696. aideva: 0x0910,
  21697. aiecyrillic: 0x04D5,
  21698. aigujarati: 0x0A90,
  21699. aigurmukhi: 0x0A10,
  21700. aimatragurmukhi: 0x0A48,
  21701. ainarabic: 0x0639,
  21702. ainfinalarabic: 0xFECA,
  21703. aininitialarabic: 0xFECB,
  21704. ainmedialarabic: 0xFECC,
  21705. ainvertedbreve: 0x0203,
  21706. aivowelsignbengali: 0x09C8,
  21707. aivowelsigndeva: 0x0948,
  21708. aivowelsigngujarati: 0x0AC8,
  21709. akatakana: 0x30A2,
  21710. akatakanahalfwidth: 0xFF71,
  21711. akorean: 0x314F,
  21712. alef: 0x05D0,
  21713. alefarabic: 0x0627,
  21714. alefdageshhebrew: 0xFB30,
  21715. aleffinalarabic: 0xFE8E,
  21716. alefhamzaabovearabic: 0x0623,
  21717. alefhamzaabovefinalarabic: 0xFE84,
  21718. alefhamzabelowarabic: 0x0625,
  21719. alefhamzabelowfinalarabic: 0xFE88,
  21720. alefhebrew: 0x05D0,
  21721. aleflamedhebrew: 0xFB4F,
  21722. alefmaddaabovearabic: 0x0622,
  21723. alefmaddaabovefinalarabic: 0xFE82,
  21724. alefmaksuraarabic: 0x0649,
  21725. alefmaksurafinalarabic: 0xFEF0,
  21726. alefmaksurainitialarabic: 0xFEF3,
  21727. alefmaksuramedialarabic: 0xFEF4,
  21728. alefpatahhebrew: 0xFB2E,
  21729. alefqamatshebrew: 0xFB2F,
  21730. aleph: 0x2135,
  21731. allequal: 0x224C,
  21732. alpha: 0x03B1,
  21733. alphatonos: 0x03AC,
  21734. amacron: 0x0101,
  21735. amonospace: 0xFF41,
  21736. ampersand: 0x0026,
  21737. ampersandmonospace: 0xFF06,
  21738. ampersandsmall: 0xF726,
  21739. amsquare: 0x33C2,
  21740. anbopomofo: 0x3122,
  21741. angbopomofo: 0x3124,
  21742. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  21743. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  21744. angkhankhuthai: 0x0E5A,
  21745. angle: 0x2220,
  21746. anglebracketleft: 0x3008,
  21747. anglebracketleftvertical: 0xFE3F,
  21748. anglebracketright: 0x3009,
  21749. anglebracketrightvertical: 0xFE40,
  21750. angleleft: 0x2329,
  21751. angleright: 0x232A,
  21752. angstrom: 0x212B,
  21753. anoteleia: 0x0387,
  21754. anudattadeva: 0x0952,
  21755. anusvarabengali: 0x0982,
  21756. anusvaradeva: 0x0902,
  21757. anusvaragujarati: 0x0A82,
  21758. aogonek: 0x0105,
  21759. apaatosquare: 0x3300,
  21760. aparen: 0x249C,
  21761. apostrophearmenian: 0x055A,
  21762. apostrophemod: 0x02BC,
  21763. apple: 0xF8FF,
  21764. approaches: 0x2250,
  21765. approxequal: 0x2248,
  21766. approxequalorimage: 0x2252,
  21767. approximatelyequal: 0x2245,
  21768. araeaekorean: 0x318E,
  21769. araeakorean: 0x318D,
  21770. arc: 0x2312,
  21771. arighthalfring: 0x1E9A,
  21772. aring: 0x00E5,
  21773. aringacute: 0x01FB,
  21774. aringbelow: 0x1E01,
  21775. arrowboth: 0x2194,
  21776. arrowdashdown: 0x21E3,
  21777. arrowdashleft: 0x21E0,
  21778. arrowdashright: 0x21E2,
  21779. arrowdashup: 0x21E1,
  21780. arrowdblboth: 0x21D4,
  21781. arrowdbldown: 0x21D3,
  21782. arrowdblleft: 0x21D0,
  21783. arrowdblright: 0x21D2,
  21784. arrowdblup: 0x21D1,
  21785. arrowdown: 0x2193,
  21786. arrowdownleft: 0x2199,
  21787. arrowdownright: 0x2198,
  21788. arrowdownwhite: 0x21E9,
  21789. arrowheaddownmod: 0x02C5,
  21790. arrowheadleftmod: 0x02C2,
  21791. arrowheadrightmod: 0x02C3,
  21792. arrowheadupmod: 0x02C4,
  21793. arrowhorizex: 0xF8E7,
  21794. arrowleft: 0x2190,
  21795. arrowleftdbl: 0x21D0,
  21796. arrowleftdblstroke: 0x21CD,
  21797. arrowleftoverright: 0x21C6,
  21798. arrowleftwhite: 0x21E6,
  21799. arrowright: 0x2192,
  21800. arrowrightdblstroke: 0x21CF,
  21801. arrowrightheavy: 0x279E,
  21802. arrowrightoverleft: 0x21C4,
  21803. arrowrightwhite: 0x21E8,
  21804. arrowtableft: 0x21E4,
  21805. arrowtabright: 0x21E5,
  21806. arrowup: 0x2191,
  21807. arrowupdn: 0x2195,
  21808. arrowupdnbse: 0x21A8,
  21809. arrowupdownbase: 0x21A8,
  21810. arrowupleft: 0x2196,
  21811. arrowupleftofdown: 0x21C5,
  21812. arrowupright: 0x2197,
  21813. arrowupwhite: 0x21E7,
  21814. arrowvertex: 0xF8E6,
  21815. asciicircum: 0x005E,
  21816. asciicircummonospace: 0xFF3E,
  21817. asciitilde: 0x007E,
  21818. asciitildemonospace: 0xFF5E,
  21819. ascript: 0x0251,
  21820. ascriptturned: 0x0252,
  21821. asmallhiragana: 0x3041,
  21822. asmallkatakana: 0x30A1,
  21823. asmallkatakanahalfwidth: 0xFF67,
  21824. asterisk: 0x002A,
  21825. asteriskaltonearabic: 0x066D,
  21826. asteriskarabic: 0x066D,
  21827. asteriskmath: 0x2217,
  21828. asteriskmonospace: 0xFF0A,
  21829. asterisksmall: 0xFE61,
  21830. asterism: 0x2042,
  21831. asuperior: 0xF6E9,
  21832. asymptoticallyequal: 0x2243,
  21833. at: 0x0040,
  21834. atilde: 0x00E3,
  21835. atmonospace: 0xFF20,
  21836. atsmall: 0xFE6B,
  21837. aturned: 0x0250,
  21838. aubengali: 0x0994,
  21839. aubopomofo: 0x3120,
  21840. audeva: 0x0914,
  21841. augujarati: 0x0A94,
  21842. augurmukhi: 0x0A14,
  21843. aulengthmarkbengali: 0x09D7,
  21844. aumatragurmukhi: 0x0A4C,
  21845. auvowelsignbengali: 0x09CC,
  21846. auvowelsigndeva: 0x094C,
  21847. auvowelsigngujarati: 0x0ACC,
  21848. avagrahadeva: 0x093D,
  21849. aybarmenian: 0x0561,
  21850. ayin: 0x05E2,
  21851. ayinaltonehebrew: 0xFB20,
  21852. ayinhebrew: 0x05E2,
  21853. b: 0x0062,
  21854. babengali: 0x09AC,
  21855. backslash: 0x005C,
  21856. backslashmonospace: 0xFF3C,
  21857. badeva: 0x092C,
  21858. bagujarati: 0x0AAC,
  21859. bagurmukhi: 0x0A2C,
  21860. bahiragana: 0x3070,
  21861. bahtthai: 0x0E3F,
  21862. bakatakana: 0x30D0,
  21863. bar: 0x007C,
  21864. barmonospace: 0xFF5C,
  21865. bbopomofo: 0x3105,
  21866. bcircle: 0x24D1,
  21867. bdotaccent: 0x1E03,
  21868. bdotbelow: 0x1E05,
  21869. beamedsixteenthnotes: 0x266C,
  21870. because: 0x2235,
  21871. becyrillic: 0x0431,
  21872. beharabic: 0x0628,
  21873. behfinalarabic: 0xFE90,
  21874. behinitialarabic: 0xFE91,
  21875. behiragana: 0x3079,
  21876. behmedialarabic: 0xFE92,
  21877. behmeeminitialarabic: 0xFC9F,
  21878. behmeemisolatedarabic: 0xFC08,
  21879. behnoonfinalarabic: 0xFC6D,
  21880. bekatakana: 0x30D9,
  21881. benarmenian: 0x0562,
  21882. bet: 0x05D1,
  21883. beta: 0x03B2,
  21884. betasymbolgreek: 0x03D0,
  21885. betdagesh: 0xFB31,
  21886. betdageshhebrew: 0xFB31,
  21887. bethebrew: 0x05D1,
  21888. betrafehebrew: 0xFB4C,
  21889. bhabengali: 0x09AD,
  21890. bhadeva: 0x092D,
  21891. bhagujarati: 0x0AAD,
  21892. bhagurmukhi: 0x0A2D,
  21893. bhook: 0x0253,
  21894. bihiragana: 0x3073,
  21895. bikatakana: 0x30D3,
  21896. bilabialclick: 0x0298,
  21897. bindigurmukhi: 0x0A02,
  21898. birusquare: 0x3331,
  21899. blackcircle: 0x25CF,
  21900. blackdiamond: 0x25C6,
  21901. blackdownpointingtriangle: 0x25BC,
  21902. blackleftpointingpointer: 0x25C4,
  21903. blackleftpointingtriangle: 0x25C0,
  21904. blacklenticularbracketleft: 0x3010,
  21905. blacklenticularbracketleftvertical: 0xFE3B,
  21906. blacklenticularbracketright: 0x3011,
  21907. blacklenticularbracketrightvertical: 0xFE3C,
  21908. blacklowerlefttriangle: 0x25E3,
  21909. blacklowerrighttriangle: 0x25E2,
  21910. blackrectangle: 0x25AC,
  21911. blackrightpointingpointer: 0x25BA,
  21912. blackrightpointingtriangle: 0x25B6,
  21913. blacksmallsquare: 0x25AA,
  21914. blacksmilingface: 0x263B,
  21915. blacksquare: 0x25A0,
  21916. blackstar: 0x2605,
  21917. blackupperlefttriangle: 0x25E4,
  21918. blackupperrighttriangle: 0x25E5,
  21919. blackuppointingsmalltriangle: 0x25B4,
  21920. blackuppointingtriangle: 0x25B2,
  21921. blank: 0x2423,
  21922. blinebelow: 0x1E07,
  21923. block: 0x2588,
  21924. bmonospace: 0xFF42,
  21925. bobaimaithai: 0x0E1A,
  21926. bohiragana: 0x307C,
  21927. bokatakana: 0x30DC,
  21928. bparen: 0x249D,
  21929. bqsquare: 0x33C3,
  21930. braceex: 0xF8F4,
  21931. braceleft: 0x007B,
  21932. braceleftbt: 0xF8F3,
  21933. braceleftmid: 0xF8F2,
  21934. braceleftmonospace: 0xFF5B,
  21935. braceleftsmall: 0xFE5B,
  21936. bracelefttp: 0xF8F1,
  21937. braceleftvertical: 0xFE37,
  21938. braceright: 0x007D,
  21939. bracerightbt: 0xF8FE,
  21940. bracerightmid: 0xF8FD,
  21941. bracerightmonospace: 0xFF5D,
  21942. bracerightsmall: 0xFE5C,
  21943. bracerighttp: 0xF8FC,
  21944. bracerightvertical: 0xFE38,
  21945. bracketleft: 0x005B,
  21946. bracketleftbt: 0xF8F0,
  21947. bracketleftex: 0xF8EF,
  21948. bracketleftmonospace: 0xFF3B,
  21949. bracketlefttp: 0xF8EE,
  21950. bracketright: 0x005D,
  21951. bracketrightbt: 0xF8FB,
  21952. bracketrightex: 0xF8FA,
  21953. bracketrightmonospace: 0xFF3D,
  21954. bracketrighttp: 0xF8F9,
  21955. breve: 0x02D8,
  21956. brevebelowcmb: 0x032E,
  21957. brevecmb: 0x0306,
  21958. breveinvertedbelowcmb: 0x032F,
  21959. breveinvertedcmb: 0x0311,
  21960. breveinverteddoublecmb: 0x0361,
  21961. bridgebelowcmb: 0x032A,
  21962. bridgeinvertedbelowcmb: 0x033A,
  21963. brokenbar: 0x00A6,
  21964. bstroke: 0x0180,
  21965. bsuperior: 0xF6EA,
  21966. btopbar: 0x0183,
  21967. buhiragana: 0x3076,
  21968. bukatakana: 0x30D6,
  21969. bullet: 0x2022,
  21970. bulletinverse: 0x25D8,
  21971. bulletoperator: 0x2219,
  21972. bullseye: 0x25CE,
  21973. c: 0x0063,
  21974. caarmenian: 0x056E,
  21975. cabengali: 0x099A,
  21976. cacute: 0x0107,
  21977. cadeva: 0x091A,
  21978. cagujarati: 0x0A9A,
  21979. cagurmukhi: 0x0A1A,
  21980. calsquare: 0x3388,
  21981. candrabindubengali: 0x0981,
  21982. candrabinducmb: 0x0310,
  21983. candrabindudeva: 0x0901,
  21984. candrabindugujarati: 0x0A81,
  21985. capslock: 0x21EA,
  21986. careof: 0x2105,
  21987. caron: 0x02C7,
  21988. caronbelowcmb: 0x032C,
  21989. caroncmb: 0x030C,
  21990. carriagereturn: 0x21B5,
  21991. cbopomofo: 0x3118,
  21992. ccaron: 0x010D,
  21993. ccedilla: 0x00E7,
  21994. ccedillaacute: 0x1E09,
  21995. ccircle: 0x24D2,
  21996. ccircumflex: 0x0109,
  21997. ccurl: 0x0255,
  21998. cdot: 0x010B,
  21999. cdotaccent: 0x010B,
  22000. cdsquare: 0x33C5,
  22001. cedilla: 0x00B8,
  22002. cedillacmb: 0x0327,
  22003. cent: 0x00A2,
  22004. centigrade: 0x2103,
  22005. centinferior: 0xF6DF,
  22006. centmonospace: 0xFFE0,
  22007. centoldstyle: 0xF7A2,
  22008. centsuperior: 0xF6E0,
  22009. chaarmenian: 0x0579,
  22010. chabengali: 0x099B,
  22011. chadeva: 0x091B,
  22012. chagujarati: 0x0A9B,
  22013. chagurmukhi: 0x0A1B,
  22014. chbopomofo: 0x3114,
  22015. cheabkhasiancyrillic: 0x04BD,
  22016. checkmark: 0x2713,
  22017. checyrillic: 0x0447,
  22018. chedescenderabkhasiancyrillic: 0x04BF,
  22019. chedescendercyrillic: 0x04B7,
  22020. chedieresiscyrillic: 0x04F5,
  22021. cheharmenian: 0x0573,
  22022. chekhakassiancyrillic: 0x04CC,
  22023. cheverticalstrokecyrillic: 0x04B9,
  22024. chi: 0x03C7,
  22025. chieuchacirclekorean: 0x3277,
  22026. chieuchaparenkorean: 0x3217,
  22027. chieuchcirclekorean: 0x3269,
  22028. chieuchkorean: 0x314A,
  22029. chieuchparenkorean: 0x3209,
  22030. chochangthai: 0x0E0A,
  22031. chochanthai: 0x0E08,
  22032. chochingthai: 0x0E09,
  22033. chochoethai: 0x0E0C,
  22034. chook: 0x0188,
  22035. cieucacirclekorean: 0x3276,
  22036. cieucaparenkorean: 0x3216,
  22037. cieuccirclekorean: 0x3268,
  22038. cieuckorean: 0x3148,
  22039. cieucparenkorean: 0x3208,
  22040. cieucuparenkorean: 0x321C,
  22041. circle: 0x25CB,
  22042. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  22043. circlemultiply: 0x2297,
  22044. circleot: 0x2299,
  22045. circleplus: 0x2295,
  22046. circlepostalmark: 0x3036,
  22047. circlewithlefthalfblack: 0x25D0,
  22048. circlewithrighthalfblack: 0x25D1,
  22049. circumflex: 0x02C6,
  22050. circumflexbelowcmb: 0x032D,
  22051. circumflexcmb: 0x0302,
  22052. clear: 0x2327,
  22053. clickalveolar: 0x01C2,
  22054. clickdental: 0x01C0,
  22055. clicklateral: 0x01C1,
  22056. clickretroflex: 0x01C3,
  22057. club: 0x2663,
  22058. clubsuitblack: 0x2663,
  22059. clubsuitwhite: 0x2667,
  22060. cmcubedsquare: 0x33A4,
  22061. cmonospace: 0xFF43,
  22062. cmsquaredsquare: 0x33A0,
  22063. coarmenian: 0x0581,
  22064. colon: 0x003A,
  22065. colonmonetary: 0x20A1,
  22066. colonmonospace: 0xFF1A,
  22067. colonsign: 0x20A1,
  22068. colonsmall: 0xFE55,
  22069. colontriangularhalfmod: 0x02D1,
  22070. colontriangularmod: 0x02D0,
  22071. comma: 0x002C,
  22072. commaabovecmb: 0x0313,
  22073. commaaboverightcmb: 0x0315,
  22074. commaaccent: 0xF6C3,
  22075. commaarabic: 0x060C,
  22076. commaarmenian: 0x055D,
  22077. commainferior: 0xF6E1,
  22078. commamonospace: 0xFF0C,
  22079. commareversedabovecmb: 0x0314,
  22080. commareversedmod: 0x02BD,
  22081. commasmall: 0xFE50,
  22082. commasuperior: 0xF6E2,
  22083. commaturnedabovecmb: 0x0312,
  22084. commaturnedmod: 0x02BB,
  22085. compass: 0x263C,
  22086. congruent: 0x2245,
  22087. contourintegral: 0x222E,
  22088. control: 0x2303,
  22089. controlACK: 0x0006,
  22090. controlBEL: 0x0007,
  22091. controlBS: 0x0008,
  22092. controlCAN: 0x0018,
  22093. controlCR: 0x000D,
  22094. controlDC1: 0x0011,
  22095. controlDC2: 0x0012,
  22096. controlDC3: 0x0013,
  22097. controlDC4: 0x0014,
  22098. controlDEL: 0x007F,
  22099. controlDLE: 0x0010,
  22100. controlEM: 0x0019,
  22101. controlENQ: 0x0005,
  22102. controlEOT: 0x0004,
  22103. controlESC: 0x001B,
  22104. controlETB: 0x0017,
  22105. controlETX: 0x0003,
  22106. controlFF: 0x000C,
  22107. controlFS: 0x001C,
  22108. controlGS: 0x001D,
  22109. controlHT: 0x0009,
  22110. controlLF: 0x000A,
  22111. controlNAK: 0x0015,
  22112. controlRS: 0x001E,
  22113. controlSI: 0x000F,
  22114. controlSO: 0x000E,
  22115. controlSOT: 0x0002,
  22116. controlSTX: 0x0001,
  22117. controlSUB: 0x001A,
  22118. controlSYN: 0x0016,
  22119. controlUS: 0x001F,
  22120. controlVT: 0x000B,
  22121. copyright: 0x00A9,
  22122. copyrightsans: 0xF8E9,
  22123. copyrightserif: 0xF6D9,
  22124. cornerbracketleft: 0x300C,
  22125. cornerbracketlefthalfwidth: 0xFF62,
  22126. cornerbracketleftvertical: 0xFE41,
  22127. cornerbracketright: 0x300D,
  22128. cornerbracketrighthalfwidth: 0xFF63,
  22129. cornerbracketrightvertical: 0xFE42,
  22130. corporationsquare: 0x337F,
  22131. cosquare: 0x33C7,
  22132. coverkgsquare: 0x33C6,
  22133. cparen: 0x249E,
  22134. cruzeiro: 0x20A2,
  22135. cstretched: 0x0297,
  22136. curlyand: 0x22CF,
  22137. curlyor: 0x22CE,
  22138. currency: 0x00A4,
  22139. cyrBreve: 0xF6D1,
  22140. cyrFlex: 0xF6D2,
  22141. cyrbreve: 0xF6D4,
  22142. cyrflex: 0xF6D5,
  22143. d: 0x0064,
  22144. daarmenian: 0x0564,
  22145. dabengali: 0x09A6,
  22146. dadarabic: 0x0636,
  22147. dadeva: 0x0926,
  22148. dadfinalarabic: 0xFEBE,
  22149. dadinitialarabic: 0xFEBF,
  22150. dadmedialarabic: 0xFEC0,
  22151. dagesh: 0x05BC,
  22152. dageshhebrew: 0x05BC,
  22153. dagger: 0x2020,
  22154. daggerdbl: 0x2021,
  22155. dagujarati: 0x0AA6,
  22156. dagurmukhi: 0x0A26,
  22157. dahiragana: 0x3060,
  22158. dakatakana: 0x30C0,
  22159. dalarabic: 0x062F,
  22160. dalet: 0x05D3,
  22161. daletdagesh: 0xFB33,
  22162. daletdageshhebrew: 0xFB33,
  22163. dalethebrew: 0x05D3,
  22164. dalfinalarabic: 0xFEAA,
  22165. dammaarabic: 0x064F,
  22166. dammalowarabic: 0x064F,
  22167. dammatanaltonearabic: 0x064C,
  22168. dammatanarabic: 0x064C,
  22169. danda: 0x0964,
  22170. dargahebrew: 0x05A7,
  22171. dargalefthebrew: 0x05A7,
  22172. dasiapneumatacyrilliccmb: 0x0485,
  22173. dblGrave: 0xF6D3,
  22174. dblanglebracketleft: 0x300A,
  22175. dblanglebracketleftvertical: 0xFE3D,
  22176. dblanglebracketright: 0x300B,
  22177. dblanglebracketrightvertical: 0xFE3E,
  22178. dblarchinvertedbelowcmb: 0x032B,
  22179. dblarrowleft: 0x21D4,
  22180. dblarrowright: 0x21D2,
  22181. dbldanda: 0x0965,
  22182. dblgrave: 0xF6D6,
  22183. dblgravecmb: 0x030F,
  22184. dblintegral: 0x222C,
  22185. dbllowline: 0x2017,
  22186. dbllowlinecmb: 0x0333,
  22187. dbloverlinecmb: 0x033F,
  22188. dblprimemod: 0x02BA,
  22189. dblverticalbar: 0x2016,
  22190. dblverticallineabovecmb: 0x030E,
  22191. dbopomofo: 0x3109,
  22192. dbsquare: 0x33C8,
  22193. dcaron: 0x010F,
  22194. dcedilla: 0x1E11,
  22195. dcircle: 0x24D3,
  22196. dcircumflexbelow: 0x1E13,
  22197. dcroat: 0x0111,
  22198. ddabengali: 0x09A1,
  22199. ddadeva: 0x0921,
  22200. ddagujarati: 0x0AA1,
  22201. ddagurmukhi: 0x0A21,
  22202. ddalarabic: 0x0688,
  22203. ddalfinalarabic: 0xFB89,
  22204. dddhadeva: 0x095C,
  22205. ddhabengali: 0x09A2,
  22206. ddhadeva: 0x0922,
  22207. ddhagujarati: 0x0AA2,
  22208. ddhagurmukhi: 0x0A22,
  22209. ddotaccent: 0x1E0B,
  22210. ddotbelow: 0x1E0D,
  22211. decimalseparatorarabic: 0x066B,
  22212. decimalseparatorpersian: 0x066B,
  22213. decyrillic: 0x0434,
  22214. degree: 0x00B0,
  22215. dehihebrew: 0x05AD,
  22216. dehiragana: 0x3067,
  22217. deicoptic: 0x03EF,
  22218. dekatakana: 0x30C7,
  22219. deleteleft: 0x232B,
  22220. deleteright: 0x2326,
  22221. delta: 0x03B4,
  22222. deltaturned: 0x018D,
  22223. denominatorminusonenumeratorbengali: 0x09F8,
  22224. dezh: 0x02A4,
  22225. dhabengali: 0x09A7,
  22226. dhadeva: 0x0927,
  22227. dhagujarati: 0x0AA7,
  22228. dhagurmukhi: 0x0A27,
  22229. dhook: 0x0257,
  22230. dialytikatonos: 0x0385,
  22231. dialytikatonoscmb: 0x0344,
  22232. diamond: 0x2666,
  22233. diamondsuitwhite: 0x2662,
  22234. dieresis: 0x00A8,
  22235. dieresisacute: 0xF6D7,
  22236. dieresisbelowcmb: 0x0324,
  22237. dieresiscmb: 0x0308,
  22238. dieresisgrave: 0xF6D8,
  22239. dieresistonos: 0x0385,
  22240. dihiragana: 0x3062,
  22241. dikatakana: 0x30C2,
  22242. dittomark: 0x3003,
  22243. divide: 0x00F7,
  22244. divides: 0x2223,
  22245. divisionslash: 0x2215,
  22246. djecyrillic: 0x0452,
  22247. dkshade: 0x2593,
  22248. dlinebelow: 0x1E0F,
  22249. dlsquare: 0x3397,
  22250. dmacron: 0x0111,
  22251. dmonospace: 0xFF44,
  22252. dnblock: 0x2584,
  22253. dochadathai: 0x0E0E,
  22254. dodekthai: 0x0E14,
  22255. dohiragana: 0x3069,
  22256. dokatakana: 0x30C9,
  22257. dollar: 0x0024,
  22258. dollarinferior: 0xF6E3,
  22259. dollarmonospace: 0xFF04,
  22260. dollaroldstyle: 0xF724,
  22261. dollarsmall: 0xFE69,
  22262. dollarsuperior: 0xF6E4,
  22263. dong: 0x20AB,
  22264. dorusquare: 0x3326,
  22265. dotaccent: 0x02D9,
  22266. dotaccentcmb: 0x0307,
  22267. dotbelowcmb: 0x0323,
  22268. dotbelowcomb: 0x0323,
  22269. dotkatakana: 0x30FB,
  22270. dotlessi: 0x0131,
  22271. dotlessj: 0xF6BE,
  22272. dotlessjstrokehook: 0x0284,
  22273. dotmath: 0x22C5,
  22274. dottedcircle: 0x25CC,
  22275. doubleyodpatah: 0xFB1F,
  22276. doubleyodpatahhebrew: 0xFB1F,
  22277. downtackbelowcmb: 0x031E,
  22278. downtackmod: 0x02D5,
  22279. dparen: 0x249F,
  22280. dsuperior: 0xF6EB,
  22281. dtail: 0x0256,
  22282. dtopbar: 0x018C,
  22283. duhiragana: 0x3065,
  22284. dukatakana: 0x30C5,
  22285. dz: 0x01F3,
  22286. dzaltone: 0x02A3,
  22287. dzcaron: 0x01C6,
  22288. dzcurl: 0x02A5,
  22289. dzeabkhasiancyrillic: 0x04E1,
  22290. dzecyrillic: 0x0455,
  22291. dzhecyrillic: 0x045F,
  22292. e: 0x0065,
  22293. eacute: 0x00E9,
  22294. earth: 0x2641,
  22295. ebengali: 0x098F,
  22296. ebopomofo: 0x311C,
  22297. ebreve: 0x0115,
  22298. ecandradeva: 0x090D,
  22299. ecandragujarati: 0x0A8D,
  22300. ecandravowelsigndeva: 0x0945,
  22301. ecandravowelsigngujarati: 0x0AC5,
  22302. ecaron: 0x011B,
  22303. ecedillabreve: 0x1E1D,
  22304. echarmenian: 0x0565,
  22305. echyiwnarmenian: 0x0587,
  22306. ecircle: 0x24D4,
  22307. ecircumflex: 0x00EA,
  22308. ecircumflexacute: 0x1EBF,
  22309. ecircumflexbelow: 0x1E19,
  22310. ecircumflexdotbelow: 0x1EC7,
  22311. ecircumflexgrave: 0x1EC1,
  22312. ecircumflexhookabove: 0x1EC3,
  22313. ecircumflextilde: 0x1EC5,
  22314. ecyrillic: 0x0454,
  22315. edblgrave: 0x0205,
  22316. edeva: 0x090F,
  22317. edieresis: 0x00EB,
  22318. edot: 0x0117,
  22319. edotaccent: 0x0117,
  22320. edotbelow: 0x1EB9,
  22321. eegurmukhi: 0x0A0F,
  22322. eematragurmukhi: 0x0A47,
  22323. efcyrillic: 0x0444,
  22324. egrave: 0x00E8,
  22325. egujarati: 0x0A8F,
  22326. eharmenian: 0x0567,
  22327. ehbopomofo: 0x311D,
  22328. ehiragana: 0x3048,
  22329. ehookabove: 0x1EBB,
  22330. eibopomofo: 0x311F,
  22331. eight: 0x0038,
  22332. eightarabic: 0x0668,
  22333. eightbengali: 0x09EE,
  22334. eightcircle: 0x2467,
  22335. eightcircleinversesansserif: 0x2791,
  22336. eightdeva: 0x096E,
  22337. eighteencircle: 0x2471,
  22338. eighteenparen: 0x2485,
  22339. eighteenperiod: 0x2499,
  22340. eightgujarati: 0x0AEE,
  22341. eightgurmukhi: 0x0A6E,
  22342. eighthackarabic: 0x0668,
  22343. eighthangzhou: 0x3028,
  22344. eighthnotebeamed: 0x266B,
  22345. eightideographicparen: 0x3227,
  22346. eightinferior: 0x2088,
  22347. eightmonospace: 0xFF18,
  22348. eightoldstyle: 0xF738,
  22349. eightparen: 0x247B,
  22350. eightperiod: 0x248F,
  22351. eightpersian: 0x06F8,
  22352. eightroman: 0x2177,
  22353. eightsuperior: 0x2078,
  22354. eightthai: 0x0E58,
  22355. einvertedbreve: 0x0207,
  22356. eiotifiedcyrillic: 0x0465,
  22357. ekatakana: 0x30A8,
  22358. ekatakanahalfwidth: 0xFF74,
  22359. ekonkargurmukhi: 0x0A74,
  22360. ekorean: 0x3154,
  22361. elcyrillic: 0x043B,
  22362. element: 0x2208,
  22363. elevencircle: 0x246A,
  22364. elevenparen: 0x247E,
  22365. elevenperiod: 0x2492,
  22366. elevenroman: 0x217A,
  22367. ellipsis: 0x2026,
  22368. ellipsisvertical: 0x22EE,
  22369. emacron: 0x0113,
  22370. emacronacute: 0x1E17,
  22371. emacrongrave: 0x1E15,
  22372. emcyrillic: 0x043C,
  22373. emdash: 0x2014,
  22374. emdashvertical: 0xFE31,
  22375. emonospace: 0xFF45,
  22376. emphasismarkarmenian: 0x055B,
  22377. emptyset: 0x2205,
  22378. enbopomofo: 0x3123,
  22379. encyrillic: 0x043D,
  22380. endash: 0x2013,
  22381. endashvertical: 0xFE32,
  22382. endescendercyrillic: 0x04A3,
  22383. eng: 0x014B,
  22384. engbopomofo: 0x3125,
  22385. enghecyrillic: 0x04A5,
  22386. enhookcyrillic: 0x04C8,
  22387. enspace: 0x2002,
  22388. eogonek: 0x0119,
  22389. eokorean: 0x3153,
  22390. eopen: 0x025B,
  22391. eopenclosed: 0x029A,
  22392. eopenreversed: 0x025C,
  22393. eopenreversedclosed: 0x025E,
  22394. eopenreversedhook: 0x025D,
  22395. eparen: 0x24A0,
  22396. epsilon: 0x03B5,
  22397. epsilontonos: 0x03AD,
  22398. equal: 0x003D,
  22399. equalmonospace: 0xFF1D,
  22400. equalsmall: 0xFE66,
  22401. equalsuperior: 0x207C,
  22402. equivalence: 0x2261,
  22403. erbopomofo: 0x3126,
  22404. ercyrillic: 0x0440,
  22405. ereversed: 0x0258,
  22406. ereversedcyrillic: 0x044D,
  22407. escyrillic: 0x0441,
  22408. esdescendercyrillic: 0x04AB,
  22409. esh: 0x0283,
  22410. eshcurl: 0x0286,
  22411. eshortdeva: 0x090E,
  22412. eshortvowelsigndeva: 0x0946,
  22413. eshreversedloop: 0x01AA,
  22414. eshsquatreversed: 0x0285,
  22415. esmallhiragana: 0x3047,
  22416. esmallkatakana: 0x30A7,
  22417. esmallkatakanahalfwidth: 0xFF6A,
  22418. estimated: 0x212E,
  22419. esuperior: 0xF6EC,
  22420. eta: 0x03B7,
  22421. etarmenian: 0x0568,
  22422. etatonos: 0x03AE,
  22423. eth: 0x00F0,
  22424. etilde: 0x1EBD,
  22425. etildebelow: 0x1E1B,
  22426. etnahtafoukhhebrew: 0x0591,
  22427. etnahtafoukhlefthebrew: 0x0591,
  22428. etnahtahebrew: 0x0591,
  22429. etnahtalefthebrew: 0x0591,
  22430. eturned: 0x01DD,
  22431. eukorean: 0x3161,
  22432. euro: 0x20AC,
  22433. evowelsignbengali: 0x09C7,
  22434. evowelsigndeva: 0x0947,
  22435. evowelsigngujarati: 0x0AC7,
  22436. exclam: 0x0021,
  22437. exclamarmenian: 0x055C,
  22438. exclamdbl: 0x203C,
  22439. exclamdown: 0x00A1,
  22440. exclamdownsmall: 0xF7A1,
  22441. exclammonospace: 0xFF01,
  22442. exclamsmall: 0xF721,
  22443. existential: 0x2203,
  22444. ezh: 0x0292,
  22445. ezhcaron: 0x01EF,
  22446. ezhcurl: 0x0293,
  22447. ezhreversed: 0x01B9,
  22448. ezhtail: 0x01BA,
  22449. f: 0x0066,
  22450. fadeva: 0x095E,
  22451. fagurmukhi: 0x0A5E,
  22452. fahrenheit: 0x2109,
  22453. fathaarabic: 0x064E,
  22454. fathalowarabic: 0x064E,
  22455. fathatanarabic: 0x064B,
  22456. fbopomofo: 0x3108,
  22457. fcircle: 0x24D5,
  22458. fdotaccent: 0x1E1F,
  22459. feharabic: 0x0641,
  22460. feharmenian: 0x0586,
  22461. fehfinalarabic: 0xFED2,
  22462. fehinitialarabic: 0xFED3,
  22463. fehmedialarabic: 0xFED4,
  22464. feicoptic: 0x03E5,
  22465. female: 0x2640,
  22466. ff: 0xFB00,
  22467. ffi: 0xFB03,
  22468. ffl: 0xFB04,
  22469. fi: 0xFB01,
  22470. fifteencircle: 0x246E,
  22471. fifteenparen: 0x2482,
  22472. fifteenperiod: 0x2496,
  22473. figuredash: 0x2012,
  22474. filledbox: 0x25A0,
  22475. filledrect: 0x25AC,
  22476. finalkaf: 0x05DA,
  22477. finalkafdagesh: 0xFB3A,
  22478. finalkafdageshhebrew: 0xFB3A,
  22479. finalkafhebrew: 0x05DA,
  22480. finalmem: 0x05DD,
  22481. finalmemhebrew: 0x05DD,
  22482. finalnun: 0x05DF,
  22483. finalnunhebrew: 0x05DF,
  22484. finalpe: 0x05E3,
  22485. finalpehebrew: 0x05E3,
  22486. finaltsadi: 0x05E5,
  22487. finaltsadihebrew: 0x05E5,
  22488. firsttonechinese: 0x02C9,
  22489. fisheye: 0x25C9,
  22490. fitacyrillic: 0x0473,
  22491. five: 0x0035,
  22492. fivearabic: 0x0665,
  22493. fivebengali: 0x09EB,
  22494. fivecircle: 0x2464,
  22495. fivecircleinversesansserif: 0x278E,
  22496. fivedeva: 0x096B,
  22497. fiveeighths: 0x215D,
  22498. fivegujarati: 0x0AEB,
  22499. fivegurmukhi: 0x0A6B,
  22500. fivehackarabic: 0x0665,
  22501. fivehangzhou: 0x3025,
  22502. fiveideographicparen: 0x3224,
  22503. fiveinferior: 0x2085,
  22504. fivemonospace: 0xFF15,
  22505. fiveoldstyle: 0xF735,
  22506. fiveparen: 0x2478,
  22507. fiveperiod: 0x248C,
  22508. fivepersian: 0x06F5,
  22509. fiveroman: 0x2174,
  22510. fivesuperior: 0x2075,
  22511. fivethai: 0x0E55,
  22512. fl: 0xFB02,
  22513. florin: 0x0192,
  22514. fmonospace: 0xFF46,
  22515. fmsquare: 0x3399,
  22516. fofanthai: 0x0E1F,
  22517. fofathai: 0x0E1D,
  22518. fongmanthai: 0x0E4F,
  22519. forall: 0x2200,
  22520. four: 0x0034,
  22521. fourarabic: 0x0664,
  22522. fourbengali: 0x09EA,
  22523. fourcircle: 0x2463,
  22524. fourcircleinversesansserif: 0x278D,
  22525. fourdeva: 0x096A,
  22526. fourgujarati: 0x0AEA,
  22527. fourgurmukhi: 0x0A6A,
  22528. fourhackarabic: 0x0664,
  22529. fourhangzhou: 0x3024,
  22530. fourideographicparen: 0x3223,
  22531. fourinferior: 0x2084,
  22532. fourmonospace: 0xFF14,
  22533. fournumeratorbengali: 0x09F7,
  22534. fouroldstyle: 0xF734,
  22535. fourparen: 0x2477,
  22536. fourperiod: 0x248B,
  22537. fourpersian: 0x06F4,
  22538. fourroman: 0x2173,
  22539. foursuperior: 0x2074,
  22540. fourteencircle: 0x246D,
  22541. fourteenparen: 0x2481,
  22542. fourteenperiod: 0x2495,
  22543. fourthai: 0x0E54,
  22544. fourthtonechinese: 0x02CB,
  22545. fparen: 0x24A1,
  22546. fraction: 0x2044,
  22547. franc: 0x20A3,
  22548. g: 0x0067,
  22549. gabengali: 0x0997,
  22550. gacute: 0x01F5,
  22551. gadeva: 0x0917,
  22552. gafarabic: 0x06AF,
  22553. gaffinalarabic: 0xFB93,
  22554. gafinitialarabic: 0xFB94,
  22555. gafmedialarabic: 0xFB95,
  22556. gagujarati: 0x0A97,
  22557. gagurmukhi: 0x0A17,
  22558. gahiragana: 0x304C,
  22559. gakatakana: 0x30AC,
  22560. gamma: 0x03B3,
  22561. gammalatinsmall: 0x0263,
  22562. gammasuperior: 0x02E0,
  22563. gangiacoptic: 0x03EB,
  22564. gbopomofo: 0x310D,
  22565. gbreve: 0x011F,
  22566. gcaron: 0x01E7,
  22567. gcedilla: 0x0123,
  22568. gcircle: 0x24D6,
  22569. gcircumflex: 0x011D,
  22570. gcommaaccent: 0x0123,
  22571. gdot: 0x0121,
  22572. gdotaccent: 0x0121,
  22573. gecyrillic: 0x0433,
  22574. gehiragana: 0x3052,
  22575. gekatakana: 0x30B2,
  22576. geometricallyequal: 0x2251,
  22577. gereshaccenthebrew: 0x059C,
  22578. gereshhebrew: 0x05F3,
  22579. gereshmuqdamhebrew: 0x059D,
  22580. germandbls: 0x00DF,
  22581. gershayimaccenthebrew: 0x059E,
  22582. gershayimhebrew: 0x05F4,
  22583. getamark: 0x3013,
  22584. ghabengali: 0x0998,
  22585. ghadarmenian: 0x0572,
  22586. ghadeva: 0x0918,
  22587. ghagujarati: 0x0A98,
  22588. ghagurmukhi: 0x0A18,
  22589. ghainarabic: 0x063A,
  22590. ghainfinalarabic: 0xFECE,
  22591. ghaininitialarabic: 0xFECF,
  22592. ghainmedialarabic: 0xFED0,
  22593. ghemiddlehookcyrillic: 0x0495,
  22594. ghestrokecyrillic: 0x0493,
  22595. gheupturncyrillic: 0x0491,
  22596. ghhadeva: 0x095A,
  22597. ghhagurmukhi: 0x0A5A,
  22598. ghook: 0x0260,
  22599. ghzsquare: 0x3393,
  22600. gihiragana: 0x304E,
  22601. gikatakana: 0x30AE,
  22602. gimarmenian: 0x0563,
  22603. gimel: 0x05D2,
  22604. gimeldagesh: 0xFB32,
  22605. gimeldageshhebrew: 0xFB32,
  22606. gimelhebrew: 0x05D2,
  22607. gjecyrillic: 0x0453,
  22608. glottalinvertedstroke: 0x01BE,
  22609. glottalstop: 0x0294,
  22610. glottalstopinverted: 0x0296,
  22611. glottalstopmod: 0x02C0,
  22612. glottalstopreversed: 0x0295,
  22613. glottalstopreversedmod: 0x02C1,
  22614. glottalstopreversedsuperior: 0x02E4,
  22615. glottalstopstroke: 0x02A1,
  22616. glottalstopstrokereversed: 0x02A2,
  22617. gmacron: 0x1E21,
  22618. gmonospace: 0xFF47,
  22619. gohiragana: 0x3054,
  22620. gokatakana: 0x30B4,
  22621. gparen: 0x24A2,
  22622. gpasquare: 0x33AC,
  22623. gradient: 0x2207,
  22624. grave: 0x0060,
  22625. gravebelowcmb: 0x0316,
  22626. gravecmb: 0x0300,
  22627. gravecomb: 0x0300,
  22628. gravedeva: 0x0953,
  22629. gravelowmod: 0x02CE,
  22630. gravemonospace: 0xFF40,
  22631. gravetonecmb: 0x0340,
  22632. greater: 0x003E,
  22633. greaterequal: 0x2265,
  22634. greaterequalorless: 0x22DB,
  22635. greatermonospace: 0xFF1E,
  22636. greaterorequivalent: 0x2273,
  22637. greaterorless: 0x2277,
  22638. greateroverequal: 0x2267,
  22639. greatersmall: 0xFE65,
  22640. gscript: 0x0261,
  22641. gstroke: 0x01E5,
  22642. guhiragana: 0x3050,
  22643. guillemotleft: 0x00AB,
  22644. guillemotright: 0x00BB,
  22645. guilsinglleft: 0x2039,
  22646. guilsinglright: 0x203A,
  22647. gukatakana: 0x30B0,
  22648. guramusquare: 0x3318,
  22649. gysquare: 0x33C9,
  22650. h: 0x0068,
  22651. haabkhasiancyrillic: 0x04A9,
  22652. haaltonearabic: 0x06C1,
  22653. habengali: 0x09B9,
  22654. hadescendercyrillic: 0x04B3,
  22655. hadeva: 0x0939,
  22656. hagujarati: 0x0AB9,
  22657. hagurmukhi: 0x0A39,
  22658. haharabic: 0x062D,
  22659. hahfinalarabic: 0xFEA2,
  22660. hahinitialarabic: 0xFEA3,
  22661. hahiragana: 0x306F,
  22662. hahmedialarabic: 0xFEA4,
  22663. haitusquare: 0x332A,
  22664. hakatakana: 0x30CF,
  22665. hakatakanahalfwidth: 0xFF8A,
  22666. halantgurmukhi: 0x0A4D,
  22667. hamzaarabic: 0x0621,
  22668. hamzalowarabic: 0x0621,
  22669. hangulfiller: 0x3164,
  22670. hardsigncyrillic: 0x044A,
  22671. harpoonleftbarbup: 0x21BC,
  22672. harpoonrightbarbup: 0x21C0,
  22673. hasquare: 0x33CA,
  22674. hatafpatah: 0x05B2,
  22675. hatafpatah16: 0x05B2,
  22676. hatafpatah23: 0x05B2,
  22677. hatafpatah2f: 0x05B2,
  22678. hatafpatahhebrew: 0x05B2,
  22679. hatafpatahnarrowhebrew: 0x05B2,
  22680. hatafpatahquarterhebrew: 0x05B2,
  22681. hatafpatahwidehebrew: 0x05B2,
  22682. hatafqamats: 0x05B3,
  22683. hatafqamats1b: 0x05B3,
  22684. hatafqamats28: 0x05B3,
  22685. hatafqamats34: 0x05B3,
  22686. hatafqamatshebrew: 0x05B3,
  22687. hatafqamatsnarrowhebrew: 0x05B3,
  22688. hatafqamatsquarterhebrew: 0x05B3,
  22689. hatafqamatswidehebrew: 0x05B3,
  22690. hatafsegol: 0x05B1,
  22691. hatafsegol17: 0x05B1,
  22692. hatafsegol24: 0x05B1,
  22693. hatafsegol30: 0x05B1,
  22694. hatafsegolhebrew: 0x05B1,
  22695. hatafsegolnarrowhebrew: 0x05B1,
  22696. hatafsegolquarterhebrew: 0x05B1,
  22697. hatafsegolwidehebrew: 0x05B1,
  22698. hbar: 0x0127,
  22699. hbopomofo: 0x310F,
  22700. hbrevebelow: 0x1E2B,
  22701. hcedilla: 0x1E29,
  22702. hcircle: 0x24D7,
  22703. hcircumflex: 0x0125,
  22704. hdieresis: 0x1E27,
  22705. hdotaccent: 0x1E23,
  22706. hdotbelow: 0x1E25,
  22707. he: 0x05D4,
  22708. heart: 0x2665,
  22709. heartsuitblack: 0x2665,
  22710. heartsuitwhite: 0x2661,
  22711. hedagesh: 0xFB34,
  22712. hedageshhebrew: 0xFB34,
  22713. hehaltonearabic: 0x06C1,
  22714. heharabic: 0x0647,
  22715. hehebrew: 0x05D4,
  22716. hehfinalaltonearabic: 0xFBA7,
  22717. hehfinalalttwoarabic: 0xFEEA,
  22718. hehfinalarabic: 0xFEEA,
  22719. hehhamzaabovefinalarabic: 0xFBA5,
  22720. hehhamzaaboveisolatedarabic: 0xFBA4,
  22721. hehinitialaltonearabic: 0xFBA8,
  22722. hehinitialarabic: 0xFEEB,
  22723. hehiragana: 0x3078,
  22724. hehmedialaltonearabic: 0xFBA9,
  22725. hehmedialarabic: 0xFEEC,
  22726. heiseierasquare: 0x337B,
  22727. hekatakana: 0x30D8,
  22728. hekatakanahalfwidth: 0xFF8D,
  22729. hekutaarusquare: 0x3336,
  22730. henghook: 0x0267,
  22731. herutusquare: 0x3339,
  22732. het: 0x05D7,
  22733. hethebrew: 0x05D7,
  22734. hhook: 0x0266,
  22735. hhooksuperior: 0x02B1,
  22736. hieuhacirclekorean: 0x327B,
  22737. hieuhaparenkorean: 0x321B,
  22738. hieuhcirclekorean: 0x326D,
  22739. hieuhkorean: 0x314E,
  22740. hieuhparenkorean: 0x320D,
  22741. hihiragana: 0x3072,
  22742. hikatakana: 0x30D2,
  22743. hikatakanahalfwidth: 0xFF8B,
  22744. hiriq: 0x05B4,
  22745. hiriq14: 0x05B4,
  22746. hiriq21: 0x05B4,
  22747. hiriq2d: 0x05B4,
  22748. hiriqhebrew: 0x05B4,
  22749. hiriqnarrowhebrew: 0x05B4,
  22750. hiriqquarterhebrew: 0x05B4,
  22751. hiriqwidehebrew: 0x05B4,
  22752. hlinebelow: 0x1E96,
  22753. hmonospace: 0xFF48,
  22754. hoarmenian: 0x0570,
  22755. hohipthai: 0x0E2B,
  22756. hohiragana: 0x307B,
  22757. hokatakana: 0x30DB,
  22758. hokatakanahalfwidth: 0xFF8E,
  22759. holam: 0x05B9,
  22760. holam19: 0x05B9,
  22761. holam26: 0x05B9,
  22762. holam32: 0x05B9,
  22763. holamhebrew: 0x05B9,
  22764. holamnarrowhebrew: 0x05B9,
  22765. holamquarterhebrew: 0x05B9,
  22766. holamwidehebrew: 0x05B9,
  22767. honokhukthai: 0x0E2E,
  22768. hookabovecomb: 0x0309,
  22769. hookcmb: 0x0309,
  22770. hookpalatalizedbelowcmb: 0x0321,
  22771. hookretroflexbelowcmb: 0x0322,
  22772. hoonsquare: 0x3342,
  22773. horicoptic: 0x03E9,
  22774. horizontalbar: 0x2015,
  22775. horncmb: 0x031B,
  22776. hotsprings: 0x2668,
  22777. house: 0x2302,
  22778. hparen: 0x24A3,
  22779. hsuperior: 0x02B0,
  22780. hturned: 0x0265,
  22781. huhiragana: 0x3075,
  22782. huiitosquare: 0x3333,
  22783. hukatakana: 0x30D5,
  22784. hukatakanahalfwidth: 0xFF8C,
  22785. hungarumlaut: 0x02DD,
  22786. hungarumlautcmb: 0x030B,
  22787. hv: 0x0195,
  22788. hyphen: 0x002D,
  22789. hypheninferior: 0xF6E5,
  22790. hyphenmonospace: 0xFF0D,
  22791. hyphensmall: 0xFE63,
  22792. hyphensuperior: 0xF6E6,
  22793. hyphentwo: 0x2010,
  22794. i: 0x0069,
  22795. iacute: 0x00ED,
  22796. iacyrillic: 0x044F,
  22797. ibengali: 0x0987,
  22798. ibopomofo: 0x3127,
  22799. ibreve: 0x012D,
  22800. icaron: 0x01D0,
  22801. icircle: 0x24D8,
  22802. icircumflex: 0x00EE,
  22803. icyrillic: 0x0456,
  22804. idblgrave: 0x0209,
  22805. ideographearthcircle: 0x328F,
  22806. ideographfirecircle: 0x328B,
  22807. ideographicallianceparen: 0x323F,
  22808. ideographiccallparen: 0x323A,
  22809. ideographiccentrecircle: 0x32A5,
  22810. ideographicclose: 0x3006,
  22811. ideographiccomma: 0x3001,
  22812. ideographiccommaleft: 0xFF64,
  22813. ideographiccongratulationparen: 0x3237,
  22814. ideographiccorrectcircle: 0x32A3,
  22815. ideographicearthparen: 0x322F,
  22816. ideographicenterpriseparen: 0x323D,
  22817. ideographicexcellentcircle: 0x329D,
  22818. ideographicfestivalparen: 0x3240,
  22819. ideographicfinancialcircle: 0x3296,
  22820. ideographicfinancialparen: 0x3236,
  22821. ideographicfireparen: 0x322B,
  22822. ideographichaveparen: 0x3232,
  22823. ideographichighcircle: 0x32A4,
  22824. ideographiciterationmark: 0x3005,
  22825. ideographiclaborcircle: 0x3298,
  22826. ideographiclaborparen: 0x3238,
  22827. ideographicleftcircle: 0x32A7,
  22828. ideographiclowcircle: 0x32A6,
  22829. ideographicmedicinecircle: 0x32A9,
  22830. ideographicmetalparen: 0x322E,
  22831. ideographicmoonparen: 0x322A,
  22832. ideographicnameparen: 0x3234,
  22833. ideographicperiod: 0x3002,
  22834. ideographicprintcircle: 0x329E,
  22835. ideographicreachparen: 0x3243,
  22836. ideographicrepresentparen: 0x3239,
  22837. ideographicresourceparen: 0x323E,
  22838. ideographicrightcircle: 0x32A8,
  22839. ideographicsecretcircle: 0x3299,
  22840. ideographicselfparen: 0x3242,
  22841. ideographicsocietyparen: 0x3233,
  22842. ideographicspace: 0x3000,
  22843. ideographicspecialparen: 0x3235,
  22844. ideographicstockparen: 0x3231,
  22845. ideographicstudyparen: 0x323B,
  22846. ideographicsunparen: 0x3230,
  22847. ideographicsuperviseparen: 0x323C,
  22848. ideographicwaterparen: 0x322C,
  22849. ideographicwoodparen: 0x322D,
  22850. ideographiczero: 0x3007,
  22851. ideographmetalcircle: 0x328E,
  22852. ideographmooncircle: 0x328A,
  22853. ideographnamecircle: 0x3294,
  22854. ideographsuncircle: 0x3290,
  22855. ideographwatercircle: 0x328C,
  22856. ideographwoodcircle: 0x328D,
  22857. ideva: 0x0907,
  22858. idieresis: 0x00EF,
  22859. idieresisacute: 0x1E2F,
  22860. idieresiscyrillic: 0x04E5,
  22861. idotbelow: 0x1ECB,
  22862. iebrevecyrillic: 0x04D7,
  22863. iecyrillic: 0x0435,
  22864. ieungacirclekorean: 0x3275,
  22865. ieungaparenkorean: 0x3215,
  22866. ieungcirclekorean: 0x3267,
  22867. ieungkorean: 0x3147,
  22868. ieungparenkorean: 0x3207,
  22869. igrave: 0x00EC,
  22870. igujarati: 0x0A87,
  22871. igurmukhi: 0x0A07,
  22872. ihiragana: 0x3044,
  22873. ihookabove: 0x1EC9,
  22874. iibengali: 0x0988,
  22875. iicyrillic: 0x0438,
  22876. iideva: 0x0908,
  22877. iigujarati: 0x0A88,
  22878. iigurmukhi: 0x0A08,
  22879. iimatragurmukhi: 0x0A40,
  22880. iinvertedbreve: 0x020B,
  22881. iishortcyrillic: 0x0439,
  22882. iivowelsignbengali: 0x09C0,
  22883. iivowelsigndeva: 0x0940,
  22884. iivowelsigngujarati: 0x0AC0,
  22885. ij: 0x0133,
  22886. ikatakana: 0x30A4,
  22887. ikatakanahalfwidth: 0xFF72,
  22888. ikorean: 0x3163,
  22889. ilde: 0x02DC,
  22890. iluyhebrew: 0x05AC,
  22891. imacron: 0x012B,
  22892. imacroncyrillic: 0x04E3,
  22893. imageorapproximatelyequal: 0x2253,
  22894. imatragurmukhi: 0x0A3F,
  22895. imonospace: 0xFF49,
  22896. increment: 0x2206,
  22897. infinity: 0x221E,
  22898. iniarmenian: 0x056B,
  22899. integral: 0x222B,
  22900. integralbottom: 0x2321,
  22901. integralbt: 0x2321,
  22902. integralex: 0xF8F5,
  22903. integraltop: 0x2320,
  22904. integraltp: 0x2320,
  22905. intersection: 0x2229,
  22906. intisquare: 0x3305,
  22907. invbullet: 0x25D8,
  22908. invcircle: 0x25D9,
  22909. invsmileface: 0x263B,
  22910. iocyrillic: 0x0451,
  22911. iogonek: 0x012F,
  22912. iota: 0x03B9,
  22913. iotadieresis: 0x03CA,
  22914. iotadieresistonos: 0x0390,
  22915. iotalatin: 0x0269,
  22916. iotatonos: 0x03AF,
  22917. iparen: 0x24A4,
  22918. irigurmukhi: 0x0A72,
  22919. ismallhiragana: 0x3043,
  22920. ismallkatakana: 0x30A3,
  22921. ismallkatakanahalfwidth: 0xFF68,
  22922. issharbengali: 0x09FA,
  22923. istroke: 0x0268,
  22924. isuperior: 0xF6ED,
  22925. iterationhiragana: 0x309D,
  22926. iterationkatakana: 0x30FD,
  22927. itilde: 0x0129,
  22928. itildebelow: 0x1E2D,
  22929. iubopomofo: 0x3129,
  22930. iucyrillic: 0x044E,
  22931. ivowelsignbengali: 0x09BF,
  22932. ivowelsigndeva: 0x093F,
  22933. ivowelsigngujarati: 0x0ABF,
  22934. izhitsacyrillic: 0x0475,
  22935. izhitsadblgravecyrillic: 0x0477,
  22936. j: 0x006A,
  22937. jaarmenian: 0x0571,
  22938. jabengali: 0x099C,
  22939. jadeva: 0x091C,
  22940. jagujarati: 0x0A9C,
  22941. jagurmukhi: 0x0A1C,
  22942. jbopomofo: 0x3110,
  22943. jcaron: 0x01F0,
  22944. jcircle: 0x24D9,
  22945. jcircumflex: 0x0135,
  22946. jcrossedtail: 0x029D,
  22947. jdotlessstroke: 0x025F,
  22948. jecyrillic: 0x0458,
  22949. jeemarabic: 0x062C,
  22950. jeemfinalarabic: 0xFE9E,
  22951. jeeminitialarabic: 0xFE9F,
  22952. jeemmedialarabic: 0xFEA0,
  22953. jeharabic: 0x0698,
  22954. jehfinalarabic: 0xFB8B,
  22955. jhabengali: 0x099D,
  22956. jhadeva: 0x091D,
  22957. jhagujarati: 0x0A9D,
  22958. jhagurmukhi: 0x0A1D,
  22959. jheharmenian: 0x057B,
  22960. jis: 0x3004,
  22961. jmonospace: 0xFF4A,
  22962. jparen: 0x24A5,
  22963. jsuperior: 0x02B2,
  22964. k: 0x006B,
  22965. kabashkircyrillic: 0x04A1,
  22966. kabengali: 0x0995,
  22967. kacute: 0x1E31,
  22968. kacyrillic: 0x043A,
  22969. kadescendercyrillic: 0x049B,
  22970. kadeva: 0x0915,
  22971. kaf: 0x05DB,
  22972. kafarabic: 0x0643,
  22973. kafdagesh: 0xFB3B,
  22974. kafdageshhebrew: 0xFB3B,
  22975. kaffinalarabic: 0xFEDA,
  22976. kafhebrew: 0x05DB,
  22977. kafinitialarabic: 0xFEDB,
  22978. kafmedialarabic: 0xFEDC,
  22979. kafrafehebrew: 0xFB4D,
  22980. kagujarati: 0x0A95,
  22981. kagurmukhi: 0x0A15,
  22982. kahiragana: 0x304B,
  22983. kahookcyrillic: 0x04C4,
  22984. kakatakana: 0x30AB,
  22985. kakatakanahalfwidth: 0xFF76,
  22986. kappa: 0x03BA,
  22987. kappasymbolgreek: 0x03F0,
  22988. kapyeounmieumkorean: 0x3171,
  22989. kapyeounphieuphkorean: 0x3184,
  22990. kapyeounpieupkorean: 0x3178,
  22991. kapyeounssangpieupkorean: 0x3179,
  22992. karoriisquare: 0x330D,
  22993. kashidaautoarabic: 0x0640,
  22994. kashidaautonosidebearingarabic: 0x0640,
  22995. kasmallkatakana: 0x30F5,
  22996. kasquare: 0x3384,
  22997. kasraarabic: 0x0650,
  22998. kasratanarabic: 0x064D,
  22999. kastrokecyrillic: 0x049F,
  23000. katahiraprolongmarkhalfwidth: 0xFF70,
  23001. kaverticalstrokecyrillic: 0x049D,
  23002. kbopomofo: 0x310E,
  23003. kcalsquare: 0x3389,
  23004. kcaron: 0x01E9,
  23005. kcedilla: 0x0137,
  23006. kcircle: 0x24DA,
  23007. kcommaaccent: 0x0137,
  23008. kdotbelow: 0x1E33,
  23009. keharmenian: 0x0584,
  23010. kehiragana: 0x3051,
  23011. kekatakana: 0x30B1,
  23012. kekatakanahalfwidth: 0xFF79,
  23013. kenarmenian: 0x056F,
  23014. kesmallkatakana: 0x30F6,
  23015. kgreenlandic: 0x0138,
  23016. khabengali: 0x0996,
  23017. khacyrillic: 0x0445,
  23018. khadeva: 0x0916,
  23019. khagujarati: 0x0A96,
  23020. khagurmukhi: 0x0A16,
  23021. khaharabic: 0x062E,
  23022. khahfinalarabic: 0xFEA6,
  23023. khahinitialarabic: 0xFEA7,
  23024. khahmedialarabic: 0xFEA8,
  23025. kheicoptic: 0x03E7,
  23026. khhadeva: 0x0959,
  23027. khhagurmukhi: 0x0A59,
  23028. khieukhacirclekorean: 0x3278,
  23029. khieukhaparenkorean: 0x3218,
  23030. khieukhcirclekorean: 0x326A,
  23031. khieukhkorean: 0x314B,
  23032. khieukhparenkorean: 0x320A,
  23033. khokhaithai: 0x0E02,
  23034. khokhonthai: 0x0E05,
  23035. khokhuatthai: 0x0E03,
  23036. khokhwaithai: 0x0E04,
  23037. khomutthai: 0x0E5B,
  23038. khook: 0x0199,
  23039. khorakhangthai: 0x0E06,
  23040. khzsquare: 0x3391,
  23041. kihiragana: 0x304D,
  23042. kikatakana: 0x30AD,
  23043. kikatakanahalfwidth: 0xFF77,
  23044. kiroguramusquare: 0x3315,
  23045. kiromeetorusquare: 0x3316,
  23046. kirosquare: 0x3314,
  23047. kiyeokacirclekorean: 0x326E,
  23048. kiyeokaparenkorean: 0x320E,
  23049. kiyeokcirclekorean: 0x3260,
  23050. kiyeokkorean: 0x3131,
  23051. kiyeokparenkorean: 0x3200,
  23052. kiyeoksioskorean: 0x3133,
  23053. kjecyrillic: 0x045C,
  23054. klinebelow: 0x1E35,
  23055. klsquare: 0x3398,
  23056. kmcubedsquare: 0x33A6,
  23057. kmonospace: 0xFF4B,
  23058. kmsquaredsquare: 0x33A2,
  23059. kohiragana: 0x3053,
  23060. kohmsquare: 0x33C0,
  23061. kokaithai: 0x0E01,
  23062. kokatakana: 0x30B3,
  23063. kokatakanahalfwidth: 0xFF7A,
  23064. kooposquare: 0x331E,
  23065. koppacyrillic: 0x0481,
  23066. koreanstandardsymbol: 0x327F,
  23067. koroniscmb: 0x0343,
  23068. kparen: 0x24A6,
  23069. kpasquare: 0x33AA,
  23070. ksicyrillic: 0x046F,
  23071. ktsquare: 0x33CF,
  23072. kturned: 0x029E,
  23073. kuhiragana: 0x304F,
  23074. kukatakana: 0x30AF,
  23075. kukatakanahalfwidth: 0xFF78,
  23076. kvsquare: 0x33B8,
  23077. kwsquare: 0x33BE,
  23078. l: 0x006C,
  23079. labengali: 0x09B2,
  23080. lacute: 0x013A,
  23081. ladeva: 0x0932,
  23082. lagujarati: 0x0AB2,
  23083. lagurmukhi: 0x0A32,
  23084. lakkhangyaothai: 0x0E45,
  23085. lamaleffinalarabic: 0xFEFC,
  23086. lamalefhamzaabovefinalarabic: 0xFEF8,
  23087. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  23088. lamalefhamzabelowfinalarabic: 0xFEFA,
  23089. lamalefhamzabelowisolatedarabic: 0xFEF9,
  23090. lamalefisolatedarabic: 0xFEFB,
  23091. lamalefmaddaabovefinalarabic: 0xFEF6,
  23092. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  23093. lamarabic: 0x0644,
  23094. lambda: 0x03BB,
  23095. lambdastroke: 0x019B,
  23096. lamed: 0x05DC,
  23097. lameddagesh: 0xFB3C,
  23098. lameddageshhebrew: 0xFB3C,
  23099. lamedhebrew: 0x05DC,
  23100. lamfinalarabic: 0xFEDE,
  23101. lamhahinitialarabic: 0xFCCA,
  23102. laminitialarabic: 0xFEDF,
  23103. lamjeeminitialarabic: 0xFCC9,
  23104. lamkhahinitialarabic: 0xFCCB,
  23105. lamlamhehisolatedarabic: 0xFDF2,
  23106. lammedialarabic: 0xFEE0,
  23107. lammeemhahinitialarabic: 0xFD88,
  23108. lammeeminitialarabic: 0xFCCC,
  23109. largecircle: 0x25EF,
  23110. lbar: 0x019A,
  23111. lbelt: 0x026C,
  23112. lbopomofo: 0x310C,
  23113. lcaron: 0x013E,
  23114. lcedilla: 0x013C,
  23115. lcircle: 0x24DB,
  23116. lcircumflexbelow: 0x1E3D,
  23117. lcommaaccent: 0x013C,
  23118. ldot: 0x0140,
  23119. ldotaccent: 0x0140,
  23120. ldotbelow: 0x1E37,
  23121. ldotbelowmacron: 0x1E39,
  23122. leftangleabovecmb: 0x031A,
  23123. lefttackbelowcmb: 0x0318,
  23124. less: 0x003C,
  23125. lessequal: 0x2264,
  23126. lessequalorgreater: 0x22DA,
  23127. lessmonospace: 0xFF1C,
  23128. lessorequivalent: 0x2272,
  23129. lessorgreater: 0x2276,
  23130. lessoverequal: 0x2266,
  23131. lesssmall: 0xFE64,
  23132. lezh: 0x026E,
  23133. lfblock: 0x258C,
  23134. lhookretroflex: 0x026D,
  23135. lira: 0x20A4,
  23136. liwnarmenian: 0x056C,
  23137. lj: 0x01C9,
  23138. ljecyrillic: 0x0459,
  23139. ll: 0xF6C0,
  23140. lladeva: 0x0933,
  23141. llagujarati: 0x0AB3,
  23142. llinebelow: 0x1E3B,
  23143. llladeva: 0x0934,
  23144. llvocalicbengali: 0x09E1,
  23145. llvocalicdeva: 0x0961,
  23146. llvocalicvowelsignbengali: 0x09E3,
  23147. llvocalicvowelsigndeva: 0x0963,
  23148. lmiddletilde: 0x026B,
  23149. lmonospace: 0xFF4C,
  23150. lmsquare: 0x33D0,
  23151. lochulathai: 0x0E2C,
  23152. logicaland: 0x2227,
  23153. logicalnot: 0x00AC,
  23154. logicalnotreversed: 0x2310,
  23155. logicalor: 0x2228,
  23156. lolingthai: 0x0E25,
  23157. longs: 0x017F,
  23158. lowlinecenterline: 0xFE4E,
  23159. lowlinecmb: 0x0332,
  23160. lowlinedashed: 0xFE4D,
  23161. lozenge: 0x25CA,
  23162. lparen: 0x24A7,
  23163. lslash: 0x0142,
  23164. lsquare: 0x2113,
  23165. lsuperior: 0xF6EE,
  23166. ltshade: 0x2591,
  23167. luthai: 0x0E26,
  23168. lvocalicbengali: 0x098C,
  23169. lvocalicdeva: 0x090C,
  23170. lvocalicvowelsignbengali: 0x09E2,
  23171. lvocalicvowelsigndeva: 0x0962,
  23172. lxsquare: 0x33D3,
  23173. m: 0x006D,
  23174. mabengali: 0x09AE,
  23175. macron: 0x00AF,
  23176. macronbelowcmb: 0x0331,
  23177. macroncmb: 0x0304,
  23178. macronlowmod: 0x02CD,
  23179. macronmonospace: 0xFFE3,
  23180. macute: 0x1E3F,
  23181. madeva: 0x092E,
  23182. magujarati: 0x0AAE,
  23183. magurmukhi: 0x0A2E,
  23184. mahapakhhebrew: 0x05A4,
  23185. mahapakhlefthebrew: 0x05A4,
  23186. mahiragana: 0x307E,
  23187. maichattawalowleftthai: 0xF895,
  23188. maichattawalowrightthai: 0xF894,
  23189. maichattawathai: 0x0E4B,
  23190. maichattawaupperleftthai: 0xF893,
  23191. maieklowleftthai: 0xF88C,
  23192. maieklowrightthai: 0xF88B,
  23193. maiekthai: 0x0E48,
  23194. maiekupperleftthai: 0xF88A,
  23195. maihanakatleftthai: 0xF884,
  23196. maihanakatthai: 0x0E31,
  23197. maitaikhuleftthai: 0xF889,
  23198. maitaikhuthai: 0x0E47,
  23199. maitholowleftthai: 0xF88F,
  23200. maitholowrightthai: 0xF88E,
  23201. maithothai: 0x0E49,
  23202. maithoupperleftthai: 0xF88D,
  23203. maitrilowleftthai: 0xF892,
  23204. maitrilowrightthai: 0xF891,
  23205. maitrithai: 0x0E4A,
  23206. maitriupperleftthai: 0xF890,
  23207. maiyamokthai: 0x0E46,
  23208. makatakana: 0x30DE,
  23209. makatakanahalfwidth: 0xFF8F,
  23210. male: 0x2642,
  23211. mansyonsquare: 0x3347,
  23212. maqafhebrew: 0x05BE,
  23213. mars: 0x2642,
  23214. masoracirclehebrew: 0x05AF,
  23215. masquare: 0x3383,
  23216. mbopomofo: 0x3107,
  23217. mbsquare: 0x33D4,
  23218. mcircle: 0x24DC,
  23219. mcubedsquare: 0x33A5,
  23220. mdotaccent: 0x1E41,
  23221. mdotbelow: 0x1E43,
  23222. meemarabic: 0x0645,
  23223. meemfinalarabic: 0xFEE2,
  23224. meeminitialarabic: 0xFEE3,
  23225. meemmedialarabic: 0xFEE4,
  23226. meemmeeminitialarabic: 0xFCD1,
  23227. meemmeemisolatedarabic: 0xFC48,
  23228. meetorusquare: 0x334D,
  23229. mehiragana: 0x3081,
  23230. meizierasquare: 0x337E,
  23231. mekatakana: 0x30E1,
  23232. mekatakanahalfwidth: 0xFF92,
  23233. mem: 0x05DE,
  23234. memdagesh: 0xFB3E,
  23235. memdageshhebrew: 0xFB3E,
  23236. memhebrew: 0x05DE,
  23237. menarmenian: 0x0574,
  23238. merkhahebrew: 0x05A5,
  23239. merkhakefulahebrew: 0x05A6,
  23240. merkhakefulalefthebrew: 0x05A6,
  23241. merkhalefthebrew: 0x05A5,
  23242. mhook: 0x0271,
  23243. mhzsquare: 0x3392,
  23244. middledotkatakanahalfwidth: 0xFF65,
  23245. middot: 0x00B7,
  23246. mieumacirclekorean: 0x3272,
  23247. mieumaparenkorean: 0x3212,
  23248. mieumcirclekorean: 0x3264,
  23249. mieumkorean: 0x3141,
  23250. mieumpansioskorean: 0x3170,
  23251. mieumparenkorean: 0x3204,
  23252. mieumpieupkorean: 0x316E,
  23253. mieumsioskorean: 0x316F,
  23254. mihiragana: 0x307F,
  23255. mikatakana: 0x30DF,
  23256. mikatakanahalfwidth: 0xFF90,
  23257. minus: 0x2212,
  23258. minusbelowcmb: 0x0320,
  23259. minuscircle: 0x2296,
  23260. minusmod: 0x02D7,
  23261. minusplus: 0x2213,
  23262. minute: 0x2032,
  23263. miribaarusquare: 0x334A,
  23264. mirisquare: 0x3349,
  23265. mlonglegturned: 0x0270,
  23266. mlsquare: 0x3396,
  23267. mmcubedsquare: 0x33A3,
  23268. mmonospace: 0xFF4D,
  23269. mmsquaredsquare: 0x339F,
  23270. mohiragana: 0x3082,
  23271. mohmsquare: 0x33C1,
  23272. mokatakana: 0x30E2,
  23273. mokatakanahalfwidth: 0xFF93,
  23274. molsquare: 0x33D6,
  23275. momathai: 0x0E21,
  23276. moverssquare: 0x33A7,
  23277. moverssquaredsquare: 0x33A8,
  23278. mparen: 0x24A8,
  23279. mpasquare: 0x33AB,
  23280. mssquare: 0x33B3,
  23281. msuperior: 0xF6EF,
  23282. mturned: 0x026F,
  23283. mu: 0x00B5,
  23284. mu1: 0x00B5,
  23285. muasquare: 0x3382,
  23286. muchgreater: 0x226B,
  23287. muchless: 0x226A,
  23288. mufsquare: 0x338C,
  23289. mugreek: 0x03BC,
  23290. mugsquare: 0x338D,
  23291. muhiragana: 0x3080,
  23292. mukatakana: 0x30E0,
  23293. mukatakanahalfwidth: 0xFF91,
  23294. mulsquare: 0x3395,
  23295. multiply: 0x00D7,
  23296. mumsquare: 0x339B,
  23297. munahhebrew: 0x05A3,
  23298. munahlefthebrew: 0x05A3,
  23299. musicalnote: 0x266A,
  23300. musicalnotedbl: 0x266B,
  23301. musicflatsign: 0x266D,
  23302. musicsharpsign: 0x266F,
  23303. mussquare: 0x33B2,
  23304. muvsquare: 0x33B6,
  23305. muwsquare: 0x33BC,
  23306. mvmegasquare: 0x33B9,
  23307. mvsquare: 0x33B7,
  23308. mwmegasquare: 0x33BF,
  23309. mwsquare: 0x33BD,
  23310. n: 0x006E,
  23311. nabengali: 0x09A8,
  23312. nabla: 0x2207,
  23313. nacute: 0x0144,
  23314. nadeva: 0x0928,
  23315. nagujarati: 0x0AA8,
  23316. nagurmukhi: 0x0A28,
  23317. nahiragana: 0x306A,
  23318. nakatakana: 0x30CA,
  23319. nakatakanahalfwidth: 0xFF85,
  23320. napostrophe: 0x0149,
  23321. nasquare: 0x3381,
  23322. nbopomofo: 0x310B,
  23323. nbspace: 0x00A0,
  23324. ncaron: 0x0148,
  23325. ncedilla: 0x0146,
  23326. ncircle: 0x24DD,
  23327. ncircumflexbelow: 0x1E4B,
  23328. ncommaaccent: 0x0146,
  23329. ndotaccent: 0x1E45,
  23330. ndotbelow: 0x1E47,
  23331. nehiragana: 0x306D,
  23332. nekatakana: 0x30CD,
  23333. nekatakanahalfwidth: 0xFF88,
  23334. newsheqelsign: 0x20AA,
  23335. nfsquare: 0x338B,
  23336. ngabengali: 0x0999,
  23337. ngadeva: 0x0919,
  23338. ngagujarati: 0x0A99,
  23339. ngagurmukhi: 0x0A19,
  23340. ngonguthai: 0x0E07,
  23341. nhiragana: 0x3093,
  23342. nhookleft: 0x0272,
  23343. nhookretroflex: 0x0273,
  23344. nieunacirclekorean: 0x326F,
  23345. nieunaparenkorean: 0x320F,
  23346. nieuncieuckorean: 0x3135,
  23347. nieuncirclekorean: 0x3261,
  23348. nieunhieuhkorean: 0x3136,
  23349. nieunkorean: 0x3134,
  23350. nieunpansioskorean: 0x3168,
  23351. nieunparenkorean: 0x3201,
  23352. nieunsioskorean: 0x3167,
  23353. nieuntikeutkorean: 0x3166,
  23354. nihiragana: 0x306B,
  23355. nikatakana: 0x30CB,
  23356. nikatakanahalfwidth: 0xFF86,
  23357. nikhahitleftthai: 0xF899,
  23358. nikhahitthai: 0x0E4D,
  23359. nine: 0x0039,
  23360. ninearabic: 0x0669,
  23361. ninebengali: 0x09EF,
  23362. ninecircle: 0x2468,
  23363. ninecircleinversesansserif: 0x2792,
  23364. ninedeva: 0x096F,
  23365. ninegujarati: 0x0AEF,
  23366. ninegurmukhi: 0x0A6F,
  23367. ninehackarabic: 0x0669,
  23368. ninehangzhou: 0x3029,
  23369. nineideographicparen: 0x3228,
  23370. nineinferior: 0x2089,
  23371. ninemonospace: 0xFF19,
  23372. nineoldstyle: 0xF739,
  23373. nineparen: 0x247C,
  23374. nineperiod: 0x2490,
  23375. ninepersian: 0x06F9,
  23376. nineroman: 0x2178,
  23377. ninesuperior: 0x2079,
  23378. nineteencircle: 0x2472,
  23379. nineteenparen: 0x2486,
  23380. nineteenperiod: 0x249A,
  23381. ninethai: 0x0E59,
  23382. nj: 0x01CC,
  23383. njecyrillic: 0x045A,
  23384. nkatakana: 0x30F3,
  23385. nkatakanahalfwidth: 0xFF9D,
  23386. nlegrightlong: 0x019E,
  23387. nlinebelow: 0x1E49,
  23388. nmonospace: 0xFF4E,
  23389. nmsquare: 0x339A,
  23390. nnabengali: 0x09A3,
  23391. nnadeva: 0x0923,
  23392. nnagujarati: 0x0AA3,
  23393. nnagurmukhi: 0x0A23,
  23394. nnnadeva: 0x0929,
  23395. nohiragana: 0x306E,
  23396. nokatakana: 0x30CE,
  23397. nokatakanahalfwidth: 0xFF89,
  23398. nonbreakingspace: 0x00A0,
  23399. nonenthai: 0x0E13,
  23400. nonuthai: 0x0E19,
  23401. noonarabic: 0x0646,
  23402. noonfinalarabic: 0xFEE6,
  23403. noonghunnaarabic: 0x06BA,
  23404. noonghunnafinalarabic: 0xFB9F,
  23405. nooninitialarabic: 0xFEE7,
  23406. noonjeeminitialarabic: 0xFCD2,
  23407. noonjeemisolatedarabic: 0xFC4B,
  23408. noonmedialarabic: 0xFEE8,
  23409. noonmeeminitialarabic: 0xFCD5,
  23410. noonmeemisolatedarabic: 0xFC4E,
  23411. noonnoonfinalarabic: 0xFC8D,
  23412. notcontains: 0x220C,
  23413. notelement: 0x2209,
  23414. notelementof: 0x2209,
  23415. notequal: 0x2260,
  23416. notgreater: 0x226F,
  23417. notgreaternorequal: 0x2271,
  23418. notgreaternorless: 0x2279,
  23419. notidentical: 0x2262,
  23420. notless: 0x226E,
  23421. notlessnorequal: 0x2270,
  23422. notparallel: 0x2226,
  23423. notprecedes: 0x2280,
  23424. notsubset: 0x2284,
  23425. notsucceeds: 0x2281,
  23426. notsuperset: 0x2285,
  23427. nowarmenian: 0x0576,
  23428. nparen: 0x24A9,
  23429. nssquare: 0x33B1,
  23430. nsuperior: 0x207F,
  23431. ntilde: 0x00F1,
  23432. nu: 0x03BD,
  23433. nuhiragana: 0x306C,
  23434. nukatakana: 0x30CC,
  23435. nukatakanahalfwidth: 0xFF87,
  23436. nuktabengali: 0x09BC,
  23437. nuktadeva: 0x093C,
  23438. nuktagujarati: 0x0ABC,
  23439. nuktagurmukhi: 0x0A3C,
  23440. numbersign: 0x0023,
  23441. numbersignmonospace: 0xFF03,
  23442. numbersignsmall: 0xFE5F,
  23443. numeralsigngreek: 0x0374,
  23444. numeralsignlowergreek: 0x0375,
  23445. numero: 0x2116,
  23446. nun: 0x05E0,
  23447. nundagesh: 0xFB40,
  23448. nundageshhebrew: 0xFB40,
  23449. nunhebrew: 0x05E0,
  23450. nvsquare: 0x33B5,
  23451. nwsquare: 0x33BB,
  23452. nyabengali: 0x099E,
  23453. nyadeva: 0x091E,
  23454. nyagujarati: 0x0A9E,
  23455. nyagurmukhi: 0x0A1E,
  23456. o: 0x006F,
  23457. oacute: 0x00F3,
  23458. oangthai: 0x0E2D,
  23459. obarred: 0x0275,
  23460. obarredcyrillic: 0x04E9,
  23461. obarreddieresiscyrillic: 0x04EB,
  23462. obengali: 0x0993,
  23463. obopomofo: 0x311B,
  23464. obreve: 0x014F,
  23465. ocandradeva: 0x0911,
  23466. ocandragujarati: 0x0A91,
  23467. ocandravowelsigndeva: 0x0949,
  23468. ocandravowelsigngujarati: 0x0AC9,
  23469. ocaron: 0x01D2,
  23470. ocircle: 0x24DE,
  23471. ocircumflex: 0x00F4,
  23472. ocircumflexacute: 0x1ED1,
  23473. ocircumflexdotbelow: 0x1ED9,
  23474. ocircumflexgrave: 0x1ED3,
  23475. ocircumflexhookabove: 0x1ED5,
  23476. ocircumflextilde: 0x1ED7,
  23477. ocyrillic: 0x043E,
  23478. odblacute: 0x0151,
  23479. odblgrave: 0x020D,
  23480. odeva: 0x0913,
  23481. odieresis: 0x00F6,
  23482. odieresiscyrillic: 0x04E7,
  23483. odotbelow: 0x1ECD,
  23484. oe: 0x0153,
  23485. oekorean: 0x315A,
  23486. ogonek: 0x02DB,
  23487. ogonekcmb: 0x0328,
  23488. ograve: 0x00F2,
  23489. ogujarati: 0x0A93,
  23490. oharmenian: 0x0585,
  23491. ohiragana: 0x304A,
  23492. ohookabove: 0x1ECF,
  23493. ohorn: 0x01A1,
  23494. ohornacute: 0x1EDB,
  23495. ohorndotbelow: 0x1EE3,
  23496. ohorngrave: 0x1EDD,
  23497. ohornhookabove: 0x1EDF,
  23498. ohorntilde: 0x1EE1,
  23499. ohungarumlaut: 0x0151,
  23500. oi: 0x01A3,
  23501. oinvertedbreve: 0x020F,
  23502. okatakana: 0x30AA,
  23503. okatakanahalfwidth: 0xFF75,
  23504. okorean: 0x3157,
  23505. olehebrew: 0x05AB,
  23506. omacron: 0x014D,
  23507. omacronacute: 0x1E53,
  23508. omacrongrave: 0x1E51,
  23509. omdeva: 0x0950,
  23510. omega: 0x03C9,
  23511. omega1: 0x03D6,
  23512. omegacyrillic: 0x0461,
  23513. omegalatinclosed: 0x0277,
  23514. omegaroundcyrillic: 0x047B,
  23515. omegatitlocyrillic: 0x047D,
  23516. omegatonos: 0x03CE,
  23517. omgujarati: 0x0AD0,
  23518. omicron: 0x03BF,
  23519. omicrontonos: 0x03CC,
  23520. omonospace: 0xFF4F,
  23521. one: 0x0031,
  23522. onearabic: 0x0661,
  23523. onebengali: 0x09E7,
  23524. onecircle: 0x2460,
  23525. onecircleinversesansserif: 0x278A,
  23526. onedeva: 0x0967,
  23527. onedotenleader: 0x2024,
  23528. oneeighth: 0x215B,
  23529. onefitted: 0xF6DC,
  23530. onegujarati: 0x0AE7,
  23531. onegurmukhi: 0x0A67,
  23532. onehackarabic: 0x0661,
  23533. onehalf: 0x00BD,
  23534. onehangzhou: 0x3021,
  23535. oneideographicparen: 0x3220,
  23536. oneinferior: 0x2081,
  23537. onemonospace: 0xFF11,
  23538. onenumeratorbengali: 0x09F4,
  23539. oneoldstyle: 0xF731,
  23540. oneparen: 0x2474,
  23541. oneperiod: 0x2488,
  23542. onepersian: 0x06F1,
  23543. onequarter: 0x00BC,
  23544. oneroman: 0x2170,
  23545. onesuperior: 0x00B9,
  23546. onethai: 0x0E51,
  23547. onethird: 0x2153,
  23548. oogonek: 0x01EB,
  23549. oogonekmacron: 0x01ED,
  23550. oogurmukhi: 0x0A13,
  23551. oomatragurmukhi: 0x0A4B,
  23552. oopen: 0x0254,
  23553. oparen: 0x24AA,
  23554. openbullet: 0x25E6,
  23555. option: 0x2325,
  23556. ordfeminine: 0x00AA,
  23557. ordmasculine: 0x00BA,
  23558. orthogonal: 0x221F,
  23559. oshortdeva: 0x0912,
  23560. oshortvowelsigndeva: 0x094A,
  23561. oslash: 0x00F8,
  23562. oslashacute: 0x01FF,
  23563. osmallhiragana: 0x3049,
  23564. osmallkatakana: 0x30A9,
  23565. osmallkatakanahalfwidth: 0xFF6B,
  23566. ostrokeacute: 0x01FF,
  23567. osuperior: 0xF6F0,
  23568. otcyrillic: 0x047F,
  23569. otilde: 0x00F5,
  23570. otildeacute: 0x1E4D,
  23571. otildedieresis: 0x1E4F,
  23572. oubopomofo: 0x3121,
  23573. overline: 0x203E,
  23574. overlinecenterline: 0xFE4A,
  23575. overlinecmb: 0x0305,
  23576. overlinedashed: 0xFE49,
  23577. overlinedblwavy: 0xFE4C,
  23578. overlinewavy: 0xFE4B,
  23579. overscore: 0x00AF,
  23580. ovowelsignbengali: 0x09CB,
  23581. ovowelsigndeva: 0x094B,
  23582. ovowelsigngujarati: 0x0ACB,
  23583. p: 0x0070,
  23584. paampssquare: 0x3380,
  23585. paasentosquare: 0x332B,
  23586. pabengali: 0x09AA,
  23587. pacute: 0x1E55,
  23588. padeva: 0x092A,
  23589. pagedown: 0x21DF,
  23590. pageup: 0x21DE,
  23591. pagujarati: 0x0AAA,
  23592. pagurmukhi: 0x0A2A,
  23593. pahiragana: 0x3071,
  23594. paiyannoithai: 0x0E2F,
  23595. pakatakana: 0x30D1,
  23596. palatalizationcyrilliccmb: 0x0484,
  23597. palochkacyrillic: 0x04C0,
  23598. pansioskorean: 0x317F,
  23599. paragraph: 0x00B6,
  23600. parallel: 0x2225,
  23601. parenleft: 0x0028,
  23602. parenleftaltonearabic: 0xFD3E,
  23603. parenleftbt: 0xF8ED,
  23604. parenleftex: 0xF8EC,
  23605. parenleftinferior: 0x208D,
  23606. parenleftmonospace: 0xFF08,
  23607. parenleftsmall: 0xFE59,
  23608. parenleftsuperior: 0x207D,
  23609. parenlefttp: 0xF8EB,
  23610. parenleftvertical: 0xFE35,
  23611. parenright: 0x0029,
  23612. parenrightaltonearabic: 0xFD3F,
  23613. parenrightbt: 0xF8F8,
  23614. parenrightex: 0xF8F7,
  23615. parenrightinferior: 0x208E,
  23616. parenrightmonospace: 0xFF09,
  23617. parenrightsmall: 0xFE5A,
  23618. parenrightsuperior: 0x207E,
  23619. parenrighttp: 0xF8F6,
  23620. parenrightvertical: 0xFE36,
  23621. partialdiff: 0x2202,
  23622. paseqhebrew: 0x05C0,
  23623. pashtahebrew: 0x0599,
  23624. pasquare: 0x33A9,
  23625. patah: 0x05B7,
  23626. patah11: 0x05B7,
  23627. patah1d: 0x05B7,
  23628. patah2a: 0x05B7,
  23629. patahhebrew: 0x05B7,
  23630. patahnarrowhebrew: 0x05B7,
  23631. patahquarterhebrew: 0x05B7,
  23632. patahwidehebrew: 0x05B7,
  23633. pazerhebrew: 0x05A1,
  23634. pbopomofo: 0x3106,
  23635. pcircle: 0x24DF,
  23636. pdotaccent: 0x1E57,
  23637. pe: 0x05E4,
  23638. pecyrillic: 0x043F,
  23639. pedagesh: 0xFB44,
  23640. pedageshhebrew: 0xFB44,
  23641. peezisquare: 0x333B,
  23642. pefinaldageshhebrew: 0xFB43,
  23643. peharabic: 0x067E,
  23644. peharmenian: 0x057A,
  23645. pehebrew: 0x05E4,
  23646. pehfinalarabic: 0xFB57,
  23647. pehinitialarabic: 0xFB58,
  23648. pehiragana: 0x307A,
  23649. pehmedialarabic: 0xFB59,
  23650. pekatakana: 0x30DA,
  23651. pemiddlehookcyrillic: 0x04A7,
  23652. perafehebrew: 0xFB4E,
  23653. percent: 0x0025,
  23654. percentarabic: 0x066A,
  23655. percentmonospace: 0xFF05,
  23656. percentsmall: 0xFE6A,
  23657. period: 0x002E,
  23658. periodarmenian: 0x0589,
  23659. periodcentered: 0x00B7,
  23660. periodhalfwidth: 0xFF61,
  23661. periodinferior: 0xF6E7,
  23662. periodmonospace: 0xFF0E,
  23663. periodsmall: 0xFE52,
  23664. periodsuperior: 0xF6E8,
  23665. perispomenigreekcmb: 0x0342,
  23666. perpendicular: 0x22A5,
  23667. perthousand: 0x2030,
  23668. peseta: 0x20A7,
  23669. pfsquare: 0x338A,
  23670. phabengali: 0x09AB,
  23671. phadeva: 0x092B,
  23672. phagujarati: 0x0AAB,
  23673. phagurmukhi: 0x0A2B,
  23674. phi: 0x03C6,
  23675. phi1: 0x03D5,
  23676. phieuphacirclekorean: 0x327A,
  23677. phieuphaparenkorean: 0x321A,
  23678. phieuphcirclekorean: 0x326C,
  23679. phieuphkorean: 0x314D,
  23680. phieuphparenkorean: 0x320C,
  23681. philatin: 0x0278,
  23682. phinthuthai: 0x0E3A,
  23683. phisymbolgreek: 0x03D5,
  23684. phook: 0x01A5,
  23685. phophanthai: 0x0E1E,
  23686. phophungthai: 0x0E1C,
  23687. phosamphaothai: 0x0E20,
  23688. pi: 0x03C0,
  23689. pieupacirclekorean: 0x3273,
  23690. pieupaparenkorean: 0x3213,
  23691. pieupcieuckorean: 0x3176,
  23692. pieupcirclekorean: 0x3265,
  23693. pieupkiyeokkorean: 0x3172,
  23694. pieupkorean: 0x3142,
  23695. pieupparenkorean: 0x3205,
  23696. pieupsioskiyeokkorean: 0x3174,
  23697. pieupsioskorean: 0x3144,
  23698. pieupsiostikeutkorean: 0x3175,
  23699. pieupthieuthkorean: 0x3177,
  23700. pieuptikeutkorean: 0x3173,
  23701. pihiragana: 0x3074,
  23702. pikatakana: 0x30D4,
  23703. pisymbolgreek: 0x03D6,
  23704. piwrarmenian: 0x0583,
  23705. plus: 0x002B,
  23706. plusbelowcmb: 0x031F,
  23707. pluscircle: 0x2295,
  23708. plusminus: 0x00B1,
  23709. plusmod: 0x02D6,
  23710. plusmonospace: 0xFF0B,
  23711. plussmall: 0xFE62,
  23712. plussuperior: 0x207A,
  23713. pmonospace: 0xFF50,
  23714. pmsquare: 0x33D8,
  23715. pohiragana: 0x307D,
  23716. pointingindexdownwhite: 0x261F,
  23717. pointingindexleftwhite: 0x261C,
  23718. pointingindexrightwhite: 0x261E,
  23719. pointingindexupwhite: 0x261D,
  23720. pokatakana: 0x30DD,
  23721. poplathai: 0x0E1B,
  23722. postalmark: 0x3012,
  23723. postalmarkface: 0x3020,
  23724. pparen: 0x24AB,
  23725. precedes: 0x227A,
  23726. prescription: 0x211E,
  23727. primemod: 0x02B9,
  23728. primereversed: 0x2035,
  23729. product: 0x220F,
  23730. projective: 0x2305,
  23731. prolongedkana: 0x30FC,
  23732. propellor: 0x2318,
  23733. propersubset: 0x2282,
  23734. propersuperset: 0x2283,
  23735. proportion: 0x2237,
  23736. proportional: 0x221D,
  23737. psi: 0x03C8,
  23738. psicyrillic: 0x0471,
  23739. psilipneumatacyrilliccmb: 0x0486,
  23740. pssquare: 0x33B0,
  23741. puhiragana: 0x3077,
  23742. pukatakana: 0x30D7,
  23743. pvsquare: 0x33B4,
  23744. pwsquare: 0x33BA,
  23745. q: 0x0071,
  23746. qadeva: 0x0958,
  23747. qadmahebrew: 0x05A8,
  23748. qafarabic: 0x0642,
  23749. qaffinalarabic: 0xFED6,
  23750. qafinitialarabic: 0xFED7,
  23751. qafmedialarabic: 0xFED8,
  23752. qamats: 0x05B8,
  23753. qamats10: 0x05B8,
  23754. qamats1a: 0x05B8,
  23755. qamats1c: 0x05B8,
  23756. qamats27: 0x05B8,
  23757. qamats29: 0x05B8,
  23758. qamats33: 0x05B8,
  23759. qamatsde: 0x05B8,
  23760. qamatshebrew: 0x05B8,
  23761. qamatsnarrowhebrew: 0x05B8,
  23762. qamatsqatanhebrew: 0x05B8,
  23763. qamatsqatannarrowhebrew: 0x05B8,
  23764. qamatsqatanquarterhebrew: 0x05B8,
  23765. qamatsqatanwidehebrew: 0x05B8,
  23766. qamatsquarterhebrew: 0x05B8,
  23767. qamatswidehebrew: 0x05B8,
  23768. qarneyparahebrew: 0x059F,
  23769. qbopomofo: 0x3111,
  23770. qcircle: 0x24E0,
  23771. qhook: 0x02A0,
  23772. qmonospace: 0xFF51,
  23773. qof: 0x05E7,
  23774. qofdagesh: 0xFB47,
  23775. qofdageshhebrew: 0xFB47,
  23776. qofhebrew: 0x05E7,
  23777. qparen: 0x24AC,
  23778. quarternote: 0x2669,
  23779. qubuts: 0x05BB,
  23780. qubuts18: 0x05BB,
  23781. qubuts25: 0x05BB,
  23782. qubuts31: 0x05BB,
  23783. qubutshebrew: 0x05BB,
  23784. qubutsnarrowhebrew: 0x05BB,
  23785. qubutsquarterhebrew: 0x05BB,
  23786. qubutswidehebrew: 0x05BB,
  23787. question: 0x003F,
  23788. questionarabic: 0x061F,
  23789. questionarmenian: 0x055E,
  23790. questiondown: 0x00BF,
  23791. questiondownsmall: 0xF7BF,
  23792. questiongreek: 0x037E,
  23793. questionmonospace: 0xFF1F,
  23794. questionsmall: 0xF73F,
  23795. quotedbl: 0x0022,
  23796. quotedblbase: 0x201E,
  23797. quotedblleft: 0x201C,
  23798. quotedblmonospace: 0xFF02,
  23799. quotedblprime: 0x301E,
  23800. quotedblprimereversed: 0x301D,
  23801. quotedblright: 0x201D,
  23802. quoteleft: 0x2018,
  23803. quoteleftreversed: 0x201B,
  23804. quotereversed: 0x201B,
  23805. quoteright: 0x2019,
  23806. quoterightn: 0x0149,
  23807. quotesinglbase: 0x201A,
  23808. quotesingle: 0x0027,
  23809. quotesinglemonospace: 0xFF07,
  23810. r: 0x0072,
  23811. raarmenian: 0x057C,
  23812. rabengali: 0x09B0,
  23813. racute: 0x0155,
  23814. radeva: 0x0930,
  23815. radical: 0x221A,
  23816. radicalex: 0xF8E5,
  23817. radoverssquare: 0x33AE,
  23818. radoverssquaredsquare: 0x33AF,
  23819. radsquare: 0x33AD,
  23820. rafe: 0x05BF,
  23821. rafehebrew: 0x05BF,
  23822. ragujarati: 0x0AB0,
  23823. ragurmukhi: 0x0A30,
  23824. rahiragana: 0x3089,
  23825. rakatakana: 0x30E9,
  23826. rakatakanahalfwidth: 0xFF97,
  23827. ralowerdiagonalbengali: 0x09F1,
  23828. ramiddlediagonalbengali: 0x09F0,
  23829. ramshorn: 0x0264,
  23830. ratio: 0x2236,
  23831. rbopomofo: 0x3116,
  23832. rcaron: 0x0159,
  23833. rcedilla: 0x0157,
  23834. rcircle: 0x24E1,
  23835. rcommaaccent: 0x0157,
  23836. rdblgrave: 0x0211,
  23837. rdotaccent: 0x1E59,
  23838. rdotbelow: 0x1E5B,
  23839. rdotbelowmacron: 0x1E5D,
  23840. referencemark: 0x203B,
  23841. reflexsubset: 0x2286,
  23842. reflexsuperset: 0x2287,
  23843. registered: 0x00AE,
  23844. registersans: 0xF8E8,
  23845. registerserif: 0xF6DA,
  23846. reharabic: 0x0631,
  23847. reharmenian: 0x0580,
  23848. rehfinalarabic: 0xFEAE,
  23849. rehiragana: 0x308C,
  23850. rekatakana: 0x30EC,
  23851. rekatakanahalfwidth: 0xFF9A,
  23852. resh: 0x05E8,
  23853. reshdageshhebrew: 0xFB48,
  23854. reshhebrew: 0x05E8,
  23855. reversedtilde: 0x223D,
  23856. reviahebrew: 0x0597,
  23857. reviamugrashhebrew: 0x0597,
  23858. revlogicalnot: 0x2310,
  23859. rfishhook: 0x027E,
  23860. rfishhookreversed: 0x027F,
  23861. rhabengali: 0x09DD,
  23862. rhadeva: 0x095D,
  23863. rho: 0x03C1,
  23864. rhook: 0x027D,
  23865. rhookturned: 0x027B,
  23866. rhookturnedsuperior: 0x02B5,
  23867. rhosymbolgreek: 0x03F1,
  23868. rhotichookmod: 0x02DE,
  23869. rieulacirclekorean: 0x3271,
  23870. rieulaparenkorean: 0x3211,
  23871. rieulcirclekorean: 0x3263,
  23872. rieulhieuhkorean: 0x3140,
  23873. rieulkiyeokkorean: 0x313A,
  23874. rieulkiyeoksioskorean: 0x3169,
  23875. rieulkorean: 0x3139,
  23876. rieulmieumkorean: 0x313B,
  23877. rieulpansioskorean: 0x316C,
  23878. rieulparenkorean: 0x3203,
  23879. rieulphieuphkorean: 0x313F,
  23880. rieulpieupkorean: 0x313C,
  23881. rieulpieupsioskorean: 0x316B,
  23882. rieulsioskorean: 0x313D,
  23883. rieulthieuthkorean: 0x313E,
  23884. rieultikeutkorean: 0x316A,
  23885. rieulyeorinhieuhkorean: 0x316D,
  23886. rightangle: 0x221F,
  23887. righttackbelowcmb: 0x0319,
  23888. righttriangle: 0x22BF,
  23889. rihiragana: 0x308A,
  23890. rikatakana: 0x30EA,
  23891. rikatakanahalfwidth: 0xFF98,
  23892. ring: 0x02DA,
  23893. ringbelowcmb: 0x0325,
  23894. ringcmb: 0x030A,
  23895. ringhalfleft: 0x02BF,
  23896. ringhalfleftarmenian: 0x0559,
  23897. ringhalfleftbelowcmb: 0x031C,
  23898. ringhalfleftcentered: 0x02D3,
  23899. ringhalfright: 0x02BE,
  23900. ringhalfrightbelowcmb: 0x0339,
  23901. ringhalfrightcentered: 0x02D2,
  23902. rinvertedbreve: 0x0213,
  23903. rittorusquare: 0x3351,
  23904. rlinebelow: 0x1E5F,
  23905. rlongleg: 0x027C,
  23906. rlonglegturned: 0x027A,
  23907. rmonospace: 0xFF52,
  23908. rohiragana: 0x308D,
  23909. rokatakana: 0x30ED,
  23910. rokatakanahalfwidth: 0xFF9B,
  23911. roruathai: 0x0E23,
  23912. rparen: 0x24AD,
  23913. rrabengali: 0x09DC,
  23914. rradeva: 0x0931,
  23915. rragurmukhi: 0x0A5C,
  23916. rreharabic: 0x0691,
  23917. rrehfinalarabic: 0xFB8D,
  23918. rrvocalicbengali: 0x09E0,
  23919. rrvocalicdeva: 0x0960,
  23920. rrvocalicgujarati: 0x0AE0,
  23921. rrvocalicvowelsignbengali: 0x09C4,
  23922. rrvocalicvowelsigndeva: 0x0944,
  23923. rrvocalicvowelsigngujarati: 0x0AC4,
  23924. rsuperior: 0xF6F1,
  23925. rtblock: 0x2590,
  23926. rturned: 0x0279,
  23927. rturnedsuperior: 0x02B4,
  23928. ruhiragana: 0x308B,
  23929. rukatakana: 0x30EB,
  23930. rukatakanahalfwidth: 0xFF99,
  23931. rupeemarkbengali: 0x09F2,
  23932. rupeesignbengali: 0x09F3,
  23933. rupiah: 0xF6DD,
  23934. ruthai: 0x0E24,
  23935. rvocalicbengali: 0x098B,
  23936. rvocalicdeva: 0x090B,
  23937. rvocalicgujarati: 0x0A8B,
  23938. rvocalicvowelsignbengali: 0x09C3,
  23939. rvocalicvowelsigndeva: 0x0943,
  23940. rvocalicvowelsigngujarati: 0x0AC3,
  23941. s: 0x0073,
  23942. sabengali: 0x09B8,
  23943. sacute: 0x015B,
  23944. sacutedotaccent: 0x1E65,
  23945. sadarabic: 0x0635,
  23946. sadeva: 0x0938,
  23947. sadfinalarabic: 0xFEBA,
  23948. sadinitialarabic: 0xFEBB,
  23949. sadmedialarabic: 0xFEBC,
  23950. sagujarati: 0x0AB8,
  23951. sagurmukhi: 0x0A38,
  23952. sahiragana: 0x3055,
  23953. sakatakana: 0x30B5,
  23954. sakatakanahalfwidth: 0xFF7B,
  23955. sallallahoualayhewasallamarabic: 0xFDFA,
  23956. samekh: 0x05E1,
  23957. samekhdagesh: 0xFB41,
  23958. samekhdageshhebrew: 0xFB41,
  23959. samekhhebrew: 0x05E1,
  23960. saraaathai: 0x0E32,
  23961. saraaethai: 0x0E41,
  23962. saraaimaimalaithai: 0x0E44,
  23963. saraaimaimuanthai: 0x0E43,
  23964. saraamthai: 0x0E33,
  23965. saraathai: 0x0E30,
  23966. saraethai: 0x0E40,
  23967. saraiileftthai: 0xF886,
  23968. saraiithai: 0x0E35,
  23969. saraileftthai: 0xF885,
  23970. saraithai: 0x0E34,
  23971. saraothai: 0x0E42,
  23972. saraueeleftthai: 0xF888,
  23973. saraueethai: 0x0E37,
  23974. saraueleftthai: 0xF887,
  23975. sarauethai: 0x0E36,
  23976. sarauthai: 0x0E38,
  23977. sarauuthai: 0x0E39,
  23978. sbopomofo: 0x3119,
  23979. scaron: 0x0161,
  23980. scarondotaccent: 0x1E67,
  23981. scedilla: 0x015F,
  23982. schwa: 0x0259,
  23983. schwacyrillic: 0x04D9,
  23984. schwadieresiscyrillic: 0x04DB,
  23985. schwahook: 0x025A,
  23986. scircle: 0x24E2,
  23987. scircumflex: 0x015D,
  23988. scommaaccent: 0x0219,
  23989. sdotaccent: 0x1E61,
  23990. sdotbelow: 0x1E63,
  23991. sdotbelowdotaccent: 0x1E69,
  23992. seagullbelowcmb: 0x033C,
  23993. second: 0x2033,
  23994. secondtonechinese: 0x02CA,
  23995. section: 0x00A7,
  23996. seenarabic: 0x0633,
  23997. seenfinalarabic: 0xFEB2,
  23998. seeninitialarabic: 0xFEB3,
  23999. seenmedialarabic: 0xFEB4,
  24000. segol: 0x05B6,
  24001. segol13: 0x05B6,
  24002. segol1f: 0x05B6,
  24003. segol2c: 0x05B6,
  24004. segolhebrew: 0x05B6,
  24005. segolnarrowhebrew: 0x05B6,
  24006. segolquarterhebrew: 0x05B6,
  24007. segoltahebrew: 0x0592,
  24008. segolwidehebrew: 0x05B6,
  24009. seharmenian: 0x057D,
  24010. sehiragana: 0x305B,
  24011. sekatakana: 0x30BB,
  24012. sekatakanahalfwidth: 0xFF7E,
  24013. semicolon: 0x003B,
  24014. semicolonarabic: 0x061B,
  24015. semicolonmonospace: 0xFF1B,
  24016. semicolonsmall: 0xFE54,
  24017. semivoicedmarkkana: 0x309C,
  24018. semivoicedmarkkanahalfwidth: 0xFF9F,
  24019. sentisquare: 0x3322,
  24020. sentosquare: 0x3323,
  24021. seven: 0x0037,
  24022. sevenarabic: 0x0667,
  24023. sevenbengali: 0x09ED,
  24024. sevencircle: 0x2466,
  24025. sevencircleinversesansserif: 0x2790,
  24026. sevendeva: 0x096D,
  24027. seveneighths: 0x215E,
  24028. sevengujarati: 0x0AED,
  24029. sevengurmukhi: 0x0A6D,
  24030. sevenhackarabic: 0x0667,
  24031. sevenhangzhou: 0x3027,
  24032. sevenideographicparen: 0x3226,
  24033. seveninferior: 0x2087,
  24034. sevenmonospace: 0xFF17,
  24035. sevenoldstyle: 0xF737,
  24036. sevenparen: 0x247A,
  24037. sevenperiod: 0x248E,
  24038. sevenpersian: 0x06F7,
  24039. sevenroman: 0x2176,
  24040. sevensuperior: 0x2077,
  24041. seventeencircle: 0x2470,
  24042. seventeenparen: 0x2484,
  24043. seventeenperiod: 0x2498,
  24044. seventhai: 0x0E57,
  24045. sfthyphen: 0x00AD,
  24046. shaarmenian: 0x0577,
  24047. shabengali: 0x09B6,
  24048. shacyrillic: 0x0448,
  24049. shaddaarabic: 0x0651,
  24050. shaddadammaarabic: 0xFC61,
  24051. shaddadammatanarabic: 0xFC5E,
  24052. shaddafathaarabic: 0xFC60,
  24053. shaddakasraarabic: 0xFC62,
  24054. shaddakasratanarabic: 0xFC5F,
  24055. shade: 0x2592,
  24056. shadedark: 0x2593,
  24057. shadelight: 0x2591,
  24058. shademedium: 0x2592,
  24059. shadeva: 0x0936,
  24060. shagujarati: 0x0AB6,
  24061. shagurmukhi: 0x0A36,
  24062. shalshelethebrew: 0x0593,
  24063. shbopomofo: 0x3115,
  24064. shchacyrillic: 0x0449,
  24065. sheenarabic: 0x0634,
  24066. sheenfinalarabic: 0xFEB6,
  24067. sheeninitialarabic: 0xFEB7,
  24068. sheenmedialarabic: 0xFEB8,
  24069. sheicoptic: 0x03E3,
  24070. sheqel: 0x20AA,
  24071. sheqelhebrew: 0x20AA,
  24072. sheva: 0x05B0,
  24073. sheva115: 0x05B0,
  24074. sheva15: 0x05B0,
  24075. sheva22: 0x05B0,
  24076. sheva2e: 0x05B0,
  24077. shevahebrew: 0x05B0,
  24078. shevanarrowhebrew: 0x05B0,
  24079. shevaquarterhebrew: 0x05B0,
  24080. shevawidehebrew: 0x05B0,
  24081. shhacyrillic: 0x04BB,
  24082. shimacoptic: 0x03ED,
  24083. shin: 0x05E9,
  24084. shindagesh: 0xFB49,
  24085. shindageshhebrew: 0xFB49,
  24086. shindageshshindot: 0xFB2C,
  24087. shindageshshindothebrew: 0xFB2C,
  24088. shindageshsindot: 0xFB2D,
  24089. shindageshsindothebrew: 0xFB2D,
  24090. shindothebrew: 0x05C1,
  24091. shinhebrew: 0x05E9,
  24092. shinshindot: 0xFB2A,
  24093. shinshindothebrew: 0xFB2A,
  24094. shinsindot: 0xFB2B,
  24095. shinsindothebrew: 0xFB2B,
  24096. shook: 0x0282,
  24097. sigma: 0x03C3,
  24098. sigma1: 0x03C2,
  24099. sigmafinal: 0x03C2,
  24100. sigmalunatesymbolgreek: 0x03F2,
  24101. sihiragana: 0x3057,
  24102. sikatakana: 0x30B7,
  24103. sikatakanahalfwidth: 0xFF7C,
  24104. siluqhebrew: 0x05BD,
  24105. siluqlefthebrew: 0x05BD,
  24106. similar: 0x223C,
  24107. sindothebrew: 0x05C2,
  24108. siosacirclekorean: 0x3274,
  24109. siosaparenkorean: 0x3214,
  24110. sioscieuckorean: 0x317E,
  24111. sioscirclekorean: 0x3266,
  24112. sioskiyeokkorean: 0x317A,
  24113. sioskorean: 0x3145,
  24114. siosnieunkorean: 0x317B,
  24115. siosparenkorean: 0x3206,
  24116. siospieupkorean: 0x317D,
  24117. siostikeutkorean: 0x317C,
  24118. six: 0x0036,
  24119. sixarabic: 0x0666,
  24120. sixbengali: 0x09EC,
  24121. sixcircle: 0x2465,
  24122. sixcircleinversesansserif: 0x278F,
  24123. sixdeva: 0x096C,
  24124. sixgujarati: 0x0AEC,
  24125. sixgurmukhi: 0x0A6C,
  24126. sixhackarabic: 0x0666,
  24127. sixhangzhou: 0x3026,
  24128. sixideographicparen: 0x3225,
  24129. sixinferior: 0x2086,
  24130. sixmonospace: 0xFF16,
  24131. sixoldstyle: 0xF736,
  24132. sixparen: 0x2479,
  24133. sixperiod: 0x248D,
  24134. sixpersian: 0x06F6,
  24135. sixroman: 0x2175,
  24136. sixsuperior: 0x2076,
  24137. sixteencircle: 0x246F,
  24138. sixteencurrencydenominatorbengali: 0x09F9,
  24139. sixteenparen: 0x2483,
  24140. sixteenperiod: 0x2497,
  24141. sixthai: 0x0E56,
  24142. slash: 0x002F,
  24143. slashmonospace: 0xFF0F,
  24144. slong: 0x017F,
  24145. slongdotaccent: 0x1E9B,
  24146. smileface: 0x263A,
  24147. smonospace: 0xFF53,
  24148. sofpasuqhebrew: 0x05C3,
  24149. softhyphen: 0x00AD,
  24150. softsigncyrillic: 0x044C,
  24151. sohiragana: 0x305D,
  24152. sokatakana: 0x30BD,
  24153. sokatakanahalfwidth: 0xFF7F,
  24154. soliduslongoverlaycmb: 0x0338,
  24155. solidusshortoverlaycmb: 0x0337,
  24156. sorusithai: 0x0E29,
  24157. sosalathai: 0x0E28,
  24158. sosothai: 0x0E0B,
  24159. sosuathai: 0x0E2A,
  24160. space: 0x0020,
  24161. spacehackarabic: 0x0020,
  24162. spade: 0x2660,
  24163. spadesuitblack: 0x2660,
  24164. spadesuitwhite: 0x2664,
  24165. sparen: 0x24AE,
  24166. squarebelowcmb: 0x033B,
  24167. squarecc: 0x33C4,
  24168. squarecm: 0x339D,
  24169. squarediagonalcrosshatchfill: 0x25A9,
  24170. squarehorizontalfill: 0x25A4,
  24171. squarekg: 0x338F,
  24172. squarekm: 0x339E,
  24173. squarekmcapital: 0x33CE,
  24174. squareln: 0x33D1,
  24175. squarelog: 0x33D2,
  24176. squaremg: 0x338E,
  24177. squaremil: 0x33D5,
  24178. squaremm: 0x339C,
  24179. squaremsquared: 0x33A1,
  24180. squareorthogonalcrosshatchfill: 0x25A6,
  24181. squareupperlefttolowerrightfill: 0x25A7,
  24182. squareupperrighttolowerleftfill: 0x25A8,
  24183. squareverticalfill: 0x25A5,
  24184. squarewhitewithsmallblack: 0x25A3,
  24185. srsquare: 0x33DB,
  24186. ssabengali: 0x09B7,
  24187. ssadeva: 0x0937,
  24188. ssagujarati: 0x0AB7,
  24189. ssangcieuckorean: 0x3149,
  24190. ssanghieuhkorean: 0x3185,
  24191. ssangieungkorean: 0x3180,
  24192. ssangkiyeokkorean: 0x3132,
  24193. ssangnieunkorean: 0x3165,
  24194. ssangpieupkorean: 0x3143,
  24195. ssangsioskorean: 0x3146,
  24196. ssangtikeutkorean: 0x3138,
  24197. ssuperior: 0xF6F2,
  24198. sterling: 0x00A3,
  24199. sterlingmonospace: 0xFFE1,
  24200. strokelongoverlaycmb: 0x0336,
  24201. strokeshortoverlaycmb: 0x0335,
  24202. subset: 0x2282,
  24203. subsetnotequal: 0x228A,
  24204. subsetorequal: 0x2286,
  24205. succeeds: 0x227B,
  24206. suchthat: 0x220B,
  24207. suhiragana: 0x3059,
  24208. sukatakana: 0x30B9,
  24209. sukatakanahalfwidth: 0xFF7D,
  24210. sukunarabic: 0x0652,
  24211. summation: 0x2211,
  24212. sun: 0x263C,
  24213. superset: 0x2283,
  24214. supersetnotequal: 0x228B,
  24215. supersetorequal: 0x2287,
  24216. svsquare: 0x33DC,
  24217. syouwaerasquare: 0x337C,
  24218. t: 0x0074,
  24219. tabengali: 0x09A4,
  24220. tackdown: 0x22A4,
  24221. tackleft: 0x22A3,
  24222. tadeva: 0x0924,
  24223. tagujarati: 0x0AA4,
  24224. tagurmukhi: 0x0A24,
  24225. taharabic: 0x0637,
  24226. tahfinalarabic: 0xFEC2,
  24227. tahinitialarabic: 0xFEC3,
  24228. tahiragana: 0x305F,
  24229. tahmedialarabic: 0xFEC4,
  24230. taisyouerasquare: 0x337D,
  24231. takatakana: 0x30BF,
  24232. takatakanahalfwidth: 0xFF80,
  24233. tatweelarabic: 0x0640,
  24234. tau: 0x03C4,
  24235. tav: 0x05EA,
  24236. tavdages: 0xFB4A,
  24237. tavdagesh: 0xFB4A,
  24238. tavdageshhebrew: 0xFB4A,
  24239. tavhebrew: 0x05EA,
  24240. tbar: 0x0167,
  24241. tbopomofo: 0x310A,
  24242. tcaron: 0x0165,
  24243. tccurl: 0x02A8,
  24244. tcedilla: 0x0163,
  24245. tcheharabic: 0x0686,
  24246. tchehfinalarabic: 0xFB7B,
  24247. tchehinitialarabic: 0xFB7C,
  24248. tchehmedialarabic: 0xFB7D,
  24249. tcircle: 0x24E3,
  24250. tcircumflexbelow: 0x1E71,
  24251. tcommaaccent: 0x0163,
  24252. tdieresis: 0x1E97,
  24253. tdotaccent: 0x1E6B,
  24254. tdotbelow: 0x1E6D,
  24255. tecyrillic: 0x0442,
  24256. tedescendercyrillic: 0x04AD,
  24257. teharabic: 0x062A,
  24258. tehfinalarabic: 0xFE96,
  24259. tehhahinitialarabic: 0xFCA2,
  24260. tehhahisolatedarabic: 0xFC0C,
  24261. tehinitialarabic: 0xFE97,
  24262. tehiragana: 0x3066,
  24263. tehjeeminitialarabic: 0xFCA1,
  24264. tehjeemisolatedarabic: 0xFC0B,
  24265. tehmarbutaarabic: 0x0629,
  24266. tehmarbutafinalarabic: 0xFE94,
  24267. tehmedialarabic: 0xFE98,
  24268. tehmeeminitialarabic: 0xFCA4,
  24269. tehmeemisolatedarabic: 0xFC0E,
  24270. tehnoonfinalarabic: 0xFC73,
  24271. tekatakana: 0x30C6,
  24272. tekatakanahalfwidth: 0xFF83,
  24273. telephone: 0x2121,
  24274. telephoneblack: 0x260E,
  24275. telishagedolahebrew: 0x05A0,
  24276. telishaqetanahebrew: 0x05A9,
  24277. tencircle: 0x2469,
  24278. tenideographicparen: 0x3229,
  24279. tenparen: 0x247D,
  24280. tenperiod: 0x2491,
  24281. tenroman: 0x2179,
  24282. tesh: 0x02A7,
  24283. tet: 0x05D8,
  24284. tetdagesh: 0xFB38,
  24285. tetdageshhebrew: 0xFB38,
  24286. tethebrew: 0x05D8,
  24287. tetsecyrillic: 0x04B5,
  24288. tevirhebrew: 0x059B,
  24289. tevirlefthebrew: 0x059B,
  24290. thabengali: 0x09A5,
  24291. thadeva: 0x0925,
  24292. thagujarati: 0x0AA5,
  24293. thagurmukhi: 0x0A25,
  24294. thalarabic: 0x0630,
  24295. thalfinalarabic: 0xFEAC,
  24296. thanthakhatlowleftthai: 0xF898,
  24297. thanthakhatlowrightthai: 0xF897,
  24298. thanthakhatthai: 0x0E4C,
  24299. thanthakhatupperleftthai: 0xF896,
  24300. theharabic: 0x062B,
  24301. thehfinalarabic: 0xFE9A,
  24302. thehinitialarabic: 0xFE9B,
  24303. thehmedialarabic: 0xFE9C,
  24304. thereexists: 0x2203,
  24305. therefore: 0x2234,
  24306. theta: 0x03B8,
  24307. theta1: 0x03D1,
  24308. thetasymbolgreek: 0x03D1,
  24309. thieuthacirclekorean: 0x3279,
  24310. thieuthaparenkorean: 0x3219,
  24311. thieuthcirclekorean: 0x326B,
  24312. thieuthkorean: 0x314C,
  24313. thieuthparenkorean: 0x320B,
  24314. thirteencircle: 0x246C,
  24315. thirteenparen: 0x2480,
  24316. thirteenperiod: 0x2494,
  24317. thonangmonthothai: 0x0E11,
  24318. thook: 0x01AD,
  24319. thophuthaothai: 0x0E12,
  24320. thorn: 0x00FE,
  24321. thothahanthai: 0x0E17,
  24322. thothanthai: 0x0E10,
  24323. thothongthai: 0x0E18,
  24324. thothungthai: 0x0E16,
  24325. thousandcyrillic: 0x0482,
  24326. thousandsseparatorarabic: 0x066C,
  24327. thousandsseparatorpersian: 0x066C,
  24328. three: 0x0033,
  24329. threearabic: 0x0663,
  24330. threebengali: 0x09E9,
  24331. threecircle: 0x2462,
  24332. threecircleinversesansserif: 0x278C,
  24333. threedeva: 0x0969,
  24334. threeeighths: 0x215C,
  24335. threegujarati: 0x0AE9,
  24336. threegurmukhi: 0x0A69,
  24337. threehackarabic: 0x0663,
  24338. threehangzhou: 0x3023,
  24339. threeideographicparen: 0x3222,
  24340. threeinferior: 0x2083,
  24341. threemonospace: 0xFF13,
  24342. threenumeratorbengali: 0x09F6,
  24343. threeoldstyle: 0xF733,
  24344. threeparen: 0x2476,
  24345. threeperiod: 0x248A,
  24346. threepersian: 0x06F3,
  24347. threequarters: 0x00BE,
  24348. threequartersemdash: 0xF6DE,
  24349. threeroman: 0x2172,
  24350. threesuperior: 0x00B3,
  24351. threethai: 0x0E53,
  24352. thzsquare: 0x3394,
  24353. tihiragana: 0x3061,
  24354. tikatakana: 0x30C1,
  24355. tikatakanahalfwidth: 0xFF81,
  24356. tikeutacirclekorean: 0x3270,
  24357. tikeutaparenkorean: 0x3210,
  24358. tikeutcirclekorean: 0x3262,
  24359. tikeutkorean: 0x3137,
  24360. tikeutparenkorean: 0x3202,
  24361. tilde: 0x02DC,
  24362. tildebelowcmb: 0x0330,
  24363. tildecmb: 0x0303,
  24364. tildecomb: 0x0303,
  24365. tildedoublecmb: 0x0360,
  24366. tildeoperator: 0x223C,
  24367. tildeoverlaycmb: 0x0334,
  24368. tildeverticalcmb: 0x033E,
  24369. timescircle: 0x2297,
  24370. tipehahebrew: 0x0596,
  24371. tipehalefthebrew: 0x0596,
  24372. tippigurmukhi: 0x0A70,
  24373. titlocyrilliccmb: 0x0483,
  24374. tiwnarmenian: 0x057F,
  24375. tlinebelow: 0x1E6F,
  24376. tmonospace: 0xFF54,
  24377. toarmenian: 0x0569,
  24378. tohiragana: 0x3068,
  24379. tokatakana: 0x30C8,
  24380. tokatakanahalfwidth: 0xFF84,
  24381. tonebarextrahighmod: 0x02E5,
  24382. tonebarextralowmod: 0x02E9,
  24383. tonebarhighmod: 0x02E6,
  24384. tonebarlowmod: 0x02E8,
  24385. tonebarmidmod: 0x02E7,
  24386. tonefive: 0x01BD,
  24387. tonesix: 0x0185,
  24388. tonetwo: 0x01A8,
  24389. tonos: 0x0384,
  24390. tonsquare: 0x3327,
  24391. topatakthai: 0x0E0F,
  24392. tortoiseshellbracketleft: 0x3014,
  24393. tortoiseshellbracketleftsmall: 0xFE5D,
  24394. tortoiseshellbracketleftvertical: 0xFE39,
  24395. tortoiseshellbracketright: 0x3015,
  24396. tortoiseshellbracketrightsmall: 0xFE5E,
  24397. tortoiseshellbracketrightvertical: 0xFE3A,
  24398. totaothai: 0x0E15,
  24399. tpalatalhook: 0x01AB,
  24400. tparen: 0x24AF,
  24401. trademark: 0x2122,
  24402. trademarksans: 0xF8EA,
  24403. trademarkserif: 0xF6DB,
  24404. tretroflexhook: 0x0288,
  24405. triagdn: 0x25BC,
  24406. triaglf: 0x25C4,
  24407. triagrt: 0x25BA,
  24408. triagup: 0x25B2,
  24409. ts: 0x02A6,
  24410. tsadi: 0x05E6,
  24411. tsadidagesh: 0xFB46,
  24412. tsadidageshhebrew: 0xFB46,
  24413. tsadihebrew: 0x05E6,
  24414. tsecyrillic: 0x0446,
  24415. tsere: 0x05B5,
  24416. tsere12: 0x05B5,
  24417. tsere1e: 0x05B5,
  24418. tsere2b: 0x05B5,
  24419. tserehebrew: 0x05B5,
  24420. tserenarrowhebrew: 0x05B5,
  24421. tserequarterhebrew: 0x05B5,
  24422. tserewidehebrew: 0x05B5,
  24423. tshecyrillic: 0x045B,
  24424. tsuperior: 0xF6F3,
  24425. ttabengali: 0x099F,
  24426. ttadeva: 0x091F,
  24427. ttagujarati: 0x0A9F,
  24428. ttagurmukhi: 0x0A1F,
  24429. tteharabic: 0x0679,
  24430. ttehfinalarabic: 0xFB67,
  24431. ttehinitialarabic: 0xFB68,
  24432. ttehmedialarabic: 0xFB69,
  24433. tthabengali: 0x09A0,
  24434. tthadeva: 0x0920,
  24435. tthagujarati: 0x0AA0,
  24436. tthagurmukhi: 0x0A20,
  24437. tturned: 0x0287,
  24438. tuhiragana: 0x3064,
  24439. tukatakana: 0x30C4,
  24440. tukatakanahalfwidth: 0xFF82,
  24441. tusmallhiragana: 0x3063,
  24442. tusmallkatakana: 0x30C3,
  24443. tusmallkatakanahalfwidth: 0xFF6F,
  24444. twelvecircle: 0x246B,
  24445. twelveparen: 0x247F,
  24446. twelveperiod: 0x2493,
  24447. twelveroman: 0x217B,
  24448. twentycircle: 0x2473,
  24449. twentyhangzhou: 0x5344,
  24450. twentyparen: 0x2487,
  24451. twentyperiod: 0x249B,
  24452. two: 0x0032,
  24453. twoarabic: 0x0662,
  24454. twobengali: 0x09E8,
  24455. twocircle: 0x2461,
  24456. twocircleinversesansserif: 0x278B,
  24457. twodeva: 0x0968,
  24458. twodotenleader: 0x2025,
  24459. twodotleader: 0x2025,
  24460. twodotleadervertical: 0xFE30,
  24461. twogujarati: 0x0AE8,
  24462. twogurmukhi: 0x0A68,
  24463. twohackarabic: 0x0662,
  24464. twohangzhou: 0x3022,
  24465. twoideographicparen: 0x3221,
  24466. twoinferior: 0x2082,
  24467. twomonospace: 0xFF12,
  24468. twonumeratorbengali: 0x09F5,
  24469. twooldstyle: 0xF732,
  24470. twoparen: 0x2475,
  24471. twoperiod: 0x2489,
  24472. twopersian: 0x06F2,
  24473. tworoman: 0x2171,
  24474. twostroke: 0x01BB,
  24475. twosuperior: 0x00B2,
  24476. twothai: 0x0E52,
  24477. twothirds: 0x2154,
  24478. u: 0x0075,
  24479. uacute: 0x00FA,
  24480. ubar: 0x0289,
  24481. ubengali: 0x0989,
  24482. ubopomofo: 0x3128,
  24483. ubreve: 0x016D,
  24484. ucaron: 0x01D4,
  24485. ucircle: 0x24E4,
  24486. ucircumflex: 0x00FB,
  24487. ucircumflexbelow: 0x1E77,
  24488. ucyrillic: 0x0443,
  24489. udattadeva: 0x0951,
  24490. udblacute: 0x0171,
  24491. udblgrave: 0x0215,
  24492. udeva: 0x0909,
  24493. udieresis: 0x00FC,
  24494. udieresisacute: 0x01D8,
  24495. udieresisbelow: 0x1E73,
  24496. udieresiscaron: 0x01DA,
  24497. udieresiscyrillic: 0x04F1,
  24498. udieresisgrave: 0x01DC,
  24499. udieresismacron: 0x01D6,
  24500. udotbelow: 0x1EE5,
  24501. ugrave: 0x00F9,
  24502. ugujarati: 0x0A89,
  24503. ugurmukhi: 0x0A09,
  24504. uhiragana: 0x3046,
  24505. uhookabove: 0x1EE7,
  24506. uhorn: 0x01B0,
  24507. uhornacute: 0x1EE9,
  24508. uhorndotbelow: 0x1EF1,
  24509. uhorngrave: 0x1EEB,
  24510. uhornhookabove: 0x1EED,
  24511. uhorntilde: 0x1EEF,
  24512. uhungarumlaut: 0x0171,
  24513. uhungarumlautcyrillic: 0x04F3,
  24514. uinvertedbreve: 0x0217,
  24515. ukatakana: 0x30A6,
  24516. ukatakanahalfwidth: 0xFF73,
  24517. ukcyrillic: 0x0479,
  24518. ukorean: 0x315C,
  24519. umacron: 0x016B,
  24520. umacroncyrillic: 0x04EF,
  24521. umacrondieresis: 0x1E7B,
  24522. umatragurmukhi: 0x0A41,
  24523. umonospace: 0xFF55,
  24524. underscore: 0x005F,
  24525. underscoredbl: 0x2017,
  24526. underscoremonospace: 0xFF3F,
  24527. underscorevertical: 0xFE33,
  24528. underscorewavy: 0xFE4F,
  24529. union: 0x222A,
  24530. universal: 0x2200,
  24531. uogonek: 0x0173,
  24532. uparen: 0x24B0,
  24533. upblock: 0x2580,
  24534. upperdothebrew: 0x05C4,
  24535. upsilon: 0x03C5,
  24536. upsilondieresis: 0x03CB,
  24537. upsilondieresistonos: 0x03B0,
  24538. upsilonlatin: 0x028A,
  24539. upsilontonos: 0x03CD,
  24540. uptackbelowcmb: 0x031D,
  24541. uptackmod: 0x02D4,
  24542. uragurmukhi: 0x0A73,
  24543. uring: 0x016F,
  24544. ushortcyrillic: 0x045E,
  24545. usmallhiragana: 0x3045,
  24546. usmallkatakana: 0x30A5,
  24547. usmallkatakanahalfwidth: 0xFF69,
  24548. ustraightcyrillic: 0x04AF,
  24549. ustraightstrokecyrillic: 0x04B1,
  24550. utilde: 0x0169,
  24551. utildeacute: 0x1E79,
  24552. utildebelow: 0x1E75,
  24553. uubengali: 0x098A,
  24554. uudeva: 0x090A,
  24555. uugujarati: 0x0A8A,
  24556. uugurmukhi: 0x0A0A,
  24557. uumatragurmukhi: 0x0A42,
  24558. uuvowelsignbengali: 0x09C2,
  24559. uuvowelsigndeva: 0x0942,
  24560. uuvowelsigngujarati: 0x0AC2,
  24561. uvowelsignbengali: 0x09C1,
  24562. uvowelsigndeva: 0x0941,
  24563. uvowelsigngujarati: 0x0AC1,
  24564. v: 0x0076,
  24565. vadeva: 0x0935,
  24566. vagujarati: 0x0AB5,
  24567. vagurmukhi: 0x0A35,
  24568. vakatakana: 0x30F7,
  24569. vav: 0x05D5,
  24570. vavdagesh: 0xFB35,
  24571. vavdagesh65: 0xFB35,
  24572. vavdageshhebrew: 0xFB35,
  24573. vavhebrew: 0x05D5,
  24574. vavholam: 0xFB4B,
  24575. vavholamhebrew: 0xFB4B,
  24576. vavvavhebrew: 0x05F0,
  24577. vavyodhebrew: 0x05F1,
  24578. vcircle: 0x24E5,
  24579. vdotbelow: 0x1E7F,
  24580. vecyrillic: 0x0432,
  24581. veharabic: 0x06A4,
  24582. vehfinalarabic: 0xFB6B,
  24583. vehinitialarabic: 0xFB6C,
  24584. vehmedialarabic: 0xFB6D,
  24585. vekatakana: 0x30F9,
  24586. venus: 0x2640,
  24587. verticalbar: 0x007C,
  24588. verticallineabovecmb: 0x030D,
  24589. verticallinebelowcmb: 0x0329,
  24590. verticallinelowmod: 0x02CC,
  24591. verticallinemod: 0x02C8,
  24592. vewarmenian: 0x057E,
  24593. vhook: 0x028B,
  24594. vikatakana: 0x30F8,
  24595. viramabengali: 0x09CD,
  24596. viramadeva: 0x094D,
  24597. viramagujarati: 0x0ACD,
  24598. visargabengali: 0x0983,
  24599. visargadeva: 0x0903,
  24600. visargagujarati: 0x0A83,
  24601. vmonospace: 0xFF56,
  24602. voarmenian: 0x0578,
  24603. voicediterationhiragana: 0x309E,
  24604. voicediterationkatakana: 0x30FE,
  24605. voicedmarkkana: 0x309B,
  24606. voicedmarkkanahalfwidth: 0xFF9E,
  24607. vokatakana: 0x30FA,
  24608. vparen: 0x24B1,
  24609. vtilde: 0x1E7D,
  24610. vturned: 0x028C,
  24611. vuhiragana: 0x3094,
  24612. vukatakana: 0x30F4,
  24613. w: 0x0077,
  24614. wacute: 0x1E83,
  24615. waekorean: 0x3159,
  24616. wahiragana: 0x308F,
  24617. wakatakana: 0x30EF,
  24618. wakatakanahalfwidth: 0xFF9C,
  24619. wakorean: 0x3158,
  24620. wasmallhiragana: 0x308E,
  24621. wasmallkatakana: 0x30EE,
  24622. wattosquare: 0x3357,
  24623. wavedash: 0x301C,
  24624. wavyunderscorevertical: 0xFE34,
  24625. wawarabic: 0x0648,
  24626. wawfinalarabic: 0xFEEE,
  24627. wawhamzaabovearabic: 0x0624,
  24628. wawhamzaabovefinalarabic: 0xFE86,
  24629. wbsquare: 0x33DD,
  24630. wcircle: 0x24E6,
  24631. wcircumflex: 0x0175,
  24632. wdieresis: 0x1E85,
  24633. wdotaccent: 0x1E87,
  24634. wdotbelow: 0x1E89,
  24635. wehiragana: 0x3091,
  24636. weierstrass: 0x2118,
  24637. wekatakana: 0x30F1,
  24638. wekorean: 0x315E,
  24639. weokorean: 0x315D,
  24640. wgrave: 0x1E81,
  24641. whitebullet: 0x25E6,
  24642. whitecircle: 0x25CB,
  24643. whitecircleinverse: 0x25D9,
  24644. whitecornerbracketleft: 0x300E,
  24645. whitecornerbracketleftvertical: 0xFE43,
  24646. whitecornerbracketright: 0x300F,
  24647. whitecornerbracketrightvertical: 0xFE44,
  24648. whitediamond: 0x25C7,
  24649. whitediamondcontainingblacksmalldiamond: 0x25C8,
  24650. whitedownpointingsmalltriangle: 0x25BF,
  24651. whitedownpointingtriangle: 0x25BD,
  24652. whiteleftpointingsmalltriangle: 0x25C3,
  24653. whiteleftpointingtriangle: 0x25C1,
  24654. whitelenticularbracketleft: 0x3016,
  24655. whitelenticularbracketright: 0x3017,
  24656. whiterightpointingsmalltriangle: 0x25B9,
  24657. whiterightpointingtriangle: 0x25B7,
  24658. whitesmallsquare: 0x25AB,
  24659. whitesmilingface: 0x263A,
  24660. whitesquare: 0x25A1,
  24661. whitestar: 0x2606,
  24662. whitetelephone: 0x260F,
  24663. whitetortoiseshellbracketleft: 0x3018,
  24664. whitetortoiseshellbracketright: 0x3019,
  24665. whiteuppointingsmalltriangle: 0x25B5,
  24666. whiteuppointingtriangle: 0x25B3,
  24667. wihiragana: 0x3090,
  24668. wikatakana: 0x30F0,
  24669. wikorean: 0x315F,
  24670. wmonospace: 0xFF57,
  24671. wohiragana: 0x3092,
  24672. wokatakana: 0x30F2,
  24673. wokatakanahalfwidth: 0xFF66,
  24674. won: 0x20A9,
  24675. wonmonospace: 0xFFE6,
  24676. wowaenthai: 0x0E27,
  24677. wparen: 0x24B2,
  24678. wring: 0x1E98,
  24679. wsuperior: 0x02B7,
  24680. wturned: 0x028D,
  24681. wynn: 0x01BF,
  24682. x: 0x0078,
  24683. xabovecmb: 0x033D,
  24684. xbopomofo: 0x3112,
  24685. xcircle: 0x24E7,
  24686. xdieresis: 0x1E8D,
  24687. xdotaccent: 0x1E8B,
  24688. xeharmenian: 0x056D,
  24689. xi: 0x03BE,
  24690. xmonospace: 0xFF58,
  24691. xparen: 0x24B3,
  24692. xsuperior: 0x02E3,
  24693. y: 0x0079,
  24694. yaadosquare: 0x334E,
  24695. yabengali: 0x09AF,
  24696. yacute: 0x00FD,
  24697. yadeva: 0x092F,
  24698. yaekorean: 0x3152,
  24699. yagujarati: 0x0AAF,
  24700. yagurmukhi: 0x0A2F,
  24701. yahiragana: 0x3084,
  24702. yakatakana: 0x30E4,
  24703. yakatakanahalfwidth: 0xFF94,
  24704. yakorean: 0x3151,
  24705. yamakkanthai: 0x0E4E,
  24706. yasmallhiragana: 0x3083,
  24707. yasmallkatakana: 0x30E3,
  24708. yasmallkatakanahalfwidth: 0xFF6C,
  24709. yatcyrillic: 0x0463,
  24710. ycircle: 0x24E8,
  24711. ycircumflex: 0x0177,
  24712. ydieresis: 0x00FF,
  24713. ydotaccent: 0x1E8F,
  24714. ydotbelow: 0x1EF5,
  24715. yeharabic: 0x064A,
  24716. yehbarreearabic: 0x06D2,
  24717. yehbarreefinalarabic: 0xFBAF,
  24718. yehfinalarabic: 0xFEF2,
  24719. yehhamzaabovearabic: 0x0626,
  24720. yehhamzaabovefinalarabic: 0xFE8A,
  24721. yehhamzaaboveinitialarabic: 0xFE8B,
  24722. yehhamzaabovemedialarabic: 0xFE8C,
  24723. yehinitialarabic: 0xFEF3,
  24724. yehmedialarabic: 0xFEF4,
  24725. yehmeeminitialarabic: 0xFCDD,
  24726. yehmeemisolatedarabic: 0xFC58,
  24727. yehnoonfinalarabic: 0xFC94,
  24728. yehthreedotsbelowarabic: 0x06D1,
  24729. yekorean: 0x3156,
  24730. yen: 0x00A5,
  24731. yenmonospace: 0xFFE5,
  24732. yeokorean: 0x3155,
  24733. yeorinhieuhkorean: 0x3186,
  24734. yerahbenyomohebrew: 0x05AA,
  24735. yerahbenyomolefthebrew: 0x05AA,
  24736. yericyrillic: 0x044B,
  24737. yerudieresiscyrillic: 0x04F9,
  24738. yesieungkorean: 0x3181,
  24739. yesieungpansioskorean: 0x3183,
  24740. yesieungsioskorean: 0x3182,
  24741. yetivhebrew: 0x059A,
  24742. ygrave: 0x1EF3,
  24743. yhook: 0x01B4,
  24744. yhookabove: 0x1EF7,
  24745. yiarmenian: 0x0575,
  24746. yicyrillic: 0x0457,
  24747. yikorean: 0x3162,
  24748. yinyang: 0x262F,
  24749. yiwnarmenian: 0x0582,
  24750. ymonospace: 0xFF59,
  24751. yod: 0x05D9,
  24752. yoddagesh: 0xFB39,
  24753. yoddageshhebrew: 0xFB39,
  24754. yodhebrew: 0x05D9,
  24755. yodyodhebrew: 0x05F2,
  24756. yodyodpatahhebrew: 0xFB1F,
  24757. yohiragana: 0x3088,
  24758. yoikorean: 0x3189,
  24759. yokatakana: 0x30E8,
  24760. yokatakanahalfwidth: 0xFF96,
  24761. yokorean: 0x315B,
  24762. yosmallhiragana: 0x3087,
  24763. yosmallkatakana: 0x30E7,
  24764. yosmallkatakanahalfwidth: 0xFF6E,
  24765. yotgreek: 0x03F3,
  24766. yoyaekorean: 0x3188,
  24767. yoyakorean: 0x3187,
  24768. yoyakthai: 0x0E22,
  24769. yoyingthai: 0x0E0D,
  24770. yparen: 0x24B4,
  24771. ypogegrammeni: 0x037A,
  24772. ypogegrammenigreekcmb: 0x0345,
  24773. yr: 0x01A6,
  24774. yring: 0x1E99,
  24775. ysuperior: 0x02B8,
  24776. ytilde: 0x1EF9,
  24777. yturned: 0x028E,
  24778. yuhiragana: 0x3086,
  24779. yuikorean: 0x318C,
  24780. yukatakana: 0x30E6,
  24781. yukatakanahalfwidth: 0xFF95,
  24782. yukorean: 0x3160,
  24783. yusbigcyrillic: 0x046B,
  24784. yusbigiotifiedcyrillic: 0x046D,
  24785. yuslittlecyrillic: 0x0467,
  24786. yuslittleiotifiedcyrillic: 0x0469,
  24787. yusmallhiragana: 0x3085,
  24788. yusmallkatakana: 0x30E5,
  24789. yusmallkatakanahalfwidth: 0xFF6D,
  24790. yuyekorean: 0x318B,
  24791. yuyeokorean: 0x318A,
  24792. yyabengali: 0x09DF,
  24793. yyadeva: 0x095F,
  24794. z: 0x007A,
  24795. zaarmenian: 0x0566,
  24796. zacute: 0x017A,
  24797. zadeva: 0x095B,
  24798. zagurmukhi: 0x0A5B,
  24799. zaharabic: 0x0638,
  24800. zahfinalarabic: 0xFEC6,
  24801. zahinitialarabic: 0xFEC7,
  24802. zahiragana: 0x3056,
  24803. zahmedialarabic: 0xFEC8,
  24804. zainarabic: 0x0632,
  24805. zainfinalarabic: 0xFEB0,
  24806. zakatakana: 0x30B6,
  24807. zaqefgadolhebrew: 0x0595,
  24808. zaqefqatanhebrew: 0x0594,
  24809. zarqahebrew: 0x0598,
  24810. zayin: 0x05D6,
  24811. zayindagesh: 0xFB36,
  24812. zayindageshhebrew: 0xFB36,
  24813. zayinhebrew: 0x05D6,
  24814. zbopomofo: 0x3117,
  24815. zcaron: 0x017E,
  24816. zcircle: 0x24E9,
  24817. zcircumflex: 0x1E91,
  24818. zcurl: 0x0291,
  24819. zdot: 0x017C,
  24820. zdotaccent: 0x017C,
  24821. zdotbelow: 0x1E93,
  24822. zecyrillic: 0x0437,
  24823. zedescendercyrillic: 0x0499,
  24824. zedieresiscyrillic: 0x04DF,
  24825. zehiragana: 0x305C,
  24826. zekatakana: 0x30BC,
  24827. zero: 0x0030,
  24828. zeroarabic: 0x0660,
  24829. zerobengali: 0x09E6,
  24830. zerodeva: 0x0966,
  24831. zerogujarati: 0x0AE6,
  24832. zerogurmukhi: 0x0A66,
  24833. zerohackarabic: 0x0660,
  24834. zeroinferior: 0x2080,
  24835. zeromonospace: 0xFF10,
  24836. zerooldstyle: 0xF730,
  24837. zeropersian: 0x06F0,
  24838. zerosuperior: 0x2070,
  24839. zerothai: 0x0E50,
  24840. zerowidthjoiner: 0xFEFF,
  24841. zerowidthnonjoiner: 0x200C,
  24842. zerowidthspace: 0x200B,
  24843. zeta: 0x03B6,
  24844. zhbopomofo: 0x3113,
  24845. zhearmenian: 0x056A,
  24846. zhebrevecyrillic: 0x04C2,
  24847. zhecyrillic: 0x0436,
  24848. zhedescendercyrillic: 0x0497,
  24849. zhedieresiscyrillic: 0x04DD,
  24850. zihiragana: 0x3058,
  24851. zikatakana: 0x30B8,
  24852. zinorhebrew: 0x05AE,
  24853. zlinebelow: 0x1E95,
  24854. zmonospace: 0xFF5A,
  24855. zohiragana: 0x305E,
  24856. zokatakana: 0x30BE,
  24857. zparen: 0x24B5,
  24858. zretroflexhook: 0x0290,
  24859. zstroke: 0x01B6,
  24860. zuhiragana: 0x305A,
  24861. zukatakana: 0x30BA,
  24862. '.notdef': 0x0000
  24863. };
  24864. var DingbatsGlyphsUnicode = {
  24865. space: 0x0020,
  24866. a1: 0x2701,
  24867. a2: 0x2702,
  24868. a202: 0x2703,
  24869. a3: 0x2704,
  24870. a4: 0x260E,
  24871. a5: 0x2706,
  24872. a119: 0x2707,
  24873. a118: 0x2708,
  24874. a117: 0x2709,
  24875. a11: 0x261B,
  24876. a12: 0x261E,
  24877. a13: 0x270C,
  24878. a14: 0x270D,
  24879. a15: 0x270E,
  24880. a16: 0x270F,
  24881. a105: 0x2710,
  24882. a17: 0x2711,
  24883. a18: 0x2712,
  24884. a19: 0x2713,
  24885. a20: 0x2714,
  24886. a21: 0x2715,
  24887. a22: 0x2716,
  24888. a23: 0x2717,
  24889. a24: 0x2718,
  24890. a25: 0x2719,
  24891. a26: 0x271A,
  24892. a27: 0x271B,
  24893. a28: 0x271C,
  24894. a6: 0x271D,
  24895. a7: 0x271E,
  24896. a8: 0x271F,
  24897. a9: 0x2720,
  24898. a10: 0x2721,
  24899. a29: 0x2722,
  24900. a30: 0x2723,
  24901. a31: 0x2724,
  24902. a32: 0x2725,
  24903. a33: 0x2726,
  24904. a34: 0x2727,
  24905. a35: 0x2605,
  24906. a36: 0x2729,
  24907. a37: 0x272A,
  24908. a38: 0x272B,
  24909. a39: 0x272C,
  24910. a40: 0x272D,
  24911. a41: 0x272E,
  24912. a42: 0x272F,
  24913. a43: 0x2730,
  24914. a44: 0x2731,
  24915. a45: 0x2732,
  24916. a46: 0x2733,
  24917. a47: 0x2734,
  24918. a48: 0x2735,
  24919. a49: 0x2736,
  24920. a50: 0x2737,
  24921. a51: 0x2738,
  24922. a52: 0x2739,
  24923. a53: 0x273A,
  24924. a54: 0x273B,
  24925. a55: 0x273C,
  24926. a56: 0x273D,
  24927. a57: 0x273E,
  24928. a58: 0x273F,
  24929. a59: 0x2740,
  24930. a60: 0x2741,
  24931. a61: 0x2742,
  24932. a62: 0x2743,
  24933. a63: 0x2744,
  24934. a64: 0x2745,
  24935. a65: 0x2746,
  24936. a66: 0x2747,
  24937. a67: 0x2748,
  24938. a68: 0x2749,
  24939. a69: 0x274A,
  24940. a70: 0x274B,
  24941. a71: 0x25CF,
  24942. a72: 0x274D,
  24943. a73: 0x25A0,
  24944. a74: 0x274F,
  24945. a203: 0x2750,
  24946. a75: 0x2751,
  24947. a204: 0x2752,
  24948. a76: 0x25B2,
  24949. a77: 0x25BC,
  24950. a78: 0x25C6,
  24951. a79: 0x2756,
  24952. a81: 0x25D7,
  24953. a82: 0x2758,
  24954. a83: 0x2759,
  24955. a84: 0x275A,
  24956. a97: 0x275B,
  24957. a98: 0x275C,
  24958. a99: 0x275D,
  24959. a100: 0x275E,
  24960. a101: 0x2761,
  24961. a102: 0x2762,
  24962. a103: 0x2763,
  24963. a104: 0x2764,
  24964. a106: 0x2765,
  24965. a107: 0x2766,
  24966. a108: 0x2767,
  24967. a112: 0x2663,
  24968. a111: 0x2666,
  24969. a110: 0x2665,
  24970. a109: 0x2660,
  24971. a120: 0x2460,
  24972. a121: 0x2461,
  24973. a122: 0x2462,
  24974. a123: 0x2463,
  24975. a124: 0x2464,
  24976. a125: 0x2465,
  24977. a126: 0x2466,
  24978. a127: 0x2467,
  24979. a128: 0x2468,
  24980. a129: 0x2469,
  24981. a130: 0x2776,
  24982. a131: 0x2777,
  24983. a132: 0x2778,
  24984. a133: 0x2779,
  24985. a134: 0x277A,
  24986. a135: 0x277B,
  24987. a136: 0x277C,
  24988. a137: 0x277D,
  24989. a138: 0x277E,
  24990. a139: 0x277F,
  24991. a140: 0x2780,
  24992. a141: 0x2781,
  24993. a142: 0x2782,
  24994. a143: 0x2783,
  24995. a144: 0x2784,
  24996. a145: 0x2785,
  24997. a146: 0x2786,
  24998. a147: 0x2787,
  24999. a148: 0x2788,
  25000. a149: 0x2789,
  25001. a150: 0x278A,
  25002. a151: 0x278B,
  25003. a152: 0x278C,
  25004. a153: 0x278D,
  25005. a154: 0x278E,
  25006. a155: 0x278F,
  25007. a156: 0x2790,
  25008. a157: 0x2791,
  25009. a158: 0x2792,
  25010. a159: 0x2793,
  25011. a160: 0x2794,
  25012. a161: 0x2192,
  25013. a163: 0x2194,
  25014. a164: 0x2195,
  25015. a196: 0x2798,
  25016. a165: 0x2799,
  25017. a192: 0x279A,
  25018. a166: 0x279B,
  25019. a167: 0x279C,
  25020. a168: 0x279D,
  25021. a169: 0x279E,
  25022. a170: 0x279F,
  25023. a171: 0x27A0,
  25024. a172: 0x27A1,
  25025. a173: 0x27A2,
  25026. a162: 0x27A3,
  25027. a174: 0x27A4,
  25028. a175: 0x27A5,
  25029. a176: 0x27A6,
  25030. a177: 0x27A7,
  25031. a178: 0x27A8,
  25032. a179: 0x27A9,
  25033. a193: 0x27AA,
  25034. a180: 0x27AB,
  25035. a199: 0x27AC,
  25036. a181: 0x27AD,
  25037. a200: 0x27AE,
  25038. a182: 0x27AF,
  25039. a201: 0x27B1,
  25040. a183: 0x27B2,
  25041. a184: 0x27B3,
  25042. a197: 0x27B4,
  25043. a185: 0x27B5,
  25044. a194: 0x27B6,
  25045. a198: 0x27B7,
  25046. a186: 0x27B8,
  25047. a195: 0x27B9,
  25048. a187: 0x27BA,
  25049. a188: 0x27BB,
  25050. a189: 0x27BC,
  25051. a190: 0x27BD,
  25052. a191: 0x27BE,
  25053. a89: 0x2768, // 0xF8D7
  25054. a90: 0x2769, // 0xF8D8
  25055. a93: 0x276A, // 0xF8D9
  25056. a94: 0x276B, // 0xF8DA
  25057. a91: 0x276C, // 0xF8DB
  25058. a92: 0x276D, // 0xF8DC
  25059. a205: 0x276E, // 0xF8DD
  25060. a85: 0x276F, // 0xF8DE
  25061. a206: 0x2770, // 0xF8DF
  25062. a86: 0x2771, // 0xF8E0
  25063. a87: 0x2772, // 0xF8E1
  25064. a88: 0x2773, // 0xF8E2
  25065. a95: 0x2774, // 0xF8E3
  25066. a96: 0x2775, // 0xF8E4
  25067. '.notdef': 0x0000
  25068. };
  25069. var PDFImage = (function PDFImageClosure() {
  25070. /**
  25071. * Decode the image in the main thread if it supported. Resovles the promise
  25072. * when the image data is ready.
  25073. */
  25074. function handleImageData(handler, xref, res, image) {
  25075. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  25076. // For natively supported jpegs send them to the main thread for decoding.
  25077. var dict = image.dict;
  25078. var colorSpace = dict.get('ColorSpace', 'CS');
  25079. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25080. var numComps = colorSpace.numComps;
  25081. var decodePromise = handler.sendWithPromise('JpegDecode',
  25082. [image.getIR(), numComps]);
  25083. return decodePromise.then(function (message) {
  25084. var data = message.data;
  25085. return new Stream(data, 0, data.length, image.dict);
  25086. });
  25087. } else {
  25088. return Promise.resolve(image);
  25089. }
  25090. }
  25091. /**
  25092. * Decode and clamp a value. The formula is different from the spec because we
  25093. * don't decode to float range [0,1], we decode it in the [0,max] range.
  25094. */
  25095. function decodeAndClamp(value, addend, coefficient, max) {
  25096. value = addend + value * coefficient;
  25097. // Clamp the value to the range
  25098. return (value < 0 ? 0 : (value > max ? max : value));
  25099. }
  25100. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  25101. this.image = image;
  25102. var dict = image.dict;
  25103. if (dict.has('Filter')) {
  25104. var filter = dict.get('Filter').name;
  25105. if (filter === 'JPXDecode') {
  25106. var jpxImage = new JpxImage();
  25107. jpxImage.parseImageProperties(image.stream);
  25108. image.stream.reset();
  25109. image.bitsPerComponent = jpxImage.bitsPerComponent;
  25110. image.numComps = jpxImage.componentsCount;
  25111. } else if (filter === 'JBIG2Decode') {
  25112. image.bitsPerComponent = 1;
  25113. image.numComps = 1;
  25114. }
  25115. }
  25116. // TODO cache rendered images?
  25117. this.width = dict.get('Width', 'W');
  25118. this.height = dict.get('Height', 'H');
  25119. if (this.width < 1 || this.height < 1) {
  25120. error('Invalid image width: ' + this.width + ' or height: ' +
  25121. this.height);
  25122. }
  25123. this.interpolate = dict.get('Interpolate', 'I') || false;
  25124. this.imageMask = dict.get('ImageMask', 'IM') || false;
  25125. this.matte = dict.get('Matte') || false;
  25126. var bitsPerComponent = image.bitsPerComponent;
  25127. if (!bitsPerComponent) {
  25128. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  25129. if (!bitsPerComponent) {
  25130. if (this.imageMask) {
  25131. bitsPerComponent = 1;
  25132. } else {
  25133. error('Bits per component missing in image: ' + this.imageMask);
  25134. }
  25135. }
  25136. }
  25137. this.bpc = bitsPerComponent;
  25138. if (!this.imageMask) {
  25139. var colorSpace = dict.get('ColorSpace', 'CS');
  25140. if (!colorSpace) {
  25141. info('JPX images (which do not require color spaces)');
  25142. switch (image.numComps) {
  25143. case 1:
  25144. colorSpace = Name.get('DeviceGray');
  25145. break;
  25146. case 3:
  25147. colorSpace = Name.get('DeviceRGB');
  25148. break;
  25149. case 4:
  25150. colorSpace = Name.get('DeviceCMYK');
  25151. break;
  25152. default:
  25153. error('JPX images with ' + this.numComps +
  25154. ' color components not supported.');
  25155. }
  25156. }
  25157. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  25158. this.numComps = this.colorSpace.numComps;
  25159. }
  25160. this.decode = dict.get('Decode', 'D');
  25161. this.needsDecode = false;
  25162. if (this.decode &&
  25163. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  25164. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  25165. this.needsDecode = true;
  25166. // Do some preprocessing to avoid more math.
  25167. var max = (1 << bitsPerComponent) - 1;
  25168. this.decodeCoefficients = [];
  25169. this.decodeAddends = [];
  25170. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  25171. var dmin = this.decode[i];
  25172. var dmax = this.decode[i + 1];
  25173. this.decodeCoefficients[j] = dmax - dmin;
  25174. this.decodeAddends[j] = max * dmin;
  25175. }
  25176. }
  25177. if (smask) {
  25178. this.smask = new PDFImage(xref, res, smask, false);
  25179. } else if (mask) {
  25180. if (isStream(mask)) {
  25181. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  25182. } else {
  25183. // Color key mask (just an array).
  25184. this.mask = mask;
  25185. }
  25186. }
  25187. }
  25188. /**
  25189. * Handles processing of image data and returns the Promise that is resolved
  25190. * with a PDFImage when the image is ready to be used.
  25191. */
  25192. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  25193. res, image, inline) {
  25194. var imagePromise = handleImageData(handler, xref, res, image);
  25195. var smaskPromise;
  25196. var maskPromise;
  25197. var smask = image.dict.get('SMask');
  25198. var mask = image.dict.get('Mask');
  25199. if (smask) {
  25200. smaskPromise = handleImageData(handler, xref, res, smask);
  25201. maskPromise = Promise.resolve(null);
  25202. } else {
  25203. smaskPromise = Promise.resolve(null);
  25204. if (mask) {
  25205. if (isStream(mask)) {
  25206. maskPromise = handleImageData(handler, xref, res, mask);
  25207. } else if (isArray(mask)) {
  25208. maskPromise = Promise.resolve(mask);
  25209. } else {
  25210. warn('Unsupported mask format.');
  25211. maskPromise = Promise.resolve(null);
  25212. }
  25213. } else {
  25214. maskPromise = Promise.resolve(null);
  25215. }
  25216. }
  25217. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  25218. function(results) {
  25219. var imageData = results[0];
  25220. var smaskData = results[1];
  25221. var maskData = results[2];
  25222. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  25223. });
  25224. };
  25225. /**
  25226. * Resize an image using the nearest neighbor algorithm. Currently only
  25227. * supports one and three component images.
  25228. * @param {TypedArray} pixels The original image with one component.
  25229. * @param {Number} bpc Number of bits per component.
  25230. * @param {Number} components Number of color components, 1 or 3 is supported.
  25231. * @param {Number} w1 Original width.
  25232. * @param {Number} h1 Original height.
  25233. * @param {Number} w2 New width.
  25234. * @param {Number} h2 New height.
  25235. * @param {TypedArray} dest (Optional) The destination buffer.
  25236. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  25237. * @return {TypedArray} Resized image data.
  25238. */
  25239. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  25240. w1, h1, w2, h2, dest, alpha01) {
  25241. if (components !== 1 && components !== 3) {
  25242. error('Unsupported component count for resizing.');
  25243. }
  25244. var length = w2 * h2 * components;
  25245. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  25246. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25247. var xRatio = w1 / w2;
  25248. var yRatio = h1 / h2;
  25249. var i, j, py, newIndex = 0, oldIndex;
  25250. var xScaled = new Uint16Array(w2);
  25251. var w1Scanline = w1 * components;
  25252. if (alpha01 !== 1) {
  25253. alpha01 = 0;
  25254. }
  25255. for (j = 0; j < w2; j++) {
  25256. xScaled[j] = Math.floor(j * xRatio) * components;
  25257. }
  25258. if (components === 1) {
  25259. for (i = 0; i < h2; i++) {
  25260. py = Math.floor(i * yRatio) * w1Scanline;
  25261. for (j = 0; j < w2; j++) {
  25262. oldIndex = py + xScaled[j];
  25263. temp[newIndex++] = pixels[oldIndex];
  25264. }
  25265. }
  25266. } else if (components === 3) {
  25267. for (i = 0; i < h2; i++) {
  25268. py = Math.floor(i * yRatio) * w1Scanline;
  25269. for (j = 0; j < w2; j++) {
  25270. oldIndex = py + xScaled[j];
  25271. temp[newIndex++] = pixels[oldIndex++];
  25272. temp[newIndex++] = pixels[oldIndex++];
  25273. temp[newIndex++] = pixels[oldIndex++];
  25274. newIndex += alpha01;
  25275. }
  25276. }
  25277. }
  25278. return temp;
  25279. };
  25280. PDFImage.createMask =
  25281. function PDFImage_createMask(imgArray, width, height,
  25282. imageIsFromDecodeStream, inverseDecode) {
  25283. // |imgArray| might not contain full data for every pixel of the mask, so
  25284. // we need to distinguish between |computedLength| and |actualLength|.
  25285. // In particular, if inverseDecode is true, then the array we return must
  25286. // have a length of |computedLength|.
  25287. var computedLength = ((width + 7) >> 3) * height;
  25288. var actualLength = imgArray.byteLength;
  25289. var haveFullData = computedLength === actualLength;
  25290. var data, i;
  25291. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  25292. // imgArray came from a DecodeStream and its data is in an appropriate
  25293. // form, so we can just transfer it.
  25294. data = imgArray;
  25295. } else if (!inverseDecode) {
  25296. data = new Uint8Array(actualLength);
  25297. data.set(imgArray);
  25298. } else {
  25299. data = new Uint8Array(computedLength);
  25300. data.set(imgArray);
  25301. for (i = actualLength; i < computedLength; i++) {
  25302. data[i] = 0xff;
  25303. }
  25304. }
  25305. // If necessary, invert the original mask data (but not any extra we might
  25306. // have added above). It's safe to modify the array -- whether it's the
  25307. // original or a copy, we're about to transfer it anyway, so nothing else
  25308. // in this thread can be relying on its contents.
  25309. if (inverseDecode) {
  25310. for (i = 0; i < actualLength; i++) {
  25311. data[i] = ~data[i];
  25312. }
  25313. }
  25314. return {data: data, width: width, height: height};
  25315. };
  25316. PDFImage.prototype = {
  25317. get drawWidth() {
  25318. return Math.max(this.width,
  25319. this.smask && this.smask.width || 0,
  25320. this.mask && this.mask.width || 0);
  25321. },
  25322. get drawHeight() {
  25323. return Math.max(this.height,
  25324. this.smask && this.smask.height || 0,
  25325. this.mask && this.mask.height || 0);
  25326. },
  25327. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  25328. var bpc = this.bpc;
  25329. var numComps = this.numComps;
  25330. var decodeAddends = this.decodeAddends;
  25331. var decodeCoefficients = this.decodeCoefficients;
  25332. var max = (1 << bpc) - 1;
  25333. var i, ii;
  25334. if (bpc === 1) {
  25335. // If the buffer needed decode that means it just needs to be inverted.
  25336. for (i = 0, ii = buffer.length; i < ii; i++) {
  25337. buffer[i] = +!(buffer[i]);
  25338. }
  25339. return;
  25340. }
  25341. var index = 0;
  25342. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  25343. for (var j = 0; j < numComps; j++) {
  25344. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  25345. decodeCoefficients[j], max);
  25346. index++;
  25347. }
  25348. }
  25349. },
  25350. getComponents: function PDFImage_getComponents(buffer) {
  25351. var bpc = this.bpc;
  25352. // This image doesn't require any extra work.
  25353. if (bpc === 8) {
  25354. return buffer;
  25355. }
  25356. var width = this.width;
  25357. var height = this.height;
  25358. var numComps = this.numComps;
  25359. var length = width * height * numComps;
  25360. var bufferPos = 0;
  25361. var output = (bpc <= 8 ? new Uint8Array(length) :
  25362. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  25363. var rowComps = width * numComps;
  25364. var max = (1 << bpc) - 1;
  25365. var i = 0, ii, buf;
  25366. if (bpc === 1) {
  25367. // Optimization for reading 1 bpc images.
  25368. var mask, loop1End, loop2End;
  25369. for (var j = 0; j < height; j++) {
  25370. loop1End = i + (rowComps & ~7);
  25371. loop2End = i + rowComps;
  25372. // unroll loop for all full bytes
  25373. while (i < loop1End) {
  25374. buf = buffer[bufferPos++];
  25375. output[i] = (buf >> 7) & 1;
  25376. output[i + 1] = (buf >> 6) & 1;
  25377. output[i + 2] = (buf >> 5) & 1;
  25378. output[i + 3] = (buf >> 4) & 1;
  25379. output[i + 4] = (buf >> 3) & 1;
  25380. output[i + 5] = (buf >> 2) & 1;
  25381. output[i + 6] = (buf >> 1) & 1;
  25382. output[i + 7] = buf & 1;
  25383. i += 8;
  25384. }
  25385. // handle remaing bits
  25386. if (i < loop2End) {
  25387. buf = buffer[bufferPos++];
  25388. mask = 128;
  25389. while (i < loop2End) {
  25390. output[i++] = +!!(buf & mask);
  25391. mask >>= 1;
  25392. }
  25393. }
  25394. }
  25395. } else {
  25396. // The general case that handles all other bpc values.
  25397. var bits = 0;
  25398. buf = 0;
  25399. for (i = 0, ii = length; i < ii; ++i) {
  25400. if (i % rowComps === 0) {
  25401. buf = 0;
  25402. bits = 0;
  25403. }
  25404. while (bits < bpc) {
  25405. buf = (buf << 8) | buffer[bufferPos++];
  25406. bits += 8;
  25407. }
  25408. var remainingBits = bits - bpc;
  25409. var value = buf >> remainingBits;
  25410. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  25411. buf = buf & ((1 << remainingBits) - 1);
  25412. bits = remainingBits;
  25413. }
  25414. }
  25415. return output;
  25416. },
  25417. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  25418. actualHeight, image) {
  25419. var smask = this.smask;
  25420. var mask = this.mask;
  25421. var alphaBuf, sw, sh, i, ii, j;
  25422. if (smask) {
  25423. sw = smask.width;
  25424. sh = smask.height;
  25425. alphaBuf = new Uint8Array(sw * sh);
  25426. smask.fillGrayBuffer(alphaBuf);
  25427. if (sw !== width || sh !== height) {
  25428. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  25429. height);
  25430. }
  25431. } else if (mask) {
  25432. if (mask instanceof PDFImage) {
  25433. sw = mask.width;
  25434. sh = mask.height;
  25435. alphaBuf = new Uint8Array(sw * sh);
  25436. mask.numComps = 1;
  25437. mask.fillGrayBuffer(alphaBuf);
  25438. // Need to invert values in rgbaBuf
  25439. for (i = 0, ii = sw * sh; i < ii; ++i) {
  25440. alphaBuf[i] = 255 - alphaBuf[i];
  25441. }
  25442. if (sw !== width || sh !== height) {
  25443. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  25444. height);
  25445. }
  25446. } else if (isArray(mask)) {
  25447. // Color key mask: if any of the compontents are outside the range
  25448. // then they should be painted.
  25449. alphaBuf = new Uint8Array(width * height);
  25450. var numComps = this.numComps;
  25451. for (i = 0, ii = width * height; i < ii; ++i) {
  25452. var opacity = 0;
  25453. var imageOffset = i * numComps;
  25454. for (j = 0; j < numComps; ++j) {
  25455. var color = image[imageOffset + j];
  25456. var maskOffset = j * 2;
  25457. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  25458. opacity = 255;
  25459. break;
  25460. }
  25461. }
  25462. alphaBuf[i] = opacity;
  25463. }
  25464. } else {
  25465. error('Unknown mask format.');
  25466. }
  25467. }
  25468. if (alphaBuf) {
  25469. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25470. rgbaBuf[j] = alphaBuf[i];
  25471. }
  25472. } else {
  25473. // No mask.
  25474. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  25475. rgbaBuf[j] = 255;
  25476. }
  25477. }
  25478. },
  25479. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  25480. var matte = this.smask && this.smask.matte;
  25481. if (!matte) {
  25482. return;
  25483. }
  25484. var matteRgb = this.colorSpace.getRgb(matte, 0);
  25485. var matteR = matteRgb[0];
  25486. var matteG = matteRgb[1];
  25487. var matteB = matteRgb[2];
  25488. var length = width * height * 4;
  25489. var r, g, b;
  25490. for (var i = 0; i < length; i += 4) {
  25491. var alpha = buffer[i + 3];
  25492. if (alpha === 0) {
  25493. // according formula we have to get Infinity in all components
  25494. // making it white (typical paper color) should be okay
  25495. buffer[i] = 255;
  25496. buffer[i + 1] = 255;
  25497. buffer[i + 2] = 255;
  25498. continue;
  25499. }
  25500. var k = 255 / alpha;
  25501. r = (buffer[i] - matteR) * k + matteR;
  25502. g = (buffer[i + 1] - matteG) * k + matteG;
  25503. b = (buffer[i + 2] - matteB) * k + matteB;
  25504. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  25505. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  25506. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  25507. }
  25508. },
  25509. createImageData: function PDFImage_createImageData(forceRGBA) {
  25510. var drawWidth = this.drawWidth;
  25511. var drawHeight = this.drawHeight;
  25512. var imgData = { // other fields are filled in below
  25513. width: drawWidth,
  25514. height: drawHeight
  25515. };
  25516. var numComps = this.numComps;
  25517. var originalWidth = this.width;
  25518. var originalHeight = this.height;
  25519. var bpc = this.bpc;
  25520. // Rows start at byte boundary.
  25521. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  25522. var imgArray;
  25523. if (!forceRGBA) {
  25524. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  25525. // without any complications, we pass a same-sized copy to the main
  25526. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  25527. // of memory for many scanned documents. It's also much faster.
  25528. //
  25529. // Similarly, if it is a 24-bit-per pixel RGB image without any
  25530. // complications, we avoid expanding by 1.333x to RGBA form.
  25531. var kind;
  25532. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  25533. kind = ImageKind.GRAYSCALE_1BPP;
  25534. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  25535. !this.needsDecode) {
  25536. kind = ImageKind.RGB_24BPP;
  25537. }
  25538. if (kind && !this.smask && !this.mask &&
  25539. drawWidth === originalWidth && drawHeight === originalHeight) {
  25540. imgData.kind = kind;
  25541. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25542. // If imgArray came from a DecodeStream, we're safe to transfer it
  25543. // (and thus neuter it) because it will constitute the entire
  25544. // DecodeStream's data. But if it came from a Stream, we need to
  25545. // copy it because it'll only be a portion of the Stream's data, and
  25546. // the rest will be read later on.
  25547. if (this.image instanceof DecodeStream) {
  25548. imgData.data = imgArray;
  25549. } else {
  25550. var newArray = new Uint8Array(imgArray.length);
  25551. newArray.set(imgArray);
  25552. imgData.data = newArray;
  25553. }
  25554. if (this.needsDecode) {
  25555. // Invert the buffer (which must be grayscale if we reached here).
  25556. assert(kind === ImageKind.GRAYSCALE_1BPP);
  25557. var buffer = imgData.data;
  25558. for (var i = 0, ii = buffer.length; i < ii; i++) {
  25559. buffer[i] ^= 0xff;
  25560. }
  25561. }
  25562. return imgData;
  25563. }
  25564. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  25565. imgData.kind = ImageKind.RGB_24BPP;
  25566. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  25567. drawWidth, drawHeight, true);
  25568. return imgData;
  25569. }
  25570. }
  25571. imgArray = this.getImageBytes(originalHeight * rowBytes);
  25572. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  25573. var actualHeight = 0 | (imgArray.length / rowBytes *
  25574. drawHeight / originalHeight);
  25575. var comps = this.getComponents(imgArray);
  25576. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  25577. // more compact RGB_24BPP form if allowable.
  25578. var alpha01, maybeUndoPreblend;
  25579. if (!forceRGBA && !this.smask && !this.mask) {
  25580. imgData.kind = ImageKind.RGB_24BPP;
  25581. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  25582. alpha01 = 0;
  25583. maybeUndoPreblend = false;
  25584. } else {
  25585. imgData.kind = ImageKind.RGBA_32BPP;
  25586. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  25587. alpha01 = 1;
  25588. maybeUndoPreblend = true;
  25589. // Color key masking (opacity) must be performed before decoding.
  25590. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  25591. comps);
  25592. }
  25593. if (this.needsDecode) {
  25594. this.decodeBuffer(comps);
  25595. }
  25596. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  25597. drawWidth, drawHeight, actualHeight, bpc, comps,
  25598. alpha01);
  25599. if (maybeUndoPreblend) {
  25600. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  25601. }
  25602. return imgData;
  25603. },
  25604. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  25605. var numComps = this.numComps;
  25606. if (numComps !== 1) {
  25607. error('Reading gray scale from a color image: ' + numComps);
  25608. }
  25609. var width = this.width;
  25610. var height = this.height;
  25611. var bpc = this.bpc;
  25612. // rows start at byte boundary
  25613. var rowBytes = (width * numComps * bpc + 7) >> 3;
  25614. var imgArray = this.getImageBytes(height * rowBytes);
  25615. var comps = this.getComponents(imgArray);
  25616. var i, length;
  25617. if (bpc === 1) {
  25618. // inline decoding (= inversion) for 1 bpc images
  25619. length = width * height;
  25620. if (this.needsDecode) {
  25621. // invert and scale to {0, 255}
  25622. for (i = 0; i < length; ++i) {
  25623. buffer[i] = (comps[i] - 1) & 255;
  25624. }
  25625. } else {
  25626. // scale to {0, 255}
  25627. for (i = 0; i < length; ++i) {
  25628. buffer[i] = (-comps[i]) & 255;
  25629. }
  25630. }
  25631. return;
  25632. }
  25633. if (this.needsDecode) {
  25634. this.decodeBuffer(comps);
  25635. }
  25636. length = width * height;
  25637. // we aren't using a colorspace so we need to scale the value
  25638. var scale = 255 / ((1 << bpc) - 1);
  25639. for (i = 0; i < length; ++i) {
  25640. buffer[i] = (scale * comps[i]) | 0;
  25641. }
  25642. },
  25643. getImageBytes: function PDFImage_getImageBytes(length,
  25644. drawWidth, drawHeight,
  25645. forceRGB) {
  25646. this.image.reset();
  25647. this.image.drawWidth = drawWidth || this.width;
  25648. this.image.drawHeight = drawHeight || this.height;
  25649. this.image.forceRGB = !!forceRGB;
  25650. return this.image.getBytes(length);
  25651. }
  25652. };
  25653. return PDFImage;
  25654. })();
  25655. // The Metrics object contains glyph widths (in glyph space units).
  25656. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  25657. // space unit corresponds to 1/1000th of text space unit.
  25658. var Metrics = {
  25659. 'Courier': 600,
  25660. 'Courier-Bold': 600,
  25661. 'Courier-BoldOblique': 600,
  25662. 'Courier-Oblique': 600,
  25663. 'Helvetica' : {
  25664. 'space': 278,
  25665. 'exclam': 278,
  25666. 'quotedbl': 355,
  25667. 'numbersign': 556,
  25668. 'dollar': 556,
  25669. 'percent': 889,
  25670. 'ampersand': 667,
  25671. 'quoteright': 222,
  25672. 'parenleft': 333,
  25673. 'parenright': 333,
  25674. 'asterisk': 389,
  25675. 'plus': 584,
  25676. 'comma': 278,
  25677. 'hyphen': 333,
  25678. 'period': 278,
  25679. 'slash': 278,
  25680. 'zero': 556,
  25681. 'one': 556,
  25682. 'two': 556,
  25683. 'three': 556,
  25684. 'four': 556,
  25685. 'five': 556,
  25686. 'six': 556,
  25687. 'seven': 556,
  25688. 'eight': 556,
  25689. 'nine': 556,
  25690. 'colon': 278,
  25691. 'semicolon': 278,
  25692. 'less': 584,
  25693. 'equal': 584,
  25694. 'greater': 584,
  25695. 'question': 556,
  25696. 'at': 1015,
  25697. 'A': 667,
  25698. 'B': 667,
  25699. 'C': 722,
  25700. 'D': 722,
  25701. 'E': 667,
  25702. 'F': 611,
  25703. 'G': 778,
  25704. 'H': 722,
  25705. 'I': 278,
  25706. 'J': 500,
  25707. 'K': 667,
  25708. 'L': 556,
  25709. 'M': 833,
  25710. 'N': 722,
  25711. 'O': 778,
  25712. 'P': 667,
  25713. 'Q': 778,
  25714. 'R': 722,
  25715. 'S': 667,
  25716. 'T': 611,
  25717. 'U': 722,
  25718. 'V': 667,
  25719. 'W': 944,
  25720. 'X': 667,
  25721. 'Y': 667,
  25722. 'Z': 611,
  25723. 'bracketleft': 278,
  25724. 'backslash': 278,
  25725. 'bracketright': 278,
  25726. 'asciicircum': 469,
  25727. 'underscore': 556,
  25728. 'quoteleft': 222,
  25729. 'a': 556,
  25730. 'b': 556,
  25731. 'c': 500,
  25732. 'd': 556,
  25733. 'e': 556,
  25734. 'f': 278,
  25735. 'g': 556,
  25736. 'h': 556,
  25737. 'i': 222,
  25738. 'j': 222,
  25739. 'k': 500,
  25740. 'l': 222,
  25741. 'm': 833,
  25742. 'n': 556,
  25743. 'o': 556,
  25744. 'p': 556,
  25745. 'q': 556,
  25746. 'r': 333,
  25747. 's': 500,
  25748. 't': 278,
  25749. 'u': 556,
  25750. 'v': 500,
  25751. 'w': 722,
  25752. 'x': 500,
  25753. 'y': 500,
  25754. 'z': 500,
  25755. 'braceleft': 334,
  25756. 'bar': 260,
  25757. 'braceright': 334,
  25758. 'asciitilde': 584,
  25759. 'exclamdown': 333,
  25760. 'cent': 556,
  25761. 'sterling': 556,
  25762. 'fraction': 167,
  25763. 'yen': 556,
  25764. 'florin': 556,
  25765. 'section': 556,
  25766. 'currency': 556,
  25767. 'quotesingle': 191,
  25768. 'quotedblleft': 333,
  25769. 'guillemotleft': 556,
  25770. 'guilsinglleft': 333,
  25771. 'guilsinglright': 333,
  25772. 'fi': 500,
  25773. 'fl': 500,
  25774. 'endash': 556,
  25775. 'dagger': 556,
  25776. 'daggerdbl': 556,
  25777. 'periodcentered': 278,
  25778. 'paragraph': 537,
  25779. 'bullet': 350,
  25780. 'quotesinglbase': 222,
  25781. 'quotedblbase': 333,
  25782. 'quotedblright': 333,
  25783. 'guillemotright': 556,
  25784. 'ellipsis': 1000,
  25785. 'perthousand': 1000,
  25786. 'questiondown': 611,
  25787. 'grave': 333,
  25788. 'acute': 333,
  25789. 'circumflex': 333,
  25790. 'tilde': 333,
  25791. 'macron': 333,
  25792. 'breve': 333,
  25793. 'dotaccent': 333,
  25794. 'dieresis': 333,
  25795. 'ring': 333,
  25796. 'cedilla': 333,
  25797. 'hungarumlaut': 333,
  25798. 'ogonek': 333,
  25799. 'caron': 333,
  25800. 'emdash': 1000,
  25801. 'AE': 1000,
  25802. 'ordfeminine': 370,
  25803. 'Lslash': 556,
  25804. 'Oslash': 778,
  25805. 'OE': 1000,
  25806. 'ordmasculine': 365,
  25807. 'ae': 889,
  25808. 'dotlessi': 278,
  25809. 'lslash': 222,
  25810. 'oslash': 611,
  25811. 'oe': 944,
  25812. 'germandbls': 611,
  25813. 'Idieresis': 278,
  25814. 'eacute': 556,
  25815. 'abreve': 556,
  25816. 'uhungarumlaut': 556,
  25817. 'ecaron': 556,
  25818. 'Ydieresis': 667,
  25819. 'divide': 584,
  25820. 'Yacute': 667,
  25821. 'Acircumflex': 667,
  25822. 'aacute': 556,
  25823. 'Ucircumflex': 722,
  25824. 'yacute': 500,
  25825. 'scommaaccent': 500,
  25826. 'ecircumflex': 556,
  25827. 'Uring': 722,
  25828. 'Udieresis': 722,
  25829. 'aogonek': 556,
  25830. 'Uacute': 722,
  25831. 'uogonek': 556,
  25832. 'Edieresis': 667,
  25833. 'Dcroat': 722,
  25834. 'commaaccent': 250,
  25835. 'copyright': 737,
  25836. 'Emacron': 667,
  25837. 'ccaron': 500,
  25838. 'aring': 556,
  25839. 'Ncommaaccent': 722,
  25840. 'lacute': 222,
  25841. 'agrave': 556,
  25842. 'Tcommaaccent': 611,
  25843. 'Cacute': 722,
  25844. 'atilde': 556,
  25845. 'Edotaccent': 667,
  25846. 'scaron': 500,
  25847. 'scedilla': 500,
  25848. 'iacute': 278,
  25849. 'lozenge': 471,
  25850. 'Rcaron': 722,
  25851. 'Gcommaaccent': 778,
  25852. 'ucircumflex': 556,
  25853. 'acircumflex': 556,
  25854. 'Amacron': 667,
  25855. 'rcaron': 333,
  25856. 'ccedilla': 500,
  25857. 'Zdotaccent': 611,
  25858. 'Thorn': 667,
  25859. 'Omacron': 778,
  25860. 'Racute': 722,
  25861. 'Sacute': 667,
  25862. 'dcaron': 643,
  25863. 'Umacron': 722,
  25864. 'uring': 556,
  25865. 'threesuperior': 333,
  25866. 'Ograve': 778,
  25867. 'Agrave': 667,
  25868. 'Abreve': 667,
  25869. 'multiply': 584,
  25870. 'uacute': 556,
  25871. 'Tcaron': 611,
  25872. 'partialdiff': 476,
  25873. 'ydieresis': 500,
  25874. 'Nacute': 722,
  25875. 'icircumflex': 278,
  25876. 'Ecircumflex': 667,
  25877. 'adieresis': 556,
  25878. 'edieresis': 556,
  25879. 'cacute': 500,
  25880. 'nacute': 556,
  25881. 'umacron': 556,
  25882. 'Ncaron': 722,
  25883. 'Iacute': 278,
  25884. 'plusminus': 584,
  25885. 'brokenbar': 260,
  25886. 'registered': 737,
  25887. 'Gbreve': 778,
  25888. 'Idotaccent': 278,
  25889. 'summation': 600,
  25890. 'Egrave': 667,
  25891. 'racute': 333,
  25892. 'omacron': 556,
  25893. 'Zacute': 611,
  25894. 'Zcaron': 611,
  25895. 'greaterequal': 549,
  25896. 'Eth': 722,
  25897. 'Ccedilla': 722,
  25898. 'lcommaaccent': 222,
  25899. 'tcaron': 317,
  25900. 'eogonek': 556,
  25901. 'Uogonek': 722,
  25902. 'Aacute': 667,
  25903. 'Adieresis': 667,
  25904. 'egrave': 556,
  25905. 'zacute': 500,
  25906. 'iogonek': 222,
  25907. 'Oacute': 778,
  25908. 'oacute': 556,
  25909. 'amacron': 556,
  25910. 'sacute': 500,
  25911. 'idieresis': 278,
  25912. 'Ocircumflex': 778,
  25913. 'Ugrave': 722,
  25914. 'Delta': 612,
  25915. 'thorn': 556,
  25916. 'twosuperior': 333,
  25917. 'Odieresis': 778,
  25918. 'mu': 556,
  25919. 'igrave': 278,
  25920. 'ohungarumlaut': 556,
  25921. 'Eogonek': 667,
  25922. 'dcroat': 556,
  25923. 'threequarters': 834,
  25924. 'Scedilla': 667,
  25925. 'lcaron': 299,
  25926. 'Kcommaaccent': 667,
  25927. 'Lacute': 556,
  25928. 'trademark': 1000,
  25929. 'edotaccent': 556,
  25930. 'Igrave': 278,
  25931. 'Imacron': 278,
  25932. 'Lcaron': 556,
  25933. 'onehalf': 834,
  25934. 'lessequal': 549,
  25935. 'ocircumflex': 556,
  25936. 'ntilde': 556,
  25937. 'Uhungarumlaut': 722,
  25938. 'Eacute': 667,
  25939. 'emacron': 556,
  25940. 'gbreve': 556,
  25941. 'onequarter': 834,
  25942. 'Scaron': 667,
  25943. 'Scommaaccent': 667,
  25944. 'Ohungarumlaut': 778,
  25945. 'degree': 400,
  25946. 'ograve': 556,
  25947. 'Ccaron': 722,
  25948. 'ugrave': 556,
  25949. 'radical': 453,
  25950. 'Dcaron': 722,
  25951. 'rcommaaccent': 333,
  25952. 'Ntilde': 722,
  25953. 'otilde': 556,
  25954. 'Rcommaaccent': 722,
  25955. 'Lcommaaccent': 556,
  25956. 'Atilde': 667,
  25957. 'Aogonek': 667,
  25958. 'Aring': 667,
  25959. 'Otilde': 778,
  25960. 'zdotaccent': 500,
  25961. 'Ecaron': 667,
  25962. 'Iogonek': 278,
  25963. 'kcommaaccent': 500,
  25964. 'minus': 584,
  25965. 'Icircumflex': 278,
  25966. 'ncaron': 556,
  25967. 'tcommaaccent': 278,
  25968. 'logicalnot': 584,
  25969. 'odieresis': 556,
  25970. 'udieresis': 556,
  25971. 'notequal': 549,
  25972. 'gcommaaccent': 556,
  25973. 'eth': 556,
  25974. 'zcaron': 500,
  25975. 'ncommaaccent': 556,
  25976. 'onesuperior': 333,
  25977. 'imacron': 278,
  25978. 'Euro': 556
  25979. },
  25980. 'Helvetica-Bold': {
  25981. 'space': 278,
  25982. 'exclam': 333,
  25983. 'quotedbl': 474,
  25984. 'numbersign': 556,
  25985. 'dollar': 556,
  25986. 'percent': 889,
  25987. 'ampersand': 722,
  25988. 'quoteright': 278,
  25989. 'parenleft': 333,
  25990. 'parenright': 333,
  25991. 'asterisk': 389,
  25992. 'plus': 584,
  25993. 'comma': 278,
  25994. 'hyphen': 333,
  25995. 'period': 278,
  25996. 'slash': 278,
  25997. 'zero': 556,
  25998. 'one': 556,
  25999. 'two': 556,
  26000. 'three': 556,
  26001. 'four': 556,
  26002. 'five': 556,
  26003. 'six': 556,
  26004. 'seven': 556,
  26005. 'eight': 556,
  26006. 'nine': 556,
  26007. 'colon': 333,
  26008. 'semicolon': 333,
  26009. 'less': 584,
  26010. 'equal': 584,
  26011. 'greater': 584,
  26012. 'question': 611,
  26013. 'at': 975,
  26014. 'A': 722,
  26015. 'B': 722,
  26016. 'C': 722,
  26017. 'D': 722,
  26018. 'E': 667,
  26019. 'F': 611,
  26020. 'G': 778,
  26021. 'H': 722,
  26022. 'I': 278,
  26023. 'J': 556,
  26024. 'K': 722,
  26025. 'L': 611,
  26026. 'M': 833,
  26027. 'N': 722,
  26028. 'O': 778,
  26029. 'P': 667,
  26030. 'Q': 778,
  26031. 'R': 722,
  26032. 'S': 667,
  26033. 'T': 611,
  26034. 'U': 722,
  26035. 'V': 667,
  26036. 'W': 944,
  26037. 'X': 667,
  26038. 'Y': 667,
  26039. 'Z': 611,
  26040. 'bracketleft': 333,
  26041. 'backslash': 278,
  26042. 'bracketright': 333,
  26043. 'asciicircum': 584,
  26044. 'underscore': 556,
  26045. 'quoteleft': 278,
  26046. 'a': 556,
  26047. 'b': 611,
  26048. 'c': 556,
  26049. 'd': 611,
  26050. 'e': 556,
  26051. 'f': 333,
  26052. 'g': 611,
  26053. 'h': 611,
  26054. 'i': 278,
  26055. 'j': 278,
  26056. 'k': 556,
  26057. 'l': 278,
  26058. 'm': 889,
  26059. 'n': 611,
  26060. 'o': 611,
  26061. 'p': 611,
  26062. 'q': 611,
  26063. 'r': 389,
  26064. 's': 556,
  26065. 't': 333,
  26066. 'u': 611,
  26067. 'v': 556,
  26068. 'w': 778,
  26069. 'x': 556,
  26070. 'y': 556,
  26071. 'z': 500,
  26072. 'braceleft': 389,
  26073. 'bar': 280,
  26074. 'braceright': 389,
  26075. 'asciitilde': 584,
  26076. 'exclamdown': 333,
  26077. 'cent': 556,
  26078. 'sterling': 556,
  26079. 'fraction': 167,
  26080. 'yen': 556,
  26081. 'florin': 556,
  26082. 'section': 556,
  26083. 'currency': 556,
  26084. 'quotesingle': 238,
  26085. 'quotedblleft': 500,
  26086. 'guillemotleft': 556,
  26087. 'guilsinglleft': 333,
  26088. 'guilsinglright': 333,
  26089. 'fi': 611,
  26090. 'fl': 611,
  26091. 'endash': 556,
  26092. 'dagger': 556,
  26093. 'daggerdbl': 556,
  26094. 'periodcentered': 278,
  26095. 'paragraph': 556,
  26096. 'bullet': 350,
  26097. 'quotesinglbase': 278,
  26098. 'quotedblbase': 500,
  26099. 'quotedblright': 500,
  26100. 'guillemotright': 556,
  26101. 'ellipsis': 1000,
  26102. 'perthousand': 1000,
  26103. 'questiondown': 611,
  26104. 'grave': 333,
  26105. 'acute': 333,
  26106. 'circumflex': 333,
  26107. 'tilde': 333,
  26108. 'macron': 333,
  26109. 'breve': 333,
  26110. 'dotaccent': 333,
  26111. 'dieresis': 333,
  26112. 'ring': 333,
  26113. 'cedilla': 333,
  26114. 'hungarumlaut': 333,
  26115. 'ogonek': 333,
  26116. 'caron': 333,
  26117. 'emdash': 1000,
  26118. 'AE': 1000,
  26119. 'ordfeminine': 370,
  26120. 'Lslash': 611,
  26121. 'Oslash': 778,
  26122. 'OE': 1000,
  26123. 'ordmasculine': 365,
  26124. 'ae': 889,
  26125. 'dotlessi': 278,
  26126. 'lslash': 278,
  26127. 'oslash': 611,
  26128. 'oe': 944,
  26129. 'germandbls': 611,
  26130. 'Idieresis': 278,
  26131. 'eacute': 556,
  26132. 'abreve': 556,
  26133. 'uhungarumlaut': 611,
  26134. 'ecaron': 556,
  26135. 'Ydieresis': 667,
  26136. 'divide': 584,
  26137. 'Yacute': 667,
  26138. 'Acircumflex': 722,
  26139. 'aacute': 556,
  26140. 'Ucircumflex': 722,
  26141. 'yacute': 556,
  26142. 'scommaaccent': 556,
  26143. 'ecircumflex': 556,
  26144. 'Uring': 722,
  26145. 'Udieresis': 722,
  26146. 'aogonek': 556,
  26147. 'Uacute': 722,
  26148. 'uogonek': 611,
  26149. 'Edieresis': 667,
  26150. 'Dcroat': 722,
  26151. 'commaaccent': 250,
  26152. 'copyright': 737,
  26153. 'Emacron': 667,
  26154. 'ccaron': 556,
  26155. 'aring': 556,
  26156. 'Ncommaaccent': 722,
  26157. 'lacute': 278,
  26158. 'agrave': 556,
  26159. 'Tcommaaccent': 611,
  26160. 'Cacute': 722,
  26161. 'atilde': 556,
  26162. 'Edotaccent': 667,
  26163. 'scaron': 556,
  26164. 'scedilla': 556,
  26165. 'iacute': 278,
  26166. 'lozenge': 494,
  26167. 'Rcaron': 722,
  26168. 'Gcommaaccent': 778,
  26169. 'ucircumflex': 611,
  26170. 'acircumflex': 556,
  26171. 'Amacron': 722,
  26172. 'rcaron': 389,
  26173. 'ccedilla': 556,
  26174. 'Zdotaccent': 611,
  26175. 'Thorn': 667,
  26176. 'Omacron': 778,
  26177. 'Racute': 722,
  26178. 'Sacute': 667,
  26179. 'dcaron': 743,
  26180. 'Umacron': 722,
  26181. 'uring': 611,
  26182. 'threesuperior': 333,
  26183. 'Ograve': 778,
  26184. 'Agrave': 722,
  26185. 'Abreve': 722,
  26186. 'multiply': 584,
  26187. 'uacute': 611,
  26188. 'Tcaron': 611,
  26189. 'partialdiff': 494,
  26190. 'ydieresis': 556,
  26191. 'Nacute': 722,
  26192. 'icircumflex': 278,
  26193. 'Ecircumflex': 667,
  26194. 'adieresis': 556,
  26195. 'edieresis': 556,
  26196. 'cacute': 556,
  26197. 'nacute': 611,
  26198. 'umacron': 611,
  26199. 'Ncaron': 722,
  26200. 'Iacute': 278,
  26201. 'plusminus': 584,
  26202. 'brokenbar': 280,
  26203. 'registered': 737,
  26204. 'Gbreve': 778,
  26205. 'Idotaccent': 278,
  26206. 'summation': 600,
  26207. 'Egrave': 667,
  26208. 'racute': 389,
  26209. 'omacron': 611,
  26210. 'Zacute': 611,
  26211. 'Zcaron': 611,
  26212. 'greaterequal': 549,
  26213. 'Eth': 722,
  26214. 'Ccedilla': 722,
  26215. 'lcommaaccent': 278,
  26216. 'tcaron': 389,
  26217. 'eogonek': 556,
  26218. 'Uogonek': 722,
  26219. 'Aacute': 722,
  26220. 'Adieresis': 722,
  26221. 'egrave': 556,
  26222. 'zacute': 500,
  26223. 'iogonek': 278,
  26224. 'Oacute': 778,
  26225. 'oacute': 611,
  26226. 'amacron': 556,
  26227. 'sacute': 556,
  26228. 'idieresis': 278,
  26229. 'Ocircumflex': 778,
  26230. 'Ugrave': 722,
  26231. 'Delta': 612,
  26232. 'thorn': 611,
  26233. 'twosuperior': 333,
  26234. 'Odieresis': 778,
  26235. 'mu': 611,
  26236. 'igrave': 278,
  26237. 'ohungarumlaut': 611,
  26238. 'Eogonek': 667,
  26239. 'dcroat': 611,
  26240. 'threequarters': 834,
  26241. 'Scedilla': 667,
  26242. 'lcaron': 400,
  26243. 'Kcommaaccent': 722,
  26244. 'Lacute': 611,
  26245. 'trademark': 1000,
  26246. 'edotaccent': 556,
  26247. 'Igrave': 278,
  26248. 'Imacron': 278,
  26249. 'Lcaron': 611,
  26250. 'onehalf': 834,
  26251. 'lessequal': 549,
  26252. 'ocircumflex': 611,
  26253. 'ntilde': 611,
  26254. 'Uhungarumlaut': 722,
  26255. 'Eacute': 667,
  26256. 'emacron': 556,
  26257. 'gbreve': 611,
  26258. 'onequarter': 834,
  26259. 'Scaron': 667,
  26260. 'Scommaaccent': 667,
  26261. 'Ohungarumlaut': 778,
  26262. 'degree': 400,
  26263. 'ograve': 611,
  26264. 'Ccaron': 722,
  26265. 'ugrave': 611,
  26266. 'radical': 549,
  26267. 'Dcaron': 722,
  26268. 'rcommaaccent': 389,
  26269. 'Ntilde': 722,
  26270. 'otilde': 611,
  26271. 'Rcommaaccent': 722,
  26272. 'Lcommaaccent': 611,
  26273. 'Atilde': 722,
  26274. 'Aogonek': 722,
  26275. 'Aring': 722,
  26276. 'Otilde': 778,
  26277. 'zdotaccent': 500,
  26278. 'Ecaron': 667,
  26279. 'Iogonek': 278,
  26280. 'kcommaaccent': 556,
  26281. 'minus': 584,
  26282. 'Icircumflex': 278,
  26283. 'ncaron': 611,
  26284. 'tcommaaccent': 333,
  26285. 'logicalnot': 584,
  26286. 'odieresis': 611,
  26287. 'udieresis': 611,
  26288. 'notequal': 549,
  26289. 'gcommaaccent': 611,
  26290. 'eth': 611,
  26291. 'zcaron': 500,
  26292. 'ncommaaccent': 611,
  26293. 'onesuperior': 333,
  26294. 'imacron': 278,
  26295. 'Euro': 556
  26296. },
  26297. 'Helvetica-BoldOblique': {
  26298. 'space': 278,
  26299. 'exclam': 333,
  26300. 'quotedbl': 474,
  26301. 'numbersign': 556,
  26302. 'dollar': 556,
  26303. 'percent': 889,
  26304. 'ampersand': 722,
  26305. 'quoteright': 278,
  26306. 'parenleft': 333,
  26307. 'parenright': 333,
  26308. 'asterisk': 389,
  26309. 'plus': 584,
  26310. 'comma': 278,
  26311. 'hyphen': 333,
  26312. 'period': 278,
  26313. 'slash': 278,
  26314. 'zero': 556,
  26315. 'one': 556,
  26316. 'two': 556,
  26317. 'three': 556,
  26318. 'four': 556,
  26319. 'five': 556,
  26320. 'six': 556,
  26321. 'seven': 556,
  26322. 'eight': 556,
  26323. 'nine': 556,
  26324. 'colon': 333,
  26325. 'semicolon': 333,
  26326. 'less': 584,
  26327. 'equal': 584,
  26328. 'greater': 584,
  26329. 'question': 611,
  26330. 'at': 975,
  26331. 'A': 722,
  26332. 'B': 722,
  26333. 'C': 722,
  26334. 'D': 722,
  26335. 'E': 667,
  26336. 'F': 611,
  26337. 'G': 778,
  26338. 'H': 722,
  26339. 'I': 278,
  26340. 'J': 556,
  26341. 'K': 722,
  26342. 'L': 611,
  26343. 'M': 833,
  26344. 'N': 722,
  26345. 'O': 778,
  26346. 'P': 667,
  26347. 'Q': 778,
  26348. 'R': 722,
  26349. 'S': 667,
  26350. 'T': 611,
  26351. 'U': 722,
  26352. 'V': 667,
  26353. 'W': 944,
  26354. 'X': 667,
  26355. 'Y': 667,
  26356. 'Z': 611,
  26357. 'bracketleft': 333,
  26358. 'backslash': 278,
  26359. 'bracketright': 333,
  26360. 'asciicircum': 584,
  26361. 'underscore': 556,
  26362. 'quoteleft': 278,
  26363. 'a': 556,
  26364. 'b': 611,
  26365. 'c': 556,
  26366. 'd': 611,
  26367. 'e': 556,
  26368. 'f': 333,
  26369. 'g': 611,
  26370. 'h': 611,
  26371. 'i': 278,
  26372. 'j': 278,
  26373. 'k': 556,
  26374. 'l': 278,
  26375. 'm': 889,
  26376. 'n': 611,
  26377. 'o': 611,
  26378. 'p': 611,
  26379. 'q': 611,
  26380. 'r': 389,
  26381. 's': 556,
  26382. 't': 333,
  26383. 'u': 611,
  26384. 'v': 556,
  26385. 'w': 778,
  26386. 'x': 556,
  26387. 'y': 556,
  26388. 'z': 500,
  26389. 'braceleft': 389,
  26390. 'bar': 280,
  26391. 'braceright': 389,
  26392. 'asciitilde': 584,
  26393. 'exclamdown': 333,
  26394. 'cent': 556,
  26395. 'sterling': 556,
  26396. 'fraction': 167,
  26397. 'yen': 556,
  26398. 'florin': 556,
  26399. 'section': 556,
  26400. 'currency': 556,
  26401. 'quotesingle': 238,
  26402. 'quotedblleft': 500,
  26403. 'guillemotleft': 556,
  26404. 'guilsinglleft': 333,
  26405. 'guilsinglright': 333,
  26406. 'fi': 611,
  26407. 'fl': 611,
  26408. 'endash': 556,
  26409. 'dagger': 556,
  26410. 'daggerdbl': 556,
  26411. 'periodcentered': 278,
  26412. 'paragraph': 556,
  26413. 'bullet': 350,
  26414. 'quotesinglbase': 278,
  26415. 'quotedblbase': 500,
  26416. 'quotedblright': 500,
  26417. 'guillemotright': 556,
  26418. 'ellipsis': 1000,
  26419. 'perthousand': 1000,
  26420. 'questiondown': 611,
  26421. 'grave': 333,
  26422. 'acute': 333,
  26423. 'circumflex': 333,
  26424. 'tilde': 333,
  26425. 'macron': 333,
  26426. 'breve': 333,
  26427. 'dotaccent': 333,
  26428. 'dieresis': 333,
  26429. 'ring': 333,
  26430. 'cedilla': 333,
  26431. 'hungarumlaut': 333,
  26432. 'ogonek': 333,
  26433. 'caron': 333,
  26434. 'emdash': 1000,
  26435. 'AE': 1000,
  26436. 'ordfeminine': 370,
  26437. 'Lslash': 611,
  26438. 'Oslash': 778,
  26439. 'OE': 1000,
  26440. 'ordmasculine': 365,
  26441. 'ae': 889,
  26442. 'dotlessi': 278,
  26443. 'lslash': 278,
  26444. 'oslash': 611,
  26445. 'oe': 944,
  26446. 'germandbls': 611,
  26447. 'Idieresis': 278,
  26448. 'eacute': 556,
  26449. 'abreve': 556,
  26450. 'uhungarumlaut': 611,
  26451. 'ecaron': 556,
  26452. 'Ydieresis': 667,
  26453. 'divide': 584,
  26454. 'Yacute': 667,
  26455. 'Acircumflex': 722,
  26456. 'aacute': 556,
  26457. 'Ucircumflex': 722,
  26458. 'yacute': 556,
  26459. 'scommaaccent': 556,
  26460. 'ecircumflex': 556,
  26461. 'Uring': 722,
  26462. 'Udieresis': 722,
  26463. 'aogonek': 556,
  26464. 'Uacute': 722,
  26465. 'uogonek': 611,
  26466. 'Edieresis': 667,
  26467. 'Dcroat': 722,
  26468. 'commaaccent': 250,
  26469. 'copyright': 737,
  26470. 'Emacron': 667,
  26471. 'ccaron': 556,
  26472. 'aring': 556,
  26473. 'Ncommaaccent': 722,
  26474. 'lacute': 278,
  26475. 'agrave': 556,
  26476. 'Tcommaaccent': 611,
  26477. 'Cacute': 722,
  26478. 'atilde': 556,
  26479. 'Edotaccent': 667,
  26480. 'scaron': 556,
  26481. 'scedilla': 556,
  26482. 'iacute': 278,
  26483. 'lozenge': 494,
  26484. 'Rcaron': 722,
  26485. 'Gcommaaccent': 778,
  26486. 'ucircumflex': 611,
  26487. 'acircumflex': 556,
  26488. 'Amacron': 722,
  26489. 'rcaron': 389,
  26490. 'ccedilla': 556,
  26491. 'Zdotaccent': 611,
  26492. 'Thorn': 667,
  26493. 'Omacron': 778,
  26494. 'Racute': 722,
  26495. 'Sacute': 667,
  26496. 'dcaron': 743,
  26497. 'Umacron': 722,
  26498. 'uring': 611,
  26499. 'threesuperior': 333,
  26500. 'Ograve': 778,
  26501. 'Agrave': 722,
  26502. 'Abreve': 722,
  26503. 'multiply': 584,
  26504. 'uacute': 611,
  26505. 'Tcaron': 611,
  26506. 'partialdiff': 494,
  26507. 'ydieresis': 556,
  26508. 'Nacute': 722,
  26509. 'icircumflex': 278,
  26510. 'Ecircumflex': 667,
  26511. 'adieresis': 556,
  26512. 'edieresis': 556,
  26513. 'cacute': 556,
  26514. 'nacute': 611,
  26515. 'umacron': 611,
  26516. 'Ncaron': 722,
  26517. 'Iacute': 278,
  26518. 'plusminus': 584,
  26519. 'brokenbar': 280,
  26520. 'registered': 737,
  26521. 'Gbreve': 778,
  26522. 'Idotaccent': 278,
  26523. 'summation': 600,
  26524. 'Egrave': 667,
  26525. 'racute': 389,
  26526. 'omacron': 611,
  26527. 'Zacute': 611,
  26528. 'Zcaron': 611,
  26529. 'greaterequal': 549,
  26530. 'Eth': 722,
  26531. 'Ccedilla': 722,
  26532. 'lcommaaccent': 278,
  26533. 'tcaron': 389,
  26534. 'eogonek': 556,
  26535. 'Uogonek': 722,
  26536. 'Aacute': 722,
  26537. 'Adieresis': 722,
  26538. 'egrave': 556,
  26539. 'zacute': 500,
  26540. 'iogonek': 278,
  26541. 'Oacute': 778,
  26542. 'oacute': 611,
  26543. 'amacron': 556,
  26544. 'sacute': 556,
  26545. 'idieresis': 278,
  26546. 'Ocircumflex': 778,
  26547. 'Ugrave': 722,
  26548. 'Delta': 612,
  26549. 'thorn': 611,
  26550. 'twosuperior': 333,
  26551. 'Odieresis': 778,
  26552. 'mu': 611,
  26553. 'igrave': 278,
  26554. 'ohungarumlaut': 611,
  26555. 'Eogonek': 667,
  26556. 'dcroat': 611,
  26557. 'threequarters': 834,
  26558. 'Scedilla': 667,
  26559. 'lcaron': 400,
  26560. 'Kcommaaccent': 722,
  26561. 'Lacute': 611,
  26562. 'trademark': 1000,
  26563. 'edotaccent': 556,
  26564. 'Igrave': 278,
  26565. 'Imacron': 278,
  26566. 'Lcaron': 611,
  26567. 'onehalf': 834,
  26568. 'lessequal': 549,
  26569. 'ocircumflex': 611,
  26570. 'ntilde': 611,
  26571. 'Uhungarumlaut': 722,
  26572. 'Eacute': 667,
  26573. 'emacron': 556,
  26574. 'gbreve': 611,
  26575. 'onequarter': 834,
  26576. 'Scaron': 667,
  26577. 'Scommaaccent': 667,
  26578. 'Ohungarumlaut': 778,
  26579. 'degree': 400,
  26580. 'ograve': 611,
  26581. 'Ccaron': 722,
  26582. 'ugrave': 611,
  26583. 'radical': 549,
  26584. 'Dcaron': 722,
  26585. 'rcommaaccent': 389,
  26586. 'Ntilde': 722,
  26587. 'otilde': 611,
  26588. 'Rcommaaccent': 722,
  26589. 'Lcommaaccent': 611,
  26590. 'Atilde': 722,
  26591. 'Aogonek': 722,
  26592. 'Aring': 722,
  26593. 'Otilde': 778,
  26594. 'zdotaccent': 500,
  26595. 'Ecaron': 667,
  26596. 'Iogonek': 278,
  26597. 'kcommaaccent': 556,
  26598. 'minus': 584,
  26599. 'Icircumflex': 278,
  26600. 'ncaron': 611,
  26601. 'tcommaaccent': 333,
  26602. 'logicalnot': 584,
  26603. 'odieresis': 611,
  26604. 'udieresis': 611,
  26605. 'notequal': 549,
  26606. 'gcommaaccent': 611,
  26607. 'eth': 611,
  26608. 'zcaron': 500,
  26609. 'ncommaaccent': 611,
  26610. 'onesuperior': 333,
  26611. 'imacron': 278,
  26612. 'Euro': 556
  26613. },
  26614. 'Helvetica-Oblique' : {
  26615. 'space': 278,
  26616. 'exclam': 278,
  26617. 'quotedbl': 355,
  26618. 'numbersign': 556,
  26619. 'dollar': 556,
  26620. 'percent': 889,
  26621. 'ampersand': 667,
  26622. 'quoteright': 222,
  26623. 'parenleft': 333,
  26624. 'parenright': 333,
  26625. 'asterisk': 389,
  26626. 'plus': 584,
  26627. 'comma': 278,
  26628. 'hyphen': 333,
  26629. 'period': 278,
  26630. 'slash': 278,
  26631. 'zero': 556,
  26632. 'one': 556,
  26633. 'two': 556,
  26634. 'three': 556,
  26635. 'four': 556,
  26636. 'five': 556,
  26637. 'six': 556,
  26638. 'seven': 556,
  26639. 'eight': 556,
  26640. 'nine': 556,
  26641. 'colon': 278,
  26642. 'semicolon': 278,
  26643. 'less': 584,
  26644. 'equal': 584,
  26645. 'greater': 584,
  26646. 'question': 556,
  26647. 'at': 1015,
  26648. 'A': 667,
  26649. 'B': 667,
  26650. 'C': 722,
  26651. 'D': 722,
  26652. 'E': 667,
  26653. 'F': 611,
  26654. 'G': 778,
  26655. 'H': 722,
  26656. 'I': 278,
  26657. 'J': 500,
  26658. 'K': 667,
  26659. 'L': 556,
  26660. 'M': 833,
  26661. 'N': 722,
  26662. 'O': 778,
  26663. 'P': 667,
  26664. 'Q': 778,
  26665. 'R': 722,
  26666. 'S': 667,
  26667. 'T': 611,
  26668. 'U': 722,
  26669. 'V': 667,
  26670. 'W': 944,
  26671. 'X': 667,
  26672. 'Y': 667,
  26673. 'Z': 611,
  26674. 'bracketleft': 278,
  26675. 'backslash': 278,
  26676. 'bracketright': 278,
  26677. 'asciicircum': 469,
  26678. 'underscore': 556,
  26679. 'quoteleft': 222,
  26680. 'a': 556,
  26681. 'b': 556,
  26682. 'c': 500,
  26683. 'd': 556,
  26684. 'e': 556,
  26685. 'f': 278,
  26686. 'g': 556,
  26687. 'h': 556,
  26688. 'i': 222,
  26689. 'j': 222,
  26690. 'k': 500,
  26691. 'l': 222,
  26692. 'm': 833,
  26693. 'n': 556,
  26694. 'o': 556,
  26695. 'p': 556,
  26696. 'q': 556,
  26697. 'r': 333,
  26698. 's': 500,
  26699. 't': 278,
  26700. 'u': 556,
  26701. 'v': 500,
  26702. 'w': 722,
  26703. 'x': 500,
  26704. 'y': 500,
  26705. 'z': 500,
  26706. 'braceleft': 334,
  26707. 'bar': 260,
  26708. 'braceright': 334,
  26709. 'asciitilde': 584,
  26710. 'exclamdown': 333,
  26711. 'cent': 556,
  26712. 'sterling': 556,
  26713. 'fraction': 167,
  26714. 'yen': 556,
  26715. 'florin': 556,
  26716. 'section': 556,
  26717. 'currency': 556,
  26718. 'quotesingle': 191,
  26719. 'quotedblleft': 333,
  26720. 'guillemotleft': 556,
  26721. 'guilsinglleft': 333,
  26722. 'guilsinglright': 333,
  26723. 'fi': 500,
  26724. 'fl': 500,
  26725. 'endash': 556,
  26726. 'dagger': 556,
  26727. 'daggerdbl': 556,
  26728. 'periodcentered': 278,
  26729. 'paragraph': 537,
  26730. 'bullet': 350,
  26731. 'quotesinglbase': 222,
  26732. 'quotedblbase': 333,
  26733. 'quotedblright': 333,
  26734. 'guillemotright': 556,
  26735. 'ellipsis': 1000,
  26736. 'perthousand': 1000,
  26737. 'questiondown': 611,
  26738. 'grave': 333,
  26739. 'acute': 333,
  26740. 'circumflex': 333,
  26741. 'tilde': 333,
  26742. 'macron': 333,
  26743. 'breve': 333,
  26744. 'dotaccent': 333,
  26745. 'dieresis': 333,
  26746. 'ring': 333,
  26747. 'cedilla': 333,
  26748. 'hungarumlaut': 333,
  26749. 'ogonek': 333,
  26750. 'caron': 333,
  26751. 'emdash': 1000,
  26752. 'AE': 1000,
  26753. 'ordfeminine': 370,
  26754. 'Lslash': 556,
  26755. 'Oslash': 778,
  26756. 'OE': 1000,
  26757. 'ordmasculine': 365,
  26758. 'ae': 889,
  26759. 'dotlessi': 278,
  26760. 'lslash': 222,
  26761. 'oslash': 611,
  26762. 'oe': 944,
  26763. 'germandbls': 611,
  26764. 'Idieresis': 278,
  26765. 'eacute': 556,
  26766. 'abreve': 556,
  26767. 'uhungarumlaut': 556,
  26768. 'ecaron': 556,
  26769. 'Ydieresis': 667,
  26770. 'divide': 584,
  26771. 'Yacute': 667,
  26772. 'Acircumflex': 667,
  26773. 'aacute': 556,
  26774. 'Ucircumflex': 722,
  26775. 'yacute': 500,
  26776. 'scommaaccent': 500,
  26777. 'ecircumflex': 556,
  26778. 'Uring': 722,
  26779. 'Udieresis': 722,
  26780. 'aogonek': 556,
  26781. 'Uacute': 722,
  26782. 'uogonek': 556,
  26783. 'Edieresis': 667,
  26784. 'Dcroat': 722,
  26785. 'commaaccent': 250,
  26786. 'copyright': 737,
  26787. 'Emacron': 667,
  26788. 'ccaron': 500,
  26789. 'aring': 556,
  26790. 'Ncommaaccent': 722,
  26791. 'lacute': 222,
  26792. 'agrave': 556,
  26793. 'Tcommaaccent': 611,
  26794. 'Cacute': 722,
  26795. 'atilde': 556,
  26796. 'Edotaccent': 667,
  26797. 'scaron': 500,
  26798. 'scedilla': 500,
  26799. 'iacute': 278,
  26800. 'lozenge': 471,
  26801. 'Rcaron': 722,
  26802. 'Gcommaaccent': 778,
  26803. 'ucircumflex': 556,
  26804. 'acircumflex': 556,
  26805. 'Amacron': 667,
  26806. 'rcaron': 333,
  26807. 'ccedilla': 500,
  26808. 'Zdotaccent': 611,
  26809. 'Thorn': 667,
  26810. 'Omacron': 778,
  26811. 'Racute': 722,
  26812. 'Sacute': 667,
  26813. 'dcaron': 643,
  26814. 'Umacron': 722,
  26815. 'uring': 556,
  26816. 'threesuperior': 333,
  26817. 'Ograve': 778,
  26818. 'Agrave': 667,
  26819. 'Abreve': 667,
  26820. 'multiply': 584,
  26821. 'uacute': 556,
  26822. 'Tcaron': 611,
  26823. 'partialdiff': 476,
  26824. 'ydieresis': 500,
  26825. 'Nacute': 722,
  26826. 'icircumflex': 278,
  26827. 'Ecircumflex': 667,
  26828. 'adieresis': 556,
  26829. 'edieresis': 556,
  26830. 'cacute': 500,
  26831. 'nacute': 556,
  26832. 'umacron': 556,
  26833. 'Ncaron': 722,
  26834. 'Iacute': 278,
  26835. 'plusminus': 584,
  26836. 'brokenbar': 260,
  26837. 'registered': 737,
  26838. 'Gbreve': 778,
  26839. 'Idotaccent': 278,
  26840. 'summation': 600,
  26841. 'Egrave': 667,
  26842. 'racute': 333,
  26843. 'omacron': 556,
  26844. 'Zacute': 611,
  26845. 'Zcaron': 611,
  26846. 'greaterequal': 549,
  26847. 'Eth': 722,
  26848. 'Ccedilla': 722,
  26849. 'lcommaaccent': 222,
  26850. 'tcaron': 317,
  26851. 'eogonek': 556,
  26852. 'Uogonek': 722,
  26853. 'Aacute': 667,
  26854. 'Adieresis': 667,
  26855. 'egrave': 556,
  26856. 'zacute': 500,
  26857. 'iogonek': 222,
  26858. 'Oacute': 778,
  26859. 'oacute': 556,
  26860. 'amacron': 556,
  26861. 'sacute': 500,
  26862. 'idieresis': 278,
  26863. 'Ocircumflex': 778,
  26864. 'Ugrave': 722,
  26865. 'Delta': 612,
  26866. 'thorn': 556,
  26867. 'twosuperior': 333,
  26868. 'Odieresis': 778,
  26869. 'mu': 556,
  26870. 'igrave': 278,
  26871. 'ohungarumlaut': 556,
  26872. 'Eogonek': 667,
  26873. 'dcroat': 556,
  26874. 'threequarters': 834,
  26875. 'Scedilla': 667,
  26876. 'lcaron': 299,
  26877. 'Kcommaaccent': 667,
  26878. 'Lacute': 556,
  26879. 'trademark': 1000,
  26880. 'edotaccent': 556,
  26881. 'Igrave': 278,
  26882. 'Imacron': 278,
  26883. 'Lcaron': 556,
  26884. 'onehalf': 834,
  26885. 'lessequal': 549,
  26886. 'ocircumflex': 556,
  26887. 'ntilde': 556,
  26888. 'Uhungarumlaut': 722,
  26889. 'Eacute': 667,
  26890. 'emacron': 556,
  26891. 'gbreve': 556,
  26892. 'onequarter': 834,
  26893. 'Scaron': 667,
  26894. 'Scommaaccent': 667,
  26895. 'Ohungarumlaut': 778,
  26896. 'degree': 400,
  26897. 'ograve': 556,
  26898. 'Ccaron': 722,
  26899. 'ugrave': 556,
  26900. 'radical': 453,
  26901. 'Dcaron': 722,
  26902. 'rcommaaccent': 333,
  26903. 'Ntilde': 722,
  26904. 'otilde': 556,
  26905. 'Rcommaaccent': 722,
  26906. 'Lcommaaccent': 556,
  26907. 'Atilde': 667,
  26908. 'Aogonek': 667,
  26909. 'Aring': 667,
  26910. 'Otilde': 778,
  26911. 'zdotaccent': 500,
  26912. 'Ecaron': 667,
  26913. 'Iogonek': 278,
  26914. 'kcommaaccent': 500,
  26915. 'minus': 584,
  26916. 'Icircumflex': 278,
  26917. 'ncaron': 556,
  26918. 'tcommaaccent': 278,
  26919. 'logicalnot': 584,
  26920. 'odieresis': 556,
  26921. 'udieresis': 556,
  26922. 'notequal': 549,
  26923. 'gcommaaccent': 556,
  26924. 'eth': 556,
  26925. 'zcaron': 500,
  26926. 'ncommaaccent': 556,
  26927. 'onesuperior': 333,
  26928. 'imacron': 278,
  26929. 'Euro': 556
  26930. },
  26931. 'Symbol': {
  26932. 'space': 250,
  26933. 'exclam': 333,
  26934. 'universal': 713,
  26935. 'numbersign': 500,
  26936. 'existential': 549,
  26937. 'percent': 833,
  26938. 'ampersand': 778,
  26939. 'suchthat': 439,
  26940. 'parenleft': 333,
  26941. 'parenright': 333,
  26942. 'asteriskmath': 500,
  26943. 'plus': 549,
  26944. 'comma': 250,
  26945. 'minus': 549,
  26946. 'period': 250,
  26947. 'slash': 278,
  26948. 'zero': 500,
  26949. 'one': 500,
  26950. 'two': 500,
  26951. 'three': 500,
  26952. 'four': 500,
  26953. 'five': 500,
  26954. 'six': 500,
  26955. 'seven': 500,
  26956. 'eight': 500,
  26957. 'nine': 500,
  26958. 'colon': 278,
  26959. 'semicolon': 278,
  26960. 'less': 549,
  26961. 'equal': 549,
  26962. 'greater': 549,
  26963. 'question': 444,
  26964. 'congruent': 549,
  26965. 'Alpha': 722,
  26966. 'Beta': 667,
  26967. 'Chi': 722,
  26968. 'Delta': 612,
  26969. 'Epsilon': 611,
  26970. 'Phi': 763,
  26971. 'Gamma': 603,
  26972. 'Eta': 722,
  26973. 'Iota': 333,
  26974. 'theta1': 631,
  26975. 'Kappa': 722,
  26976. 'Lambda': 686,
  26977. 'Mu': 889,
  26978. 'Nu': 722,
  26979. 'Omicron': 722,
  26980. 'Pi': 768,
  26981. 'Theta': 741,
  26982. 'Rho': 556,
  26983. 'Sigma': 592,
  26984. 'Tau': 611,
  26985. 'Upsilon': 690,
  26986. 'sigma1': 439,
  26987. 'Omega': 768,
  26988. 'Xi': 645,
  26989. 'Psi': 795,
  26990. 'Zeta': 611,
  26991. 'bracketleft': 333,
  26992. 'therefore': 863,
  26993. 'bracketright': 333,
  26994. 'perpendicular': 658,
  26995. 'underscore': 500,
  26996. 'radicalex': 500,
  26997. 'alpha': 631,
  26998. 'beta': 549,
  26999. 'chi': 549,
  27000. 'delta': 494,
  27001. 'epsilon': 439,
  27002. 'phi': 521,
  27003. 'gamma': 411,
  27004. 'eta': 603,
  27005. 'iota': 329,
  27006. 'phi1': 603,
  27007. 'kappa': 549,
  27008. 'lambda': 549,
  27009. 'mu': 576,
  27010. 'nu': 521,
  27011. 'omicron': 549,
  27012. 'pi': 549,
  27013. 'theta': 521,
  27014. 'rho': 549,
  27015. 'sigma': 603,
  27016. 'tau': 439,
  27017. 'upsilon': 576,
  27018. 'omega1': 713,
  27019. 'omega': 686,
  27020. 'xi': 493,
  27021. 'psi': 686,
  27022. 'zeta': 494,
  27023. 'braceleft': 480,
  27024. 'bar': 200,
  27025. 'braceright': 480,
  27026. 'similar': 549,
  27027. 'Euro': 750,
  27028. 'Upsilon1': 620,
  27029. 'minute': 247,
  27030. 'lessequal': 549,
  27031. 'fraction': 167,
  27032. 'infinity': 713,
  27033. 'florin': 500,
  27034. 'club': 753,
  27035. 'diamond': 753,
  27036. 'heart': 753,
  27037. 'spade': 753,
  27038. 'arrowboth': 1042,
  27039. 'arrowleft': 987,
  27040. 'arrowup': 603,
  27041. 'arrowright': 987,
  27042. 'arrowdown': 603,
  27043. 'degree': 400,
  27044. 'plusminus': 549,
  27045. 'second': 411,
  27046. 'greaterequal': 549,
  27047. 'multiply': 549,
  27048. 'proportional': 713,
  27049. 'partialdiff': 494,
  27050. 'bullet': 460,
  27051. 'divide': 549,
  27052. 'notequal': 549,
  27053. 'equivalence': 549,
  27054. 'approxequal': 549,
  27055. 'ellipsis': 1000,
  27056. 'arrowvertex': 603,
  27057. 'arrowhorizex': 1000,
  27058. 'carriagereturn': 658,
  27059. 'aleph': 823,
  27060. 'Ifraktur': 686,
  27061. 'Rfraktur': 795,
  27062. 'weierstrass': 987,
  27063. 'circlemultiply': 768,
  27064. 'circleplus': 768,
  27065. 'emptyset': 823,
  27066. 'intersection': 768,
  27067. 'union': 768,
  27068. 'propersuperset': 713,
  27069. 'reflexsuperset': 713,
  27070. 'notsubset': 713,
  27071. 'propersubset': 713,
  27072. 'reflexsubset': 713,
  27073. 'element': 713,
  27074. 'notelement': 713,
  27075. 'angle': 768,
  27076. 'gradient': 713,
  27077. 'registerserif': 790,
  27078. 'copyrightserif': 790,
  27079. 'trademarkserif': 890,
  27080. 'product': 823,
  27081. 'radical': 549,
  27082. 'dotmath': 250,
  27083. 'logicalnot': 713,
  27084. 'logicaland': 603,
  27085. 'logicalor': 603,
  27086. 'arrowdblboth': 1042,
  27087. 'arrowdblleft': 987,
  27088. 'arrowdblup': 603,
  27089. 'arrowdblright': 987,
  27090. 'arrowdbldown': 603,
  27091. 'lozenge': 494,
  27092. 'angleleft': 329,
  27093. 'registersans': 790,
  27094. 'copyrightsans': 790,
  27095. 'trademarksans': 786,
  27096. 'summation': 713,
  27097. 'parenlefttp': 384,
  27098. 'parenleftex': 384,
  27099. 'parenleftbt': 384,
  27100. 'bracketlefttp': 384,
  27101. 'bracketleftex': 384,
  27102. 'bracketleftbt': 384,
  27103. 'bracelefttp': 494,
  27104. 'braceleftmid': 494,
  27105. 'braceleftbt': 494,
  27106. 'braceex': 494,
  27107. 'angleright': 329,
  27108. 'integral': 274,
  27109. 'integraltp': 686,
  27110. 'integralex': 686,
  27111. 'integralbt': 686,
  27112. 'parenrighttp': 384,
  27113. 'parenrightex': 384,
  27114. 'parenrightbt': 384,
  27115. 'bracketrighttp': 384,
  27116. 'bracketrightex': 384,
  27117. 'bracketrightbt': 384,
  27118. 'bracerighttp': 494,
  27119. 'bracerightmid': 494,
  27120. 'bracerightbt': 494,
  27121. 'apple': 790
  27122. },
  27123. 'Times-Roman': {
  27124. 'space': 250,
  27125. 'exclam': 333,
  27126. 'quotedbl': 408,
  27127. 'numbersign': 500,
  27128. 'dollar': 500,
  27129. 'percent': 833,
  27130. 'ampersand': 778,
  27131. 'quoteright': 333,
  27132. 'parenleft': 333,
  27133. 'parenright': 333,
  27134. 'asterisk': 500,
  27135. 'plus': 564,
  27136. 'comma': 250,
  27137. 'hyphen': 333,
  27138. 'period': 250,
  27139. 'slash': 278,
  27140. 'zero': 500,
  27141. 'one': 500,
  27142. 'two': 500,
  27143. 'three': 500,
  27144. 'four': 500,
  27145. 'five': 500,
  27146. 'six': 500,
  27147. 'seven': 500,
  27148. 'eight': 500,
  27149. 'nine': 500,
  27150. 'colon': 278,
  27151. 'semicolon': 278,
  27152. 'less': 564,
  27153. 'equal': 564,
  27154. 'greater': 564,
  27155. 'question': 444,
  27156. 'at': 921,
  27157. 'A': 722,
  27158. 'B': 667,
  27159. 'C': 667,
  27160. 'D': 722,
  27161. 'E': 611,
  27162. 'F': 556,
  27163. 'G': 722,
  27164. 'H': 722,
  27165. 'I': 333,
  27166. 'J': 389,
  27167. 'K': 722,
  27168. 'L': 611,
  27169. 'M': 889,
  27170. 'N': 722,
  27171. 'O': 722,
  27172. 'P': 556,
  27173. 'Q': 722,
  27174. 'R': 667,
  27175. 'S': 556,
  27176. 'T': 611,
  27177. 'U': 722,
  27178. 'V': 722,
  27179. 'W': 944,
  27180. 'X': 722,
  27181. 'Y': 722,
  27182. 'Z': 611,
  27183. 'bracketleft': 333,
  27184. 'backslash': 278,
  27185. 'bracketright': 333,
  27186. 'asciicircum': 469,
  27187. 'underscore': 500,
  27188. 'quoteleft': 333,
  27189. 'a': 444,
  27190. 'b': 500,
  27191. 'c': 444,
  27192. 'd': 500,
  27193. 'e': 444,
  27194. 'f': 333,
  27195. 'g': 500,
  27196. 'h': 500,
  27197. 'i': 278,
  27198. 'j': 278,
  27199. 'k': 500,
  27200. 'l': 278,
  27201. 'm': 778,
  27202. 'n': 500,
  27203. 'o': 500,
  27204. 'p': 500,
  27205. 'q': 500,
  27206. 'r': 333,
  27207. 's': 389,
  27208. 't': 278,
  27209. 'u': 500,
  27210. 'v': 500,
  27211. 'w': 722,
  27212. 'x': 500,
  27213. 'y': 500,
  27214. 'z': 444,
  27215. 'braceleft': 480,
  27216. 'bar': 200,
  27217. 'braceright': 480,
  27218. 'asciitilde': 541,
  27219. 'exclamdown': 333,
  27220. 'cent': 500,
  27221. 'sterling': 500,
  27222. 'fraction': 167,
  27223. 'yen': 500,
  27224. 'florin': 500,
  27225. 'section': 500,
  27226. 'currency': 500,
  27227. 'quotesingle': 180,
  27228. 'quotedblleft': 444,
  27229. 'guillemotleft': 500,
  27230. 'guilsinglleft': 333,
  27231. 'guilsinglright': 333,
  27232. 'fi': 556,
  27233. 'fl': 556,
  27234. 'endash': 500,
  27235. 'dagger': 500,
  27236. 'daggerdbl': 500,
  27237. 'periodcentered': 250,
  27238. 'paragraph': 453,
  27239. 'bullet': 350,
  27240. 'quotesinglbase': 333,
  27241. 'quotedblbase': 444,
  27242. 'quotedblright': 444,
  27243. 'guillemotright': 500,
  27244. 'ellipsis': 1000,
  27245. 'perthousand': 1000,
  27246. 'questiondown': 444,
  27247. 'grave': 333,
  27248. 'acute': 333,
  27249. 'circumflex': 333,
  27250. 'tilde': 333,
  27251. 'macron': 333,
  27252. 'breve': 333,
  27253. 'dotaccent': 333,
  27254. 'dieresis': 333,
  27255. 'ring': 333,
  27256. 'cedilla': 333,
  27257. 'hungarumlaut': 333,
  27258. 'ogonek': 333,
  27259. 'caron': 333,
  27260. 'emdash': 1000,
  27261. 'AE': 889,
  27262. 'ordfeminine': 276,
  27263. 'Lslash': 611,
  27264. 'Oslash': 722,
  27265. 'OE': 889,
  27266. 'ordmasculine': 310,
  27267. 'ae': 667,
  27268. 'dotlessi': 278,
  27269. 'lslash': 278,
  27270. 'oslash': 500,
  27271. 'oe': 722,
  27272. 'germandbls': 500,
  27273. 'Idieresis': 333,
  27274. 'eacute': 444,
  27275. 'abreve': 444,
  27276. 'uhungarumlaut': 500,
  27277. 'ecaron': 444,
  27278. 'Ydieresis': 722,
  27279. 'divide': 564,
  27280. 'Yacute': 722,
  27281. 'Acircumflex': 722,
  27282. 'aacute': 444,
  27283. 'Ucircumflex': 722,
  27284. 'yacute': 500,
  27285. 'scommaaccent': 389,
  27286. 'ecircumflex': 444,
  27287. 'Uring': 722,
  27288. 'Udieresis': 722,
  27289. 'aogonek': 444,
  27290. 'Uacute': 722,
  27291. 'uogonek': 500,
  27292. 'Edieresis': 611,
  27293. 'Dcroat': 722,
  27294. 'commaaccent': 250,
  27295. 'copyright': 760,
  27296. 'Emacron': 611,
  27297. 'ccaron': 444,
  27298. 'aring': 444,
  27299. 'Ncommaaccent': 722,
  27300. 'lacute': 278,
  27301. 'agrave': 444,
  27302. 'Tcommaaccent': 611,
  27303. 'Cacute': 667,
  27304. 'atilde': 444,
  27305. 'Edotaccent': 611,
  27306. 'scaron': 389,
  27307. 'scedilla': 389,
  27308. 'iacute': 278,
  27309. 'lozenge': 471,
  27310. 'Rcaron': 667,
  27311. 'Gcommaaccent': 722,
  27312. 'ucircumflex': 500,
  27313. 'acircumflex': 444,
  27314. 'Amacron': 722,
  27315. 'rcaron': 333,
  27316. 'ccedilla': 444,
  27317. 'Zdotaccent': 611,
  27318. 'Thorn': 556,
  27319. 'Omacron': 722,
  27320. 'Racute': 667,
  27321. 'Sacute': 556,
  27322. 'dcaron': 588,
  27323. 'Umacron': 722,
  27324. 'uring': 500,
  27325. 'threesuperior': 300,
  27326. 'Ograve': 722,
  27327. 'Agrave': 722,
  27328. 'Abreve': 722,
  27329. 'multiply': 564,
  27330. 'uacute': 500,
  27331. 'Tcaron': 611,
  27332. 'partialdiff': 476,
  27333. 'ydieresis': 500,
  27334. 'Nacute': 722,
  27335. 'icircumflex': 278,
  27336. 'Ecircumflex': 611,
  27337. 'adieresis': 444,
  27338. 'edieresis': 444,
  27339. 'cacute': 444,
  27340. 'nacute': 500,
  27341. 'umacron': 500,
  27342. 'Ncaron': 722,
  27343. 'Iacute': 333,
  27344. 'plusminus': 564,
  27345. 'brokenbar': 200,
  27346. 'registered': 760,
  27347. 'Gbreve': 722,
  27348. 'Idotaccent': 333,
  27349. 'summation': 600,
  27350. 'Egrave': 611,
  27351. 'racute': 333,
  27352. 'omacron': 500,
  27353. 'Zacute': 611,
  27354. 'Zcaron': 611,
  27355. 'greaterequal': 549,
  27356. 'Eth': 722,
  27357. 'Ccedilla': 667,
  27358. 'lcommaaccent': 278,
  27359. 'tcaron': 326,
  27360. 'eogonek': 444,
  27361. 'Uogonek': 722,
  27362. 'Aacute': 722,
  27363. 'Adieresis': 722,
  27364. 'egrave': 444,
  27365. 'zacute': 444,
  27366. 'iogonek': 278,
  27367. 'Oacute': 722,
  27368. 'oacute': 500,
  27369. 'amacron': 444,
  27370. 'sacute': 389,
  27371. 'idieresis': 278,
  27372. 'Ocircumflex': 722,
  27373. 'Ugrave': 722,
  27374. 'Delta': 612,
  27375. 'thorn': 500,
  27376. 'twosuperior': 300,
  27377. 'Odieresis': 722,
  27378. 'mu': 500,
  27379. 'igrave': 278,
  27380. 'ohungarumlaut': 500,
  27381. 'Eogonek': 611,
  27382. 'dcroat': 500,
  27383. 'threequarters': 750,
  27384. 'Scedilla': 556,
  27385. 'lcaron': 344,
  27386. 'Kcommaaccent': 722,
  27387. 'Lacute': 611,
  27388. 'trademark': 980,
  27389. 'edotaccent': 444,
  27390. 'Igrave': 333,
  27391. 'Imacron': 333,
  27392. 'Lcaron': 611,
  27393. 'onehalf': 750,
  27394. 'lessequal': 549,
  27395. 'ocircumflex': 500,
  27396. 'ntilde': 500,
  27397. 'Uhungarumlaut': 722,
  27398. 'Eacute': 611,
  27399. 'emacron': 444,
  27400. 'gbreve': 500,
  27401. 'onequarter': 750,
  27402. 'Scaron': 556,
  27403. 'Scommaaccent': 556,
  27404. 'Ohungarumlaut': 722,
  27405. 'degree': 400,
  27406. 'ograve': 500,
  27407. 'Ccaron': 667,
  27408. 'ugrave': 500,
  27409. 'radical': 453,
  27410. 'Dcaron': 722,
  27411. 'rcommaaccent': 333,
  27412. 'Ntilde': 722,
  27413. 'otilde': 500,
  27414. 'Rcommaaccent': 667,
  27415. 'Lcommaaccent': 611,
  27416. 'Atilde': 722,
  27417. 'Aogonek': 722,
  27418. 'Aring': 722,
  27419. 'Otilde': 722,
  27420. 'zdotaccent': 444,
  27421. 'Ecaron': 611,
  27422. 'Iogonek': 333,
  27423. 'kcommaaccent': 500,
  27424. 'minus': 564,
  27425. 'Icircumflex': 333,
  27426. 'ncaron': 500,
  27427. 'tcommaaccent': 278,
  27428. 'logicalnot': 564,
  27429. 'odieresis': 500,
  27430. 'udieresis': 500,
  27431. 'notequal': 549,
  27432. 'gcommaaccent': 500,
  27433. 'eth': 500,
  27434. 'zcaron': 444,
  27435. 'ncommaaccent': 500,
  27436. 'onesuperior': 300,
  27437. 'imacron': 278,
  27438. 'Euro': 500
  27439. },
  27440. 'Times-Bold': {
  27441. 'space': 250,
  27442. 'exclam': 333,
  27443. 'quotedbl': 555,
  27444. 'numbersign': 500,
  27445. 'dollar': 500,
  27446. 'percent': 1000,
  27447. 'ampersand': 833,
  27448. 'quoteright': 333,
  27449. 'parenleft': 333,
  27450. 'parenright': 333,
  27451. 'asterisk': 500,
  27452. 'plus': 570,
  27453. 'comma': 250,
  27454. 'hyphen': 333,
  27455. 'period': 250,
  27456. 'slash': 278,
  27457. 'zero': 500,
  27458. 'one': 500,
  27459. 'two': 500,
  27460. 'three': 500,
  27461. 'four': 500,
  27462. 'five': 500,
  27463. 'six': 500,
  27464. 'seven': 500,
  27465. 'eight': 500,
  27466. 'nine': 500,
  27467. 'colon': 333,
  27468. 'semicolon': 333,
  27469. 'less': 570,
  27470. 'equal': 570,
  27471. 'greater': 570,
  27472. 'question': 500,
  27473. 'at': 930,
  27474. 'A': 722,
  27475. 'B': 667,
  27476. 'C': 722,
  27477. 'D': 722,
  27478. 'E': 667,
  27479. 'F': 611,
  27480. 'G': 778,
  27481. 'H': 778,
  27482. 'I': 389,
  27483. 'J': 500,
  27484. 'K': 778,
  27485. 'L': 667,
  27486. 'M': 944,
  27487. 'N': 722,
  27488. 'O': 778,
  27489. 'P': 611,
  27490. 'Q': 778,
  27491. 'R': 722,
  27492. 'S': 556,
  27493. 'T': 667,
  27494. 'U': 722,
  27495. 'V': 722,
  27496. 'W': 1000,
  27497. 'X': 722,
  27498. 'Y': 722,
  27499. 'Z': 667,
  27500. 'bracketleft': 333,
  27501. 'backslash': 278,
  27502. 'bracketright': 333,
  27503. 'asciicircum': 581,
  27504. 'underscore': 500,
  27505. 'quoteleft': 333,
  27506. 'a': 500,
  27507. 'b': 556,
  27508. 'c': 444,
  27509. 'd': 556,
  27510. 'e': 444,
  27511. 'f': 333,
  27512. 'g': 500,
  27513. 'h': 556,
  27514. 'i': 278,
  27515. 'j': 333,
  27516. 'k': 556,
  27517. 'l': 278,
  27518. 'm': 833,
  27519. 'n': 556,
  27520. 'o': 500,
  27521. 'p': 556,
  27522. 'q': 556,
  27523. 'r': 444,
  27524. 's': 389,
  27525. 't': 333,
  27526. 'u': 556,
  27527. 'v': 500,
  27528. 'w': 722,
  27529. 'x': 500,
  27530. 'y': 500,
  27531. 'z': 444,
  27532. 'braceleft': 394,
  27533. 'bar': 220,
  27534. 'braceright': 394,
  27535. 'asciitilde': 520,
  27536. 'exclamdown': 333,
  27537. 'cent': 500,
  27538. 'sterling': 500,
  27539. 'fraction': 167,
  27540. 'yen': 500,
  27541. 'florin': 500,
  27542. 'section': 500,
  27543. 'currency': 500,
  27544. 'quotesingle': 278,
  27545. 'quotedblleft': 500,
  27546. 'guillemotleft': 500,
  27547. 'guilsinglleft': 333,
  27548. 'guilsinglright': 333,
  27549. 'fi': 556,
  27550. 'fl': 556,
  27551. 'endash': 500,
  27552. 'dagger': 500,
  27553. 'daggerdbl': 500,
  27554. 'periodcentered': 250,
  27555. 'paragraph': 540,
  27556. 'bullet': 350,
  27557. 'quotesinglbase': 333,
  27558. 'quotedblbase': 500,
  27559. 'quotedblright': 500,
  27560. 'guillemotright': 500,
  27561. 'ellipsis': 1000,
  27562. 'perthousand': 1000,
  27563. 'questiondown': 500,
  27564. 'grave': 333,
  27565. 'acute': 333,
  27566. 'circumflex': 333,
  27567. 'tilde': 333,
  27568. 'macron': 333,
  27569. 'breve': 333,
  27570. 'dotaccent': 333,
  27571. 'dieresis': 333,
  27572. 'ring': 333,
  27573. 'cedilla': 333,
  27574. 'hungarumlaut': 333,
  27575. 'ogonek': 333,
  27576. 'caron': 333,
  27577. 'emdash': 1000,
  27578. 'AE': 1000,
  27579. 'ordfeminine': 300,
  27580. 'Lslash': 667,
  27581. 'Oslash': 778,
  27582. 'OE': 1000,
  27583. 'ordmasculine': 330,
  27584. 'ae': 722,
  27585. 'dotlessi': 278,
  27586. 'lslash': 278,
  27587. 'oslash': 500,
  27588. 'oe': 722,
  27589. 'germandbls': 556,
  27590. 'Idieresis': 389,
  27591. 'eacute': 444,
  27592. 'abreve': 500,
  27593. 'uhungarumlaut': 556,
  27594. 'ecaron': 444,
  27595. 'Ydieresis': 722,
  27596. 'divide': 570,
  27597. 'Yacute': 722,
  27598. 'Acircumflex': 722,
  27599. 'aacute': 500,
  27600. 'Ucircumflex': 722,
  27601. 'yacute': 500,
  27602. 'scommaaccent': 389,
  27603. 'ecircumflex': 444,
  27604. 'Uring': 722,
  27605. 'Udieresis': 722,
  27606. 'aogonek': 500,
  27607. 'Uacute': 722,
  27608. 'uogonek': 556,
  27609. 'Edieresis': 667,
  27610. 'Dcroat': 722,
  27611. 'commaaccent': 250,
  27612. 'copyright': 747,
  27613. 'Emacron': 667,
  27614. 'ccaron': 444,
  27615. 'aring': 500,
  27616. 'Ncommaaccent': 722,
  27617. 'lacute': 278,
  27618. 'agrave': 500,
  27619. 'Tcommaaccent': 667,
  27620. 'Cacute': 722,
  27621. 'atilde': 500,
  27622. 'Edotaccent': 667,
  27623. 'scaron': 389,
  27624. 'scedilla': 389,
  27625. 'iacute': 278,
  27626. 'lozenge': 494,
  27627. 'Rcaron': 722,
  27628. 'Gcommaaccent': 778,
  27629. 'ucircumflex': 556,
  27630. 'acircumflex': 500,
  27631. 'Amacron': 722,
  27632. 'rcaron': 444,
  27633. 'ccedilla': 444,
  27634. 'Zdotaccent': 667,
  27635. 'Thorn': 611,
  27636. 'Omacron': 778,
  27637. 'Racute': 722,
  27638. 'Sacute': 556,
  27639. 'dcaron': 672,
  27640. 'Umacron': 722,
  27641. 'uring': 556,
  27642. 'threesuperior': 300,
  27643. 'Ograve': 778,
  27644. 'Agrave': 722,
  27645. 'Abreve': 722,
  27646. 'multiply': 570,
  27647. 'uacute': 556,
  27648. 'Tcaron': 667,
  27649. 'partialdiff': 494,
  27650. 'ydieresis': 500,
  27651. 'Nacute': 722,
  27652. 'icircumflex': 278,
  27653. 'Ecircumflex': 667,
  27654. 'adieresis': 500,
  27655. 'edieresis': 444,
  27656. 'cacute': 444,
  27657. 'nacute': 556,
  27658. 'umacron': 556,
  27659. 'Ncaron': 722,
  27660. 'Iacute': 389,
  27661. 'plusminus': 570,
  27662. 'brokenbar': 220,
  27663. 'registered': 747,
  27664. 'Gbreve': 778,
  27665. 'Idotaccent': 389,
  27666. 'summation': 600,
  27667. 'Egrave': 667,
  27668. 'racute': 444,
  27669. 'omacron': 500,
  27670. 'Zacute': 667,
  27671. 'Zcaron': 667,
  27672. 'greaterequal': 549,
  27673. 'Eth': 722,
  27674. 'Ccedilla': 722,
  27675. 'lcommaaccent': 278,
  27676. 'tcaron': 416,
  27677. 'eogonek': 444,
  27678. 'Uogonek': 722,
  27679. 'Aacute': 722,
  27680. 'Adieresis': 722,
  27681. 'egrave': 444,
  27682. 'zacute': 444,
  27683. 'iogonek': 278,
  27684. 'Oacute': 778,
  27685. 'oacute': 500,
  27686. 'amacron': 500,
  27687. 'sacute': 389,
  27688. 'idieresis': 278,
  27689. 'Ocircumflex': 778,
  27690. 'Ugrave': 722,
  27691. 'Delta': 612,
  27692. 'thorn': 556,
  27693. 'twosuperior': 300,
  27694. 'Odieresis': 778,
  27695. 'mu': 556,
  27696. 'igrave': 278,
  27697. 'ohungarumlaut': 500,
  27698. 'Eogonek': 667,
  27699. 'dcroat': 556,
  27700. 'threequarters': 750,
  27701. 'Scedilla': 556,
  27702. 'lcaron': 394,
  27703. 'Kcommaaccent': 778,
  27704. 'Lacute': 667,
  27705. 'trademark': 1000,
  27706. 'edotaccent': 444,
  27707. 'Igrave': 389,
  27708. 'Imacron': 389,
  27709. 'Lcaron': 667,
  27710. 'onehalf': 750,
  27711. 'lessequal': 549,
  27712. 'ocircumflex': 500,
  27713. 'ntilde': 556,
  27714. 'Uhungarumlaut': 722,
  27715. 'Eacute': 667,
  27716. 'emacron': 444,
  27717. 'gbreve': 500,
  27718. 'onequarter': 750,
  27719. 'Scaron': 556,
  27720. 'Scommaaccent': 556,
  27721. 'Ohungarumlaut': 778,
  27722. 'degree': 400,
  27723. 'ograve': 500,
  27724. 'Ccaron': 722,
  27725. 'ugrave': 556,
  27726. 'radical': 549,
  27727. 'Dcaron': 722,
  27728. 'rcommaaccent': 444,
  27729. 'Ntilde': 722,
  27730. 'otilde': 500,
  27731. 'Rcommaaccent': 722,
  27732. 'Lcommaaccent': 667,
  27733. 'Atilde': 722,
  27734. 'Aogonek': 722,
  27735. 'Aring': 722,
  27736. 'Otilde': 778,
  27737. 'zdotaccent': 444,
  27738. 'Ecaron': 667,
  27739. 'Iogonek': 389,
  27740. 'kcommaaccent': 556,
  27741. 'minus': 570,
  27742. 'Icircumflex': 389,
  27743. 'ncaron': 556,
  27744. 'tcommaaccent': 333,
  27745. 'logicalnot': 570,
  27746. 'odieresis': 500,
  27747. 'udieresis': 556,
  27748. 'notequal': 549,
  27749. 'gcommaaccent': 500,
  27750. 'eth': 500,
  27751. 'zcaron': 444,
  27752. 'ncommaaccent': 556,
  27753. 'onesuperior': 300,
  27754. 'imacron': 278,
  27755. 'Euro': 500
  27756. },
  27757. 'Times-BoldItalic': {
  27758. 'space': 250,
  27759. 'exclam': 389,
  27760. 'quotedbl': 555,
  27761. 'numbersign': 500,
  27762. 'dollar': 500,
  27763. 'percent': 833,
  27764. 'ampersand': 778,
  27765. 'quoteright': 333,
  27766. 'parenleft': 333,
  27767. 'parenright': 333,
  27768. 'asterisk': 500,
  27769. 'plus': 570,
  27770. 'comma': 250,
  27771. 'hyphen': 333,
  27772. 'period': 250,
  27773. 'slash': 278,
  27774. 'zero': 500,
  27775. 'one': 500,
  27776. 'two': 500,
  27777. 'three': 500,
  27778. 'four': 500,
  27779. 'five': 500,
  27780. 'six': 500,
  27781. 'seven': 500,
  27782. 'eight': 500,
  27783. 'nine': 500,
  27784. 'colon': 333,
  27785. 'semicolon': 333,
  27786. 'less': 570,
  27787. 'equal': 570,
  27788. 'greater': 570,
  27789. 'question': 500,
  27790. 'at': 832,
  27791. 'A': 667,
  27792. 'B': 667,
  27793. 'C': 667,
  27794. 'D': 722,
  27795. 'E': 667,
  27796. 'F': 667,
  27797. 'G': 722,
  27798. 'H': 778,
  27799. 'I': 389,
  27800. 'J': 500,
  27801. 'K': 667,
  27802. 'L': 611,
  27803. 'M': 889,
  27804. 'N': 722,
  27805. 'O': 722,
  27806. 'P': 611,
  27807. 'Q': 722,
  27808. 'R': 667,
  27809. 'S': 556,
  27810. 'T': 611,
  27811. 'U': 722,
  27812. 'V': 667,
  27813. 'W': 889,
  27814. 'X': 667,
  27815. 'Y': 611,
  27816. 'Z': 611,
  27817. 'bracketleft': 333,
  27818. 'backslash': 278,
  27819. 'bracketright': 333,
  27820. 'asciicircum': 570,
  27821. 'underscore': 500,
  27822. 'quoteleft': 333,
  27823. 'a': 500,
  27824. 'b': 500,
  27825. 'c': 444,
  27826. 'd': 500,
  27827. 'e': 444,
  27828. 'f': 333,
  27829. 'g': 500,
  27830. 'h': 556,
  27831. 'i': 278,
  27832. 'j': 278,
  27833. 'k': 500,
  27834. 'l': 278,
  27835. 'm': 778,
  27836. 'n': 556,
  27837. 'o': 500,
  27838. 'p': 500,
  27839. 'q': 500,
  27840. 'r': 389,
  27841. 's': 389,
  27842. 't': 278,
  27843. 'u': 556,
  27844. 'v': 444,
  27845. 'w': 667,
  27846. 'x': 500,
  27847. 'y': 444,
  27848. 'z': 389,
  27849. 'braceleft': 348,
  27850. 'bar': 220,
  27851. 'braceright': 348,
  27852. 'asciitilde': 570,
  27853. 'exclamdown': 389,
  27854. 'cent': 500,
  27855. 'sterling': 500,
  27856. 'fraction': 167,
  27857. 'yen': 500,
  27858. 'florin': 500,
  27859. 'section': 500,
  27860. 'currency': 500,
  27861. 'quotesingle': 278,
  27862. 'quotedblleft': 500,
  27863. 'guillemotleft': 500,
  27864. 'guilsinglleft': 333,
  27865. 'guilsinglright': 333,
  27866. 'fi': 556,
  27867. 'fl': 556,
  27868. 'endash': 500,
  27869. 'dagger': 500,
  27870. 'daggerdbl': 500,
  27871. 'periodcentered': 250,
  27872. 'paragraph': 500,
  27873. 'bullet': 350,
  27874. 'quotesinglbase': 333,
  27875. 'quotedblbase': 500,
  27876. 'quotedblright': 500,
  27877. 'guillemotright': 500,
  27878. 'ellipsis': 1000,
  27879. 'perthousand': 1000,
  27880. 'questiondown': 500,
  27881. 'grave': 333,
  27882. 'acute': 333,
  27883. 'circumflex': 333,
  27884. 'tilde': 333,
  27885. 'macron': 333,
  27886. 'breve': 333,
  27887. 'dotaccent': 333,
  27888. 'dieresis': 333,
  27889. 'ring': 333,
  27890. 'cedilla': 333,
  27891. 'hungarumlaut': 333,
  27892. 'ogonek': 333,
  27893. 'caron': 333,
  27894. 'emdash': 1000,
  27895. 'AE': 944,
  27896. 'ordfeminine': 266,
  27897. 'Lslash': 611,
  27898. 'Oslash': 722,
  27899. 'OE': 944,
  27900. 'ordmasculine': 300,
  27901. 'ae': 722,
  27902. 'dotlessi': 278,
  27903. 'lslash': 278,
  27904. 'oslash': 500,
  27905. 'oe': 722,
  27906. 'germandbls': 500,
  27907. 'Idieresis': 389,
  27908. 'eacute': 444,
  27909. 'abreve': 500,
  27910. 'uhungarumlaut': 556,
  27911. 'ecaron': 444,
  27912. 'Ydieresis': 611,
  27913. 'divide': 570,
  27914. 'Yacute': 611,
  27915. 'Acircumflex': 667,
  27916. 'aacute': 500,
  27917. 'Ucircumflex': 722,
  27918. 'yacute': 444,
  27919. 'scommaaccent': 389,
  27920. 'ecircumflex': 444,
  27921. 'Uring': 722,
  27922. 'Udieresis': 722,
  27923. 'aogonek': 500,
  27924. 'Uacute': 722,
  27925. 'uogonek': 556,
  27926. 'Edieresis': 667,
  27927. 'Dcroat': 722,
  27928. 'commaaccent': 250,
  27929. 'copyright': 747,
  27930. 'Emacron': 667,
  27931. 'ccaron': 444,
  27932. 'aring': 500,
  27933. 'Ncommaaccent': 722,
  27934. 'lacute': 278,
  27935. 'agrave': 500,
  27936. 'Tcommaaccent': 611,
  27937. 'Cacute': 667,
  27938. 'atilde': 500,
  27939. 'Edotaccent': 667,
  27940. 'scaron': 389,
  27941. 'scedilla': 389,
  27942. 'iacute': 278,
  27943. 'lozenge': 494,
  27944. 'Rcaron': 667,
  27945. 'Gcommaaccent': 722,
  27946. 'ucircumflex': 556,
  27947. 'acircumflex': 500,
  27948. 'Amacron': 667,
  27949. 'rcaron': 389,
  27950. 'ccedilla': 444,
  27951. 'Zdotaccent': 611,
  27952. 'Thorn': 611,
  27953. 'Omacron': 722,
  27954. 'Racute': 667,
  27955. 'Sacute': 556,
  27956. 'dcaron': 608,
  27957. 'Umacron': 722,
  27958. 'uring': 556,
  27959. 'threesuperior': 300,
  27960. 'Ograve': 722,
  27961. 'Agrave': 667,
  27962. 'Abreve': 667,
  27963. 'multiply': 570,
  27964. 'uacute': 556,
  27965. 'Tcaron': 611,
  27966. 'partialdiff': 494,
  27967. 'ydieresis': 444,
  27968. 'Nacute': 722,
  27969. 'icircumflex': 278,
  27970. 'Ecircumflex': 667,
  27971. 'adieresis': 500,
  27972. 'edieresis': 444,
  27973. 'cacute': 444,
  27974. 'nacute': 556,
  27975. 'umacron': 556,
  27976. 'Ncaron': 722,
  27977. 'Iacute': 389,
  27978. 'plusminus': 570,
  27979. 'brokenbar': 220,
  27980. 'registered': 747,
  27981. 'Gbreve': 722,
  27982. 'Idotaccent': 389,
  27983. 'summation': 600,
  27984. 'Egrave': 667,
  27985. 'racute': 389,
  27986. 'omacron': 500,
  27987. 'Zacute': 611,
  27988. 'Zcaron': 611,
  27989. 'greaterequal': 549,
  27990. 'Eth': 722,
  27991. 'Ccedilla': 667,
  27992. 'lcommaaccent': 278,
  27993. 'tcaron': 366,
  27994. 'eogonek': 444,
  27995. 'Uogonek': 722,
  27996. 'Aacute': 667,
  27997. 'Adieresis': 667,
  27998. 'egrave': 444,
  27999. 'zacute': 389,
  28000. 'iogonek': 278,
  28001. 'Oacute': 722,
  28002. 'oacute': 500,
  28003. 'amacron': 500,
  28004. 'sacute': 389,
  28005. 'idieresis': 278,
  28006. 'Ocircumflex': 722,
  28007. 'Ugrave': 722,
  28008. 'Delta': 612,
  28009. 'thorn': 500,
  28010. 'twosuperior': 300,
  28011. 'Odieresis': 722,
  28012. 'mu': 576,
  28013. 'igrave': 278,
  28014. 'ohungarumlaut': 500,
  28015. 'Eogonek': 667,
  28016. 'dcroat': 500,
  28017. 'threequarters': 750,
  28018. 'Scedilla': 556,
  28019. 'lcaron': 382,
  28020. 'Kcommaaccent': 667,
  28021. 'Lacute': 611,
  28022. 'trademark': 1000,
  28023. 'edotaccent': 444,
  28024. 'Igrave': 389,
  28025. 'Imacron': 389,
  28026. 'Lcaron': 611,
  28027. 'onehalf': 750,
  28028. 'lessequal': 549,
  28029. 'ocircumflex': 500,
  28030. 'ntilde': 556,
  28031. 'Uhungarumlaut': 722,
  28032. 'Eacute': 667,
  28033. 'emacron': 444,
  28034. 'gbreve': 500,
  28035. 'onequarter': 750,
  28036. 'Scaron': 556,
  28037. 'Scommaaccent': 556,
  28038. 'Ohungarumlaut': 722,
  28039. 'degree': 400,
  28040. 'ograve': 500,
  28041. 'Ccaron': 667,
  28042. 'ugrave': 556,
  28043. 'radical': 549,
  28044. 'Dcaron': 722,
  28045. 'rcommaaccent': 389,
  28046. 'Ntilde': 722,
  28047. 'otilde': 500,
  28048. 'Rcommaaccent': 667,
  28049. 'Lcommaaccent': 611,
  28050. 'Atilde': 667,
  28051. 'Aogonek': 667,
  28052. 'Aring': 667,
  28053. 'Otilde': 722,
  28054. 'zdotaccent': 389,
  28055. 'Ecaron': 667,
  28056. 'Iogonek': 389,
  28057. 'kcommaaccent': 500,
  28058. 'minus': 606,
  28059. 'Icircumflex': 389,
  28060. 'ncaron': 556,
  28061. 'tcommaaccent': 278,
  28062. 'logicalnot': 606,
  28063. 'odieresis': 500,
  28064. 'udieresis': 556,
  28065. 'notequal': 549,
  28066. 'gcommaaccent': 500,
  28067. 'eth': 500,
  28068. 'zcaron': 389,
  28069. 'ncommaaccent': 556,
  28070. 'onesuperior': 300,
  28071. 'imacron': 278,
  28072. 'Euro': 500
  28073. },
  28074. 'Times-Italic': {
  28075. 'space': 250,
  28076. 'exclam': 333,
  28077. 'quotedbl': 420,
  28078. 'numbersign': 500,
  28079. 'dollar': 500,
  28080. 'percent': 833,
  28081. 'ampersand': 778,
  28082. 'quoteright': 333,
  28083. 'parenleft': 333,
  28084. 'parenright': 333,
  28085. 'asterisk': 500,
  28086. 'plus': 675,
  28087. 'comma': 250,
  28088. 'hyphen': 333,
  28089. 'period': 250,
  28090. 'slash': 278,
  28091. 'zero': 500,
  28092. 'one': 500,
  28093. 'two': 500,
  28094. 'three': 500,
  28095. 'four': 500,
  28096. 'five': 500,
  28097. 'six': 500,
  28098. 'seven': 500,
  28099. 'eight': 500,
  28100. 'nine': 500,
  28101. 'colon': 333,
  28102. 'semicolon': 333,
  28103. 'less': 675,
  28104. 'equal': 675,
  28105. 'greater': 675,
  28106. 'question': 500,
  28107. 'at': 920,
  28108. 'A': 611,
  28109. 'B': 611,
  28110. 'C': 667,
  28111. 'D': 722,
  28112. 'E': 611,
  28113. 'F': 611,
  28114. 'G': 722,
  28115. 'H': 722,
  28116. 'I': 333,
  28117. 'J': 444,
  28118. 'K': 667,
  28119. 'L': 556,
  28120. 'M': 833,
  28121. 'N': 667,
  28122. 'O': 722,
  28123. 'P': 611,
  28124. 'Q': 722,
  28125. 'R': 611,
  28126. 'S': 500,
  28127. 'T': 556,
  28128. 'U': 722,
  28129. 'V': 611,
  28130. 'W': 833,
  28131. 'X': 611,
  28132. 'Y': 556,
  28133. 'Z': 556,
  28134. 'bracketleft': 389,
  28135. 'backslash': 278,
  28136. 'bracketright': 389,
  28137. 'asciicircum': 422,
  28138. 'underscore': 500,
  28139. 'quoteleft': 333,
  28140. 'a': 500,
  28141. 'b': 500,
  28142. 'c': 444,
  28143. 'd': 500,
  28144. 'e': 444,
  28145. 'f': 278,
  28146. 'g': 500,
  28147. 'h': 500,
  28148. 'i': 278,
  28149. 'j': 278,
  28150. 'k': 444,
  28151. 'l': 278,
  28152. 'm': 722,
  28153. 'n': 500,
  28154. 'o': 500,
  28155. 'p': 500,
  28156. 'q': 500,
  28157. 'r': 389,
  28158. 's': 389,
  28159. 't': 278,
  28160. 'u': 500,
  28161. 'v': 444,
  28162. 'w': 667,
  28163. 'x': 444,
  28164. 'y': 444,
  28165. 'z': 389,
  28166. 'braceleft': 400,
  28167. 'bar': 275,
  28168. 'braceright': 400,
  28169. 'asciitilde': 541,
  28170. 'exclamdown': 389,
  28171. 'cent': 500,
  28172. 'sterling': 500,
  28173. 'fraction': 167,
  28174. 'yen': 500,
  28175. 'florin': 500,
  28176. 'section': 500,
  28177. 'currency': 500,
  28178. 'quotesingle': 214,
  28179. 'quotedblleft': 556,
  28180. 'guillemotleft': 500,
  28181. 'guilsinglleft': 333,
  28182. 'guilsinglright': 333,
  28183. 'fi': 500,
  28184. 'fl': 500,
  28185. 'endash': 500,
  28186. 'dagger': 500,
  28187. 'daggerdbl': 500,
  28188. 'periodcentered': 250,
  28189. 'paragraph': 523,
  28190. 'bullet': 350,
  28191. 'quotesinglbase': 333,
  28192. 'quotedblbase': 556,
  28193. 'quotedblright': 556,
  28194. 'guillemotright': 500,
  28195. 'ellipsis': 889,
  28196. 'perthousand': 1000,
  28197. 'questiondown': 500,
  28198. 'grave': 333,
  28199. 'acute': 333,
  28200. 'circumflex': 333,
  28201. 'tilde': 333,
  28202. 'macron': 333,
  28203. 'breve': 333,
  28204. 'dotaccent': 333,
  28205. 'dieresis': 333,
  28206. 'ring': 333,
  28207. 'cedilla': 333,
  28208. 'hungarumlaut': 333,
  28209. 'ogonek': 333,
  28210. 'caron': 333,
  28211. 'emdash': 889,
  28212. 'AE': 889,
  28213. 'ordfeminine': 276,
  28214. 'Lslash': 556,
  28215. 'Oslash': 722,
  28216. 'OE': 944,
  28217. 'ordmasculine': 310,
  28218. 'ae': 667,
  28219. 'dotlessi': 278,
  28220. 'lslash': 278,
  28221. 'oslash': 500,
  28222. 'oe': 667,
  28223. 'germandbls': 500,
  28224. 'Idieresis': 333,
  28225. 'eacute': 444,
  28226. 'abreve': 500,
  28227. 'uhungarumlaut': 500,
  28228. 'ecaron': 444,
  28229. 'Ydieresis': 556,
  28230. 'divide': 675,
  28231. 'Yacute': 556,
  28232. 'Acircumflex': 611,
  28233. 'aacute': 500,
  28234. 'Ucircumflex': 722,
  28235. 'yacute': 444,
  28236. 'scommaaccent': 389,
  28237. 'ecircumflex': 444,
  28238. 'Uring': 722,
  28239. 'Udieresis': 722,
  28240. 'aogonek': 500,
  28241. 'Uacute': 722,
  28242. 'uogonek': 500,
  28243. 'Edieresis': 611,
  28244. 'Dcroat': 722,
  28245. 'commaaccent': 250,
  28246. 'copyright': 760,
  28247. 'Emacron': 611,
  28248. 'ccaron': 444,
  28249. 'aring': 500,
  28250. 'Ncommaaccent': 667,
  28251. 'lacute': 278,
  28252. 'agrave': 500,
  28253. 'Tcommaaccent': 556,
  28254. 'Cacute': 667,
  28255. 'atilde': 500,
  28256. 'Edotaccent': 611,
  28257. 'scaron': 389,
  28258. 'scedilla': 389,
  28259. 'iacute': 278,
  28260. 'lozenge': 471,
  28261. 'Rcaron': 611,
  28262. 'Gcommaaccent': 722,
  28263. 'ucircumflex': 500,
  28264. 'acircumflex': 500,
  28265. 'Amacron': 611,
  28266. 'rcaron': 389,
  28267. 'ccedilla': 444,
  28268. 'Zdotaccent': 556,
  28269. 'Thorn': 611,
  28270. 'Omacron': 722,
  28271. 'Racute': 611,
  28272. 'Sacute': 500,
  28273. 'dcaron': 544,
  28274. 'Umacron': 722,
  28275. 'uring': 500,
  28276. 'threesuperior': 300,
  28277. 'Ograve': 722,
  28278. 'Agrave': 611,
  28279. 'Abreve': 611,
  28280. 'multiply': 675,
  28281. 'uacute': 500,
  28282. 'Tcaron': 556,
  28283. 'partialdiff': 476,
  28284. 'ydieresis': 444,
  28285. 'Nacute': 667,
  28286. 'icircumflex': 278,
  28287. 'Ecircumflex': 611,
  28288. 'adieresis': 500,
  28289. 'edieresis': 444,
  28290. 'cacute': 444,
  28291. 'nacute': 500,
  28292. 'umacron': 500,
  28293. 'Ncaron': 667,
  28294. 'Iacute': 333,
  28295. 'plusminus': 675,
  28296. 'brokenbar': 275,
  28297. 'registered': 760,
  28298. 'Gbreve': 722,
  28299. 'Idotaccent': 333,
  28300. 'summation': 600,
  28301. 'Egrave': 611,
  28302. 'racute': 389,
  28303. 'omacron': 500,
  28304. 'Zacute': 556,
  28305. 'Zcaron': 556,
  28306. 'greaterequal': 549,
  28307. 'Eth': 722,
  28308. 'Ccedilla': 667,
  28309. 'lcommaaccent': 278,
  28310. 'tcaron': 300,
  28311. 'eogonek': 444,
  28312. 'Uogonek': 722,
  28313. 'Aacute': 611,
  28314. 'Adieresis': 611,
  28315. 'egrave': 444,
  28316. 'zacute': 389,
  28317. 'iogonek': 278,
  28318. 'Oacute': 722,
  28319. 'oacute': 500,
  28320. 'amacron': 500,
  28321. 'sacute': 389,
  28322. 'idieresis': 278,
  28323. 'Ocircumflex': 722,
  28324. 'Ugrave': 722,
  28325. 'Delta': 612,
  28326. 'thorn': 500,
  28327. 'twosuperior': 300,
  28328. 'Odieresis': 722,
  28329. 'mu': 500,
  28330. 'igrave': 278,
  28331. 'ohungarumlaut': 500,
  28332. 'Eogonek': 611,
  28333. 'dcroat': 500,
  28334. 'threequarters': 750,
  28335. 'Scedilla': 500,
  28336. 'lcaron': 300,
  28337. 'Kcommaaccent': 667,
  28338. 'Lacute': 556,
  28339. 'trademark': 980,
  28340. 'edotaccent': 444,
  28341. 'Igrave': 333,
  28342. 'Imacron': 333,
  28343. 'Lcaron': 611,
  28344. 'onehalf': 750,
  28345. 'lessequal': 549,
  28346. 'ocircumflex': 500,
  28347. 'ntilde': 500,
  28348. 'Uhungarumlaut': 722,
  28349. 'Eacute': 611,
  28350. 'emacron': 444,
  28351. 'gbreve': 500,
  28352. 'onequarter': 750,
  28353. 'Scaron': 500,
  28354. 'Scommaaccent': 500,
  28355. 'Ohungarumlaut': 722,
  28356. 'degree': 400,
  28357. 'ograve': 500,
  28358. 'Ccaron': 667,
  28359. 'ugrave': 500,
  28360. 'radical': 453,
  28361. 'Dcaron': 722,
  28362. 'rcommaaccent': 389,
  28363. 'Ntilde': 667,
  28364. 'otilde': 500,
  28365. 'Rcommaaccent': 611,
  28366. 'Lcommaaccent': 556,
  28367. 'Atilde': 611,
  28368. 'Aogonek': 611,
  28369. 'Aring': 611,
  28370. 'Otilde': 722,
  28371. 'zdotaccent': 389,
  28372. 'Ecaron': 611,
  28373. 'Iogonek': 333,
  28374. 'kcommaaccent': 444,
  28375. 'minus': 675,
  28376. 'Icircumflex': 333,
  28377. 'ncaron': 500,
  28378. 'tcommaaccent': 278,
  28379. 'logicalnot': 675,
  28380. 'odieresis': 500,
  28381. 'udieresis': 500,
  28382. 'notequal': 549,
  28383. 'gcommaaccent': 500,
  28384. 'eth': 500,
  28385. 'zcaron': 389,
  28386. 'ncommaaccent': 500,
  28387. 'onesuperior': 300,
  28388. 'imacron': 278,
  28389. 'Euro': 500
  28390. },
  28391. 'ZapfDingbats': {
  28392. 'space': 278,
  28393. 'a1': 974,
  28394. 'a2': 961,
  28395. 'a202': 974,
  28396. 'a3': 980,
  28397. 'a4': 719,
  28398. 'a5': 789,
  28399. 'a119': 790,
  28400. 'a118': 791,
  28401. 'a117': 690,
  28402. 'a11': 960,
  28403. 'a12': 939,
  28404. 'a13': 549,
  28405. 'a14': 855,
  28406. 'a15': 911,
  28407. 'a16': 933,
  28408. 'a105': 911,
  28409. 'a17': 945,
  28410. 'a18': 974,
  28411. 'a19': 755,
  28412. 'a20': 846,
  28413. 'a21': 762,
  28414. 'a22': 761,
  28415. 'a23': 571,
  28416. 'a24': 677,
  28417. 'a25': 763,
  28418. 'a26': 760,
  28419. 'a27': 759,
  28420. 'a28': 754,
  28421. 'a6': 494,
  28422. 'a7': 552,
  28423. 'a8': 537,
  28424. 'a9': 577,
  28425. 'a10': 692,
  28426. 'a29': 786,
  28427. 'a30': 788,
  28428. 'a31': 788,
  28429. 'a32': 790,
  28430. 'a33': 793,
  28431. 'a34': 794,
  28432. 'a35': 816,
  28433. 'a36': 823,
  28434. 'a37': 789,
  28435. 'a38': 841,
  28436. 'a39': 823,
  28437. 'a40': 833,
  28438. 'a41': 816,
  28439. 'a42': 831,
  28440. 'a43': 923,
  28441. 'a44': 744,
  28442. 'a45': 723,
  28443. 'a46': 749,
  28444. 'a47': 790,
  28445. 'a48': 792,
  28446. 'a49': 695,
  28447. 'a50': 776,
  28448. 'a51': 768,
  28449. 'a52': 792,
  28450. 'a53': 759,
  28451. 'a54': 707,
  28452. 'a55': 708,
  28453. 'a56': 682,
  28454. 'a57': 701,
  28455. 'a58': 826,
  28456. 'a59': 815,
  28457. 'a60': 789,
  28458. 'a61': 789,
  28459. 'a62': 707,
  28460. 'a63': 687,
  28461. 'a64': 696,
  28462. 'a65': 689,
  28463. 'a66': 786,
  28464. 'a67': 787,
  28465. 'a68': 713,
  28466. 'a69': 791,
  28467. 'a70': 785,
  28468. 'a71': 791,
  28469. 'a72': 873,
  28470. 'a73': 761,
  28471. 'a74': 762,
  28472. 'a203': 762,
  28473. 'a75': 759,
  28474. 'a204': 759,
  28475. 'a76': 892,
  28476. 'a77': 892,
  28477. 'a78': 788,
  28478. 'a79': 784,
  28479. 'a81': 438,
  28480. 'a82': 138,
  28481. 'a83': 277,
  28482. 'a84': 415,
  28483. 'a97': 392,
  28484. 'a98': 392,
  28485. 'a99': 668,
  28486. 'a100': 668,
  28487. 'a89': 390,
  28488. 'a90': 390,
  28489. 'a93': 317,
  28490. 'a94': 317,
  28491. 'a91': 276,
  28492. 'a92': 276,
  28493. 'a205': 509,
  28494. 'a85': 509,
  28495. 'a206': 410,
  28496. 'a86': 410,
  28497. 'a87': 234,
  28498. 'a88': 234,
  28499. 'a95': 334,
  28500. 'a96': 334,
  28501. 'a101': 732,
  28502. 'a102': 544,
  28503. 'a103': 544,
  28504. 'a104': 910,
  28505. 'a106': 667,
  28506. 'a107': 760,
  28507. 'a108': 760,
  28508. 'a112': 776,
  28509. 'a111': 595,
  28510. 'a110': 694,
  28511. 'a109': 626,
  28512. 'a120': 788,
  28513. 'a121': 788,
  28514. 'a122': 788,
  28515. 'a123': 788,
  28516. 'a124': 788,
  28517. 'a125': 788,
  28518. 'a126': 788,
  28519. 'a127': 788,
  28520. 'a128': 788,
  28521. 'a129': 788,
  28522. 'a130': 788,
  28523. 'a131': 788,
  28524. 'a132': 788,
  28525. 'a133': 788,
  28526. 'a134': 788,
  28527. 'a135': 788,
  28528. 'a136': 788,
  28529. 'a137': 788,
  28530. 'a138': 788,
  28531. 'a139': 788,
  28532. 'a140': 788,
  28533. 'a141': 788,
  28534. 'a142': 788,
  28535. 'a143': 788,
  28536. 'a144': 788,
  28537. 'a145': 788,
  28538. 'a146': 788,
  28539. 'a147': 788,
  28540. 'a148': 788,
  28541. 'a149': 788,
  28542. 'a150': 788,
  28543. 'a151': 788,
  28544. 'a152': 788,
  28545. 'a153': 788,
  28546. 'a154': 788,
  28547. 'a155': 788,
  28548. 'a156': 788,
  28549. 'a157': 788,
  28550. 'a158': 788,
  28551. 'a159': 788,
  28552. 'a160': 894,
  28553. 'a161': 838,
  28554. 'a163': 1016,
  28555. 'a164': 458,
  28556. 'a196': 748,
  28557. 'a165': 924,
  28558. 'a192': 748,
  28559. 'a166': 918,
  28560. 'a167': 927,
  28561. 'a168': 928,
  28562. 'a169': 928,
  28563. 'a170': 834,
  28564. 'a171': 873,
  28565. 'a172': 828,
  28566. 'a173': 924,
  28567. 'a162': 924,
  28568. 'a174': 917,
  28569. 'a175': 930,
  28570. 'a176': 931,
  28571. 'a177': 463,
  28572. 'a178': 883,
  28573. 'a179': 836,
  28574. 'a193': 836,
  28575. 'a180': 867,
  28576. 'a199': 867,
  28577. 'a181': 696,
  28578. 'a200': 696,
  28579. 'a182': 874,
  28580. 'a201': 874,
  28581. 'a183': 760,
  28582. 'a184': 946,
  28583. 'a197': 771,
  28584. 'a185': 865,
  28585. 'a194': 771,
  28586. 'a198': 888,
  28587. 'a186': 967,
  28588. 'a195': 888,
  28589. 'a187': 831,
  28590. 'a188': 873,
  28591. 'a189': 927,
  28592. 'a190': 970,
  28593. 'a191': 918
  28594. }
  28595. };
  28596. var EOF = {};
  28597. function isEOF(v) {
  28598. return (v === EOF);
  28599. }
  28600. var MAX_LENGTH_TO_CACHE = 1000;
  28601. var Parser = (function ParserClosure() {
  28602. function Parser(lexer, allowStreams, xref) {
  28603. this.lexer = lexer;
  28604. this.allowStreams = allowStreams;
  28605. this.xref = xref;
  28606. this.imageCache = {};
  28607. this.refill();
  28608. }
  28609. Parser.prototype = {
  28610. refill: function Parser_refill() {
  28611. this.buf1 = this.lexer.getObj();
  28612. this.buf2 = this.lexer.getObj();
  28613. },
  28614. shift: function Parser_shift() {
  28615. if (isCmd(this.buf2, 'ID')) {
  28616. this.buf1 = this.buf2;
  28617. this.buf2 = null;
  28618. } else {
  28619. this.buf1 = this.buf2;
  28620. this.buf2 = this.lexer.getObj();
  28621. }
  28622. },
  28623. getObj: function Parser_getObj(cipherTransform) {
  28624. var buf1 = this.buf1;
  28625. this.shift();
  28626. if (buf1 instanceof Cmd) {
  28627. switch (buf1.cmd) {
  28628. case 'BI': // inline image
  28629. return this.makeInlineImage(cipherTransform);
  28630. case '[': // array
  28631. var array = [];
  28632. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  28633. array.push(this.getObj(cipherTransform));
  28634. }
  28635. if (isEOF(this.buf1)) {
  28636. error('End of file inside array');
  28637. }
  28638. this.shift();
  28639. return array;
  28640. case '<<': // dictionary or stream
  28641. var dict = new Dict(this.xref);
  28642. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  28643. if (!isName(this.buf1)) {
  28644. info('Malformed dictionary: key must be a name object');
  28645. this.shift();
  28646. continue;
  28647. }
  28648. var key = this.buf1.name;
  28649. this.shift();
  28650. if (isEOF(this.buf1)) {
  28651. break;
  28652. }
  28653. dict.set(key, this.getObj(cipherTransform));
  28654. }
  28655. if (isEOF(this.buf1)) {
  28656. error('End of file inside dictionary');
  28657. }
  28658. // Stream objects are not allowed inside content streams or
  28659. // object streams.
  28660. if (isCmd(this.buf2, 'stream')) {
  28661. return (this.allowStreams ?
  28662. this.makeStream(dict, cipherTransform) : dict);
  28663. }
  28664. this.shift();
  28665. return dict;
  28666. default: // simple object
  28667. return buf1;
  28668. }
  28669. }
  28670. if (isInt(buf1)) { // indirect reference or integer
  28671. var num = buf1;
  28672. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  28673. var ref = new Ref(num, this.buf1);
  28674. this.shift();
  28675. this.shift();
  28676. return ref;
  28677. }
  28678. return num;
  28679. }
  28680. if (isString(buf1)) { // string
  28681. var str = buf1;
  28682. if (cipherTransform) {
  28683. str = cipherTransform.decryptString(str);
  28684. }
  28685. return str;
  28686. }
  28687. // simple object
  28688. return buf1;
  28689. },
  28690. /**
  28691. * Find the end of the stream by searching for the /EI\s/.
  28692. * @returns {number} The inline stream length.
  28693. */
  28694. findDefaultInlineStreamEnd:
  28695. function Parser_findDefaultInlineStreamEnd(stream) {
  28696. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  28697. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  28698. while ((ch = stream.getByte()) !== -1) {
  28699. if (state === 0) {
  28700. state = (ch === E) ? 1 : 0;
  28701. } else if (state === 1) {
  28702. state = (ch === I) ? 2 : 0;
  28703. } else {
  28704. assert(state === 2);
  28705. if (ch === SPACE || ch === LF || ch === CR) {
  28706. // Let's check the next five bytes are ASCII... just be sure.
  28707. n = 5;
  28708. followingBytes = stream.peekBytes(n);
  28709. for (i = 0; i < n; i++) {
  28710. ch = followingBytes[i];
  28711. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  28712. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  28713. // it's binary stuff. Resetting the state.
  28714. state = 0;
  28715. break;
  28716. }
  28717. }
  28718. if (state === 2) {
  28719. break; // Finished!
  28720. }
  28721. } else {
  28722. state = 0;
  28723. }
  28724. }
  28725. }
  28726. return ((stream.pos - 4) - startPos);
  28727. },
  28728. /**
  28729. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  28730. * @returns {number} The inline stream length.
  28731. */
  28732. findDCTDecodeInlineStreamEnd:
  28733. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  28734. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  28735. while ((b = stream.getByte()) !== -1) {
  28736. if (b !== 0xFF) { // Not a valid marker.
  28737. continue;
  28738. }
  28739. switch (stream.getByte()) {
  28740. case 0x00: // Byte stuffing.
  28741. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  28742. break;
  28743. case 0xFF: // Fill byte.
  28744. // Avoid skipping a valid marker, resetting the stream position.
  28745. stream.skip(-1);
  28746. break;
  28747. case 0xD9: // EOI
  28748. foundEOI = true;
  28749. break;
  28750. case 0xC0: // SOF0
  28751. case 0xC1: // SOF1
  28752. case 0xC2: // SOF2
  28753. case 0xC3: // SOF3
  28754. case 0xC5: // SOF5
  28755. case 0xC6: // SOF6
  28756. case 0xC7: // SOF7
  28757. case 0xC9: // SOF9
  28758. case 0xCA: // SOF10
  28759. case 0xCB: // SOF11
  28760. case 0xCD: // SOF13
  28761. case 0xCE: // SOF14
  28762. case 0xCF: // SOF15
  28763. case 0xC4: // DHT
  28764. case 0xCC: // DAC
  28765. case 0xDA: // SOS
  28766. case 0xDB: // DQT
  28767. case 0xDC: // DNL
  28768. case 0xDD: // DRI
  28769. case 0xDE: // DHP
  28770. case 0xDF: // EXP
  28771. case 0xE0: // APP0
  28772. case 0xE1: // APP1
  28773. case 0xE2: // APP2
  28774. case 0xE3: // APP3
  28775. case 0xE4: // APP4
  28776. case 0xE5: // APP5
  28777. case 0xE6: // APP6
  28778. case 0xE7: // APP7
  28779. case 0xE8: // APP8
  28780. case 0xE9: // APP9
  28781. case 0xEA: // APP10
  28782. case 0xEB: // APP11
  28783. case 0xEC: // APP12
  28784. case 0xED: // APP13
  28785. case 0xEE: // APP14
  28786. case 0xEF: // APP15
  28787. case 0xFE: // COM
  28788. // The marker should be followed by the length of the segment.
  28789. markerLength = stream.getUint16();
  28790. if (markerLength > 2) {
  28791. // |markerLength| contains the byte length of the marker segment,
  28792. // including its own length (2 bytes) and excluding the marker.
  28793. stream.skip(markerLength - 2); // Jump to the next marker.
  28794. } else {
  28795. // The marker length is invalid, resetting the stream position.
  28796. stream.skip(-2);
  28797. }
  28798. break;
  28799. }
  28800. if (foundEOI) {
  28801. break;
  28802. }
  28803. }
  28804. length = stream.pos - startPos;
  28805. if (b === -1) {
  28806. warn('Inline DCTDecode image stream: ' +
  28807. 'EOI marker not found, searching for /EI/ instead.');
  28808. stream.skip(-length); // Reset the stream position.
  28809. return this.findDefaultInlineStreamEnd(stream);
  28810. }
  28811. this.inlineStreamSkipEI(stream);
  28812. return length;
  28813. },
  28814. /**
  28815. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  28816. * @returns {number} The inline stream length.
  28817. */
  28818. findASCII85DecodeInlineStreamEnd:
  28819. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  28820. var TILDE = 0x7E, GT = 0x3E;
  28821. var startPos = stream.pos, ch, length;
  28822. while ((ch = stream.getByte()) !== -1) {
  28823. if (ch === TILDE && stream.peekByte() === GT) {
  28824. stream.skip();
  28825. break;
  28826. }
  28827. }
  28828. length = stream.pos - startPos;
  28829. if (ch === -1) {
  28830. warn('Inline ASCII85Decode image stream: ' +
  28831. 'EOD marker not found, searching for /EI/ instead.');
  28832. stream.skip(-length); // Reset the stream position.
  28833. return this.findDefaultInlineStreamEnd(stream);
  28834. }
  28835. this.inlineStreamSkipEI(stream);
  28836. return length;
  28837. },
  28838. /**
  28839. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  28840. * @returns {number} The inline stream length.
  28841. */
  28842. findASCIIHexDecodeInlineStreamEnd:
  28843. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  28844. var GT = 0x3E;
  28845. var startPos = stream.pos, ch, length;
  28846. while ((ch = stream.getByte()) !== -1) {
  28847. if (ch === GT) {
  28848. break;
  28849. }
  28850. }
  28851. length = stream.pos - startPos;
  28852. if (ch === -1) {
  28853. warn('Inline ASCIIHexDecode image stream: ' +
  28854. 'EOD marker not found, searching for /EI/ instead.');
  28855. stream.skip(-length); // Reset the stream position.
  28856. return this.findDefaultInlineStreamEnd(stream);
  28857. }
  28858. this.inlineStreamSkipEI(stream);
  28859. return length;
  28860. },
  28861. /**
  28862. * Skip over the /EI/ for streams where we search for an EOD marker.
  28863. */
  28864. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  28865. var E = 0x45, I = 0x49;
  28866. var state = 0, ch;
  28867. while ((ch = stream.getByte()) !== -1) {
  28868. if (state === 0) {
  28869. state = (ch === E) ? 1 : 0;
  28870. } else if (state === 1) {
  28871. state = (ch === I) ? 2 : 0;
  28872. } else if (state === 2) {
  28873. break;
  28874. }
  28875. }
  28876. },
  28877. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  28878. var lexer = this.lexer;
  28879. var stream = lexer.stream;
  28880. // Parse dictionary.
  28881. var dict = new Dict(null);
  28882. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  28883. if (!isName(this.buf1)) {
  28884. error('Dictionary key must be a name object');
  28885. }
  28886. var key = this.buf1.name;
  28887. this.shift();
  28888. if (isEOF(this.buf1)) {
  28889. break;
  28890. }
  28891. dict.set(key, this.getObj(cipherTransform));
  28892. }
  28893. // Extract the name of the first (i.e. the current) image filter.
  28894. var filter = this.fetchIfRef(dict.get('Filter', 'F')), filterName;
  28895. if (isName(filter)) {
  28896. filterName = filter.name;
  28897. } else if (isArray(filter) && isName(filter[0])) {
  28898. filterName = filter[0].name;
  28899. }
  28900. // Parse image stream.
  28901. var startPos = stream.pos, length, i, ii;
  28902. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  28903. length = this.findDCTDecodeInlineStreamEnd(stream);
  28904. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  28905. length = this.findASCII85DecodeInlineStreamEnd(stream);
  28906. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  28907. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  28908. } else {
  28909. length = this.findDefaultInlineStreamEnd(stream);
  28910. }
  28911. var imageStream = stream.makeSubStream(startPos, length, dict);
  28912. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  28913. // adler32 checksum.
  28914. var adler32;
  28915. if (length < MAX_LENGTH_TO_CACHE) {
  28916. var imageBytes = imageStream.getBytes();
  28917. imageStream.reset();
  28918. var a = 1;
  28919. var b = 0;
  28920. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  28921. // No modulo required in the loop if imageBytes.length < 5552.
  28922. a += imageBytes[i] & 0xff;
  28923. b += a;
  28924. }
  28925. adler32 = ((b % 65521) << 16) | (a % 65521);
  28926. if (this.imageCache.adler32 === adler32) {
  28927. this.buf2 = Cmd.get('EI');
  28928. this.shift();
  28929. this.imageCache[adler32].reset();
  28930. return this.imageCache[adler32];
  28931. }
  28932. }
  28933. if (cipherTransform) {
  28934. imageStream = cipherTransform.createStream(imageStream, length);
  28935. }
  28936. imageStream = this.filter(imageStream, dict, length);
  28937. imageStream.dict = dict;
  28938. if (adler32 !== undefined) {
  28939. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  28940. this.imageCache[adler32] = imageStream;
  28941. }
  28942. this.buf2 = Cmd.get('EI');
  28943. this.shift();
  28944. return imageStream;
  28945. },
  28946. fetchIfRef: function Parser_fetchIfRef(obj) {
  28947. // not relying on the xref.fetchIfRef -- xref might not be set
  28948. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  28949. },
  28950. makeStream: function Parser_makeStream(dict, cipherTransform) {
  28951. var lexer = this.lexer;
  28952. var stream = lexer.stream;
  28953. // get stream start position
  28954. lexer.skipToNextLine();
  28955. var pos = stream.pos - 1;
  28956. // get length
  28957. var length = this.fetchIfRef(dict.get('Length'));
  28958. if (!isInt(length)) {
  28959. info('Bad ' + length + ' attribute in stream');
  28960. length = 0;
  28961. }
  28962. // skip over the stream data
  28963. stream.pos = pos + length;
  28964. lexer.nextChar();
  28965. this.shift(); // '>>'
  28966. this.shift(); // 'stream'
  28967. if (!isCmd(this.buf1, 'endstream')) {
  28968. // bad stream length, scanning for endstream
  28969. stream.pos = pos;
  28970. var SCAN_BLOCK_SIZE = 2048;
  28971. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  28972. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  28973. 0x61, 0x6D];
  28974. var skipped = 0, found = false, i, j;
  28975. while (stream.pos < stream.end) {
  28976. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  28977. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  28978. if (scanLength <= 0) {
  28979. break;
  28980. }
  28981. found = false;
  28982. for (i = 0, j = 0; i < scanLength; i++) {
  28983. var b = scanBytes[i];
  28984. if (b !== ENDSTREAM_SIGNATURE[j]) {
  28985. i -= j;
  28986. j = 0;
  28987. } else {
  28988. j++;
  28989. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  28990. i++;
  28991. found = true;
  28992. break;
  28993. }
  28994. }
  28995. }
  28996. if (found) {
  28997. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  28998. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  28999. break;
  29000. }
  29001. skipped += scanLength;
  29002. stream.pos += scanLength;
  29003. }
  29004. if (!found) {
  29005. error('Missing endstream');
  29006. }
  29007. length = skipped;
  29008. lexer.nextChar();
  29009. this.shift();
  29010. this.shift();
  29011. }
  29012. this.shift(); // 'endstream'
  29013. stream = stream.makeSubStream(pos, length, dict);
  29014. if (cipherTransform) {
  29015. stream = cipherTransform.createStream(stream, length);
  29016. }
  29017. stream = this.filter(stream, dict, length);
  29018. stream.dict = dict;
  29019. return stream;
  29020. },
  29021. filter: function Parser_filter(stream, dict, length) {
  29022. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  29023. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  29024. if (isName(filter)) {
  29025. return this.makeFilter(stream, filter.name, length, params);
  29026. }
  29027. var maybeLength = length;
  29028. if (isArray(filter)) {
  29029. var filterArray = filter;
  29030. var paramsArray = params;
  29031. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  29032. filter = filterArray[i];
  29033. if (!isName(filter)) {
  29034. error('Bad filter name: ' + filter);
  29035. }
  29036. params = null;
  29037. if (isArray(paramsArray) && (i in paramsArray)) {
  29038. params = paramsArray[i];
  29039. }
  29040. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  29041. // after the first stream the length variable is invalid
  29042. maybeLength = null;
  29043. }
  29044. }
  29045. return stream;
  29046. },
  29047. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  29048. if (stream.dict.get('Length') === 0) {
  29049. return new NullStream(stream);
  29050. }
  29051. try {
  29052. if (params) {
  29053. params = this.fetchIfRef(params);
  29054. }
  29055. var xrefStreamStats = this.xref.stats.streamTypes;
  29056. if (name === 'FlateDecode' || name === 'Fl') {
  29057. xrefStreamStats[StreamType.FLATE] = true;
  29058. if (params) {
  29059. return new PredictorStream(new FlateStream(stream, maybeLength),
  29060. maybeLength, params);
  29061. }
  29062. return new FlateStream(stream, maybeLength);
  29063. }
  29064. if (name === 'LZWDecode' || name === 'LZW') {
  29065. xrefStreamStats[StreamType.LZW] = true;
  29066. var earlyChange = 1;
  29067. if (params) {
  29068. if (params.has('EarlyChange')) {
  29069. earlyChange = params.get('EarlyChange');
  29070. }
  29071. return new PredictorStream(
  29072. new LZWStream(stream, maybeLength, earlyChange),
  29073. maybeLength, params);
  29074. }
  29075. return new LZWStream(stream, maybeLength, earlyChange);
  29076. }
  29077. if (name === 'DCTDecode' || name === 'DCT') {
  29078. xrefStreamStats[StreamType.DCT] = true;
  29079. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  29080. }
  29081. if (name === 'JPXDecode' || name === 'JPX') {
  29082. xrefStreamStats[StreamType.JPX] = true;
  29083. return new JpxStream(stream, maybeLength, stream.dict);
  29084. }
  29085. if (name === 'ASCII85Decode' || name === 'A85') {
  29086. xrefStreamStats[StreamType.A85] = true;
  29087. return new Ascii85Stream(stream, maybeLength);
  29088. }
  29089. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  29090. xrefStreamStats[StreamType.AHX] = true;
  29091. return new AsciiHexStream(stream, maybeLength);
  29092. }
  29093. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  29094. xrefStreamStats[StreamType.CCF] = true;
  29095. return new CCITTFaxStream(stream, maybeLength, params);
  29096. }
  29097. if (name === 'RunLengthDecode' || name === 'RL') {
  29098. xrefStreamStats[StreamType.RL] = true;
  29099. return new RunLengthStream(stream, maybeLength);
  29100. }
  29101. if (name === 'JBIG2Decode') {
  29102. xrefStreamStats[StreamType.JBIG] = true;
  29103. return new Jbig2Stream(stream, maybeLength, stream.dict);
  29104. }
  29105. warn('filter "' + name + '" not supported yet');
  29106. return stream;
  29107. } catch (ex) {
  29108. if (ex instanceof MissingDataException) {
  29109. throw ex;
  29110. }
  29111. warn('Invalid stream: \"' + ex + '\"');
  29112. return new NullStream(stream);
  29113. }
  29114. }
  29115. };
  29116. return Parser;
  29117. })();
  29118. var Lexer = (function LexerClosure() {
  29119. function Lexer(stream, knownCommands) {
  29120. this.stream = stream;
  29121. this.nextChar();
  29122. // While lexing, we build up many strings one char at a time. Using += for
  29123. // this can result in lots of garbage strings. It's better to build an
  29124. // array of single-char strings and then join() them together at the end.
  29125. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  29126. // purpose uses less memory than using a new array for each string.
  29127. this.strBuf = [];
  29128. // The PDFs might have "glued" commands with other commands, operands or
  29129. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  29130. // commands and their prefixes. The prefixes are built the following way:
  29131. // if there a command that is a prefix of the other valid command or
  29132. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  29133. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  29134. // other commands or literals as a prefix. The knowCommands is optional.
  29135. this.knownCommands = knownCommands;
  29136. }
  29137. Lexer.isSpace = function Lexer_isSpace(ch) {
  29138. // Space is one of the following characters: SPACE, TAB, CR or LF.
  29139. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  29140. };
  29141. // A '1' in this array means the character is white space. A '1' or
  29142. // '2' means the character ends a name or command.
  29143. var specialChars = [
  29144. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  29145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  29146. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  29147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  29148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  29149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  29150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  29151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  29152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  29153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  29154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  29155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  29156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  29157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  29158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  29159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  29160. ];
  29161. function toHexDigit(ch) {
  29162. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  29163. return ch & 0x0F;
  29164. }
  29165. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  29166. // 'A'-'F', 'a'-'f'
  29167. return (ch & 0x0F) + 9;
  29168. }
  29169. return -1;
  29170. }
  29171. Lexer.prototype = {
  29172. nextChar: function Lexer_nextChar() {
  29173. return (this.currentChar = this.stream.getByte());
  29174. },
  29175. peekChar: function Lexer_peekChar() {
  29176. return this.stream.peekByte();
  29177. },
  29178. getNumber: function Lexer_getNumber() {
  29179. var ch = this.currentChar;
  29180. var eNotation = false;
  29181. var divideBy = 0; // different from 0 if it's a floating point value
  29182. var sign = 1;
  29183. if (ch === 0x2D) { // '-'
  29184. sign = -1;
  29185. ch = this.nextChar();
  29186. } else if (ch === 0x2B) { // '+'
  29187. ch = this.nextChar();
  29188. }
  29189. if (ch === 0x2E) { // '.'
  29190. divideBy = 10;
  29191. ch = this.nextChar();
  29192. }
  29193. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29194. error('Invalid number: ' + String.fromCharCode(ch));
  29195. return 0;
  29196. }
  29197. var baseValue = ch - 0x30; // '0'
  29198. var powerValue = 0;
  29199. var powerValueSign = 1;
  29200. while ((ch = this.nextChar()) >= 0) {
  29201. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  29202. var currentDigit = ch - 0x30; // '0'
  29203. if (eNotation) { // We are after an 'e' or 'E'
  29204. powerValue = powerValue * 10 + currentDigit;
  29205. } else {
  29206. if (divideBy !== 0) { // We are after a point
  29207. divideBy *= 10;
  29208. }
  29209. baseValue = baseValue * 10 + currentDigit;
  29210. }
  29211. } else if (ch === 0x2E) { // '.'
  29212. if (divideBy === 0) {
  29213. divideBy = 1;
  29214. } else {
  29215. // A number can have only one '.'
  29216. break;
  29217. }
  29218. } else if (ch === 0x2D) { // '-'
  29219. // ignore minus signs in the middle of numbers to match
  29220. // Adobe's behavior
  29221. warn('Badly formated number');
  29222. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  29223. // 'E' can be either a scientific notation or the beginning of a new
  29224. // operator
  29225. ch = this.peekChar();
  29226. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  29227. powerValueSign = (ch === 0x2D) ? -1 : 1;
  29228. this.nextChar(); // Consume the sign character
  29229. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  29230. // The 'E' must be the beginning of a new operator
  29231. break;
  29232. }
  29233. eNotation = true;
  29234. } else {
  29235. // the last character doesn't belong to us
  29236. break;
  29237. }
  29238. }
  29239. if (divideBy !== 0) {
  29240. baseValue /= divideBy;
  29241. }
  29242. if (eNotation) {
  29243. baseValue *= Math.pow(10, powerValueSign * powerValue);
  29244. }
  29245. return sign * baseValue;
  29246. },
  29247. getString: function Lexer_getString() {
  29248. var numParen = 1;
  29249. var done = false;
  29250. var strBuf = this.strBuf;
  29251. strBuf.length = 0;
  29252. var ch = this.nextChar();
  29253. while (true) {
  29254. var charBuffered = false;
  29255. switch (ch | 0) {
  29256. case -1:
  29257. warn('Unterminated string');
  29258. done = true;
  29259. break;
  29260. case 0x28: // '('
  29261. ++numParen;
  29262. strBuf.push('(');
  29263. break;
  29264. case 0x29: // ')'
  29265. if (--numParen === 0) {
  29266. this.nextChar(); // consume strings ')'
  29267. done = true;
  29268. } else {
  29269. strBuf.push(')');
  29270. }
  29271. break;
  29272. case 0x5C: // '\\'
  29273. ch = this.nextChar();
  29274. switch (ch) {
  29275. case -1:
  29276. warn('Unterminated string');
  29277. done = true;
  29278. break;
  29279. case 0x6E: // 'n'
  29280. strBuf.push('\n');
  29281. break;
  29282. case 0x72: // 'r'
  29283. strBuf.push('\r');
  29284. break;
  29285. case 0x74: // 't'
  29286. strBuf.push('\t');
  29287. break;
  29288. case 0x62: // 'b'
  29289. strBuf.push('\b');
  29290. break;
  29291. case 0x66: // 'f'
  29292. strBuf.push('\f');
  29293. break;
  29294. case 0x5C: // '\'
  29295. case 0x28: // '('
  29296. case 0x29: // ')'
  29297. strBuf.push(String.fromCharCode(ch));
  29298. break;
  29299. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  29300. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  29301. var x = ch & 0x0F;
  29302. ch = this.nextChar();
  29303. charBuffered = true;
  29304. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29305. x = (x << 3) + (ch & 0x0F);
  29306. ch = this.nextChar();
  29307. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  29308. charBuffered = false;
  29309. x = (x << 3) + (ch & 0x0F);
  29310. }
  29311. }
  29312. strBuf.push(String.fromCharCode(x));
  29313. break;
  29314. case 0x0D: // CR
  29315. if (this.peekChar() === 0x0A) { // LF
  29316. this.nextChar();
  29317. }
  29318. break;
  29319. case 0x0A: // LF
  29320. break;
  29321. default:
  29322. strBuf.push(String.fromCharCode(ch));
  29323. break;
  29324. }
  29325. break;
  29326. default:
  29327. strBuf.push(String.fromCharCode(ch));
  29328. break;
  29329. }
  29330. if (done) {
  29331. break;
  29332. }
  29333. if (!charBuffered) {
  29334. ch = this.nextChar();
  29335. }
  29336. }
  29337. return strBuf.join('');
  29338. },
  29339. getName: function Lexer_getName() {
  29340. var ch;
  29341. var strBuf = this.strBuf;
  29342. strBuf.length = 0;
  29343. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29344. if (ch === 0x23) { // '#'
  29345. ch = this.nextChar();
  29346. var x = toHexDigit(ch);
  29347. if (x !== -1) {
  29348. var x2 = toHexDigit(this.nextChar());
  29349. if (x2 === -1) {
  29350. error('Illegal digit in hex char in name: ' + x2);
  29351. }
  29352. strBuf.push(String.fromCharCode((x << 4) | x2));
  29353. } else {
  29354. strBuf.push('#', String.fromCharCode(ch));
  29355. }
  29356. } else {
  29357. strBuf.push(String.fromCharCode(ch));
  29358. }
  29359. }
  29360. if (strBuf.length > 128) {
  29361. error('Warning: name token is longer than allowed by the spec: ' +
  29362. strBuf.length);
  29363. }
  29364. return Name.get(strBuf.join(''));
  29365. },
  29366. getHexString: function Lexer_getHexString() {
  29367. var strBuf = this.strBuf;
  29368. strBuf.length = 0;
  29369. var ch = this.currentChar;
  29370. var isFirstHex = true;
  29371. var firstDigit;
  29372. var secondDigit;
  29373. while (true) {
  29374. if (ch < 0) {
  29375. warn('Unterminated hex string');
  29376. break;
  29377. } else if (ch === 0x3E) { // '>'
  29378. this.nextChar();
  29379. break;
  29380. } else if (specialChars[ch] === 1) {
  29381. ch = this.nextChar();
  29382. continue;
  29383. } else {
  29384. if (isFirstHex) {
  29385. firstDigit = toHexDigit(ch);
  29386. if (firstDigit === -1) {
  29387. warn('Ignoring invalid character "' + ch + '" in hex string');
  29388. ch = this.nextChar();
  29389. continue;
  29390. }
  29391. } else {
  29392. secondDigit = toHexDigit(ch);
  29393. if (secondDigit === -1) {
  29394. warn('Ignoring invalid character "' + ch + '" in hex string');
  29395. ch = this.nextChar();
  29396. continue;
  29397. }
  29398. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  29399. }
  29400. isFirstHex = !isFirstHex;
  29401. ch = this.nextChar();
  29402. }
  29403. }
  29404. return strBuf.join('');
  29405. },
  29406. getObj: function Lexer_getObj() {
  29407. // skip whitespace and comments
  29408. var comment = false;
  29409. var ch = this.currentChar;
  29410. while (true) {
  29411. if (ch < 0) {
  29412. return EOF;
  29413. }
  29414. if (comment) {
  29415. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  29416. comment = false;
  29417. }
  29418. } else if (ch === 0x25) { // '%'
  29419. comment = true;
  29420. } else if (specialChars[ch] !== 1) {
  29421. break;
  29422. }
  29423. ch = this.nextChar();
  29424. }
  29425. // start reading token
  29426. switch (ch | 0) {
  29427. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29428. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29429. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29430. return this.getNumber();
  29431. case 0x28: // '('
  29432. return this.getString();
  29433. case 0x2F: // '/'
  29434. return this.getName();
  29435. // array punctuation
  29436. case 0x5B: // '['
  29437. this.nextChar();
  29438. return Cmd.get('[');
  29439. case 0x5D: // ']'
  29440. this.nextChar();
  29441. return Cmd.get(']');
  29442. // hex string or dict punctuation
  29443. case 0x3C: // '<'
  29444. ch = this.nextChar();
  29445. if (ch === 0x3C) {
  29446. // dict punctuation
  29447. this.nextChar();
  29448. return Cmd.get('<<');
  29449. }
  29450. return this.getHexString();
  29451. // dict punctuation
  29452. case 0x3E: // '>'
  29453. ch = this.nextChar();
  29454. if (ch === 0x3E) {
  29455. this.nextChar();
  29456. return Cmd.get('>>');
  29457. }
  29458. return Cmd.get('>');
  29459. case 0x7B: // '{'
  29460. this.nextChar();
  29461. return Cmd.get('{');
  29462. case 0x7D: // '}'
  29463. this.nextChar();
  29464. return Cmd.get('}');
  29465. case 0x29: // ')'
  29466. error('Illegal character: ' + ch);
  29467. break;
  29468. }
  29469. // command
  29470. var str = String.fromCharCode(ch);
  29471. var knownCommands = this.knownCommands;
  29472. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29473. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  29474. // stop if known command is found and next character does not make
  29475. // the str a command
  29476. var possibleCommand = str + String.fromCharCode(ch);
  29477. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  29478. break;
  29479. }
  29480. if (str.length === 128) {
  29481. error('Command token too long: ' + str.length);
  29482. }
  29483. str = possibleCommand;
  29484. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  29485. }
  29486. if (str === 'true') {
  29487. return true;
  29488. }
  29489. if (str === 'false') {
  29490. return false;
  29491. }
  29492. if (str === 'null') {
  29493. return null;
  29494. }
  29495. return Cmd.get(str);
  29496. },
  29497. skipToNextLine: function Lexer_skipToNextLine() {
  29498. var ch = this.currentChar;
  29499. while (ch >= 0) {
  29500. if (ch === 0x0D) { // CR
  29501. ch = this.nextChar();
  29502. if (ch === 0x0A) { // LF
  29503. this.nextChar();
  29504. }
  29505. break;
  29506. } else if (ch === 0x0A) { // LF
  29507. this.nextChar();
  29508. break;
  29509. }
  29510. ch = this.nextChar();
  29511. }
  29512. }
  29513. };
  29514. return Lexer;
  29515. })();
  29516. var Linearization = {
  29517. create: function LinearizationCreate(stream) {
  29518. function getInt(name, allowZeroValue) {
  29519. var obj = linDict.get(name);
  29520. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  29521. return obj;
  29522. }
  29523. throw new Error('The "' + name + '" parameter in the linearization ' +
  29524. 'dictionary is invalid.');
  29525. }
  29526. function getHints() {
  29527. var hints = linDict.get('H'), hintsLength, item;
  29528. if (isArray(hints) &&
  29529. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  29530. for (var index = 0; index < hintsLength; index++) {
  29531. if (!(isInt(item = hints[index]) && item > 0)) {
  29532. throw new Error('Hint (' + index +
  29533. ') in the linearization dictionary is invalid.');
  29534. }
  29535. }
  29536. return hints;
  29537. }
  29538. throw new Error('Hint array in the linearization dictionary is invalid.');
  29539. }
  29540. var parser = new Parser(new Lexer(stream), false, null);
  29541. var obj1 = parser.getObj();
  29542. var obj2 = parser.getObj();
  29543. var obj3 = parser.getObj();
  29544. var linDict = parser.getObj();
  29545. var obj, length;
  29546. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  29547. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  29548. return null; // No valid linearization dictionary found.
  29549. } else if ((length = getInt('L')) !== stream.length) {
  29550. throw new Error('The "L" parameter in the linearization dictionary ' +
  29551. 'does not equal the stream length.');
  29552. }
  29553. return {
  29554. length: length,
  29555. hints: getHints(),
  29556. objectNumberFirst: getInt('O'),
  29557. endFirst: getInt('E'),
  29558. numPages: getInt('N'),
  29559. mainXRefEntriesOffset: getInt('T'),
  29560. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  29561. };
  29562. }
  29563. };
  29564. var PostScriptParser = (function PostScriptParserClosure() {
  29565. function PostScriptParser(lexer) {
  29566. this.lexer = lexer;
  29567. this.operators = [];
  29568. this.token = null;
  29569. this.prev = null;
  29570. }
  29571. PostScriptParser.prototype = {
  29572. nextToken: function PostScriptParser_nextToken() {
  29573. this.prev = this.token;
  29574. this.token = this.lexer.getToken();
  29575. },
  29576. accept: function PostScriptParser_accept(type) {
  29577. if (this.token.type === type) {
  29578. this.nextToken();
  29579. return true;
  29580. }
  29581. return false;
  29582. },
  29583. expect: function PostScriptParser_expect(type) {
  29584. if (this.accept(type)) {
  29585. return true;
  29586. }
  29587. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29588. type + '.');
  29589. },
  29590. parse: function PostScriptParser_parse() {
  29591. this.nextToken();
  29592. this.expect(PostScriptTokenTypes.LBRACE);
  29593. this.parseBlock();
  29594. this.expect(PostScriptTokenTypes.RBRACE);
  29595. return this.operators;
  29596. },
  29597. parseBlock: function PostScriptParser_parseBlock() {
  29598. while (true) {
  29599. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29600. this.operators.push(this.prev.value);
  29601. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29602. this.operators.push(this.prev.value);
  29603. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29604. this.parseCondition();
  29605. } else {
  29606. return;
  29607. }
  29608. }
  29609. },
  29610. parseCondition: function PostScriptParser_parseCondition() {
  29611. // Add two place holders that will be updated later
  29612. var conditionLocation = this.operators.length;
  29613. this.operators.push(null, null);
  29614. this.parseBlock();
  29615. this.expect(PostScriptTokenTypes.RBRACE);
  29616. if (this.accept(PostScriptTokenTypes.IF)) {
  29617. // The true block is right after the 'if' so it just falls through on
  29618. // true else it jumps and skips the true block.
  29619. this.operators[conditionLocation] = this.operators.length;
  29620. this.operators[conditionLocation + 1] = 'jz';
  29621. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29622. var jumpLocation = this.operators.length;
  29623. this.operators.push(null, null);
  29624. var endOfTrue = this.operators.length;
  29625. this.parseBlock();
  29626. this.expect(PostScriptTokenTypes.RBRACE);
  29627. this.expect(PostScriptTokenTypes.IFELSE);
  29628. // The jump is added at the end of the true block to skip the false
  29629. // block.
  29630. this.operators[jumpLocation] = this.operators.length;
  29631. this.operators[jumpLocation + 1] = 'j';
  29632. this.operators[conditionLocation] = endOfTrue;
  29633. this.operators[conditionLocation + 1] = 'jz';
  29634. } else {
  29635. error('PS Function: error parsing conditional.');
  29636. }
  29637. }
  29638. };
  29639. return PostScriptParser;
  29640. })();
  29641. var PostScriptTokenTypes = {
  29642. LBRACE: 0,
  29643. RBRACE: 1,
  29644. NUMBER: 2,
  29645. OPERATOR: 3,
  29646. IF: 4,
  29647. IFELSE: 5
  29648. };
  29649. var PostScriptToken = (function PostScriptTokenClosure() {
  29650. function PostScriptToken(type, value) {
  29651. this.type = type;
  29652. this.value = value;
  29653. }
  29654. var opCache = {};
  29655. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29656. var opValue = opCache[op];
  29657. if (opValue) {
  29658. return opValue;
  29659. }
  29660. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29661. };
  29662. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29663. '{');
  29664. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29665. '}');
  29666. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29667. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29668. 'IFELSE');
  29669. return PostScriptToken;
  29670. })();
  29671. var PostScriptLexer = (function PostScriptLexerClosure() {
  29672. function PostScriptLexer(stream) {
  29673. this.stream = stream;
  29674. this.nextChar();
  29675. this.strBuf = [];
  29676. }
  29677. PostScriptLexer.prototype = {
  29678. nextChar: function PostScriptLexer_nextChar() {
  29679. return (this.currentChar = this.stream.getByte());
  29680. },
  29681. getToken: function PostScriptLexer_getToken() {
  29682. var comment = false;
  29683. var ch = this.currentChar;
  29684. // skip comments
  29685. while (true) {
  29686. if (ch < 0) {
  29687. return EOF;
  29688. }
  29689. if (comment) {
  29690. if (ch === 0x0A || ch === 0x0D) {
  29691. comment = false;
  29692. }
  29693. } else if (ch === 0x25) { // '%'
  29694. comment = true;
  29695. } else if (!Lexer.isSpace(ch)) {
  29696. break;
  29697. }
  29698. ch = this.nextChar();
  29699. }
  29700. switch (ch | 0) {
  29701. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29702. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29703. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29704. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29705. this.getNumber());
  29706. case 0x7B: // '{'
  29707. this.nextChar();
  29708. return PostScriptToken.LBRACE;
  29709. case 0x7D: // '}'
  29710. this.nextChar();
  29711. return PostScriptToken.RBRACE;
  29712. }
  29713. // operator
  29714. var strBuf = this.strBuf;
  29715. strBuf.length = 0;
  29716. strBuf[0] = String.fromCharCode(ch);
  29717. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29718. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29719. strBuf.push(String.fromCharCode(ch));
  29720. }
  29721. var str = strBuf.join('');
  29722. switch (str.toLowerCase()) {
  29723. case 'if':
  29724. return PostScriptToken.IF;
  29725. case 'ifelse':
  29726. return PostScriptToken.IFELSE;
  29727. default:
  29728. return PostScriptToken.getOperator(str);
  29729. }
  29730. },
  29731. getNumber: function PostScriptLexer_getNumber() {
  29732. var ch = this.currentChar;
  29733. var strBuf = this.strBuf;
  29734. strBuf.length = 0;
  29735. strBuf[0] = String.fromCharCode(ch);
  29736. while ((ch = this.nextChar()) >= 0) {
  29737. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29738. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29739. strBuf.push(String.fromCharCode(ch));
  29740. } else {
  29741. break;
  29742. }
  29743. }
  29744. var value = parseFloat(strBuf.join(''));
  29745. if (isNaN(value)) {
  29746. error('Invalid floating point number: ' + value);
  29747. }
  29748. return value;
  29749. }
  29750. };
  29751. return PostScriptLexer;
  29752. })();
  29753. var Stream = (function StreamClosure() {
  29754. function Stream(arrayBuffer, start, length, dict) {
  29755. this.bytes = (arrayBuffer instanceof Uint8Array ?
  29756. arrayBuffer : new Uint8Array(arrayBuffer));
  29757. this.start = start || 0;
  29758. this.pos = this.start;
  29759. this.end = (start + length) || this.bytes.length;
  29760. this.dict = dict;
  29761. }
  29762. // required methods for a stream. if a particular stream does not
  29763. // implement these, an error should be thrown
  29764. Stream.prototype = {
  29765. get length() {
  29766. return this.end - this.start;
  29767. },
  29768. get isEmpty() {
  29769. return this.length === 0;
  29770. },
  29771. getByte: function Stream_getByte() {
  29772. if (this.pos >= this.end) {
  29773. return -1;
  29774. }
  29775. return this.bytes[this.pos++];
  29776. },
  29777. getUint16: function Stream_getUint16() {
  29778. var b0 = this.getByte();
  29779. var b1 = this.getByte();
  29780. if (b0 === -1 || b1 === -1) {
  29781. return -1;
  29782. }
  29783. return (b0 << 8) + b1;
  29784. },
  29785. getInt32: function Stream_getInt32() {
  29786. var b0 = this.getByte();
  29787. var b1 = this.getByte();
  29788. var b2 = this.getByte();
  29789. var b3 = this.getByte();
  29790. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29791. },
  29792. // returns subarray of original buffer
  29793. // should only be read
  29794. getBytes: function Stream_getBytes(length) {
  29795. var bytes = this.bytes;
  29796. var pos = this.pos;
  29797. var strEnd = this.end;
  29798. if (!length) {
  29799. return bytes.subarray(pos, strEnd);
  29800. }
  29801. var end = pos + length;
  29802. if (end > strEnd) {
  29803. end = strEnd;
  29804. }
  29805. this.pos = end;
  29806. return bytes.subarray(pos, end);
  29807. },
  29808. peekByte: function Stream_peekByte() {
  29809. var peekedByte = this.getByte();
  29810. this.pos--;
  29811. return peekedByte;
  29812. },
  29813. peekBytes: function Stream_peekBytes(length) {
  29814. var bytes = this.getBytes(length);
  29815. this.pos -= bytes.length;
  29816. return bytes;
  29817. },
  29818. skip: function Stream_skip(n) {
  29819. if (!n) {
  29820. n = 1;
  29821. }
  29822. this.pos += n;
  29823. },
  29824. reset: function Stream_reset() {
  29825. this.pos = this.start;
  29826. },
  29827. moveStart: function Stream_moveStart() {
  29828. this.start = this.pos;
  29829. },
  29830. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  29831. return new Stream(this.bytes.buffer, start, length, dict);
  29832. },
  29833. isStream: true
  29834. };
  29835. return Stream;
  29836. })();
  29837. var StringStream = (function StringStreamClosure() {
  29838. function StringStream(str) {
  29839. var length = str.length;
  29840. var bytes = new Uint8Array(length);
  29841. for (var n = 0; n < length; ++n) {
  29842. bytes[n] = str.charCodeAt(n);
  29843. }
  29844. Stream.call(this, bytes);
  29845. }
  29846. StringStream.prototype = Stream.prototype;
  29847. return StringStream;
  29848. })();
  29849. // super class for the decoding streams
  29850. var DecodeStream = (function DecodeStreamClosure() {
  29851. // Lots of DecodeStreams are created whose buffers are never used. For these
  29852. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  29853. // having special cases that would be required if we used |null| for an empty
  29854. // buffer.
  29855. var emptyBuffer = new Uint8Array(0);
  29856. function DecodeStream(maybeMinBufferLength) {
  29857. this.pos = 0;
  29858. this.bufferLength = 0;
  29859. this.eof = false;
  29860. this.buffer = emptyBuffer;
  29861. this.minBufferLength = 512;
  29862. if (maybeMinBufferLength) {
  29863. // Compute the first power of two that is as big as maybeMinBufferLength.
  29864. while (this.minBufferLength < maybeMinBufferLength) {
  29865. this.minBufferLength *= 2;
  29866. }
  29867. }
  29868. }
  29869. DecodeStream.prototype = {
  29870. get isEmpty() {
  29871. while (!this.eof && this.bufferLength === 0) {
  29872. this.readBlock();
  29873. }
  29874. return this.bufferLength === 0;
  29875. },
  29876. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  29877. var buffer = this.buffer;
  29878. if (requested <= buffer.byteLength) {
  29879. return buffer;
  29880. }
  29881. var size = this.minBufferLength;
  29882. while (size < requested) {
  29883. size *= 2;
  29884. }
  29885. var buffer2 = new Uint8Array(size);
  29886. buffer2.set(buffer);
  29887. return (this.buffer = buffer2);
  29888. },
  29889. getByte: function DecodeStream_getByte() {
  29890. var pos = this.pos;
  29891. while (this.bufferLength <= pos) {
  29892. if (this.eof) {
  29893. return -1;
  29894. }
  29895. this.readBlock();
  29896. }
  29897. return this.buffer[this.pos++];
  29898. },
  29899. getUint16: function DecodeStream_getUint16() {
  29900. var b0 = this.getByte();
  29901. var b1 = this.getByte();
  29902. if (b0 === -1 || b1 === -1) {
  29903. return -1;
  29904. }
  29905. return (b0 << 8) + b1;
  29906. },
  29907. getInt32: function DecodeStream_getInt32() {
  29908. var b0 = this.getByte();
  29909. var b1 = this.getByte();
  29910. var b2 = this.getByte();
  29911. var b3 = this.getByte();
  29912. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  29913. },
  29914. getBytes: function DecodeStream_getBytes(length) {
  29915. var end, pos = this.pos;
  29916. if (length) {
  29917. this.ensureBuffer(pos + length);
  29918. end = pos + length;
  29919. while (!this.eof && this.bufferLength < end) {
  29920. this.readBlock();
  29921. }
  29922. var bufEnd = this.bufferLength;
  29923. if (end > bufEnd) {
  29924. end = bufEnd;
  29925. }
  29926. } else {
  29927. while (!this.eof) {
  29928. this.readBlock();
  29929. }
  29930. end = this.bufferLength;
  29931. }
  29932. this.pos = end;
  29933. return this.buffer.subarray(pos, end);
  29934. },
  29935. peekByte: function DecodeStream_peekByte() {
  29936. var peekedByte = this.getByte();
  29937. this.pos--;
  29938. return peekedByte;
  29939. },
  29940. peekBytes: function DecodeStream_peekBytes(length) {
  29941. var bytes = this.getBytes(length);
  29942. this.pos -= bytes.length;
  29943. return bytes;
  29944. },
  29945. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  29946. var end = start + length;
  29947. while (this.bufferLength <= end && !this.eof) {
  29948. this.readBlock();
  29949. }
  29950. return new Stream(this.buffer, start, length, dict);
  29951. },
  29952. skip: function DecodeStream_skip(n) {
  29953. if (!n) {
  29954. n = 1;
  29955. }
  29956. this.pos += n;
  29957. },
  29958. reset: function DecodeStream_reset() {
  29959. this.pos = 0;
  29960. },
  29961. getBaseStreams: function DecodeStream_getBaseStreams() {
  29962. if (this.str && this.str.getBaseStreams) {
  29963. return this.str.getBaseStreams();
  29964. }
  29965. return [];
  29966. }
  29967. };
  29968. return DecodeStream;
  29969. })();
  29970. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  29971. function StreamsSequenceStream(streams) {
  29972. this.streams = streams;
  29973. DecodeStream.call(this, /* maybeLength = */ null);
  29974. }
  29975. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  29976. StreamsSequenceStream.prototype.readBlock =
  29977. function streamSequenceStreamReadBlock() {
  29978. var streams = this.streams;
  29979. if (streams.length === 0) {
  29980. this.eof = true;
  29981. return;
  29982. }
  29983. var stream = streams.shift();
  29984. var chunk = stream.getBytes();
  29985. var bufferLength = this.bufferLength;
  29986. var newLength = bufferLength + chunk.length;
  29987. var buffer = this.ensureBuffer(newLength);
  29988. buffer.set(chunk, bufferLength);
  29989. this.bufferLength = newLength;
  29990. };
  29991. StreamsSequenceStream.prototype.getBaseStreams =
  29992. function StreamsSequenceStream_getBaseStreams() {
  29993. var baseStreams = [];
  29994. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  29995. var stream = this.streams[i];
  29996. if (stream.getBaseStreams) {
  29997. Util.appendToArray(baseStreams, stream.getBaseStreams());
  29998. }
  29999. }
  30000. return baseStreams;
  30001. };
  30002. return StreamsSequenceStream;
  30003. })();
  30004. var FlateStream = (function FlateStreamClosure() {
  30005. var codeLenCodeMap = new Int32Array([
  30006. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  30007. ]);
  30008. var lengthDecode = new Int32Array([
  30009. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  30010. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  30011. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  30012. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  30013. ]);
  30014. var distDecode = new Int32Array([
  30015. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  30016. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  30017. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  30018. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  30019. ]);
  30020. var fixedLitCodeTab = [new Int32Array([
  30021. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  30022. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  30023. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  30024. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  30025. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  30026. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  30027. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  30028. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  30029. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  30030. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  30031. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  30032. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  30033. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  30034. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  30035. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  30036. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  30037. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  30038. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  30039. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  30040. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  30041. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  30042. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  30043. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  30044. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  30045. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  30046. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  30047. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  30048. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  30049. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  30050. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  30051. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  30052. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  30053. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  30054. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  30055. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  30056. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  30057. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  30058. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  30059. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  30060. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  30061. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  30062. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  30063. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  30064. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  30065. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  30066. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  30067. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  30068. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  30069. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  30070. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  30071. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  30072. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  30073. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  30074. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  30075. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  30076. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  30077. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  30078. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  30079. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  30080. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  30081. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  30082. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  30083. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  30084. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  30085. ]), 9];
  30086. var fixedDistCodeTab = [new Int32Array([
  30087. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  30088. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  30089. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  30090. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  30091. ]), 5];
  30092. function FlateStream(str, maybeLength) {
  30093. this.str = str;
  30094. this.dict = str.dict;
  30095. var cmf = str.getByte();
  30096. var flg = str.getByte();
  30097. if (cmf === -1 || flg === -1) {
  30098. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  30099. }
  30100. if ((cmf & 0x0f) !== 0x08) {
  30101. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  30102. }
  30103. if ((((cmf << 8) + flg) % 31) !== 0) {
  30104. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  30105. }
  30106. if (flg & 0x20) {
  30107. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  30108. }
  30109. this.codeSize = 0;
  30110. this.codeBuf = 0;
  30111. DecodeStream.call(this, maybeLength);
  30112. }
  30113. FlateStream.prototype = Object.create(DecodeStream.prototype);
  30114. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  30115. var str = this.str;
  30116. var codeSize = this.codeSize;
  30117. var codeBuf = this.codeBuf;
  30118. var b;
  30119. while (codeSize < bits) {
  30120. if ((b = str.getByte()) === -1) {
  30121. error('Bad encoding in flate stream');
  30122. }
  30123. codeBuf |= b << codeSize;
  30124. codeSize += 8;
  30125. }
  30126. b = codeBuf & ((1 << bits) - 1);
  30127. this.codeBuf = codeBuf >> bits;
  30128. this.codeSize = codeSize -= bits;
  30129. return b;
  30130. };
  30131. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  30132. var str = this.str;
  30133. var codes = table[0];
  30134. var maxLen = table[1];
  30135. var codeSize = this.codeSize;
  30136. var codeBuf = this.codeBuf;
  30137. var b;
  30138. while (codeSize < maxLen) {
  30139. if ((b = str.getByte()) === -1) {
  30140. // premature end of stream. code might however still be valid.
  30141. // codeSize < codeLen check below guards against incomplete codeVal.
  30142. break;
  30143. }
  30144. codeBuf |= (b << codeSize);
  30145. codeSize += 8;
  30146. }
  30147. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  30148. var codeLen = code >> 16;
  30149. var codeVal = code & 0xffff;
  30150. if (codeLen < 1 || codeSize < codeLen) {
  30151. error('Bad encoding in flate stream');
  30152. }
  30153. this.codeBuf = (codeBuf >> codeLen);
  30154. this.codeSize = (codeSize - codeLen);
  30155. return codeVal;
  30156. };
  30157. FlateStream.prototype.generateHuffmanTable =
  30158. function flateStreamGenerateHuffmanTable(lengths) {
  30159. var n = lengths.length;
  30160. // find max code length
  30161. var maxLen = 0;
  30162. var i;
  30163. for (i = 0; i < n; ++i) {
  30164. if (lengths[i] > maxLen) {
  30165. maxLen = lengths[i];
  30166. }
  30167. }
  30168. // build the table
  30169. var size = 1 << maxLen;
  30170. var codes = new Int32Array(size);
  30171. for (var len = 1, code = 0, skip = 2;
  30172. len <= maxLen;
  30173. ++len, code <<= 1, skip <<= 1) {
  30174. for (var val = 0; val < n; ++val) {
  30175. if (lengths[val] === len) {
  30176. // bit-reverse the code
  30177. var code2 = 0;
  30178. var t = code;
  30179. for (i = 0; i < len; ++i) {
  30180. code2 = (code2 << 1) | (t & 1);
  30181. t >>= 1;
  30182. }
  30183. // fill the table entries
  30184. for (i = code2; i < size; i += skip) {
  30185. codes[i] = (len << 16) | val;
  30186. }
  30187. ++code;
  30188. }
  30189. }
  30190. }
  30191. return [codes, maxLen];
  30192. };
  30193. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  30194. var buffer, len;
  30195. var str = this.str;
  30196. // read block header
  30197. var hdr = this.getBits(3);
  30198. if (hdr & 1) {
  30199. this.eof = true;
  30200. }
  30201. hdr >>= 1;
  30202. if (hdr === 0) { // uncompressed block
  30203. var b;
  30204. if ((b = str.getByte()) === -1) {
  30205. error('Bad block header in flate stream');
  30206. }
  30207. var blockLen = b;
  30208. if ((b = str.getByte()) === -1) {
  30209. error('Bad block header in flate stream');
  30210. }
  30211. blockLen |= (b << 8);
  30212. if ((b = str.getByte()) === -1) {
  30213. error('Bad block header in flate stream');
  30214. }
  30215. var check = b;
  30216. if ((b = str.getByte()) === -1) {
  30217. error('Bad block header in flate stream');
  30218. }
  30219. check |= (b << 8);
  30220. if (check !== (~blockLen & 0xffff) &&
  30221. (blockLen !== 0 || check !== 0)) {
  30222. // Ignoring error for bad "empty" block (see issue 1277)
  30223. error('Bad uncompressed block length in flate stream');
  30224. }
  30225. this.codeBuf = 0;
  30226. this.codeSize = 0;
  30227. var bufferLength = this.bufferLength;
  30228. buffer = this.ensureBuffer(bufferLength + blockLen);
  30229. var end = bufferLength + blockLen;
  30230. this.bufferLength = end;
  30231. if (blockLen === 0) {
  30232. if (str.peekByte() === -1) {
  30233. this.eof = true;
  30234. }
  30235. } else {
  30236. for (var n = bufferLength; n < end; ++n) {
  30237. if ((b = str.getByte()) === -1) {
  30238. this.eof = true;
  30239. break;
  30240. }
  30241. buffer[n] = b;
  30242. }
  30243. }
  30244. return;
  30245. }
  30246. var litCodeTable;
  30247. var distCodeTable;
  30248. if (hdr === 1) { // compressed block, fixed codes
  30249. litCodeTable = fixedLitCodeTab;
  30250. distCodeTable = fixedDistCodeTab;
  30251. } else if (hdr === 2) { // compressed block, dynamic codes
  30252. var numLitCodes = this.getBits(5) + 257;
  30253. var numDistCodes = this.getBits(5) + 1;
  30254. var numCodeLenCodes = this.getBits(4) + 4;
  30255. // build the code lengths code table
  30256. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  30257. var i;
  30258. for (i = 0; i < numCodeLenCodes; ++i) {
  30259. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  30260. }
  30261. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  30262. // build the literal and distance code tables
  30263. len = 0;
  30264. i = 0;
  30265. var codes = numLitCodes + numDistCodes;
  30266. var codeLengths = new Uint8Array(codes);
  30267. var bitsLength, bitsOffset, what;
  30268. while (i < codes) {
  30269. var code = this.getCode(codeLenCodeTab);
  30270. if (code === 16) {
  30271. bitsLength = 2; bitsOffset = 3; what = len;
  30272. } else if (code === 17) {
  30273. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  30274. } else if (code === 18) {
  30275. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  30276. } else {
  30277. codeLengths[i++] = len = code;
  30278. continue;
  30279. }
  30280. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  30281. while (repeatLength-- > 0) {
  30282. codeLengths[i++] = what;
  30283. }
  30284. }
  30285. litCodeTable =
  30286. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  30287. distCodeTable =
  30288. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  30289. } else {
  30290. error('Unknown block type in flate stream');
  30291. }
  30292. buffer = this.buffer;
  30293. var limit = buffer ? buffer.length : 0;
  30294. var pos = this.bufferLength;
  30295. while (true) {
  30296. var code1 = this.getCode(litCodeTable);
  30297. if (code1 < 256) {
  30298. if (pos + 1 >= limit) {
  30299. buffer = this.ensureBuffer(pos + 1);
  30300. limit = buffer.length;
  30301. }
  30302. buffer[pos++] = code1;
  30303. continue;
  30304. }
  30305. if (code1 === 256) {
  30306. this.bufferLength = pos;
  30307. return;
  30308. }
  30309. code1 -= 257;
  30310. code1 = lengthDecode[code1];
  30311. var code2 = code1 >> 16;
  30312. if (code2 > 0) {
  30313. code2 = this.getBits(code2);
  30314. }
  30315. len = (code1 & 0xffff) + code2;
  30316. code1 = this.getCode(distCodeTable);
  30317. code1 = distDecode[code1];
  30318. code2 = code1 >> 16;
  30319. if (code2 > 0) {
  30320. code2 = this.getBits(code2);
  30321. }
  30322. var dist = (code1 & 0xffff) + code2;
  30323. if (pos + len >= limit) {
  30324. buffer = this.ensureBuffer(pos + len);
  30325. limit = buffer.length;
  30326. }
  30327. for (var k = 0; k < len; ++k, ++pos) {
  30328. buffer[pos] = buffer[pos - dist];
  30329. }
  30330. }
  30331. };
  30332. return FlateStream;
  30333. })();
  30334. var PredictorStream = (function PredictorStreamClosure() {
  30335. function PredictorStream(str, maybeLength, params) {
  30336. var predictor = this.predictor = params.get('Predictor') || 1;
  30337. if (predictor <= 1) {
  30338. return str; // no prediction
  30339. }
  30340. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  30341. error('Unsupported predictor: ' + predictor);
  30342. }
  30343. if (predictor === 2) {
  30344. this.readBlock = this.readBlockTiff;
  30345. } else {
  30346. this.readBlock = this.readBlockPng;
  30347. }
  30348. this.str = str;
  30349. this.dict = str.dict;
  30350. var colors = this.colors = params.get('Colors') || 1;
  30351. var bits = this.bits = params.get('BitsPerComponent') || 8;
  30352. var columns = this.columns = params.get('Columns') || 1;
  30353. this.pixBytes = (colors * bits + 7) >> 3;
  30354. this.rowBytes = (columns * colors * bits + 7) >> 3;
  30355. DecodeStream.call(this, maybeLength);
  30356. return this;
  30357. }
  30358. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  30359. PredictorStream.prototype.readBlockTiff =
  30360. function predictorStreamReadBlockTiff() {
  30361. var rowBytes = this.rowBytes;
  30362. var bufferLength = this.bufferLength;
  30363. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30364. var bits = this.bits;
  30365. var colors = this.colors;
  30366. var rawBytes = this.str.getBytes(rowBytes);
  30367. this.eof = !rawBytes.length;
  30368. if (this.eof) {
  30369. return;
  30370. }
  30371. var inbuf = 0, outbuf = 0;
  30372. var inbits = 0, outbits = 0;
  30373. var pos = bufferLength;
  30374. var i;
  30375. if (bits === 1) {
  30376. for (i = 0; i < rowBytes; ++i) {
  30377. var c = rawBytes[i];
  30378. inbuf = (inbuf << 8) | c;
  30379. // bitwise addition is exclusive or
  30380. // first shift inbuf and then add
  30381. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  30382. // truncate inbuf (assumes colors < 16)
  30383. inbuf &= 0xFFFF;
  30384. }
  30385. } else if (bits === 8) {
  30386. for (i = 0; i < colors; ++i) {
  30387. buffer[pos++] = rawBytes[i];
  30388. }
  30389. for (; i < rowBytes; ++i) {
  30390. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  30391. pos++;
  30392. }
  30393. } else {
  30394. var compArray = new Uint8Array(colors + 1);
  30395. var bitMask = (1 << bits) - 1;
  30396. var j = 0, k = bufferLength;
  30397. var columns = this.columns;
  30398. for (i = 0; i < columns; ++i) {
  30399. for (var kk = 0; kk < colors; ++kk) {
  30400. if (inbits < bits) {
  30401. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  30402. inbits += 8;
  30403. }
  30404. compArray[kk] = (compArray[kk] +
  30405. (inbuf >> (inbits - bits))) & bitMask;
  30406. inbits -= bits;
  30407. outbuf = (outbuf << bits) | compArray[kk];
  30408. outbits += bits;
  30409. if (outbits >= 8) {
  30410. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  30411. outbits -= 8;
  30412. }
  30413. }
  30414. }
  30415. if (outbits > 0) {
  30416. buffer[k++] = (outbuf << (8 - outbits)) +
  30417. (inbuf & ((1 << (8 - outbits)) - 1));
  30418. }
  30419. }
  30420. this.bufferLength += rowBytes;
  30421. };
  30422. PredictorStream.prototype.readBlockPng =
  30423. function predictorStreamReadBlockPng() {
  30424. var rowBytes = this.rowBytes;
  30425. var pixBytes = this.pixBytes;
  30426. var predictor = this.str.getByte();
  30427. var rawBytes = this.str.getBytes(rowBytes);
  30428. this.eof = !rawBytes.length;
  30429. if (this.eof) {
  30430. return;
  30431. }
  30432. var bufferLength = this.bufferLength;
  30433. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  30434. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  30435. if (prevRow.length === 0) {
  30436. prevRow = new Uint8Array(rowBytes);
  30437. }
  30438. var i, j = bufferLength, up, c;
  30439. switch (predictor) {
  30440. case 0:
  30441. for (i = 0; i < rowBytes; ++i) {
  30442. buffer[j++] = rawBytes[i];
  30443. }
  30444. break;
  30445. case 1:
  30446. for (i = 0; i < pixBytes; ++i) {
  30447. buffer[j++] = rawBytes[i];
  30448. }
  30449. for (; i < rowBytes; ++i) {
  30450. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  30451. j++;
  30452. }
  30453. break;
  30454. case 2:
  30455. for (i = 0; i < rowBytes; ++i) {
  30456. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  30457. }
  30458. break;
  30459. case 3:
  30460. for (i = 0; i < pixBytes; ++i) {
  30461. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  30462. }
  30463. for (; i < rowBytes; ++i) {
  30464. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  30465. rawBytes[i]) & 0xFF;
  30466. j++;
  30467. }
  30468. break;
  30469. case 4:
  30470. // we need to save the up left pixels values. the simplest way
  30471. // is to create a new buffer
  30472. for (i = 0; i < pixBytes; ++i) {
  30473. up = prevRow[i];
  30474. c = rawBytes[i];
  30475. buffer[j++] = up + c;
  30476. }
  30477. for (; i < rowBytes; ++i) {
  30478. up = prevRow[i];
  30479. var upLeft = prevRow[i - pixBytes];
  30480. var left = buffer[j - pixBytes];
  30481. var p = left + up - upLeft;
  30482. var pa = p - left;
  30483. if (pa < 0) {
  30484. pa = -pa;
  30485. }
  30486. var pb = p - up;
  30487. if (pb < 0) {
  30488. pb = -pb;
  30489. }
  30490. var pc = p - upLeft;
  30491. if (pc < 0) {
  30492. pc = -pc;
  30493. }
  30494. c = rawBytes[i];
  30495. if (pa <= pb && pa <= pc) {
  30496. buffer[j++] = left + c;
  30497. } else if (pb <= pc) {
  30498. buffer[j++] = up + c;
  30499. } else {
  30500. buffer[j++] = upLeft + c;
  30501. }
  30502. }
  30503. break;
  30504. default:
  30505. error('Unsupported predictor: ' + predictor);
  30506. }
  30507. this.bufferLength += rowBytes;
  30508. };
  30509. return PredictorStream;
  30510. })();
  30511. /**
  30512. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  30513. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  30514. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  30515. * a library to decode these images and the stream behaves like all the other
  30516. * DecodeStreams.
  30517. */
  30518. var JpegStream = (function JpegStreamClosure() {
  30519. function JpegStream(stream, maybeLength, dict, xref) {
  30520. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  30521. // Note: this seems to mainly affect inline images.
  30522. var ch;
  30523. while ((ch = stream.getByte()) !== -1) {
  30524. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  30525. stream.skip(-1); // Reset the stream position to the SOI.
  30526. break;
  30527. }
  30528. }
  30529. this.stream = stream;
  30530. this.maybeLength = maybeLength;
  30531. this.dict = dict;
  30532. DecodeStream.call(this, maybeLength);
  30533. }
  30534. JpegStream.prototype = Object.create(DecodeStream.prototype);
  30535. Object.defineProperty(JpegStream.prototype, 'bytes', {
  30536. get: function JpegStream_bytes() {
  30537. // If this.maybeLength is null, we'll get the entire stream.
  30538. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30539. },
  30540. configurable: true
  30541. });
  30542. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  30543. if (this.bufferLength) {
  30544. return;
  30545. }
  30546. try {
  30547. var jpegImage = new JpegImage();
  30548. // checking if values needs to be transformed before conversion
  30549. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  30550. var decodeArr = this.dict.get('Decode');
  30551. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  30552. var decodeArrLength = decodeArr.length;
  30553. var transform = new Int32Array(decodeArrLength);
  30554. var transformNeeded = false;
  30555. var maxValue = (1 << bitsPerComponent) - 1;
  30556. for (var i = 0; i < decodeArrLength; i += 2) {
  30557. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  30558. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  30559. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  30560. transformNeeded = true;
  30561. }
  30562. }
  30563. if (transformNeeded) {
  30564. jpegImage.decodeTransform = transform;
  30565. }
  30566. }
  30567. jpegImage.parse(this.bytes);
  30568. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  30569. this.forceRGB);
  30570. this.buffer = data;
  30571. this.bufferLength = data.length;
  30572. this.eof = true;
  30573. } catch (e) {
  30574. error('JPEG error: ' + e);
  30575. }
  30576. };
  30577. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  30578. this.ensureBuffer();
  30579. return this.buffer;
  30580. };
  30581. JpegStream.prototype.getIR = function JpegStream_getIR() {
  30582. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  30583. };
  30584. /**
  30585. * Checks if the image can be decoded and displayed by the browser without any
  30586. * further processing such as color space conversions.
  30587. */
  30588. JpegStream.prototype.isNativelySupported =
  30589. function JpegStream_isNativelySupported(xref, res) {
  30590. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30591. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  30592. };
  30593. /**
  30594. * Checks if the image can be decoded by the browser.
  30595. */
  30596. JpegStream.prototype.isNativelyDecodable =
  30597. function JpegStream_isNativelyDecodable(xref, res) {
  30598. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  30599. var numComps = cs.numComps;
  30600. return numComps === 1 || numComps === 3;
  30601. };
  30602. return JpegStream;
  30603. })();
  30604. /**
  30605. * For JPEG 2000's we use a library to decode these images and
  30606. * the stream behaves like all the other DecodeStreams.
  30607. */
  30608. var JpxStream = (function JpxStreamClosure() {
  30609. function JpxStream(stream, maybeLength, dict) {
  30610. this.stream = stream;
  30611. this.maybeLength = maybeLength;
  30612. this.dict = dict;
  30613. DecodeStream.call(this, maybeLength);
  30614. }
  30615. JpxStream.prototype = Object.create(DecodeStream.prototype);
  30616. Object.defineProperty(JpxStream.prototype, 'bytes', {
  30617. get: function JpxStream_bytes() {
  30618. // If this.maybeLength is null, we'll get the entire stream.
  30619. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30620. },
  30621. configurable: true
  30622. });
  30623. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  30624. if (this.bufferLength) {
  30625. return;
  30626. }
  30627. var jpxImage = new JpxImage();
  30628. jpxImage.parse(this.bytes);
  30629. var width = jpxImage.width;
  30630. var height = jpxImage.height;
  30631. var componentsCount = jpxImage.componentsCount;
  30632. var tileCount = jpxImage.tiles.length;
  30633. if (tileCount === 1) {
  30634. this.buffer = jpxImage.tiles[0].items;
  30635. } else {
  30636. var data = new Uint8Array(width * height * componentsCount);
  30637. for (var k = 0; k < tileCount; k++) {
  30638. var tileComponents = jpxImage.tiles[k];
  30639. var tileWidth = tileComponents.width;
  30640. var tileHeight = tileComponents.height;
  30641. var tileLeft = tileComponents.left;
  30642. var tileTop = tileComponents.top;
  30643. var src = tileComponents.items;
  30644. var srcPosition = 0;
  30645. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  30646. var imgRowSize = width * componentsCount;
  30647. var tileRowSize = tileWidth * componentsCount;
  30648. for (var j = 0; j < tileHeight; j++) {
  30649. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  30650. data.set(rowBytes, dataPosition);
  30651. srcPosition += tileRowSize;
  30652. dataPosition += imgRowSize;
  30653. }
  30654. }
  30655. this.buffer = data;
  30656. }
  30657. this.bufferLength = this.buffer.length;
  30658. this.eof = true;
  30659. };
  30660. return JpxStream;
  30661. })();
  30662. /**
  30663. * For JBIG2's we use a library to decode these images and
  30664. * the stream behaves like all the other DecodeStreams.
  30665. */
  30666. var Jbig2Stream = (function Jbig2StreamClosure() {
  30667. function Jbig2Stream(stream, maybeLength, dict) {
  30668. this.stream = stream;
  30669. this.maybeLength = maybeLength;
  30670. this.dict = dict;
  30671. DecodeStream.call(this, maybeLength);
  30672. }
  30673. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  30674. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  30675. get: function Jbig2Stream_bytes() {
  30676. // If this.maybeLength is null, we'll get the entire stream.
  30677. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  30678. },
  30679. configurable: true
  30680. });
  30681. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  30682. if (this.bufferLength) {
  30683. return;
  30684. }
  30685. var jbig2Image = new Jbig2Image();
  30686. var chunks = [], xref = this.dict.xref;
  30687. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  30688. // According to the PDF specification, DecodeParms can be either
  30689. // a dictionary, or an array whose elements are dictionaries.
  30690. if (isArray(decodeParams)) {
  30691. if (decodeParams.length > 1) {
  30692. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  30693. 'not supported.');
  30694. }
  30695. decodeParams = xref.fetchIfRef(decodeParams[0]);
  30696. }
  30697. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  30698. var globalsStream = decodeParams.get('JBIG2Globals');
  30699. var globals = globalsStream.getBytes();
  30700. chunks.push({data: globals, start: 0, end: globals.length});
  30701. }
  30702. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  30703. var data = jbig2Image.parseChunks(chunks);
  30704. var dataLength = data.length;
  30705. // JBIG2 had black as 1 and white as 0, inverting the colors
  30706. for (var i = 0; i < dataLength; i++) {
  30707. data[i] ^= 0xFF;
  30708. }
  30709. this.buffer = data;
  30710. this.bufferLength = dataLength;
  30711. this.eof = true;
  30712. };
  30713. return Jbig2Stream;
  30714. })();
  30715. var DecryptStream = (function DecryptStreamClosure() {
  30716. function DecryptStream(str, maybeLength, decrypt) {
  30717. this.str = str;
  30718. this.dict = str.dict;
  30719. this.decrypt = decrypt;
  30720. this.nextChunk = null;
  30721. this.initialized = false;
  30722. DecodeStream.call(this, maybeLength);
  30723. }
  30724. var chunkSize = 512;
  30725. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  30726. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  30727. var chunk;
  30728. if (this.initialized) {
  30729. chunk = this.nextChunk;
  30730. } else {
  30731. chunk = this.str.getBytes(chunkSize);
  30732. this.initialized = true;
  30733. }
  30734. if (!chunk || chunk.length === 0) {
  30735. this.eof = true;
  30736. return;
  30737. }
  30738. this.nextChunk = this.str.getBytes(chunkSize);
  30739. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  30740. var decrypt = this.decrypt;
  30741. chunk = decrypt(chunk, !hasMoreData);
  30742. var bufferLength = this.bufferLength;
  30743. var i, n = chunk.length;
  30744. var buffer = this.ensureBuffer(bufferLength + n);
  30745. for (i = 0; i < n; i++) {
  30746. buffer[bufferLength++] = chunk[i];
  30747. }
  30748. this.bufferLength = bufferLength;
  30749. };
  30750. return DecryptStream;
  30751. })();
  30752. var Ascii85Stream = (function Ascii85StreamClosure() {
  30753. function Ascii85Stream(str, maybeLength) {
  30754. this.str = str;
  30755. this.dict = str.dict;
  30756. this.input = new Uint8Array(5);
  30757. // Most streams increase in size when decoded, but Ascii85 streams
  30758. // typically shrink by ~20%.
  30759. if (maybeLength) {
  30760. maybeLength = 0.8 * maybeLength;
  30761. }
  30762. DecodeStream.call(this, maybeLength);
  30763. }
  30764. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  30765. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  30766. var TILDA_CHAR = 0x7E; // '~'
  30767. var Z_LOWER_CHAR = 0x7A; // 'z'
  30768. var EOF = -1;
  30769. var str = this.str;
  30770. var c = str.getByte();
  30771. while (Lexer.isSpace(c)) {
  30772. c = str.getByte();
  30773. }
  30774. if (c === EOF || c === TILDA_CHAR) {
  30775. this.eof = true;
  30776. return;
  30777. }
  30778. var bufferLength = this.bufferLength, buffer;
  30779. var i;
  30780. // special code for z
  30781. if (c === Z_LOWER_CHAR) {
  30782. buffer = this.ensureBuffer(bufferLength + 4);
  30783. for (i = 0; i < 4; ++i) {
  30784. buffer[bufferLength + i] = 0;
  30785. }
  30786. this.bufferLength += 4;
  30787. } else {
  30788. var input = this.input;
  30789. input[0] = c;
  30790. for (i = 1; i < 5; ++i) {
  30791. c = str.getByte();
  30792. while (Lexer.isSpace(c)) {
  30793. c = str.getByte();
  30794. }
  30795. input[i] = c;
  30796. if (c === EOF || c === TILDA_CHAR) {
  30797. break;
  30798. }
  30799. }
  30800. buffer = this.ensureBuffer(bufferLength + i - 1);
  30801. this.bufferLength += i - 1;
  30802. // partial ending;
  30803. if (i < 5) {
  30804. for (; i < 5; ++i) {
  30805. input[i] = 0x21 + 84;
  30806. }
  30807. this.eof = true;
  30808. }
  30809. var t = 0;
  30810. for (i = 0; i < 5; ++i) {
  30811. t = t * 85 + (input[i] - 0x21);
  30812. }
  30813. for (i = 3; i >= 0; --i) {
  30814. buffer[bufferLength + i] = t & 0xFF;
  30815. t >>= 8;
  30816. }
  30817. }
  30818. };
  30819. return Ascii85Stream;
  30820. })();
  30821. var AsciiHexStream = (function AsciiHexStreamClosure() {
  30822. function AsciiHexStream(str, maybeLength) {
  30823. this.str = str;
  30824. this.dict = str.dict;
  30825. this.firstDigit = -1;
  30826. // Most streams increase in size when decoded, but AsciiHex streams shrink
  30827. // by 50%.
  30828. if (maybeLength) {
  30829. maybeLength = 0.5 * maybeLength;
  30830. }
  30831. DecodeStream.call(this, maybeLength);
  30832. }
  30833. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  30834. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  30835. var UPSTREAM_BLOCK_SIZE = 8000;
  30836. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  30837. if (!bytes.length) {
  30838. this.eof = true;
  30839. return;
  30840. }
  30841. var maxDecodeLength = (bytes.length + 1) >> 1;
  30842. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  30843. var bufferLength = this.bufferLength;
  30844. var firstDigit = this.firstDigit;
  30845. for (var i = 0, ii = bytes.length; i < ii; i++) {
  30846. var ch = bytes[i], digit;
  30847. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  30848. digit = ch & 0x0F;
  30849. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  30850. // 'A'-'Z', 'a'-'z'
  30851. digit = (ch & 0x0F) + 9;
  30852. } else if (ch === 0x3E) { // '>'
  30853. this.eof = true;
  30854. break;
  30855. } else { // probably whitespace
  30856. continue; // ignoring
  30857. }
  30858. if (firstDigit < 0) {
  30859. firstDigit = digit;
  30860. } else {
  30861. buffer[bufferLength++] = (firstDigit << 4) | digit;
  30862. firstDigit = -1;
  30863. }
  30864. }
  30865. if (firstDigit >= 0 && this.eof) {
  30866. // incomplete byte
  30867. buffer[bufferLength++] = (firstDigit << 4);
  30868. firstDigit = -1;
  30869. }
  30870. this.firstDigit = firstDigit;
  30871. this.bufferLength = bufferLength;
  30872. };
  30873. return AsciiHexStream;
  30874. })();
  30875. var RunLengthStream = (function RunLengthStreamClosure() {
  30876. function RunLengthStream(str, maybeLength) {
  30877. this.str = str;
  30878. this.dict = str.dict;
  30879. DecodeStream.call(this, maybeLength);
  30880. }
  30881. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  30882. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  30883. // The repeatHeader has following format. The first byte defines type of run
  30884. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  30885. // (in addition to the second byte from the header), n = 129 through 255 -
  30886. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  30887. var repeatHeader = this.str.getBytes(2);
  30888. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  30889. this.eof = true;
  30890. return;
  30891. }
  30892. var buffer;
  30893. var bufferLength = this.bufferLength;
  30894. var n = repeatHeader[0];
  30895. if (n < 128) {
  30896. // copy n bytes
  30897. buffer = this.ensureBuffer(bufferLength + n + 1);
  30898. buffer[bufferLength++] = repeatHeader[1];
  30899. if (n > 0) {
  30900. var source = this.str.getBytes(n);
  30901. buffer.set(source, bufferLength);
  30902. bufferLength += n;
  30903. }
  30904. } else {
  30905. n = 257 - n;
  30906. var b = repeatHeader[1];
  30907. buffer = this.ensureBuffer(bufferLength + n + 1);
  30908. for (var i = 0; i < n; i++) {
  30909. buffer[bufferLength++] = b;
  30910. }
  30911. }
  30912. this.bufferLength = bufferLength;
  30913. };
  30914. return RunLengthStream;
  30915. })();
  30916. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  30917. var ccittEOL = -2;
  30918. var twoDimPass = 0;
  30919. var twoDimHoriz = 1;
  30920. var twoDimVert0 = 2;
  30921. var twoDimVertR1 = 3;
  30922. var twoDimVertL1 = 4;
  30923. var twoDimVertR2 = 5;
  30924. var twoDimVertL2 = 6;
  30925. var twoDimVertR3 = 7;
  30926. var twoDimVertL3 = 8;
  30927. var twoDimTable = [
  30928. [-1, -1], [-1, -1], // 000000x
  30929. [7, twoDimVertL3], // 0000010
  30930. [7, twoDimVertR3], // 0000011
  30931. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  30932. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  30933. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  30934. [4, twoDimPass], [4, twoDimPass],
  30935. [4, twoDimPass], [4, twoDimPass],
  30936. [4, twoDimPass], [4, twoDimPass],
  30937. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  30938. [3, twoDimHoriz], [3, twoDimHoriz],
  30939. [3, twoDimHoriz], [3, twoDimHoriz],
  30940. [3, twoDimHoriz], [3, twoDimHoriz],
  30941. [3, twoDimHoriz], [3, twoDimHoriz],
  30942. [3, twoDimHoriz], [3, twoDimHoriz],
  30943. [3, twoDimHoriz], [3, twoDimHoriz],
  30944. [3, twoDimHoriz], [3, twoDimHoriz],
  30945. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  30946. [3, twoDimVertL1], [3, twoDimVertL1],
  30947. [3, twoDimVertL1], [3, twoDimVertL1],
  30948. [3, twoDimVertL1], [3, twoDimVertL1],
  30949. [3, twoDimVertL1], [3, twoDimVertL1],
  30950. [3, twoDimVertL1], [3, twoDimVertL1],
  30951. [3, twoDimVertL1], [3, twoDimVertL1],
  30952. [3, twoDimVertL1], [3, twoDimVertL1],
  30953. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  30954. [3, twoDimVertR1], [3, twoDimVertR1],
  30955. [3, twoDimVertR1], [3, twoDimVertR1],
  30956. [3, twoDimVertR1], [3, twoDimVertR1],
  30957. [3, twoDimVertR1], [3, twoDimVertR1],
  30958. [3, twoDimVertR1], [3, twoDimVertR1],
  30959. [3, twoDimVertR1], [3, twoDimVertR1],
  30960. [3, twoDimVertR1], [3, twoDimVertR1],
  30961. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  30962. [1, twoDimVert0], [1, twoDimVert0],
  30963. [1, twoDimVert0], [1, twoDimVert0],
  30964. [1, twoDimVert0], [1, twoDimVert0],
  30965. [1, twoDimVert0], [1, twoDimVert0],
  30966. [1, twoDimVert0], [1, twoDimVert0],
  30967. [1, twoDimVert0], [1, twoDimVert0],
  30968. [1, twoDimVert0], [1, twoDimVert0],
  30969. [1, twoDimVert0], [1, twoDimVert0],
  30970. [1, twoDimVert0], [1, twoDimVert0],
  30971. [1, twoDimVert0], [1, twoDimVert0],
  30972. [1, twoDimVert0], [1, twoDimVert0],
  30973. [1, twoDimVert0], [1, twoDimVert0],
  30974. [1, twoDimVert0], [1, twoDimVert0],
  30975. [1, twoDimVert0], [1, twoDimVert0],
  30976. [1, twoDimVert0], [1, twoDimVert0],
  30977. [1, twoDimVert0], [1, twoDimVert0],
  30978. [1, twoDimVert0], [1, twoDimVert0],
  30979. [1, twoDimVert0], [1, twoDimVert0],
  30980. [1, twoDimVert0], [1, twoDimVert0],
  30981. [1, twoDimVert0], [1, twoDimVert0],
  30982. [1, twoDimVert0], [1, twoDimVert0],
  30983. [1, twoDimVert0], [1, twoDimVert0],
  30984. [1, twoDimVert0], [1, twoDimVert0],
  30985. [1, twoDimVert0], [1, twoDimVert0],
  30986. [1, twoDimVert0], [1, twoDimVert0],
  30987. [1, twoDimVert0], [1, twoDimVert0],
  30988. [1, twoDimVert0], [1, twoDimVert0],
  30989. [1, twoDimVert0], [1, twoDimVert0],
  30990. [1, twoDimVert0], [1, twoDimVert0],
  30991. [1, twoDimVert0], [1, twoDimVert0],
  30992. [1, twoDimVert0], [1, twoDimVert0]
  30993. ];
  30994. var whiteTable1 = [
  30995. [-1, -1], // 00000
  30996. [12, ccittEOL], // 00001
  30997. [-1, -1], [-1, -1], // 0001x
  30998. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  30999. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  31000. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  31001. [11, 1792], [11, 1792], // 1000x
  31002. [12, 1984], // 10010
  31003. [12, 2048], // 10011
  31004. [12, 2112], // 10100
  31005. [12, 2176], // 10101
  31006. [12, 2240], // 10110
  31007. [12, 2304], // 10111
  31008. [11, 1856], [11, 1856], // 1100x
  31009. [11, 1920], [11, 1920], // 1101x
  31010. [12, 2368], // 11100
  31011. [12, 2432], // 11101
  31012. [12, 2496], // 11110
  31013. [12, 2560] // 11111
  31014. ];
  31015. var whiteTable2 = [
  31016. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  31017. [8, 29], [8, 29], // 00000010x
  31018. [8, 30], [8, 30], // 00000011x
  31019. [8, 45], [8, 45], // 00000100x
  31020. [8, 46], [8, 46], // 00000101x
  31021. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  31022. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  31023. [8, 47], [8, 47], // 00001010x
  31024. [8, 48], [8, 48], // 00001011x
  31025. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  31026. [6, 13], [6, 13], [6, 13], [6, 13],
  31027. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  31028. [8, 33], [8, 33], // 00010010x
  31029. [8, 34], [8, 34], // 00010011x
  31030. [8, 35], [8, 35], // 00010100x
  31031. [8, 36], [8, 36], // 00010101x
  31032. [8, 37], [8, 37], // 00010110x
  31033. [8, 38], [8, 38], // 00010111x
  31034. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  31035. [8, 31], [8, 31], // 00011010x
  31036. [8, 32], [8, 32], // 00011011x
  31037. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  31038. [6, 1], [6, 1], [6, 1], [6, 1],
  31039. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  31040. [6, 12], [6, 12], [6, 12], [6, 12],
  31041. [8, 53], [8, 53], // 00100100x
  31042. [8, 54], [8, 54], // 00100101x
  31043. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  31044. [8, 39], [8, 39], // 00101000x
  31045. [8, 40], [8, 40], // 00101001x
  31046. [8, 41], [8, 41], // 00101010x
  31047. [8, 42], [8, 42], // 00101011x
  31048. [8, 43], [8, 43], // 00101100x
  31049. [8, 44], [8, 44], // 00101101x
  31050. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  31051. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  31052. [8, 61], [8, 61], // 00110010x
  31053. [8, 62], [8, 62], // 00110011x
  31054. [8, 63], [8, 63], // 00110100x
  31055. [8, 0], [8, 0], // 00110101x
  31056. [8, 320], [8, 320], // 00110110x
  31057. [8, 384], [8, 384], // 00110111x
  31058. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  31059. [5, 10], [5, 10], [5, 10], [5, 10],
  31060. [5, 10], [5, 10], [5, 10], [5, 10],
  31061. [5, 10], [5, 10], [5, 10], [5, 10],
  31062. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  31063. [5, 11], [5, 11], [5, 11], [5, 11],
  31064. [5, 11], [5, 11], [5, 11], [5, 11],
  31065. [5, 11], [5, 11], [5, 11], [5, 11],
  31066. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  31067. [8, 59], [8, 59], // 01001010x
  31068. [8, 60], [8, 60], // 01001011x
  31069. [9, 1472], // 010011000
  31070. [9, 1536], // 010011001
  31071. [9, 1600], // 010011010
  31072. [9, 1728], // 010011011
  31073. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  31074. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  31075. [8, 49], [8, 49], // 01010010x
  31076. [8, 50], [8, 50], // 01010011x
  31077. [8, 51], [8, 51], // 01010100x
  31078. [8, 52], [8, 52], // 01010101x
  31079. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  31080. [8, 55], [8, 55], // 01011000x
  31081. [8, 56], [8, 56], // 01011001x
  31082. [8, 57], [8, 57], // 01011010x
  31083. [8, 58], [8, 58], // 01011011x
  31084. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  31085. [6, 192], [6, 192], [6, 192], [6, 192],
  31086. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  31087. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  31088. [8, 448], [8, 448], // 01100100x
  31089. [8, 512], [8, 512], // 01100101x
  31090. [9, 704], // 011001100
  31091. [9, 768], // 011001101
  31092. [8, 640], [8, 640], // 01100111x
  31093. [8, 576], [8, 576], // 01101000x
  31094. [9, 832], // 011010010
  31095. [9, 896], // 011010011
  31096. [9, 960], // 011010100
  31097. [9, 1024], // 011010101
  31098. [9, 1088], // 011010110
  31099. [9, 1152], // 011010111
  31100. [9, 1216], // 011011000
  31101. [9, 1280], // 011011001
  31102. [9, 1344], // 011011010
  31103. [9, 1408], // 011011011
  31104. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  31105. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  31106. [4, 2], [4, 2], [4, 2], [4, 2],
  31107. [4, 2], [4, 2], [4, 2], [4, 2],
  31108. [4, 2], [4, 2], [4, 2], [4, 2],
  31109. [4, 2], [4, 2], [4, 2], [4, 2],
  31110. [4, 2], [4, 2], [4, 2], [4, 2],
  31111. [4, 2], [4, 2], [4, 2], [4, 2],
  31112. [4, 2], [4, 2], [4, 2], [4, 2],
  31113. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  31114. [4, 3], [4, 3], [4, 3], [4, 3],
  31115. [4, 3], [4, 3], [4, 3], [4, 3],
  31116. [4, 3], [4, 3], [4, 3], [4, 3],
  31117. [4, 3], [4, 3], [4, 3], [4, 3],
  31118. [4, 3], [4, 3], [4, 3], [4, 3],
  31119. [4, 3], [4, 3], [4, 3], [4, 3],
  31120. [4, 3], [4, 3], [4, 3], [4, 3],
  31121. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  31122. [5, 128], [5, 128], [5, 128], [5, 128],
  31123. [5, 128], [5, 128], [5, 128], [5, 128],
  31124. [5, 128], [5, 128], [5, 128], [5, 128],
  31125. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  31126. [5, 8], [5, 8], [5, 8], [5, 8],
  31127. [5, 8], [5, 8], [5, 8], [5, 8],
  31128. [5, 8], [5, 8], [5, 8], [5, 8],
  31129. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  31130. [5, 9], [5, 9], [5, 9], [5, 9],
  31131. [5, 9], [5, 9], [5, 9], [5, 9],
  31132. [5, 9], [5, 9], [5, 9], [5, 9],
  31133. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  31134. [6, 16], [6, 16], [6, 16], [6, 16],
  31135. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  31136. [6, 17], [6, 17], [6, 17], [6, 17],
  31137. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  31138. [4, 4], [4, 4], [4, 4], [4, 4],
  31139. [4, 4], [4, 4], [4, 4], [4, 4],
  31140. [4, 4], [4, 4], [4, 4], [4, 4],
  31141. [4, 4], [4, 4], [4, 4], [4, 4],
  31142. [4, 4], [4, 4], [4, 4], [4, 4],
  31143. [4, 4], [4, 4], [4, 4], [4, 4],
  31144. [4, 4], [4, 4], [4, 4], [4, 4],
  31145. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  31146. [4, 5], [4, 5], [4, 5], [4, 5],
  31147. [4, 5], [4, 5], [4, 5], [4, 5],
  31148. [4, 5], [4, 5], [4, 5], [4, 5],
  31149. [4, 5], [4, 5], [4, 5], [4, 5],
  31150. [4, 5], [4, 5], [4, 5], [4, 5],
  31151. [4, 5], [4, 5], [4, 5], [4, 5],
  31152. [4, 5], [4, 5], [4, 5], [4, 5],
  31153. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  31154. [6, 14], [6, 14], [6, 14], [6, 14],
  31155. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  31156. [6, 15], [6, 15], [6, 15], [6, 15],
  31157. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  31158. [5, 64], [5, 64], [5, 64], [5, 64],
  31159. [5, 64], [5, 64], [5, 64], [5, 64],
  31160. [5, 64], [5, 64], [5, 64], [5, 64],
  31161. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  31162. [4, 6], [4, 6], [4, 6], [4, 6],
  31163. [4, 6], [4, 6], [4, 6], [4, 6],
  31164. [4, 6], [4, 6], [4, 6], [4, 6],
  31165. [4, 6], [4, 6], [4, 6], [4, 6],
  31166. [4, 6], [4, 6], [4, 6], [4, 6],
  31167. [4, 6], [4, 6], [4, 6], [4, 6],
  31168. [4, 6], [4, 6], [4, 6], [4, 6],
  31169. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  31170. [4, 7], [4, 7], [4, 7], [4, 7],
  31171. [4, 7], [4, 7], [4, 7], [4, 7],
  31172. [4, 7], [4, 7], [4, 7], [4, 7],
  31173. [4, 7], [4, 7], [4, 7], [4, 7],
  31174. [4, 7], [4, 7], [4, 7], [4, 7],
  31175. [4, 7], [4, 7], [4, 7], [4, 7],
  31176. [4, 7], [4, 7], [4, 7], [4, 7]
  31177. ];
  31178. var blackTable1 = [
  31179. [-1, -1], [-1, -1], // 000000000000x
  31180. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  31181. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  31182. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  31183. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  31184. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  31185. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  31186. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  31187. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  31188. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  31189. [12, 1984], [12, 1984], // 000000010010x
  31190. [12, 2048], [12, 2048], // 000000010011x
  31191. [12, 2112], [12, 2112], // 000000010100x
  31192. [12, 2176], [12, 2176], // 000000010101x
  31193. [12, 2240], [12, 2240], // 000000010110x
  31194. [12, 2304], [12, 2304], // 000000010111x
  31195. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  31196. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  31197. [12, 2368], [12, 2368], // 000000011100x
  31198. [12, 2432], [12, 2432], // 000000011101x
  31199. [12, 2496], [12, 2496], // 000000011110x
  31200. [12, 2560], [12, 2560], // 000000011111x
  31201. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  31202. [10, 18], [10, 18], [10, 18], [10, 18],
  31203. [12, 52], [12, 52], // 000000100100x
  31204. [13, 640], // 0000001001010
  31205. [13, 704], // 0000001001011
  31206. [13, 768], // 0000001001100
  31207. [13, 832], // 0000001001101
  31208. [12, 55], [12, 55], // 000000100111x
  31209. [12, 56], [12, 56], // 000000101000x
  31210. [13, 1280], // 0000001010010
  31211. [13, 1344], // 0000001010011
  31212. [13, 1408], // 0000001010100
  31213. [13, 1472], // 0000001010101
  31214. [12, 59], [12, 59], // 000000101011x
  31215. [12, 60], [12, 60], // 000000101100x
  31216. [13, 1536], // 0000001011010
  31217. [13, 1600], // 0000001011011
  31218. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  31219. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  31220. [13, 1664], // 0000001100100
  31221. [13, 1728], // 0000001100101
  31222. [12, 320], [12, 320], // 000000110011x
  31223. [12, 384], [12, 384], // 000000110100x
  31224. [12, 448], [12, 448], // 000000110101x
  31225. [13, 512], // 0000001101100
  31226. [13, 576], // 0000001101101
  31227. [12, 53], [12, 53], // 000000110111x
  31228. [12, 54], [12, 54], // 000000111000x
  31229. [13, 896], // 0000001110010
  31230. [13, 960], // 0000001110011
  31231. [13, 1024], // 0000001110100
  31232. [13, 1088], // 0000001110101
  31233. [13, 1152], // 0000001110110
  31234. [13, 1216], // 0000001110111
  31235. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  31236. [10, 64], [10, 64], [10, 64], [10, 64]
  31237. ];
  31238. var blackTable2 = [
  31239. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  31240. [8, 13], [8, 13], [8, 13], [8, 13],
  31241. [8, 13], [8, 13], [8, 13], [8, 13],
  31242. [8, 13], [8, 13], [8, 13], [8, 13],
  31243. [11, 23], [11, 23], // 00000101000x
  31244. [12, 50], // 000001010010
  31245. [12, 51], // 000001010011
  31246. [12, 44], // 000001010100
  31247. [12, 45], // 000001010101
  31248. [12, 46], // 000001010110
  31249. [12, 47], // 000001010111
  31250. [12, 57], // 000001011000
  31251. [12, 58], // 000001011001
  31252. [12, 61], // 000001011010
  31253. [12, 256], // 000001011011
  31254. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  31255. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  31256. [12, 48], // 000001100100
  31257. [12, 49], // 000001100101
  31258. [12, 62], // 000001100110
  31259. [12, 63], // 000001100111
  31260. [12, 30], // 000001101000
  31261. [12, 31], // 000001101001
  31262. [12, 32], // 000001101010
  31263. [12, 33], // 000001101011
  31264. [12, 40], // 000001101100
  31265. [12, 41], // 000001101101
  31266. [11, 22], [11, 22], // 00000110111x
  31267. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  31268. [8, 14], [8, 14], [8, 14], [8, 14],
  31269. [8, 14], [8, 14], [8, 14], [8, 14],
  31270. [8, 14], [8, 14], [8, 14], [8, 14],
  31271. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  31272. [7, 10], [7, 10], [7, 10], [7, 10],
  31273. [7, 10], [7, 10], [7, 10], [7, 10],
  31274. [7, 10], [7, 10], [7, 10], [7, 10],
  31275. [7, 10], [7, 10], [7, 10], [7, 10],
  31276. [7, 10], [7, 10], [7, 10], [7, 10],
  31277. [7, 10], [7, 10], [7, 10], [7, 10],
  31278. [7, 10], [7, 10], [7, 10], [7, 10],
  31279. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  31280. [7, 11], [7, 11], [7, 11], [7, 11],
  31281. [7, 11], [7, 11], [7, 11], [7, 11],
  31282. [7, 11], [7, 11], [7, 11], [7, 11],
  31283. [7, 11], [7, 11], [7, 11], [7, 11],
  31284. [7, 11], [7, 11], [7, 11], [7, 11],
  31285. [7, 11], [7, 11], [7, 11], [7, 11],
  31286. [7, 11], [7, 11], [7, 11], [7, 11],
  31287. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  31288. [9, 15], [9, 15], [9, 15], [9, 15],
  31289. [12, 128], // 000011001000
  31290. [12, 192], // 000011001001
  31291. [12, 26], // 000011001010
  31292. [12, 27], // 000011001011
  31293. [12, 28], // 000011001100
  31294. [12, 29], // 000011001101
  31295. [11, 19], [11, 19], // 00001100111x
  31296. [11, 20], [11, 20], // 00001101000x
  31297. [12, 34], // 000011010010
  31298. [12, 35], // 000011010011
  31299. [12, 36], // 000011010100
  31300. [12, 37], // 000011010101
  31301. [12, 38], // 000011010110
  31302. [12, 39], // 000011010111
  31303. [11, 21], [11, 21], // 00001101100x
  31304. [12, 42], // 000011011010
  31305. [12, 43], // 000011011011
  31306. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  31307. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  31308. [7, 12], [7, 12], [7, 12], [7, 12],
  31309. [7, 12], [7, 12], [7, 12], [7, 12],
  31310. [7, 12], [7, 12], [7, 12], [7, 12],
  31311. [7, 12], [7, 12], [7, 12], [7, 12],
  31312. [7, 12], [7, 12], [7, 12], [7, 12],
  31313. [7, 12], [7, 12], [7, 12], [7, 12],
  31314. [7, 12], [7, 12], [7, 12], [7, 12]
  31315. ];
  31316. var blackTable3 = [
  31317. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  31318. [6, 9], // 000100
  31319. [6, 8], // 000101
  31320. [5, 7], [5, 7], // 00011x
  31321. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  31322. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  31323. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  31324. [3, 1], [3, 1], [3, 1], [3, 1],
  31325. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  31326. [3, 4], [3, 4], [3, 4], [3, 4],
  31327. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  31328. [2, 3], [2, 3], [2, 3], [2, 3],
  31329. [2, 3], [2, 3], [2, 3], [2, 3],
  31330. [2, 3], [2, 3], [2, 3], [2, 3],
  31331. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  31332. [2, 2], [2, 2], [2, 2], [2, 2],
  31333. [2, 2], [2, 2], [2, 2], [2, 2],
  31334. [2, 2], [2, 2], [2, 2], [2, 2]
  31335. ];
  31336. function CCITTFaxStream(str, maybeLength, params) {
  31337. this.str = str;
  31338. this.dict = str.dict;
  31339. params = params || Dict.empty;
  31340. this.encoding = params.get('K') || 0;
  31341. this.eoline = params.get('EndOfLine') || false;
  31342. this.byteAlign = params.get('EncodedByteAlign') || false;
  31343. this.columns = params.get('Columns') || 1728;
  31344. this.rows = params.get('Rows') || 0;
  31345. var eoblock = params.get('EndOfBlock');
  31346. if (eoblock === null || eoblock === undefined) {
  31347. eoblock = true;
  31348. }
  31349. this.eoblock = eoblock;
  31350. this.black = params.get('BlackIs1') || false;
  31351. this.codingLine = new Uint32Array(this.columns + 1);
  31352. this.refLine = new Uint32Array(this.columns + 2);
  31353. this.codingLine[0] = this.columns;
  31354. this.codingPos = 0;
  31355. this.row = 0;
  31356. this.nextLine2D = this.encoding < 0;
  31357. this.inputBits = 0;
  31358. this.inputBuf = 0;
  31359. this.outputBits = 0;
  31360. var code1;
  31361. while ((code1 = this.lookBits(12)) === 0) {
  31362. this.eatBits(1);
  31363. }
  31364. if (code1 === 1) {
  31365. this.eatBits(12);
  31366. }
  31367. if (this.encoding > 0) {
  31368. this.nextLine2D = !this.lookBits(1);
  31369. this.eatBits(1);
  31370. }
  31371. DecodeStream.call(this, maybeLength);
  31372. }
  31373. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  31374. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  31375. while (!this.eof) {
  31376. var c = this.lookChar();
  31377. this.ensureBuffer(this.bufferLength + 1);
  31378. this.buffer[this.bufferLength++] = c;
  31379. }
  31380. };
  31381. CCITTFaxStream.prototype.addPixels =
  31382. function ccittFaxStreamAddPixels(a1, blackPixels) {
  31383. var codingLine = this.codingLine;
  31384. var codingPos = this.codingPos;
  31385. if (a1 > codingLine[codingPos]) {
  31386. if (a1 > this.columns) {
  31387. info('row is wrong length');
  31388. this.err = true;
  31389. a1 = this.columns;
  31390. }
  31391. if ((codingPos & 1) ^ blackPixels) {
  31392. ++codingPos;
  31393. }
  31394. codingLine[codingPos] = a1;
  31395. }
  31396. this.codingPos = codingPos;
  31397. };
  31398. CCITTFaxStream.prototype.addPixelsNeg =
  31399. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  31400. var codingLine = this.codingLine;
  31401. var codingPos = this.codingPos;
  31402. if (a1 > codingLine[codingPos]) {
  31403. if (a1 > this.columns) {
  31404. info('row is wrong length');
  31405. this.err = true;
  31406. a1 = this.columns;
  31407. }
  31408. if ((codingPos & 1) ^ blackPixels) {
  31409. ++codingPos;
  31410. }
  31411. codingLine[codingPos] = a1;
  31412. } else if (a1 < codingLine[codingPos]) {
  31413. if (a1 < 0) {
  31414. info('invalid code');
  31415. this.err = true;
  31416. a1 = 0;
  31417. }
  31418. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  31419. --codingPos;
  31420. }
  31421. codingLine[codingPos] = a1;
  31422. }
  31423. this.codingPos = codingPos;
  31424. };
  31425. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  31426. var refLine = this.refLine;
  31427. var codingLine = this.codingLine;
  31428. var columns = this.columns;
  31429. var refPos, blackPixels, bits, i;
  31430. if (this.outputBits === 0) {
  31431. if (this.eof) {
  31432. return null;
  31433. }
  31434. this.err = false;
  31435. var code1, code2, code3;
  31436. if (this.nextLine2D) {
  31437. for (i = 0; codingLine[i] < columns; ++i) {
  31438. refLine[i] = codingLine[i];
  31439. }
  31440. refLine[i++] = columns;
  31441. refLine[i] = columns;
  31442. codingLine[0] = 0;
  31443. this.codingPos = 0;
  31444. refPos = 0;
  31445. blackPixels = 0;
  31446. while (codingLine[this.codingPos] < columns) {
  31447. code1 = this.getTwoDimCode();
  31448. switch (code1) {
  31449. case twoDimPass:
  31450. this.addPixels(refLine[refPos + 1], blackPixels);
  31451. if (refLine[refPos + 1] < columns) {
  31452. refPos += 2;
  31453. }
  31454. break;
  31455. case twoDimHoriz:
  31456. code1 = code2 = 0;
  31457. if (blackPixels) {
  31458. do {
  31459. code1 += (code3 = this.getBlackCode());
  31460. } while (code3 >= 64);
  31461. do {
  31462. code2 += (code3 = this.getWhiteCode());
  31463. } while (code3 >= 64);
  31464. } else {
  31465. do {
  31466. code1 += (code3 = this.getWhiteCode());
  31467. } while (code3 >= 64);
  31468. do {
  31469. code2 += (code3 = this.getBlackCode());
  31470. } while (code3 >= 64);
  31471. }
  31472. this.addPixels(codingLine[this.codingPos] +
  31473. code1, blackPixels);
  31474. if (codingLine[this.codingPos] < columns) {
  31475. this.addPixels(codingLine[this.codingPos] + code2,
  31476. blackPixels ^ 1);
  31477. }
  31478. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31479. refLine[refPos] < columns) {
  31480. refPos += 2;
  31481. }
  31482. break;
  31483. case twoDimVertR3:
  31484. this.addPixels(refLine[refPos] + 3, blackPixels);
  31485. blackPixels ^= 1;
  31486. if (codingLine[this.codingPos] < columns) {
  31487. ++refPos;
  31488. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31489. refLine[refPos] < columns) {
  31490. refPos += 2;
  31491. }
  31492. }
  31493. break;
  31494. case twoDimVertR2:
  31495. this.addPixels(refLine[refPos] + 2, blackPixels);
  31496. blackPixels ^= 1;
  31497. if (codingLine[this.codingPos] < columns) {
  31498. ++refPos;
  31499. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31500. refLine[refPos] < columns) {
  31501. refPos += 2;
  31502. }
  31503. }
  31504. break;
  31505. case twoDimVertR1:
  31506. this.addPixels(refLine[refPos] + 1, blackPixels);
  31507. blackPixels ^= 1;
  31508. if (codingLine[this.codingPos] < columns) {
  31509. ++refPos;
  31510. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31511. refLine[refPos] < columns) {
  31512. refPos += 2;
  31513. }
  31514. }
  31515. break;
  31516. case twoDimVert0:
  31517. this.addPixels(refLine[refPos], blackPixels);
  31518. blackPixels ^= 1;
  31519. if (codingLine[this.codingPos] < columns) {
  31520. ++refPos;
  31521. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31522. refLine[refPos] < columns) {
  31523. refPos += 2;
  31524. }
  31525. }
  31526. break;
  31527. case twoDimVertL3:
  31528. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  31529. blackPixels ^= 1;
  31530. if (codingLine[this.codingPos] < columns) {
  31531. if (refPos > 0) {
  31532. --refPos;
  31533. } else {
  31534. ++refPos;
  31535. }
  31536. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31537. refLine[refPos] < columns) {
  31538. refPos += 2;
  31539. }
  31540. }
  31541. break;
  31542. case twoDimVertL2:
  31543. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  31544. blackPixels ^= 1;
  31545. if (codingLine[this.codingPos] < columns) {
  31546. if (refPos > 0) {
  31547. --refPos;
  31548. } else {
  31549. ++refPos;
  31550. }
  31551. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31552. refLine[refPos] < columns) {
  31553. refPos += 2;
  31554. }
  31555. }
  31556. break;
  31557. case twoDimVertL1:
  31558. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  31559. blackPixels ^= 1;
  31560. if (codingLine[this.codingPos] < columns) {
  31561. if (refPos > 0) {
  31562. --refPos;
  31563. } else {
  31564. ++refPos;
  31565. }
  31566. while (refLine[refPos] <= codingLine[this.codingPos] &&
  31567. refLine[refPos] < columns) {
  31568. refPos += 2;
  31569. }
  31570. }
  31571. break;
  31572. case EOF:
  31573. this.addPixels(columns, 0);
  31574. this.eof = true;
  31575. break;
  31576. default:
  31577. info('bad 2d code');
  31578. this.addPixels(columns, 0);
  31579. this.err = true;
  31580. }
  31581. }
  31582. } else {
  31583. codingLine[0] = 0;
  31584. this.codingPos = 0;
  31585. blackPixels = 0;
  31586. while (codingLine[this.codingPos] < columns) {
  31587. code1 = 0;
  31588. if (blackPixels) {
  31589. do {
  31590. code1 += (code3 = this.getBlackCode());
  31591. } while (code3 >= 64);
  31592. } else {
  31593. do {
  31594. code1 += (code3 = this.getWhiteCode());
  31595. } while (code3 >= 64);
  31596. }
  31597. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  31598. blackPixels ^= 1;
  31599. }
  31600. }
  31601. var gotEOL = false;
  31602. if (this.byteAlign) {
  31603. this.inputBits &= ~7;
  31604. }
  31605. if (!this.eoblock && this.row === this.rows - 1) {
  31606. this.eof = true;
  31607. } else {
  31608. code1 = this.lookBits(12);
  31609. if (this.eoline) {
  31610. while (code1 !== EOF && code1 !== 1) {
  31611. this.eatBits(1);
  31612. code1 = this.lookBits(12);
  31613. }
  31614. } else {
  31615. while (code1 === 0) {
  31616. this.eatBits(1);
  31617. code1 = this.lookBits(12);
  31618. }
  31619. }
  31620. if (code1 === 1) {
  31621. this.eatBits(12);
  31622. gotEOL = true;
  31623. } else if (code1 === EOF) {
  31624. this.eof = true;
  31625. }
  31626. }
  31627. if (!this.eof && this.encoding > 0) {
  31628. this.nextLine2D = !this.lookBits(1);
  31629. this.eatBits(1);
  31630. }
  31631. if (this.eoblock && gotEOL && this.byteAlign) {
  31632. code1 = this.lookBits(12);
  31633. if (code1 === 1) {
  31634. this.eatBits(12);
  31635. if (this.encoding > 0) {
  31636. this.lookBits(1);
  31637. this.eatBits(1);
  31638. }
  31639. if (this.encoding >= 0) {
  31640. for (i = 0; i < 4; ++i) {
  31641. code1 = this.lookBits(12);
  31642. if (code1 !== 1) {
  31643. info('bad rtc code: ' + code1);
  31644. }
  31645. this.eatBits(12);
  31646. if (this.encoding > 0) {
  31647. this.lookBits(1);
  31648. this.eatBits(1);
  31649. }
  31650. }
  31651. }
  31652. this.eof = true;
  31653. }
  31654. } else if (this.err && this.eoline) {
  31655. while (true) {
  31656. code1 = this.lookBits(13);
  31657. if (code1 === EOF) {
  31658. this.eof = true;
  31659. return null;
  31660. }
  31661. if ((code1 >> 1) === 1) {
  31662. break;
  31663. }
  31664. this.eatBits(1);
  31665. }
  31666. this.eatBits(12);
  31667. if (this.encoding > 0) {
  31668. this.eatBits(1);
  31669. this.nextLine2D = !(code1 & 1);
  31670. }
  31671. }
  31672. if (codingLine[0] > 0) {
  31673. this.outputBits = codingLine[this.codingPos = 0];
  31674. } else {
  31675. this.outputBits = codingLine[this.codingPos = 1];
  31676. }
  31677. this.row++;
  31678. }
  31679. var c;
  31680. if (this.outputBits >= 8) {
  31681. c = (this.codingPos & 1) ? 0 : 0xFF;
  31682. this.outputBits -= 8;
  31683. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  31684. this.codingPos++;
  31685. this.outputBits = (codingLine[this.codingPos] -
  31686. codingLine[this.codingPos - 1]);
  31687. }
  31688. } else {
  31689. bits = 8;
  31690. c = 0;
  31691. do {
  31692. if (this.outputBits > bits) {
  31693. c <<= bits;
  31694. if (!(this.codingPos & 1)) {
  31695. c |= 0xFF >> (8 - bits);
  31696. }
  31697. this.outputBits -= bits;
  31698. bits = 0;
  31699. } else {
  31700. c <<= this.outputBits;
  31701. if (!(this.codingPos & 1)) {
  31702. c |= 0xFF >> (8 - this.outputBits);
  31703. }
  31704. bits -= this.outputBits;
  31705. this.outputBits = 0;
  31706. if (codingLine[this.codingPos] < columns) {
  31707. this.codingPos++;
  31708. this.outputBits = (codingLine[this.codingPos] -
  31709. codingLine[this.codingPos - 1]);
  31710. } else if (bits > 0) {
  31711. c <<= bits;
  31712. bits = 0;
  31713. }
  31714. }
  31715. } while (bits);
  31716. }
  31717. if (this.black) {
  31718. c ^= 0xFF;
  31719. }
  31720. return c;
  31721. };
  31722. // This functions returns the code found from the table.
  31723. // The start and end parameters set the boundaries for searching the table.
  31724. // The limit parameter is optional. Function returns an array with three
  31725. // values. The first array element indicates whether a valid code is being
  31726. // returned. The second array element is the actual code. The third array
  31727. // element indicates whether EOF was reached.
  31728. CCITTFaxStream.prototype.findTableCode =
  31729. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  31730. var limitValue = limit || 0;
  31731. for (var i = start; i <= end; ++i) {
  31732. var code = this.lookBits(i);
  31733. if (code === EOF) {
  31734. return [true, 1, false];
  31735. }
  31736. if (i < end) {
  31737. code <<= end - i;
  31738. }
  31739. if (!limitValue || code >= limitValue) {
  31740. var p = table[code - limitValue];
  31741. if (p[0] === i) {
  31742. this.eatBits(i);
  31743. return [true, p[1], true];
  31744. }
  31745. }
  31746. }
  31747. return [false, 0, false];
  31748. };
  31749. CCITTFaxStream.prototype.getTwoDimCode =
  31750. function ccittFaxStreamGetTwoDimCode() {
  31751. var code = 0;
  31752. var p;
  31753. if (this.eoblock) {
  31754. code = this.lookBits(7);
  31755. p = twoDimTable[code];
  31756. if (p && p[0] > 0) {
  31757. this.eatBits(p[0]);
  31758. return p[1];
  31759. }
  31760. } else {
  31761. var result = this.findTableCode(1, 7, twoDimTable);
  31762. if (result[0] && result[2]) {
  31763. return result[1];
  31764. }
  31765. }
  31766. info('Bad two dim code');
  31767. return EOF;
  31768. };
  31769. CCITTFaxStream.prototype.getWhiteCode =
  31770. function ccittFaxStreamGetWhiteCode() {
  31771. var code = 0;
  31772. var p;
  31773. if (this.eoblock) {
  31774. code = this.lookBits(12);
  31775. if (code === EOF) {
  31776. return 1;
  31777. }
  31778. if ((code >> 5) === 0) {
  31779. p = whiteTable1[code];
  31780. } else {
  31781. p = whiteTable2[code >> 3];
  31782. }
  31783. if (p[0] > 0) {
  31784. this.eatBits(p[0]);
  31785. return p[1];
  31786. }
  31787. } else {
  31788. var result = this.findTableCode(1, 9, whiteTable2);
  31789. if (result[0]) {
  31790. return result[1];
  31791. }
  31792. result = this.findTableCode(11, 12, whiteTable1);
  31793. if (result[0]) {
  31794. return result[1];
  31795. }
  31796. }
  31797. info('bad white code');
  31798. this.eatBits(1);
  31799. return 1;
  31800. };
  31801. CCITTFaxStream.prototype.getBlackCode =
  31802. function ccittFaxStreamGetBlackCode() {
  31803. var code, p;
  31804. if (this.eoblock) {
  31805. code = this.lookBits(13);
  31806. if (code === EOF) {
  31807. return 1;
  31808. }
  31809. if ((code >> 7) === 0) {
  31810. p = blackTable1[code];
  31811. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  31812. p = blackTable2[(code >> 1) - 64];
  31813. } else {
  31814. p = blackTable3[code >> 7];
  31815. }
  31816. if (p[0] > 0) {
  31817. this.eatBits(p[0]);
  31818. return p[1];
  31819. }
  31820. } else {
  31821. var result = this.findTableCode(2, 6, blackTable3);
  31822. if (result[0]) {
  31823. return result[1];
  31824. }
  31825. result = this.findTableCode(7, 12, blackTable2, 64);
  31826. if (result[0]) {
  31827. return result[1];
  31828. }
  31829. result = this.findTableCode(10, 13, blackTable1);
  31830. if (result[0]) {
  31831. return result[1];
  31832. }
  31833. }
  31834. info('bad black code');
  31835. this.eatBits(1);
  31836. return 1;
  31837. };
  31838. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  31839. var c;
  31840. while (this.inputBits < n) {
  31841. if ((c = this.str.getByte()) === -1) {
  31842. if (this.inputBits === 0) {
  31843. return EOF;
  31844. }
  31845. return ((this.inputBuf << (n - this.inputBits)) &
  31846. (0xFFFF >> (16 - n)));
  31847. }
  31848. this.inputBuf = (this.inputBuf << 8) + c;
  31849. this.inputBits += 8;
  31850. }
  31851. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  31852. };
  31853. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  31854. if ((this.inputBits -= n) < 0) {
  31855. this.inputBits = 0;
  31856. }
  31857. };
  31858. return CCITTFaxStream;
  31859. })();
  31860. var LZWStream = (function LZWStreamClosure() {
  31861. function LZWStream(str, maybeLength, earlyChange) {
  31862. this.str = str;
  31863. this.dict = str.dict;
  31864. this.cachedData = 0;
  31865. this.bitsCached = 0;
  31866. var maxLzwDictionarySize = 4096;
  31867. var lzwState = {
  31868. earlyChange: earlyChange,
  31869. codeLength: 9,
  31870. nextCode: 258,
  31871. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  31872. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  31873. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  31874. currentSequence: new Uint8Array(maxLzwDictionarySize),
  31875. currentSequenceLength: 0
  31876. };
  31877. for (var i = 0; i < 256; ++i) {
  31878. lzwState.dictionaryValues[i] = i;
  31879. lzwState.dictionaryLengths[i] = 1;
  31880. }
  31881. this.lzwState = lzwState;
  31882. DecodeStream.call(this, maybeLength);
  31883. }
  31884. LZWStream.prototype = Object.create(DecodeStream.prototype);
  31885. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  31886. var bitsCached = this.bitsCached;
  31887. var cachedData = this.cachedData;
  31888. while (bitsCached < n) {
  31889. var c = this.str.getByte();
  31890. if (c === -1) {
  31891. this.eof = true;
  31892. return null;
  31893. }
  31894. cachedData = (cachedData << 8) | c;
  31895. bitsCached += 8;
  31896. }
  31897. this.bitsCached = (bitsCached -= n);
  31898. this.cachedData = cachedData;
  31899. this.lastCode = null;
  31900. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  31901. };
  31902. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  31903. var blockSize = 512;
  31904. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  31905. var i, j, q;
  31906. var lzwState = this.lzwState;
  31907. if (!lzwState) {
  31908. return; // eof was found
  31909. }
  31910. var earlyChange = lzwState.earlyChange;
  31911. var nextCode = lzwState.nextCode;
  31912. var dictionaryValues = lzwState.dictionaryValues;
  31913. var dictionaryLengths = lzwState.dictionaryLengths;
  31914. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  31915. var codeLength = lzwState.codeLength;
  31916. var prevCode = lzwState.prevCode;
  31917. var currentSequence = lzwState.currentSequence;
  31918. var currentSequenceLength = lzwState.currentSequenceLength;
  31919. var decodedLength = 0;
  31920. var currentBufferLength = this.bufferLength;
  31921. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31922. for (i = 0; i < blockSize; i++) {
  31923. var code = this.readBits(codeLength);
  31924. var hasPrev = currentSequenceLength > 0;
  31925. if (code < 256) {
  31926. currentSequence[0] = code;
  31927. currentSequenceLength = 1;
  31928. } else if (code >= 258) {
  31929. if (code < nextCode) {
  31930. currentSequenceLength = dictionaryLengths[code];
  31931. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  31932. currentSequence[j] = dictionaryValues[q];
  31933. q = dictionaryPrevCodes[q];
  31934. }
  31935. } else {
  31936. currentSequence[currentSequenceLength++] = currentSequence[0];
  31937. }
  31938. } else if (code === 256) {
  31939. codeLength = 9;
  31940. nextCode = 258;
  31941. currentSequenceLength = 0;
  31942. continue;
  31943. } else {
  31944. this.eof = true;
  31945. delete this.lzwState;
  31946. break;
  31947. }
  31948. if (hasPrev) {
  31949. dictionaryPrevCodes[nextCode] = prevCode;
  31950. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  31951. dictionaryValues[nextCode] = currentSequence[0];
  31952. nextCode++;
  31953. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  31954. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  31955. 0.6931471805599453 + 1, 12) | 0;
  31956. }
  31957. prevCode = code;
  31958. decodedLength += currentSequenceLength;
  31959. if (estimatedDecodedSize < decodedLength) {
  31960. do {
  31961. estimatedDecodedSize += decodedSizeDelta;
  31962. } while (estimatedDecodedSize < decodedLength);
  31963. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  31964. }
  31965. for (j = 0; j < currentSequenceLength; j++) {
  31966. buffer[currentBufferLength++] = currentSequence[j];
  31967. }
  31968. }
  31969. lzwState.nextCode = nextCode;
  31970. lzwState.codeLength = codeLength;
  31971. lzwState.prevCode = prevCode;
  31972. lzwState.currentSequenceLength = currentSequenceLength;
  31973. this.bufferLength = currentBufferLength;
  31974. };
  31975. return LZWStream;
  31976. })();
  31977. var NullStream = (function NullStreamClosure() {
  31978. function NullStream() {
  31979. Stream.call(this, new Uint8Array(0));
  31980. }
  31981. NullStream.prototype = Stream.prototype;
  31982. return NullStream;
  31983. })();
  31984. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  31985. setup: function wphSetup(handler) {
  31986. var pdfManager;
  31987. function loadDocument(recoveryMode) {
  31988. var loadDocumentCapability = createPromiseCapability();
  31989. var parseSuccess = function parseSuccess() {
  31990. var numPagesPromise = pdfManager.ensureDoc('numPages');
  31991. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  31992. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  31993. Promise.all([numPagesPromise, fingerprintPromise,
  31994. encryptedPromise]).then(function onDocReady(results) {
  31995. var doc = {
  31996. numPages: results[0],
  31997. fingerprint: results[1],
  31998. encrypted: !!results[2],
  31999. };
  32000. loadDocumentCapability.resolve(doc);
  32001. },
  32002. parseFailure);
  32003. };
  32004. var parseFailure = function parseFailure(e) {
  32005. loadDocumentCapability.reject(e);
  32006. };
  32007. pdfManager.ensureDoc('checkHeader', []).then(function() {
  32008. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  32009. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  32010. parseSuccess, parseFailure);
  32011. }, parseFailure);
  32012. }, parseFailure);
  32013. return loadDocumentCapability.promise;
  32014. }
  32015. function getPdfManager(data) {
  32016. var pdfManagerCapability = createPromiseCapability();
  32017. var source = data.source;
  32018. var disableRange = data.disableRange;
  32019. if (source.data) {
  32020. try {
  32021. pdfManager = new LocalPdfManager(source.data, source.password);
  32022. pdfManagerCapability.resolve();
  32023. } catch (ex) {
  32024. pdfManagerCapability.reject(ex);
  32025. }
  32026. return pdfManagerCapability.promise;
  32027. } else if (source.chunkedViewerLoading) {
  32028. try {
  32029. pdfManager = new NetworkPdfManager(source, handler);
  32030. pdfManagerCapability.resolve();
  32031. } catch (ex) {
  32032. pdfManagerCapability.reject(ex);
  32033. }
  32034. return pdfManagerCapability.promise;
  32035. }
  32036. var networkManager = new NetworkManager(source.url, {
  32037. httpHeaders: source.httpHeaders,
  32038. withCredentials: source.withCredentials
  32039. });
  32040. var cachedChunks = [];
  32041. var fullRequestXhrId = networkManager.requestFull({
  32042. onHeadersReceived: function onHeadersReceived() {
  32043. if (disableRange) {
  32044. return;
  32045. }
  32046. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  32047. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  32048. return;
  32049. }
  32050. var contentEncoding =
  32051. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  32052. if (contentEncoding !== 'identity') {
  32053. return;
  32054. }
  32055. var length = fullRequestXhr.getResponseHeader('Content-Length');
  32056. length = parseInt(length, 10);
  32057. if (!isInt(length)) {
  32058. return;
  32059. }
  32060. source.length = length;
  32061. if (length <= 2 * RANGE_CHUNK_SIZE) {
  32062. // The file size is smaller than the size of two chunks, so it does
  32063. // not make any sense to abort the request and retry with a range
  32064. // request.
  32065. return;
  32066. }
  32067. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  32068. // We can continue fetching when progressive loading is enabled,
  32069. // and we don't need the autoFetch feature.
  32070. source.disableAutoFetch = true;
  32071. } else {
  32072. // NOTE: by cancelling the full request, and then issuing range
  32073. // requests, there will be an issue for sites where you can only
  32074. // request the pdf once. However, if this is the case, then the
  32075. // server should not be returning that it can support range
  32076. // requests.
  32077. networkManager.abortRequest(fullRequestXhrId);
  32078. }
  32079. try {
  32080. pdfManager = new NetworkPdfManager(source, handler);
  32081. pdfManagerCapability.resolve(pdfManager);
  32082. } catch (ex) {
  32083. pdfManagerCapability.reject(ex);
  32084. }
  32085. },
  32086. onProgressiveData: source.disableStream ? null :
  32087. function onProgressiveData(chunk) {
  32088. if (!pdfManager) {
  32089. cachedChunks.push(chunk);
  32090. return;
  32091. }
  32092. pdfManager.sendProgressiveData(chunk);
  32093. },
  32094. onDone: function onDone(args) {
  32095. if (pdfManager) {
  32096. return; // already processed
  32097. }
  32098. var pdfFile;
  32099. if (args === null) {
  32100. // TODO add some streaming manager, e.g. for unknown length files.
  32101. // The data was returned in the onProgressiveData, combining...
  32102. var pdfFileLength = 0, pos = 0;
  32103. cachedChunks.forEach(function (chunk) {
  32104. pdfFileLength += chunk.byteLength;
  32105. });
  32106. if (source.length && pdfFileLength !== source.length) {
  32107. warn('reported HTTP length is different from actual');
  32108. }
  32109. var pdfFileArray = new Uint8Array(pdfFileLength);
  32110. cachedChunks.forEach(function (chunk) {
  32111. pdfFileArray.set(new Uint8Array(chunk), pos);
  32112. pos += chunk.byteLength;
  32113. });
  32114. pdfFile = pdfFileArray.buffer;
  32115. } else {
  32116. pdfFile = args.chunk;
  32117. }
  32118. // the data is array, instantiating directly from it
  32119. try {
  32120. pdfManager = new LocalPdfManager(pdfFile, source.password);
  32121. pdfManagerCapability.resolve();
  32122. } catch (ex) {
  32123. pdfManagerCapability.reject(ex);
  32124. }
  32125. },
  32126. onError: function onError(status) {
  32127. var exception;
  32128. if (status === 404) {
  32129. exception = new MissingPDFException('Missing PDF "' +
  32130. source.url + '".');
  32131. handler.send('MissingPDF', exception);
  32132. } else {
  32133. exception = new UnexpectedResponseException(
  32134. 'Unexpected server response (' + status +
  32135. ') while retrieving PDF "' + source.url + '".', status);
  32136. handler.send('UnexpectedResponse', exception);
  32137. }
  32138. },
  32139. onProgress: function onProgress(evt) {
  32140. handler.send('DocProgress', {
  32141. loaded: evt.loaded,
  32142. total: evt.lengthComputable ? evt.total : source.length
  32143. });
  32144. }
  32145. });
  32146. return pdfManagerCapability.promise;
  32147. }
  32148. handler.on('test', function wphSetupTest(data) {
  32149. // check if Uint8Array can be sent to worker
  32150. if (!(data instanceof Uint8Array)) {
  32151. handler.send('test', false);
  32152. return;
  32153. }
  32154. // making sure postMessage transfers are working
  32155. var supportTransfers = data[0] === 255;
  32156. handler.postMessageTransfers = supportTransfers;
  32157. // check if the response property is supported by xhr
  32158. var xhr = new XMLHttpRequest();
  32159. var responseExists = 'response' in xhr;
  32160. // check if the property is actually implemented
  32161. try {
  32162. var dummy = xhr.responseType;
  32163. } catch (e) {
  32164. responseExists = false;
  32165. }
  32166. if (!responseExists) {
  32167. handler.send('test', false);
  32168. return;
  32169. }
  32170. handler.send('test', {
  32171. supportTypedArray: true,
  32172. supportTransfers: supportTransfers
  32173. });
  32174. });
  32175. handler.on('GetDocRequest', function wphSetupDoc(data) {
  32176. var onSuccess = function(doc) {
  32177. handler.send('GetDoc', { pdfInfo: doc });
  32178. };
  32179. var onFailure = function(e) {
  32180. if (e instanceof PasswordException) {
  32181. if (e.code === PasswordResponses.NEED_PASSWORD) {
  32182. handler.send('NeedPassword', e);
  32183. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  32184. handler.send('IncorrectPassword', e);
  32185. }
  32186. } else if (e instanceof InvalidPDFException) {
  32187. handler.send('InvalidPDF', e);
  32188. } else if (e instanceof MissingPDFException) {
  32189. handler.send('MissingPDF', e);
  32190. } else if (e instanceof UnexpectedResponseException) {
  32191. handler.send('UnexpectedResponse', e);
  32192. } else {
  32193. handler.send('UnknownError',
  32194. new UnknownErrorException(e.message, e.toString()));
  32195. }
  32196. };
  32197. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  32198. -1 : data.maxImageSize;
  32199. PDFJS.disableFontFace = data.disableFontFace;
  32200. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  32201. PDFJS.verbosity = data.verbosity;
  32202. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  32203. null : data.cMapUrl;
  32204. PDFJS.cMapPacked = data.cMapPacked === true;
  32205. getPdfManager(data).then(function () {
  32206. handler.send('PDFManagerReady', null);
  32207. pdfManager.onLoadedStream().then(function(stream) {
  32208. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  32209. });
  32210. }).then(function pdfManagerReady() {
  32211. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  32212. // Try again with recoveryMode == true
  32213. if (!(ex instanceof XRefParseException)) {
  32214. if (ex instanceof PasswordException) {
  32215. // after password exception prepare to receive a new password
  32216. // to repeat loading
  32217. pdfManager.passwordChanged().then(pdfManagerReady);
  32218. }
  32219. onFailure(ex);
  32220. return;
  32221. }
  32222. pdfManager.requestLoadedStream();
  32223. pdfManager.onLoadedStream().then(function() {
  32224. loadDocument(true).then(onSuccess, onFailure);
  32225. });
  32226. }, onFailure);
  32227. }, onFailure);
  32228. });
  32229. handler.on('GetPage', function wphSetupGetPage(data) {
  32230. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32231. var rotatePromise = pdfManager.ensure(page, 'rotate');
  32232. var refPromise = pdfManager.ensure(page, 'ref');
  32233. var viewPromise = pdfManager.ensure(page, 'view');
  32234. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  32235. function(results) {
  32236. return {
  32237. rotate: results[0],
  32238. ref: results[1],
  32239. view: results[2]
  32240. };
  32241. });
  32242. });
  32243. });
  32244. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  32245. var ref = new Ref(data.ref.num, data.ref.gen);
  32246. var catalog = pdfManager.pdfDocument.catalog;
  32247. return catalog.getPageIndex(ref);
  32248. });
  32249. handler.on('GetDestinations',
  32250. function wphSetupGetDestinations(data) {
  32251. return pdfManager.ensureCatalog('destinations');
  32252. }
  32253. );
  32254. handler.on('GetDestination',
  32255. function wphSetupGetDestination(data) {
  32256. return pdfManager.ensureCatalog('getDestination', [ data.id ]);
  32257. }
  32258. );
  32259. handler.on('GetAttachments',
  32260. function wphSetupGetAttachments(data) {
  32261. return pdfManager.ensureCatalog('attachments');
  32262. }
  32263. );
  32264. handler.on('GetJavaScript',
  32265. function wphSetupGetJavaScript(data) {
  32266. return pdfManager.ensureCatalog('javaScript');
  32267. }
  32268. );
  32269. handler.on('GetOutline',
  32270. function wphSetupGetOutline(data) {
  32271. return pdfManager.ensureCatalog('documentOutline');
  32272. }
  32273. );
  32274. handler.on('GetMetadata',
  32275. function wphSetupGetMetadata(data) {
  32276. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  32277. pdfManager.ensureCatalog('metadata')]);
  32278. }
  32279. );
  32280. handler.on('GetData', function wphSetupGetData(data) {
  32281. pdfManager.requestLoadedStream();
  32282. return pdfManager.onLoadedStream().then(function(stream) {
  32283. return stream.bytes;
  32284. });
  32285. });
  32286. handler.on('GetStats',
  32287. function wphSetupGetStats(data) {
  32288. return pdfManager.pdfDocument.xref.stats;
  32289. }
  32290. );
  32291. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  32292. pdfManager.updatePassword(data);
  32293. });
  32294. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  32295. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32296. return pdfManager.ensure(page, 'getAnnotationsData', []);
  32297. });
  32298. });
  32299. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  32300. pdfManager.getPage(data.pageIndex).then(function(page) {
  32301. var pageNum = data.pageIndex + 1;
  32302. var start = Date.now();
  32303. // Pre compile the pdf page and fetch the fonts/images.
  32304. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  32305. info('page=' + pageNum + ' - getOperatorList: time=' +
  32306. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  32307. }, function(e) {
  32308. var minimumStackMessage =
  32309. 'worker.js: while trying to getPage() and getOperatorList()';
  32310. var wrappedException;
  32311. // Turn the error into an obj that can be serialized
  32312. if (typeof e === 'string') {
  32313. wrappedException = {
  32314. message: e,
  32315. stack: minimumStackMessage
  32316. };
  32317. } else if (typeof e === 'object') {
  32318. wrappedException = {
  32319. message: e.message || e.toString(),
  32320. stack: e.stack || minimumStackMessage
  32321. };
  32322. } else {
  32323. wrappedException = {
  32324. message: 'Unknown exception type: ' + (typeof e),
  32325. stack: minimumStackMessage
  32326. };
  32327. }
  32328. handler.send('PageError', {
  32329. pageNum: pageNum,
  32330. error: wrappedException,
  32331. intent: data.intent
  32332. });
  32333. });
  32334. });
  32335. }, this);
  32336. handler.on('GetTextContent', function wphExtractText(data) {
  32337. return pdfManager.getPage(data.pageIndex).then(function(page) {
  32338. var pageNum = data.pageIndex + 1;
  32339. var start = Date.now();
  32340. return page.extractTextContent().then(function(textContent) {
  32341. info('text indexing: page=' + pageNum + ' - time=' +
  32342. (Date.now() - start) + 'ms');
  32343. return textContent;
  32344. });
  32345. });
  32346. });
  32347. handler.on('Cleanup', function wphCleanup(data) {
  32348. return pdfManager.cleanup();
  32349. });
  32350. handler.on('Terminate', function wphTerminate(data) {
  32351. pdfManager.terminate();
  32352. });
  32353. }
  32354. };
  32355. var consoleTimer = {};
  32356. var workerConsole = {
  32357. log: function log() {
  32358. var args = Array.prototype.slice.call(arguments);
  32359. globalScope.postMessage({
  32360. action: 'console_log',
  32361. data: args
  32362. });
  32363. },
  32364. error: function error() {
  32365. var args = Array.prototype.slice.call(arguments);
  32366. globalScope.postMessage({
  32367. action: 'console_error',
  32368. data: args
  32369. });
  32370. throw 'pdf.js execution error';
  32371. },
  32372. time: function time(name) {
  32373. consoleTimer[name] = Date.now();
  32374. },
  32375. timeEnd: function timeEnd(name) {
  32376. var time = consoleTimer[name];
  32377. if (!time) {
  32378. error('Unknown timer name ' + name);
  32379. }
  32380. this.log('Timer:', name, Date.now() - time);
  32381. }
  32382. };
  32383. // Worker thread?
  32384. if (typeof window === 'undefined') {
  32385. if (!('console' in globalScope)) {
  32386. globalScope.console = workerConsole;
  32387. }
  32388. // Listen for unsupported features so we can pass them on to the main thread.
  32389. PDFJS.UnsupportedManager.listen(function (msg) {
  32390. globalScope.postMessage({
  32391. action: '_unsupported_feature',
  32392. data: msg
  32393. });
  32394. });
  32395. var handler = new MessageHandler('worker_processor', this);
  32396. WorkerMessageHandler.setup(handler);
  32397. }
  32398. /* This class implements the QM Coder decoding as defined in
  32399. * JPEG 2000 Part I Final Committee Draft Version 1.0
  32400. * Annex C.3 Arithmetic decoding procedure
  32401. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  32402. *
  32403. * The arithmetic decoder is used in conjunction with context models to decode
  32404. * JPEG2000 and JBIG2 streams.
  32405. */
  32406. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  32407. // Table C-2
  32408. var QeTable = [
  32409. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  32410. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  32411. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  32412. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  32413. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  32414. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  32415. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  32416. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  32417. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  32418. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  32419. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  32420. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  32421. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  32422. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  32423. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  32424. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  32425. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  32426. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  32427. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  32428. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  32429. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  32430. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  32431. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  32432. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  32433. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  32434. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  32435. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  32436. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  32437. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  32438. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  32439. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  32440. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  32441. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  32442. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  32443. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  32444. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  32445. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  32446. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  32447. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  32448. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  32449. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  32450. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  32451. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  32452. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  32453. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  32454. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  32455. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  32456. ];
  32457. // C.3.5 Initialisation of the decoder (INITDEC)
  32458. function ArithmeticDecoder(data, start, end) {
  32459. this.data = data;
  32460. this.bp = start;
  32461. this.dataEnd = end;
  32462. this.chigh = data[start];
  32463. this.clow = 0;
  32464. this.byteIn();
  32465. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  32466. this.clow = (this.clow << 7) & 0xFFFF;
  32467. this.ct -= 7;
  32468. this.a = 0x8000;
  32469. }
  32470. ArithmeticDecoder.prototype = {
  32471. // C.3.4 Compressed data input (BYTEIN)
  32472. byteIn: function ArithmeticDecoder_byteIn() {
  32473. var data = this.data;
  32474. var bp = this.bp;
  32475. if (data[bp] === 0xFF) {
  32476. var b1 = data[bp + 1];
  32477. if (b1 > 0x8F) {
  32478. this.clow += 0xFF00;
  32479. this.ct = 8;
  32480. } else {
  32481. bp++;
  32482. this.clow += (data[bp] << 9);
  32483. this.ct = 7;
  32484. this.bp = bp;
  32485. }
  32486. } else {
  32487. bp++;
  32488. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  32489. this.ct = 8;
  32490. this.bp = bp;
  32491. }
  32492. if (this.clow > 0xFFFF) {
  32493. this.chigh += (this.clow >> 16);
  32494. this.clow &= 0xFFFF;
  32495. }
  32496. },
  32497. // C.3.2 Decoding a decision (DECODE)
  32498. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  32499. // contexts are packed into 1 byte:
  32500. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  32501. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  32502. var qeTableIcx = QeTable[cx_index];
  32503. var qeIcx = qeTableIcx.qe;
  32504. var d;
  32505. var a = this.a - qeIcx;
  32506. if (this.chigh < qeIcx) {
  32507. // exchangeLps
  32508. if (a < qeIcx) {
  32509. a = qeIcx;
  32510. d = cx_mps;
  32511. cx_index = qeTableIcx.nmps;
  32512. } else {
  32513. a = qeIcx;
  32514. d = 1 ^ cx_mps;
  32515. if (qeTableIcx.switchFlag === 1) {
  32516. cx_mps = d;
  32517. }
  32518. cx_index = qeTableIcx.nlps;
  32519. }
  32520. } else {
  32521. this.chigh -= qeIcx;
  32522. if ((a & 0x8000) !== 0) {
  32523. this.a = a;
  32524. return cx_mps;
  32525. }
  32526. // exchangeMps
  32527. if (a < qeIcx) {
  32528. d = 1 ^ cx_mps;
  32529. if (qeTableIcx.switchFlag === 1) {
  32530. cx_mps = d;
  32531. }
  32532. cx_index = qeTableIcx.nlps;
  32533. } else {
  32534. d = cx_mps;
  32535. cx_index = qeTableIcx.nmps;
  32536. }
  32537. }
  32538. // C.3.3 renormD;
  32539. do {
  32540. if (this.ct === 0) {
  32541. this.byteIn();
  32542. }
  32543. a <<= 1;
  32544. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  32545. this.clow = (this.clow << 1) & 0xFFFF;
  32546. this.ct--;
  32547. } while ((a & 0x8000) === 0);
  32548. this.a = a;
  32549. contexts[pos] = cx_index << 1 | cx_mps;
  32550. return d;
  32551. }
  32552. };
  32553. return ArithmeticDecoder;
  32554. })();
  32555. var JpegImage = (function jpegImage() {
  32556. var dctZigZag = new Uint8Array([
  32557. 0,
  32558. 1, 8,
  32559. 16, 9, 2,
  32560. 3, 10, 17, 24,
  32561. 32, 25, 18, 11, 4,
  32562. 5, 12, 19, 26, 33, 40,
  32563. 48, 41, 34, 27, 20, 13, 6,
  32564. 7, 14, 21, 28, 35, 42, 49, 56,
  32565. 57, 50, 43, 36, 29, 22, 15,
  32566. 23, 30, 37, 44, 51, 58,
  32567. 59, 52, 45, 38, 31,
  32568. 39, 46, 53, 60,
  32569. 61, 54, 47,
  32570. 55, 62,
  32571. 63
  32572. ]);
  32573. var dctCos1 = 4017; // cos(pi/16)
  32574. var dctSin1 = 799; // sin(pi/16)
  32575. var dctCos3 = 3406; // cos(3*pi/16)
  32576. var dctSin3 = 2276; // sin(3*pi/16)
  32577. var dctCos6 = 1567; // cos(6*pi/16)
  32578. var dctSin6 = 3784; // sin(6*pi/16)
  32579. var dctSqrt2 = 5793; // sqrt(2)
  32580. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  32581. function constructor() {
  32582. }
  32583. function buildHuffmanTable(codeLengths, values) {
  32584. var k = 0, code = [], i, j, length = 16;
  32585. while (length > 0 && !codeLengths[length - 1]) {
  32586. length--;
  32587. }
  32588. code.push({children: [], index: 0});
  32589. var p = code[0], q;
  32590. for (i = 0; i < length; i++) {
  32591. for (j = 0; j < codeLengths[i]; j++) {
  32592. p = code.pop();
  32593. p.children[p.index] = values[k];
  32594. while (p.index > 0) {
  32595. p = code.pop();
  32596. }
  32597. p.index++;
  32598. code.push(p);
  32599. while (code.length <= i) {
  32600. code.push(q = {children: [], index: 0});
  32601. p.children[p.index] = q.children;
  32602. p = q;
  32603. }
  32604. k++;
  32605. }
  32606. if (i + 1 < length) {
  32607. // p here points to last code
  32608. code.push(q = {children: [], index: 0});
  32609. p.children[p.index] = q.children;
  32610. p = q;
  32611. }
  32612. }
  32613. return code[0].children;
  32614. }
  32615. function getBlockBufferOffset(component, row, col) {
  32616. return 64 * ((component.blocksPerLine + 1) * row + col);
  32617. }
  32618. function decodeScan(data, offset, frame, components, resetInterval,
  32619. spectralStart, spectralEnd, successivePrev, successive) {
  32620. var precision = frame.precision;
  32621. var samplesPerLine = frame.samplesPerLine;
  32622. var scanLines = frame.scanLines;
  32623. var mcusPerLine = frame.mcusPerLine;
  32624. var progressive = frame.progressive;
  32625. var maxH = frame.maxH, maxV = frame.maxV;
  32626. var startOffset = offset, bitsData = 0, bitsCount = 0;
  32627. function readBit() {
  32628. if (bitsCount > 0) {
  32629. bitsCount--;
  32630. return (bitsData >> bitsCount) & 1;
  32631. }
  32632. bitsData = data[offset++];
  32633. if (bitsData === 0xFF) {
  32634. var nextByte = data[offset++];
  32635. if (nextByte) {
  32636. throw 'unexpected marker: ' +
  32637. ((bitsData << 8) | nextByte).toString(16);
  32638. }
  32639. // unstuff 0
  32640. }
  32641. bitsCount = 7;
  32642. return bitsData >>> 7;
  32643. }
  32644. function decodeHuffman(tree) {
  32645. var node = tree;
  32646. while (true) {
  32647. node = node[readBit()];
  32648. if (typeof node === 'number') {
  32649. return node;
  32650. }
  32651. if (typeof node !== 'object') {
  32652. throw 'invalid huffman sequence';
  32653. }
  32654. }
  32655. }
  32656. function receive(length) {
  32657. var n = 0;
  32658. while (length > 0) {
  32659. n = (n << 1) | readBit();
  32660. length--;
  32661. }
  32662. return n;
  32663. }
  32664. function receiveAndExtend(length) {
  32665. if (length === 1) {
  32666. return readBit() === 1 ? 1 : -1;
  32667. }
  32668. var n = receive(length);
  32669. if (n >= 1 << (length - 1)) {
  32670. return n;
  32671. }
  32672. return n + (-1 << length) + 1;
  32673. }
  32674. function decodeBaseline(component, offset) {
  32675. var t = decodeHuffman(component.huffmanTableDC);
  32676. var diff = t === 0 ? 0 : receiveAndExtend(t);
  32677. component.blockData[offset] = (component.pred += diff);
  32678. var k = 1;
  32679. while (k < 64) {
  32680. var rs = decodeHuffman(component.huffmanTableAC);
  32681. var s = rs & 15, r = rs >> 4;
  32682. if (s === 0) {
  32683. if (r < 15) {
  32684. break;
  32685. }
  32686. k += 16;
  32687. continue;
  32688. }
  32689. k += r;
  32690. var z = dctZigZag[k];
  32691. component.blockData[offset + z] = receiveAndExtend(s);
  32692. k++;
  32693. }
  32694. }
  32695. function decodeDCFirst(component, offset) {
  32696. var t = decodeHuffman(component.huffmanTableDC);
  32697. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  32698. component.blockData[offset] = (component.pred += diff);
  32699. }
  32700. function decodeDCSuccessive(component, offset) {
  32701. component.blockData[offset] |= readBit() << successive;
  32702. }
  32703. var eobrun = 0;
  32704. function decodeACFirst(component, offset) {
  32705. if (eobrun > 0) {
  32706. eobrun--;
  32707. return;
  32708. }
  32709. var k = spectralStart, e = spectralEnd;
  32710. while (k <= e) {
  32711. var rs = decodeHuffman(component.huffmanTableAC);
  32712. var s = rs & 15, r = rs >> 4;
  32713. if (s === 0) {
  32714. if (r < 15) {
  32715. eobrun = receive(r) + (1 << r) - 1;
  32716. break;
  32717. }
  32718. k += 16;
  32719. continue;
  32720. }
  32721. k += r;
  32722. var z = dctZigZag[k];
  32723. component.blockData[offset + z] =
  32724. receiveAndExtend(s) * (1 << successive);
  32725. k++;
  32726. }
  32727. }
  32728. var successiveACState = 0, successiveACNextValue;
  32729. function decodeACSuccessive(component, offset) {
  32730. var k = spectralStart;
  32731. var e = spectralEnd;
  32732. var r = 0;
  32733. var s;
  32734. var rs;
  32735. while (k <= e) {
  32736. var z = dctZigZag[k];
  32737. switch (successiveACState) {
  32738. case 0: // initial state
  32739. rs = decodeHuffman(component.huffmanTableAC);
  32740. s = rs & 15;
  32741. r = rs >> 4;
  32742. if (s === 0) {
  32743. if (r < 15) {
  32744. eobrun = receive(r) + (1 << r);
  32745. successiveACState = 4;
  32746. } else {
  32747. r = 16;
  32748. successiveACState = 1;
  32749. }
  32750. } else {
  32751. if (s !== 1) {
  32752. throw 'invalid ACn encoding';
  32753. }
  32754. successiveACNextValue = receiveAndExtend(s);
  32755. successiveACState = r ? 2 : 3;
  32756. }
  32757. continue;
  32758. case 1: // skipping r zero items
  32759. case 2:
  32760. if (component.blockData[offset + z]) {
  32761. component.blockData[offset + z] += (readBit() << successive);
  32762. } else {
  32763. r--;
  32764. if (r === 0) {
  32765. successiveACState = successiveACState === 2 ? 3 : 0;
  32766. }
  32767. }
  32768. break;
  32769. case 3: // set value for a zero item
  32770. if (component.blockData[offset + z]) {
  32771. component.blockData[offset + z] += (readBit() << successive);
  32772. } else {
  32773. component.blockData[offset + z] =
  32774. successiveACNextValue << successive;
  32775. successiveACState = 0;
  32776. }
  32777. break;
  32778. case 4: // eob
  32779. if (component.blockData[offset + z]) {
  32780. component.blockData[offset + z] += (readBit() << successive);
  32781. }
  32782. break;
  32783. }
  32784. k++;
  32785. }
  32786. if (successiveACState === 4) {
  32787. eobrun--;
  32788. if (eobrun === 0) {
  32789. successiveACState = 0;
  32790. }
  32791. }
  32792. }
  32793. function decodeMcu(component, decode, mcu, row, col) {
  32794. var mcuRow = (mcu / mcusPerLine) | 0;
  32795. var mcuCol = mcu % mcusPerLine;
  32796. var blockRow = mcuRow * component.v + row;
  32797. var blockCol = mcuCol * component.h + col;
  32798. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32799. decode(component, offset);
  32800. }
  32801. function decodeBlock(component, decode, mcu) {
  32802. var blockRow = (mcu / component.blocksPerLine) | 0;
  32803. var blockCol = mcu % component.blocksPerLine;
  32804. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  32805. decode(component, offset);
  32806. }
  32807. var componentsLength = components.length;
  32808. var component, i, j, k, n;
  32809. var decodeFn;
  32810. if (progressive) {
  32811. if (spectralStart === 0) {
  32812. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  32813. } else {
  32814. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  32815. }
  32816. } else {
  32817. decodeFn = decodeBaseline;
  32818. }
  32819. var mcu = 0, marker;
  32820. var mcuExpected;
  32821. if (componentsLength === 1) {
  32822. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  32823. } else {
  32824. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  32825. }
  32826. if (!resetInterval) {
  32827. resetInterval = mcuExpected;
  32828. }
  32829. var h, v;
  32830. while (mcu < mcuExpected) {
  32831. // reset interval stuff
  32832. for (i = 0; i < componentsLength; i++) {
  32833. components[i].pred = 0;
  32834. }
  32835. eobrun = 0;
  32836. if (componentsLength === 1) {
  32837. component = components[0];
  32838. for (n = 0; n < resetInterval; n++) {
  32839. decodeBlock(component, decodeFn, mcu);
  32840. mcu++;
  32841. }
  32842. } else {
  32843. for (n = 0; n < resetInterval; n++) {
  32844. for (i = 0; i < componentsLength; i++) {
  32845. component = components[i];
  32846. h = component.h;
  32847. v = component.v;
  32848. for (j = 0; j < v; j++) {
  32849. for (k = 0; k < h; k++) {
  32850. decodeMcu(component, decodeFn, mcu, j, k);
  32851. }
  32852. }
  32853. }
  32854. mcu++;
  32855. }
  32856. }
  32857. // find marker
  32858. bitsCount = 0;
  32859. marker = (data[offset] << 8) | data[offset + 1];
  32860. if (marker <= 0xFF00) {
  32861. throw 'marker was not found';
  32862. }
  32863. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  32864. offset += 2;
  32865. } else {
  32866. break;
  32867. }
  32868. }
  32869. return offset - startOffset;
  32870. }
  32871. // A port of poppler's IDCT method which in turn is taken from:
  32872. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  32873. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  32874. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  32875. // 988-991.
  32876. function quantizeAndInverse(component, blockBufferOffset, p) {
  32877. var qt = component.quantizationTable, blockData = component.blockData;
  32878. var v0, v1, v2, v3, v4, v5, v6, v7;
  32879. var p0, p1, p2, p3, p4, p5, p6, p7;
  32880. var t;
  32881. // inverse DCT on rows
  32882. for (var row = 0; row < 64; row += 8) {
  32883. // gather block data
  32884. p0 = blockData[blockBufferOffset + row];
  32885. p1 = blockData[blockBufferOffset + row + 1];
  32886. p2 = blockData[blockBufferOffset + row + 2];
  32887. p3 = blockData[blockBufferOffset + row + 3];
  32888. p4 = blockData[blockBufferOffset + row + 4];
  32889. p5 = blockData[blockBufferOffset + row + 5];
  32890. p6 = blockData[blockBufferOffset + row + 6];
  32891. p7 = blockData[blockBufferOffset + row + 7];
  32892. // dequant p0
  32893. p0 *= qt[row];
  32894. // check for all-zero AC coefficients
  32895. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32896. t = (dctSqrt2 * p0 + 512) >> 10;
  32897. p[row] = t;
  32898. p[row + 1] = t;
  32899. p[row + 2] = t;
  32900. p[row + 3] = t;
  32901. p[row + 4] = t;
  32902. p[row + 5] = t;
  32903. p[row + 6] = t;
  32904. p[row + 7] = t;
  32905. continue;
  32906. }
  32907. // dequant p1 ... p7
  32908. p1 *= qt[row + 1];
  32909. p2 *= qt[row + 2];
  32910. p3 *= qt[row + 3];
  32911. p4 *= qt[row + 4];
  32912. p5 *= qt[row + 5];
  32913. p6 *= qt[row + 6];
  32914. p7 *= qt[row + 7];
  32915. // stage 4
  32916. v0 = (dctSqrt2 * p0 + 128) >> 8;
  32917. v1 = (dctSqrt2 * p4 + 128) >> 8;
  32918. v2 = p2;
  32919. v3 = p6;
  32920. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  32921. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  32922. v5 = p3 << 4;
  32923. v6 = p5 << 4;
  32924. // stage 3
  32925. v0 = (v0 + v1 + 1) >> 1;
  32926. v1 = v0 - v1;
  32927. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  32928. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  32929. v3 = t;
  32930. v4 = (v4 + v6 + 1) >> 1;
  32931. v6 = v4 - v6;
  32932. v7 = (v7 + v5 + 1) >> 1;
  32933. v5 = v7 - v5;
  32934. // stage 2
  32935. v0 = (v0 + v3 + 1) >> 1;
  32936. v3 = v0 - v3;
  32937. v1 = (v1 + v2 + 1) >> 1;
  32938. v2 = v1 - v2;
  32939. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  32940. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  32941. v7 = t;
  32942. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  32943. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  32944. v6 = t;
  32945. // stage 1
  32946. p[row] = v0 + v7;
  32947. p[row + 7] = v0 - v7;
  32948. p[row + 1] = v1 + v6;
  32949. p[row + 6] = v1 - v6;
  32950. p[row + 2] = v2 + v5;
  32951. p[row + 5] = v2 - v5;
  32952. p[row + 3] = v3 + v4;
  32953. p[row + 4] = v3 - v4;
  32954. }
  32955. // inverse DCT on columns
  32956. for (var col = 0; col < 8; ++col) {
  32957. p0 = p[col];
  32958. p1 = p[col + 8];
  32959. p2 = p[col + 16];
  32960. p3 = p[col + 24];
  32961. p4 = p[col + 32];
  32962. p5 = p[col + 40];
  32963. p6 = p[col + 48];
  32964. p7 = p[col + 56];
  32965. // check for all-zero AC coefficients
  32966. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  32967. t = (dctSqrt2 * p0 + 8192) >> 14;
  32968. // convert to 8 bit
  32969. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  32970. blockData[blockBufferOffset + col] = t;
  32971. blockData[blockBufferOffset + col + 8] = t;
  32972. blockData[blockBufferOffset + col + 16] = t;
  32973. blockData[blockBufferOffset + col + 24] = t;
  32974. blockData[blockBufferOffset + col + 32] = t;
  32975. blockData[blockBufferOffset + col + 40] = t;
  32976. blockData[blockBufferOffset + col + 48] = t;
  32977. blockData[blockBufferOffset + col + 56] = t;
  32978. continue;
  32979. }
  32980. // stage 4
  32981. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  32982. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  32983. v2 = p2;
  32984. v3 = p6;
  32985. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  32986. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  32987. v5 = p3;
  32988. v6 = p5;
  32989. // stage 3
  32990. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  32991. // converting to UInt8 range later.
  32992. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  32993. v1 = v0 - v1;
  32994. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  32995. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  32996. v3 = t;
  32997. v4 = (v4 + v6 + 1) >> 1;
  32998. v6 = v4 - v6;
  32999. v7 = (v7 + v5 + 1) >> 1;
  33000. v5 = v7 - v5;
  33001. // stage 2
  33002. v0 = (v0 + v3 + 1) >> 1;
  33003. v3 = v0 - v3;
  33004. v1 = (v1 + v2 + 1) >> 1;
  33005. v2 = v1 - v2;
  33006. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  33007. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  33008. v7 = t;
  33009. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  33010. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  33011. v6 = t;
  33012. // stage 1
  33013. p0 = v0 + v7;
  33014. p7 = v0 - v7;
  33015. p1 = v1 + v6;
  33016. p6 = v1 - v6;
  33017. p2 = v2 + v5;
  33018. p5 = v2 - v5;
  33019. p3 = v3 + v4;
  33020. p4 = v3 - v4;
  33021. // convert to 8-bit integers
  33022. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  33023. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  33024. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  33025. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  33026. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  33027. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  33028. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  33029. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  33030. // store block data
  33031. blockData[blockBufferOffset + col] = p0;
  33032. blockData[blockBufferOffset + col + 8] = p1;
  33033. blockData[blockBufferOffset + col + 16] = p2;
  33034. blockData[blockBufferOffset + col + 24] = p3;
  33035. blockData[blockBufferOffset + col + 32] = p4;
  33036. blockData[blockBufferOffset + col + 40] = p5;
  33037. blockData[blockBufferOffset + col + 48] = p6;
  33038. blockData[blockBufferOffset + col + 56] = p7;
  33039. }
  33040. }
  33041. function buildComponentData(frame, component) {
  33042. var blocksPerLine = component.blocksPerLine;
  33043. var blocksPerColumn = component.blocksPerColumn;
  33044. var computationBuffer = new Int16Array(64);
  33045. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  33046. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  33047. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  33048. quantizeAndInverse(component, offset, computationBuffer);
  33049. }
  33050. }
  33051. return component.blockData;
  33052. }
  33053. function clamp0to255(a) {
  33054. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  33055. }
  33056. constructor.prototype = {
  33057. parse: function parse(data) {
  33058. function readUint16() {
  33059. var value = (data[offset] << 8) | data[offset + 1];
  33060. offset += 2;
  33061. return value;
  33062. }
  33063. function readDataBlock() {
  33064. var length = readUint16();
  33065. var array = data.subarray(offset, offset + length - 2);
  33066. offset += array.length;
  33067. return array;
  33068. }
  33069. function prepareComponents(frame) {
  33070. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  33071. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  33072. for (var i = 0; i < frame.components.length; i++) {
  33073. component = frame.components[i];
  33074. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  33075. component.h / frame.maxH);
  33076. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  33077. component.v / frame.maxV);
  33078. var blocksPerLineForMcu = mcusPerLine * component.h;
  33079. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  33080. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  33081. (blocksPerLineForMcu + 1);
  33082. component.blockData = new Int16Array(blocksBufferSize);
  33083. component.blocksPerLine = blocksPerLine;
  33084. component.blocksPerColumn = blocksPerColumn;
  33085. }
  33086. frame.mcusPerLine = mcusPerLine;
  33087. frame.mcusPerColumn = mcusPerColumn;
  33088. }
  33089. var offset = 0, length = data.length;
  33090. var jfif = null;
  33091. var adobe = null;
  33092. var pixels = null;
  33093. var frame, resetInterval;
  33094. var quantizationTables = [];
  33095. var huffmanTablesAC = [], huffmanTablesDC = [];
  33096. var fileMarker = readUint16();
  33097. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  33098. throw 'SOI not found';
  33099. }
  33100. fileMarker = readUint16();
  33101. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  33102. var i, j, l;
  33103. switch(fileMarker) {
  33104. case 0xFFE0: // APP0 (Application Specific)
  33105. case 0xFFE1: // APP1
  33106. case 0xFFE2: // APP2
  33107. case 0xFFE3: // APP3
  33108. case 0xFFE4: // APP4
  33109. case 0xFFE5: // APP5
  33110. case 0xFFE6: // APP6
  33111. case 0xFFE7: // APP7
  33112. case 0xFFE8: // APP8
  33113. case 0xFFE9: // APP9
  33114. case 0xFFEA: // APP10
  33115. case 0xFFEB: // APP11
  33116. case 0xFFEC: // APP12
  33117. case 0xFFED: // APP13
  33118. case 0xFFEE: // APP14
  33119. case 0xFFEF: // APP15
  33120. case 0xFFFE: // COM (Comment)
  33121. var appData = readDataBlock();
  33122. if (fileMarker === 0xFFE0) {
  33123. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  33124. appData[2] === 0x49 && appData[3] === 0x46 &&
  33125. appData[4] === 0) { // 'JFIF\x00'
  33126. jfif = {
  33127. version: { major: appData[5], minor: appData[6] },
  33128. densityUnits: appData[7],
  33129. xDensity: (appData[8] << 8) | appData[9],
  33130. yDensity: (appData[10] << 8) | appData[11],
  33131. thumbWidth: appData[12],
  33132. thumbHeight: appData[13],
  33133. thumbData: appData.subarray(14, 14 +
  33134. 3 * appData[12] * appData[13])
  33135. };
  33136. }
  33137. }
  33138. // TODO APP1 - Exif
  33139. if (fileMarker === 0xFFEE) {
  33140. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  33141. appData[2] === 0x6F && appData[3] === 0x62 &&
  33142. appData[4] === 0x65) { // 'Adobe'
  33143. adobe = {
  33144. version: (appData[5] << 8) | appData[6],
  33145. flags0: (appData[7] << 8) | appData[8],
  33146. flags1: (appData[9] << 8) | appData[10],
  33147. transformCode: appData[11]
  33148. };
  33149. }
  33150. }
  33151. break;
  33152. case 0xFFDB: // DQT (Define Quantization Tables)
  33153. var quantizationTablesLength = readUint16();
  33154. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  33155. var z;
  33156. while (offset < quantizationTablesEnd) {
  33157. var quantizationTableSpec = data[offset++];
  33158. var tableData = new Uint16Array(64);
  33159. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  33160. for (j = 0; j < 64; j++) {
  33161. z = dctZigZag[j];
  33162. tableData[z] = data[offset++];
  33163. }
  33164. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  33165. for (j = 0; j < 64; j++) {
  33166. z = dctZigZag[j];
  33167. tableData[z] = readUint16();
  33168. }
  33169. } else {
  33170. throw 'DQT: invalid table spec';
  33171. }
  33172. quantizationTables[quantizationTableSpec & 15] = tableData;
  33173. }
  33174. break;
  33175. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  33176. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  33177. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  33178. if (frame) {
  33179. throw 'Only single frame JPEGs supported';
  33180. }
  33181. readUint16(); // skip data length
  33182. frame = {};
  33183. frame.extended = (fileMarker === 0xFFC1);
  33184. frame.progressive = (fileMarker === 0xFFC2);
  33185. frame.precision = data[offset++];
  33186. frame.scanLines = readUint16();
  33187. frame.samplesPerLine = readUint16();
  33188. frame.components = [];
  33189. frame.componentIds = {};
  33190. var componentsCount = data[offset++], componentId;
  33191. var maxH = 0, maxV = 0;
  33192. for (i = 0; i < componentsCount; i++) {
  33193. componentId = data[offset];
  33194. var h = data[offset + 1] >> 4;
  33195. var v = data[offset + 1] & 15;
  33196. if (maxH < h) {
  33197. maxH = h;
  33198. }
  33199. if (maxV < v) {
  33200. maxV = v;
  33201. }
  33202. var qId = data[offset + 2];
  33203. l = frame.components.push({
  33204. h: h,
  33205. v: v,
  33206. quantizationTable: quantizationTables[qId]
  33207. });
  33208. frame.componentIds[componentId] = l - 1;
  33209. offset += 3;
  33210. }
  33211. frame.maxH = maxH;
  33212. frame.maxV = maxV;
  33213. prepareComponents(frame);
  33214. break;
  33215. case 0xFFC4: // DHT (Define Huffman Tables)
  33216. var huffmanLength = readUint16();
  33217. for (i = 2; i < huffmanLength;) {
  33218. var huffmanTableSpec = data[offset++];
  33219. var codeLengths = new Uint8Array(16);
  33220. var codeLengthSum = 0;
  33221. for (j = 0; j < 16; j++, offset++) {
  33222. codeLengthSum += (codeLengths[j] = data[offset]);
  33223. }
  33224. var huffmanValues = new Uint8Array(codeLengthSum);
  33225. for (j = 0; j < codeLengthSum; j++, offset++) {
  33226. huffmanValues[j] = data[offset];
  33227. }
  33228. i += 17 + codeLengthSum;
  33229. ((huffmanTableSpec >> 4) === 0 ?
  33230. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  33231. buildHuffmanTable(codeLengths, huffmanValues);
  33232. }
  33233. break;
  33234. case 0xFFDD: // DRI (Define Restart Interval)
  33235. readUint16(); // skip data length
  33236. resetInterval = readUint16();
  33237. break;
  33238. case 0xFFDA: // SOS (Start of Scan)
  33239. var scanLength = readUint16();
  33240. var selectorsCount = data[offset++];
  33241. var components = [], component;
  33242. for (i = 0; i < selectorsCount; i++) {
  33243. var componentIndex = frame.componentIds[data[offset++]];
  33244. component = frame.components[componentIndex];
  33245. var tableSpec = data[offset++];
  33246. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  33247. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  33248. components.push(component);
  33249. }
  33250. var spectralStart = data[offset++];
  33251. var spectralEnd = data[offset++];
  33252. var successiveApproximation = data[offset++];
  33253. var processed = decodeScan(data, offset,
  33254. frame, components, resetInterval,
  33255. spectralStart, spectralEnd,
  33256. successiveApproximation >> 4, successiveApproximation & 15);
  33257. offset += processed;
  33258. break;
  33259. case 0xFFFF: // Fill bytes
  33260. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  33261. offset--;
  33262. }
  33263. break;
  33264. default:
  33265. if (data[offset - 3] === 0xFF &&
  33266. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  33267. // could be incorrect encoding -- last 0xFF byte of the previous
  33268. // block was eaten by the encoder
  33269. offset -= 3;
  33270. break;
  33271. }
  33272. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  33273. }
  33274. fileMarker = readUint16();
  33275. }
  33276. this.width = frame.samplesPerLine;
  33277. this.height = frame.scanLines;
  33278. this.jfif = jfif;
  33279. this.adobe = adobe;
  33280. this.components = [];
  33281. for (i = 0; i < frame.components.length; i++) {
  33282. component = frame.components[i];
  33283. this.components.push({
  33284. output: buildComponentData(frame, component),
  33285. scaleX: component.h / frame.maxH,
  33286. scaleY: component.v / frame.maxV,
  33287. blocksPerLine: component.blocksPerLine,
  33288. blocksPerColumn: component.blocksPerColumn
  33289. });
  33290. }
  33291. this.numComponents = this.components.length;
  33292. },
  33293. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  33294. var scaleX = this.width / width, scaleY = this.height / height;
  33295. var component, componentScaleX, componentScaleY, blocksPerScanline;
  33296. var x, y, i, j, k;
  33297. var index;
  33298. var offset = 0;
  33299. var output;
  33300. var numComponents = this.components.length;
  33301. var dataLength = width * height * numComponents;
  33302. var data = new Uint8Array(dataLength);
  33303. var xScaleBlockOffset = new Uint32Array(width);
  33304. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  33305. for (i = 0; i < numComponents; i++) {
  33306. component = this.components[i];
  33307. componentScaleX = component.scaleX * scaleX;
  33308. componentScaleY = component.scaleY * scaleY;
  33309. offset = i;
  33310. output = component.output;
  33311. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  33312. // precalculate the xScaleBlockOffset
  33313. for (x = 0; x < width; x++) {
  33314. j = 0 | (x * componentScaleX);
  33315. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  33316. }
  33317. // linearize the blocks of the component
  33318. for (y = 0; y < height; y++) {
  33319. j = 0 | (y * componentScaleY);
  33320. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  33321. for (x = 0; x < width; x++) {
  33322. data[offset] = output[index + xScaleBlockOffset[x]];
  33323. offset += numComponents;
  33324. }
  33325. }
  33326. }
  33327. // decodeTransform contains pairs of multiplier (-256..256) and additive
  33328. var transform = this.decodeTransform;
  33329. if (transform) {
  33330. for (i = 0; i < dataLength;) {
  33331. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  33332. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  33333. }
  33334. }
  33335. }
  33336. return data;
  33337. },
  33338. _isColorConversionNeeded: function isColorConversionNeeded() {
  33339. if (this.adobe && this.adobe.transformCode) {
  33340. // The adobe transform marker overrides any previous setting
  33341. return true;
  33342. } else if (this.numComponents === 3) {
  33343. return true;
  33344. } else {
  33345. return false;
  33346. }
  33347. },
  33348. _convertYccToRgb: function convertYccToRgb(data) {
  33349. var Y, Cb, Cr;
  33350. for (var i = 0, length = data.length; i < length; i += 3) {
  33351. Y = data[i ];
  33352. Cb = data[i + 1];
  33353. Cr = data[i + 2];
  33354. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  33355. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  33356. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  33357. }
  33358. return data;
  33359. },
  33360. _convertYcckToRgb: function convertYcckToRgb(data) {
  33361. var Y, Cb, Cr, k;
  33362. var offset = 0;
  33363. for (var i = 0, length = data.length; i < length; i += 4) {
  33364. Y = data[i];
  33365. Cb = data[i + 1];
  33366. Cr = data[i + 2];
  33367. k = data[i + 3];
  33368. var r = -122.67195406894 +
  33369. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  33370. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  33371. 0.154362151871126) +
  33372. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  33373. 0.00477271405408747 * k + 1.53380253221734) +
  33374. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  33375. 0.48357088451265) +
  33376. k * (-0.000336197177618394 * k + 0.484791561490776);
  33377. var g = 107.268039397724 +
  33378. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  33379. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  33380. 0.176491792462875) +
  33381. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  33382. 0.000770482631801132 * k - 0.151051492775562) +
  33383. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  33384. 0.25802910206845) +
  33385. k * (-0.000318913117588328 * k - 0.213742400323665);
  33386. var b = -20.810012546947 +
  33387. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  33388. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  33389. 0.814272968359295) +
  33390. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  33391. 0.000560833691242812 * k - 0.195152027534049) +
  33392. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  33393. 0.116935020465145) +
  33394. k * (-0.000343531996510555 * k + 0.24165260232407);
  33395. data[offset++] = clamp0to255(r);
  33396. data[offset++] = clamp0to255(g);
  33397. data[offset++] = clamp0to255(b);
  33398. }
  33399. return data;
  33400. },
  33401. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  33402. var Y, Cb, Cr;
  33403. for (var i = 0, length = data.length; i < length; i += 4) {
  33404. Y = data[i];
  33405. Cb = data[i + 1];
  33406. Cr = data[i + 2];
  33407. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  33408. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  33409. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  33410. // K in data[i + 3] is unchanged
  33411. }
  33412. return data;
  33413. },
  33414. _convertCmykToRgb: function convertCmykToRgb(data) {
  33415. var c, m, y, k;
  33416. var offset = 0;
  33417. var min = -255 * 255 * 255;
  33418. var scale = 1 / 255 / 255;
  33419. for (var i = 0, length = data.length; i < length; i += 4) {
  33420. c = data[i];
  33421. m = data[i + 1];
  33422. y = data[i + 2];
  33423. k = data[i + 3];
  33424. var r =
  33425. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  33426. 18.82290502165302 * y + 212.25662451639585 * k -
  33427. 72734.4411664936) +
  33428. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  33429. 17.873870861415444 * k - 1401.7366389350734) +
  33430. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  33431. 4465.541406466231) -
  33432. k * (21.86122147463605 * k + 48317.86113160301);
  33433. var g =
  33434. c * (8.841041422036149 * c + 60.118027045597366 * m +
  33435. 6.871425592049007 * y + 31.159100130055922 * k -
  33436. 20220.756542821975) +
  33437. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  33438. 131.35250912493976 * k - 48691.05921601825) +
  33439. y * (4.444339102852739 * y + 9.8632861493405 * k -
  33440. 6341.191035517494) -
  33441. k * (20.737325471181034 * k + 47890.15695978492);
  33442. var b =
  33443. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  33444. 30.89978309703729 * y - 0.23883238689178934 * k -
  33445. 3616.812083916688) +
  33446. m * (10.49593273432072 * m + 63.02378494754052 * y +
  33447. 50.606957656360734 * k - 28620.90484698408) +
  33448. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  33449. 49363.43385999684) -
  33450. k * (22.33816807309886 * k + 45932.16563550634);
  33451. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  33452. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  33453. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  33454. }
  33455. return data;
  33456. },
  33457. getData: function getData(width, height, forceRGBoutput) {
  33458. if (this.numComponents > 4) {
  33459. throw 'Unsupported color mode';
  33460. }
  33461. // type of data: Uint8Array(width * height * numComponents)
  33462. var data = this._getLinearizedBlockData(width, height);
  33463. if (this.numComponents === 3) {
  33464. return this._convertYccToRgb(data);
  33465. } else if (this.numComponents === 4) {
  33466. if (this._isColorConversionNeeded()) {
  33467. if (forceRGBoutput) {
  33468. return this._convertYcckToRgb(data);
  33469. } else {
  33470. return this._convertYcckToCmyk(data);
  33471. }
  33472. } else if (forceRGBoutput) {
  33473. return this._convertCmykToRgb(data);
  33474. }
  33475. }
  33476. return data;
  33477. }
  33478. };
  33479. return constructor;
  33480. })();
  33481. var JpxImage = (function JpxImageClosure() {
  33482. // Table E.1
  33483. var SubbandsGainLog2 = {
  33484. 'LL': 0,
  33485. 'LH': 1,
  33486. 'HL': 1,
  33487. 'HH': 2
  33488. };
  33489. function JpxImage() {
  33490. this.failOnCorruptedImage = false;
  33491. }
  33492. JpxImage.prototype = {
  33493. parse: function JpxImage_parse(data) {
  33494. var head = readUint16(data, 0);
  33495. // No box header, immediate start of codestream (SOC)
  33496. if (head === 0xFF4F) {
  33497. this.parseCodestream(data, 0, data.length);
  33498. return;
  33499. }
  33500. var position = 0, length = data.length;
  33501. while (position < length) {
  33502. var headerSize = 8;
  33503. var lbox = readUint32(data, position);
  33504. var tbox = readUint32(data, position + 4);
  33505. position += headerSize;
  33506. if (lbox === 1) {
  33507. // XLBox: read UInt64 according to spec.
  33508. // JavaScript's int precision of 53 bit should be sufficient here.
  33509. lbox = readUint32(data, position) * 4294967296 +
  33510. readUint32(data, position + 4);
  33511. position += 8;
  33512. headerSize += 8;
  33513. }
  33514. if (lbox === 0) {
  33515. lbox = length - position + headerSize;
  33516. }
  33517. if (lbox < headerSize) {
  33518. throw new Error('JPX Error: Invalid box field size');
  33519. }
  33520. var dataLength = lbox - headerSize;
  33521. var jumpDataLength = true;
  33522. switch (tbox) {
  33523. case 0x6A703268: // 'jp2h'
  33524. jumpDataLength = false; // parsing child boxes
  33525. break;
  33526. case 0x636F6C72: // 'colr'
  33527. // Colorspaces are not used, the CS from the PDF is used.
  33528. var method = data[position];
  33529. var precedence = data[position + 1];
  33530. var approximation = data[position + 2];
  33531. if (method === 1) {
  33532. // enumerated colorspace
  33533. var colorspace = readUint32(data, position + 3);
  33534. switch (colorspace) {
  33535. case 16: // this indicates a sRGB colorspace
  33536. case 17: // this indicates a grayscale colorspace
  33537. case 18: // this indicates a YUV colorspace
  33538. break;
  33539. default:
  33540. warn('Unknown colorspace ' + colorspace);
  33541. break;
  33542. }
  33543. } else if (method === 2) {
  33544. info('ICC profile not supported');
  33545. }
  33546. break;
  33547. case 0x6A703263: // 'jp2c'
  33548. this.parseCodestream(data, position, position + dataLength);
  33549. break;
  33550. case 0x6A502020: // 'jP\024\024'
  33551. if (0x0d0a870a !== readUint32(data, position)) {
  33552. warn('Invalid JP2 signature');
  33553. }
  33554. break;
  33555. // The following header types are valid but currently not used:
  33556. case 0x6A501A1A: // 'jP\032\032'
  33557. case 0x66747970: // 'ftyp'
  33558. case 0x72726571: // 'rreq'
  33559. case 0x72657320: // 'res '
  33560. case 0x69686472: // 'ihdr'
  33561. break;
  33562. default:
  33563. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  33564. (tbox >> 16) & 0xFF,
  33565. (tbox >> 8) & 0xFF,
  33566. tbox & 0xFF);
  33567. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  33568. break;
  33569. }
  33570. if (jumpDataLength) {
  33571. position += dataLength;
  33572. }
  33573. }
  33574. },
  33575. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  33576. var newByte = stream.getByte();
  33577. while (newByte >= 0) {
  33578. var oldByte = newByte;
  33579. newByte = stream.getByte();
  33580. var code = (oldByte << 8) | newByte;
  33581. // Image and tile size (SIZ)
  33582. if (code === 0xFF51) {
  33583. stream.skip(4);
  33584. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  33585. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  33586. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  33587. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  33588. stream.skip(16);
  33589. var Csiz = stream.getUint16(); // Byte 36
  33590. this.width = Xsiz - XOsiz;
  33591. this.height = Ysiz - YOsiz;
  33592. this.componentsCount = Csiz;
  33593. // Results are always returned as Uint8Arrays
  33594. this.bitsPerComponent = 8;
  33595. return;
  33596. }
  33597. }
  33598. throw new Error('JPX Error: No size marker found in JPX stream');
  33599. },
  33600. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  33601. var context = {};
  33602. try {
  33603. var doNotRecover = false;
  33604. var position = start;
  33605. while (position + 1 < end) {
  33606. var code = readUint16(data, position);
  33607. position += 2;
  33608. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  33609. switch (code) {
  33610. case 0xFF4F: // Start of codestream (SOC)
  33611. context.mainHeader = true;
  33612. break;
  33613. case 0xFFD9: // End of codestream (EOC)
  33614. break;
  33615. case 0xFF51: // Image and tile size (SIZ)
  33616. length = readUint16(data, position);
  33617. var siz = {};
  33618. siz.Xsiz = readUint32(data, position + 4);
  33619. siz.Ysiz = readUint32(data, position + 8);
  33620. siz.XOsiz = readUint32(data, position + 12);
  33621. siz.YOsiz = readUint32(data, position + 16);
  33622. siz.XTsiz = readUint32(data, position + 20);
  33623. siz.YTsiz = readUint32(data, position + 24);
  33624. siz.XTOsiz = readUint32(data, position + 28);
  33625. siz.YTOsiz = readUint32(data, position + 32);
  33626. var componentsCount = readUint16(data, position + 36);
  33627. siz.Csiz = componentsCount;
  33628. var components = [];
  33629. j = position + 38;
  33630. for (var i = 0; i < componentsCount; i++) {
  33631. var component = {
  33632. precision: (data[j] & 0x7F) + 1,
  33633. isSigned: !!(data[j] & 0x80),
  33634. XRsiz: data[j + 1],
  33635. YRsiz: data[j + 1]
  33636. };
  33637. calculateComponentDimensions(component, siz);
  33638. components.push(component);
  33639. }
  33640. context.SIZ = siz;
  33641. context.components = components;
  33642. calculateTileGrids(context, components);
  33643. context.QCC = [];
  33644. context.COC = [];
  33645. break;
  33646. case 0xFF5C: // Quantization default (QCD)
  33647. length = readUint16(data, position);
  33648. var qcd = {};
  33649. j = position + 2;
  33650. sqcd = data[j++];
  33651. switch (sqcd & 0x1F) {
  33652. case 0:
  33653. spqcdSize = 8;
  33654. scalarExpounded = true;
  33655. break;
  33656. case 1:
  33657. spqcdSize = 16;
  33658. scalarExpounded = false;
  33659. break;
  33660. case 2:
  33661. spqcdSize = 16;
  33662. scalarExpounded = true;
  33663. break;
  33664. default:
  33665. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33666. }
  33667. qcd.noQuantization = (spqcdSize === 8);
  33668. qcd.scalarExpounded = scalarExpounded;
  33669. qcd.guardBits = sqcd >> 5;
  33670. spqcds = [];
  33671. while (j < length + position) {
  33672. var spqcd = {};
  33673. if (spqcdSize === 8) {
  33674. spqcd.epsilon = data[j++] >> 3;
  33675. spqcd.mu = 0;
  33676. } else {
  33677. spqcd.epsilon = data[j] >> 3;
  33678. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33679. j += 2;
  33680. }
  33681. spqcds.push(spqcd);
  33682. }
  33683. qcd.SPqcds = spqcds;
  33684. if (context.mainHeader) {
  33685. context.QCD = qcd;
  33686. } else {
  33687. context.currentTile.QCD = qcd;
  33688. context.currentTile.QCC = [];
  33689. }
  33690. break;
  33691. case 0xFF5D: // Quantization component (QCC)
  33692. length = readUint16(data, position);
  33693. var qcc = {};
  33694. j = position + 2;
  33695. var cqcc;
  33696. if (context.SIZ.Csiz < 257) {
  33697. cqcc = data[j++];
  33698. } else {
  33699. cqcc = readUint16(data, j);
  33700. j += 2;
  33701. }
  33702. sqcd = data[j++];
  33703. switch (sqcd & 0x1F) {
  33704. case 0:
  33705. spqcdSize = 8;
  33706. scalarExpounded = true;
  33707. break;
  33708. case 1:
  33709. spqcdSize = 16;
  33710. scalarExpounded = false;
  33711. break;
  33712. case 2:
  33713. spqcdSize = 16;
  33714. scalarExpounded = true;
  33715. break;
  33716. default:
  33717. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  33718. }
  33719. qcc.noQuantization = (spqcdSize === 8);
  33720. qcc.scalarExpounded = scalarExpounded;
  33721. qcc.guardBits = sqcd >> 5;
  33722. spqcds = [];
  33723. while (j < (length + position)) {
  33724. spqcd = {};
  33725. if (spqcdSize === 8) {
  33726. spqcd.epsilon = data[j++] >> 3;
  33727. spqcd.mu = 0;
  33728. } else {
  33729. spqcd.epsilon = data[j] >> 3;
  33730. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  33731. j += 2;
  33732. }
  33733. spqcds.push(spqcd);
  33734. }
  33735. qcc.SPqcds = spqcds;
  33736. if (context.mainHeader) {
  33737. context.QCC[cqcc] = qcc;
  33738. } else {
  33739. context.currentTile.QCC[cqcc] = qcc;
  33740. }
  33741. break;
  33742. case 0xFF52: // Coding style default (COD)
  33743. length = readUint16(data, position);
  33744. var cod = {};
  33745. j = position + 2;
  33746. var scod = data[j++];
  33747. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  33748. cod.sopMarkerUsed = !!(scod & 2);
  33749. cod.ephMarkerUsed = !!(scod & 4);
  33750. cod.progressionOrder = data[j++];
  33751. cod.layersCount = readUint16(data, j);
  33752. j += 2;
  33753. cod.multipleComponentTransform = data[j++];
  33754. cod.decompositionLevelsCount = data[j++];
  33755. cod.xcb = (data[j++] & 0xF) + 2;
  33756. cod.ycb = (data[j++] & 0xF) + 2;
  33757. var blockStyle = data[j++];
  33758. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  33759. cod.resetContextProbabilities = !!(blockStyle & 2);
  33760. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  33761. cod.verticalyStripe = !!(blockStyle & 8);
  33762. cod.predictableTermination = !!(blockStyle & 16);
  33763. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  33764. cod.reversibleTransformation = data[j++];
  33765. if (cod.entropyCoderWithCustomPrecincts) {
  33766. var precinctsSizes = [];
  33767. while (j < length + position) {
  33768. var precinctsSize = data[j++];
  33769. precinctsSizes.push({
  33770. PPx: precinctsSize & 0xF,
  33771. PPy: precinctsSize >> 4
  33772. });
  33773. }
  33774. cod.precinctsSizes = precinctsSizes;
  33775. }
  33776. var unsupported = [];
  33777. if (cod.selectiveArithmeticCodingBypass) {
  33778. unsupported.push('selectiveArithmeticCodingBypass');
  33779. }
  33780. if (cod.resetContextProbabilities) {
  33781. unsupported.push('resetContextProbabilities');
  33782. }
  33783. if (cod.terminationOnEachCodingPass) {
  33784. unsupported.push('terminationOnEachCodingPass');
  33785. }
  33786. if (cod.verticalyStripe) {
  33787. unsupported.push('verticalyStripe');
  33788. }
  33789. if (cod.predictableTermination) {
  33790. unsupported.push('predictableTermination');
  33791. }
  33792. if (unsupported.length > 0) {
  33793. doNotRecover = true;
  33794. throw new Error('JPX Error: Unsupported COD options (' +
  33795. unsupported.join(', ') + ')');
  33796. }
  33797. if (context.mainHeader) {
  33798. context.COD = cod;
  33799. } else {
  33800. context.currentTile.COD = cod;
  33801. context.currentTile.COC = [];
  33802. }
  33803. break;
  33804. case 0xFF90: // Start of tile-part (SOT)
  33805. length = readUint16(data, position);
  33806. tile = {};
  33807. tile.index = readUint16(data, position + 2);
  33808. tile.length = readUint32(data, position + 4);
  33809. tile.dataEnd = tile.length + position - 2;
  33810. tile.partIndex = data[position + 8];
  33811. tile.partsCount = data[position + 9];
  33812. context.mainHeader = false;
  33813. if (tile.partIndex === 0) {
  33814. // reset component specific settings
  33815. tile.COD = context.COD;
  33816. tile.COC = context.COC.slice(0); // clone of the global COC
  33817. tile.QCD = context.QCD;
  33818. tile.QCC = context.QCC.slice(0); // clone of the global COC
  33819. }
  33820. context.currentTile = tile;
  33821. break;
  33822. case 0xFF93: // Start of data (SOD)
  33823. tile = context.currentTile;
  33824. if (tile.partIndex === 0) {
  33825. initializeTile(context, tile.index);
  33826. buildPackets(context);
  33827. }
  33828. // moving to the end of the data
  33829. length = tile.dataEnd - position;
  33830. parseTilePackets(context, data, position, length);
  33831. break;
  33832. case 0xFF55: // Tile-part lengths, main header (TLM)
  33833. case 0xFF57: // Packet length, main header (PLM)
  33834. case 0xFF58: // Packet length, tile-part header (PLT)
  33835. case 0xFF64: // Comment (COM)
  33836. length = readUint16(data, position);
  33837. // skipping content
  33838. break;
  33839. case 0xFF53: // Coding style component (COC)
  33840. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  33841. 'not implemented');
  33842. default:
  33843. throw new Error('JPX Error: Unknown codestream code: ' +
  33844. code.toString(16));
  33845. }
  33846. position += length;
  33847. }
  33848. } catch (e) {
  33849. if (doNotRecover || this.failOnCorruptedImage) {
  33850. throw e;
  33851. } else {
  33852. warn('Trying to recover from ' + e.message);
  33853. }
  33854. }
  33855. this.tiles = transformComponents(context);
  33856. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  33857. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  33858. this.componentsCount = context.SIZ.Csiz;
  33859. }
  33860. };
  33861. function calculateComponentDimensions(component, siz) {
  33862. // Section B.2 Component mapping
  33863. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  33864. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  33865. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  33866. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  33867. component.width = component.x1 - component.x0;
  33868. component.height = component.y1 - component.y0;
  33869. }
  33870. function calculateTileGrids(context, components) {
  33871. var siz = context.SIZ;
  33872. // Section B.3 Division into tile and tile-components
  33873. var tile, tiles = [];
  33874. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  33875. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  33876. for (var q = 0; q < numYtiles; q++) {
  33877. for (var p = 0; p < numXtiles; p++) {
  33878. tile = {};
  33879. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  33880. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  33881. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  33882. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  33883. tile.width = tile.tx1 - tile.tx0;
  33884. tile.height = tile.ty1 - tile.ty0;
  33885. tile.components = [];
  33886. tiles.push(tile);
  33887. }
  33888. }
  33889. context.tiles = tiles;
  33890. var componentsCount = siz.Csiz;
  33891. for (var i = 0, ii = componentsCount; i < ii; i++) {
  33892. var component = components[i];
  33893. for (var j = 0, jj = tiles.length; j < jj; j++) {
  33894. var tileComponent = {};
  33895. tile = tiles[j];
  33896. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  33897. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  33898. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  33899. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  33900. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  33901. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  33902. tile.components[i] = tileComponent;
  33903. }
  33904. }
  33905. }
  33906. function getBlocksDimensions(context, component, r) {
  33907. var codOrCoc = component.codingStyleParameters;
  33908. var result = {};
  33909. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  33910. result.PPx = 15;
  33911. result.PPy = 15;
  33912. } else {
  33913. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  33914. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  33915. }
  33916. // calculate codeblock size as described in section B.7
  33917. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  33918. Math.min(codOrCoc.xcb, result.PPx));
  33919. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  33920. Math.min(codOrCoc.ycb, result.PPy));
  33921. return result;
  33922. }
  33923. function buildPrecincts(context, resolution, dimensions) {
  33924. // Section B.6 Division resolution to precincts
  33925. var precinctWidth = 1 << dimensions.PPx;
  33926. var precinctHeight = 1 << dimensions.PPy;
  33927. // Jasper introduces codeblock groups for mapping each subband codeblocks
  33928. // to precincts. Precinct partition divides a resolution according to width
  33929. // and height parameters. The subband that belongs to the resolution level
  33930. // has a different size than the level, unless it is the zero resolution.
  33931. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  33932. // The precinct partitioning for a particular subband is derived from a
  33933. // partitioning of its parent LL band (i.e., the LL band at the next higher
  33934. // resolution level)... The LL band associated with each resolution level is
  33935. // divided into precincts... Each of the resulting precinct regions is then
  33936. // mapped into its child subbands (if any) at the next lower resolution
  33937. // level. This is accomplished by using the coordinate transformation
  33938. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  33939. // coordinates of a point in the LL band and child subband, respectively.
  33940. var isZeroRes = resolution.resLevel === 0;
  33941. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  33942. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  33943. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  33944. Math.ceil(resolution.trx1 / precinctWidth) -
  33945. Math.floor(resolution.trx0 / precinctWidth) : 0);
  33946. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  33947. Math.ceil(resolution.try1 / precinctHeight) -
  33948. Math.floor(resolution.try0 / precinctHeight) : 0);
  33949. var numprecincts = numprecinctswide * numprecinctshigh;
  33950. resolution.precinctParameters = {
  33951. precinctWidth: precinctWidth,
  33952. precinctHeight: precinctHeight,
  33953. numprecinctswide: numprecinctswide,
  33954. numprecinctshigh: numprecinctshigh,
  33955. numprecincts: numprecincts,
  33956. precinctWidthInSubband: precinctWidthInSubband,
  33957. precinctHeightInSubband: precinctHeightInSubband
  33958. };
  33959. }
  33960. function buildCodeblocks(context, subband, dimensions) {
  33961. // Section B.7 Division sub-band into code-blocks
  33962. var xcb_ = dimensions.xcb_;
  33963. var ycb_ = dimensions.ycb_;
  33964. var codeblockWidth = 1 << xcb_;
  33965. var codeblockHeight = 1 << ycb_;
  33966. var cbx0 = subband.tbx0 >> xcb_;
  33967. var cby0 = subband.tby0 >> ycb_;
  33968. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  33969. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  33970. var precinctParameters = subband.resolution.precinctParameters;
  33971. var codeblocks = [];
  33972. var precincts = [];
  33973. var i, j, codeblock, precinctNumber;
  33974. for (j = cby0; j < cby1; j++) {
  33975. for (i = cbx0; i < cbx1; i++) {
  33976. codeblock = {
  33977. cbx: i,
  33978. cby: j,
  33979. tbx0: codeblockWidth * i,
  33980. tby0: codeblockHeight * j,
  33981. tbx1: codeblockWidth * (i + 1),
  33982. tby1: codeblockHeight * (j + 1)
  33983. };
  33984. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  33985. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  33986. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  33987. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  33988. // Calculate precinct number for this codeblock, codeblock position
  33989. // should be relative to its subband, use actual dimension and position
  33990. // See comment about codeblock group width and height
  33991. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  33992. precinctParameters.precinctWidthInSubband);
  33993. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  33994. precinctParameters.precinctHeightInSubband);
  33995. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  33996. codeblock.precinctNumber = precinctNumber;
  33997. codeblock.subbandType = subband.type;
  33998. codeblock.Lblock = 3;
  33999. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  34000. codeblock.tby1_ <= codeblock.tby0_) {
  34001. continue;
  34002. }
  34003. codeblocks.push(codeblock);
  34004. // building precinct for the sub-band
  34005. var precinct = precincts[precinctNumber];
  34006. if (precinct !== undefined) {
  34007. if (i < precinct.cbxMin) {
  34008. precinct.cbxMin = i;
  34009. } else if (i > precinct.cbxMax) {
  34010. precinct.cbxMax = i;
  34011. }
  34012. if (j < precinct.cbyMin) {
  34013. precinct.cbxMin = j;
  34014. } else if (j > precinct.cbyMax) {
  34015. precinct.cbyMax = j;
  34016. }
  34017. } else {
  34018. precincts[precinctNumber] = precinct = {
  34019. cbxMin: i,
  34020. cbyMin: j,
  34021. cbxMax: i,
  34022. cbyMax: j
  34023. };
  34024. }
  34025. codeblock.precinct = precinct;
  34026. }
  34027. }
  34028. subband.codeblockParameters = {
  34029. codeblockWidth: xcb_,
  34030. codeblockHeight: ycb_,
  34031. numcodeblockwide: cbx1 - cbx0 + 1,
  34032. numcodeblockhigh: cby1 - cby0 + 1
  34033. };
  34034. subband.codeblocks = codeblocks;
  34035. subband.precincts = precincts;
  34036. }
  34037. function createPacket(resolution, precinctNumber, layerNumber) {
  34038. var precinctCodeblocks = [];
  34039. // Section B.10.8 Order of info in packet
  34040. var subbands = resolution.subbands;
  34041. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  34042. for (var i = 0, ii = subbands.length; i < ii; i++) {
  34043. var subband = subbands[i];
  34044. var codeblocks = subband.codeblocks;
  34045. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  34046. var codeblock = codeblocks[j];
  34047. if (codeblock.precinctNumber !== precinctNumber) {
  34048. continue;
  34049. }
  34050. precinctCodeblocks.push(codeblock);
  34051. }
  34052. }
  34053. return {
  34054. layerNumber: layerNumber,
  34055. codeblocks: precinctCodeblocks
  34056. };
  34057. }
  34058. function LayerResolutionComponentPositionIterator(context) {
  34059. var siz = context.SIZ;
  34060. var tileIndex = context.currentTile.index;
  34061. var tile = context.tiles[tileIndex];
  34062. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34063. var componentsCount = siz.Csiz;
  34064. var maxDecompositionLevelsCount = 0;
  34065. for (var q = 0; q < componentsCount; q++) {
  34066. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34067. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34068. }
  34069. var l = 0, r = 0, i = 0, k = 0;
  34070. this.nextPacket = function JpxImage_nextPacket() {
  34071. // Section B.12.1.1 Layer-resolution-component-position
  34072. for (; l < layersCount; l++) {
  34073. for (; r <= maxDecompositionLevelsCount; r++) {
  34074. for (; i < componentsCount; i++) {
  34075. var component = tile.components[i];
  34076. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34077. continue;
  34078. }
  34079. var resolution = component.resolutions[r];
  34080. var numprecincts = resolution.precinctParameters.numprecincts;
  34081. for (; k < numprecincts;) {
  34082. var packet = createPacket(resolution, k, l);
  34083. k++;
  34084. return packet;
  34085. }
  34086. k = 0;
  34087. }
  34088. i = 0;
  34089. }
  34090. r = 0;
  34091. }
  34092. throw new Error('JPX Error: Out of packets');
  34093. };
  34094. }
  34095. function ResolutionLayerComponentPositionIterator(context) {
  34096. var siz = context.SIZ;
  34097. var tileIndex = context.currentTile.index;
  34098. var tile = context.tiles[tileIndex];
  34099. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34100. var componentsCount = siz.Csiz;
  34101. var maxDecompositionLevelsCount = 0;
  34102. for (var q = 0; q < componentsCount; q++) {
  34103. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34104. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  34105. }
  34106. var r = 0, l = 0, i = 0, k = 0;
  34107. this.nextPacket = function JpxImage_nextPacket() {
  34108. // Section B.12.1.2 Resolution-layer-component-position
  34109. for (; r <= maxDecompositionLevelsCount; r++) {
  34110. for (; l < layersCount; l++) {
  34111. for (; i < componentsCount; i++) {
  34112. var component = tile.components[i];
  34113. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34114. continue;
  34115. }
  34116. var resolution = component.resolutions[r];
  34117. var numprecincts = resolution.precinctParameters.numprecincts;
  34118. for (; k < numprecincts;) {
  34119. var packet = createPacket(resolution, k, l);
  34120. k++;
  34121. return packet;
  34122. }
  34123. k = 0;
  34124. }
  34125. i = 0;
  34126. }
  34127. l = 0;
  34128. }
  34129. throw new Error('JPX Error: Out of packets');
  34130. };
  34131. }
  34132. function ResolutionPositionComponentLayerIterator(context) {
  34133. var siz = context.SIZ;
  34134. var tileIndex = context.currentTile.index;
  34135. var tile = context.tiles[tileIndex];
  34136. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34137. var componentsCount = siz.Csiz;
  34138. var l, r, c, p;
  34139. var maxDecompositionLevelsCount = 0;
  34140. for (c = 0; c < componentsCount; c++) {
  34141. var component = tile.components[c];
  34142. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  34143. component.codingStyleParameters.decompositionLevelsCount);
  34144. }
  34145. var maxNumPrecinctsInLevel = new Int32Array(
  34146. maxDecompositionLevelsCount + 1);
  34147. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  34148. var maxNumPrecincts = 0;
  34149. for (c = 0; c < componentsCount; ++c) {
  34150. var resolutions = tile.components[c].resolutions;
  34151. if (r < resolutions.length) {
  34152. maxNumPrecincts = Math.max(maxNumPrecincts,
  34153. resolutions[r].precinctParameters.numprecincts);
  34154. }
  34155. }
  34156. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  34157. }
  34158. l = 0;
  34159. r = 0;
  34160. c = 0;
  34161. p = 0;
  34162. this.nextPacket = function JpxImage_nextPacket() {
  34163. // Section B.12.1.3 Resolution-position-component-layer
  34164. for (; r <= maxDecompositionLevelsCount; r++) {
  34165. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  34166. for (; c < componentsCount; c++) {
  34167. var component = tile.components[c];
  34168. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  34169. continue;
  34170. }
  34171. var resolution = component.resolutions[r];
  34172. var numprecincts = resolution.precinctParameters.numprecincts;
  34173. if (p >= numprecincts) {
  34174. continue;
  34175. }
  34176. for (; l < layersCount;) {
  34177. var packet = createPacket(resolution, p, l);
  34178. l++;
  34179. return packet;
  34180. }
  34181. l = 0;
  34182. }
  34183. c = 0;
  34184. }
  34185. p = 0;
  34186. }
  34187. throw new Error('JPX Error: Out of packets');
  34188. };
  34189. }
  34190. function PositionComponentResolutionLayerIterator(context) {
  34191. var siz = context.SIZ;
  34192. var tileIndex = context.currentTile.index;
  34193. var tile = context.tiles[tileIndex];
  34194. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34195. var componentsCount = siz.Csiz;
  34196. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34197. var precinctsIterationSizes = precinctsSizes;
  34198. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34199. this.nextPacket = function JpxImage_nextPacket() {
  34200. // Section B.12.1.4 Position-component-resolution-layer
  34201. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34202. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34203. for (; c < componentsCount; c++) {
  34204. var component = tile.components[c];
  34205. var decompositionLevelsCount =
  34206. component.codingStyleParameters.decompositionLevelsCount;
  34207. for (; r <= decompositionLevelsCount; r++) {
  34208. var resolution = component.resolutions[r];
  34209. var sizeInImageScale =
  34210. precinctsSizes.components[c].resolutions[r];
  34211. var k = getPrecinctIndexIfExist(
  34212. px,
  34213. py,
  34214. sizeInImageScale,
  34215. precinctsIterationSizes,
  34216. resolution);
  34217. if (k === null) {
  34218. continue;
  34219. }
  34220. for (; l < layersCount;) {
  34221. var packet = createPacket(resolution, k, l);
  34222. l++;
  34223. return packet;
  34224. }
  34225. l = 0;
  34226. }
  34227. r = 0;
  34228. }
  34229. c = 0;
  34230. }
  34231. px = 0;
  34232. }
  34233. throw new Error('JPX Error: Out of packets');
  34234. };
  34235. }
  34236. function ComponentPositionResolutionLayerIterator(context) {
  34237. var siz = context.SIZ;
  34238. var tileIndex = context.currentTile.index;
  34239. var tile = context.tiles[tileIndex];
  34240. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  34241. var componentsCount = siz.Csiz;
  34242. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  34243. var l = 0, r = 0, c = 0, px = 0, py = 0;
  34244. this.nextPacket = function JpxImage_nextPacket() {
  34245. // Section B.12.1.5 Component-position-resolution-layer
  34246. for (; c < componentsCount; ++c) {
  34247. var component = tile.components[c];
  34248. var precinctsIterationSizes = precinctsSizes.components[c];
  34249. var decompositionLevelsCount =
  34250. component.codingStyleParameters.decompositionLevelsCount;
  34251. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  34252. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  34253. for (; r <= decompositionLevelsCount; r++) {
  34254. var resolution = component.resolutions[r];
  34255. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  34256. var k = getPrecinctIndexIfExist(
  34257. px,
  34258. py,
  34259. sizeInImageScale,
  34260. precinctsIterationSizes,
  34261. resolution);
  34262. if (k === null) {
  34263. continue;
  34264. }
  34265. for (; l < layersCount;) {
  34266. var packet = createPacket(resolution, k, l);
  34267. l++;
  34268. return packet;
  34269. }
  34270. l = 0;
  34271. }
  34272. r = 0;
  34273. }
  34274. px = 0;
  34275. }
  34276. py = 0;
  34277. }
  34278. throw new Error('JPX Error: Out of packets');
  34279. };
  34280. }
  34281. function getPrecinctIndexIfExist(
  34282. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  34283. var posX = pxIndex * precinctIterationSizes.minWidth;
  34284. var posY = pyIndex * precinctIterationSizes.minHeight;
  34285. if (posX % sizeInImageScale.width !== 0 ||
  34286. posY % sizeInImageScale.height !== 0) {
  34287. return null;
  34288. }
  34289. var startPrecinctRowIndex =
  34290. (posY / sizeInImageScale.width) *
  34291. resolution.precinctParameters.numprecinctswide;
  34292. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  34293. }
  34294. function getPrecinctSizesInImageScale(tile) {
  34295. var componentsCount = tile.components.length;
  34296. var minWidth = Number.MAX_VALUE;
  34297. var minHeight = Number.MAX_VALUE;
  34298. var maxNumWide = 0;
  34299. var maxNumHigh = 0;
  34300. var sizePerComponent = new Array(componentsCount);
  34301. for (var c = 0; c < componentsCount; c++) {
  34302. var component = tile.components[c];
  34303. var decompositionLevelsCount =
  34304. component.codingStyleParameters.decompositionLevelsCount;
  34305. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  34306. var minWidthCurrentComponent = Number.MAX_VALUE;
  34307. var minHeightCurrentComponent = Number.MAX_VALUE;
  34308. var maxNumWideCurrentComponent = 0;
  34309. var maxNumHighCurrentComponent = 0;
  34310. var scale = 1;
  34311. for (var r = decompositionLevelsCount; r >= 0; --r) {
  34312. var resolution = component.resolutions[r];
  34313. var widthCurrentResolution =
  34314. scale * resolution.precinctParameters.precinctWidth;
  34315. var heightCurrentResolution =
  34316. scale * resolution.precinctParameters.precinctHeight;
  34317. minWidthCurrentComponent = Math.min(
  34318. minWidthCurrentComponent,
  34319. widthCurrentResolution);
  34320. minHeightCurrentComponent = Math.min(
  34321. minHeightCurrentComponent,
  34322. heightCurrentResolution);
  34323. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  34324. resolution.precinctParameters.numprecinctswide);
  34325. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  34326. resolution.precinctParameters.numprecinctshigh);
  34327. sizePerResolution[r] = {
  34328. width: widthCurrentResolution,
  34329. height: heightCurrentResolution
  34330. };
  34331. scale <<= 1;
  34332. }
  34333. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  34334. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  34335. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  34336. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  34337. sizePerComponent[c] = {
  34338. resolutions: sizePerResolution,
  34339. minWidth: minWidthCurrentComponent,
  34340. minHeight: minHeightCurrentComponent,
  34341. maxNumWide: maxNumWideCurrentComponent,
  34342. maxNumHigh: maxNumHighCurrentComponent
  34343. };
  34344. }
  34345. return {
  34346. components: sizePerComponent,
  34347. minWidth: minWidth,
  34348. minHeight: minHeight,
  34349. maxNumWide: maxNumWide,
  34350. maxNumHigh: maxNumHigh
  34351. };
  34352. }
  34353. function buildPackets(context) {
  34354. var siz = context.SIZ;
  34355. var tileIndex = context.currentTile.index;
  34356. var tile = context.tiles[tileIndex];
  34357. var componentsCount = siz.Csiz;
  34358. // Creating resolutions and sub-bands for each component
  34359. for (var c = 0; c < componentsCount; c++) {
  34360. var component = tile.components[c];
  34361. var decompositionLevelsCount =
  34362. component.codingStyleParameters.decompositionLevelsCount;
  34363. // Section B.5 Resolution levels and sub-bands
  34364. var resolutions = [];
  34365. var subbands = [];
  34366. for (var r = 0; r <= decompositionLevelsCount; r++) {
  34367. var blocksDimensions = getBlocksDimensions(context, component, r);
  34368. var resolution = {};
  34369. var scale = 1 << (decompositionLevelsCount - r);
  34370. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  34371. resolution.try0 = Math.ceil(component.tcy0 / scale);
  34372. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  34373. resolution.try1 = Math.ceil(component.tcy1 / scale);
  34374. resolution.resLevel = r;
  34375. buildPrecincts(context, resolution, blocksDimensions);
  34376. resolutions.push(resolution);
  34377. var subband;
  34378. if (r === 0) {
  34379. // one sub-band (LL) with last decomposition
  34380. subband = {};
  34381. subband.type = 'LL';
  34382. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  34383. subband.tby0 = Math.ceil(component.tcy0 / scale);
  34384. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  34385. subband.tby1 = Math.ceil(component.tcy1 / scale);
  34386. subband.resolution = resolution;
  34387. buildCodeblocks(context, subband, blocksDimensions);
  34388. subbands.push(subband);
  34389. resolution.subbands = [subband];
  34390. } else {
  34391. var bscale = 1 << (decompositionLevelsCount - r + 1);
  34392. var resolutionSubbands = [];
  34393. // three sub-bands (HL, LH and HH) with rest of decompositions
  34394. subband = {};
  34395. subband.type = 'HL';
  34396. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34397. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  34398. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34399. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  34400. subband.resolution = resolution;
  34401. buildCodeblocks(context, subband, blocksDimensions);
  34402. subbands.push(subband);
  34403. resolutionSubbands.push(subband);
  34404. subband = {};
  34405. subband.type = 'LH';
  34406. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  34407. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34408. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  34409. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34410. subband.resolution = resolution;
  34411. buildCodeblocks(context, subband, blocksDimensions);
  34412. subbands.push(subband);
  34413. resolutionSubbands.push(subband);
  34414. subband = {};
  34415. subband.type = 'HH';
  34416. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  34417. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  34418. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  34419. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  34420. subband.resolution = resolution;
  34421. buildCodeblocks(context, subband, blocksDimensions);
  34422. subbands.push(subband);
  34423. resolutionSubbands.push(subband);
  34424. resolution.subbands = resolutionSubbands;
  34425. }
  34426. }
  34427. component.resolutions = resolutions;
  34428. component.subbands = subbands;
  34429. }
  34430. // Generate the packets sequence
  34431. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  34432. switch (progressionOrder) {
  34433. case 0:
  34434. tile.packetsIterator =
  34435. new LayerResolutionComponentPositionIterator(context);
  34436. break;
  34437. case 1:
  34438. tile.packetsIterator =
  34439. new ResolutionLayerComponentPositionIterator(context);
  34440. break;
  34441. case 2:
  34442. tile.packetsIterator =
  34443. new ResolutionPositionComponentLayerIterator(context);
  34444. break;
  34445. case 3:
  34446. tile.packetsIterator =
  34447. new PositionComponentResolutionLayerIterator(context);
  34448. break;
  34449. case 4:
  34450. tile.packetsIterator =
  34451. new ComponentPositionResolutionLayerIterator(context);
  34452. break;
  34453. default:
  34454. throw new Error('JPX Error: Unsupported progression order ' +
  34455. progressionOrder);
  34456. }
  34457. }
  34458. function parseTilePackets(context, data, offset, dataLength) {
  34459. var position = 0;
  34460. var buffer, bufferSize = 0, skipNextBit = false;
  34461. function readBits(count) {
  34462. while (bufferSize < count) {
  34463. var b = data[offset + position];
  34464. position++;
  34465. if (skipNextBit) {
  34466. buffer = (buffer << 7) | b;
  34467. bufferSize += 7;
  34468. skipNextBit = false;
  34469. } else {
  34470. buffer = (buffer << 8) | b;
  34471. bufferSize += 8;
  34472. }
  34473. if (b === 0xFF) {
  34474. skipNextBit = true;
  34475. }
  34476. }
  34477. bufferSize -= count;
  34478. return (buffer >>> bufferSize) & ((1 << count) - 1);
  34479. }
  34480. function skipMarkerIfEqual(value) {
  34481. if (data[offset + position - 1] === 0xFF &&
  34482. data[offset + position] === value) {
  34483. skipBytes(1);
  34484. return true;
  34485. } else if (data[offset + position] === 0xFF &&
  34486. data[offset + position + 1] === value) {
  34487. skipBytes(2);
  34488. return true;
  34489. }
  34490. return false;
  34491. }
  34492. function skipBytes(count) {
  34493. position += count;
  34494. }
  34495. function alignToByte() {
  34496. bufferSize = 0;
  34497. if (skipNextBit) {
  34498. position++;
  34499. skipNextBit = false;
  34500. }
  34501. }
  34502. function readCodingpasses() {
  34503. if (readBits(1) === 0) {
  34504. return 1;
  34505. }
  34506. if (readBits(1) === 0) {
  34507. return 2;
  34508. }
  34509. var value = readBits(2);
  34510. if (value < 3) {
  34511. return value + 3;
  34512. }
  34513. value = readBits(5);
  34514. if (value < 31) {
  34515. return value + 6;
  34516. }
  34517. value = readBits(7);
  34518. return value + 37;
  34519. }
  34520. var tileIndex = context.currentTile.index;
  34521. var tile = context.tiles[tileIndex];
  34522. var sopMarkerUsed = context.COD.sopMarkerUsed;
  34523. var ephMarkerUsed = context.COD.ephMarkerUsed;
  34524. var packetsIterator = tile.packetsIterator;
  34525. while (position < dataLength) {
  34526. alignToByte();
  34527. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  34528. // Skip also marker segment length and packet sequence ID
  34529. skipBytes(4);
  34530. }
  34531. var packet = packetsIterator.nextPacket();
  34532. if (!readBits(1)) {
  34533. continue;
  34534. }
  34535. var layerNumber = packet.layerNumber;
  34536. var queue = [], codeblock;
  34537. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  34538. codeblock = packet.codeblocks[i];
  34539. var precinct = codeblock.precinct;
  34540. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  34541. var codeblockRow = codeblock.cby - precinct.cbyMin;
  34542. var codeblockIncluded = false;
  34543. var firstTimeInclusion = false;
  34544. var valueReady;
  34545. if (codeblock['included'] !== undefined) {
  34546. codeblockIncluded = !!readBits(1);
  34547. } else {
  34548. // reading inclusion tree
  34549. precinct = codeblock.precinct;
  34550. var inclusionTree, zeroBitPlanesTree;
  34551. if (precinct['inclusionTree'] !== undefined) {
  34552. inclusionTree = precinct.inclusionTree;
  34553. } else {
  34554. // building inclusion and zero bit-planes trees
  34555. var width = precinct.cbxMax - precinct.cbxMin + 1;
  34556. var height = precinct.cbyMax - precinct.cbyMin + 1;
  34557. inclusionTree = new InclusionTree(width, height, layerNumber);
  34558. zeroBitPlanesTree = new TagTree(width, height);
  34559. precinct.inclusionTree = inclusionTree;
  34560. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  34561. }
  34562. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  34563. while (true) {
  34564. if (readBits(1)) {
  34565. valueReady = !inclusionTree.nextLevel();
  34566. if (valueReady) {
  34567. codeblock.included = true;
  34568. codeblockIncluded = firstTimeInclusion = true;
  34569. break;
  34570. }
  34571. } else {
  34572. inclusionTree.incrementValue(layerNumber);
  34573. break;
  34574. }
  34575. }
  34576. }
  34577. }
  34578. if (!codeblockIncluded) {
  34579. continue;
  34580. }
  34581. if (firstTimeInclusion) {
  34582. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  34583. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  34584. while (true) {
  34585. if (readBits(1)) {
  34586. valueReady = !zeroBitPlanesTree.nextLevel();
  34587. if (valueReady) {
  34588. break;
  34589. }
  34590. } else {
  34591. zeroBitPlanesTree.incrementValue();
  34592. }
  34593. }
  34594. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  34595. }
  34596. var codingpasses = readCodingpasses();
  34597. while (readBits(1)) {
  34598. codeblock.Lblock++;
  34599. }
  34600. var codingpassesLog2 = log2(codingpasses);
  34601. // rounding down log2
  34602. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  34603. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  34604. var codedDataLength = readBits(bits);
  34605. queue.push({
  34606. codeblock: codeblock,
  34607. codingpasses: codingpasses,
  34608. dataLength: codedDataLength
  34609. });
  34610. }
  34611. alignToByte();
  34612. if (ephMarkerUsed) {
  34613. skipMarkerIfEqual(0x92);
  34614. }
  34615. while (queue.length > 0) {
  34616. var packetItem = queue.shift();
  34617. codeblock = packetItem.codeblock;
  34618. if (codeblock['data'] === undefined) {
  34619. codeblock.data = [];
  34620. }
  34621. codeblock.data.push({
  34622. data: data,
  34623. start: offset + position,
  34624. end: offset + position + packetItem.dataLength,
  34625. codingpasses: packetItem.codingpasses
  34626. });
  34627. position += packetItem.dataLength;
  34628. }
  34629. }
  34630. return position;
  34631. }
  34632. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  34633. delta, mb, reversible, segmentationSymbolUsed) {
  34634. var x0 = subband.tbx0;
  34635. var y0 = subband.tby0;
  34636. var width = subband.tbx1 - subband.tbx0;
  34637. var codeblocks = subband.codeblocks;
  34638. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  34639. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  34640. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  34641. var codeblock = codeblocks[i];
  34642. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  34643. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  34644. if (blockWidth === 0 || blockHeight === 0) {
  34645. continue;
  34646. }
  34647. if (codeblock['data'] === undefined) {
  34648. continue;
  34649. }
  34650. var bitModel, currentCodingpassType;
  34651. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  34652. codeblock.zeroBitPlanes, mb);
  34653. currentCodingpassType = 2; // first bit plane starts from cleanup
  34654. // collect data
  34655. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  34656. var j, jj, dataItem;
  34657. for (j = 0, jj = data.length; j < jj; j++) {
  34658. dataItem = data[j];
  34659. totalLength += dataItem.end - dataItem.start;
  34660. codingpasses += dataItem.codingpasses;
  34661. }
  34662. var encodedData = new Uint8Array(totalLength);
  34663. var position = 0;
  34664. for (j = 0, jj = data.length; j < jj; j++) {
  34665. dataItem = data[j];
  34666. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  34667. encodedData.set(chunk, position);
  34668. position += chunk.length;
  34669. }
  34670. // decoding the item
  34671. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  34672. bitModel.setDecoder(decoder);
  34673. for (j = 0; j < codingpasses; j++) {
  34674. switch (currentCodingpassType) {
  34675. case 0:
  34676. bitModel.runSignificancePropogationPass();
  34677. break;
  34678. case 1:
  34679. bitModel.runMagnitudeRefinementPass();
  34680. break;
  34681. case 2:
  34682. bitModel.runCleanupPass();
  34683. if (segmentationSymbolUsed) {
  34684. bitModel.checkSegmentationSymbol();
  34685. }
  34686. break;
  34687. }
  34688. currentCodingpassType = (currentCodingpassType + 1) % 3;
  34689. }
  34690. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  34691. var sign = bitModel.coefficentsSign;
  34692. var magnitude = bitModel.coefficentsMagnitude;
  34693. var bitsDecoded = bitModel.bitsDecoded;
  34694. var magnitudeCorrection = reversible ? 0 : 0.5;
  34695. var k, n, nb;
  34696. position = 0;
  34697. // Do the interleaving of Section F.3.3 here, so we do not need
  34698. // to copy later. LL level is not interleaved, just copied.
  34699. var interleave = (subband.type !== 'LL');
  34700. for (j = 0; j < blockHeight; j++) {
  34701. var row = (offset / width) | 0; // row in the non-interleaved subband
  34702. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  34703. for (k = 0; k < blockWidth; k++) {
  34704. n = magnitude[position];
  34705. if (n !== 0) {
  34706. n = (n + magnitudeCorrection) * delta;
  34707. if (sign[position] !== 0) {
  34708. n = -n;
  34709. }
  34710. nb = bitsDecoded[position];
  34711. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  34712. if (reversible && (nb >= mb)) {
  34713. coefficients[pos] = n;
  34714. } else {
  34715. coefficients[pos] = n * (1 << (mb - nb));
  34716. }
  34717. }
  34718. offset++;
  34719. position++;
  34720. }
  34721. offset += width - blockWidth;
  34722. }
  34723. }
  34724. }
  34725. function transformTile(context, tile, c) {
  34726. var component = tile.components[c];
  34727. var codingStyleParameters = component.codingStyleParameters;
  34728. var quantizationParameters = component.quantizationParameters;
  34729. var decompositionLevelsCount =
  34730. codingStyleParameters.decompositionLevelsCount;
  34731. var spqcds = quantizationParameters.SPqcds;
  34732. var scalarExpounded = quantizationParameters.scalarExpounded;
  34733. var guardBits = quantizationParameters.guardBits;
  34734. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  34735. var precision = context.components[c].precision;
  34736. var reversible = codingStyleParameters.reversibleTransformation;
  34737. var transform = (reversible ? new ReversibleTransform() :
  34738. new IrreversibleTransform());
  34739. var subbandCoefficients = [];
  34740. var b = 0;
  34741. for (var i = 0; i <= decompositionLevelsCount; i++) {
  34742. var resolution = component.resolutions[i];
  34743. var width = resolution.trx1 - resolution.trx0;
  34744. var height = resolution.try1 - resolution.try0;
  34745. // Allocate space for the whole sublevel.
  34746. var coefficients = new Float32Array(width * height);
  34747. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  34748. var mu, epsilon;
  34749. if (!scalarExpounded) {
  34750. // formula E-5
  34751. mu = spqcds[0].mu;
  34752. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  34753. } else {
  34754. mu = spqcds[b].mu;
  34755. epsilon = spqcds[b].epsilon;
  34756. b++;
  34757. }
  34758. var subband = resolution.subbands[j];
  34759. var gainLog2 = SubbandsGainLog2[subband.type];
  34760. // calulate quantization coefficient (Section E.1.1.1)
  34761. var delta = (reversible ? 1 :
  34762. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  34763. var mb = (guardBits + epsilon - 1);
  34764. // In the first resolution level, copyCoefficients will fill the
  34765. // whole array with coefficients. In the succeding passes,
  34766. // copyCoefficients will consecutively fill in the values that belong
  34767. // to the interleaved positions of the HL, LH, and HH coefficients.
  34768. // The LL coefficients will then be interleaved in Transform.iterate().
  34769. copyCoefficients(coefficients, width, height, subband, delta, mb,
  34770. reversible, segmentationSymbolUsed);
  34771. }
  34772. subbandCoefficients.push({
  34773. width: width,
  34774. height: height,
  34775. items: coefficients
  34776. });
  34777. }
  34778. var result = transform.calculate(subbandCoefficients,
  34779. component.tcx0, component.tcy0);
  34780. return {
  34781. left: component.tcx0,
  34782. top: component.tcy0,
  34783. width: result.width,
  34784. height: result.height,
  34785. items: result.items
  34786. };
  34787. }
  34788. function transformComponents(context) {
  34789. var siz = context.SIZ;
  34790. var components = context.components;
  34791. var componentsCount = siz.Csiz;
  34792. var resultImages = [];
  34793. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  34794. var tile = context.tiles[i];
  34795. var transformedTiles = [];
  34796. var c;
  34797. for (c = 0; c < componentsCount; c++) {
  34798. transformedTiles[c] = transformTile(context, tile, c);
  34799. }
  34800. var tile0 = transformedTiles[0];
  34801. var out = new Uint8Array(tile0.items.length * componentsCount);
  34802. var result = {
  34803. left: tile0.left,
  34804. top: tile0.top,
  34805. width: tile0.width,
  34806. height: tile0.height,
  34807. items: out
  34808. };
  34809. // Section G.2.2 Inverse multi component transform
  34810. var shift, offset, max, min, maxK;
  34811. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  34812. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  34813. var fourComponents = componentsCount === 4;
  34814. var y0items = transformedTiles[0].items;
  34815. var y1items = transformedTiles[1].items;
  34816. var y2items = transformedTiles[2].items;
  34817. var y3items = fourComponents ? transformedTiles[3].items : null;
  34818. // HACK: The multiple component transform formulas below assume that
  34819. // all components have the same precision. With this in mind, we
  34820. // compute shift and offset only once.
  34821. shift = components[0].precision - 8;
  34822. offset = (128 << shift) + 0.5;
  34823. max = 255 * (1 << shift);
  34824. maxK = max * 0.5;
  34825. min = -maxK;
  34826. var component0 = tile.components[0];
  34827. var alpha01 = componentsCount - 3;
  34828. jj = y0items.length;
  34829. if (!component0.codingStyleParameters.reversibleTransformation) {
  34830. // inverse irreversible multiple component transform
  34831. for (j = 0; j < jj; j++, pos += alpha01) {
  34832. y0 = y0items[j] + offset;
  34833. y1 = y1items[j];
  34834. y2 = y2items[j];
  34835. r = y0 + 1.402 * y2;
  34836. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  34837. b = y0 + 1.772 * y1;
  34838. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34839. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34840. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34841. }
  34842. } else {
  34843. // inverse reversible multiple component transform
  34844. for (j = 0; j < jj; j++, pos += alpha01) {
  34845. y0 = y0items[j] + offset;
  34846. y1 = y1items[j];
  34847. y2 = y2items[j];
  34848. g = y0 - ((y2 + y1) >> 2);
  34849. r = g + y2;
  34850. b = g + y1;
  34851. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  34852. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  34853. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  34854. }
  34855. }
  34856. if (fourComponents) {
  34857. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  34858. k = y3items[j];
  34859. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  34860. }
  34861. }
  34862. } else { // no multi-component transform
  34863. for (c = 0; c < componentsCount; c++) {
  34864. var items = transformedTiles[c].items;
  34865. shift = components[c].precision - 8;
  34866. offset = (128 << shift) + 0.5;
  34867. max = (127.5 * (1 << shift));
  34868. min = -max;
  34869. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  34870. val = items[j];
  34871. out[pos] = val <= min ? 0 :
  34872. val >= max ? 255 : (val + offset) >> shift;
  34873. pos += componentsCount;
  34874. }
  34875. }
  34876. }
  34877. resultImages.push(result);
  34878. }
  34879. return resultImages;
  34880. }
  34881. function initializeTile(context, tileIndex) {
  34882. var siz = context.SIZ;
  34883. var componentsCount = siz.Csiz;
  34884. var tile = context.tiles[tileIndex];
  34885. for (var c = 0; c < componentsCount; c++) {
  34886. var component = tile.components[c];
  34887. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  34888. context.currentTile.QCC[c] : context.currentTile.QCD);
  34889. component.quantizationParameters = qcdOrQcc;
  34890. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  34891. context.currentTile.COC[c] : context.currentTile.COD);
  34892. component.codingStyleParameters = codOrCoc;
  34893. }
  34894. tile.codingStyleDefaultParameters = context.currentTile.COD;
  34895. }
  34896. // Section B.10.2 Tag trees
  34897. var TagTree = (function TagTreeClosure() {
  34898. function TagTree(width, height) {
  34899. var levelsLength = log2(Math.max(width, height)) + 1;
  34900. this.levels = [];
  34901. for (var i = 0; i < levelsLength; i++) {
  34902. var level = {
  34903. width: width,
  34904. height: height,
  34905. items: []
  34906. };
  34907. this.levels.push(level);
  34908. width = Math.ceil(width / 2);
  34909. height = Math.ceil(height / 2);
  34910. }
  34911. }
  34912. TagTree.prototype = {
  34913. reset: function TagTree_reset(i, j) {
  34914. var currentLevel = 0, value = 0, level;
  34915. while (currentLevel < this.levels.length) {
  34916. level = this.levels[currentLevel];
  34917. var index = i + j * level.width;
  34918. if (level.items[index] !== undefined) {
  34919. value = level.items[index];
  34920. break;
  34921. }
  34922. level.index = index;
  34923. i >>= 1;
  34924. j >>= 1;
  34925. currentLevel++;
  34926. }
  34927. currentLevel--;
  34928. level = this.levels[currentLevel];
  34929. level.items[level.index] = value;
  34930. this.currentLevel = currentLevel;
  34931. delete this.value;
  34932. },
  34933. incrementValue: function TagTree_incrementValue() {
  34934. var level = this.levels[this.currentLevel];
  34935. level.items[level.index]++;
  34936. },
  34937. nextLevel: function TagTree_nextLevel() {
  34938. var currentLevel = this.currentLevel;
  34939. var level = this.levels[currentLevel];
  34940. var value = level.items[level.index];
  34941. currentLevel--;
  34942. if (currentLevel < 0) {
  34943. this.value = value;
  34944. return false;
  34945. }
  34946. this.currentLevel = currentLevel;
  34947. level = this.levels[currentLevel];
  34948. level.items[level.index] = value;
  34949. return true;
  34950. }
  34951. };
  34952. return TagTree;
  34953. })();
  34954. var InclusionTree = (function InclusionTreeClosure() {
  34955. function InclusionTree(width, height, defaultValue) {
  34956. var levelsLength = log2(Math.max(width, height)) + 1;
  34957. this.levels = [];
  34958. for (var i = 0; i < levelsLength; i++) {
  34959. var items = new Uint8Array(width * height);
  34960. for (var j = 0, jj = items.length; j < jj; j++) {
  34961. items[j] = defaultValue;
  34962. }
  34963. var level = {
  34964. width: width,
  34965. height: height,
  34966. items: items
  34967. };
  34968. this.levels.push(level);
  34969. width = Math.ceil(width / 2);
  34970. height = Math.ceil(height / 2);
  34971. }
  34972. }
  34973. InclusionTree.prototype = {
  34974. reset: function InclusionTree_reset(i, j, stopValue) {
  34975. var currentLevel = 0;
  34976. while (currentLevel < this.levels.length) {
  34977. var level = this.levels[currentLevel];
  34978. var index = i + j * level.width;
  34979. level.index = index;
  34980. var value = level.items[index];
  34981. if (value === 0xFF) {
  34982. break;
  34983. }
  34984. if (value > stopValue) {
  34985. this.currentLevel = currentLevel;
  34986. // already know about this one, propagating the value to top levels
  34987. this.propagateValues();
  34988. return false;
  34989. }
  34990. i >>= 1;
  34991. j >>= 1;
  34992. currentLevel++;
  34993. }
  34994. this.currentLevel = currentLevel - 1;
  34995. return true;
  34996. },
  34997. incrementValue: function InclusionTree_incrementValue(stopValue) {
  34998. var level = this.levels[this.currentLevel];
  34999. level.items[level.index] = stopValue + 1;
  35000. this.propagateValues();
  35001. },
  35002. propagateValues: function InclusionTree_propagateValues() {
  35003. var levelIndex = this.currentLevel;
  35004. var level = this.levels[levelIndex];
  35005. var currentValue = level.items[level.index];
  35006. while (--levelIndex >= 0) {
  35007. level = this.levels[levelIndex];
  35008. level.items[level.index] = currentValue;
  35009. }
  35010. },
  35011. nextLevel: function InclusionTree_nextLevel() {
  35012. var currentLevel = this.currentLevel;
  35013. var level = this.levels[currentLevel];
  35014. var value = level.items[level.index];
  35015. level.items[level.index] = 0xFF;
  35016. currentLevel--;
  35017. if (currentLevel < 0) {
  35018. return false;
  35019. }
  35020. this.currentLevel = currentLevel;
  35021. level = this.levels[currentLevel];
  35022. level.items[level.index] = value;
  35023. return true;
  35024. }
  35025. };
  35026. return InclusionTree;
  35027. })();
  35028. // Section D. Coefficient bit modeling
  35029. var BitModel = (function BitModelClosure() {
  35030. var UNIFORM_CONTEXT = 17;
  35031. var RUNLENGTH_CONTEXT = 18;
  35032. // Table D-1
  35033. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  35034. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  35035. var LLAndLHContextsLabel = new Uint8Array([
  35036. 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,
  35037. 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,
  35038. 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
  35039. ]);
  35040. var HLContextLabel = new Uint8Array([
  35041. 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,
  35042. 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,
  35043. 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
  35044. ]);
  35045. var HHContextLabel = new Uint8Array([
  35046. 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,
  35047. 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,
  35048. 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
  35049. ]);
  35050. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  35051. this.width = width;
  35052. this.height = height;
  35053. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  35054. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  35055. var coefficientCount = width * height;
  35056. // coefficients outside the encoding region treated as insignificant
  35057. // add border state cells for significanceState
  35058. this.neighborsSignificance = new Uint8Array(coefficientCount);
  35059. this.coefficentsSign = new Uint8Array(coefficientCount);
  35060. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  35061. mb > 6 ? new Uint16Array(coefficientCount) :
  35062. new Uint8Array(coefficientCount);
  35063. this.processingFlags = new Uint8Array(coefficientCount);
  35064. var bitsDecoded = new Uint8Array(coefficientCount);
  35065. if (zeroBitPlanes !== 0) {
  35066. for (var i = 0; i < coefficientCount; i++) {
  35067. bitsDecoded[i] = zeroBitPlanes;
  35068. }
  35069. }
  35070. this.bitsDecoded = bitsDecoded;
  35071. this.reset();
  35072. }
  35073. BitModel.prototype = {
  35074. setDecoder: function BitModel_setDecoder(decoder) {
  35075. this.decoder = decoder;
  35076. },
  35077. reset: function BitModel_reset() {
  35078. // We have 17 contexts that are accessed via context labels,
  35079. // plus the uniform and runlength context.
  35080. this.contexts = new Int8Array(19);
  35081. // Contexts are packed into 1 byte:
  35082. // highest 7 bits carry the index, lowest bit carries mps
  35083. this.contexts[0] = (4 << 1) | 0;
  35084. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  35085. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  35086. },
  35087. setNeighborsSignificance:
  35088. function BitModel_setNeighborsSignificance(row, column, index) {
  35089. var neighborsSignificance = this.neighborsSignificance;
  35090. var width = this.width, height = this.height;
  35091. var left = (column > 0);
  35092. var right = (column + 1 < width);
  35093. var i;
  35094. if (row > 0) {
  35095. i = index - width;
  35096. if (left) {
  35097. neighborsSignificance[i - 1] += 0x10;
  35098. }
  35099. if (right) {
  35100. neighborsSignificance[i + 1] += 0x10;
  35101. }
  35102. neighborsSignificance[i] += 0x04;
  35103. }
  35104. if (row + 1 < height) {
  35105. i = index + width;
  35106. if (left) {
  35107. neighborsSignificance[i - 1] += 0x10;
  35108. }
  35109. if (right) {
  35110. neighborsSignificance[i + 1] += 0x10;
  35111. }
  35112. neighborsSignificance[i] += 0x04;
  35113. }
  35114. if (left) {
  35115. neighborsSignificance[index - 1] += 0x01;
  35116. }
  35117. if (right) {
  35118. neighborsSignificance[index + 1] += 0x01;
  35119. }
  35120. neighborsSignificance[index] |= 0x80;
  35121. },
  35122. runSignificancePropogationPass:
  35123. function BitModel_runSignificancePropogationPass() {
  35124. var decoder = this.decoder;
  35125. var width = this.width, height = this.height;
  35126. var coefficentsMagnitude = this.coefficentsMagnitude;
  35127. var coefficentsSign = this.coefficentsSign;
  35128. var neighborsSignificance = this.neighborsSignificance;
  35129. var processingFlags = this.processingFlags;
  35130. var contexts = this.contexts;
  35131. var labels = this.contextLabelTable;
  35132. var bitsDecoded = this.bitsDecoded;
  35133. var processedInverseMask = ~1;
  35134. var processedMask = 1;
  35135. var firstMagnitudeBitMask = 2;
  35136. for (var i0 = 0; i0 < height; i0 += 4) {
  35137. for (var j = 0; j < width; j++) {
  35138. var index = i0 * width + j;
  35139. for (var i1 = 0; i1 < 4; i1++, index += width) {
  35140. var i = i0 + i1;
  35141. if (i >= height) {
  35142. break;
  35143. }
  35144. // clear processed flag first
  35145. processingFlags[index] &= processedInverseMask;
  35146. if (coefficentsMagnitude[index] ||
  35147. !neighborsSignificance[index]) {
  35148. continue;
  35149. }
  35150. var contextLabel = labels[neighborsSignificance[index]];
  35151. var decision = decoder.readBit(contexts, contextLabel);
  35152. if (decision) {
  35153. var sign = this.decodeSignBit(i, j, index);
  35154. coefficentsSign[index] = sign;
  35155. coefficentsMagnitude[index] = 1;
  35156. this.setNeighborsSignificance(i, j, index);
  35157. processingFlags[index] |= firstMagnitudeBitMask;
  35158. }
  35159. bitsDecoded[index]++;
  35160. processingFlags[index] |= processedMask;
  35161. }
  35162. }
  35163. }
  35164. },
  35165. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  35166. var width = this.width, height = this.height;
  35167. var coefficentsMagnitude = this.coefficentsMagnitude;
  35168. var coefficentsSign = this.coefficentsSign;
  35169. var contribution, sign0, sign1, significance1;
  35170. var contextLabel, decoded;
  35171. // calculate horizontal contribution
  35172. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  35173. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  35174. sign1 = coefficentsSign[index + 1];
  35175. if (significance1) {
  35176. sign0 = coefficentsSign[index - 1];
  35177. contribution = 1 - sign1 - sign0;
  35178. } else {
  35179. contribution = 1 - sign1 - sign1;
  35180. }
  35181. } else if (significance1) {
  35182. sign0 = coefficentsSign[index - 1];
  35183. contribution = 1 - sign0 - sign0;
  35184. } else {
  35185. contribution = 0;
  35186. }
  35187. var horizontalContribution = 3 * contribution;
  35188. // calculate vertical contribution and combine with the horizontal
  35189. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  35190. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  35191. sign1 = coefficentsSign[index + width];
  35192. if (significance1) {
  35193. sign0 = coefficentsSign[index - width];
  35194. contribution = 1 - sign1 - sign0 + horizontalContribution;
  35195. } else {
  35196. contribution = 1 - sign1 - sign1 + horizontalContribution;
  35197. }
  35198. } else if (significance1) {
  35199. sign0 = coefficentsSign[index - width];
  35200. contribution = 1 - sign0 - sign0 + horizontalContribution;
  35201. } else {
  35202. contribution = horizontalContribution;
  35203. }
  35204. if (contribution >= 0) {
  35205. contextLabel = 9 + contribution;
  35206. decoded = this.decoder.readBit(this.contexts, contextLabel);
  35207. } else {
  35208. contextLabel = 9 - contribution;
  35209. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  35210. }
  35211. return decoded;
  35212. },
  35213. runMagnitudeRefinementPass:
  35214. function BitModel_runMagnitudeRefinementPass() {
  35215. var decoder = this.decoder;
  35216. var width = this.width, height = this.height;
  35217. var coefficentsMagnitude = this.coefficentsMagnitude;
  35218. var neighborsSignificance = this.neighborsSignificance;
  35219. var contexts = this.contexts;
  35220. var bitsDecoded = this.bitsDecoded;
  35221. var processingFlags = this.processingFlags;
  35222. var processedMask = 1;
  35223. var firstMagnitudeBitMask = 2;
  35224. var length = width * height;
  35225. var width4 = width * 4;
  35226. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  35227. indexNext = Math.min(length, index0 + width4);
  35228. for (var j = 0; j < width; j++) {
  35229. for (var index = index0 + j; index < indexNext; index += width) {
  35230. // significant but not those that have just become
  35231. if (!coefficentsMagnitude[index] ||
  35232. (processingFlags[index] & processedMask) !== 0) {
  35233. continue;
  35234. }
  35235. var contextLabel = 16;
  35236. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  35237. processingFlags[index] ^= firstMagnitudeBitMask;
  35238. // first refinement
  35239. var significance = neighborsSignificance[index] & 127;
  35240. contextLabel = significance === 0 ? 15 : 14;
  35241. }
  35242. var bit = decoder.readBit(contexts, contextLabel);
  35243. coefficentsMagnitude[index] =
  35244. (coefficentsMagnitude[index] << 1) | bit;
  35245. bitsDecoded[index]++;
  35246. processingFlags[index] |= processedMask;
  35247. }
  35248. }
  35249. }
  35250. },
  35251. runCleanupPass: function BitModel_runCleanupPass() {
  35252. var decoder = this.decoder;
  35253. var width = this.width, height = this.height;
  35254. var neighborsSignificance = this.neighborsSignificance;
  35255. var coefficentsMagnitude = this.coefficentsMagnitude;
  35256. var coefficentsSign = this.coefficentsSign;
  35257. var contexts = this.contexts;
  35258. var labels = this.contextLabelTable;
  35259. var bitsDecoded = this.bitsDecoded;
  35260. var processingFlags = this.processingFlags;
  35261. var processedMask = 1;
  35262. var firstMagnitudeBitMask = 2;
  35263. var oneRowDown = width;
  35264. var twoRowsDown = width * 2;
  35265. var threeRowsDown = width * 3;
  35266. var iNext;
  35267. for (var i0 = 0; i0 < height; i0 = iNext) {
  35268. iNext = Math.min(i0 + 4, height);
  35269. var indexBase = i0 * width;
  35270. var checkAllEmpty = i0 + 3 < height;
  35271. for (var j = 0; j < width; j++) {
  35272. var index0 = indexBase + j;
  35273. // using the property: labels[neighborsSignificance[index]] === 0
  35274. // when neighborsSignificance[index] === 0
  35275. var allEmpty = (checkAllEmpty &&
  35276. processingFlags[index0] === 0 &&
  35277. processingFlags[index0 + oneRowDown] === 0 &&
  35278. processingFlags[index0 + twoRowsDown] === 0 &&
  35279. processingFlags[index0 + threeRowsDown] === 0 &&
  35280. neighborsSignificance[index0] === 0 &&
  35281. neighborsSignificance[index0 + oneRowDown] === 0 &&
  35282. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  35283. neighborsSignificance[index0 + threeRowsDown] === 0);
  35284. var i1 = 0, index = index0;
  35285. var i = i0, sign;
  35286. if (allEmpty) {
  35287. var hasSignificantCoefficent =
  35288. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  35289. if (!hasSignificantCoefficent) {
  35290. bitsDecoded[index0]++;
  35291. bitsDecoded[index0 + oneRowDown]++;
  35292. bitsDecoded[index0 + twoRowsDown]++;
  35293. bitsDecoded[index0 + threeRowsDown]++;
  35294. continue; // next column
  35295. }
  35296. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35297. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35298. if (i1 !== 0) {
  35299. i = i0 + i1;
  35300. index += i1 * width;
  35301. }
  35302. sign = this.decodeSignBit(i, j, index);
  35303. coefficentsSign[index] = sign;
  35304. coefficentsMagnitude[index] = 1;
  35305. this.setNeighborsSignificance(i, j, index);
  35306. processingFlags[index] |= firstMagnitudeBitMask;
  35307. index = index0;
  35308. for (var i2 = i0; i2 <= i; i2++, index += width) {
  35309. bitsDecoded[index]++;
  35310. }
  35311. i1++;
  35312. }
  35313. for (i = i0 + i1; i < iNext; i++, index += width) {
  35314. if (coefficentsMagnitude[index] ||
  35315. (processingFlags[index] & processedMask) !== 0) {
  35316. continue;
  35317. }
  35318. var contextLabel = labels[neighborsSignificance[index]];
  35319. var decision = decoder.readBit(contexts, contextLabel);
  35320. if (decision === 1) {
  35321. sign = this.decodeSignBit(i, j, index);
  35322. coefficentsSign[index] = sign;
  35323. coefficentsMagnitude[index] = 1;
  35324. this.setNeighborsSignificance(i, j, index);
  35325. processingFlags[index] |= firstMagnitudeBitMask;
  35326. }
  35327. bitsDecoded[index]++;
  35328. }
  35329. }
  35330. }
  35331. },
  35332. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  35333. var decoder = this.decoder;
  35334. var contexts = this.contexts;
  35335. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  35336. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  35337. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  35338. decoder.readBit(contexts, UNIFORM_CONTEXT);
  35339. if (symbol !== 0xA) {
  35340. throw new Error('JPX Error: Invalid segmentation symbol');
  35341. }
  35342. }
  35343. };
  35344. return BitModel;
  35345. })();
  35346. // Section F, Discrete wavelet transformation
  35347. var Transform = (function TransformClosure() {
  35348. function Transform() {}
  35349. Transform.prototype.calculate =
  35350. function transformCalculate(subbands, u0, v0) {
  35351. var ll = subbands[0];
  35352. for (var i = 1, ii = subbands.length; i < ii; i++) {
  35353. ll = this.iterate(ll, subbands[i], u0, v0);
  35354. }
  35355. return ll;
  35356. };
  35357. Transform.prototype.extend = function extend(buffer, offset, size) {
  35358. // Section F.3.7 extending... using max extension of 4
  35359. var i1 = offset - 1, j1 = offset + 1;
  35360. var i2 = offset + size - 2, j2 = offset + size;
  35361. buffer[i1--] = buffer[j1++];
  35362. buffer[j2++] = buffer[i2--];
  35363. buffer[i1--] = buffer[j1++];
  35364. buffer[j2++] = buffer[i2--];
  35365. buffer[i1--] = buffer[j1++];
  35366. buffer[j2++] = buffer[i2--];
  35367. buffer[i1] = buffer[j1];
  35368. buffer[j2] = buffer[i2];
  35369. };
  35370. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  35371. u0, v0) {
  35372. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  35373. var width = hl_lh_hh.width;
  35374. var height = hl_lh_hh.height;
  35375. var items = hl_lh_hh.items;
  35376. var i, j, k, l, u, v;
  35377. // Interleave LL according to Section F.3.3
  35378. for (k = 0, i = 0; i < llHeight; i++) {
  35379. l = i * 2 * width;
  35380. for (j = 0; j < llWidth; j++, k++, l += 2) {
  35381. items[l] = llItems[k];
  35382. }
  35383. }
  35384. // The LL band is not needed anymore.
  35385. llItems = ll.items = null;
  35386. var bufferPadding = 4;
  35387. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  35388. // Section F.3.4 HOR_SR
  35389. if (width === 1) {
  35390. // if width = 1, when u0 even keep items as is, when odd divide by 2
  35391. if ((u0 & 1) !== 0) {
  35392. for (v = 0, k = 0; v < height; v++, k += width) {
  35393. items[k] *= 0.5;
  35394. }
  35395. }
  35396. } else {
  35397. for (v = 0, k = 0; v < height; v++, k += width) {
  35398. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  35399. this.extend(rowBuffer, bufferPadding, width);
  35400. this.filter(rowBuffer, bufferPadding, width);
  35401. items.set(
  35402. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  35403. k);
  35404. }
  35405. }
  35406. // Accesses to the items array can take long, because it may not fit into
  35407. // CPU cache and has to be fetched from main memory. Since subsequent
  35408. // accesses to the items array are not local when reading columns, we
  35409. // have a cache miss every time. To reduce cache misses, get up to
  35410. // 'numBuffers' items at a time and store them into the individual
  35411. // buffers. The colBuffers should be small enough to fit into CPU cache.
  35412. var numBuffers = 16;
  35413. var colBuffers = [];
  35414. for (i = 0; i < numBuffers; i++) {
  35415. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  35416. }
  35417. var b, currentBuffer = 0;
  35418. ll = bufferPadding + height;
  35419. // Section F.3.5 VER_SR
  35420. if (height === 1) {
  35421. // if height = 1, when v0 even keep items as is, when odd divide by 2
  35422. if ((v0 & 1) !== 0) {
  35423. for (u = 0; u < width; u++) {
  35424. items[u] *= 0.5;
  35425. }
  35426. }
  35427. } else {
  35428. for (u = 0; u < width; u++) {
  35429. // if we ran out of buffers, copy several image columns at once
  35430. if (currentBuffer === 0) {
  35431. numBuffers = Math.min(width - u, numBuffers);
  35432. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  35433. for (b = 0; b < numBuffers; b++) {
  35434. colBuffers[b][l] = items[k + b];
  35435. }
  35436. }
  35437. currentBuffer = numBuffers;
  35438. }
  35439. currentBuffer--;
  35440. var buffer = colBuffers[currentBuffer];
  35441. this.extend(buffer, bufferPadding, height);
  35442. this.filter(buffer, bufferPadding, height);
  35443. // If this is last buffer in this group of buffers, flush all buffers.
  35444. if (currentBuffer === 0) {
  35445. k = u - numBuffers + 1;
  35446. for (l = bufferPadding; l < ll; k += width, l++) {
  35447. for (b = 0; b < numBuffers; b++) {
  35448. items[k + b] = colBuffers[b][l];
  35449. }
  35450. }
  35451. }
  35452. }
  35453. }
  35454. return {
  35455. width: width,
  35456. height: height,
  35457. items: items
  35458. };
  35459. };
  35460. return Transform;
  35461. })();
  35462. // Section 3.8.2 Irreversible 9-7 filter
  35463. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  35464. function IrreversibleTransform() {
  35465. Transform.call(this);
  35466. }
  35467. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  35468. IrreversibleTransform.prototype.filter =
  35469. function irreversibleTransformFilter(x, offset, length) {
  35470. var len = length >> 1;
  35471. offset = offset | 0;
  35472. var j, n, current, next;
  35473. var alpha = -1.586134342059924;
  35474. var beta = -0.052980118572961;
  35475. var gamma = 0.882911075530934;
  35476. var delta = 0.443506852043971;
  35477. var K = 1.230174104914001;
  35478. var K_ = 1 / K;
  35479. // step 1 is combined with step 3
  35480. // step 2
  35481. j = offset - 3;
  35482. for (n = len + 4; n--; j += 2) {
  35483. x[j] *= K_;
  35484. }
  35485. // step 1 & 3
  35486. j = offset - 2;
  35487. current = delta * x[j -1];
  35488. for (n = len + 3; n--; j += 2) {
  35489. next = delta * x[j + 1];
  35490. x[j] = K * x[j] - current - next;
  35491. if (n--) {
  35492. j += 2;
  35493. current = delta * x[j + 1];
  35494. x[j] = K * x[j] - current - next;
  35495. } else {
  35496. break;
  35497. }
  35498. }
  35499. // step 4
  35500. j = offset - 1;
  35501. current = gamma * x[j - 1];
  35502. for (n = len + 2; n--; j += 2) {
  35503. next = gamma * x[j + 1];
  35504. x[j] -= current + next;
  35505. if (n--) {
  35506. j += 2;
  35507. current = gamma * x[j + 1];
  35508. x[j] -= current + next;
  35509. } else {
  35510. break;
  35511. }
  35512. }
  35513. // step 5
  35514. j = offset;
  35515. current = beta * x[j - 1];
  35516. for (n = len + 1; n--; j += 2) {
  35517. next = beta * x[j + 1];
  35518. x[j] -= current + next;
  35519. if (n--) {
  35520. j += 2;
  35521. current = beta * x[j + 1];
  35522. x[j] -= current + next;
  35523. } else {
  35524. break;
  35525. }
  35526. }
  35527. // step 6
  35528. if (len !== 0) {
  35529. j = offset + 1;
  35530. current = alpha * x[j - 1];
  35531. for (n = len; n--; j += 2) {
  35532. next = alpha * x[j + 1];
  35533. x[j] -= current + next;
  35534. if (n--) {
  35535. j += 2;
  35536. current = alpha * x[j + 1];
  35537. x[j] -= current + next;
  35538. } else {
  35539. break;
  35540. }
  35541. }
  35542. }
  35543. };
  35544. return IrreversibleTransform;
  35545. })();
  35546. // Section 3.8.1 Reversible 5-3 filter
  35547. var ReversibleTransform = (function ReversibleTransformClosure() {
  35548. function ReversibleTransform() {
  35549. Transform.call(this);
  35550. }
  35551. ReversibleTransform.prototype = Object.create(Transform.prototype);
  35552. ReversibleTransform.prototype.filter =
  35553. function reversibleTransformFilter(x, offset, length) {
  35554. var len = length >> 1;
  35555. offset = offset | 0;
  35556. var j, n;
  35557. for (j = offset, n = len + 1; n--; j += 2) {
  35558. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  35559. }
  35560. for (j = offset + 1, n = len; n--; j += 2) {
  35561. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  35562. }
  35563. };
  35564. return ReversibleTransform;
  35565. })();
  35566. return JpxImage;
  35567. })();
  35568. var Jbig2Image = (function Jbig2ImageClosure() {
  35569. // Utility data structures
  35570. function ContextCache() {}
  35571. ContextCache.prototype = {
  35572. getContexts: function(id) {
  35573. if (id in this) {
  35574. return this[id];
  35575. }
  35576. return (this[id] = new Int8Array(1 << 16));
  35577. }
  35578. };
  35579. function DecodingContext(data, start, end) {
  35580. this.data = data;
  35581. this.start = start;
  35582. this.end = end;
  35583. }
  35584. DecodingContext.prototype = {
  35585. get decoder() {
  35586. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  35587. return shadow(this, 'decoder', decoder);
  35588. },
  35589. get contextCache() {
  35590. var cache = new ContextCache();
  35591. return shadow(this, 'contextCache', cache);
  35592. }
  35593. };
  35594. // Annex A. Arithmetic Integer Decoding Procedure
  35595. // A.2 Procedure for decoding values
  35596. function decodeInteger(contextCache, procedure, decoder) {
  35597. var contexts = contextCache.getContexts(procedure);
  35598. var prev = 1;
  35599. function readBits(length) {
  35600. var v = 0;
  35601. for (var i = 0; i < length; i++) {
  35602. var bit = decoder.readBit(contexts, prev);
  35603. prev = (prev < 256 ? (prev << 1) | bit :
  35604. (((prev << 1) | bit) & 511) | 256);
  35605. v = (v << 1) | bit;
  35606. }
  35607. return v >>> 0;
  35608. }
  35609. var sign = readBits(1);
  35610. var value = readBits(1) ?
  35611. (readBits(1) ?
  35612. (readBits(1) ?
  35613. (readBits(1) ?
  35614. (readBits(1) ?
  35615. (readBits(32) + 4436) :
  35616. readBits(12) + 340) :
  35617. readBits(8) + 84) :
  35618. readBits(6) + 20) :
  35619. readBits(4) + 4) :
  35620. readBits(2);
  35621. return (sign === 0 ? value : (value > 0 ? -value : null));
  35622. }
  35623. // A.3 The IAID decoding procedure
  35624. function decodeIAID(contextCache, decoder, codeLength) {
  35625. var contexts = contextCache.getContexts('IAID');
  35626. var prev = 1;
  35627. for (var i = 0; i < codeLength; i++) {
  35628. var bit = decoder.readBit(contexts, prev);
  35629. prev = (prev << 1) | bit;
  35630. }
  35631. if (codeLength < 31) {
  35632. return prev & ((1 << codeLength) - 1);
  35633. }
  35634. return prev & 0x7FFFFFFF;
  35635. }
  35636. // 7.3 Segment types
  35637. var SegmentTypes = [
  35638. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  35639. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  35640. null, null, null, null, null, 'patternDictionary', null, null, null,
  35641. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  35642. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  35643. null, null, null, null, null, 'IntermediateGenericRegion', null,
  35644. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  35645. 'IntermediateGenericRefinementRegion', null,
  35646. 'ImmediateGenericRefinementRegion',
  35647. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  35648. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  35649. 'Tables', null, null, null, null, null, null, null, null,
  35650. 'Extension'
  35651. ];
  35652. var CodingTemplates = [
  35653. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35654. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  35655. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35656. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  35657. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  35658. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  35659. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  35660. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  35661. {x: -1, y: 0}],
  35662. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  35663. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  35664. ];
  35665. var RefinementTemplates = [
  35666. {
  35667. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35668. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  35669. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  35670. },
  35671. {
  35672. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  35673. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  35674. {x: 0, y: 1}, {x: 1, y: 1}]
  35675. }
  35676. ];
  35677. // See 6.2.5.7 Decoding the bitmap.
  35678. var ReusedContexts = [
  35679. 0x9B25, // 10011 0110010 0101
  35680. 0x0795, // 0011 110010 101
  35681. 0x00E5, // 001 11001 01
  35682. 0x0195 // 011001 0101
  35683. ];
  35684. var RefinementReusedContexts = [
  35685. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  35686. 0x0008 // '0000' + '001000'
  35687. ];
  35688. function decodeBitmapTemplate0(width, height, decodingContext) {
  35689. var decoder = decodingContext.decoder;
  35690. var contexts = decodingContext.contextCache.getContexts('GB');
  35691. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  35692. // ...ooooo....
  35693. // ..ooooooo... Context template for current pixel (X)
  35694. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  35695. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  35696. for (i = 0; i < height; i++) {
  35697. row = bitmap[i] = new Uint8Array(width);
  35698. row1 = (i < 1) ? row : bitmap[i - 1];
  35699. row2 = (i < 2) ? row : bitmap[i - 2];
  35700. // At the beginning of each row:
  35701. // Fill contextLabel with pixels that are above/right of (X)
  35702. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  35703. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  35704. (row1[3] << 4);
  35705. for (j = 0; j < width; j++) {
  35706. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  35707. // At each pixel: Clear contextLabel pixels that are shifted
  35708. // out of the context, then add new ones.
  35709. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  35710. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  35711. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  35712. }
  35713. }
  35714. return bitmap;
  35715. }
  35716. // 6.2 Generic Region Decoding Procedure
  35717. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  35718. decodingContext) {
  35719. if (mmr) {
  35720. error('JBIG2 error: MMR encoding is not supported');
  35721. }
  35722. // Use optimized version for the most common case
  35723. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  35724. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  35725. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  35726. return decodeBitmapTemplate0(width, height, decodingContext);
  35727. }
  35728. var useskip = !!skip;
  35729. var template = CodingTemplates[templateIndex].concat(at);
  35730. // Sorting is non-standard, and it is not required. But sorting increases
  35731. // the number of template bits that can be reused from the previous
  35732. // contextLabel in the main loop.
  35733. template.sort(function (a, b) {
  35734. return (a.y - b.y) || (a.x - b.x);
  35735. });
  35736. var templateLength = template.length;
  35737. var templateX = new Int8Array(templateLength);
  35738. var templateY = new Int8Array(templateLength);
  35739. var changingTemplateEntries = [];
  35740. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  35741. var c, k;
  35742. for (k = 0; k < templateLength; k++) {
  35743. templateX[k] = template[k].x;
  35744. templateY[k] = template[k].y;
  35745. minX = Math.min(minX, template[k].x);
  35746. maxX = Math.max(maxX, template[k].x);
  35747. minY = Math.min(minY, template[k].y);
  35748. // Check if the template pixel appears in two consecutive context labels,
  35749. // so it can be reused. Otherwise, we add it to the list of changing
  35750. // template entries.
  35751. if (k < templateLength - 1 &&
  35752. template[k].y === template[k + 1].y &&
  35753. template[k].x === template[k + 1].x - 1) {
  35754. reuseMask |= 1 << (templateLength - 1 - k);
  35755. } else {
  35756. changingTemplateEntries.push(k);
  35757. }
  35758. }
  35759. var changingEntriesLength = changingTemplateEntries.length;
  35760. var changingTemplateX = new Int8Array(changingEntriesLength);
  35761. var changingTemplateY = new Int8Array(changingEntriesLength);
  35762. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  35763. for (c = 0; c < changingEntriesLength; c++) {
  35764. k = changingTemplateEntries[c];
  35765. changingTemplateX[c] = template[k].x;
  35766. changingTemplateY[c] = template[k].y;
  35767. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  35768. }
  35769. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  35770. var sbb_left = -minX;
  35771. var sbb_top = -minY;
  35772. var sbb_right = width - maxX;
  35773. var pseudoPixelContext = ReusedContexts[templateIndex];
  35774. var row = new Uint8Array(width);
  35775. var bitmap = [];
  35776. var decoder = decodingContext.decoder;
  35777. var contexts = decodingContext.contextCache.getContexts('GB');
  35778. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  35779. for (var i = 0; i < height; i++) {
  35780. if (prediction) {
  35781. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35782. ltp ^= sltp;
  35783. if (ltp) {
  35784. bitmap.push(row); // duplicate previous row
  35785. continue;
  35786. }
  35787. }
  35788. row = new Uint8Array(row);
  35789. bitmap.push(row);
  35790. for (j = 0; j < width; j++) {
  35791. if (useskip && skip[i][j]) {
  35792. row[j] = 0;
  35793. continue;
  35794. }
  35795. // Are we in the middle of a scanline, so we can reuse contextLabel
  35796. // bits?
  35797. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  35798. // If yes, we can just shift the bits that are reusable and only
  35799. // fetch the remaining ones.
  35800. contextLabel = (contextLabel << 1) & reuseMask;
  35801. for (k = 0; k < changingEntriesLength; k++) {
  35802. i0 = i + changingTemplateY[k];
  35803. j0 = j + changingTemplateX[k];
  35804. bit = bitmap[i0][j0];
  35805. if (bit) {
  35806. bit = changingTemplateBit[k];
  35807. contextLabel |= bit;
  35808. }
  35809. }
  35810. } else {
  35811. // compute the contextLabel from scratch
  35812. contextLabel = 0;
  35813. shift = templateLength - 1;
  35814. for (k = 0; k < templateLength; k++, shift--) {
  35815. j0 = j + templateX[k];
  35816. if (j0 >= 0 && j0 < width) {
  35817. i0 = i + templateY[k];
  35818. if (i0 >= 0) {
  35819. bit = bitmap[i0][j0];
  35820. if (bit) {
  35821. contextLabel |= bit << shift;
  35822. }
  35823. }
  35824. }
  35825. }
  35826. }
  35827. var pixel = decoder.readBit(contexts, contextLabel);
  35828. row[j] = pixel;
  35829. }
  35830. }
  35831. return bitmap;
  35832. }
  35833. // 6.3.2 Generic Refinement Region Decoding Procedure
  35834. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  35835. offsetX, offsetY, prediction, at,
  35836. decodingContext) {
  35837. var codingTemplate = RefinementTemplates[templateIndex].coding;
  35838. if (templateIndex === 0) {
  35839. codingTemplate = codingTemplate.concat([at[0]]);
  35840. }
  35841. var codingTemplateLength = codingTemplate.length;
  35842. var codingTemplateX = new Int32Array(codingTemplateLength);
  35843. var codingTemplateY = new Int32Array(codingTemplateLength);
  35844. var k;
  35845. for (k = 0; k < codingTemplateLength; k++) {
  35846. codingTemplateX[k] = codingTemplate[k].x;
  35847. codingTemplateY[k] = codingTemplate[k].y;
  35848. }
  35849. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  35850. if (templateIndex === 0) {
  35851. referenceTemplate = referenceTemplate.concat([at[1]]);
  35852. }
  35853. var referenceTemplateLength = referenceTemplate.length;
  35854. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  35855. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  35856. for (k = 0; k < referenceTemplateLength; k++) {
  35857. referenceTemplateX[k] = referenceTemplate[k].x;
  35858. referenceTemplateY[k] = referenceTemplate[k].y;
  35859. }
  35860. var referenceWidth = referenceBitmap[0].length;
  35861. var referenceHeight = referenceBitmap.length;
  35862. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  35863. var bitmap = [];
  35864. var decoder = decodingContext.decoder;
  35865. var contexts = decodingContext.contextCache.getContexts('GR');
  35866. var ltp = 0;
  35867. for (var i = 0; i < height; i++) {
  35868. if (prediction) {
  35869. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  35870. ltp ^= sltp;
  35871. if (ltp) {
  35872. error('JBIG2 error: prediction is not supported');
  35873. }
  35874. }
  35875. var row = new Uint8Array(width);
  35876. bitmap.push(row);
  35877. for (var j = 0; j < width; j++) {
  35878. var i0, j0;
  35879. var contextLabel = 0;
  35880. for (k = 0; k < codingTemplateLength; k++) {
  35881. i0 = i + codingTemplateY[k];
  35882. j0 = j + codingTemplateX[k];
  35883. if (i0 < 0 || j0 < 0 || j0 >= width) {
  35884. contextLabel <<= 1; // out of bound pixel
  35885. } else {
  35886. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  35887. }
  35888. }
  35889. for (k = 0; k < referenceTemplateLength; k++) {
  35890. i0 = i + referenceTemplateY[k] + offsetY;
  35891. j0 = j + referenceTemplateX[k] + offsetX;
  35892. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  35893. j0 >= referenceWidth) {
  35894. contextLabel <<= 1; // out of bound pixel
  35895. } else {
  35896. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  35897. }
  35898. }
  35899. var pixel = decoder.readBit(contexts, contextLabel);
  35900. row[j] = pixel;
  35901. }
  35902. }
  35903. return bitmap;
  35904. }
  35905. // 6.5.5 Decoding the symbol dictionary
  35906. function decodeSymbolDictionary(huffman, refinement, symbols,
  35907. numberOfNewSymbols, numberOfExportedSymbols,
  35908. huffmanTables, templateIndex, at,
  35909. refinementTemplateIndex, refinementAt,
  35910. decodingContext) {
  35911. if (huffman) {
  35912. error('JBIG2 error: huffman is not supported');
  35913. }
  35914. var newSymbols = [];
  35915. var currentHeight = 0;
  35916. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  35917. var decoder = decodingContext.decoder;
  35918. var contextCache = decodingContext.contextCache;
  35919. while (newSymbols.length < numberOfNewSymbols) {
  35920. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  35921. currentHeight += deltaHeight;
  35922. var currentWidth = 0;
  35923. var totalWidth = 0;
  35924. while (true) {
  35925. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  35926. if (deltaWidth === null) {
  35927. break; // OOB
  35928. }
  35929. currentWidth += deltaWidth;
  35930. totalWidth += currentWidth;
  35931. var bitmap;
  35932. if (refinement) {
  35933. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  35934. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  35935. if (numberOfInstances > 1) {
  35936. bitmap = decodeTextRegion(huffman, refinement,
  35937. currentWidth, currentHeight, 0,
  35938. numberOfInstances, 1, //strip size
  35939. symbols.concat(newSymbols),
  35940. symbolCodeLength,
  35941. 0, //transposed
  35942. 0, //ds offset
  35943. 1, //top left 7.4.3.1.1
  35944. 0, //OR operator
  35945. huffmanTables,
  35946. refinementTemplateIndex, refinementAt,
  35947. decodingContext);
  35948. } else {
  35949. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  35950. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  35951. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  35952. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  35953. newSymbols[symbolId - symbols.length]);
  35954. bitmap = decodeRefinement(currentWidth, currentHeight,
  35955. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  35956. decodingContext);
  35957. }
  35958. } else {
  35959. // 6.5.8.1 Direct-coded symbol bitmap
  35960. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  35961. templateIndex, false, null, at, decodingContext);
  35962. }
  35963. newSymbols.push(bitmap);
  35964. }
  35965. }
  35966. // 6.5.10 Exported symbols
  35967. var exportedSymbols = [];
  35968. var flags = [], currentFlag = false;
  35969. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  35970. while (flags.length < totalSymbolsLength) {
  35971. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  35972. while (runLength--) {
  35973. flags.push(currentFlag);
  35974. }
  35975. currentFlag = !currentFlag;
  35976. }
  35977. for (var i = 0, ii = symbols.length; i < ii; i++) {
  35978. if (flags[i]) {
  35979. exportedSymbols.push(symbols[i]);
  35980. }
  35981. }
  35982. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  35983. if (flags[i]) {
  35984. exportedSymbols.push(newSymbols[j]);
  35985. }
  35986. }
  35987. return exportedSymbols;
  35988. }
  35989. function decodeTextRegion(huffman, refinement, width, height,
  35990. defaultPixelValue, numberOfSymbolInstances,
  35991. stripSize, inputSymbols, symbolCodeLength,
  35992. transposed, dsOffset, referenceCorner,
  35993. combinationOperator, huffmanTables,
  35994. refinementTemplateIndex, refinementAt,
  35995. decodingContext) {
  35996. if (huffman) {
  35997. error('JBIG2 error: huffman is not supported');
  35998. }
  35999. // Prepare bitmap
  36000. var bitmap = [];
  36001. var i, row;
  36002. for (i = 0; i < height; i++) {
  36003. row = new Uint8Array(width);
  36004. if (defaultPixelValue) {
  36005. for (var j = 0; j < width; j++) {
  36006. row[j] = defaultPixelValue;
  36007. }
  36008. }
  36009. bitmap.push(row);
  36010. }
  36011. var decoder = decodingContext.decoder;
  36012. var contextCache = decodingContext.contextCache;
  36013. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36014. var firstS = 0;
  36015. i = 0;
  36016. while (i < numberOfSymbolInstances) {
  36017. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  36018. stripT += deltaT;
  36019. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  36020. firstS += deltaFirstS;
  36021. var currentS = firstS;
  36022. do {
  36023. var currentT = (stripSize === 1 ? 0 :
  36024. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  36025. var t = stripSize * stripT + currentT;
  36026. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  36027. var applyRefinement = (refinement &&
  36028. decodeInteger(contextCache, 'IARI', decoder));
  36029. var symbolBitmap = inputSymbols[symbolId];
  36030. var symbolWidth = symbolBitmap[0].length;
  36031. var symbolHeight = symbolBitmap.length;
  36032. if (applyRefinement) {
  36033. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  36034. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  36035. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  36036. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  36037. symbolWidth += rdw;
  36038. symbolHeight += rdh;
  36039. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  36040. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  36041. (rdh >> 1) + rdy, false, refinementAt,
  36042. decodingContext);
  36043. }
  36044. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  36045. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  36046. var s2, t2, symbolRow;
  36047. if (transposed) {
  36048. // Place Symbol Bitmap from T1,S1
  36049. for (s2 = 0; s2 < symbolHeight; s2++) {
  36050. row = bitmap[offsetS + s2];
  36051. if (!row) {
  36052. continue;
  36053. }
  36054. symbolRow = symbolBitmap[s2];
  36055. // To ignore Parts of Symbol bitmap which goes
  36056. // outside bitmap region
  36057. var maxWidth = Math.min(width - offsetT, symbolWidth);
  36058. switch (combinationOperator) {
  36059. case 0: // OR
  36060. for (t2 = 0; t2 < maxWidth; t2++) {
  36061. row[offsetT + t2] |= symbolRow[t2];
  36062. }
  36063. break;
  36064. case 2: // XOR
  36065. for (t2 = 0; t2 < maxWidth; t2++) {
  36066. row[offsetT + t2] ^= symbolRow[t2];
  36067. }
  36068. break;
  36069. default:
  36070. error('JBIG2 error: operator ' + combinationOperator +
  36071. ' is not supported');
  36072. }
  36073. }
  36074. currentS += symbolHeight - 1;
  36075. } else {
  36076. for (t2 = 0; t2 < symbolHeight; t2++) {
  36077. row = bitmap[offsetT + t2];
  36078. if (!row) {
  36079. continue;
  36080. }
  36081. symbolRow = symbolBitmap[t2];
  36082. switch (combinationOperator) {
  36083. case 0: // OR
  36084. for (s2 = 0; s2 < symbolWidth; s2++) {
  36085. row[offsetS + s2] |= symbolRow[s2];
  36086. }
  36087. break;
  36088. case 2: // XOR
  36089. for (s2 = 0; s2 < symbolWidth; s2++) {
  36090. row[offsetS + s2] ^= symbolRow[s2];
  36091. }
  36092. break;
  36093. default:
  36094. error('JBIG2 error: operator ' + combinationOperator +
  36095. ' is not supported');
  36096. }
  36097. }
  36098. currentS += symbolWidth - 1;
  36099. }
  36100. i++;
  36101. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  36102. if (deltaS === null) {
  36103. break; // OOB
  36104. }
  36105. currentS += deltaS + dsOffset;
  36106. } while (true);
  36107. }
  36108. return bitmap;
  36109. }
  36110. function readSegmentHeader(data, start) {
  36111. var segmentHeader = {};
  36112. segmentHeader.number = readUint32(data, start);
  36113. var flags = data[start + 4];
  36114. var segmentType = flags & 0x3F;
  36115. if (!SegmentTypes[segmentType]) {
  36116. error('JBIG2 error: invalid segment type: ' + segmentType);
  36117. }
  36118. segmentHeader.type = segmentType;
  36119. segmentHeader.typeName = SegmentTypes[segmentType];
  36120. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  36121. var pageAssociationFieldSize = !!(flags & 0x40);
  36122. var referredFlags = data[start + 5];
  36123. var referredToCount = (referredFlags >> 5) & 7;
  36124. var retainBits = [referredFlags & 31];
  36125. var position = start + 6;
  36126. if (referredFlags === 7) {
  36127. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  36128. position += 3;
  36129. var bytes = (referredToCount + 7) >> 3;
  36130. retainBits[0] = data[position++];
  36131. while (--bytes > 0) {
  36132. retainBits.push(data[position++]);
  36133. }
  36134. } else if (referredFlags === 5 || referredFlags === 6) {
  36135. error('JBIG2 error: invalid referred-to flags');
  36136. }
  36137. segmentHeader.retainBits = retainBits;
  36138. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  36139. (segmentHeader.number <= 65536 ? 2 : 4));
  36140. var referredTo = [];
  36141. var i, ii;
  36142. for (i = 0; i < referredToCount; i++) {
  36143. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  36144. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  36145. readUint32(data, position)));
  36146. referredTo.push(number);
  36147. position += referredToSegmentNumberSize;
  36148. }
  36149. segmentHeader.referredTo = referredTo;
  36150. if (!pageAssociationFieldSize) {
  36151. segmentHeader.pageAssociation = data[position++];
  36152. } else {
  36153. segmentHeader.pageAssociation = readUint32(data, position);
  36154. position += 4;
  36155. }
  36156. segmentHeader.length = readUint32(data, position);
  36157. position += 4;
  36158. if (segmentHeader.length === 0xFFFFFFFF) {
  36159. // 7.2.7 Segment data length, unknown segment length
  36160. if (segmentType === 38) { // ImmediateGenericRegion
  36161. var genericRegionInfo = readRegionSegmentInformation(data, position);
  36162. var genericRegionSegmentFlags = data[position +
  36163. RegionSegmentInformationFieldLength];
  36164. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  36165. // searching for the segment end
  36166. var searchPatternLength = 6;
  36167. var searchPattern = new Uint8Array(searchPatternLength);
  36168. if (!genericRegionMmr) {
  36169. searchPattern[0] = 0xFF;
  36170. searchPattern[1] = 0xAC;
  36171. }
  36172. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  36173. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  36174. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  36175. searchPattern[5] = genericRegionInfo.height & 0xFF;
  36176. for (i = position, ii = data.length; i < ii; i++) {
  36177. var j = 0;
  36178. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  36179. j++;
  36180. }
  36181. if (j === searchPatternLength) {
  36182. segmentHeader.length = i + searchPatternLength;
  36183. break;
  36184. }
  36185. }
  36186. if (segmentHeader.length === 0xFFFFFFFF) {
  36187. error('JBIG2 error: segment end was not found');
  36188. }
  36189. } else {
  36190. error('JBIG2 error: invalid unknown segment length');
  36191. }
  36192. }
  36193. segmentHeader.headerEnd = position;
  36194. return segmentHeader;
  36195. }
  36196. function readSegments(header, data, start, end) {
  36197. var segments = [];
  36198. var position = start;
  36199. while (position < end) {
  36200. var segmentHeader = readSegmentHeader(data, position);
  36201. position = segmentHeader.headerEnd;
  36202. var segment = {
  36203. header: segmentHeader,
  36204. data: data
  36205. };
  36206. if (!header.randomAccess) {
  36207. segment.start = position;
  36208. position += segmentHeader.length;
  36209. segment.end = position;
  36210. }
  36211. segments.push(segment);
  36212. if (segmentHeader.type === 51) {
  36213. break; // end of file is found
  36214. }
  36215. }
  36216. if (header.randomAccess) {
  36217. for (var i = 0, ii = segments.length; i < ii; i++) {
  36218. segments[i].start = position;
  36219. position += segments[i].header.length;
  36220. segments[i].end = position;
  36221. }
  36222. }
  36223. return segments;
  36224. }
  36225. // 7.4.1 Region segment information field
  36226. function readRegionSegmentInformation(data, start) {
  36227. return {
  36228. width: readUint32(data, start),
  36229. height: readUint32(data, start + 4),
  36230. x: readUint32(data, start + 8),
  36231. y: readUint32(data, start + 12),
  36232. combinationOperator: data[start + 16] & 7
  36233. };
  36234. }
  36235. var RegionSegmentInformationFieldLength = 17;
  36236. function processSegment(segment, visitor) {
  36237. var header = segment.header;
  36238. var data = segment.data, position = segment.start, end = segment.end;
  36239. var args, at, i, atLength;
  36240. switch (header.type) {
  36241. case 0: // SymbolDictionary
  36242. // 7.4.2 Symbol dictionary segment syntax
  36243. var dictionary = {};
  36244. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  36245. dictionary.huffman = !!(dictionaryFlags & 1);
  36246. dictionary.refinement = !!(dictionaryFlags & 2);
  36247. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  36248. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  36249. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  36250. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  36251. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  36252. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  36253. dictionary.template = (dictionaryFlags >> 10) & 3;
  36254. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  36255. position += 2;
  36256. if (!dictionary.huffman) {
  36257. atLength = dictionary.template === 0 ? 4 : 1;
  36258. at = [];
  36259. for (i = 0; i < atLength; i++) {
  36260. at.push({
  36261. x: readInt8(data, position),
  36262. y: readInt8(data, position + 1)
  36263. });
  36264. position += 2;
  36265. }
  36266. dictionary.at = at;
  36267. }
  36268. if (dictionary.refinement && !dictionary.refinementTemplate) {
  36269. at = [];
  36270. for (i = 0; i < 2; i++) {
  36271. at.push({
  36272. x: readInt8(data, position),
  36273. y: readInt8(data, position + 1)
  36274. });
  36275. position += 2;
  36276. }
  36277. dictionary.refinementAt = at;
  36278. }
  36279. dictionary.numberOfExportedSymbols = readUint32(data, position);
  36280. position += 4;
  36281. dictionary.numberOfNewSymbols = readUint32(data, position);
  36282. position += 4;
  36283. args = [dictionary, header.number, header.referredTo,
  36284. data, position, end];
  36285. break;
  36286. case 6: // ImmediateTextRegion
  36287. case 7: // ImmediateLosslessTextRegion
  36288. var textRegion = {};
  36289. textRegion.info = readRegionSegmentInformation(data, position);
  36290. position += RegionSegmentInformationFieldLength;
  36291. var textRegionSegmentFlags = readUint16(data, position);
  36292. position += 2;
  36293. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  36294. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  36295. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  36296. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  36297. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  36298. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  36299. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  36300. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  36301. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  36302. if (textRegion.huffman) {
  36303. var textRegionHuffmanFlags = readUint16(data, position);
  36304. position += 2;
  36305. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  36306. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  36307. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  36308. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  36309. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  36310. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  36311. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  36312. textRegion.huffmanRefinementSizeSelector =
  36313. !!(textRegionHuffmanFlags & 14);
  36314. }
  36315. if (textRegion.refinement && !textRegion.refinementTemplate) {
  36316. at = [];
  36317. for (i = 0; i < 2; i++) {
  36318. at.push({
  36319. x: readInt8(data, position),
  36320. y: readInt8(data, position + 1)
  36321. });
  36322. position += 2;
  36323. }
  36324. textRegion.refinementAt = at;
  36325. }
  36326. textRegion.numberOfSymbolInstances = readUint32(data, position);
  36327. position += 4;
  36328. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  36329. if (textRegion.huffman) {
  36330. error('JBIG2 error: huffman is not supported');
  36331. }
  36332. args = [textRegion, header.referredTo, data, position, end];
  36333. break;
  36334. case 38: // ImmediateGenericRegion
  36335. case 39: // ImmediateLosslessGenericRegion
  36336. var genericRegion = {};
  36337. genericRegion.info = readRegionSegmentInformation(data, position);
  36338. position += RegionSegmentInformationFieldLength;
  36339. var genericRegionSegmentFlags = data[position++];
  36340. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  36341. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  36342. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  36343. if (!genericRegion.mmr) {
  36344. atLength = genericRegion.template === 0 ? 4 : 1;
  36345. at = [];
  36346. for (i = 0; i < atLength; i++) {
  36347. at.push({
  36348. x: readInt8(data, position),
  36349. y: readInt8(data, position + 1)
  36350. });
  36351. position += 2;
  36352. }
  36353. genericRegion.at = at;
  36354. }
  36355. args = [genericRegion, data, position, end];
  36356. break;
  36357. case 48: // PageInformation
  36358. var pageInfo = {
  36359. width: readUint32(data, position),
  36360. height: readUint32(data, position + 4),
  36361. resolutionX: readUint32(data, position + 8),
  36362. resolutionY: readUint32(data, position + 12)
  36363. };
  36364. if (pageInfo.height === 0xFFFFFFFF) {
  36365. delete pageInfo.height;
  36366. }
  36367. var pageSegmentFlags = data[position + 16];
  36368. var pageStripingInformatiom = readUint16(data, position + 17);
  36369. pageInfo.lossless = !!(pageSegmentFlags & 1);
  36370. pageInfo.refinement = !!(pageSegmentFlags & 2);
  36371. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  36372. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  36373. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  36374. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  36375. args = [pageInfo];
  36376. break;
  36377. case 49: // EndOfPage
  36378. break;
  36379. case 50: // EndOfStripe
  36380. break;
  36381. case 51: // EndOfFile
  36382. break;
  36383. case 62: // 7.4.15 defines 2 extension types which
  36384. // are comments and can be ignored.
  36385. break;
  36386. default:
  36387. error('JBIG2 error: segment type ' + header.typeName + '(' +
  36388. header.type + ') is not implemented');
  36389. }
  36390. var callbackName = 'on' + header.typeName;
  36391. if (callbackName in visitor) {
  36392. visitor[callbackName].apply(visitor, args);
  36393. }
  36394. }
  36395. function processSegments(segments, visitor) {
  36396. for (var i = 0, ii = segments.length; i < ii; i++) {
  36397. processSegment(segments[i], visitor);
  36398. }
  36399. }
  36400. function parseJbig2(data, start, end) {
  36401. var position = start;
  36402. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  36403. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  36404. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  36405. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  36406. error('JBIG2 error: invalid header');
  36407. }
  36408. var header = {};
  36409. position += 8;
  36410. var flags = data[position++];
  36411. header.randomAccess = !(flags & 1);
  36412. if (!(flags & 2)) {
  36413. header.numberOfPages = readUint32(data, position);
  36414. position += 4;
  36415. }
  36416. var segments = readSegments(header, data, position, end);
  36417. error('Not implemented');
  36418. // processSegments(segments, new SimpleSegmentVisitor());
  36419. }
  36420. function parseJbig2Chunks(chunks) {
  36421. var visitor = new SimpleSegmentVisitor();
  36422. for (var i = 0, ii = chunks.length; i < ii; i++) {
  36423. var chunk = chunks[i];
  36424. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  36425. processSegments(segments, visitor);
  36426. }
  36427. return visitor.buffer;
  36428. }
  36429. function SimpleSegmentVisitor() {}
  36430. SimpleSegmentVisitor.prototype = {
  36431. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  36432. this.currentPageInfo = info;
  36433. var rowSize = (info.width + 7) >> 3;
  36434. var buffer = new Uint8Array(rowSize * info.height);
  36435. // The contents of ArrayBuffers are initialized to 0.
  36436. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  36437. if (info.defaultPixelValue) {
  36438. for (var i = 0, ii = buffer.length; i < ii; i++) {
  36439. buffer[i] = 0xFF;
  36440. }
  36441. }
  36442. this.buffer = buffer;
  36443. },
  36444. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  36445. var pageInfo = this.currentPageInfo;
  36446. var width = regionInfo.width, height = regionInfo.height;
  36447. var rowSize = (pageInfo.width + 7) >> 3;
  36448. var combinationOperator = pageInfo.combinationOperatorOverride ?
  36449. regionInfo.combinationOperator : pageInfo.combinationOperator;
  36450. var buffer = this.buffer;
  36451. var mask0 = 128 >> (regionInfo.x & 7);
  36452. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  36453. var i, j, mask, offset;
  36454. switch (combinationOperator) {
  36455. case 0: // OR
  36456. for (i = 0; i < height; i++) {
  36457. mask = mask0;
  36458. offset = offset0;
  36459. for (j = 0; j < width; j++) {
  36460. if (bitmap[i][j]) {
  36461. buffer[offset] |= mask;
  36462. }
  36463. mask >>= 1;
  36464. if (!mask) {
  36465. mask = 128;
  36466. offset++;
  36467. }
  36468. }
  36469. offset0 += rowSize;
  36470. }
  36471. break;
  36472. case 2: // XOR
  36473. for (i = 0; i < height; i++) {
  36474. mask = mask0;
  36475. offset = offset0;
  36476. for (j = 0; j < width; j++) {
  36477. if (bitmap[i][j]) {
  36478. buffer[offset] ^= mask;
  36479. }
  36480. mask >>= 1;
  36481. if (!mask) {
  36482. mask = 128;
  36483. offset++;
  36484. }
  36485. }
  36486. offset0 += rowSize;
  36487. }
  36488. break;
  36489. default:
  36490. error('JBIG2 error: operator ' + combinationOperator +
  36491. ' is not supported');
  36492. }
  36493. },
  36494. onImmediateGenericRegion:
  36495. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  36496. start, end) {
  36497. var regionInfo = region.info;
  36498. var decodingContext = new DecodingContext(data, start, end);
  36499. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  36500. region.template, region.prediction, null,
  36501. region.at, decodingContext);
  36502. this.drawBitmap(regionInfo, bitmap);
  36503. },
  36504. onImmediateLosslessGenericRegion:
  36505. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  36506. this.onImmediateGenericRegion.apply(this, arguments);
  36507. },
  36508. onSymbolDictionary:
  36509. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  36510. currentSegment,
  36511. referredSegments,
  36512. data, start, end) {
  36513. var huffmanTables;
  36514. if (dictionary.huffman) {
  36515. error('JBIG2 error: huffman is not supported');
  36516. }
  36517. // Combines exported symbols from all referred segments
  36518. var symbols = this.symbols;
  36519. if (!symbols) {
  36520. this.symbols = symbols = {};
  36521. }
  36522. var inputSymbols = [];
  36523. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36524. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36525. }
  36526. var decodingContext = new DecodingContext(data, start, end);
  36527. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  36528. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  36529. dictionary.numberOfExportedSymbols, huffmanTables,
  36530. dictionary.template, dictionary.at,
  36531. dictionary.refinementTemplate, dictionary.refinementAt,
  36532. decodingContext);
  36533. },
  36534. onImmediateTextRegion:
  36535. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  36536. referredSegments,
  36537. data, start, end) {
  36538. var regionInfo = region.info;
  36539. var huffmanTables;
  36540. // Combines exported symbols from all referred segments
  36541. var symbols = this.symbols;
  36542. var inputSymbols = [];
  36543. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  36544. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  36545. }
  36546. var symbolCodeLength = log2(inputSymbols.length);
  36547. var decodingContext = new DecodingContext(data, start, end);
  36548. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  36549. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  36550. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  36551. symbolCodeLength, region.transposed, region.dsOffset,
  36552. region.referenceCorner, region.combinationOperator, huffmanTables,
  36553. region.refinementTemplate, region.refinementAt, decodingContext);
  36554. this.drawBitmap(regionInfo, bitmap);
  36555. },
  36556. onImmediateLosslessTextRegion:
  36557. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  36558. this.onImmediateTextRegion.apply(this, arguments);
  36559. }
  36560. };
  36561. function Jbig2Image() {}
  36562. Jbig2Image.prototype = {
  36563. parseChunks: function Jbig2Image_parseChunks(chunks) {
  36564. return parseJbig2Chunks(chunks);
  36565. }
  36566. };
  36567. return Jbig2Image;
  36568. })();
  36569. var bidi = PDFJS.bidi = (function bidiClosure() {
  36570. // Character types for symbols from 0000 to 00FF.
  36571. var baseTypes = [
  36572. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  36573. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36574. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  36575. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  36576. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  36577. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36578. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  36579. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36580. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36581. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  36582. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36583. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  36584. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  36585. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  36586. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36587. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36588. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36589. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  36590. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  36591. ];
  36592. // Character types for symbols from 0600 to 06FF
  36593. var arabicTypes = [
  36594. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36595. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  36596. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36597. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36598. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36599. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36600. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36601. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36602. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  36603. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  36604. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36605. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36606. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36607. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36608. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36609. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36610. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36611. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36612. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  36613. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  36614. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  36615. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  36616. ];
  36617. function isOdd(i) {
  36618. return (i & 1) !== 0;
  36619. }
  36620. function isEven(i) {
  36621. return (i & 1) === 0;
  36622. }
  36623. function findUnequal(arr, start, value) {
  36624. for (var j = start, jj = arr.length; j < jj; ++j) {
  36625. if (arr[j] !== value) {
  36626. return j;
  36627. }
  36628. }
  36629. return j;
  36630. }
  36631. function setValues(arr, start, end, value) {
  36632. for (var j = start; j < end; ++j) {
  36633. arr[j] = value;
  36634. }
  36635. }
  36636. function reverseValues(arr, start, end) {
  36637. for (var i = start, j = end - 1; i < j; ++i, --j) {
  36638. var temp = arr[i];
  36639. arr[i] = arr[j];
  36640. arr[j] = temp;
  36641. }
  36642. }
  36643. function createBidiText(str, isLTR, vertical) {
  36644. return {
  36645. str: str,
  36646. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  36647. };
  36648. }
  36649. // These are used in bidi(), which is called frequently. We re-use them on
  36650. // each call to avoid unnecessary allocations.
  36651. var chars = [];
  36652. var types = [];
  36653. function bidi(str, startLevel, vertical) {
  36654. var isLTR = true;
  36655. var strLength = str.length;
  36656. if (strLength === 0 || vertical) {
  36657. return createBidiText(str, isLTR, vertical);
  36658. }
  36659. // Get types and fill arrays
  36660. chars.length = strLength;
  36661. types.length = strLength;
  36662. var numBidi = 0;
  36663. var i, ii;
  36664. for (i = 0; i < strLength; ++i) {
  36665. chars[i] = str.charAt(i);
  36666. var charCode = str.charCodeAt(i);
  36667. var charType = 'L';
  36668. if (charCode <= 0x00ff) {
  36669. charType = baseTypes[charCode];
  36670. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  36671. charType = 'R';
  36672. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  36673. charType = arabicTypes[charCode & 0xff];
  36674. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  36675. charType = 'AL';
  36676. }
  36677. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  36678. numBidi++;
  36679. }
  36680. types[i] = charType;
  36681. }
  36682. // Detect the bidi method
  36683. // - If there are no rtl characters then no bidi needed
  36684. // - If less than 30% chars are rtl then string is primarily ltr
  36685. // - If more than 30% chars are rtl then string is primarily rtl
  36686. if (numBidi === 0) {
  36687. isLTR = true;
  36688. return createBidiText(str, isLTR);
  36689. }
  36690. if (startLevel === -1) {
  36691. if ((strLength / numBidi) < 0.3) {
  36692. isLTR = true;
  36693. startLevel = 0;
  36694. } else {
  36695. isLTR = false;
  36696. startLevel = 1;
  36697. }
  36698. }
  36699. var levels = [];
  36700. for (i = 0; i < strLength; ++i) {
  36701. levels[i] = startLevel;
  36702. }
  36703. /*
  36704. X1-X10: skip most of this, since we are NOT doing the embeddings.
  36705. */
  36706. var e = (isOdd(startLevel) ? 'R' : 'L');
  36707. var sor = e;
  36708. var eor = sor;
  36709. /*
  36710. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  36711. type of the NSM to the type of the previous character. If the NSM is at the
  36712. start of the level run, it will get the type of sor.
  36713. */
  36714. var lastType = sor;
  36715. for (i = 0; i < strLength; ++i) {
  36716. if (types[i] === 'NSM') {
  36717. types[i] = lastType;
  36718. } else {
  36719. lastType = types[i];
  36720. }
  36721. }
  36722. /*
  36723. W2. Search backwards from each instance of a European number until the
  36724. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  36725. the type of the European number to Arabic number.
  36726. */
  36727. lastType = sor;
  36728. var t;
  36729. for (i = 0; i < strLength; ++i) {
  36730. t = types[i];
  36731. if (t === 'EN') {
  36732. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  36733. } else if (t === 'R' || t === 'L' || t === 'AL') {
  36734. lastType = t;
  36735. }
  36736. }
  36737. /*
  36738. W3. Change all ALs to R.
  36739. */
  36740. for (i = 0; i < strLength; ++i) {
  36741. t = types[i];
  36742. if (t === 'AL') {
  36743. types[i] = 'R';
  36744. }
  36745. }
  36746. /*
  36747. W4. A single European separator between two European numbers changes to a
  36748. European number. A single common separator between two numbers of the same
  36749. type changes to that type:
  36750. */
  36751. for (i = 1; i < strLength - 1; ++i) {
  36752. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  36753. types[i] = 'EN';
  36754. }
  36755. if (types[i] === 'CS' &&
  36756. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  36757. types[i + 1] === types[i - 1]) {
  36758. types[i] = types[i - 1];
  36759. }
  36760. }
  36761. /*
  36762. W5. A sequence of European terminators adjacent to European numbers changes
  36763. to all European numbers:
  36764. */
  36765. for (i = 0; i < strLength; ++i) {
  36766. if (types[i] === 'EN') {
  36767. // do before
  36768. var j;
  36769. for (j = i - 1; j >= 0; --j) {
  36770. if (types[j] !== 'ET') {
  36771. break;
  36772. }
  36773. types[j] = 'EN';
  36774. }
  36775. // do after
  36776. for (j = i + 1; j < strLength; --j) {
  36777. if (types[j] !== 'ET') {
  36778. break;
  36779. }
  36780. types[j] = 'EN';
  36781. }
  36782. }
  36783. }
  36784. /*
  36785. W6. Otherwise, separators and terminators change to Other Neutral:
  36786. */
  36787. for (i = 0; i < strLength; ++i) {
  36788. t = types[i];
  36789. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  36790. types[i] = 'ON';
  36791. }
  36792. }
  36793. /*
  36794. W7. Search backwards from each instance of a European number until the
  36795. first strong type (R, L, or sor) is found. If an L is found, then change
  36796. the type of the European number to L.
  36797. */
  36798. lastType = sor;
  36799. for (i = 0; i < strLength; ++i) {
  36800. t = types[i];
  36801. if (t === 'EN') {
  36802. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  36803. } else if (t === 'R' || t === 'L') {
  36804. lastType = t;
  36805. }
  36806. }
  36807. /*
  36808. N1. A sequence of neutrals takes the direction of the surrounding strong
  36809. text if the text on both sides has the same direction. European and Arabic
  36810. numbers are treated as though they were R. Start-of-level-run (sor) and
  36811. end-of-level-run (eor) are used at level run boundaries.
  36812. */
  36813. for (i = 0; i < strLength; ++i) {
  36814. if (types[i] === 'ON') {
  36815. var end = findUnequal(types, i + 1, 'ON');
  36816. var before = sor;
  36817. if (i > 0) {
  36818. before = types[i - 1];
  36819. }
  36820. var after = eor;
  36821. if (end + 1 < strLength) {
  36822. after = types[end + 1];
  36823. }
  36824. if (before !== 'L') {
  36825. before = 'R';
  36826. }
  36827. if (after !== 'L') {
  36828. after = 'R';
  36829. }
  36830. if (before === after) {
  36831. setValues(types, i, end, before);
  36832. }
  36833. i = end - 1; // reset to end (-1 so next iteration is ok)
  36834. }
  36835. }
  36836. /*
  36837. N2. Any remaining neutrals take the embedding direction.
  36838. */
  36839. for (i = 0; i < strLength; ++i) {
  36840. if (types[i] === 'ON') {
  36841. types[i] = e;
  36842. }
  36843. }
  36844. /*
  36845. I1. For all characters with an even (left-to-right) embedding direction,
  36846. those of type R go up one level and those of type AN or EN go up two
  36847. levels.
  36848. I2. For all characters with an odd (right-to-left) embedding direction,
  36849. those of type L, EN or AN go up one level.
  36850. */
  36851. for (i = 0; i < strLength; ++i) {
  36852. t = types[i];
  36853. if (isEven(levels[i])) {
  36854. if (t === 'R') {
  36855. levels[i] += 1;
  36856. } else if (t === 'AN' || t === 'EN') {
  36857. levels[i] += 2;
  36858. }
  36859. } else { // isOdd
  36860. if (t === 'L' || t === 'AN' || t === 'EN') {
  36861. levels[i] += 1;
  36862. }
  36863. }
  36864. }
  36865. /*
  36866. L1. On each line, reset the embedding level of the following characters to
  36867. the paragraph embedding level:
  36868. segment separators,
  36869. paragraph separators,
  36870. any sequence of whitespace characters preceding a segment separator or
  36871. paragraph separator, and any sequence of white space characters at the end
  36872. of the line.
  36873. */
  36874. // don't bother as text is only single line
  36875. /*
  36876. L2. From the highest level found in the text to the lowest odd level on
  36877. each line, reverse any contiguous sequence of characters that are at that
  36878. level or higher.
  36879. */
  36880. // find highest level & lowest odd level
  36881. var highestLevel = -1;
  36882. var lowestOddLevel = 99;
  36883. var level;
  36884. for (i = 0, ii = levels.length; i < ii; ++i) {
  36885. level = levels[i];
  36886. if (highestLevel < level) {
  36887. highestLevel = level;
  36888. }
  36889. if (lowestOddLevel > level && isOdd(level)) {
  36890. lowestOddLevel = level;
  36891. }
  36892. }
  36893. // now reverse between those limits
  36894. for (level = highestLevel; level >= lowestOddLevel; --level) {
  36895. // find segments to reverse
  36896. var start = -1;
  36897. for (i = 0, ii = levels.length; i < ii; ++i) {
  36898. if (levels[i] < level) {
  36899. if (start >= 0) {
  36900. reverseValues(chars, start, i);
  36901. start = -1;
  36902. }
  36903. } else if (start < 0) {
  36904. start = i;
  36905. }
  36906. }
  36907. if (start >= 0) {
  36908. reverseValues(chars, start, levels.length);
  36909. }
  36910. }
  36911. /*
  36912. L3. Combining marks applied to a right-to-left base character will at this
  36913. point precede their base character. If the rendering engine expects them to
  36914. follow the base characters in the final display process, then the ordering
  36915. of the marks and the base character must be reversed.
  36916. */
  36917. // don't bother for now
  36918. /*
  36919. L4. A character that possesses the mirrored property as specified by
  36920. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  36921. directionality of that character is R.
  36922. */
  36923. // don't mirror as characters are already mirrored in the pdf
  36924. // Finally, return string
  36925. var result = '';
  36926. for (i = 0, ii = chars.length; i < ii; ++i) {
  36927. var ch = chars[i];
  36928. if (ch !== '<' && ch !== '>') {
  36929. result += ch;
  36930. }
  36931. }
  36932. return createBidiText(result, isLTR);
  36933. }
  36934. return bidi;
  36935. })();
  36936. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  36937. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  36938. /* Copyright 2014 Opera Software ASA
  36939. *
  36940. * Licensed under the Apache License, Version 2.0 (the "License");
  36941. * you may not use this file except in compliance with the License.
  36942. * You may obtain a copy of the License at
  36943. *
  36944. * http://www.apache.org/licenses/LICENSE-2.0
  36945. *
  36946. * Unless required by applicable law or agreed to in writing, software
  36947. * distributed under the License is distributed on an "AS IS" BASIS,
  36948. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  36949. * See the License for the specific language governing permissions and
  36950. * limitations under the License.
  36951. *
  36952. *
  36953. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  36954. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  36955. */
  36956. /* globals Uint32ArrayView */
  36957. 'use strict';
  36958. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  36959. // Workaround for missing math precison in JS.
  36960. var MASK_HIGH = 0xffff0000;
  36961. var MASK_LOW = 0xffff;
  36962. function MurmurHash3_64 (seed) {
  36963. var SEED = 0xc3d2e1f0;
  36964. this.h1 = seed ? seed & 0xffffffff : SEED;
  36965. this.h2 = seed ? seed & 0xffffffff : SEED;
  36966. }
  36967. var alwaysUseUint32ArrayView = false;
  36968. // old webkits have issues with non-aligned arrays
  36969. try {
  36970. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  36971. } catch (e) {
  36972. alwaysUseUint32ArrayView = true;
  36973. }
  36974. MurmurHash3_64.prototype = {
  36975. update: function MurmurHash3_64_update(input) {
  36976. var useUint32ArrayView = alwaysUseUint32ArrayView;
  36977. var i;
  36978. if (typeof input === 'string') {
  36979. var data = new Uint8Array(input.length * 2);
  36980. var length = 0;
  36981. for (i = 0; i < input.length; i++) {
  36982. var code = input.charCodeAt(i);
  36983. if (code <= 0xff) {
  36984. data[length++] = code;
  36985. }
  36986. else {
  36987. data[length++] = code >>> 8;
  36988. data[length++] = code & 0xff;
  36989. }
  36990. }
  36991. } else if (input instanceof Uint8Array) {
  36992. data = input;
  36993. length = data.length;
  36994. } else if (typeof input === 'object' && ('length' in input)) {
  36995. // processing regular arrays as well, e.g. for IE9
  36996. data = input;
  36997. length = data.length;
  36998. useUint32ArrayView = true;
  36999. } else {
  37000. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  37001. 'Input must be a string or array.');
  37002. }
  37003. var blockCounts = length >> 2;
  37004. var tailLength = length - blockCounts * 4;
  37005. // we don't care about endianness here
  37006. var dataUint32 = useUint32ArrayView ?
  37007. new Uint32ArrayView(data, blockCounts) :
  37008. new Uint32Array(data.buffer, 0, blockCounts);
  37009. var k1 = 0;
  37010. var k2 = 0;
  37011. var h1 = this.h1;
  37012. var h2 = this.h2;
  37013. var C1 = 0xcc9e2d51;
  37014. var C2 = 0x1b873593;
  37015. var C1_LOW = C1 & MASK_LOW;
  37016. var C2_LOW = C2 & MASK_LOW;
  37017. for (i = 0; i < blockCounts; i++) {
  37018. if (i & 1) {
  37019. k1 = dataUint32[i];
  37020. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37021. k1 = k1 << 15 | k1 >>> 17;
  37022. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37023. h1 ^= k1;
  37024. h1 = h1 << 13 | h1 >>> 19;
  37025. h1 = h1 * 5 + 0xe6546b64;
  37026. } else {
  37027. k2 = dataUint32[i];
  37028. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  37029. k2 = k2 << 15 | k2 >>> 17;
  37030. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  37031. h2 ^= k2;
  37032. h2 = h2 << 13 | h2 >>> 19;
  37033. h2 = h2 * 5 + 0xe6546b64;
  37034. }
  37035. }
  37036. k1 = 0;
  37037. switch (tailLength) {
  37038. case 3:
  37039. k1 ^= data[blockCounts * 4 + 2] << 16;
  37040. /* falls through */
  37041. case 2:
  37042. k1 ^= data[blockCounts * 4 + 1] << 8;
  37043. /* falls through */
  37044. case 1:
  37045. k1 ^= data[blockCounts * 4];
  37046. /* falls through */
  37047. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  37048. k1 = k1 << 15 | k1 >>> 17;
  37049. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  37050. if (blockCounts & 1) {
  37051. h1 ^= k1;
  37052. } else {
  37053. h2 ^= k1;
  37054. }
  37055. }
  37056. this.h1 = h1;
  37057. this.h2 = h2;
  37058. return this;
  37059. },
  37060. hexdigest: function MurmurHash3_64_hexdigest () {
  37061. var h1 = this.h1;
  37062. var h2 = this.h2;
  37063. h1 ^= h2 >>> 1;
  37064. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  37065. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  37066. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  37067. h1 ^= h2 >>> 1;
  37068. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  37069. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  37070. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  37071. h1 ^= h2 >>> 1;
  37072. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  37073. var hex = (arr[i] >>> 0).toString(16);
  37074. while (hex.length < 8) {
  37075. hex = '0' + hex;
  37076. }
  37077. str += hex;
  37078. }
  37079. return str;
  37080. }
  37081. };
  37082. return MurmurHash3_64;
  37083. })();
  37084. }).call((typeof window === 'undefined') ? this : window);
  37085. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  37086. // workerSrc is not set -- using last script url to define default location
  37087. PDFJS.workerSrc = (function () {
  37088. 'use strict';
  37089. var scriptTagContainer = document.body ||
  37090. document.getElementsByTagName('head')[0];
  37091. var pdfjsSrc = scriptTagContainer.lastChild.src;
  37092. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  37093. })();
  37094. }